Exemplo n.º 1
0
    bool Delete(int discardsID)
    {
        objPurchaseDiscardsMaster = objPurchaseDiscardsMaster.Single(p => p.PurchaseDiscardsID == discardsID);

        List <PurchaseDiscardsDetail> itemsList = objPurchaseDiscardsMaster.PurchaseDiscardsDetails.ToList();

        objSupplier = objPurchaseDiscardsMaster.PurchasesMaster.Supplier;

        try
        {
            objPurchaseDiscardsMaster.BeginTransaction();


            //update Supplier balance
            // هيزيد
            objSupplier.Balance += objPurchaseDiscardsMaster.TotalReturn;
            objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);


            //update products (store)
            itemsList.ForEach(p =>
            {
                //update qty
                //هيزيد
                SalesManager.UpdateproductQTY(QTYOperation.Increment, p.ProductID, p.Quantity);
            }
                              );

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

            //delete masetr(PurchasesMaster)
            objPurchaseDiscardsMaster.Delete(p => p.PurchaseDiscardsID == discardsID);

            objPurchaseDiscardsMaster.EndTransaction();
        }
        catch (Exception ex)
        {
            ExtenssionClass.Rollback();
            Page.Show(ex.Message);
            return(false);
        }
        return(true);
    }
Exemplo n.º 2
0
    bool Insert()
    {
        objPurchaseDiscardsMaster = new PurchaseDiscardsMaster();

        objPurchaseDiscardsMaster.PurchaseID            = Convert.ToInt32(hfPID.Value);
        objPurchaseDiscardsMaster.PurchaseDiscardsDateM = Convert.ToDateTime(txtPurchaseDiscardDateM.Text.Trim(), culture);
        objPurchaseDiscardsMaster.PurchaseDiscardsDateH = txtPurchaseDiscardDateH.Text.Trim();
        objPurchaseDiscardsMaster.Notes = txtNotes.Text.Trim();

        objPurchaseDiscardsMaster.TotalReturn = Convert.ToDouble(lblTotalPurchaseDiscardsPrice.Text);

        List <PurchaseDiscardsDetail> discardsList = new List <PurchaseDiscardsDetail>();

        discardsList = CurrentgvProducts(gvProducts);

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

        objPurchaseDiscardsMaster.PurchaseDiscardsDetails.AddRange(discardsList);

        objPurchaseDiscardsMaster.BeginTransaction();

        objPurchaseDiscardsMaster.Insert();

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

        // update supplier balance
        objSupplier         = objSupplier.Single(p => p.SupplierID == int.Parse(hfSID.Value));
        objSupplier.Balance = Convert.ToDouble(lblNewSupplierBalance.Text);
        objSupplier.Update(p => p.SupplierID == objSupplier.SupplierID);

        objPurchaseDiscardsMaster.EndTransaction();

        return(true);
    }