private void btn_Save_Click(object sender, EventArgs e) { if (CheckForm()) { Product product = FormToProduct(); ProductArr productArr = new ProductArr(); productArr.Fill(); if (product.Id == 0) { if (!productArr.IsContainLicenseNumber(txt_LicenseNumber.Text)) { if (product.Insert()) { MessageBox.Show("Data saved successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); productArr.Fill(); product = productArr.GetProductWithMaxId(); ProductArrToForm(product); } } else { MessageBox.Show("License Number already exsits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (product.Update()) { MessageBox.Show("Data updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearForm(); ProductArrToForm(null); } } } }
private void Save(object sender, EventArgs e) { if (!CheckGood()) { MessageBox.Show("You didn't write right", "TRY AGAIN", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); All_White(); } else { Product product = FormToProduct(); ProductDetailsArr productDetailsArr_new; ProductDetailsArr productDetailsArr_old = new ProductDetailsArr(); ProductArr productArr_new = new ProductArr(); productArr_new.Fill(); if (product.ID == 0) { if (product.Insert()) { ProductArr productArr = new ProductArr(); productArr.Fill(); product = productArr.GetProductWithMaxId(); productDetailsArr_new = FormToProductDetailsArr(product); productDetailsArr_new.Insert(); CategoryProductArr categoryProductArr = productDetailsArr_new.GetCategoryProductArr(); categoryProductArr.Update(); MessageBox.Show("Products Details Saved"); CleanForm(); ProductArrToForm(); CategoryProductArrToForm(); } else { MessageBox.Show("Cannot Save Products Details"); } } else { if (product.Update()) { productDetailsArr_new = FormToProductDetailsArr(product); productDetailsArr_old.Fill(); productDetailsArr_old = productDetailsArr_old.Filter(product); productDetailsArr_old.Delete(); productDetailsArr_new.Insert(); //(listBox_category_choosed.DataSource as CategoryProductArr).Update(); //(listBox_category_potential.DataSource as CategoryProductArr).Update(); MessageBox.Show("Products Details UPDATED"); CleanForm(); ProductArrToForm(); } else { MessageBox.Show("Cannot UPDATE Products Details"); } } } }