private void buttonUpdate_Click(object sender, EventArgs e) { bool isAvailable; if (radioButtonYes.Checked == true) { isAvailable = true; } else { isAvailable = false; } ProductDao productDao = new ProductDao(); productDao.setNameOfTheProduct(textBoxName1.Text); productDao.setCompanyNameOfAProduct(textBoxCompany1.Text); productDao.setPriceOfAProduct(Convert.ToInt32(textBoxPrice1.Text)); productDao.setAvailable(isAvailable); if (ID != "") { if (textBoxName1.Text.Trim() == string.Empty || textBoxPrice1.Text.Trim() == string.Empty || textBoxCompany1.Text.Trim() == string.Empty) { MessageBox.Show("Please fill every field!", "Required field", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { productDao.Update(productDao, textBoxOldName.Text); ShowUpdatings(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Please first select product from table", "Selection", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (ID != "") { try { ProductDao productDao = new ProductDao(); productDao.Delete(this.textBoxOldName.Text); ShowUpdatings(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { MessageBox.Show("Please first select product from table", "Selection", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { DataTable table = new DataTable(); bool isAvailable; if (radioButtonYes.Checked == true) { isAvailable = true; } else { isAvailable = false; } ProductDao productDao = new ProductDao(); productDao.setNameOfTheProduct(textBoxNameAdd.Text); productDao.setCompanyNameOfAProduct(textBoxCompany.Text); productDao.setPriceOfAProduct(Convert.ToInt32(textBoxPrice.Text)); productDao.setAvailable(isAvailable); if (textBoxNameAdd.Text.Trim() == string.Empty || textBoxPrice.Text.Trim() == string.Empty || textBoxCompany.Text.Trim() == string.Empty) { MessageBox.Show("Please fill all the fields!", "Required field", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command2 = new MySqlCommand("SELECT * FROM `product` WHERE `name` = @name", db.GetConnection()); command2.Parameters.Add("@name", MySqlDbType.VarChar).Value = productDao.getNameOfTheProduct(); adapter.SelectCommand = command2; adapter.Fill(table); if (table.Rows.Count > 0) { MessageBox.Show("We already have this product in database", "Product information", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { productDao.Insert(productDao); ShowUpdatings(); } } }