public static bool InsertarStock(Entidades.Stock _stock) { bool exito = false; int CantidadEnviada = _stock.Cantidad; //bool stockExistente = DAO.ConsultarDao.ValidarStockExistente(_stock.idProducto); List <int> stockExistente = new List <int>(); stockExistente = DAO.ConsultarDao.ValidarStockExistente(_stock.idProducto); if (stockExistente.Count > 0) { int cant = Convert.ToInt32(stockExistente[0].ToString()); _stock.Cantidad = _stock.Cantidad + cant; exito = DAO.EditarDao.ActualizarStock(_stock.idProducto, _stock.Cantidad); } else { exito = InsertarStock(_stock.idProducto, _stock.Cantidad, _stock.CodigoProducto); } if (_stock.PrecioDeVenta > 0) { exito = InsertarPrecioVenta(_stock.idProducto, _stock.PrecioDeVenta, _stock.FechaActual, _stock.idUsuario); } if (exito == true) { connection.Close(); connection.Open(); string proceso = "AltaMovimientoStock"; MySqlCommand cmd = new MySqlCommand(proceso, connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("idProducto_in", _stock.idProducto); cmd.Parameters.AddWithValue("Cantidad_in", CantidadEnviada); cmd.Parameters.AddWithValue("Proveedor_in", _stock.Proveedor); cmd.Parameters.AddWithValue("FechaCompra_in", _stock.FechaCompra); cmd.Parameters.AddWithValue("ValorUnitario_in", _stock.ValorUnitario); cmd.Parameters.AddWithValue("ValorCompra_in", _stock.ValorCompra); cmd.Parameters.AddWithValue("Remito_in", _stock.Remito); cmd.Parameters.AddWithValue("VencimientoLote_in", _stock.VencimientoLote); cmd.Parameters.AddWithValue("ReditoPorcentual_in", _stock.ReditoPorcentual); cmd.Parameters.AddWithValue("PrecioDeVenta_in", _stock.PrecioDeVenta); cmd.Parameters.AddWithValue("FechaActual_in", _stock.FechaActual); cmd.Parameters.AddWithValue("idUsuario_in", _stock.idUsuario); cmd.ExecuteNonQuery(); exito = true; connection.Close(); return(exito); } else { exito = false; } return(exito); }
public static bool CargarStock(Entidades.Stock _stock) { bool exito = false; try { ValidarDatos(_stock); exito = DAO.AgregarDao.InsertarStock(_stock); } catch (Exception ex) { } return(exito); }
public static bool CargarPrecioDeVenta(Entidades.Stock stock) { bool Exito = false; connection.Close(); connection.Open(); string proceso = "CargarPrecioDeVenta"; MySqlCommand cmd = new MySqlCommand(proceso, connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("idProducto_in", stock.idProducto); cmd.Parameters.AddWithValue("PrecioDeVenta_in", stock.PrecioDeVenta); cmd.Parameters.AddWithValue("FechaActual_in", stock.FechaActual); cmd.Parameters.AddWithValue("idUsuario_in", stock.idUsuario); cmd.ExecuteNonQuery(); Exito = true; return(Exito); }
private static void ValidarDatos(Entidades.Stock _stock) { if (_stock.Cantidad == 0) { const string message = "El campo cantidad es obligatorio."; const string caption = "Error"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new Exception(); } if (String.IsNullOrEmpty(_stock.Proveedor)) { const string message = "El campo proveedor es obligatorio."; const string caption = "Error"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new Exception(); } }