private void BtnGenerarCompra_Click(object sender, EventArgs e) { using (DBVentaContainer db = new DBVentaContainer()) { using (var transaccion = db.Database.BeginTransaction()) { try { Compra oCompra = new Compra(); oCompra.Codigo = TxtCodigoVenta.Text.Trim(); oCompra.FechaCompra = DateTime.Now; oCompra.EmpleadoIdEmpleado = int.Parse(TxtIdEmpleado.Text.ToString().Trim()); oCompra.ProveedorIdProveedor = int.Parse(txtIdProveedor.Text.ToString().Trim()); db.Compra.Add(oCompra); db.SaveChanges(); foreach (DataGridViewRow item in DgvDetalleCompra.Rows) { DetalleCompra oDetalleCompra = new DetalleCompra(); oDetalleCompra.Precio = decimal.Parse(item.Cells[1].Value.ToString()); oDetalleCompra.Cantidad = int.Parse(item.Cells[2].Value.ToString()); //oDetalleVenta.IdDetalleVenta = int.Parse(item.Cells[0].Value.ToString()); oDetalleCompra.ProductoIdProducto = int.Parse(item.Cells[4].Value.ToString()); //oDetalleVenta.Importe = decimal.Parse(item.Cells[3].Value.ToString()); oDetalleCompra.CompraIdCompra = oCompra.IdCompra; db.DetalleCompra.Add(oDetalleCompra); } //DetalleVenta detalleVenta = new DetalleVenta(); //detalleVenta.ProductoIdProducto = int.Parse(TxtIdProducto.Text.ToString()); //db.DetalleVenta.Add(detalleVenta); db.SaveChanges(); transaccion.Commit(); transaccion.Dispose(); this.Close(); TxtCodgoEmpleado.Text = ""; TxtCodigoCliente.Text = ""; txtIdProveedor.Text = ""; TxtIdEmpleado.Text = ""; TxtCodigoVenta.Text = ""; TxtCodgoEmpleado.Text = ""; TxtCodigoCliente.Text = ""; TxtNombreCliente.Text = ""; TxtNombreEmpleado.Text = ""; var reporte = new Reportes.frmReporteUltimaCompra(); reporte.ShowDialog(); } catch (Exception ex) { transaccion.Rollback(); //regresar la base de datos como estaba } } } }
public bool Agregar(Producto oProducto) { db.Producto.Add(oProducto); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Modelo oModelo) { db.Modelo.Add(oModelo); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Categoria oCategoria) { db.Categoria.Add(oCategoria); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Datos oDatos) { db.Datos.Add(oDatos); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Venta oVenta) { db.Venta.Add(oVenta); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Empleado oEmpledo) { db.Empleado.Add(oEmpledo); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Cliente oCliente) { db.Cliente.Add(oCliente); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Proveedor oProveedor) { db.Proveedor.Add(oProveedor); return(db.SaveChanges() > 0 ? true : false); }
public bool Agregar(Marca oMarca) { db.Marca.Add(oMarca); return(db.SaveChanges() > 0 ? true : false); }