private bool Guardar() { try { registro.IdUsuario = FactoryUsuarios.UsuarioActivo.IdUsuario; proveedor = FactoryProveedores.Item(db, registro.CedulaRif); if (proveedor == null) { using (var newDb = new DatosEntities()) { proveedor = new Proveedore(); proveedor.CedulaRif = registro.CedulaRif; proveedor.RazonSocial = registro.RazonSocial; proveedor.Direccion = registro.Direccion; proveedor.IdProveedor = FactoryContadores.GetMax("IdProveedor"); newDb.Proveedores.AddObject(proveedor); newDb.SaveChanges(); } } else { proveedor.CedulaRif = registro.CedulaRif; proveedor.RazonSocial = registro.RazonSocial; proveedor.Direccion = registro.Direccion; } registro.Totalizar(); if (registro.Errores().Count > 0) { MessageBox.Show(registro.ErroresStr(), "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (esNuevo) { registro.IdCompra = FactoryContadores.GetMax("IdCompra"); db.Compras.AddObject(registro); } foreach (HK.ComprasIngrediente p in registro.ComprasIngredientes) { if (p.IdCompraIngrediente == null) { p.IdCompraIngrediente = FactoryContadores.GetMax("IdCompraIngrediente"); } } db.SaveChanges(); if (registro.Estatus == "CERRADA") { FactoryLibroCompras.EscribirItem(registro); FactoryLibroInventarios.RegistrarCompra(registro); FactoryCompras.Inventario(registro); } return(true); } catch (Exception x) { Basicas.ManejarError(x); return(false); } }
void btnActualizarInventario_Click(object sender, EventArgs e) { if (this.bs.Current == null) { return; } Compra registro = (Compra)this.bs.Current; try { if (registro.ActualizadoInventario.GetValueOrDefault(false) == true) { throw new Exception("Esta compra se tiene el inventario actualizado"); } registro.FechaInventario = DateTime.Today; FactoryCompras.Inventario(registro); this.bs.ResetCurrentItem(); } catch (Exception x) { MessageBox.Show(x.Message); } }