/// <summary> /// Set the fields /// Check to see if the selected supplier ID already exists and whether the fields are empty /// If conditions are met, insert a new supplier with an auto generated ID and specified supplier name into the database /// </summary> private void btnAddSupplier_Click(object sender, EventArgs e) { int supplierID = Convert.ToInt32(txtSupID.Text); string supName = txtSupName.Text; bool SupplierExists = SupplierDB.CheckDataBase(supplierID); if (supName == "" || supName == "") { MessageBox.Show("Please enter a name for the supplier"); cmbSupplierID.SelectedIndex = 0; } else if (SupplierExists == false) { SupplierDB.InsertSupplier(supplierID, supName); MessageBox.Show("Supplier with ID: " + supplierID + " AND Suplier Name: " + supName + " Added"); cmbSupplierID.SelectedItem = cmbSupplierID.Items[cmbSupplierID.Items.Count - 1]; } else { MessageBox.Show("Supplier with ID: " + supplierID + " already exists"); } RefreshRecords(supplierID); DisplaySuppliers(); cmbSupplierID.SelectedItem = supplierID; btnAddSupplier.Visible = false; btnNewSpplier.Visible = true; lblFeedBack.Text = ""; }
/// <summary> /// set the specified fields /// delete specified supplier /// check to see if the deleted supplier has been actually deleted from the database /// </summary> private void btnDeleteSupplier_Click(object sender, EventArgs e) { int supplierID = Convert.ToInt32(txtSupID.Text); string supName = txtSupName.Text; SupplierDB.DeleteSupplier(supplierID, supName); bool SupplierExists = SupplierDB.CheckDataBase(supplierID); if (SupplierExists == false) { txtSupID.Text = ""; txtSupName.Text = ""; RefreshRecords(supplierID + 2); MessageBox.Show("Supplier with ID: " + supplierID + " deleted"); } else { MessageBox.Show("Supplier with ID: " + supplierID + " was not deleted"); } DisplaySuppliers(); cmbSupplierID.SelectedItem = supplierIDs[supplierIDs.Count - 1]; }