private void mainForm_Load(object sender, EventArgs e) { packageList = PackagesDB.GetAll(); productList = ProductsDB.GetAll(); supplierList = SupplierDB.ListSupplier(); suppliersContactList = SupplierContactsDB.listSuppliers(); }
// button for filtering the dgv private void btnFilter_Click(object sender, EventArgs e) { try // tries to get datat from the db wuith the filter { suppliersContacts = new List <SupplierContacts>(); suppliersContacts = SupplierContactsDB.listSuppliersByFilter(((Item)cbFilter.SelectedItem).Value, txtFilter.Text); refreshDGV(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
//sets up the form pn load and displays the datagridview private void frmSuppliers_Load(object sender, EventArgs e) { try // tries to get info from the db and refreshes the dgv and loads the combobox { suppliersContacts = SupplierContactsDB.listSuppliers(); refreshDGV(); loadComboBox(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
// btn to delete a record private void btnDelete_Click(object sender, EventArgs e) { if (dgvSuppliers.SelectedRows.Count > 0) { // sets the object to delete int index = dgvSuppliers.SelectedRows[0].Index; suplierContact = suppliersContacts[index]; // asks user if they are sure DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // creates the other table objects Supplier supplier = new Supplier(); List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>(); try // tries to delete the table records { // gets the data for the tasble records that need to be deleted supplier = SupplierDB.GetSupplier(suplierContact.SupplierId); products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId); // deletes each productsuppliers table record foreach (Products_Suppliers ps in products_suppliers) { Products_SuppliersDB.DeleteProdSup(ps); } // deltes the suppliercontacts record SupplierContactsDB.DeleteSup(suplierContact); // deltes the supplier record SupplierDB.DeleteSup(supplier); // redisplays the dgv suppliersContacts = SupplierContactsDB.listSuppliers(); refreshDGV(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else { MessageBox.Show("Please select a Product"); } }
private void editToolStripMenuItem_Click(object sender, EventArgs e) { switch (uxTreeView.SelectedNode.Parent.Name) { case "rootPackages": // open AddEditPackage form with related Package object in Edit mode Package pkg = frmMain.packageList[frmMain.packageList.FindIndex(pk => pk.PkgName == uxTreeView.SelectedNode.Name)]; frmAddModifyPackages frmEditPackage = new frmAddModifyPackages(); frmEditPackage.add = false; frmEditPackage.package = pkg; if (frmEditPackage.ShowDialog() == DialogResult.OK) { RefreshPackages(); // Refresh the Package List and the TreeView Node frmMain.DisplayMessage("The package has been modified successfully."); } break; case "rootProducts": // open AddEditProduct form with related Product object in Edit mode Product prd = frmMain.productList[frmMain.productList.FindIndex(pr => pr.ProdName == uxTreeView.SelectedNode.Name)]; frmProductAddEdit frmEditProduct = new frmProductAddEdit(); frmEditProduct.xNewProduct = false; frmEditProduct.txbProductID.Text = prd.ProductId.ToString(); frmEditProduct.txbProductName.Text = prd.ProdName; if (frmEditProduct.ShowDialog() == DialogResult.OK) { RefreshProducts(); // Refresh the Product List and the TreeView Node frmMain.DisplayMessage("The product has been modified successfully."); } break; case "rootSuppliers": // open AddEditSupplier form with related Supplier object in Edit mode Supplier sp = frmMain.supplierList[frmMain.supplierList.FindIndex(s => s.SupName == uxTreeView.SelectedNode.Name)]; frmAddModifySupplier frmEditSupplier = new frmAddModifySupplier(); frmEditSupplier.add = false; frmEditSupplier.supplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId); if (frmEditSupplier.ShowDialog() == DialogResult.OK) { RefreshSuppliers(); // Refresh the Supplier List and the TreeView Node frmMain.DisplayMessage("The supplier information have been modified successfully."); } break; default: break; } }
// btn to bring up the addmodify form to edit a record private void btnEdit_Click(object sender, EventArgs e) { // checks if there is a record selected if (dgvSuppliers.SelectedRows.Count > 0) { //creates the form and sets the options int index = dgvSuppliers.SelectedRows[0].Index; frmAddModifySupplier editsupplier = new frmAddModifySupplier(); editsupplier.add = false; editsupplier.supplierContact = suppliersContacts[index]; DialogResult result = editsupplier.ShowDialog(); if (result == DialogResult.OK) { try // if the edit for good redisplay the dgv { suplierContact = editsupplier.supplierContact; suppliersContacts = SupplierContactsDB.listSuppliers(); refreshDGV(); // selects the edited record int n = -1; foreach (SupplierContacts sc in suppliersContacts) { if (sc.SupplierContactId == suplierContact.SupplierContactId) { n = suppliersContacts.IndexOf(sc); break; } } dgvSuppliers.Rows[n].Selected = true; //dgvSuppliers.FirstDisplayedScrollingRowIndex = n; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void DeleteSupplier(Supplier sp) { SupplierContacts suplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId); // asks user if they are sure DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // creates the other table objects Supplier supplier = new Supplier(); List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>(); try // tries to delete the table records { // gets the data for the tasble records that need to be deleted supplier = SupplierDB.GetSupplier(suplierContact.SupplierId); products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId); // deletes each productsuppliers table record foreach (Products_Suppliers ps in products_suppliers) { Products_SuppliersDB.DeleteProdSup(ps); } // deletes the suppliercontacts record SupplierContactsDB.DeleteSup(suplierContact); // deletes the supplier record SupplierDB.DeleteSup(supplier); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } RefreshSuppliers(); } }
// button to bring up the addmodify form to add data to the DB private void btnAdd_Click(object sender, EventArgs e) { // creates the new form and sets the options frmAddModifySupplier newaddfrm = new frmAddModifySupplier(); newaddfrm.add = true; DialogResult result = newaddfrm.ShowDialog(); // if the results are good redisplay the dgv if (result == DialogResult.OK) { try // tries to get the data from the db and refresh the dgv { suplierContact = newaddfrm.supplierContact; suppliersContacts = SupplierContactsDB.listSuppliers(); refreshDGV(); // select the newly made record int n = -1; foreach (SupplierContacts sc in suppliersContacts) { if (sc.SupplierContactId == suplierContact.SupplierContactId) { n = suppliersContacts.IndexOf(sc); break; } } dgvSuppliers.Rows[n].Selected = true; dgvSuppliers.FirstDisplayedScrollingRowIndex = n; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
// sets up the form on load private void frmAddModifySupplier_Load(object sender, EventArgs e) { this.LoadProductComboBox(); // does the fiollowing if its a add if (this.add) { // find the next availble supplierid and suppliercontactid supplierContact.SupplierContactId = SupplierContactsDB.GetNextAvailableID(); txtSCID.Text = supplierContact.SupplierContactId.ToString(); supplierContact.SupplierId = SupplierDB.GetNextAvailableID(); supplier.SupplierId = SupplierDB.GetNextAvailableID(); this.Text = "Add a Supplier"; lblTitle.Text = "Add Supplier Information"; cmbProductBName.SelectedIndex = -1; } //else does this for modify else { this.Text = "Modify a Supplier"; lblTitle.Text = "Modify Supplier Information"; try { supplier = SupplierDB.GetSupplier(supplierContact.SupplierId); productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId); this.DisplaySupplier(); this.RedisplayList(); cmbProductBName.SelectedIndex = -1; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
// button for accepting the form private void btnAccept_Click(object sender, EventArgs e) { if (txtCName.IsPresent()) { //for add if (add) { this.createSupplierObjects(); try { SupplierDB.AddSupp(supplier); SupplierContactsDB.AddSupp(supplierContact); foreach (Products_Suppliers ps in productSuppliers) { ps.supplierid = supplier.SupplierId; Products_SuppliersDB.AddProdSupp(ps); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } // for modify else { SupplierContacts newSupplierinfo = new SupplierContacts(); newSupplierinfo.SupplierContactId = Convert.ToInt32(txtSCID.Text); newSupplierinfo.SupConFirstName = txtFirst.Text.ToString(); newSupplierinfo.SupConLastName = txtLast.Text.ToString(); newSupplierinfo.SupConCompany = txtCName.Text.ToString(); newSupplierinfo.SupConAddress = txtAddress.Text.ToString(); newSupplierinfo.SupConCity = txtCity.Text.ToString(); newSupplierinfo.SupConProv = txtProv.Text.ToString(); newSupplierinfo.SupConPostal = txtPO.Text.ToString(); newSupplierinfo.SupConCountry = txtCountry.Text.ToString(); newSupplierinfo.SupConBusPhone = txtPhone.Text.ToString(); newSupplierinfo.SupConFax = txtFax.Text.ToString(); newSupplierinfo.SupConEmail = txtEmail.Text.ToString(); newSupplierinfo.SupConURL = txtURL.Text.ToString(); newSupplierinfo.AffiliationId = ""; newSupplierinfo.SupplierId = Convert.ToInt32(txtSCID.Text); try { if (!SupplierContactsDB.UpdateSupplier(supplierContact, newSupplierinfo)) { MessageBox.Show("That Supplier has been updated or deleted already.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { supplierContact = newSupplierinfo; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }