public static void GetDishWithComponent(List <DishWithComponent> list) // Получение списка блюд с составом { connect = new NpgsqlConnection(connString); connect.Open(); NpgsqlCommand command = new NpgsqlCommand("SELECT dishname, price, " + "weight, category FROM public.dish", connect); using (command) { using (NpgsqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DishWithComponent item = new DishWithComponent(); item.name = reader[0].ToString(); item.price = Convert.ToInt32(reader[1]); item.weight = Convert.ToInt32(reader[2]); item.category = reader[3].ToString(); item.productList = new List <Product>(); list.Add(item); } } } for (int i = 0; i < list.Count; i++) { NpgsqlCommand command1 = new NpgsqlCommand("SELECT productname, countprod FROM " + "public.dishcomponent WHERE dishname = '" + list[i].name + "'", connect); using (command1) { using (NpgsqlDataReader reader = command1.ExecuteReader()) { while (reader.Read()) { Product prod = new Product(); prod.name = reader[0].ToString(); prod.count = Convert.ToDouble(reader[1]); list[i].productList.Add(prod); } } } } connect.Close(); }
private void Button4_Click(object sender, EventArgs e) { string price = textBox6.Text.Trim(); bool isPrice = false; if (price.Length != 0) { isPrice = int.TryParse(price, out _); } string weight = textBox7.Text.Trim(); bool isWeight = false; if (weight.Length != 0) { isWeight = int.TryParse(weight, out _); } if (textBox2.Text.Length > 3) { if (isPrice) { if (isWeight) { if (comboBox2.SelectedItem != null) { if (listView1.Items.Count != 0) { Functions.AddDish(textBox2.Text, Convert.ToDouble(textBox6.Text), Convert.ToDouble(textBox7.Text), comboBox2.Text, productList); Functions.UpdateConnect(); DishWithComponent item = new DishWithComponent(); item.name = textBox2.Text; item.price = Convert.ToInt32(textBox6.Text); item.weight = Convert.ToInt32(textBox7.Text); item.category = comboBox2.Text; item.productList = new List <Product>(); dishList.Add(item); for (int i = 0; i < productList.Count; i++) { Product prod = new Product(); prod.name = productList[i].name; prod.count = productList[i].count; dishList[dishList.Count - 1].productList.Add(prod); } string[] items = { item.name, item.price.ToString(), item.weight.ToString(), item.category }; listView3.Items.Add(new ListViewItem(items)); ClearDishBoxes(); panel6.Visible = true; panel6.BringToFront(); aTimer.Interval = 1000; aTimer.Tick += new EventHandler(OnTimeEvent); aTimer.Start(); } else { label25.Visible = true; listView1.BackColor = Color.FromArgb(255, 192, 192); comboBox4.BackColor = Color.FromArgb(255, 192, 192); } } else { label24.Visible = true; comboBox2.BackColor = Color.FromArgb(255, 192, 192); } } else { label23.Visible = true; textBox7.BackColor = Color.FromArgb(255, 192, 192); } } else { label22.Visible = true; textBox6.BackColor = Color.FromArgb(255, 192, 192); } } else { label21.Visible = true; textBox2.BackColor = Color.FromArgb(255, 192, 192); } }