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