private void actualizadtgIngredientes(int id_plato) { PlatoBLL plBLL = new PlatoBLL(); DataTable DtIngredientesNecesarios = new DataTable(); DtIngredientesNecesarios = plBLL.GetIngredientesPlato(id_plato); bool coincide; foreach (DataRow ingNec in DtIngredientesNecesarios.Rows) { double cantidadNecesaria = double.Parse(ingNec[2].ToString()) * Int32.Parse(txtCantidad.Text); int id_ingredienteNec = Int32.Parse(ingNec[1].ToString()); string nombre = ingNec[3].ToString(); coincide = false; foreach (DataRow row in IngredientesAEnviar.Rows) { int id_ingrediente = Int32.Parse(row["id"].ToString()); if (id_ingrediente == id_ingredienteNec) { row["cantidad"] = double.Parse(row["cantidad"].ToString()) + cantidadNecesaria; dtgIngEnviar.ItemsSource = IngredientesAEnviar.DefaultView; coincide = true; break; } } if (!coincide) { DataRow row = IngredientesAEnviar.NewRow(); row["id"] = id_ingredienteNec; row["nombre"] = nombre; row["cantidad"] = cantidadNecesaria; IngredientesAEnviar.Rows.Add(row); dtgIngEnviar.ItemsSource = IngredientesAEnviar.DefaultView; } } }
private void CbPlatos_SelectionChanged(object sender, SelectionChangedEventArgs e) { int id_plato = Int32.Parse(cbPlatos.SelectedValue.ToString()); Ing1Plato.Clear(); PlatoBLL plBLL = new PlatoBLL(); DataTable DtIngredientesNecesarios = new DataTable(); DtIngredientesNecesarios = plBLL.GetIngredientesPlato(id_plato); foreach (DataRow row in DtIngredientesNecesarios.Rows) { DataRow line = Ing1Plato.NewRow(); line["Nombre"] = row[3]; line["Cantidad"] = row[2]; Ing1Plato.Rows.Add(line); } dtgingredientes1plato.ItemsSource = Ing1Plato.DefaultView; }
private void BtnAgregar_Click(object sender, RoutedEventArgs e) { try { int idplato = Int32.Parse(cbPlatos.SelectedValue.ToString()); DataTable DtIngredientesNecesarios = new DataTable(); DataTable IngredientesTemporal = ingredientesDT; PlatoBLL plBLL = new PlatoBLL(); DtIngredientesNecesarios = plBLL.GetIngredientesPlato(idplato); bool estadoComprovacion = true; if (Int32.Parse(txtCantidad.Text) > 0) { foreach (DataRow ingNec in DtIngredientesNecesarios.Rows) { double cantidadNecesaria = double.Parse(ingNec[2].ToString()) * Int32.Parse(txtCantidad.Text); int id_ingredienteNec = Int32.Parse(ingNec[1].ToString()); foreach (DataRow row in IngredientesTemporal.Rows) { string prueba1 = row[0].ToString(); string prueba2 = row[1].ToString(); string prueba3 = row[2].ToString(); int id_ingrediente = Int32.Parse(row[0].ToString()); if (id_ingrediente == id_ingredienteNec) { double stockActual = double.Parse(row[2].ToString()); if (cantidadNecesaria > stockActual) { MessageBox.Show("Insuficiente Stock de: " + prueba2); estadoComprovacion = false; break; } row[2] = stockActual - cantidadNecesaria; } } if (estadoComprovacion == false) { break; } } if (estadoComprovacion) { MessageBox.Show("Se ha agregado el plato"); ingredientesDT = IngredientesTemporal; dtgIngredientesDisp.ItemsSource = IngredientesTemporal.DefaultView; actualizadtgIngredientes(idplato); actualizardtgplatos(idplato, int.Parse(txtCantidad.Text)); } else { dtgIngredientesDisp.ItemsSource = ingredientesDT.DefaultView; } } else { lb1.Content = "Ingrese una cantidad mayor a 0"; } } catch { } }