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 btnAcceptEdit_Click(object sender, EventArgs e) { Packages currentPackage = PackagesDB.GetPackageById((int)id); Packages newPackage = new Packages(); bool currentDates = IsValidShippedDate(); if (currentPackage.PkgName == null || currentPackage.PkgDesc == null ) { MessageBox.Show("Fill in name and description before adding package", "Please check"); this.DialogResult = DialogResult.OK; } else if (Validator.IsPresent(txtPkgName) && Validator.IsPresent(txtPkgDesc) && Validator.IsDecimal(txtBasePrice) && Validator.IsDecimal(txtCommission) && currentDates == true) { newPackage.PackageId = currentPackage.PackageId; this.PutPackageData(newPackage); try { if (!PackagesDB.UpdatePackage(currentPackage, newPackage)) { MessageBox.Show("Another user has updated or " + "deleted that package.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { package = newPackage; MessageBox.Show("Package updated", "Success!"); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } this.Close(); } }
private void DisplayPackage() { currentProductSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds((int)id); Packages currentPackage = PackagesDB.GetPackageById((int)id); txtPackageId.Text = currentPackage.PackageId.ToString(); txtPkgName.Text = currentPackage.PkgName; txtPkgDesc.Text = currentPackage.PkgDesc; txtBasePrice.Text = currentPackage.PkgBasePrice.ToString(); DisplayCurrentPackageProductSupplierData(); if (currentPackage.PkgStartDate == null) { dtpStartDate.Text = ""; } else { DateTime startDate = (DateTime)currentPackage.PkgStartDate; dtpStartDate.Text = startDate.ToShortDateString(); } if (currentPackage.PkgEndDate == null) { dtpEndDate.Text = ""; } else { DateTime endDate = (DateTime)currentPackage.PkgEndDate; dtpEndDate.Text = endDate.ToShortDateString(); } if (currentPackage.PkgAgencyCommission.Equals(null)) { txtCommission.Text = ""; } else { txtCommission.Text = Convert.ToDecimal(currentPackage.PkgAgencyCommission).ToString(); } }
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 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()); } } }
// delete item button based on which radio button and item is selected private void btnDelete_Click(object sender, EventArgs e) { if (radPackages.Checked == false && radProducts.Checked == false && radSuppliers.Checked == false) { MessageBox.Show("Please select a database to delete from.", "Select a Database"); } else if (radPackages.Checked) { string i = lstView.SelectedItem.ToString(); string[] s = i.Split('|'); int packageId = Int32.Parse(s[0].Trim()); string nameSelected = s[1].Trim(); currentPackage = PackagesDB.GetPackageById(packageId); DialogResult result = MessageBox.Show("Delete Packages " + nameSelected + "?", "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(packageId); } else { this.DisplayPackages(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else if (radProducts.Checked) { string i = lstView.SelectedItem.ToString(); string[] s = i.Split('|'); int productId = Int32.Parse(s[0].Trim()); string nameSelected = s[1].Trim(); currentProduct = ProductsDB.GetProductById(productId); DialogResult result = MessageBox.Show("Delete Product " + nameSelected + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!ProductsDB.DeleteProduct(currentProduct)) { MessageBox.Show("Another user has updated or deleted " + "that package.", "Database Error"); currentProduct = ProductsDB.GetProductById(productId); } else { this.DisplayProducts(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else if (radSuppliers.Checked) { string i = lstView.SelectedItem.ToString(); string[] s = i.Split('|'); int supplierId = Int32.Parse(s[0].Trim()); string nameSelected = s[1].Trim(); currentSupplier = SuppliersDB.GetSupplierById(supplierId); DialogResult result = MessageBox.Show("Delete Supplier " + nameSelected + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!SuppliersDB.DeleteSupplier(currentSupplier)) { MessageBox.Show("Another user has updated or deleted " + "that package.", "Database Error"); currentSupplier = SuppliersDB.GetSupplierById(supplierId); } else { this.DisplaySuppliers(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }