// button the add the data to the DB private void btnAccept_Click(object sender, EventArgs e) { if (isValid()) { if (add) { package = this.createPackageObjects(); try { package.PackageId = PackagesDB.AddPackage(package); foreach (Packages_Products_Suppliers ps in pack_prod_sup) { ps.PackageId = package.PackageId; Packages_Products_SuppliersDB.AddPackProdSupp(ps); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Package newPackage = new Package(); newPackage = this.createPackageObjects(); try { if (!PackagesDB.UpdatePackage(package, newPackage)) { MessageBox.Show("That Package has been updated or deleted already.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { package = newPackage; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
// button to add a product supplier to the package private void btnProduct_Click(object sender, EventArgs e) { if (cmbProductBName.IsPresent()) { if (add) { Packages_Products_Suppliers product = new Packages_Products_Suppliers(); product.ProductSupplierId = (int)cmbSuppliers.SelectedValue; product.ProdName = cmbProductBName.Text; product.SupName = cmbSuppliers.Text; pack_prod_sup.Add(product); RedisplayList(); cmbProductBName.SelectedIndex = -1; cmbSuppliers.SelectedIndex = -1; } else { Packages_Products_Suppliers product = new Packages_Products_Suppliers(); product.ProductSupplierId = (int)cmbSuppliers.SelectedValue; product.ProdName = cmbProductBName.Text; product.SupName = cmbSuppliers.Text; product.PackageId = package.PackageId; try { Packages_Products_SuppliersDB.AddPackProdSupp(product); pack_prod_sup = Packages_Products_SuppliersDB.GetList(package.PackageId); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } RedisplayList(); cmbProductBName.SelectedIndex = -1; } } }