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