コード例 #1
0
    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();
    }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //string ModeCheck = "";
        if (Request.QueryString["DailyExpMasterID"] != null && Request.QueryString["DailyExpMasterID"].ToString() != "" && Request.QueryString["DailyExpDetailID"] != null && Request.QueryString["DailyExpDetailID"].ToString() != "" && !Page.IsPostBack)
        {
            // This is for Updating and ITEM in Expense
            long ExpenseDetailID = Convert.ToInt32(Request.QueryString["DailyExpDetailID"].ToString());
            PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster Expense = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();
            txtItemDescID.Text  = Request.QueryString["DailyExpDetailID"].ToString();
            lblTotalAmount.Text = "0";
            dtExpenseEdit       = Expense.GetDailyExpDetailByID(ExpenseDetailID);
            for (int a = 0; a < dtExpenseEdit.Rows.Count; a++)
            {
                if (dtExpenseEdit.Rows[a]["ID"].ToString() == Request.QueryString["DailyExpDetailID"].ToString())
                {
                    txtItemDesc.Text           = dtExpenseEdit.Rows[a]["ItemDesc"].ToString();
                    txtItemDescID.Text         = dtExpenseEdit.Rows[a]["ID"].ToString();
                    txtQuantity.Text           = dtExpenseEdit.Rows[a]["Quantity"].ToString();
                    txtUnitPrice.Text          = dtExpenseEdit.Rows[a]["UnitPrice"].ToString();
                    txtItemAmount.Text         = dtExpenseEdit.Rows[a]["ItemAmount"].ToString();
                    txtItemAmountPrevious.Text = dtExpenseEdit.Rows[a]["ItemAmount"].ToString();

                    PopulateExpenses(Convert.ToInt32(Request.QueryString["DailyExpMasterID"].ToString()));
                }

                lblTotalAmount.Text     = Convert.ToString(Convert.ToInt32(lblTotalAmount.Text) + Convert.ToInt32(dtExpenseEdit.Rows[a]["ItemAmount"].ToString()));
                lblTotalExpOfToday.Text = lblTotalAmount.Text;
            }
        }

        if (!Page.IsPostBack)
        {
            PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster ExpM    = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();
            PCSN.InvoiceSystem.BusinessLogicLayer.Closing        closing = new PCSN.InvoiceSystem.BusinessLogicLayer.Closing();
            DataTable dtClosing = new DataTable();
            DataTable dtExpM    = new DataTable();
            // It is to refresh the total expense page.
            if (Request.QueryString["DailyExpMasterID"] != null && Request.QueryString["DailyExpMasterID"].ToString() != "")
            {
                txtDailyExpMasterID.Text = Request.QueryString["DailyExpMasterID"].ToString();
            }
            else
            {
                dtExpM = ExpM.GetDailyExpMasterByExpDate(DateTime.Now.ToShortDateString());
                if (dtExpM.Rows.Count > 0)
                {
                    txtDailyExpMasterID.Text = dtExpM.Rows[0]["ID"].ToString();
                    lblExpenseNumber.Text    = txtDailyExpMasterID.Text;
                }
            }
            if (txtDailyExpMasterID.Text == "")
            {
                // This will run everytime u access the Expense page, to check if it is a new Day or the closing has been made for this day?.

                // Checking the Closing of Today?
                dtClosing = closing.GetAllDailyClosingByDate(DateTime.Now.ToShortDateString());
                if (dtClosing.Rows.Count > 0)
                {
                }
                else
                {
                    // So the Closing has not been performed.. Means NO NEW EXPENSE

                    dtExpM = ExpM.GetDailyExpMasterByExpDate(DateTime.Now.ToShortDateString());
                    if (dtExpM.Rows.Count > 0)
                    {
                        txtDailyExpMasterID.Text = dtExpM.Rows[0]["ID"].ToString();
                        lblExpenseNumber.Text    = txtDailyExpMasterID.Text;
                    }

                    // Performing Closing ( IT WILL CHECK IF THE CLOSING FOR YESTERDAY IS PERFORMED OR NOT )
                    //=============================
                    long DEM_ID = 0;
                    // First we will get the EXPENSE ID of Yesterday
                    dtExpM = ExpM.GetDailyExpMasterByExpDate(DateTime.Now.AddDays(-1).ToShortDateString());
                    if (dtExpM.Rows.Count > 0)
                    {
                        DEM_ID = Convert.ToInt32(dtExpM.Rows[0]["ID"].ToString());
                    }
                    // Now we are Checking the Closing of Yesterday
                    dtClosing = closing.GetAllDailyClosingByDate(DateTime.Now.AddDays(-1).ToShortDateString());
                    if (dtClosing.Rows.Count > 0 || DEM_ID == 0)
                    {
                        // Closing is already DONE or It was a Holiday or WeekEnd
                    }
                    else
                    {
                        // CLOSING Daily Closing of Yesterday
                        closing.InsertDailyClosing(DateTime.Now.AddDays(-1).ToShortDateString(), DEM_ID);
                    }
                    //========================================
                }
            }
            if (txtDailyExpMasterID.Text == "")
            {
                // This is when a Fresh Expense is About to Generate
                // DAILY CLOSING Is DONE for Previous day
                lblRemainingCash.Text = "0";
                lblStartCash.Text     = "0";
                PCSN.InvoiceSystem.BusinessLogicLayer.OurCompany ourCompany = new PCSN.InvoiceSystem.BusinessLogicLayer.OurCompany();
                dtOurCompany = ourCompany.GetOurCompanyByID(Convert.ToInt32("1"));

                if (dtOurCompany.Rows.Count <= 0)
                {
                    txtOurCompany.Text = "PC.Solutions.NET";
                }
                else
                {
                    txtOurCompanyID.Text = dtOurCompany.Rows[0]["ID"].ToString();
                    txtOurCompany.Text   = dtOurCompany.Rows[0]["CompanyName"].ToString() + Environment.NewLine;
                    txtOurCompany.Text   = txtOurCompany.Text + dtOurCompany.Rows[0]["CompanyAddress"].ToString() + Environment.NewLine;
                }
                lblStartCash.Text = "0";
                PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster Expense    = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();
                PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand     CashinHand = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
                DataTable dtCashinHand = new DataTable();
                // Getting Cash in Hand Detail
                dtCashinHand = CashinHand.GetAllCashInHandByMAXID();
                if (dtCashinHand.Rows.Count > 0)
                {
                    txtCashInHandID.Text = dtCashinHand.Rows[0]["ID"].ToString();
                    dtCashinHand         = CashinHand.GetAllCashInHandByDateIN(DateTime.Now.ToShortDateString());
                    // Getting the CASH IN HAND details of Today
                    if (dtCashinHand.Rows.Count > 0)
                    {
                        if (dtCashinHand.Rows.Count > 1)
                        {
                            for (int i = 0; i > dtCashinHand.Rows.Count; i++)
                            {
                                txtCashInHandID.Text  = dtCashinHand.Rows[i]["ID"].ToString();
                                lblStartCash.Text     = Convert.ToString(Convert.ToInt32(lblStartCash.Text) + Convert.ToInt32(dtCashinHand.Rows[i]["CashIN"].ToString()));
                                lblRemainingCash.Text = Convert.ToString(Convert.ToInt32(lblRemainingCash.Text) + Convert.ToInt32(dtCashinHand.Rows[i]["TotalAmount"].ToString()));
                            }
                        }
                        else
                        {
                            txtCashInHandID.Text  = dtCashinHand.Rows[0]["ID"].ToString();
                            lblStartCash.Text     = dtCashinHand.Rows[0]["CashAvailable"].ToString();
                            lblRemainingCash.Text = dtCashinHand.Rows[0]["CashAvailable"].ToString();
                        }
                    }
                    else
                    {
                        dtCashinHand = CashinHand.GetAllCashInHandByMAXID();
                        if (dtCashinHand.Rows.Count > 0)
                        {
                            long CashinhandID = CashinHand.InsertCashInHand(Convert.ToInt32(dtCashinHand.Rows[0]["ChequeIssueID"].ToString()), Convert.ToInt32(dtCashinHand.Rows[0]["CashAvailable"].ToString()), Convert.ToInt32("0"), DateTime.Now.ToShortDateString(), Convert.ToInt32(dtCashinHand.Rows[0]["CashAvailable"].ToString()), "Automatic Entry to Data Base of Starting Cash in Hand for Today");

                            dtCashinHand = CashinHand.GetAllCashInHandByMAXID();
                            if (dtCashinHand.Rows.Count > 0)
                            {
                                txtCashInHandID.Text  = dtCashinHand.Rows[0]["ID"].ToString();
                                lblStartCash.Text     = dtCashinHand.Rows[0]["CashAvailable"].ToString();
                                lblRemainingCash.Text = dtCashinHand.Rows[0]["CashAvailable"].ToString();
                            }
                        }
                    }
                }
                else
                {
                    Response.Redirect("CashRegister.aspx?errmsg=You do not have enough Funds available to use as Cash. Please issue a Cheque for Personal Use and then Use it in order to use Daily Expense System.");
                }

                lblHeaderDate.Text      = Convert.ToString(DateTime.Now.ToShortDateString());
                lblTotalAmount.Text     = "0";
                lblTotalExpOfToday.Text = lblTotalAmount.Text;


                dtExpense = Expense.GetAllDailyExpMasterMAX();
                if (dtExpense.Rows.Count == 0 || dtExpense.Rows[0]["MAXID"].ToString() == "")
                {
                    lblExpenseNumber.Text = "1";
                }
                else
                {
                    lblExpenseNumber.Text = Convert.ToInt32(Convert.ToInt32(dtExpense.Rows[0]["MAXID"].ToString()) + 1).ToString();
                }
            }
            else
            {
                // This is when the Expense ID is getting from somewhere
                // AND the DAILY CLOSING has not been performed
                // Like from Query Strings

                PCSN.InvoiceSystem.BusinessLogicLayer.OurCompany ourCompany = new PCSN.InvoiceSystem.BusinessLogicLayer.OurCompany();
                dtOurCompany = ourCompany.GetOurCompanyByID(Convert.ToInt32("1"));

                if (dtOurCompany.Rows.Count <= 0)
                {
                    txtOurCompany.Text = "PC.Solutions.NET";
                }
                else
                {
                    txtOurCompanyID.Text = dtOurCompany.Rows[0]["ID"].ToString();
                    txtOurCompany.Text   = dtOurCompany.Rows[0]["CompanyName"].ToString() + Environment.NewLine;
                    txtOurCompany.Text   = txtOurCompany.Text + dtOurCompany.Rows[0]["CompanyAddress"].ToString() + Environment.NewLine;
                }

                PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand CashinHand = new PCSN.InvoiceSystem.BusinessLogicLayer.CashInHand();
                DataTable dtCashinHand = new DataTable();
                dtCashinHand = CashinHand.GetAllCashInHandByMAXID();
                // Setting up the CASH IN HAND VALUES
                if (dtCashinHand.Rows.Count > 0)
                {
                    txtCashInHandID.Text = dtCashinHand.Rows[0]["ID"].ToString();
                }
                else
                {
                    // If Cash in Hand Not Found then you Need to Add some Cash in Hand in order to run Daily Expense
                    Response.Redirect("CashRegister.aspx");
                }

                lblHeaderDate.Text  = Convert.ToString(DateTime.Now.ToShortDateString());
                lblTotalAmount.Text = "0";
                PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster Expense = new PCSN.InvoiceSystem.BusinessLogicLayer.DailyExpMaster();

                dtExpense = Expense.GetDailyExpMasterByID(Convert.ToInt32(txtDailyExpMasterID.Text));
                if (dtExpense.Rows.Count > 0)
                {
                    lblStartCash.Text       = dtExpense.Rows[0]["StartCash"].ToString();
                    lblRemainingCash.Text   = dtExpense.Rows[0]["EndCash"].ToString();
                    lblExpenseNumber.Text   = dtExpense.Rows[0]["ID"].ToString();
                    lblTotalAmount.Text     = dtExpense.Rows[0]["TotalAmount"].ToString();
                    txtCashInHandID.Text    = dtExpense.Rows[0]["CashInHandID"].ToString();
                    lblHeaderDate.Text      = dtExpense.Rows[0]["ExpDate"].ToString();
                    lblTotalExpOfToday.Text = lblTotalAmount.Text;
                    lblRemainingCash.Text   = Convert.ToString(Convert.ToInt32(lblStartCash.Text) - Convert.ToInt32(lblTotalExpOfToday.Text));
                }
                if (txtDailyExpMasterID.Text != "")
                {
                    PopulateExpenses(Convert.ToInt32(txtDailyExpMasterID.Text));
                }
            }
        }
    }