public List <CashMovement> GetCashMovements()
        {
            //...Create New Instance of Object...
            List <CashMovement> list = new List <CashMovement>();
            CashMovement        ins;

            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection      con    = dbConn.SqlConn();
            SqlCommand         cmdI;

            //...SQL Commands...
            cmdI = new SqlCommand("SELECT cm.*, mu.MoneyUnit, mt.MovementType, (e.Name + ' ' + e.Surname) as Employee "
                                  + " FROM t_CashMovement cm INNER JOIN l_MoneyUnit mu on cm.MoneyUnitID = mu.MoneyUnitID "
                                  + " INNER JOIN l_MovementType mt ON cm.MovementTypeID = mt.MovementTypeID "
                                  + " INNER JOIN Employee e on cm.EmployeeID = e.EmployeeID "
                                  + " WHERE cm.Removed = 0", con);

            cmdI.Connection.Open();
            SqlDataReader drI = cmdI.ExecuteReader();

            //...Retrieve Data...
            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins                = new CashMovement();
                    ins.ActualDate     = Convert.ToDateTime(drI["ActualDate"]);
                    ins.Amount         = Convert.ToDecimal(drI["Amount"]);
                    ins.CashMovementID = Convert.ToInt32(drI["CashMovementID"]);
                    ins.employee       = drI["Employee"].ToString();
                    ins.EmployeeID     = Convert.ToInt32(drI["EmployeeID"]);
                    ins.ModifiedDate   = Convert.ToDateTime(drI["ModifiedDate"]);
                    ins.moneyunit      = drI["MoneyUnit"].ToString();
                    ins.MoneyUnitID    = Convert.ToInt32(drI["MoneyUnitID"]);
                    ins.movementtype   = drI["MovementType"].ToString();
                    ins.MovementTypeID = Convert.ToInt32(drI["MovementTypeID"]);
                    ins.ModifiedBy     = drI["ModifiedBy"].ToString();
                    ins.Count          = (int)(ins.Amount / murep.GetMoneyUnitValue(ins.MoneyUnitID));
                    list.Add(ins);
                }
            }

            //...Close Connections...
            drI.Close();
            con.Close();


            //...Return...
            return(list);
        }
        public CashOffice Insert(CashOffice ins)
        {
            //...Get User and Date Data...
            string              ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now);
            string              UserID       = HttpContext.Current.Session["Username"].ToString();
            string              strTrx       = "CashoffIns_" + UserID;
            DropDownRepository  ddrep        = new DropDownRepository();
            MoneyUnitRepository mRep         = new MoneyUnitRepository();
            decimal             moneyunit    = mRep.GetMoneyUnitValue(ins.MoneyUnitTypeID);
            string              cashstatus   = ddrep.GetCashOfficeStatus(ins.CashStatus);

            if (cashstatus == "Sealed")
            {
                ins.Amount = ins.Amount;
            }
            else if (cashstatus == "Opened")
            {
                ins.Amount = ins.Amount * moneyunit;
            }
            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection      con    = dbConn.SqlConn();

            con.Open();

            //...Command Interface...
            SqlCommand     cmdI = con.CreateCommand();
            SqlTransaction trx;

            trx              = con.BeginTransaction(strTrx);
            cmdI.Connection  = con;
            cmdI.Transaction = trx;

            try
            {
                //...Insert Record...
                cmdI.CommandText = StoredProcedures.CashOfficeInsert;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@CashOfficeTypeID", ins.CashOfficeTypeID);
                cmdI.Parameters.AddWithValue("@MoneyUnitTypeID", ins.MoneyUnitTypeID);
                cmdI.Parameters.AddWithValue("@Amount", ins.Amount);
                cmdI.Parameters.AddWithValue("@CashStatus", ins.CashStatus);
                cmdI.Parameters.AddWithValue("@ModifiedBy", UserID);
                cmdI.Parameters.AddWithValue("@ModifiedDate", ModifiedDate);
                cmdI.Parameters.AddWithValue("@ActualDate", ins.ActualDate);
                cmdI.Parameters.AddWithValue("@Removed", 0);
                cmdI.Parameters.AddWithValue("@CompanyID", ins.CompanyID);


                //...Return new ID
                ins.CashOfficeID = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null)
                {
                    trx.Rollback();
                }
            }
            finally
            {
                //Check for close and respond accordingly
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
                //Clean up
                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }
            return(ins);
        }
        public CashOffice Insert(CashOffice ins)
        {
            //...Get User and Date Data...
            string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now);
            string UserID = HttpContext.Current.Session["Username"].ToString();
            string strTrx = "CashoffIns_" + UserID;
            DropDownRepository ddrep = new DropDownRepository();
            MoneyUnitRepository mRep = new MoneyUnitRepository();
            decimal moneyunit = mRep.GetMoneyUnitValue(ins.MoneyUnitTypeID);
            string cashstatus = ddrep.GetCashOfficeStatus(ins.CashStatus);
            if(cashstatus == "Sealed")
            {
                ins.Amount = ins.Amount;
            }
            else if (cashstatus == "Opened")
            {
                ins.Amount = ins.Amount * moneyunit;
            }
            //...Database Connection...
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();

            //...Command Interface...
            SqlCommand cmdI = con.CreateCommand();
            SqlTransaction trx;
            trx = con.BeginTransaction(strTrx);
            cmdI.Connection = con;
            cmdI.Transaction = trx;

            try
            {
                //...Insert Record...
                cmdI.CommandText = StoredProcedures.CashOfficeInsert;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@CashOfficeTypeID", ins.CashOfficeTypeID);
                cmdI.Parameters.AddWithValue("@MoneyUnitTypeID", ins.MoneyUnitTypeID);
                cmdI.Parameters.AddWithValue("@Amount", ins.Amount);
                cmdI.Parameters.AddWithValue("@CashStatus" , ins.CashStatus);
                cmdI.Parameters.AddWithValue("@ModifiedBy", UserID);
                cmdI.Parameters.AddWithValue("@ModifiedDate" , ModifiedDate);
                cmdI.Parameters.AddWithValue("@ActualDate", ins.ActualDate);
                cmdI.Parameters.AddWithValue("@Removed", 0);
                cmdI.Parameters.AddWithValue("@CompanyID", ins.CompanyID);

                //...Return new ID
                ins.CashOfficeID = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null) trx.Rollback();
            }
            finally
            {
                //Check for close and respond accordingly
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
                //Clean up
                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }
            return ins;
        }