private void button1_Click(object sender, EventArgs e) { if (textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "" || comboBox2.Text == "") { MessageBox.Show("Вы не заполнили некоторые поля", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // it need to check name Products = BridgeToBD.LoadProductShopFromDB(TypeBD.SQL); ProductsMoving = BridgeToBD.LoadProductMovingFromDB(TypeBD.SQL); if (!Products.Any(it => it.Name == textBox3.Text)) { ProductShop pr = new ProductShop(); pr.ID = Products.Last().ID + 1; pr.Name = textBox3.Text; pr.PriceSell = (float)Convert.ToDouble(textBox5.Text); pr.PriceBuy = (float)Convert.ToDouble(textBox4.Text); pr.UoM = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text); ProductMoving prmove = new ProductMoving(); prmove.IDproduct = pr.ID; prmove.Sold = 0; if (comboBox2.Text == "Warehouse") { prmove.CountStore = Convert.ToDouble(textBox6.Text); } else if (comboBox2.Text == "Shop") { prmove.CountShop = Convert.ToDouble(textBox6.Text); } else { MessageBox.Show("Некорректно выбран склад"); } Products.Add(pr); ProductsMoving.Add(prmove); //HelperProduct.SaveUsersFromFile(Products); // this.Update(); // it doesn't work //HelperProduct.InsertToSql(pr); BridgeToBD.SaveProductShopToBD(Products, TypeBD.SQL); BridgeToBD.SaveProductMovingToSQL(ProductsMoving); dataGridView1ReLoad(); } else { MessageBox.Show("Товар с таким именем уже есть на складе"); } }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { int id = BridgeToBD.Products.First(it => it.Name == row.Cells[0].Value.ToString()).ID; int id_prmove = BridgeToBD.ProductsMoving.First(it => it.IDproduct == id).ID; BridgeToBD.SaveProductMovingToBD(id_prmove, BridgeToBD.ChoiceBD); BridgeToBD.SaveProductShopToBD(id, BridgeToBD.ChoiceBD); } dataGridView1ReLoad(); } else { MessageBox.Show("Вы не выбрали строку с товаром для удаления", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void button1_Click(object sender, EventArgs e) { if (textBox3.Text == string.Empty) { MessageBox.Show("Вы не заполнили поле 'Название товара'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (comboBox1.Text == string.Empty) { MessageBox.Show("Вы не заполнили поле 'Единицы измерения'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (textBox4.Text == "") { MessageBox.Show("Вы не заполнили поле 'Цена закупки'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (textBox5.Text == "") { MessageBox.Show("Вы не заполнили поле 'Цена продажи'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (textBox6.Text == "") { MessageBox.Show("Вы не заполнили поле 'Количество товара'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (comboBox2.Text == "") { MessageBox.Show("Вы не заполнили поле 'Склад'", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD); if (!BridgeToBD.Products.Any(it => it.Name == textBox3.Text)) { ProductShop pr = new ProductShop(); pr.Name = textBox3.Text; pr.PriceSell = (float)Convert.ToDouble(textBox5.Text); pr.PriceBuy = (float)Convert.ToDouble(textBox4.Text); pr.UoM = (UoM)Enum.Parse(typeof(UoM), comboBox1.Text); ProductMoving prmove = new ProductMoving(); prmove.Sold = 0; if (comboBox2.Text == "Warehouse") { prmove.CountStore = Convert.ToDouble(textBox6.Text); prmove.CountShop = 0; } else if (comboBox2.Text == "Shop") { prmove.CountShop = Convert.ToDouble(textBox6.Text); prmove.CountStore = 0; } else { MessageBox.Show("Некорректно выбран склад"); } BridgeToBD.SaveProductShopToBD(pr, BridgeToBD.ChoiceBD); BridgeToBD.LoadProductShopFromDB(BridgeToBD.ChoiceBD); prmove.IDproduct = BridgeToBD.Products.Last().ID; BridgeToBD.SaveProductMovingToBD(prmove, BridgeToBD.ChoiceBD); dataGridView1ReLoad(); } else { MessageBox.Show("Товар с таким именем уже есть на складе"); } }