コード例 #1
0
    bool Delete(int PurchaseID)
    {
        objPurchasesMaster = objPurchasesMaster.Single(p => p.PurchaseID == PurchaseID);
        // totalpurchase-payments
        Double rest = objPurchasesMaster.Rest;//محصله الفاتوره النهائيه الا هى عباره عن اجمالى الفاتوره ناقص مدفوع العميل
        List <PurchasesDetail> itemslist = objPurchasesMaster.PurchasesDetails.ToList();
        var payments = objPurchasesMaster.PaymentsForSupplier;

        objSupplier = objPurchasesMaster.Supplier;


        try
        {
            objPurchasesMaster.BeginTransaction();

            //update supplier balance
            objSupplier.Balance -= rest;
            objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);
            //update products (store)
            itemslist.ForEach(p =>
            {
                //update qty
                SalesManager.UpdateproductQTY(QTYOperation.Decrement, p.ProductID, p.Quantity);
            }
                              );



            // delete purchaseitems(PurchasesDetails)
            itemslist.DeleteAll();



            //delete masetr(PurchasesMaster)

            objPurchasesMaster.Delete(p => p.PurchaseID == PurchaseID);
            //delete payments
            if (payments != null)
            {
                payments.Delete(p => p.SupplierPaymentID == payments.SupplierPaymentID);
            }
            objPurchasesMaster.EndTransaction();
        }
        catch (Exception ex)
        {
            ExtenssionClass.Rollback();
            Page.Show(ex.Message);
            return(false);
        }
        return(true);
    }
コード例 #2
0
    bool Update()
    {
        objPurchasesMaster = new PurchasesMaster();


        objPurchasesMaster = objPurchasesMaster.Single(p => p.PurchaseID == Convert.ToInt32(txtID.Text.Trim()));

        //objPurchasesMaster.SupplierID = int.Parse(ddlSupplier.SelectedValue);
        objPurchasesMaster.EmployeeID    = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null;
        objPurchasesMaster.Notes         = txtNotes.Text.Trim();
        objPurchasesMaster.PurchaseDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture);
        objPurchasesMaster.PurchaseDateH = txtPurchaseDateH.Text.Trim();
        objPurchasesMaster.ISCash        = cboxIsCash.Checked;

        double oldrest        = objPurchasesMaster.Rest;
        bool   oldPaymentType = objPurchasesMaster.ISCash;
        int?   paymentid      = objPurchasesMaster.SupplierPaymentID;

        objPurchasesMaster.TotalPurchase = Convert.ToDouble(lblTotalPurchasePrice.Text);
        objPurchasesMaster.Rest          = Convert.ToDouble(lblRest.Text);

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

        objPurchasesMaster.Payments = Payments;



        objPurchasesMaster.BeginTransaction();
        PaymentsForSupplier paymentforsupplier = new PaymentsForSupplier();

        if (paymentid == null)
        {
            if (Payments > 0)
            {
                paymentforsupplier.SupplierID        = Convert.ToInt32(ddlSupplier.SelectedValue);
                paymentforsupplier.PaymentDateM      = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture);
                paymentforsupplier.PaymentDateH      = txtPurchaseDateH.Text.Trim();
                paymentforsupplier.Payment           = Payments;
                objPurchasesMaster.SupplierPaymentID = Convert.ToInt32(paymentforsupplier.Insert());
            }
        }
        else if (paymentid != null)
        {
            paymentforsupplier = objPurchasesMaster.PaymentsForSupplier;
            paymentforsupplier.PaymentDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture);
            paymentforsupplier.PaymentDateH = txtPurchaseDateH.Text.Trim();
            paymentforsupplier.Payment      = Payments;
            paymentforsupplier.Update(p => p.SupplierPaymentID == paymentforsupplier.SupplierPaymentID);
        }

        objPurchasesMaster.Update(p => p.PurchaseID == objPurchasesMaster.PurchaseID);

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


        List <PurchasesDetail> Purchaseslist = CurrentgvProducts(gvProducts);

        Purchaseslist.ForEach(p =>
        {
            p.Quantity    = SalesManager.UnitConvert(p.UnitID, p.PQTY);
            p.UnitPrice   = SalesManager.UnitPriceConvert(p.UnitID, p.PUnitPrice);
            p.BasicUnitID = SalesManager.getBasicUnitID;
        });

        //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice );
        List <PurchasesDetail> newPurchaseslist    = Purchaseslist.Where(p => p.PurchasesDetailID == 0).ToList();
        List <PurchasesDetail> updatePurchaseslist = Purchaseslist.Where(p => p.PurchasesDetailID > 0).ToList();



        if (newPurchaseslist.Count > 0)
        {
            newPurchaseslist.ForEach(p => p.PurchaseID = objPurchasesMaster.PurchaseID);
            newPurchaseslist.InsertAll();

            // update qty product in store(table product)
            newPurchaseslist.ForEach(p => SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, p.Quantity));
        }
        if (updatePurchaseslist.Count > 0)
        {
            updatePurchaseslist.ForEach(p =>
            {
                p.Update(z => z.PurchasesDetailID == p.PurchasesDetailID);
                SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, (p.Quantity - p.oldQty));
            });
        }



        //========= composite calcualtion balance --- compare between old value and new  value
        if (oldPaymentType != true)// not cash
        {
            // any way( - balance) form old supplier if user change supplier
            objSupplier          = objSupplier.Single(p => p.SupplierID == objPurchasesMaster.SupplierID);
            objSupplier.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));
                objSupplier.Balance += objPurchasesMaster.Rest;
            }
            objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);
        }
        else if (oldPaymentType == true)    //  cash
        {
            if (cboxIsCash.Checked != true) // if user change to (not cash) will add new price to supplier balance
            {
                objSupplier          = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue));
                objSupplier.Balance += objPurchasesMaster.Rest;
                objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);
            }
        }

        objPurchasesMaster.EndTransaction();

        return(true);
    }
コード例 #3
0
    bool Insert()
    {
        objPurchasesMaster = new PurchasesMaster();

        objPurchasesMaster.SupplierID    = int.Parse(ddlSupplier.SelectedValue);
        objPurchasesMaster.EmployeeID    = (ddlEmployee.SelectedIndex > 0) ? (Nullable <int>) int.Parse(ddlEmployee.SelectedValue) : null;
        objPurchasesMaster.Notes         = txtNotes.Text.Trim();
        objPurchasesMaster.PurchaseDateM = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture);
        objPurchasesMaster.PurchaseDateH = txtPurchaseDateH.Text.Trim();

        objPurchasesMaster.TotalPurchase = Convert.ToDouble(lblTotalPurchasePrice.Text);
        objPurchasesMaster.Rest          = Convert.ToDouble(lblRest.Text);

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

        objPurchasesMaster.Payments = Payments;


        objPurchasesMaster.ISCash = cboxIsCash.Checked;



        List <PurchasesDetail> Purchaseslist = new List <PurchasesDetail>();

        Purchaseslist = CurrentgvProducts(gvProducts);
        Purchaseslist.ForEach(p => {
            p.Quantity    = SalesManager.UnitConvert(p.UnitID, p.PQTY);
            p.UnitPrice   = SalesManager.UnitPriceConvert(p.UnitID, p.PUnitPrice);
            p.BasicUnitID = SalesManager.getBasicUnitID;
        });



        //double TotalPurchasePrice = Purchaseslist.Sum(p => p.TotalPrice);
        objPurchasesMaster.PurchasesDetails.AddRange(Purchaseslist);


        objPurchasesMaster.BeginTransaction();

        if (Payments > 0)
        {
            PaymentsForSupplier paymentforsupplier = new PaymentsForSupplier();
            paymentforsupplier.SupplierID        = Convert.ToInt32(ddlSupplier.SelectedValue);
            paymentforsupplier.PaymentDateM      = Convert.ToDateTime(txtPurchaseDateM.Text.Trim(), culture);
            paymentforsupplier.PaymentDateH      = txtPurchaseDateH.Text.Trim();
            paymentforsupplier.Payment           = Payments;
            objPurchasesMaster.SupplierPaymentID = Convert.ToInt32(paymentforsupplier.Insert());
        }

        objPurchasesMaster.Insert();

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

        if (cboxIsCash.Checked != true)
        {
            objSupplier          = objSupplier.Single(p => p.SupplierID == int.Parse(ddlSupplier.SelectedValue));
            objSupplier.Balance += objPurchasesMaster.Rest;
            objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);
        }


        objPurchasesMaster.EndTransaction();



        return(true);
    }