private void DeletingAnItem(long ExpDetailID)
    {
        PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster DExp   = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();
        PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand     CashIn = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
        DataTable dtExpDetail = new DataTable();

        dtExpDetail = DExp.GetDailyExpDetailByID(ExpDetailID);
        if (dtExpDetail.Rows.Count > 0)
        {
            txtItemDesc.Text           = dtExpDetail.Rows[0]["ItemDesc"].ToString();
            txtItemDescID.Text         = dtExpDetail.Rows[0]["ID"].ToString();
            txtQuantity.Text           = dtExpDetail.Rows[0]["Quantity"].ToString();
            txtUnitPrice.Text          = dtExpDetail.Rows[0]["UnitPrice"].ToString();
            txtItemAmount.Text         = dtExpDetail.Rows[0]["ItemAmount"].ToString();
            txtItemAmountPrevious.Text = dtExpDetail.Rows[0]["ItemAmount"].ToString();

            long newamount = Convert.ToInt32(lblRemainingCash.Text.ToString().Trim()) + Convert.ToInt32(txtItemAmount.Text);

            if (newamount < 0)
            {
                lblErrorMessage.Text = "Out of money Error, Please add some cash in Hand first.";
            }
            else
            {
                lblRemainingCash.Text = newamount.ToString();
                //DExp.InsertDailyExpDetail(Convert.ToInt32(txtDailyExpMasterID.Text), txtItemDesc.Text, Convert.ToInt32(txtQuantity.Text), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtItemAmount.Text));
                //PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand CashIn = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
                CashIn.UpdateCashInHandCashAvail(Convert.ToInt32(txtCashInHandID.Text), Convert.ToInt32(lblRemainingCash.Text));

                DataTable dtUpAmount = new DataTable();
                dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                if (dtUpAmount.Rows.Count > 0)
                {
                    long startCash   = Convert.ToInt32(dtUpAmount.Rows[0]["StartCash"].ToString());
                    long TotalAmount = Convert.ToInt32(dtUpAmount.Rows[0]["TotalAmount"].ToString()) - Convert.ToInt32(txtItemAmount.Text);
                    //lblTotalAmount.Text = TotalAmount.ToString();
                    long endCash = startCash - TotalAmount;
                    DExp.UpdateDailyExpMasterTotalAmount(Convert.ToInt32(txtDailyExpMasterID.Text), endCash, TotalAmount);

                    dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                    if (dtUpAmount.Rows.Count > 0)
                    {
                        lblTotalAmount.Text = dtUpAmount.Rows[0]["TotalAmount"].ToString();
                    }
                }

                //lblErrorMessage.Text = "This expense is saved and added to your todays Expense control.";
                lblTotalExpOfToday.Text = lblTotalAmount.Text;
            }
        }
        ClearControlDetail();
    }
    protected void btnSaveExpense_Click(object sender, EventArgs e)
    {
        if (ValidateExpenseSide())
        {
            PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster DExp   = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();
            PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand     CashIn = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
            if (txtDailyExpMasterID.Text == "")
            {
                long newamount = Convert.ToInt32(lblRemainingCash.Text.ToString().Trim()) - Convert.ToInt32(txtItemAmount.Text);
                lblRemainingCash.Text = newamount.ToString();
                long DailyExpMasterID = DExp.InsertDailyExpMaster(Convert.ToInt32(txtCashInHandID.Text), lblHeaderDate.Text, Convert.ToInt32(lblStartCash.Text), Convert.ToInt32(lblRemainingCash.Text), Convert.ToInt32(Convert.ToInt32(lblTotalAmount.Text) + Convert.ToInt32(txtItemAmount.Text)));
                CashIn.UpdateCashInHandCashAvail(Convert.ToInt32(txtCashInHandID.Text), Convert.ToInt32(lblRemainingCash.Text));
                if (DailyExpMasterID > 0)
                {
                    DExp.InsertDailyExpDetail(DailyExpMasterID, txtItemDesc.Text, Convert.ToInt32(txtQuantity.Text), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtItemAmount.Text));

                    lblErrorMessage.Text = "This expense is saved and added to your todays Expense control.";
                    PopulateExpenses(DailyExpMasterID);

                    txtDailyExpMasterID.Text = DailyExpMasterID.ToString();
                    lblExpenseNumber.Text    = DailyExpMasterID.ToString();
                    lblTotalExpOfToday.Text  = Convert.ToString(Convert.ToInt32(lblTotalAmount.Text) + Convert.ToInt32(txtItemAmount.Text));
                    ClearControlDetail();
                }
            }
            else
            {
                if (txtItemDescID.Text == "")
                {
                    long newamount = Convert.ToInt32(lblRemainingCash.Text.ToString().Trim()) - Convert.ToInt32(txtItemAmount.Text);

                    if (newamount < 0)
                    {
                        lblErrorMessage.Text = "Out of money Error, Please add some cash in Hand first.";
                    }
                    else
                    {
                        lblRemainingCash.Text = newamount.ToString();
                        DExp.InsertDailyExpDetail(Convert.ToInt32(txtDailyExpMasterID.Text), txtItemDesc.Text, Convert.ToInt32(txtQuantity.Text), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtItemAmount.Text));
                        //PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand CashIn = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
                        CashIn.UpdateCashInHandCashAvail(Convert.ToInt32(txtCashInHandID.Text), Convert.ToInt32(lblRemainingCash.Text));

                        DataTable dtUpAmount = new DataTable();
                        dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                        if (dtUpAmount.Rows.Count > 0)
                        {
                            long startCash   = Convert.ToInt32(dtUpAmount.Rows[0]["StartCash"].ToString());
                            long TotalAmount = Convert.ToInt32(dtUpAmount.Rows[0]["TotalAmount"].ToString()) + Convert.ToInt32(txtItemAmount.Text);
                            //lblTotalAmount.Text = TotalAmount.ToString();
                            long endCash = startCash - TotalAmount;
                            DExp.UpdateDailyExpMasterTotalAmount(Convert.ToInt32(txtDailyExpMasterID.Text), endCash, TotalAmount);

                            dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                            if (dtUpAmount.Rows.Count > 0)
                            {
                                lblTotalAmount.Text = dtUpAmount.Rows[0]["TotalAmount"].ToString();
                            }
                        }

                        lblErrorMessage.Text = "This expense is saved and added to your todays Expense control.";
                        PopulateExpenses(Convert.ToInt32(txtDailyExpMasterID.Text));

                        lblTotalExpOfToday.Text = lblTotalAmount.Text;
                        ClearControlDetail();
                    }
                }
                else
                {
                    long newamount = Convert.ToInt32(Convert.ToInt32(lblRemainingCash.Text.ToString().Trim()) + Convert.ToInt32(txtItemAmountPrevious.Text)) - Convert.ToInt32(txtItemAmount.Text);

                    if (newamount < 0)
                    {
                        lblErrorMessage.Text = "Out of money Error, Please add some cash in Hand first.";
                    }
                    else
                    {
                        lblRemainingCash.Text = newamount.ToString();
                        DExp.UpdateDailyExpDetail(Convert.ToInt32(txtItemDescID.Text), Convert.ToInt32(txtDailyExpMasterID.Text), txtItemDesc.Text, Convert.ToInt32(txtQuantity.Text), Convert.ToInt32(txtUnitPrice.Text), Convert.ToInt32(txtItemAmount.Text));
                        CashIn.UpdateCashInHandCashAvail(Convert.ToInt32(txtCashInHandID.Text), Convert.ToInt32(lblRemainingCash.Text));

                        DataTable dtUpAmount = new DataTable();
                        dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                        if (dtUpAmount.Rows.Count > 0)
                        {
                            long startCash   = Convert.ToInt32(dtUpAmount.Rows[0]["StartCash"].ToString());
                            long TotalAmount = Convert.ToInt32(Convert.ToInt32(dtUpAmount.Rows[0]["TotalAmount"].ToString()) - Convert.ToInt32(txtItemAmountPrevious.Text)) + Convert.ToInt32(txtItemAmount.Text);
                            lblTotalAmount.Text = TotalAmount.ToString();
                            long endCash = startCash - TotalAmount;
                            DExp.UpdateDailyExpMasterTotalAmount(Convert.ToInt32(txtDailyExpMasterID.Text), endCash, TotalAmount);

                            dtUpAmount = DExp.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                            if (dtUpAmount.Rows.Count > 0)
                            {
                                lblTotalAmount.Text = dtUpAmount.Rows[0]["TotalAmount"].ToString();
                            }
                        }

                        lblErrorMessage.Text = "This expense is updated to your todays Expense control.";
                        PopulateExpenses(Convert.ToInt32(txtDailyExpMasterID.Text));

                        lblTotalExpOfToday.Text = lblTotalAmount.Text;
                        ClearControlDetail();
                    }
                }
            }
        }
    }