Search Chirayu Software Solutions Blog

Monday, September 30, 2013

Link to Free MySQL Edition

Saturday, September 28, 2013

Yes or No confirm box using jQuery

$('<div></div>').appendTo('body')
                    .html('<div><h6>Are you sure?</h6></div>')
                    .dialog({
                        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
                        width: 'auto', resizable: false,
                        buttons: {
                            Yes: function () {
                                // $(obj).removeAttr('onclick');                                
                                // $(obj).parents('.Parent').remove();

                                $(this).dialog("close");
                            },
                            No: function () {
                                $(this).dialog("close");
                            }
                        },
                        close: function (event, ui) {
                            $(this).remove();
                        }
                    });

NewLine in C#

Program that uses Environment.NewLine: C#

using System;

class Program
{
    static void Main()
    {
 //
 // Use string concat to combine two literals
 // with the newline constant.
 //
 string s = "First line" +
     Environment.NewLine +
     "Second line";
 Console.Write(s);
 Console.Read();
    }
}

Output

First line
Second line

convert dataset into csv file

Code Snippet
Dim str As New StringBuilder
For Each dr As DataRow In Me.NorthwindDataSet.Customers
     For Each field As Object In dr.ItemArray
     str.Append(field.ToString & ",")
     Next
     str.Replace(",", vbNewLine, str.Length - 1, 1)
Next

Try
     My.Computer.FileSystem.WriteAllText("C:\temp\testcsv.csv", str.ToString, False)
Catch ex As Exception
     MessageBox.Show("Write Error")

End Try

Thursday, September 26, 2013

check if a program is already running in c#

 if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1)
            { 
                //application is already running
                MessageBox.Show("Cannot start,  please close it before starting again");
                System.Diagnostics.Process.GetCurrentProcess().Kill();

            }

run an external program in c#

using System.Diagnostics;

class Program
{
    static void Main()
    {
 //
 // Use Process.Start here.
 //
 Process.Start("C:\\");
    }
}

Getting Date only from a DateTime Object

DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);
Console.WriteLine(date1.ToString());

// Get date-only portion of date, without its time.
DateTime dateOnly = date1.Date;
// Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"));
// Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"));
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"));   
// The example displays the following output to the console: 
//       6/1/2008 7:47:00 AM 
//       6/1/2008 
//       6/1/2008 12:00 AM 
//       06/01/2008 00:00

How to identify if a string is a number?

This will return true if input is all numbers. Don't know if it's any better than TryParse, but it will work.
Regex.IsMatch(input, @"^\d+$")
If you just want to know if it has one or more numbers mixed in with characters, leave off the ^ + and$.
Regex.IsMatch(input, @"\d")
Edit: Actually I think it is better than TryParse because a very long string could potentially overflow TryParse.