Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Billing pur = new Billing();
                pur.IdEmployee  = frmMain.idEmpleado;
                pur.IdClient    = (int)cbCliente.SelectedValue;
                pur.NoFactura   = txtNoFactura.Text;
                pur.DateBilling = DateTime.Now;

                if (pursCont.AddOrUpdateBilling(pur))
                {
                    foreach (DetallesGrd x in listProd)
                    {
                        DetailBilling det = new DetailBilling();
                        det.IdProduct = x.IdProducto;
                        det.Quantity  = x.Cantidad;
                        det.Cost      = x.Costo;
                        det.IVA       = x.IVA;
                        det.Desc      = x.Desc;
                        det.IdBilling = pur.IdBilling;
                        detPurCont.AddOrUpdateDetailBilling(det);

                        Kardex kard = new Kardex();
                        kard.IdDocument   = pur.IdBilling;
                        kard.Document     = "Factura";
                        kard.IdProducto   = x.IdProducto;
                        kard.EntryAmount  = 0;
                        kard.OutputAmount = x.Cantidad;
                        kard.Stock        = kardCont.GetStockActual(x.IdProducto) - x.Cantidad;
                        kard.IdWarehouse  = (int)cbBodega.SelectedValue;
                        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();
            }
        }
Example #2
0
 public bool AddOrUpdateDetailBilling(DetailBilling DetailBilling)
 {
     try
     {
         using (TeamCellContext _DBContext = new TeamCellContext())
         {
             _DBContext.DetailBilling.AddOrUpdate(DetailBilling);
             _DBContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }