public static bool Guardar(FacturaDetalle factura) { MySqlDataAdapter dater = new MySqlDataAdapter(); bool estado = true; try { var Id = FacturacionBLL.Buscar(); var IDfactura = Id.ElementAt(Id.Count() - 1); dater.InsertCommand = new MySqlCommand("insert into FacturaDetalles (Id,FacturaId,ProductoId,Cantidad,Precio,Descripcion) values ('" + factura.Id + "','" + factura.FacturaId + "','" + factura.ProductoId + "','" + factura.Cantidad + "','" + factura.Precio + "','" + factura.Descripcion + "')", ConexionGlobal.ConexionGlobalDb.RetornarConexion()); dater.InsertCommand.Connection = ConexionGlobal.ConexionGlobalDb.RetornarConexion(); dater.InsertCommand.ExecuteNonQuery(); } catch (Exception) { estado = false; throw; } return(estado); }
public static bool Guardar(List <FacturaDetalle> factura) { MySqlDataAdapter dater = new MySqlDataAdapter(); bool estado = true; try { TestConnectiong(); var Id = FacturacionBLL.Buscar(); var IDfactura = Id.ElementAt(Id.Count() - 1); foreach (var item in factura) { dater.InsertCommand = new MySqlCommand("insert into FacturaDetalles (Id,FacturaId,ProductoId,Cantidad,Precio,Descripcion) values ('" + item.Id + "','" + IDfactura.FacturaId + "','" + item.ProductoId + "','" + item.Cantidad + "','" + item.Precio + "','" + item.Descripcion + "')", db); dater.InsertCommand.Connection = db; dater.InsertCommand.ExecuteNonQuery(); } } catch (Exception) { estado = false; throw; } finally { db.Close(); } return(estado); }
public static bool Modificar(List <FacturaDetalle> factura) { MySqlDataAdapter dater = new MySqlDataAdapter(); bool estado = true; try { foreach (var item in factura) { if (item.Id == 0) { Guardar(item); FacturacionBLL.DescontarProductos(item); } else { //var detalle = Buscar(item.Id.ToString()); //var cDetalle = detalle.ElementAt(0); //if (item.Cantidad != cDetalle.Cantidad) //{ // FacturacionBLL.ArreglarProducto(cDetalle); // FacturacionBLL.DescontarProductos(item); //} dater.UpdateCommand = new MySqlCommand("update FacturaDetalles set Id= '" + item.Id + "', FacturaId = '" + item.FacturaId + "', ProductoId = '" + item.ProductoId + "', Cantidad = '" + item.Cantidad + "', Precio= '" + item.Precio + "',Descripcion='" + item.Descripcion + "'where Id = '" + item.Id + "'", ConexionGlobal.ConexionGlobalDb.RetornarConexion()); dater.UpdateCommand.Connection = ConexionGlobal.ConexionGlobalDb.RetornarConexion(); dater.UpdateCommand.ExecuteNonQuery(); } } } catch (Exception) { estado = false; throw; } return(estado); }