public static List<stock> BuscarStockTienda(int tienda) { List<stock> lstStock = new List<stock>(); SqlConnection conn = new SqlConnection(Properties.Settings.Default.inf245g4ConnectionString); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "select p.idproducto, p.nombre 'producto', t.nombre 'tienda', pt.stockActual,pt.stockmax,pt.stockmin from producto p join productoxtienda pt on (p.idproducto = pt.idproducto) join tienda t on (t.idTienda = pt.idTienda) where t.idTienda =" + tienda; cmd.CommandType = CommandType.Text; cmd.Connection = conn; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { stock e = new stock(); e.IdProducto = Convert.ToInt32(reader["idproducto"]); e.Producto = reader["producto"].ToString(); e.Tienda = reader["tienda"].ToString(); e.Stockactual = Convert.ToInt32(reader["stockActual"]); e.Stockmax = Convert.ToInt32(reader["stockmax"]); e.Stockmin = Convert.ToInt32(reader["stockmin"]); lstStock.Add(e); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace.ToString()); } return lstStock; }
public static List<stock> BuscarStockCentral() { List<stock> lstStock = new List<stock>(); SqlConnection conn = new SqlConnection(Properties.Settings.Default.inf245g4ConnectionString); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "select * from producto"; cmd.CommandType = CommandType.Text; cmd.Connection = conn; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { stock e = new stock(); e.IdProducto = Convert.ToInt32(reader["idproducto"]); e.Producto = reader["nombre"].ToString(); e.Tienda = "ALMACEN CENTRAL"; e.Stockactual = reader.IsDBNull(reader.GetOrdinal("stockActual")) ? 0 : Convert.ToInt32(reader["stockActual"]); e.Stockmax = reader.IsDBNull(reader.GetOrdinal("stockmax")) ? 0 : Convert.ToInt32(reader["stockmax"]); e.Stockmin = reader.IsDBNull(reader.GetOrdinal("stockmin")) ? 0 : Convert.ToInt32(reader["stockmin"]); lstStock.Add(e); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace.ToString()); } return lstStock; }