Wednesday, 11 May 2016

SqlDb 


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Configuration;


namespace SNSCT
{
    public class SqlDb 
    {
        public System.Collections.ArrayList fieldName = new System.Collections.ArrayList();
        public System.Collections.ArrayList fieldValue = new System.Collections.ArrayList();
        public int affectedRecords = 0;

        private SqlConnection con;
  
        private bool mbIsTransactionPending, mbIsDisposed;
        private SqlTransaction mtraCurrentTransaction;

        public SqlDb()
        {
            con = new SqlConnection();
           
            //undo_Comment_For_Testing_Jayesh_19_Dec_2013

            con.ConnectionString = "Data Source=P03\\SQLEXPRESS;Initial catalog = SNSCT;User Id=sa;Password=softex"; //ConfigurationManager.AppSettings["LocalConnectionString"].ToString();
           
        
            mtraCurrentTransaction = null;

            mbIsTransactionPending = false;
            mbIsDisposed = false;
        }

        #region ...DB Operations...

        /// <summary>
        /// Implements the IDispose' method Dispose.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }


        /// <summary>
        /// Implements the Dispose functionality.
        /// </summary>
        protected virtual void Dispose(bool bIsDisposing)
        {
            // Check to see if Dispose has already been called.
            if (!mbIsDisposed)
            {
                if (bIsDisposing)
                {
                    // Dispose managed resources.
                    if (mtraCurrentTransaction != null)
                    {
                        mtraCurrentTransaction.Dispose();
                        mtraCurrentTransaction = null;
                    }
                    if (con != null)
                    {
                        // closing the connection will abort (rollback) any pending transactions
                        con.Close();
                        con.Dispose();
                        con = null;
                    }
                }
            }
            mbIsDisposed = true;
        }

        /// <summary>
        /// Opens the connection object.
        /// </summary>
        /// <returns>True, if succeeded, otherwise an exception is thrown.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Cannot open a connection without specifying a data source or server.<br/>
        /// or<br/>
        /// The connection is already open.<br/>
        /// </exception>
        /// <exception cref="System.Data.SqlClient.SqlException">
        /// A connection-level error occurred while opening the connection.
        /// </exception>
        public bool OpenConnection()
        {
            try
            {
                if ((con.State & ConnectionState.Open) > 0)
                {
                    // it's already open.

                    throw new InvalidOperationException("Connection is already open.");
                }
                con.Open();
                mbIsTransactionPending = false;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble exception
                throw ex;
            }
        }
        public bool OpenConnection(string constring)
        {
            try
            {
                con.ConnectionString = constring;
                if ((con.State & ConnectionState.Open) > 0)
                {
                    // it's already open.

                    throw new InvalidOperationException("Connection is already open.");
                }
                con.Open();
                mbIsTransactionPending = false;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble exception
                throw ex;
            }
        }


        /// <summary>
        /// Starts a new ADO.NET transaction using the open connection object of this class.
        /// </summary>
        /// <returns>True, if transaction is started correctly, otherwise an exception is thrown.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Transaction is already pending.<br/>
        /// or<br/>
        /// Connection is not open.
        /// </exception>
        public bool BeginTransaction()
        {
            try
            {
                if (mbIsTransactionPending)
                {
                    // no nested transactions allowed.
                    throw new InvalidOperationException("Already transaction pending. Nesting not allowed");
                }
                if ((con.State & ConnectionState.Open) == 0)
                {
                    // no open connection
                    throw new InvalidOperationException("Connection is not open.");
                }
                // begin the transaction and store the transaction object.
                mtraCurrentTransaction = con.BeginTransaction();
                mbIsTransactionPending = true;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble error
                throw ex;
            }
        }

        /// <summary>
        /// Starts a new ADO.NET transaction using the open connection object of this class
        /// with the specified transaction locking behaviour.
        /// </summary>
        /// <param name="enuIso">Transaction locking behaviour for the connection.</param>
        /// <returns>True, if transaction is started correctly, otherwise an exception is thrown.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// Transaction is already pending.<br/>
        /// or<br/>
        /// Connection is not open.
        /// </exception>
        public bool BeginTransaction(IsolationLevel enuIso)
        {
            try
            {
                if (mbIsTransactionPending)
                {
                    // no nested transactions allowed.
                    throw new InvalidOperationException("Already transaction pending. Nesting not allowed");
                }
                if ((con.State & ConnectionState.Open) == 0)
                {
                    // no open connection
                    throw new InvalidOperationException("Connection is not open.");
                }
                // begin the transaction and store the transaction object.
                mtraCurrentTransaction = con.BeginTransaction(enuIso);
                mbIsTransactionPending = true;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble error
                throw ex;
            }
        }


        /// <summary>
        /// Commits a pending transaction on the open connection object of this class.
        /// </summary>
        /// <returns>True, if commit was succesful, or an exception is thrown.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// No transaction pending.<br/>
        /// or<br/>
        /// Connection is not open.
        /// </exception>
        /// <exception cref="System.Exception">
        /// An error occurred while trying to commit the transaction.
        /// </exception>
        public bool CommitTransaction()
        {
            try
            {
                if (!mbIsTransactionPending)
                {
                    // no transaction pending
                    throw new InvalidOperationException("No transaction pending.");
                }
                if ((con.State & ConnectionState.Open) == 0)
                {
                    // no open connection
                    throw new InvalidOperationException("Connection is not open.");
                }
                // commit the transaction
                mtraCurrentTransaction.Commit();
                mbIsTransactionPending = false;
                mtraCurrentTransaction.Dispose();
                mtraCurrentTransaction = null;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble error
                throw ex;
            }
        }


        /// <summary>
        /// Rolls back a pending transaction on the open connection object of this class.
        /// </summary>
        /// <returns>True, if rollback was succesful, or an exception is thrown.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// No transaction pending.<br/>
        /// or<br/>
        /// Connection is not open.
        /// </exception>
        /// <exception cref="System.Exception">
        /// An error occurred while trying to rollback the transaction.
        /// </exception>
        public bool RollbackTransaction()
        {
            try
            {
                if (!mbIsTransactionPending)
                {
                    // no transaction pending
                    throw new InvalidOperationException("No transaction pending.");
                }
                if ((con.State & ConnectionState.Open) == 0)
                {
                    // no open connection
                    throw new InvalidOperationException("Connection is not open.");
                }
                // rollback the transaction
                mtraCurrentTransaction.Rollback();

                mbIsTransactionPending = false;
                mtraCurrentTransaction.Dispose();
                mtraCurrentTransaction = null;
                return (true);
            }
            catch (Exception ex)
            {
                // bubble error
                throw ex;
            }
        }



        /// <summary>
        /// Closes the open connection. A pending transaction is aborted. 
        /// </summary>
        /// <returns>True, if close was succesful, False if connection was already closed, 
        /// or an exception is thrown when an error occurs</returns>
        /// <exception cref="System.Data.SqlClient.SqlException">
        /// A connection-level error occurred while closing the connection.
        /// </exception>
        public bool CloseConnection()
        {
            return (CloseConnection(false));
        }


        public SqlConnection getDBConnection()
        {
            return (con);
        }



        /// <summary>
        /// Closes the open connection. Depending on <i>bCommitPendingTransactions</i>, a pending
        /// transaction is commited, or aborted. 
        /// </summary>
        /// <param name="bCommitPendingTransaction">Flag for what to do when a transaction is still pending. 
        /// True will commit the current transaction, false will abort (rollback) the complete 
        /// current transaction.</param>
        /// <returns>True, if close was succesful, False if connection was already closed, or 
        /// an exception is thrown when an error occurs</returns>
        /// <exception cref="System.Data.SqlClient.SqlException">
        /// A connection-level error occurred while closing the connection.
        /// </exception>
        public bool CloseConnection(bool bCommitPendingTransaction)
        {
            try
            {
                if ((con.State & ConnectionState.Open) == 0)
                {
                    // no open connection
                    return (false);
                }
                if (mbIsTransactionPending)
                {
                    if (bCommitPendingTransaction)
                    {
                        // commit the pending transaction
                        mtraCurrentTransaction.Commit();
                    }
                    else
                    {
                        // rollback the pending transaction
                        mtraCurrentTransaction.Rollback();
                    }
                    mbIsTransactionPending = false;
                    mtraCurrentTransaction.Dispose();
                    mtraCurrentTransaction = null;
                }
                // close the connection
                con.Close();
                return (true);
            }
            catch (Exception ex)
            {
                // bubble error
                throw ex;
            }


        }

        #endregion

        #region Class Property Declarations
        /// <summary>
        /// Returns current transaction.
        /// </summary>
        public SqlTransaction CurrentTransaction
        {
            get
            {
                return (mtraCurrentTransaction);
            }
        }

        /// <summary>
        /// Returns a flag specifies whether transaction is pending.
        /// </summary>
        public bool IsTransactionPending
        {
            get
            {
                return (mbIsTransactionPending);
            }
        }

        /// <summary>
        /// Returns connection object.
        /// </summary>
        public IDbConnection DBConnection
        {
            get
            {
                return (con);
            }
        }
        /// <summary>
        /// Sets the connection string.
        /// </summary>
        public string ConnectionString
        {
            set
            {
                con.ConnectionString = value;
            }
            get
            {
                return con.ConnectionString;
            }
        }
        #endregion

        #region ...Methods...
       
        public void setCmbFill(System.Windows.Forms.ComboBox cmb, string Qry)
        {
            cmb.Items.Clear();
            DataTable dt = getTable(Qry);
            for (int r = 0; r < dt.Rows.Count; r++)
            {
                cmb.Items.Add(dt.Rows[r][0].ToString().Trim());
            }
            cmb.SelectedIndex = 0;
        }

        public void setListFill(System.Windows.Forms.ListBox lst, string Qry)
        {
            lst.Items.Clear();
            DataTable dt = getTable(Qry);
            for (int r = 0; r < dt.Rows.Count; r++)
            {
                lst.Items.Add(dt.Rows[r][0].ToString().Trim());
            }

        }

        //public void  SetColumnSortMode( DataGridView dataGridView, DataGridViewColumnSortMode sortMode)
        //{
            
        //}



        public DataTable getTable_(string Qry)
        {
            SqlDataAdapter ada = new SqlDataAdapter(Qry, con);
            DataTable dt = new DataTable();
            try
            {
                ada.Fill(dt);
            }
            catch (Exception ex) {  }
            return dt;
        }
       
        public DataTable getTable(string Qry)
        {
            SqlDataAdapter da = new SqlDataAdapter(Qry, con);
            DataSet ds = new DataSet();
            da.SelectCommand.Transaction = mtraCurrentTransaction;
            try
            {

                da.Fill(ds);
                ds.Tables.Add();
                return ds.Tables[0];
            }
            catch (System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message, "Connection error !!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                return null;
            }
            finally
            {

            }
        }

        public SqlDataReader getRow(string Qry)
        {
            //OpenConnection();
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand(Qry, con);
            myReader = myCommand.ExecuteReader();
            myCommand.Dispose();
            return myReader;

        }

        public string GetValue(string Qry)
        {
            string retStr = "";
            DataTable dt = new DataTable();
            dt = getTable(Qry);
            if (dt.Rows.Count > 0)
            {
                retStr = dt.Rows[0][0].ToString().Trim();
            }
            return retStr;

        }

        public int getColumnInt(string Qry)
        {
            int intColumn = 0;
            DataTable dt = getTable(Qry);
            if (dt.Rows.Count > 0)
            {
                intColumn = Convert.ToInt32(dt.Rows[0][0].ToString());
            }
            return intColumn;
        }

        public string getColumnString(string Qry)
        {
            string strColumn = "";
            DataTable dt = getTable(Qry);
            if (dt.Rows.Count > 0)
            {
                strColumn = dt.Rows[0][0].ToString().Trim();
            }
            return strColumn;
        }

        public double getColumnDouble(string Qry)
        {
            double dblColumn = 0;
            DataTable dt = getTable(Qry);
            if (dt.Rows.Count > 0)
            {
                dblColumn = Convert.ToDouble(dt.Rows[0][0].ToString());
            }
            return dblColumn;
        }

        public bool isConnectionOK()
        {
            SqlConnection Cnn;
            SqlDataAdapter da;
            DataSet ds;
            try
            {
                Cnn = new SqlConnection(con.ConnectionString);
                Cnn.Open();
                da = new SqlDataAdapter("select getDate()", Cnn);
                ds = new DataSet();
                da.Fill(ds);

                ds.Clear();
                da.Dispose();
                Cnn.Close();
                return true;
            }
            catch (System.Exception ee)
            {
                System.Windows.Forms.MessageBox.Show(ee.ToString());
            }
            finally
            {
            }
            return false;
        }

        public int Execute(string Qry)
        {
            SqlCommand cmd = new SqlCommand(Qry, con);
            cmd.Transaction = mtraCurrentTransaction;
            int r = cmd.ExecuteNonQuery();
            return r;
        }
        public int Execute_(string Qry)
        {
            int r = 0;
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(Qry, con);
                r = cmd.ExecuteNonQuery();
                con.Close();
                return r;
            }
            catch (Exception ex)
            {

            }
            return r;
        }

        public int Execute_Img(string Qry,byte[] img)
        {
            int r = 0;
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = Qry;
                cmd.Parameters.AddWithValue("@image", img);
                r = cmd.ExecuteNonQuery();
                con.Close();
                return r;
            }
            catch (Exception ex)
            {

            }
            return r;
        }
       
       
       
        public void setFieldDataClear()
        {
            fieldName.Clear();
            fieldValue.Clear();
        }

        public void setFieldData(string fName, DateTime fValue) { setFieldData(fName, fValue.ToString("yyyy-MM-dd HH:mm"), "'"); }
        public void setFieldData(string fName, int fValue) { setFieldData(fName, fValue.ToString(), ""); }
        public void setFieldData(string fName, bool fValue) { setFieldData(fName, fValue.ToString(), ""); }
        public void setFieldData(string fName, decimal fValue) { setFieldData(fName, fValue.ToString(), ""); }
        public void setFieldData(string fName, double fValue) { setFieldData(fName, fValue.ToString(), ""); }
        public void setFieldData(string fName, string fValue) { setFieldData(fName, fValue, "'"); }
        public void setFieldData(string fName, string fValue, string Sign)
        {
            fieldName.Add(fName);
            fieldValue.Add(Sign + fValue + Sign);
        }

        public int getInsert(string tableName)
        {
            string q1 = "";
            string q2 = "";
            foreach (string nam in fieldName)
            {
                if (q1 != "") q1 += ", ";
                q1 += nam;
            }
            foreach (string val in fieldValue)
            {
                if (q2 != "") q2 += ", ";
                q2 += val;
            }
            fieldName.Clear();
            fieldValue.Clear();
            return Execute("Insert into " + tableName + "(" + q1 + ") values(" + q2 + ")");
        }

        public int getUpdate(string tableName, string wherCondition)
        {
            string q = "";
            for (int n = 0; n < fieldName.Count; n++)
            {
                if (q != "") q += ", ";
                q += fieldName[n].ToString() + "=" + fieldValue[n].ToString();
            }
            fieldName.Clear();
            fieldValue.Clear();
            return Execute("Update " + tableName + " set " + q + " where " + wherCondition);
        }

        public string getTimeString(string Seconds)
        {
            int TimeSeconds = 0;
            try
            {
                TimeSeconds = int.Parse(Seconds);
            }
            catch { }
            return getTimeString(TimeSeconds);
        }

        public string getTimeString(int Seconds)
        {
            if (Seconds < (60 * 60))
            {
                return (Seconds / 60).ToString() + ":" + (Seconds % 60).ToString("00");
            }
            return TimeSpan.FromSeconds((double)Seconds).ToString();
        }

        public string getTitleCase(string txt)
        {
            try
            {
                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en");
                return ci.TextInfo.ToTitleCase(txt.Trim());
            }
            catch
            {
                return txt;
            }
        }

        public int getInt(object strValue)
        {
            if (strValue == null) return 0;
            try
            {
                return int.Parse(strValue.ToString());
            }
            catch { }
            return 0;
        }

        public double getDouble(object strValue)
        {

            if (strValue == null) return 0;
            try
            {
                return double.Parse(strValue.ToString());
            }
            catch { }
            return 0;
        }

        public string getSysDate()
        {
            string strQry = "SELECT CONVERT(VARCHAR(20), GETDATE(), 1)";
            string strSysDate = GetValue(strQry);
            return strSysDate;
        }
        public string getSysDate_NEW()
        {
            string strQry = "SELECT CONVERT(VARCHAR(20), GETDATE(), 103)";
            string strSysDate = GetValue(strQry);
            return strSysDate;
        }

        
        public string getSysDateOnly()
        {
            string strQry = "SELECT CONVERT(VARCHAR(20), GETDATE(), 101)";
            string strSysDate = GetValue(strQry);
            return strSysDate;
        }
        public string getSysDateTime()
        {
            string Query = " SELECT GETDATE() ";
            return GetValue(Query);
        }
        public string getBetweenString(DateTime dt1, DateTime dt2)
        {
            return string.Format("cast('{0} 00:00:00' as datetime) and cast('{1} 23:59:59' as datetime)"
                , dt1.ToString("yyyy-MM-dd"), dt2.ToString("yyyy-MM-dd"));
        }

        public string tableManipulation(string tableName, string command, string columnName, string dataType, int size)
        {
            return tableManipulation(tableName, command, columnName, dataType, size, "");
        }
        public string tableManipulation(string tableName, string command, string columnName, string dataType, int size, string defaltValue)
        {
            string QuerydataType = "";
            dataType = dataType.ToLower().Trim();
            command = command.ToLower().Trim();
            if (dataType == "varchar" || dataType == "char" || dataType == "nchar")
            {
                QuerydataType = dataType + " (" + size + ") ";
            }
            else
            {
                QuerydataType = dataType;
            }
            string strQuery = "alter table " + tableName + " ";
            if (command == "alter")
            {
                strQuery += command + " column " + columnName + " " + QuerydataType;
            }
            else if (command == "drop")
            {
                strQuery += command + " column " + columnName;
            }
            else if (command == "add")
            {
                strQuery += command + " " + columnName + " " + QuerydataType + " DEFAULT '0'";
            }
            affectedRecords = 0;
            try
            {
                affectedRecords = Execute(strQuery);
            }
            catch (Exception ee) { return "Error : \t" + ee.Message + ",\t Query - > " + strQuery; }

            strQuery = "update {0} set {1}={2} where {1} is null";
            if (dataType == "varchar" || dataType == "char" || dataType == "nchar")
            {
                Execute(String.Format(strQuery, tableName, columnName, "'" + defaltValue + "'"));
            }
            else if (dataType == "bit" || dataType == "int" || dataType == "money" || dataType == "decimal" || dataType == "numeric")
            {
                if (defaltValue == "") defaltValue = "0";
                Execute(String.Format(strQuery, tableName, columnName, defaltValue));
            }
            return strQuery;
        }
        #endregion

        /// <summary>
        /// Hashim
        /// </summary>



        public static void RestoreDatabase(string database_name, string path)
        { 
        
        }
        /// <summary>
        /// Hashim
        /// </summary>
        public int BulkCopy(DataTable dt, string DestinationTableName)
        {
            int updated = 0;
            try
            {
                SqlBulkCopy sbc = new SqlBulkCopy(con);
                sbc.DestinationTableName = DestinationTableName;
                sbc.WriteToServer(dt);
                updated = 1;
            }
            catch  { updated = 0; }
            return updated;
        }

        /// <summary>
        /// Hashim 01-12-2010
        /// </summary>
        public void WriteToConfigFile(string Key,string Value)
        {
            //System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
            //config.AppSettings.Settings[Key].Value = Value;

            //config.Save(ConfigurationSaveMode.Modified);
            //ConfigurationManager.RefreshSection("appSettings");
        }

        public void BackupDb()
        {
            if (!System.IO.Directory.Exists("C:\\Cube_DB_Backup"))
            System.IO.Directory.CreateDirectory("C:\\Cube_DB_Backup");

            SqlDb.BackUpDatabase("CubeHomeTrans", "C:\\Cube_DB_Backup\\"
            , "Backup_" + System.DateTime.Now.ToString() + "__" + "CubeHomeTrans");
                
                
        }
        public static void BackUpDatabase(string database_name, string path, string filename)
        {
            filename = filename.Replace("/", "_");
            filename = filename.Replace(":", "_");
            filename = filename.Replace(" ", "_");

            path += filename;
            string Query = " BACKUP DATABASE " + database_name + " TO  DISK = N'" + path + "' "
                            + " WITH NOFORMAT, INIT,  NAME = N'" + database_name + "-Full Database Backup' "
                            + " , SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
            SqlDb db = new SqlDb();
            db.Execute_(Query);
        }


    }
}

ClsUsers


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SNSCT
{
    class ClsUsers
    {
       public bool Login(string User, string Password)
        {
            DataTable Dt_Users = new DataTable();
            SqlDb Db = new SqlDb();
            StringBuilder str = new StringBuilder();
            str.Append("Select * from Users where User_Name='" + User + "' and Password='" + Password + "'");
            Dt_Users = Db.getTable_(str.ToString());
            if (Dt_Users.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}

ClsSubscriptionReport


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data .SqlClient;
using System.Data;

namespace SNSCT
{
    class ClsSubscriptionReport
    {
        SqlDb Db = new SqlDb();
        StringBuilder Str = new StringBuilder();
        DataTable Dt = new DataTable();


        public DataTable Get_Members()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberName from MonthlyPayment ");
            return Db.getTable_(Str.ToString());
        }
        public DataTable Get_Year()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            DataTable Dt = new DataTable();

            Str.Append("Select Year from MonthlyPayment GROUP BY year HAVING Count(*) >= 1 ");
            Dt = Db.getTable(Str.ToString());
            return Dt;
        }


        public DataTable Fill_MonthDetails(int month,int Year)
            {
                SqlDb Db = new SqlDb();
                StringBuilder Str = new StringBuilder();
                DataTable Dt = new DataTable();

                Str.Append("select  0 + ROW_NUMBER() OVER(ORDER BY M.MemberName) AS [SL No] ,Reg.RegNo,M.MemberName As Name, DateName( month , DateAdd( month , M.Month , -1 ) ) AS Month,M.Year,M.Amount  ");
                Str.Append(" from MonthlyPayment M inner join Registration Reg on M.MemberID=Reg.MemberID  ");
                Str.Append("where M.Month='" + month + "' and M.Year='"+Year+"'");
       
            Dt = Db.getTable(Str.ToString());
            return Dt;


        }
        public DataTable Fill_MemberDetails(string Name)
            {
                SqlDb Db = new SqlDb();
                StringBuilder Str = new StringBuilder();
                DataTable Dt = new DataTable();

                Str.Append("select  0 + ROW_NUMBER() OVER(ORDER BY M.MemberName) AS [SL No] ,Reg.RegNo,M.MemberName As Name, DateName( month , DateAdd( month , M.Month , -1 ) ) AS Month,M.Year,M.Amount  ");
                Str.Append(" from MonthlyPayment M inner join Registration Reg on M.MemberID=Reg.MemberID  ");
                Str.Append("where  M.MemberName='" + Name + "'");

                Dt = Db.getTable(Str.ToString());
                return Dt;

            }

        public DataTable Fill_Details(int month,int Year,string Name)
            {
                SqlDb Db = new SqlDb();
                StringBuilder Str = new StringBuilder();
                DataTable Dt = new DataTable();

                Str.Append("select  0 + ROW_NUMBER() OVER(ORDER BY M.MemberName) AS [SL No] ,Reg.RegNo,M.MemberName As Name, DateName( month , DateAdd( month , M.Month , -1 ) ) AS Month,M.Year,M.Amount  ");
                Str.Append(" from MonthlyPayment M inner join Registration Reg on M.MemberID=Reg.MemberID  ");
                Str.Append("where M.Month='" + month + "' and M.MemberName='" + Name + "' and M.Year='"+Year+"'");

                Dt = Db.getTable(Str.ToString());
                return Dt;

            }

    }
}

ClsRegistration


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace SNSCT
{
    class ClsRegistration
    {
        public byte[] arr_img { set; get; }
        public string Reg_no { set; get; }
        public string Name { set; get; }
        public DateTime DOB { set; get; }
        public DateTime DOJ { set; get; }
        public string BloodGroup { set; get; }
        public string Father { set; get; }
        public DateTime FatherDOB { set; get; }
        public string FatherBloodGroup { set; get; }
        public string Wife { set; get; }
        public DateTime WifeDOB { set; get; }
        public string WifeBloodGroup { set; get; }
        public string HouseName { set; get; }
        public string HouseNo { set; get; }
        public string street { set; get; }
        public string City { set; get; }
        public string District { set; get; }
        public string State { set; get; }
        public string Occupation { set; get; }
        public string Office { set; get; }
        public string OfficeBuilding { set; get; }
        public string OfficeStreet { set; get; }
        public string OfficeCity { set; get; }
        public string OfficeDistrict { set; get; }
        public string OfficeState { set; get; }
        public string OfficeCountry { set; get; }
        public string WifeOccupation { set; get; }
        public string WifeOffice { set; get; }
        public string WifeOfficeBuilding { set; get; }
        public string WifeOfficeStreet { set; get; }
        public string WifeOfficeCity { set; get; }
        public string WifeOfficeDistrict { set; get; }
        public string WifeOfficeState { set; get; }
        public string WifeOfficeCountry { set; get; }
        public string Mobile { set; get; }
        public string Landline { set; get; }
        public string Phone_Office { set; get; }
        public string Email { set; get; }
        public string Child1 { set; get; }
        public string Child1_Details { set; get; }
        public DateTime Child1_DOB { set; get; }
        public string Child1_BloodGroup { set; get; }
        public string Child2 { set; get; }
        public string Child2_Details { set; get; }
        public DateTime Child2_DOB { set; get; }
        public string Child2_BloodGroup { set; get; }
        public string Child3 { set; get; }
        public string Child3_Details { set; get; }
        public DateTime Child3_DOB { set; get; }
        public string Child3_BloodGroup { set; get; }
        public string Child4 { set; get; }
        public string Child4_Details { set; get; }
        public DateTime Child4_DOB { set; get; }
        public string Child4_BloodGroup { set; get; }
        public int Alert_Sms { set; get; }
        public int Alert_VoiceCall { set; get; }
        public int Alert_Email { set; get; }


        public int RegNo_present()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select * from Registration where  RegNo=" + Reg_no + "");
            DataTable Dt_temp = new DataTable();
            Dt_temp = Db.getTable_(Str.ToString());
            if (Dt_temp.Rows.Count > 0)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }

        public int Update_reg(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();

            Str.Append("Select * from Registration where  RegNo=" + Reg_no + " and MemberID<>" + ID + " ");
            DataTable Dt_temp = new DataTable();
            Dt_temp = Db.getTable_(Str.ToString());
            if (Dt_temp.Rows.Count > 0)
            {
                return 2;
            }
            else
            {

            Str.Remove(0, Str.Length);
            Str.Append("Update Registration set ");
            Str.Append("Name='" + Name + "',");
            Str.Append("JoinDate='" + DOJ + "',");
            Str.Append("Image=@image,");
            Str.Append("DOB='" + DOB + "',");
            Str.Append("BloodGroup='" + BloodGroup + "',");
            Str.Append("Father='" + Father + "',");
            Str.Append("FatherDOB='" + FatherDOB + "',");
            Str.Append("FatherBloodGroup='" + FatherBloodGroup + "',");
            Str.Append("Wife='" + Wife + "',");
            Str.Append("WifeDOB='" + WifeDOB + "',");
            Str.Append("WifeBloodGroup='" + WifeBloodGroup + "',");
            Str.Append("HouseName='" + HouseName + "',");
            Str.Append("HouseNo='" + HouseNo + "',");
            Str.Append("street='" + street + "',");
            Str.Append("City='" + City + "',");
            Str.Append("District='" + District + "',");
            Str.Append("State='" + State + "',");
            Str.Append("Occupation='" + Occupation + "',");
            Str.Append("Office='" + Office + "',");
            Str.Append("OfficeBuilding='" + OfficeBuilding + "',");
            Str.Append("OfficeStreet='" + OfficeStreet + "',");
            Str.Append("OfficeCity='" + OfficeCity + "',");
            Str.Append("OfficeDistrict='" + OfficeDistrict + "',");
            Str.Append("OfficeState='" + OfficeState + "',");
            Str.Append("OfficeCountry='" + OfficeCountry + "',");
            Str.Append("WifeOccupation='" + WifeOccupation + "',");
            Str.Append("WifeOffice='" + WifeOffice + "',");
            Str.Append("WifeOfficeBuilding='" + WifeOfficeBuilding + "',");
            Str.Append("WifeOfficeStreet='" + WifeOfficeStreet + "',");
            Str.Append("WifeOfficeCity='" + WifeOfficeCity + "',");
            Str.Append("WifeOfficeDistrict='" + WifeOfficeDistrict + "',");
            Str.Append("WifeOfficeState='" + WifeOfficeState + "',");
            Str.Append("WifeOfficeCountry='" + WifeOfficeCountry + "',");
            Str.Append("Mobile='" + Mobile + "',");
            Str.Append("Landline='" + Landline + "',");
            Str.Append("Phone_Office='" + Phone_Office + "',");
            Str.Append("Email='" + Email + "',");
            Str.Append("Child1='" + Child1 + "',");
            Str.Append("Child1_Details='" + Child1_Details + "',");
            Str.Append("Child1_DOB='" + Child1_DOB + "',");
            Str.Append("Child1_BloodGroup='" + Child1_BloodGroup + "',");
            Str.Append("Child2='" + Child2 + "',");
            Str.Append("Child2_Details='" + Child2_Details + "',");
            Str.Append("Child2_DOB='" + Child2_DOB + "',");
            Str.Append("Child2_BloodGroup='" + Child2_BloodGroup + "',");
            Str.Append("Child3='" + Child3 + "',");
            Str.Append("Child3_Details='" + Child3_Details + "',");
            Str.Append("Child3_DOB='" + Child3_DOB + "',");
            Str.Append("Child3_BloodGroup='" + Child3_BloodGroup + "',");
            Str.Append("Child4='" + Child4 + "',");
            Str.Append("Child4_Details='" + Child4_Details + "',");
            Str.Append("Child4_DOB='" + Child4_DOB + "',");
            Str.Append("Child4_BloodGroup='" + Child4_BloodGroup + "',");
            Str.Append("AlertSMS=" + Alert_Sms + ",");
            Str.Append("AlertvoiceCall=" + Alert_VoiceCall + ",");
            Str.Append("AlertEmail=" + Alert_Email + "");
            Str.Append(" where MemberID=" + ID + "");
            Db.Execute_Img(Str.ToString(), arr_img);
            return 1;
            }
        }

        public void Delete_Reg(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Delete from Registration where MemberID = " + ID + "");
            Db.Execute_(Str.ToString());
        }

        public DataTable Get_by_Name()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberID,Name from Registration order by Name");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_Member(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select * from Registration where MemberID=" + ID + "");
            return Db.getTable_(Str.ToString());
        }


        public DataTable Get_by_Reg()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberID,RegNo from Registration ");
            return Db.getTable_(Str.ToString());

        }
        public void insert_reg()
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Insert into Registration(RegNo,JoinDate,Image,Name,DOB,BloodGroup,Father,");
            Str.Append("FatherDOB,FatherBloodGroup,Wife,WifeDOB,");
            Str.Append("WifeBloodGroup,HouseName,HouseNo,street,");
            Str.Append("City,District,State,Occupation,");
            Str.Append("Office,OfficeBuilding,OfficeStreet,OfficeCity,");
            Str.Append("OfficeDistrict,OfficeState,OfficeCountry,WifeOccupation,");
            Str.Append("WifeOffice,WifeOfficeBuilding,WifeOfficeStreet,WifeOfficeCity,");
            Str.Append("WifeOfficeDistrict,WifeOfficeState,WifeOfficeCountry,Mobile,");
            Str.Append("Landline,Phone_Office,Email,Child1,Child1_Details,");
            Str.Append("Child1_DOB,Child1_BloodGroup,Child2,Child2_Details,");
            Str.Append("Child2_DOB,Child2_BloodGroup,Child3,Child3_Details,");
            Str.Append("Child3_DOB,Child3_BloodGroup,Child4,Child4_Details,");
            Str.Append("Child4_DOB,Child4_BloodGroup,AlertSMS,AlertvoiceCall,AlertEmail) values");
            Str.Append("('" + Reg_no + "','"+DOJ+"',@image,'" + Name + "','" + DOB + "','" + BloodGroup + "','" + Father + "',");
            Str.Append("'" + FatherDOB + "','" + FatherBloodGroup + "','" + Wife + "','" + WifeDOB + "',");
            Str.Append("'" + WifeBloodGroup + "','" + HouseName + "','" + HouseNo + "','" + street + "',");
            Str.Append("'" + City + "','" + District + "','" + State + "','" + Occupation + "',");
            Str.Append("'" + Office + "','" + OfficeBuilding + "','" + OfficeStreet + "','" + OfficeCity + "',");
            Str.Append("'" + OfficeDistrict + "','" + OfficeState + "','" + OfficeCountry + "','" + WifeOccupation + "',");
            Str.Append("'" + WifeOffice + "','" + WifeOfficeBuilding + "','" + WifeOfficeStreet + "','" + WifeOfficeCity + "',");
            Str.Append("'" + WifeOfficeDistrict + "','" + WifeOfficeState + "','" + WifeOfficeCountry + "','" + Mobile + "',");
            Str.Append("'" + Landline + "','" + Phone_Office + "','"+Email+"','" + Child1 + "','" + Child1_Details + "',");
            Str.Append("'" + Child1_DOB + "','" + Child1_BloodGroup + "','" + Child2 + "','" + Child2_Details + "',");
            Str.Append("'" + Child2_DOB + "','" + Child2_BloodGroup + "','" + Child3 + "','" + Child3_Details + "',");
            Str.Append("'" + Child3_DOB + "','" + Child3_BloodGroup + "','" + Child4 + "','" + Child4_Details + "',");
            Str.Append("'" + Child4_DOB + "','" + Child4_BloodGroup + "',"+Alert_Sms+","+Alert_VoiceCall+","+Alert_Email+")");
            Db.Execute_Img(Str.ToString(),arr_img);
        }



    }
}

ClsReceipt


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SNSCT
{
    class ClsReceipt
    {
        public int Voucher_No { set; get; }
        public int Receipt_No { set; get; }
        public int Member_ID { set; get; }
        public int Member_Type { set; get; }
        public string Member_Name { set; get; }
        public DateTime Date { set; get; }
        public int Acc_Head { set; get; }
        public decimal  Amount { set; get; }
        public string Narration { set; get; }
     

        public DataTable Get_ReceiptHeads()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select AccountHeadID,AccountHead from Account_Head where Type=1");
            return Db.getTable_(Str.ToString());
        }
        public decimal Get_Amount(int ID,int Type)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select AMOUNT from Account_Head where Type=" + Type + " and AccountHeadID=" + ID + "");
            DataTable Dt = new DataTable();
            Dt=Db.getTable_(Str.ToString());
            if (Dt.Rows.Count > 0)
            {
                return Dt.Rows[0][0].ToDecimal();
            }
            else
            {
                return 0;
            }
           
        }

        public DataTable Get_PaymentHeads()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select AccountHeadID,AccountHead from Account_Head where Type=0");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_by_Name()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberID,Name from Registration Order by Name ");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_by_Name_Acc_Members()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select UserID,Name from AccountMembers Order by Name");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_Details(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select RegNo,Mobile,HouseName+ CHAR(13) + CHAR(10)+HouseNo+CHAR(13) +CHAR(10)+ ");
            Str.Append("street+CHAR(13) + CHAR(10)+City+CHAR(13) + CHAR(10)+District+ ");
            Str.Append("CHAR(13) + CHAR(10)+State[Address],Image from Registration where MemberID="+ID+"");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_Details_AccountMambers(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select RegNo,Mobile,HouseName+ CHAR(13) + CHAR(10)+HouseNo+CHAR(13) +CHAR(10)+ ");
            Str.Append("street+CHAR(13) + CHAR(10)+City+CHAR(13) + CHAR(10)+District+ ");
            Str.Append("CHAR(13) + CHAR(10)+State[Address] from AccountMembers where UserID=" + ID + "");
            return Db.getTable_(Str.ToString());
        }


        public int get_ID(string REG_NO)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberID from Registration where RegNo='" + REG_NO + "'");
            return Db.GetValue(Str.ToString()).ToInt() ;


        }

        public DataTable Get_Pervious_Rec(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select top 10 R.ReceiptNo,R.ReceiptDate,A.AccountHead,R.Amount,R.Narration ");
            Str.Append("from Receipt R inner join Account_Head A on R.AccountHeadID=A.AccountHeadID ");
            Str.Append("Where R.MemberID=" + ID + " and R.Status=0 order by R.ReceiptDate");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_Row(int Rec_NO)
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select  RE.Name[Name],R.ReceiptNo[Receipt No],convert(varchar,R.ReceiptDate,106)[Date],A.AccountHead[Account Head],R.Amount,R.Narration ");
            Str.Append("from Receipt R inner join Account_Head A on R.AccountHeadID=A.AccountHeadID ");
            Str.Append("inner join Registration RE on R.MemberID=RE.MemberID Where R.ReceiptNo=" + Rec_NO + " and R.Status=0 ");
            return Db.getTable_(Str.ToString());

        }

        public DataTable Get_Row_Pay(int Voucher_No)
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select  RE.Name[Name],P.VoucherNo[Voucher No],convert(varchar,P.PaymentDate,106)[Date],A.AccountHead[Account Head],P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Account_Head A on P.AccountHeadID=A.AccountHeadID ");
            Str.Append("inner join Registration RE on P.MemberID=RE.MemberID Where P.VoucherNo=" + Voucher_No + " and P.Status=0 ");
            return Db.getTable_(Str.ToString());

        }
        public DataTable Get_Row_Pay_acc(int Voucher_No)
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select  RE.Name[Name],P.VoucherNo[Voucher No],convert(varchar,P.PaymentDate,106)[Date],A.AccountHead[Account Head],P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Account_Head A on P.AccountHeadID=A.AccountHeadID ");
            Str.Append("inner join AccountMembers RE on P.MemberID=RE.UserID Where P.VoucherNo=" + Voucher_No + " and P.Status=0 ");
            return Db.getTable_(Str.ToString());

        }
        public DataTable Get_Row_Pay_othr(int Voucher_No)
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select  P.MemberName[Name],P.VoucherNo[Voucher No],convert(varchar,P.PaymentDate,106)[Date],A.AccountHead[Account Head],P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Account_Head A on P.AccountHeadID=A.AccountHeadID ");
            Str.Append("Where P.VoucherNo=" + Voucher_No + " and P.Status=0 ");
            return Db.getTable_(Str.ToString());

        }

        public int Get_Paytype(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select MemberType from Payment where VoucherNo="+ID+"");
            DataTable dt = new DataTable();
            dt = Db.getTable_(Str.ToString());
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0][0].ToInt();
            }
            else
            {
                return 4;
            }
        }


        public DataTable Get_Pervious_Pay(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select top 10 P.VoucherNo,P.PaymentDate,A.AccountHead,P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Account_Head A on P.AccountHeadID=A.AccountHeadID ");
            Str.Append("Where P.MemberID=" + ID + " and MemberType="+ClsConst.Reg_Member+" and P.Status=0 order by P.PaymentDate");
            return Db.getTable_(Str.ToString());
        }

        public DataTable Get_Pervious_Pay_NonMembers(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select top 10 P.VoucherNo,P.PaymentDate,A.AccountHead,P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Account_Head A on P.AccountHeadID=A.AccountHeadID ");
            Str.Append("Where P.MemberID=" + ID + " and MemberType=" + ClsConst.Acc_Member + " and P.Status=0 order by P.PaymentDate");
            return Db.getTable_(Str.ToString());
        }

        public int Get_Next_ID()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select Max(ReceiptNo) from Receipt ");
            DataTable Dt = new DataTable();
            Dt=Db.getTable_(Str.ToString());
            if (Dt.Rows.Count > 0)
            {
                return Dt.Rows[0][0].ToInt() + 1;
            }
            else
            {
                return 1;
            }

        }

        public int Get_Next_ID_Payment()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select Max(VoucherNo) from Payment ");
            DataTable Dt = new DataTable();
            Dt = Db.getTable_(Str.ToString());
            if (Dt.Rows.Count > 0)
            {
                return Dt.Rows[0][0].ToInt() + 1;
            }
            else
            {
                return 1;
            }

        }
        //public DataTable Get_Pervious_Pay(int ID)
        //{
        //    SqlDb Db = new SqlDb();
        //    StringBuilder Str = new StringBuilder();
        //    Str.Append("Select P.ID,P.Payment_No,P.Date,A.ACCOUNT_HEAD,P.Amount,P.Narration ");
        //    Str.Append("from Payment P inner join Account_Head A on P.Payment_Head=A.ID ");
        //    Str.Append("Where P.Member_ID=" + ID + " and P.Status=0");
        //    return Db.getTable_(Str.ToString());
        //}

        public void insert_Receipt()
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Insert into Receipt(ReceiptNo,MemberID,ReceiptDate,AccountHeadID,Amount,Narration,Status,UserID) values");
            Str.Append("("+Receipt_No+"," + Member_ID + ",'"+Date+"',"+Acc_Head+","+Amount+",'"+Narration+"',0,"+ClsConst.User_ID+")");
            Db.Execute_(Str.ToString());
        }
        public void insert_Payment()
        {

            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Insert into Payment(VoucherNo,MemberID,MemberType,MemberName,PaymentDate,AccountHeadID,Amount,Narration,Status,UserID) values");
            Str.Append("(" + Voucher_No + "," + Member_ID + "," + Member_Type + ",'" + Member_Name + "','" + Date + "'," + Acc_Head + "," + Amount + ",'" + Narration + "',0," + ClsConst.User_ID + ")");
            Db.Execute_(Str.ToString());
        }


        public DataTable Get_todays_Receipts()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            string Str_Dt = Db.getBetweenString(DateTime.Now, DateTime.Now);
            Str.Append("Select R.ReceiptID,R.ReceiptNo,REG.Name,R.ReceiptDate[Date],A.AccountHead[Account Head],R.Amount,R.Narration ");
            Str.Append("from Receipt R inner join Registration REG on R.MemberID=REG.MemberID inner join ");
            Str.Append("Account_Head A on R.AccountHeadID=A.AccountHeadID where R.Status=0 and R.ReceiptDate between " + Str_Dt);
            return Db.getTable_(Str.ToString());
        }
        public DataTable Get_todays_Payments_old()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            string Str_Dt = Db.getBetweenString(DateTime.Now, DateTime.Now);
            Str.Append("Select P.VoucherNo,REG.Name,P.PaymentDate[Date],A.AccountHead[Account Head],P.Amount,P.Narration ");
            Str.Append("from Payment P inner join Registration REG on P.MemberID=REG.MemberID inner join ");
            Str.Append("Account_Head A on P.AccountHeadID=A.AccountHeadID where P.Status=0 and P.PaymentDate between " + Str_Dt);
            return Db.getTable_(Str.ToString());
        }
       
         public DataTable Get_todays_Payments()
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            string Str_Dt = Db.getBetweenString(DateTime.Now, DateTime.Now);
            Str.Append("Select P.PaymentID,P.VoucherNo[VoucherNo],T.Name[Name],T.ID[ID],P.MemberType[MemberType],P.PaymentDate[PaymentDate],A.AccountHead[AccountHead],P.Amount,P.Narration from Payment P ");
            Str.Append("inner join (Select UserID[ID],Name,2[Type] from AccountMembers union Select MemberID[ID],Name,1[Type] from Registration) T ");
            Str.Append("on P.MemberID=T.ID and P.MemberType=T.Type inner join Account_Head A on P.AccountHeadID=A.AccountHeadID where P.Status=0 and P.PaymentDate between " +Str_Dt);
            Str.Append(" union ");
            Str.Append("Select P.PaymentID,P.VoucherNo,P.MemberName[Name],0[ID],P.MemberType,P.PaymentDate,A.AccountHead,P.Amount,P.Narration from Payment P ");
            Str.Append("inner join  Account_Head A on P.AccountHeadID=A.AccountHeadID where P.MemberType=0 and  P.Status=0 and P.PaymentDate between " + Str_Dt);
            return Db.getTable_(Str.ToString());
        }


         public int Receipt_no_present()
         {
             SqlDb Db = new SqlDb();
             StringBuilder Str = new StringBuilder();
             Str.Append("Select * from Receipt where  ReceiptNo=" + Receipt_No + "");
             DataTable Dt_temp = new DataTable();
             Dt_temp = Db.getTable_(Str.ToString());
             if (Dt_temp.Rows.Count > 0)
             {
                 return 0;
             }
             else
             {
                 return 1;
             }
         }

         public int Payment_no_present()
         {
             SqlDb Db = new SqlDb();
             StringBuilder Str = new StringBuilder();
             Str.Append("Select * from Payment where  VoucherNo=" + Voucher_No + "");
             DataTable Dt_temp = new DataTable();
             Dt_temp = Db.getTable_(Str.ToString());
             if (Dt_temp.Rows.Count > 0)
             {
                 return 0;
             }
             else
             {
                 return 1;
             }
         }

        public int Edit_Receipt(int ID)
        {


            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("Select * from Receipt where ReceiptID=" + ID + " and ReceiptNo<>" + Receipt_No + "");
            DataTable Dt_temp = new DataTable();
            Dt_temp = Db.getTable_(Str.ToString());
            if (Dt_temp.Rows.Count > 0)
            {
                return 2;
            }
            else
            {
                Str.Remove(0, Str.Length);
                Str.Append("update Receipt set ");
                Str.Append("ReceiptNo='" + Receipt_No + "',");
                Str.Append("MemberID=" + Member_ID + ",");
                Str.Append("ReceiptDate='" + Date + "', ");
                Str.Append("AccountHeadID=" + Acc_Head + ",");
                Str.Append("Amount=" + Amount + ",");
                Str.Append("UserID=" + ClsConst.User_ID + ",");
                Str.Append("Narration='" + Narration + "' where ReceiptID=" + ID + " ");
                Db.Execute_(Str.ToString());
                return 1;
            }
        }

        public int  Edit_Payement(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();

            Str.Append("Select * from Payment where PaymentID=" + ID + " and VoucherNo<>" + Voucher_No + "");
            DataTable Dt_temp = new DataTable();
            Dt_temp = Db.getTable_(Str.ToString());
            if (Dt_temp.Rows.Count > 0)
            {
                return 2;
            }
            else
            {
                Str.Remove(0, Str.Length);
                Str.Append("update Payment set ");
                Str.Append("VoucherNo='" + Voucher_No + "',");
                Str.Append("MemberID=" + Member_ID + ",");
                Str.Append("MemberType=" + Member_Type + ",");
                Str.Append("MemberName='" + Member_Name + "',");
                Str.Append("PaymentDate='" + Date + "', ");
                Str.Append("AccountHeadID=" + Acc_Head + ",");
                Str.Append("Amount=" + Amount + ",");
                Str.Append("UserID=" + ClsConst.User_ID + ",");
                Str.Append("Narration='" + Narration + "' where PaymentID=" + ID + " ");
                Db.Execute_(Str.ToString());
                return 1;
            }
        }


        public void Delete_Receipt(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("update Receipt set status=1 where ReceiptID=" + ID + " ");
            Db.Execute_(Str.ToString());
        }
        public void Delete_Payment(int ID)
        {
            SqlDb Db = new SqlDb();
            StringBuilder Str = new StringBuilder();
            Str.Append("update payment set status=1 where VoucherNo=" + ID + " ");
            Db.Execute_(Str.ToString());
        }

    }
}