// Adds Supplier by name to the list of suppliers and appends it to the DB private void btnAddSuppliers_Click(object sender, EventArgs e) { // get input supplier.Text and append to list and then DB if (Validator.IsProvided(txtSuppliers, "Supplier Name")) { string supplier = txtSuppliers.Text.ToUpper(); bool valid = true; foreach (Supplier createdSup in suppliers) { if (createdSup.SupName == supplier) { MessageBox.Show(supplier + " already exists"); valid = false; break; } } if (valid) { Supplier sup = new Supplier(); sup.SupName = supplier; sup.SupplierId = SupplierDB.AddSupplier(sup); suppliers = SupplierDB.GetSuppliers(); displaySuppliers(); listSuppliers(); txtSuppliers.Clear(); MessageBox.Show(supplier + " was added"); } } }
// METHOD WHICH BUILDS LIST OF SUPPLIER-ID PAIRS public static List <Supplier> createSupplierIdPairsList(int prodID) { List <Supplier> list = null; list = SupplierDB.supplierIdPairsList(prodID); return(list); }
private void btnSaveSupplier_Click(object sender, EventArgs e) { if (Validator.IsPresent(txtModifySupplier)) { string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem); string editedSup = txtModifySupplier.Text; if (selectedSup != editedSup) { DialogResult update = MessageBox.Show("Change '" + selectedSup + "' to '" + editedSup + "'?" , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (update == DialogResult.OK) { SupplierDB.UpdateSupplier(selectedSup, editedSup); // Refresh table adapter to display updated list this.frmModifyProductSupplier_Load(this, null); lstSupplierList.GetItemText(lstSupplierList.SelectedItem); // Select the item that was just updated int index = lstSupplierList.FindString(editedSup, -1); if (index != -1) { lstSupplierList.SetSelected(index, true); } } } } }
private void btnDelelteSupClick_Click(object sender, EventArgs e) { Supplier delSupplier = suppliers[supplierDataGridView.CurrentCell.RowIndex]; if (delSupplier != null) { DialogResult result = MessageBox.Show("Are you sure you want to delete " + delSupplier.SupplierName + " supplier ID " + delSupplier.SupplierID + "? ", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { try { SupplierDB.DeleteSupplier(delSupplier); suppliers = SupplierDB.GetAllSuppliers(); supplierDataGridView.DataSource = suppliers; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else { MessageBox.Show("Please select a supplier to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RefreshSuppliers() { frmMain.supplierList = null; frmMain.supplierList = SupplierDB.ListSupplier(); PopulateTreeNode("rootSuppliers"); PopulateViewer("rootSuppliers"); }
private void mainForm_Load(object sender, EventArgs e) { packageList = PackagesDB.GetAll(); productList = ProductsDB.GetAll(); supplierList = SupplierDB.ListSupplier(); suppliersContactList = SupplierContactsDB.listSuppliers(); }
// Delete a selected item for both the products and suppliers tab private void btnDelete_Click(object sender, EventArgs e) { if (tabModifyProductSupplier.SelectedTab == tabProduct) // Delete objects for the product tab { string selectedProd = lstProductList.GetItemText(lstProductList.SelectedItem); var deleteList = string.Join("\n", ProductDB.GetDeleteList(selectedProd)); DialogResult delProd = MessageBox.Show("Are you sure you want to delete '" + selectedProd + "'?\n\n" + "You will also be deleting the following links to this product:\n" + deleteList, "Confirm Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (delProd == DialogResult.OK) // Delete if dialog result is OK { ProductDB.DeleteProductName(selectedProd); // Delete the product this.frmModifyProductSupplier_Load(this, null); // Refresh the page } } else if (tabModifyProductSupplier.SelectedTab == tabSupplier) // Delete objects for the supplier tab { string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem); var deleteList = string.Join("\n", SupplierDB.GetDeleteList(selectedSup)); DialogResult delProd = MessageBox.Show("Are you sure you want to delete '" + selectedSup + "'?\n\n" + "You will also be deleting the following links to this supplier:\n" + deleteList, "Confirm Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (delProd == DialogResult.OK) // Delete if dialog result is OK { SupplierDB.DeleteSupplierName(selectedSup); // Delete the selected supplier this.frmModifyProductSupplier_Load(this, null); // Refresh the page } } }
// call delete function for the supplier selected and set a confirmation box. private void btnDeleteSupplier_Click(object sender, EventArgs e) { string selectedSupplier = lbSuppliers.SelectedItem.ToString(); var confirmDelete = MessageBox.Show("Are you sure you want to delete " + selectedSupplier + "?", "Confirm?", MessageBoxButtons.YesNo); if (confirmDelete == DialogResult.Yes) { try { SupplierDB.DeleteSupplier(selectedSupplier); MessageBox.Show(selectedSupplier + " was deleted"); } catch { MessageBox.Show(selectedSupplier + " could not be deleted, contact the administrator"); } displaySuppliers(); listSuppliers(); cbSuppliers.SelectedIndex = -1; cbSuppliers.Text = ""; } else { MessageBox.Show(selectedSupplier + " was not deleted"); } }
// Save button for the suppliers tab private void btnSaveSupplier_Click(object sender, EventArgs e) { string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem); string editedSup = txtModifySupplier.Text; // Validation to see if the typed item is already in the list int index = lstSupplierList.FindString(editedSup, -1); if (editedSup != "" && index != -1) { MessageBox.Show("Warning: Supplier already exists.", "Duplicate Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // Test for saving or editing if (lstSupplierList.Enabled == false && editedSup != "") { DialogResult result = MessageBox.Show("Save '" + editedSup + "' as a new supplier?", "Confirm Add", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { SupplierDB.AddSupplierName(editedSup); this.frmModifyProductSupplier_Load(this, null); // Select the item that was just saved SelectItem(editedSup, lstSupplierList); } } else if (lstSupplierList.Enabled == false && editedSup == "") { MessageBox.Show("Please enter a new supplier name.", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtModifySupplier.Focus(); } else if (lstSupplierList.Enabled == true && selectedSup != editedSup) { DialogResult update = MessageBox.Show("Change '" + selectedSup + "' to '" + editedSup + "'?" , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (update == DialogResult.OK) { SupplierDB.UpdateSupplier(selectedSup, editedSup); // Refresh table adapter to display updated list this.frmModifyProductSupplier_Load(this, null); lstSupplierList.GetItemText(lstSupplierList.SelectedItem); // Select the item that was just updated SelectItem(editedSup, lstSupplierList); } } else if (lstSupplierList.Enabled == true && selectedSup == "") { MessageBox.Show("Please select a supplier name to edit.", "Item Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtModifySupplier.Focus(); } } }
// display lsit box of supplies private void displaySuppliers() { suppliers = SupplierDB.GetSuppliers(); lbSuppliers.Items.Clear(); // take all the suppliers from list and display it in the list box foreach (Supplier supplier in suppliers) { lbSuppliers.Items.Add(supplier.SupName); } }
private void Form1_Load(object sender, EventArgs e) { //add panels in product tab listPanelProduct.Add(panelProductAdd); listPanelProduct.Add(panelProductEdit); //add panels of package tab listPanelPackage.Add(panelAddPkg); listPanelPackage.Add(panelEditPkg); //add panels of supplier tab listPanelSupplier.Add(panelAddSupplier); listPanelSupplier.Add(panelEditSupplier); //hide all panels when form loads panelProductAdd.Visible = false; panelProductEdit.Visible = false; panelAddPkg.Visible = false; panelEditPkg.Visible = false; panelAddSupplier.Visible = false; panelEditSupplier.Visible = false; panelDetailPkg.Visible = false; //Load products data in gridview from database try { products = ProductDB.GetProducts(); productBindingSource.DataSource = products; //load supplier data suppliers = SupplierDB.GetAllSuppliers(); //supplierNameComboBox.DataSource = suppliers; //comboBoxPEditSupID.DataSource = suppliers; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } //Load supplier data in gridview from database try { suppliers = SupplierDB.GetAllSuppliers(); supplierDataGridView.DataSource = suppliers; } 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 btnEditSupplier_Click(object sender, EventArgs e) { //Get the supplier name value from the textbox. string updatedSupName = txtboxEditSupName.Text; updatedSupName = updatedSupName.Trim(); if (updatedSupName != "")//check if a value was provided { Supplier oldSupplier = suppliers[supplierDataGridView.CurrentCell.RowIndex]; if (updatedSupName != oldSupplier.SupplierName) { //Make a copy of the supplier we are updating Supplier newSupplier = oldSupplier.GetCopy(); //Update the information in the new supplier; newSupplier.SupplierName = updatedSupName; try { bool result = SupplierDB.UpdateSupplier(oldSupplier, newSupplier); if (result) { //Update the UI suppliers = SupplierDB.GetAllSuppliers(); supplierDataGridView.DataSource = suppliers; MessageBox.Show("The new supplier name has been saved", "Supplier Updated", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The changes were not saved", "Updated Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } panelEditSupplier.Visible = false; btnDelelteSupClick.Enabled = true; btnAddSupClick.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
// Creates an ordered list of the Suppliers private void LoadSupplierComboBox() { List <Supplier> supList = new List <Supplier>(); try { supList = SupplierDB.GetSupplier(); cboSupplierList.DataSource = supList; cboSupplierList.DisplayMember = "SupName"; cboSupplierList.ValueMember = "SupplierId"; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void frmModifyProductSupplier_Load(object sender, EventArgs e) { // Data binding for the Products & Suppliers lists this.productsTableAdapter.Fill(this.travelExpertsDataSet.Products); // Popluate the supplier list box with list information taken from the SupplierDB class lstSupplierList.DataSource = SupplierDB.GetSupplier(); lstProductList.ClearSelected(); lstSupplierList.ClearSelected(); lstProductList.Enabled = true; lstSupplierList.Enabled = true; txtModifyProduct.Enabled = false; txtModifySupplier.Enabled = false; btnCancel.Enabled = false; btnDelete.Enabled = false; }
private void SearchFor() { bool isIncludeExpiredPackagesEnabled = false; dgvMainPage.DataSource = null; //search for Packages if (rdbPackage.Checked) { grpListOf.Text = "List Of Package"; isIncludeExpiredPackagesEnabled = true; dgvMainPage.DataSource = PackageDB.GetPackages(txtSearch.Text, chbIncludeExpiredPackages.Checked); hideColumn(5); hideColumn(6); dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; } //search for Products if (rdbProduct.Checked) { grpListOf.Text = "List Of Products"; dgvMainPage.DataSource = ProductDB.SearchProducts(txtSearch.Text); dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; } //search for Suppliers if (rdbSupplier.Checked) { grpListOf.Text = "List Of Suppliers"; dgvMainPage.DataSource = SupplierDB.SearchSuppliers(txtSearch.Text); dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; } //search for Agents if (rdbAgents.Checked) { grpListOf.Text = "List Of Agents"; dgvMainPage.DataSource = AgentDB.SearchAgents(txtSearch.Text); dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; hideColumn(8); } chbIncludeExpiredPackages.Enabled = isIncludeExpiredPackagesEnabled;//enable 'IncludeExpiredPackages' box or not this.Refresh(); EnableDisableEditButton(); //dgvMainPage.Columns[columNo].Visible = false; }
// on load check if supplier or product is being edited and display respective messages private void EditProdSup_Load(object sender, EventArgs e) { products = ProductDB.GetProducts(); suppliers = SupplierDB.GetSuppliers(); if (SelectedProductName != null) { btnUpdate.Text = "Update Product"; lblProdSup.Text = "Selected Product Name:"; txtProdSup.Text = SelectedProductName; txtProdSup.MaxLength = 50; } else { btnUpdate.Text = "Update Supplier"; lblProdSup.Text = "Selected Supplier Name:"; txtProdSup.Text = SelectedSupplierName; txtProdSup.MaxLength = 255; } }
// Andy Gao private void LoadSupplierComboBox() { try { suppliers = SupplierDB.GetSupplier(); supplierNameComboBox.ValueMember = "SupplierId"; supplierNameComboBox.DisplayMember = "SupName"; supplierNameComboBox.DataSource = suppliers; supplierIDTextBox.Text = supplierNameComboBox.SelectedValue.ToString(); DisplaySupplierDetails(); loaded = true; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
/// <summary> /// Event is fired when the add button on the supplier tab is clicked. /// /// </summary> /// <param name="sender">The button that was clicked</param> /// <param name="e">The arguements of the event</param> private void btnAddSupplier_Click(object sender, EventArgs e) { //Get the information from the text box string newSupName = txtboxAddSupName.Text; newSupName = newSupName.Trim(); if (newSupName != "") //A value was provided { //Create a new supplier and assign the supplier name provided to the //SupplierName property Supplier newSupplier = new Supplier(); newSupplier.SupplierName = newSupName; //Write the new supplier to the DB try { int newSupID = SupplierDB.AddSupplier(newSupplier); //Read supplier data again suppliers = SupplierDB.GetAllSuppliers(); supplierDataGridView.DataSource = suppliers; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Message"); } //setup the UI after adding a new supplier panelAddSupplier.Visible = false; btnDelelteSupClick.Enabled = true; btnEditSupClick.Enabled = true; } else { MessageBox.Show("Please provide the suppliers name", "Required information"); } txtboxAddSupName.Text = ""; }
// Andy Gao private void addButton_Click(object sender, EventArgs e) { string supplierinput; // Check if input is null if (supplierNameTextBox.Text == null || supplierNameTextBox.Text == "") { MessageBox.Show("Supplier Name must be filled!"); } else { // Retrieve input supplierinput = Convert.ToString(supplierNameTextBox.Text.ToUpper()); suppliers = SupplierDB.GetSupplier(); // Check if Supplier is already in system foreach (Supplier supplier in suppliers) { if (supplier.SupName == supplierinput) { MessageBox.Show("This supplier is already in the system."); break; } } // Successful input int success = SupplierDB.AddSupplier(supplierinput); if (success == 1) { MessageBox.Show("Supplier is successfully added!"); this.Close(); } else { MessageBox.Show("Error!"); } } }
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(); } }
private void saveModifyButton_Click(object sender, EventArgs e) { // Check if null if (supplierNameTextBox.Text == null || supplierNameTextBox.Text == "") { MessageBox.Show("Supplier Name must not be empty!"); } else { // Retrieve input Supplier changedsupplier = new Supplier(); Supplier oldsupplier = new Supplier(); changedsupplier.SupName = supplierNameTextBox.Text.ToString(); changedsupplier.SupplierId = Convert.ToInt32(supplierNameComboBox.SelectedValue); oldsupplier.SupName = supplierNameComboBox.Text; oldsupplier.SupplierId = Convert.ToInt32(supplierNameComboBox.SelectedValue); DialogResult dr = MessageBox.Show("Confirm your changes: " + oldsupplier.SupName + " to " + changedsupplier.SupName, "Confirm Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { // Update in database SupplierDB.EditSupplier(changedsupplier, oldsupplier); MessageBox.Show("Your Change is saved!"); // Display Changes addNewButton.Visible = true; supplierNameComboBox.Visible = true; supplierNameTextBox.Visible = false; saveModifyButton.Visible = false; cancelButton.Visible = false; LoadSupplierComboBox(); } } }
// 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()); } } } }
// call the proper function for insertion of the the supplier of the product and put to upper for the suppliers private void btnUpdate_Click(object sender, EventArgs e) { if (SelectedProductName != null) { if (Validator.IsProvided(txtProdSup, "A Product Name")) { string newName = txtProdSup.Text; bool valid = false; foreach (Product p in products) { if (p.ProdName == newName) { MessageBox.Show("Product already exists, choose a unique product name"); valid = false; break; } else { valid = true; } } if (valid == true) { try { ProductDB.UpdateProduct(SelectedProductName, newName); MessageBox.Show(SelectedProductName + " was updated to " + newName); this.Close(); } catch { MessageBox.Show("Update was unsuccessful, try again"); } } } } else if (Validator.IsProvided(txtProdSup, "A Supplier name")) { string newName = txtProdSup.Text.ToUpper(); bool valid = false; foreach (Supplier s in suppliers) { if (s.SupName == newName) { MessageBox.Show("Supplier already exists, choose a unique supplier name"); valid = false; break; } else { valid = true; } } if (valid == true) { try { SupplierDB.UpdateSupplier(SelectedSupplierName, newName); MessageBox.Show(SelectedSupplierName + " was updated to " + newName); this.Close(); } catch { MessageBox.Show("Update was unsuccessful, try again"); } } } }