25 March, 2012

Get All Date Between Two Date in SQL

Use a recursive query:


WITH RetAlldate AS (
  SELECT CAST('20 Jan 2012' AS DATETIME) AS EventDate
  UNION ALL
  SELECT DATEADD(ww, 1, EventDate)
    FROM RetAlldate s
   WHERE DATEADD(ww, 1, EventDate) <= CAST('01 Dec 2012' AS DATETIME))
SELECT *
  FROM RetAlldate

15 March, 2012

Check Network/Internet Connection Using C#


To check for a network connection in .NET use this:
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
To monitor a change in IP address or a change in network availability, use the events from the NetworkChange class:
System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged

System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged
For Example.......................................................................

using System.Net.NetworkInformation;

Call following function............

public void CheckInternet()
{
        if(NetworkInterface.GetIsNetworkAvailable())
                Console.Write("Network connected!\n");
        else
                Console.Write("Network disconnected!\n");           
}

public void IsConnectedToInternet()
{
        string host = "http://www.google.com";
        bool result = false;
        Ping p = new Ping();
            try
            {
                PingReply reply = p.Send(host, 3000);
                if (reply.Status == IPStatus.Success)
                    result=true;
            }
            catch {
            }
           
        if (result==true)
                Console.Write("Internet connected!\n");
        else
                Console.Write("Internet disconnected!\n");  
 }

13 March, 2012

My Own Easy Encrypt & Decrypt in C#

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Text;
///


/// Summary description for EnD
///

public class EnD
{
    public static string[] data = { "A", "B", "C", "D", "E", "F", "G", "H",
                                          "I", "J", "K", "L", "M", "N","O","P",
                                      "Q", "R", "S", "T", "U", "V","W","X",
                                      "Y", "Z", "0", "1", "2", "3","4","5","6","7","8","9"};
    public string imranEncrypt(string input, int key)
    {
        input = input.ToUpper();
        string output = "";
        int shift = 0;
        for (int i = 0; i < input.Length; i++)
        {
            if ((Array.IndexOf(data, input.Substring(i, 1)) + key + shift) > 35)
                output = output + data[(Array.IndexOf(data, input.Substring(i, 1)) + key + shift) % 36];
            else
                output = output + data[Array.IndexOf(data, input.Substring(i, 1)) + key + shift];
            shift++;
        }
        return output;
    }
    public string imranDecrypt(string input, int key)
    {
        int shift = 0;
        input = input.ToUpper();
        string output = "";
        int indexLen = 0;

        for (int i = 0; i < input.Length; i++)
        {
            indexLen = (Array.IndexOf(data, input.Substring(i, 1))) - key - shift;
            if (indexLen < 0)
            {
                do
                {
                    indexLen += 36;
                } while (indexLen < 0);
                output = output + data[indexLen];
            }
            else
                output = output + data[indexLen];
            shift++;
        }
        return output;
    }
    public EnD()
    {

    }
}

05 March, 2012

EnCryption & Decryption in C#

public string EncryptDecrypt(string textToEncrypt, int encryptionKey)
{
StringBuilder inSb = new StringBuilder(textToEncrypt);
StringBuilder outSb = new StringBuilder(textToEncrypt.Length);
char c;
for (int i = 0; i < textToEncrypt.Length; i++)
{
c = inSb[i];
c = (char)(c ^ encryptionKey);
outSb.Append(c);
}
return outSb.ToString();
}