Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Purchases pur = new Purchases();
                pur.IdEmployee   = frmMain.idEmpleado;
                pur.IdProvider   = (int)cbProveedor.SelectedValue;
                pur.IdWarehouse  = (int)cbBodega.SelectedValue;
                pur.Factura      = txtNoFactura.Text;
                pur.EntryDate    = DateTime.Now;
                pur.PurchaseDate = dtFechaFactura.DateTime;

                if (pursCont.AddOrUpdatePurchases(pur))
                {
                    foreach (DetallesGrd x in listProd)
                    {
                        DetailPurchase det = new DetailPurchase();
                        det.IdProduct   = x.IdProducto;
                        det.Quantity    = x.Cantidad;
                        det.Cost        = x.Costo;
                        det.IVA         = x.IVA;
                        det.Desc        = x.Desc;
                        det.IdPurchases = pur.IdPurchases;
                        detPurCont.AddOrUpdateDetailPurchase(det);

                        Kardex kard = new Kardex();
                        kard.IdDocument   = pur.IdPurchases;
                        kard.Document     = "Compra";
                        kard.IdProducto   = x.IdProducto;
                        kard.EntryAmount  = x.Cantidad;
                        kard.OutputAmount = 0;
                        kard.Stock        = kardCont.GetStockActual(x.IdProducto) + x.Cantidad;
                        kard.IdWarehouse  = pur.IdWarehouse;
                        kardCont.AddOrUpdateClient(kard);

                        CostingAverage costAver = new CostingAverage();
                        costAver.IdKardex = kard.IdKardex;
                        costAver.Cost     = costAveCont.getCalcularPromedioSimple(x.IdProducto);
                        costAveCont.AddOrUpdateCostingAverage(costAver);

                        CostingWeighted costWeig = new CostingWeighted();
                        costWeig.IdKardex = kard.IdKardex;
                        costWeig.Cost     = 0;
                        cosWeiCont.AddOrUpdateCostingWeighted(costWeig);
                    }
                }

                FrmSuccess.ConfirmacionFrom("Guardado Correctamente.");
                Limpiar();
            }
            catch (Exception ex)
            {
                MessageBox.Show("ocurrio un error al guardar.");
                Limpiar();
            }
        }
Exemplo n.º 2
0
 public bool AddOrUpdateCostingAverage(CostingAverage CostingAverage)
 {
     try
     {
         using (TeamCellContext _DBContext = new TeamCellContext())
         {
             _DBContext.CostingAverage.AddOrUpdate(CostingAverage);
             _DBContext.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }