/// <summary> /// Add selected product to package in detail view /// </summary> /// @author Harry private void btnAddProdToPkg_Click(object sender, EventArgs e) { if (cmboBoxSupsOfProd.SelectedIndex > -1) // selection required { // get product and supplier ids (to get ProductSupplierId) int prodId = products[cmboBoxProducts.SelectedIndex].ProductID; int supplierId = suppliersOfProd[cmboBoxSupsOfProd.SelectedIndex].SupplierId; try { // get product supplier id int prodSuppId = ProductSupplierDB.GetId(prodId, supplierId); // create new package product supplier object to enter into package products suppliers table PackageProductSupplier newPkgProdSup = new PackageProductSupplier(); newPkgProdSup.PackageId = Convert.ToInt32(packageIdTextBox.Text); newPkgProdSup.ProductSupplierId = prodSuppId; // update packages product supplier table bool success = PackageProductSupplierDB.AddNewPkgProdSupp(newPkgProdSup); if (success) { // clear combo boxes cmboBoxProducts.Items.Clear(); cmboBoxSupsOfProd.Items.Clear(); // show updated version of products associated with package List <string> pkgProducts; List <string> pkgProdSupps; // access products and suppliers associated with current package PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps); ShowPkgProducts(pkgProducts, pkgProdSupps); ShowAllProducts(); cmboBoxSupsOfProd.Text = ""; cmboBoxProducts.Text = ""; cmboBoxSupsOfProd.Items.Clear(); MessageBox.Show("Added product successfully.", "Success"); } else { // clear combo boxes cmboBoxProducts.Items.Clear(); cmboBoxSupsOfProd.Items.Clear(); MessageBox.Show("Error occured while adding product.", "Failure"); } } catch (Exception ex) { MessageBox.Show("Error while adding product to package\n" + ex.Message, ex.GetType().ToString()); } } else { MessageBox.Show("Please select a product and its supplier.", "Select Error"); } }
/// <summary> /// Fill packages detail view with the last package (by package id). /// </summary> /// @author Harry private void btnSkpToEnd_Click(object sender, EventArgs e) { // list of products associated with current package in detail view in packages tab List <string> pkgProducts; // list of supplier names of the products associated with package in detail view in packages tab List <string> pkgProdSupps; pkgPos = packages.Count - 1; ShowPackages(); // access products and suppliers associated with current package PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps); ShowPkgProducts(pkgProducts, pkgProdSupps); }
/// <summary> /// Show add form /// </summary> /// @author Harry private void btnAddPkg_Click(object sender, EventArgs e) { frmAddPkg addPkg = new frmAddPkg(); // show add new package form DialogResult addPkgResult = addPkg.ShowDialog(); if (addPkgResult == DialogResult.OK) { // set view to new package packages = PackageDB.GetPackages(); pkgPos = packages.Count - 1; ShowPackages(); // access products and suppliers associated with current package PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps); ShowPkgProducts(pkgProducts, pkgProdSupps); } }
// Load data for main form (first tab - Packages). private void loadMainFormData() { try { // access packages from db in thread (ASYNCHRONOUS) - Probably uneccessary /*Thread pkgWork = new Thread(() => * Thread pkgWork = new Thread(() => * { * packages = PackageDB.GetPackages(); * }); * * // access all products from db in thread * Thread prodWork = new Thread(() => * { * products = ProductsDB.GetAllProducts(); * }); * * pkgWork.Start(); * prodWork.Start(); * * pkgWork.Join(); * prodWork.Join();*/ packages = PackageDB.GetPackages(); products = ProductsDB.GetAllProducts(); // access products and suppliers associated with current package PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps); ShowPackages(); ShowAllProducts(); ShowPkgProducts(pkgProducts, pkgProdSupps); } catch (Exception ex) { MessageBox.Show("Error while loading data.\n\n" + ex.Message, ex.GetType().ToString()); } }
/// <summary> /// Fill packages detail view with next package (by package id) /// wrap to first package if current package is the last. /// </summary> /// @author Harry private void btnNext_Click(object sender, EventArgs e) { // list of products associated with current package in detail view in packages tab List <string> pkgProducts; // list of supplier names of the products associated with package in detail view in packages tab List <string> pkgProdSupps; // wrap around if current package is the first. if (pkgPos == packages.Count - 1) { pkgPos = 0; } else { pkgPos++; } ShowPackages(); // access products and suppliers associated with current package PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps); ShowPkgProducts(pkgProducts, pkgProdSupps); }