// DELETE a supplier to current product click private void btnRemove_Click(object sender, EventArgs e) { string i = lstSuppliers.SelectedItem.ToString(); string[] s = i.Split('|'); int prodSupId = Int32.Parse(s[0].Trim()); Products_Suppliers productsSuppliers = new Products_Suppliers(); if (prodSupId < 1) // no selection { MessageBox.Show("Please select supplier to add"); } else // user selected a product to add { try { this.DialogResult = DialogResult.OK; Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(prodSupId); Products_SuppliersDB.DeleteProductSupplier(ps); MessageBox.Show("Supplier deleted", "Success!"); loadData(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
private void btnAdd_Click(object sender, EventArgs e) { int index = cboProducts.SelectedIndex; int prodId = productsList[index].ProductId; Products_Suppliers productsSuppliers = new Products_Suppliers(); if (prodId < 1) // no selection { MessageBox.Show("Please select supplier to add"); } else // user selected a product to add { try { int ProductSupplierId = Products_SuppliersDB.AddSupplierById(prodId, (int)supId); MessageBox.Show("Product deleted", "Success!"); this.DialogResult = DialogResult.OK; Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(ProductSupplierId); // selected product //add selected product currentProductSupplierIds.Add(ps); // add to current product supplier list loadData(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } //DisplayCurrentPackageProductSupplierData(); } }
// ADD a supplier to current product click private void btnAdd_Click(object sender, EventArgs e) { int index = cboSupplier.SelectedIndex; int supId = suppliersList[index].SupplierId; Products_Suppliers productsSuppliers = new Products_Suppliers(); if (supId < 1) { MessageBox.Show("Please select supplier to add"); } else { try { int ProductSupplierId = Products_SuppliersDB.AddSupplierById((int)prodId, supId); MessageBox.Show("Supplier added", "Success!"); this.DialogResult = DialogResult.OK; Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(ProductSupplierId); currentProductSupplierIds.Add(ps); DisplayProductSupplier(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (lstProdSup.SelectedIndex < 0) // no selection { MessageBox.Show("Please select product supplier to add"); } else { Packages currentPackage = PackagesDB.GetPackageById((int)id); string i = lstProdSup.SelectedItem.ToString(); string[] s = i.Split('|'); int prodSupId = Int32.Parse(s[0].Trim()); Products_Suppliers selectedProductSupplier = Products_SuppliersDB.GetProductSupplierById(prodSupId); try { if (!Packages_Products_SuppliersDB.AddPackageProductSupplier(currentPackage.PackageId, selectedProductSupplier.ProductSupplierId)) { MessageBox.Show("Product added", "Success!"); this.DialogResult = DialogResult.OK; DisplayPackage(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
private void DisplayProductSupplierData() { productSupplierIds = Products_SuppliersDB.GetProductSupplierIds(); lstProdSup.Items.Clear(); lstProdSup.Items.Add("Id " + ": " + "Product Name" + ", " + "Supplier Name"); foreach (int id in productSupplierIds) { Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(id); lstProdSup.Items.Add(ps); } }
private void btnDelete_Click(object sender, EventArgs e) { int index = lstPackProdSupp.SelectedIndex; string i = lstPackProdSupp.SelectedItem.ToString(); string[] s = i.Split('|'); int pid = Int32.Parse(s[0].Trim()); //Packages_Products_Suppliers currentPackage = Packages_Products_SuppliersDB.GetPackageIds if (pid < 1) // no selection { MessageBox.Show("Please select product supplier to delete"); } else // user selected a product to delete { if (type == "View") { Products_Suppliers pps = Products_SuppliersDB.GetProductSupplierById(pid); // selected product DialogResult answer = MessageBox.Show("Are you sure to delete " + pps.ProdName + "?", "Please Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (answer == DialogResult.Yes) { //delete selected package product supplier try { if (!Packages_Products_SuppliersDB.DeletePackageProductSupplier((int)id, pps.ProductSupplierId)) { MessageBox.Show("Another user has updated or deleted " + "that product.", "Database Error"); } else { currentProductSupplierIds.RemoveAt(index - 1); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } // remove from the current product supplier list DisplayCurrentPackageProductSupplierData(); } } } }
private void DisplayCurrentPackageProductSupplierData() { if (productSupplierIds != null) // if we have product suppliers to display { lstProductSupplierId.Items.Clear(); //start with empty list box lstProductSupplierId.Items.Add("Id " + ": " + "Product Name" + ", " + "Supplier Name"); foreach (int id in productSupplierIds) { Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(id); lstProductSupplierId.Items.Add(ps); } } else // null this product does not exist - need to refresh combo box { packageIds = Packages_Products_SuppliersDB.GetPackageIds(); } }
// display ProductSupplier attached to package by DB method, passing through the packageID inherited from main form private void DisplayCurrentPackageProductSupplierData() { if (currentProductSupplierIds != null) // if we have product suppliers to display { lstPackProdSupp.Items.Clear(); //start with empty list box lstPackProdSupp.Items.Add("Id " + ": " + "Product Name" + ", " + "Supplier Name"); foreach (int id in currentProductSupplierIds) { Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById((int)id); lstPackProdSupp.Items.Add(ps); } } else { lstPackProdSupp.Items.Clear(); } }
private void btnDelete_Click(object sender, EventArgs e) { string tableName = cboTableNames.SelectedValue.ToString(); if (tableName == "Products") { DialogResult result = MessageBox.Show("Delete " + currentProd.ProdName + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!ProductsDB.DeleteProduct(currentProd)) { MessageBox.Show("Another user has updated or deleted " + "that product.", "Database Error"); currentProd = ProductsDB.GetProductById(currentProd.ProductId); if (currentProd != null) { this.DisplayProductData(); } } else { this.DisplayProductData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else if (tableName == "Suppliers") { DialogResult result = MessageBox.Show("Delete " + currentSupplier.SupName + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!SuppliersDB.DeleteSupplier(currentSupplier)) { MessageBox.Show("Another user has updated or deleted " + "that supplier.", "Database Error"); currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId); if (currentSupplier != null) { this.DisplaySupplierData(); } } else { this.DisplaySupplierData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else if (tableName == "Products_Suppliers") { DialogResult result = MessageBox.Show("Delete Product Supplier " + currentProductSupplier.ProductSupplierId + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!Products_SuppliersDB.DeleteProductSupplier(currentProductSupplier)) { MessageBox.Show("Another user has updated or deleted " + "that product_supplier.", "Database Error"); currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId); if (currentProductSupplier != null) { this.DisplayCurrentProductSupplierData(); } this.DisplayProductSupplierData(); } else { this.DisplayCurrentProductSupplierData(); } this.DisplayProductSupplierData(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else if (tableName == "Packages") { DialogResult result = MessageBox.Show("Delete Packages " + currentPackage.PkgName + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!PackagesDB.DeletePackage(currentPackage)) { MessageBox.Show("Another user has updated or deleted " + "that package.", "Database Error"); currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId); if (currentPackage != null) { //this.DisplayCurrentProductSupplierData(); this.DisplayProductSupplierData(); } } else { //this.DisplayCurrentProductSupplierData(); this.DisplayPackages(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btnUpdate_Click(object sender, EventArgs e) { string tableName = cboTableNames.SelectedValue.ToString(); if (tableName == "Products") { frmAddUpdateProducts updateProductForm = new frmAddUpdateProducts(); updateProductForm.addProduct = false; updateProductForm.product = currentProd; DialogResult result = updateProductForm.ShowDialog(); if (result == DialogResult.OK) { currentProd = updateProductForm.product; this.DisplayProductData(); } else if (result == DialogResult.Retry) { currentProd = ProductsDB.GetProductById(currentProd.ProductId); if (currentProd != null) { this.DisplayProductData(); } } } else if (tableName == "Suppliers") { frmAddUpdateSuppliers updateSupplierForm = new frmAddUpdateSuppliers(); updateSupplierForm.addSupplier = false; updateSupplierForm.supplier = currentSupplier; DialogResult result = updateSupplierForm.ShowDialog(); if (result == DialogResult.OK) { currentSupplier = updateSupplierForm.supplier; this.DisplaySupplierData(); } else if (result == DialogResult.Retry) { currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId); if (currentSupplier != null) { this.DisplaySupplierData(); } } } else if (tableName == "Products_Suppliers") { frmAddUpdateProductSupplier updateProductSupplierForm = new frmAddUpdateProductSupplier(); updateProductSupplierForm.addProductSupplier = false; updateProductSupplierForm.productSupplier = currentProductSupplier; DialogResult result = updateProductSupplierForm.ShowDialog(); if (result == DialogResult.OK) { this.DisplayCurrentProductSupplierData(); this.DisplayProductSupplierData(); } else if (result == DialogResult.Retry) { currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId); if (currentProductSupplier != null) { this.DisplayCurrentProductSupplierData(); } this.DisplayProductSupplierData(); } } else if (tableName == "Packages") { frmAddUpdatePackages updatePackageForm = new frmAddUpdatePackages(); updatePackageForm.addPackage = false; updatePackageForm.package = currentPackage; updatePackageForm.currentProductSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(currentPackage.PackageId); DialogResult result = updatePackageForm.ShowDialog(); if (result == DialogResult.OK) { this.DisplayPackages(); DisplayCurrentPackageProductSupplierData(); } else if (result == DialogResult.Retry) { currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId); if (currentPackage != null) { DisplayCurrentPackageProductSupplierData(); } this.DisplayPackages(); } } }
private void DisplayCurrentProductSupplierData() { currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId); txtName.Text = currentProductSupplier.ProdName; txtName2.Text = currentProductSupplier.SupName; }
private void cboId_SelectedIndexChanged(object sender, EventArgs e) { string tableName = cboTableNames.SelectedValue.ToString(); if (tableName == "Products") { int selectedID = (int)cboId.SelectedValue; lblName.Text = "Product Name"; try { currentProd = ProductsDB.GetProductById(selectedID); DisplayCurrentProductData(); } catch (Exception ex) { MessageBox.Show("Error while retrieving product with selected ID: " + ex.Message, ex.GetType().ToString()); } } else if (tableName == "Suppliers") { int selectedID = (int)cboId.SelectedValue; lblName.Text = "Supplier Name"; try { currentSupplier = SuppliersDB.GetSupplierById(selectedID); DisplayCurrentSupplierData(); } catch (Exception ex) { MessageBox.Show("Error while retrieving supplier with selected ID: " + ex.Message, ex.GetType().ToString()); } } else if (tableName == "Products_Suppliers") { int selectedID = (int)cboId.SelectedValue; try { currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(selectedID); DisplayCurrentProductSupplierData(); } catch (Exception ex) { MessageBox.Show("Error while retrieving product supplier with selected ID: " + ex.Message, ex.GetType().ToString()); } } else if (tableName == "Packages_Products_Suppliers") { int selectedID = (int)cboId.SelectedValue; try { productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID); DisplayCurrentPackageProductSupplierData(); } catch (Exception ex) { MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message, ex.GetType().ToString()); } } else if (tableName == "Packages") { int selectedID = (int)cboId.SelectedValue; lblName.Text = "Package Name"; try { productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID); DisplayCurrentPackageProductSupplierData(); } catch (Exception ex) { MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message, ex.GetType().ToString()); } try { currentPackage = PackagesDB.GetPackageById(selectedID); txtName.Text = currentPackage.PkgName; } catch (Exception ex) { MessageBox.Show("Error while retrieving package with selected ID: " + ex.Message, ex.GetType().ToString()); } } }