void Dir(CustomersPayment entity)
    {
        txtID.Text = entity.CustomerPaymentID.ToString();

        ddlCustomer.SelectedValue = entity.CustomerID.ToString();
        txtPayment.Text           = entity.Payment.ToString();
        txtPaymentDateM.Text      = entity.PaymentDateM.ToString("MM/dd/yyyy", culture);
        txtPaymentDateH.Text      = entity.PaymentDateH;
        oldPayment = entity.Payment;
    }
 bool Insert()
 {
     objCustomersPayment = new CustomersPayment();
     objCustomersPayment.BeginTransaction();
     objCustomersPayment.CustomerID   = int.Parse(ddlCustomer.SelectedValue);
     objCustomersPayment.Payment      = Convert.ToDouble(txtPayment.Text.Trim());
     objCustomersPayment.PaymentDateM = Convert.ToDateTime(txtPaymentDateM.Text.Trim(), culture);
     objCustomersPayment.PaymentDateH = txtPaymentDateH.Text.Trim();
     objCustomersPayment.Insert();
     objCustomer          = objCustomer.Single(p => p.CustomerID == int.Parse(ddlCustomer.SelectedValue));
     objCustomer.Balance -= Convert.ToDouble(txtPayment.Text.Trim());
     objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID);
     objCustomer.EndTransaction();
     return(true);
 }
    bool Delete(int CustomerPaymentID)
    {
        try
        {
            objCustomersPayment.BeginTransaction();
            objCustomersPayment = objCustomersPayment.Single(z => z.CustomerPaymentID == CustomerPaymentID);


            objCustomer          = objCustomer.Single(p => p.CustomerID == objCustomersPayment.CustomerID);
            objCustomer.Balance += objCustomersPayment.Payment;
            objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID);

            objCustomersPayment.Delete(p => p.CustomerPaymentID == objCustomersPayment.CustomerPaymentID);
            objCustomersPayment.EndTransaction();
        }
        catch (Exception ex)
        {
            return(false);
        }
        return(true);
    }
示例#4
0
    bool Update()
    {
        objSalesMaster = new SalesMaster();
        objSalesMaster = objSalesMaster.Single(p => p.SalesID == Convert.ToInt32(txtID.Text.Trim()));

        objSalesMaster.CustomerName = txtCustomerName.Text;

        objSalesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null;

        //objSalesMaster.CustomerID  = int.Parse(ddlCustomer .SelectedValue);//?
        objSalesMaster.Notes = txtNotes.Text.Trim();

        objSalesMaster.SalesDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture);

        objSalesMaster.SalesDateH = txtSalesDateH.Text.Trim();

        objSalesMaster.IsCash = cboxIsCash.Checked;

        double oldrest = objSalesMaster.Rest;

        bool oldPaymentType = objSalesMaster.IsCash;
        int? paymentid      = objSalesMaster.CustomerPaymentID;

        objSalesMaster.TotalSales = Convert.ToDouble(lblTotalSalesPrice.Text);
        objSalesMaster.Rest       = Convert.ToDouble(lblRest.Text);

        double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0");

        objSalesMaster.Payments = Payments;



        objSalesMaster.BeginTransaction();


        CustomersPayment CustomersPayment = new CustomersPayment();

        if (paymentid == null)
        {
            if (Payments > 0)
            {
                CustomersPayment.CustomerID        = objSalesMaster.CustomerID;;
                CustomersPayment.PaymentDateM      = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture);
                CustomersPayment.PaymentDateH      = txtSalesDateH.Text.Trim();
                CustomersPayment.Payment           = Payments;
                CustomersPayment.CustomerPaymentID = Convert.ToInt32(CustomersPayment.Insert());
            }
        }
        else if (paymentid != null)
        {
            CustomersPayment = objSalesMaster.CustomersPayment;
            CustomersPayment.PaymentDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture);
            CustomersPayment.PaymentDateH = txtSalesDateH.Text.Trim();
            CustomersPayment.Payment      = Payments;
            CustomersPayment.Update(p => p.CustomerPaymentID == CustomersPayment.CustomerPaymentID);
        }

        objSalesMaster.Update(p => p.SalesID == objSalesMaster.SalesID);

        //var q=objPurchasesDetail.Filter(p => p.PurchaseID == objPurchasesMaster.PurchaseID).Select(p => (p.TotalPrice ));
        //double oldTotalPurchasePrice =(q!=null )?q.Sum():0.0;


        List <SalesDetail> SalesList = CurrentgvProducts(gvProducts);

        SalesList.ForEach(p =>
        {
            p.Quantity    = SalesManager.UnitConvert(p.UnitID, p.SQTY);
            p.UnitPrice   = SalesManager.UnitPriceConvert(p.UnitID, p.SUnitPrice);
            p.BasicUnitID = SalesManager.getBasicUnitID;
        });

        //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice );
        List <SalesDetail> newSalesList    = SalesList.Where(p => p.SalesDetailID == 0).ToList();
        List <SalesDetail> updateSalesList = SalesList.Where(p => p.SalesDetailID > 0).ToList();



        if (newSalesList.Count > 0)
        {
            newSalesList.ForEach(p => p.SalesID = objSalesMaster.SalesID);
            newSalesList.InsertAll();

            // update qty product in store(table product)
            newSalesList.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity));
        }
        if (updateSalesList.Count > 0)
        {
            updateSalesList.ForEach(p =>
            {
                p.Update(z => z.SalesDetailID == p.SalesDetailID);
                SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, (p.Quantity - p.oldQty));
            });
        }



        //========= composite calcualtion balance --- compare between old value and new  value
        if (oldPaymentType != true)// not cash
        {
            if (ddlCustomer.SelectedIndex > 0)
            {
                // any way( - balance) form old supplier if user change supplier
                objCustomer          = objCustomer.Single(p => p.CustomerID == objSalesMaster.CustomerID);
                objCustomer.Balance -= oldrest;
                // objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);

                if (cboxIsCash.Checked != true)// if (not cash) add new price to balance
                {
                    //objSupplier = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue));
                    objCustomer.Balance += objSalesMaster.Rest;
                }
                objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID);
            }
        }
        else if (oldPaymentType == true)    //  cash
        {
            if (cboxIsCash.Checked != true) // if user change to (not cash) will add new price to supplier balance
            {
                if (ddlCustomer.SelectedIndex > 0)
                {
                    objCustomer          = objCustomer.Single(p => p.CustomerID == objSalesMaster.CustomerID);
                    objCustomer.Balance += objSalesMaster.Rest;
                    objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID);
                }
            }
        }

        objSalesMaster.EndTransaction();

        return(true);
    }
示例#5
0
    bool Insert()
    {
        objSalesMaster = new SalesMaster();

        objSalesMaster.CustomerID   = (ddlCustomer.SelectedIndex == 0)?null:(Nullable <int>)Convert.ToInt32(ddlCustomer.SelectedValue);
        objSalesMaster.CustomerName = txtCustomerName.Text;

        objSalesMaster.EmployeeID = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null;
        objSalesMaster.Notes      = txtNotes.Text.Trim();
        objSalesMaster.SalesDateM = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture);
        objSalesMaster.SalesDateH = txtSalesDateH.Text.Trim();
        objSalesMaster.IsCash     = cboxIsCash.Checked;

        // new-------------------
        objSalesMaster.TotalSales = Convert.ToDouble(lblTotalSalesPrice.Text);
        objSalesMaster.Rest       = Convert.ToDouble(lblRest.Text);

        double Payments = Convert.ToDouble(!string.IsNullOrEmpty(txtPayment.Text) ? txtPayment.Text : "0.0");

        objSalesMaster.Payments = Payments;

        //-----------



        List <SalesDetail> saleslist = new List <SalesDetail>();

        saleslist = CurrentgvProducts(gvProducts);
        saleslist.ForEach(p =>
        {
            p.Quantity    = SalesManager.UnitConvert(p.UnitID, p.SQTY);
            p.UnitPrice   = SalesManager.UnitPriceConvert(p.UnitID, p.SUnitPrice);
            p.BasicUnitID = SalesManager.getBasicUnitID;
        });
        //var q = saleslist.Select(p => new { SalesID = p["SalesID"], ProductID = p["ProductID"] }).GroupBy(p => p.ProductID).Select(z => new { ProductID = z.Key, Count = z.Count() }).Where(p => p.Count > 1);
        //if (q.Count() > 0)
        //{
        //    MessageBox.Show(this.Page, "Cant Insert same Product more than once in Sales.");
        //    return false ;
        //}


        //  double TotalSalesPrice = saleslist.Sum(p=> (p.Quantity*p.Price));

        objSalesMaster.SalesDetails.AddRange(saleslist);

        objSalesMaster.BeginTransaction();


        // update qty product in store(table product)
        saleslist.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity));

        if (Payments > 0)
        {
            CustomersPayment CustomersPayment = new CustomersPayment();
            CustomersPayment.CustomerID      = objSalesMaster.CustomerID;
            CustomersPayment.PaymentDateM    = Convert.ToDateTime(txtSalesDateM.Text.Trim(), culture);
            CustomersPayment.PaymentDateH    = txtSalesDateH.Text.Trim();
            CustomersPayment.Payment         = Payments;
            objSalesMaster.CustomerPaymentID = Convert.ToInt32(CustomersPayment.Insert());
        }
        objSalesMaster.Insert();

        if (cboxIsCash.Checked != true)
        {
            if (ddlCustomer.SelectedIndex > 0)
            {
                objCustomer          = objCustomer.Single(p => p.CustomerID == int.Parse(ddlCustomer.SelectedValue));
                objCustomer.Balance += objSalesMaster.Rest;;
                objCustomer.Update(p => p.CustomerID == objCustomer.CustomerID);
            }
        }


        objSalesMaster.EndTransaction();



        return(true);
    }