About Me

My photo
New Delhi, Delhi, India
I am working in Infosys.

April 30, 2015

clsGetProvider.cs

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;

/// <summary>
/// Summary description for clsGetProvider
/// </summary>
public class clsGetProvider
{
    public clsGetProvider()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public String Provider { get; set; }
    public String ProviderID { get; set; }
}

SqlHelper.cs


// http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Xml;
using System.Collections;


namespace DBLibrary
{
   
    public sealed class SqlHelper
    {
       
       
        #region private utility methods & constructors

       
        private SqlHelper() {}



       
        private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
        {
            foreach (SqlParameter p in commandParameters)
            {
                //check for derived output value with no value assigned
                if ((p.Direction == ParameterDirection.InputOutput) && (p.Value == null))
                {
                    p.Value = DBNull.Value;
                }
               
                command.Parameters.Add(p);
            }
        }

   
        private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)
        {
            if ((commandParameters == null) || (parameterValues == null))
            {
                //do nothing if we get no data
                return;
            }

            // we must have the same number of values as we pave parameters to put them in
            if (commandParameters.Length != parameterValues.Length)
            {
                throw new ArgumentException("Parameter count does not match Parameter Value count.");
            }

            //iterate through the SqlParameters, assigning the values from the corresponding position in the
            //value array
            for (int i = 0, j = commandParameters.Length; i < j; i++)
            {
                commandParameters[i].Value = parameterValues[i];
            }
        }

       
        private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters)
        {
            //if the provided connection is not open, we will open it
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            //associate the connection with the command
            command.Connection = connection;

            //set the command text (stored procedure name or SQL statement)
            command.CommandText = commandText;

            //if we were provided a transaction, assign it.
            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            //set the command type
            command.CommandType = commandType;

            //attach the command parameters if they are provided
            if (commandParameters != null)
            {
                AttachParameters(command, commandParameters);
            }

            return;
        }


        #endregion private utility methods & constructors

        #region ExecuteNonQuery

       
        public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteNonQuery(connectionString, commandType, commandText, (SqlParameter[])null);
        }

       
        public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            CnSettings objCN = new CnSettings();

            //create & open a SqlConnection, and dispose of it after we are done.
            using (SqlConnection cn = new SqlConnection(objCN.getdb()))
            {
                try
                {
                    cn.Open();

                    //call the overload that takes a connection in place of the connection string
                    return ExecuteNonQuery(cn, commandType, commandText, commandParameters);
                }
                finally
                {
                    cn.Dispose();
                    }
            }
        }

       
        public static int ExecuteNonQuery(string connectionString, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);
            }
        }

       
        public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteNonQuery(connection, commandType, commandText, (SqlParameter[])null);
        }

       
        public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {   
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
           
            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
           
            //finally, execute the command.
            int retval = cmd.ExecuteNonQuery();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
           
            return retval;
        }

       
        public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteNonQuery(connection, CommandType.StoredProcedure, spName);
            }
        }

       
        public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteNonQuery(transaction, commandType, commandText, (SqlParameter[])null);
        }

   
        public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
           
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);
           
            //finally, execute the command.
            int retval = cmd.ExecuteNonQuery();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
       

            return retval;
        }

   
        public static int ExecuteNonQuery(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName);
            }
        }


        #endregion ExecuteNonQuery

        #region ExecuteDataSet



      


      
       
        public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataset(connectionString, commandType, commandText, (SqlParameter[])null);
        }

       
        public static DataSet ExecuteDataset(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            CnSettings objCN = new CnSettings();
            //create & open a SqlConnection, and dispose of it after we are done.
            using (SqlConnection cn = new SqlConnection(objCN.getdb()))
            {
                try
                {
                    cn.Open();
                   
                    //call the overload that takes a connection in place of the connection string
                    return ExecuteDataset(cn, commandType, commandText, commandParameters);
                }
              catch (Exception ex) { throw (ex); }
                finally
                {
                    cn.Dispose();
                }

            }
       
        }

       
        public static DataSet ExecuteDataset(string connectionString, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataset(connectionString, CommandType.StoredProcedure, spName);
            }
        }

   
        public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataset(connection, commandType, commandText, (SqlParameter[])null);
        }
       
       
        public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
           
            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
           
            //create the DataAdapter & DataSet
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(ds);
           
            // detach the SqlParameters from the command object, so they can be used again.           
            cmd.Parameters.Clear();
           
            //return the dataset
            connection.Close();
            return ds;                       
        }
       
       
        public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataset(connection, CommandType.StoredProcedure, spName);
            }
        }

       
        public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null);
        }
       
       
        public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
       
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);
           
            //create the DataAdapter & DataSet
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(ds);
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
           
           
            //return the dataset
            return ds;
        }
       
       
        public static DataSet ExecuteDataset(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataset(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataset(transaction, CommandType.StoredProcedure, spName);
            }
        }

        #endregion ExecuteDataSet
       
        #region ExecuteReader

       
        private enum SqlConnectionOwnership   
        {
            /// <summary>Connection is owned and managed by SqlHelper</summary>
            Internal,
            /// <summary>Connection is owned and managed by the caller</summary>
            External
        }

       
        private static SqlDataReader ExecuteReader(SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, SqlConnectionOwnership connectionOwnership)
        {   
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
       
            PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters);
           
            //create a reader
            SqlDataReader dr;

            // call ExecuteReader with the appropriate CommandBehavior
            if (connectionOwnership == SqlConnectionOwnership.External)
            {
                dr = cmd.ExecuteReader();
            }
            else
            {
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
           
            return dr;
        }

       
        public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteReader(connectionString, commandType, commandText, (SqlParameter[])null);
        }

       
        public static SqlDataReader ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            CnSettings objCN = new CnSettings();
            //create & open a SqlConnection
            SqlConnection cn = new SqlConnection(objCN.getdb());
            cn.Open();

            try
            {
                //call the private overload that takes an internally owned connection in place of the connection string
                return ExecuteReader(cn, null, commandType, commandText, commandParameters, SqlConnectionOwnership.Internal);
            }
            catch(Exception ex)
            {
                //DBLayer.DBLInstance.GlobalInstance.ExceptionAndEventHandling(ex);
                //if we fail to return the SqlDatReader, we need to close the connection ourselves
                cn.Close();
                throw ex;
                return null;
               
            }

             

        }

       
        public static SqlDataReader ExecuteReader(string connectionString, string spName, params   object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteReader(connectionString, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteReader(connectionString, CommandType.StoredProcedure, spName);
            }
        }

       
        public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteReader(connection, commandType, commandText, (SqlParameter[])null);
        }

       
        public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //pass through the call to the private overload using a null transaction value and an externally owned connection
            return ExecuteReader(connection, (SqlTransaction)null, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
        }

       
        public static SqlDataReader ExecuteReader(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                AssignParameterValues(commandParameters, parameterValues);

                return ExecuteReader(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteReader(connection, CommandType.StoredProcedure, spName);
            }
        }

       
        public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteReader(transaction, commandType, commandText, (SqlParameter[])null);
        }

       
        public static SqlDataReader ExecuteReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //pass through to private overload, indicating that the connection is owned by the caller
            return ExecuteReader(transaction.Connection, transaction, commandType, commandText, commandParameters, SqlConnectionOwnership.External);
        }

       
        public static SqlDataReader ExecuteReader(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                AssignParameterValues(commandParameters, parameterValues);

                return ExecuteReader(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteReader(transaction, CommandType.StoredProcedure, spName);
            }
        }


        #endregion ExecuteReader

        #region ExecuteScalar
       
       
        public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteScalar(connectionString, commandType, commandText, (SqlParameter[])null);
        }

       
        public static object ExecuteScalar(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            CnSettings objCN = new CnSettings();
            //create & open a SqlConnection, and dispose of it after we are done.
            using (SqlConnection cn = new SqlConnection(objCN.getdb()))
            {
                cn.Open();

                //call the overload that takes a connection in place of the connection string
                return ExecuteScalar(cn, commandType, commandText, commandParameters);
               
            }
        }

   
        public static object ExecuteScalar(string connectionString, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName);
            }
        }

       
        public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteScalar(connection, commandType, commandText, (SqlParameter[])null);
        }

       
        public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
           
            //execute the command & return the results
           
            object retval = cmd.ExecuteScalar();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
            connection.Close ();

            return retval;
           
        }

       
        public static object ExecuteScalar(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteScalar(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteScalar(connection, CommandType.StoredProcedure, spName);
            }
        }

       
        public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteScalar(transaction, commandType, commandText, (SqlParameter[])null);
        }

       
        public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);
           
            //execute the command & return the results
            object retval = cmd.ExecuteScalar();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
            transaction.Connection.Close();
            return retval;
        }

       
        public static object ExecuteScalar(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteScalar(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteScalar(transaction, CommandType.StoredProcedure, spName);
            }
        }

        #endregion ExecuteScalar   
   
        #region ExecuteXmlReader

        public  XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteXmlReader(connection, commandType, commandText, (SqlParameter[])null);
        }

       
        public  XmlReader ExecuteXmlReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
           
            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);
           
            //create the DataAdapter & DataSet
            XmlReader retval = cmd.ExecuteXmlReader();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
            return retval;
           
        }

       
        public  XmlReader ExecuteXmlReader(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteXmlReader(connection, CommandType.StoredProcedure, spName);
            }
        }

       
        public  XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteXmlReader(transaction, commandType, commandText, (SqlParameter[])null);
        }

        public  XmlReader ExecuteXmlReader(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();
       
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);
           
            //create the DataAdapter & DataSet
            XmlReader retval = cmd.ExecuteXmlReader();
           
            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();
            return retval;           
        }

       
        public  XmlReader ExecuteXmlReader(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
                //otherwise we can just call the SP without params
            else
            {
                return ExecuteXmlReader(transaction, CommandType.StoredProcedure, spName);
            }
        }


        #endregion ExecuteXmlReader
        #region ExecuteDataTable

     
        public static DataTable ExecuteDataTable(string connectionString, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataTable(connectionString, commandType, commandText, (SqlParameter[])null);
        }

     
        public static DataTable ExecuteDataTable(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            CnSettings objCN = new CnSettings();
            //create & open a SqlConnection, and dispose of it after we are done.
            using (SqlConnection cn = new SqlConnection(objCN.getdb()))
            {
                try
                {
                    cn.Open();

                    //call the overload that takes a connection in place of the connection string
                    return ExecuteDataTable(cn, commandType, commandText, commandParameters);
                }
                finally
                {
                    cn.Dispose();
                }

            }
        }

     
        public static DataTable ExecuteDataTable(string connectionString, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataTable(connectionString, CommandType.StoredProcedure, spName, commandParameters);
            }
            //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataTable(connectionString, CommandType.StoredProcedure, spName);
            }
        }

      
        public static DataTable ExecuteDataTable(SqlConnection connection, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataTable(connection, commandType, commandText, (SqlParameter[])null);
        }

     
        public static DataTable ExecuteDataTable(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();

            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

            //create the DataAdapter & DataSet
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(dt);

            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();

            //return the dataset
            connection.Close();
            return dt;
        }

      
        public static DataTable ExecuteDataTable(SqlConnection connection, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataTable(connection, CommandType.StoredProcedure, spName, commandParameters);
            }
            //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataTable(connection, CommandType.StoredProcedure, spName);
            }
        }

      
        public static DataTable ExecuteDataTable(SqlTransaction transaction, CommandType commandType, string commandText)
        {
            //pass through the call providing null for the set of SqlParameters
            return ExecuteDataTable(transaction, commandType, commandText, (SqlParameter[])null);
        }

    
        public static DataTable ExecuteDataTable(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            //create a command and prepare it for execution
            SqlCommand cmd = new SqlCommand();

            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

            //create the DataAdapter & DataSet
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();

            //fill the DataSet using default values for DataTable names, etc.
            da.Fill(dt);

            // detach the SqlParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();


            //return the dataset
            return dt;
        }

    
        public static DataTable ExecuteDataTable(SqlTransaction transaction, string spName, params object[] parameterValues)
        {
            //if we receive parameter values, we need to figure out where they go
            if ((parameterValues != null) && (parameterValues.Length > 0))
            {
                //pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
                SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString, spName);

                //assign the provided values to these parameters based on parameter order
                AssignParameterValues(commandParameters, parameterValues);

                //call the overload that takes an array of SqlParameters
                return ExecuteDataTable(transaction, CommandType.StoredProcedure, spName, commandParameters);
            }
            //otherwise we can just call the SP without params
            else
            {
                return ExecuteDataTable(transaction, CommandType.StoredProcedure, spName);
            }
        }

        #endregion ExecuteDataTable
       
    }

   
    public sealed class SqlHelperParameterCache
    {
        CnSettings objCN = new CnSettings();

      
        #region private methods, variables, and constructors

       
        private SqlHelperParameterCache() {}

        private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable());

   
        private static SqlParameter[] DiscoverSpParameterSet(string connectionString, string spName, bool includeReturnValueParameter)
        {
            CnSettings objCN = new CnSettings();
            using (SqlConnection cn = new SqlConnection(objCN.getdb()))
            using (SqlCommand cmd = new SqlCommand(spName,cn))
            {
                cn.Open();
                cmd.CommandType = CommandType.StoredProcedure;

                SqlCommandBuilder.DeriveParameters(cmd);

                if (!includeReturnValueParameter)
                {
                    cmd.Parameters.RemoveAt(0);
                }

                SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count];;

                cmd.Parameters.CopyTo(discoveredParameters, 0);
                cn.Close();

                return discoveredParameters;
            }
        }

        //deep copy of cached SqlParameter array
        private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters)
        {
            SqlParameter[] clonedParameters = new SqlParameter[originalParameters.Length];

            for (int i = 0, j = originalParameters.Length; i < j; i++)
            {
                clonedParameters[i] = (SqlParameter)((ICloneable)originalParameters[i]).Clone();
            }

            return clonedParameters;
        }

        #endregion private methods, variables, and constructors

        #region caching functions

       
        public static void CacheParameterSet(string connectionString, string commandText, params SqlParameter[] commandParameters)
        {
            string hashKey = connectionString + ":" + commandText;

            paramCache[hashKey] = commandParameters;
        }

       
        public static SqlParameter[] GetCachedParameterSet(string connectionString, string commandText)
        {
            string hashKey = connectionString + ":" + commandText;

            SqlParameter[] cachedParameters = (SqlParameter[])paramCache[hashKey];
           
            if (cachedParameters == null)
            {           
                return null;
            }
            else
            {
                return CloneParameters(cachedParameters);
            }
        }

        #endregion caching functions

        #region Parameter Discovery Functions

       
        public static SqlParameter[] GetSpParameterSet(string connectionString, string spName)
        {
            return GetSpParameterSet(connectionString, spName, false);
        }

   
        public static SqlParameter[] GetSpParameterSet(string connectionString, string spName, bool includeReturnValueParameter)
        {
            string hashKey = connectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter":"");

            SqlParameter[] cachedParameters;
           
            cachedParameters = (SqlParameter[])paramCache[hashKey];

            if (cachedParameters == null)
            {           
                cachedParameters = (SqlParameter[])(paramCache[hashKey] = DiscoverSpParameterSet(connectionString, spName, includeReturnValueParameter));
            }
           
            return CloneParameters(cachedParameters);
        }

        #endregion Parameter Discovery Functions

    }



}

ClsCommon

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using DBLibrary;
using System.Security.Cryptography;


/// <summary>
/// Summary description for clsPatientInfo
/// </summary>
public class clsCommon
{
    public  string ConnStr;
    public String User_ID { get; set; }
    public String Token_No { get; set; }
    public String UserName { get; set; }
    public String Login_Date { get; set; }
    public int DepID { get; set; }
    public string Password { get; set; }
    public string ProviderID { get; set; }
    public int Profile { get; set; }
    public Boolean Status { get; set; }
    public string StaffNumber { get; set; }
    public string FullName { get; set; }
    public int CounterID { get; set; }
    public string UserType { get; set; }
     static List<clsGetProvider> lstGetProvider = new List<clsGetProvider>();
     List<clsGetProvider> lstPatientList_ASMX1 = new List<clsGetProvider>();
     List<clsGetProvider> lstGet_Final_Provider = new List<clsGetProvider>();
    public clsCommon()
    {
       
                CnSettings clsObjSetting = new CnSettings();
                ConnStr = clsObjSetting.ConnectionStr;
      
    }
   
    public DataSet RunSQLQuery(string sql)
    {
        DataSet ds = new DataSet();       
        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
        return ds;
       
    }

    public Int32 MaxId(string FieldName, string TableName)
    {
        int i;
        object value = null;
        string str = "select isnull(max(" + FieldName + "),0) as MaxID from " + TableName + " ";
        DataSet ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, str);
        value =Convert.ToInt32( ds.Tables[0].Rows[0]["MaxID"].ToString());

        i = Convert.ToInt32(value);

        i = i + 1;
        return i;

    }

    public string GetDateForUI(string obj)
    {
        DateTime objDate;
        if (DateTime.TryParse(obj.ToString(), out objDate) && objDate.Year != 1)
            return objDate.ToString("dd/MM/yyyy");
        else
            return "";
    }
    public DateTime GetDateForDBAddOneDate(object obj)
    {
        DateTime objDate;
        if (!string.IsNullOrEmpty(obj.ToString()))
        {
            obj = (object)GetDateInMMDDYYYY(obj);
            DateTime a = Convert.ToDateTime(obj.ToString());
            obj = a.AddDays(1);
        }

        if (DateTime.TryParse(obj.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out objDate) && objDate.Year != 1)
            return objDate;
        else
            return objDate;

    }
    public DateTime GetDateForDB(object obj)
    {
        DateTime objDate;
        if (!string.IsNullOrEmpty(obj.ToString()))
            obj = (object)GetDateInMMDDYYYY(obj);

        if (DateTime.TryParse(obj.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out objDate) && objDate.Year != 1)
            return objDate;
        else
            return objDate;
      
    }
    public String GetDateTimeOP(object obj)
    {
        String objDate="";
        if (!string.IsNullOrEmpty(obj.ToString()))
        {
            char rowSep = ' ';
            objDate = GetDateForDB(obj).ToString();
            string[] Text = objDate.Split(rowSep);
            if (Text.Length >= 1)
            {
                objDate = Text[0].TrimStart().ToString() + " ";
                objDate = objDate + DateTime.Now.ToShortTimeString();
                return objDate;
            }
            else
                return objDate;
        }
        else
            return objDate;


    }


    public String GetDateInMMDDYYYY(object obj)
    {
        String[] objDate = obj.ToString().Split('/');
        return objDate[1] + "/" + objDate[0] + "/" + objDate[2];
    }


    public bool IsDateTime(object Expression)
    {
        try
        {
            if (Expression == null)
                return false;

            DateTime objVal;
            if (DateTime.TryParse(Expression.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out objVal))
                return true;
            else

                return false;
        }
        catch (Exception ex)
        {
             throw ex;
            return false;
        }
    }


    public DataSet UserLogin(String UserName, String Pass, String ProviderID)
    {

        string sql = "select * from UserLogin where UserName = '" + UserName + "'  and Password = '" + Pass + "'";
        DataSet ds = new DataSet();


        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
       
      
        return ds;
       
    }
   



    public DataSet DepartmentDetail(string UserID,Int32 DepartmentID)
    {

        string sql = "select * from Userlogin where UserName = '" + UserID + "'";
        DataSet ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
       
        return ds;
      
    }


    public DataSet DataGridFill(String FldName, String FldValue, String tableName)
    {
        string sql = null;
        if (String.IsNullOrEmpty(FldName))
            sql = "select * from " + tableName + "";
        else
        {
            FldName = FldName + " = ";
            /// FldValue = FldValue ;
            sql = "select * from " + tableName + " where " + FldName + " '" + FldValue + "'";
        }
        DataSet ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
        return ds;
       
    }


    public bool CheckSessionValue( String ProviderID,  string userID)
    {
        bool  mes = false ;
        
        if (ProviderID == "")
        { mes = true; }
        
        if (userID == "")
            mes = true ;
        return mes;
   
    }

    public bool CheckCookiesValue(String ProviderID, string userID)
    {
        bool mes = false;

        if (ProviderID == "" || ProviderID==null)
        { mes = true; }

        if (userID == "" || userID==null)
            mes = true;
        return mes;

    }
    public DateTime GetDateForDBNew(object obj)
    {
        DateTime objDate;
        String FORMAT = "dd/MM/yyyy";
        if (!DateTime.TryParseExact(obj.ToString(), FORMAT, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out objDate))
        {
            DateTime.TryParse("01/01/0001", out objDate);
        }

        return objDate;
       
    }
    public Int64 GetInteger64(object objVal)
    {
        Int64 intValue = 0;
        if (objVal == null) return 0;
        if (objVal is DBNull) return 0;
        if (objVal is Int64) return (Int64)objVal;
        Int64.TryParse(objVal.ToString(), out intValue);
        return intValue;
    }
   

    public Int32 GetInteger32(object objVal)
    {
        Int32 intValue = 0;
        if (objVal == null) return 0;
        if (objVal is DBNull) return 0;
        if (objVal is Int32) return (Int32)objVal;
        Int32.TryParse(objVal.ToString(), out intValue);
        return intValue;
    }

    public DateTime GetTimeForDB(object obj)
    {
        DateTime objDate;
        if (DateTime.TryParse("01/01/1900 " + obj.ToString(), out objDate) && objDate.Year != 1)
            return objDate;
        else
            return objDate;
    }

    public object GetTimeForUI(object obj)
    {
        DateTime objDate;
        if (DateTime.TryParse(obj.ToString(), out objDate) && objDate.Year != 1)
            return objDate.ToString("hh:mm:ss tt");
        else
            return null;
    }
    public DateTime GetDate(object objVal)
    {
        if (objVal == null) return Convert.ToDateTime(null);
        if (objVal is DBNull) return Convert.ToDateTime(null);
        if (objVal is string && string.IsNullOrEmpty(objVal.ToString())) return Convert.ToDateTime(null);
        return Convert.ToDateTime(objVal);
    }
    public DateTime GetDateForDB_APP(object obj)
    {

        DateTime objDate;
        String FORMAT = "dd/MM/yyyy";
        if (!DateTime.TryParseExact(obj.ToString(), FORMAT, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out objDate))
        {
            DateTime.TryParse("01/01/0001", out objDate);
        }

        return objDate;
    }

    public DateTime GetDateForDB_APP_FromDB(object obj)
    {
        DateTime objDate;
        String FORMAT = "dd/MM/yyyy";
        if (!DateTime.TryParseExact(obj.ToString(), FORMAT, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out objDate))
        {
            DateTime.TryParse("01/01/0001", out objDate);
        }

        return objDate;
    }

    public void GetAge(DateTime DOB, System.Web.UI.WebControls.TextBox txt)
    {
        if (DOB < DateTime.Now)
        {
            TimeSpan dateDiff = DateTime.Now - DOB;
            DateTime age = new DateTime(dateDiff.Ticks);

            Int32 Years = age.Year - 1;
            Int32 Month = age.Month - 1;
            Int32 Days = age.Day - 1;
            txt.Text = Years.ToString("00") + " Y, " + Month.ToString("00") + " M, " + Days.ToString("00") + " D ";

        }

    }
    public string GetUniqueFileName(string filename)
    {
        try
        {
            string[] ext = new string[5];
            ext = filename.Split('.');
            return Guid.NewGuid().ToString() + "." + ext[ext.Length - 1];
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
    public DateTime GetDateForDB_IPD(object obj)
    {
    
        DateTime objDate;
        String FORMAT = "dd/MM/yyyy";
        if (!DateTime.TryParseExact(obj.ToString(), FORMAT, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out objDate))
        {
            DateTime.TryParse("01/01/0001", out objDate);
        }

        return objDate;
    }

    public DataSet DeleteData(String FldName, String FldValue, String tableName)
    {
        string sql = null;
        if (String.IsNullOrEmpty(FldName))
            sql = "Delete from " + tableName + "";
        else
        {
            FldName = FldName + " = ";
            /// FldValue = FldValue ;
            sql = "delete from " + tableName + " where " + FldName + " '" + FldValue + "'";
        }
        DataSet ds = new DataSet();
        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
        return ds;
    }

    public string  Database(string ProviderID)
    {
       // try
        //{
            string con = null;
            string sql = "select * from IE_Database_Setting where ProviderID='" +  HttpContext.Current.Session["Check"].ToString() + "' ";
            DataSet ds = new DataSet();

            ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.Text, sql);
         
           if (ds.Tables[0].Rows.Count > 0)
            {
                ConnStr = ds.Tables[0].Rows[0]["ConnectionString"].ToString();
                ;
            }
            return ConnStr;
       
    }

    public string autostring10()
    {

        string id = Guid.NewGuid().ToString("N").Substring(15);
        return id;
    }
    public string autopassword()
    {
        var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
        var random = new Random(); string output = "";
        for (int i = 0; i < 7; i++)
        {
            output += chars[random.Next(chars.Length)];
        }
        return output;
    }

    public System.Collections.Generic.List<clsCommon> CheckLogin(String UserName, String Pass, Int32 CounterID, String QueryType, string ProviderId)
    {

        SqlDataReader dr = null;
        System.Collections.Generic.List<clsCommon> lstLoginInfo = new System.Collections.Generic.List<clsCommon>();
      
        SqlParameter[] ParamList = new SqlParameter[5];
        ParamList[0] = new SqlParameter("@UserName", UserName);
        ParamList[1] = new SqlParameter("@Password", Pass);
        ParamList[2] = new SqlParameter("@ProviderID", ProviderId);
        ParamList[3] = new SqlParameter("@QueryType", QueryType);
        ParamList[4] = new SqlParameter("@CounterID", CounterID);
        dr = SqlHelper.ExecuteReader(ConnStr, CommandType.StoredProcedure, "Proc_Create_Login", ParamList);

        while (dr.Read())
        {
            clsCommon objApp = new clsCommon();
            objApp.User_ID = dr["UserID"].ToString();
            objApp.UserName = dr["UserName"].ToString();
            objApp.Password = dr["Password"].ToString();
            objApp.ProviderID = dr["ProviderID"].ToString();
            objApp.Profile = Convert.ToInt32(dr["Profile"].ToString());
            objApp.Status = Convert.ToBoolean(dr["Status"].ToString());
            objApp.StaffNumber = dr["StaffNumber"].ToString();
            objApp.FullName = dr["FullName"].ToString();
          
            lstLoginInfo.Add(objApp);
        }
        return lstLoginInfo;
    }

    public string ChopStringWithLen(string StrName, int Len)
    {
        if (StrName.Length > Len)
            return (StrName.Substring(0, Len) + "...");
        else
            return StrName;
    }



    public string EncryptString(string Message, string Passphrase)
    {
        byte[] Results;
        System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

        MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
        byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));

        // Step 2. Create a new TripleDESCryptoServiceProvider object
        TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

        // Step 3. Setup the encoder
        TDESAlgorithm.Key = TDESKey;
        TDESAlgorithm.Mode = CipherMode.ECB;
        TDESAlgorithm.Padding = PaddingMode.PKCS7;

        // Step 4. Convert the input string to a byte[]
        byte[] DataToEncrypt = UTF8.GetBytes(Message);

        // Step 5. Attempt to encrypt the string
        try
        {
            ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
            Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
        }
        finally
        {
            // Clear the TripleDes and Hashprovider services of any sensitive information
            TDESAlgorithm.Clear();
            HashProvider.Clear();
        }
        // Step 6. Return the encrypted string as a base64 encoded string
        return Convert.ToBase64String(Results);
    }

    public string DecryptString(string Message, string Passphrase)
    {
        byte[] Results;
        System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

        // Step 1. We hash the passphrase using MD5
        // We use the MD5 hash generator as the result is a 128 bit byte array
        // which is a valid length for the TripleDES encoder we use below

        MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
        byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));

        // Step 2. Create a new TripleDESCryptoServiceProvider object
        TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

        // Step 3. Setup the decoder
        TDESAlgorithm.Key = TDESKey;
        TDESAlgorithm.Mode = CipherMode.ECB;
        TDESAlgorithm.Padding = PaddingMode.PKCS7;

        // Step 4. Convert the input string to a byte[]
        byte[] DataToDecrypt = Convert.FromBase64String(Message);

        // Step 5. Attempt to decrypt the string
        try
        {
            ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
            Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
        }
        finally
        {
            // Clear the TripleDes and Hashprovider services of any sensitive information
            TDESAlgorithm.Clear();
            HashProvider.Clear();
        }

        // Step 6. Return the decrypted string in UTF8 format
        return UTF8.GetString(Results);
    }
    public System.Collections.Generic.List<clsCommon> CheckLoginAmbiguity(Int64 UserID, String QueryType)
    {

        SqlDataReader dr = null;
        System.Collections.Generic.List<clsCommon> lstLoginInfo = new System.Collections.Generic.List<clsCommon>();
        SqlParameter[] ParamList = new SqlParameter[2];
        ParamList[0] = new SqlParameter("@User_Id", UserID);
        ParamList[1] = new SqlParameter("@QueryType", QueryType);
        dr=SqlHelper.ExecuteReader(ConnStr, CommandType.StoredProcedure, "Proc_IE_LoginStatus", ParamList);
      
         while (dr.Read())
        {
            clsCommon objApp = new clsCommon();
            objApp.User_ID = dr["User_Id"].ToString();
            objApp.Token_No = dr["Token_No"].ToString();
            objApp.Login_Date = dr["Login_Date"].ToString();
            //objApp.Status = Convert.ToBoolean(dr["Status"].ToString());
            lstLoginInfo.Add(objApp);
        }
        return lstLoginInfo;
    }

    public System.Collections.Generic.List<clsCommon> CheckForLogout(Int64 UserID, string  TokenIdNo, String QueryType)
    {

        SqlDataReader dr = null;
        System.Collections.Generic.List<clsCommon> lstLoginInfo = new System.Collections.Generic.List<clsCommon>();
        SqlParameter[] ParamList = new SqlParameter[3];
        ParamList[0] = new SqlParameter("@User_Id", UserID);
        ParamList[1] = new SqlParameter("@Token_No", TokenIdNo);
        ParamList[2] = new SqlParameter("@QueryType", QueryType);
        dr = SqlHelper.ExecuteReader(ConnStr, CommandType.StoredProcedure, "Proc_IE_LoginStatus", ParamList);
        while (dr.Read())
        {
            clsCommon objApp = new clsCommon();
            objApp.User_ID = dr["User_Id"].ToString();
            objApp.Token_No = dr["Token_No"].ToString();
            objApp.Login_Date = dr["Login_Date"].ToString();
            //objApp.Status = Convert.ToBoolean(dr["Status"].ToString());
            lstLoginInfo.Add(objApp);
        }
        return lstLoginInfo;
    }

    public System.Collections.Generic.List<clsCommon> LoginCounter()
    {
        SqlDataReader dr = null;
        System.Collections.Generic.List<clsCommon> lstLoginInfo = new System.Collections.Generic.List<clsCommon>();
      
        SqlParameter[] ParamList = new SqlParameter[1];      
        ParamList[0] = new SqlParameter("@QueryType", "SlectCount");
        dr=SqlHelper.ExecuteReader(ConnStr, CommandType.StoredProcedure, "Proc_IE_LoginStatus", ParamList);
        while (dr.Read())
        {
            clsCommon objApp = new clsCommon();
            objApp.User_ID = dr["User_Id"].ToString();
            objApp.Token_No = dr["Token_No"].ToString();
            objApp.Login_Date = dr["Login_Date"].ToString();
            //objApp.Status = Convert.ToBoolean(dr["Status"].ToString());
            objApp.UserName =dr["UserName"].ToString();
           

            lstLoginInfo.Add(objApp);
        }
        return lstLoginInfo;
    }

    public void DeleteLogin(String TokenNo, String QueryType)
    {
        SqlParameter[] ParamList = new SqlParameter[2];
        ParamList[0] = new SqlParameter("@QueryType", QueryType);
        ParamList[1] = new SqlParameter("@Token_No", TokenNo);
        SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, "Proc_IE_LoginStatus", ParamList);
    }
    public void InsertLogin(Int64 UserID, String QueryType, String Token_No)
    {
        SqlParameter[] ParamList = new SqlParameter[3];
        ParamList[0] = new SqlParameter("@QueryType", QueryType);
        ParamList[1] = new SqlParameter("@User_Id", UserID);
        ParamList[2] = new SqlParameter("@Token_No", Token_No);
        SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, "Proc_IE_LoginStatus", ParamList);
    }

}