// 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"); } } }
// 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); } }
// 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; } }