//deletes the selected cell private void DeleteButton_Click(object sender, EventArgs e) { if (isValid())//checks there is a value selected { //confirmation window DialogResult result = MessageBox.Show("Delete " + supp.SupName + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { if (!SuppliersDB.DeleteSupplier(supp))//failed { MessageBox.Show("Another user has updated or deleted that supplier.", "Database Error"); clearContent(); } else//success { MessageBox.Show("Delete Successful."); clearContent(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else { MessageBox.Show("Data fields are empty.", "Input Error"); } }
//update the supplier list when new product selected private void lstProducts_SelectedIndexChanged_1(object sender, EventArgs e) { currentProduct = ProductDB.getProductById(Convert.ToInt32(lstProducts.SelectedValue)); supplierList = SuppliersDB.GetSuppliers(); //concurrency issue occurs if product is deleted from DB LoadProductSuppliers(currentProduct.ProductId); }
private void cboSupplierId_SelectedIndexChanged(object sender, EventArgs e) { int selectedID = (int)cboSupplierId.SelectedValue; sup = SuppliersDB.GetSupplierById(selectedID); lblSupName.Text = sup.SupName; }
// Tab Two Changed (by using ALL, EDIT, ADD btn): change UI appearance accordingly private void twoTab_SelectedIndexChanged(object sender, EventArgs e) { twoBtnViewAll.BackColor = Color.DarkCyan;; twoBtnEdit.BackColor = Color.DarkCyan; twoBtnAdd.BackColor = Color.DarkCyan; twoBtnSave.Visible = true; if (twoTab.SelectedIndex == 0) { twoBtnSave.Visible = false; // 'ALL' tab, load all Product Supplier data and fill DataSource _psList = Products_suppliersDB.GetAllProductSupplierWithNames().OrderBy(ps => ps.ProdName).ToList(); // use List to make a SortableBindingList var _sortableList = new SortableBindingList <ProductSupplierWithName>(_psList); productSupplierWithNameBindingSource.DataSource = _sortableList; // databinding for combo boxes suppliersBindingSource.DataSource = SuppliersDB.GetSuppliers().OrderBy(s => s.SupName); productsBindingSource.DataSource = ProductsDB.GetProducts(); } else if (twoTab.SelectedIndex == 2) { // 'ADD' tab // select nothing when load twoCmbAddProdName.SelectedIndex = -1; twoCmbAddSuppName.SelectedIndex = -1; } // 'EDIT' tab }
/// <summary> /// Load supplier tab data /// </summary> Raymond private void loadSupplierTab() { supplierCount = 0; suppliersDetails = SuppliersDB.GetSuppliers(); supplierId.Text = suppliersDetails[supplierCount].SupplierId.ToString(); supplierName.Text = ProcessNullSupplierName(suppliersDetails[supplierCount].SupName); }
private void btnSaveSupp_Click(object sender, EventArgs e) { try { if (Validator.IsPresent(txtNewSupp, "New Supplier Name")) { Suppliers newSupplier = new Suppliers(); newSupplier.SupName = txtNewSupp.Text; newSupplier.SupplierId = AllSuppliers.Max(s => s.SupplierId) + 1; if (SuppliersDB.AddSupplier(newSupplier)) { MessageBox.Show("Supplier has been updated :)"); UpdateAllInfos(); suppliersDataGridView.DataSource = AllSuppliers; } } } //catch the other error and show the ex error message from db class catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
// ------------Added by Wei Guang Yan---------------- // Method of inserting suplier's name to database public void AddSupplier(string txtAdd) { // Innitialize for messagebox string message; string title = "New Product Insert"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon; // Generate new supplier Id based on max id in database int id = SuppliersDB.GetMaxId() + 1; // Add new item to database bool flag = SuppliersDB.AddSupplier(id, txtAdd); // Check whether adding excution is successful, and show message if (flag == true) { comboBox2.DataSource = SuppliersDB.GetSuppliers(); comboBox2.DisplayMember = "SupName"; comboBox2.ValueMember = "SupplierId"; comboBox2.SelectedIndex = comboBox2.Items.Count - 1; txtAddItem.Text = ""; message = "The supplier is added successfully!"; icon = MessageBoxIcon.None; } else { message = "Error: Fail to add new supplier!\n Please try again or contact IT supports."; icon = MessageBoxIcon.Error; } MessageBox.Show(message, title, button, icon); }
// ------------Added by Wei Guang Yan---------------- // method of Updating suplier's name to database public void UpdateSupplier(string txtUpdate) { // Initialization for messagebox string message; string title = "Supplier Update"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon = MessageBoxIcon.Warning; // Excute updating int id = Convert.ToInt32(comboBox2.SelectedValue); bool flag = SuppliersDB.UpdateSupplier(id, txtUpdate); // Check whether updating is successful, and show message if (flag == true) { int index = comboBox2.SelectedIndex; comboBox2.DataSource = SuppliersDB.GetSuppliers(); comboBox2.DisplayMember = "SupName"; comboBox2.ValueMember = "SupplierId"; comboBox2.SelectedIndex = index; message = "The supplier is updated successfully!"; icon = MessageBoxIcon.None; } else { message = "Error: Fail to update supplier!\n Please try again or contact IT support."; icon = MessageBoxIcon.Error; } MessageBox.Show(message, title, button, icon); }
/// <summary> /// Update All List of Infos /// </summary> private void UpdateAllInfos() { AllPackages = PackagesDB.GetPackages(); AllProducts = ProductsDB.GetProducts(); AllSuppliers = SuppliersDB.GetSuppliers(); ProSupLinkages = ProSupDB.GetProSups(); PacProSupLinkages = PacProSupDB.GetPacProSup(); }
//delete supplier button private void btnSupDelete_Click(object sender, EventArgs e) { bool res = SuppliersDB.DeleteSupplier((int)LBSuppliers.SelectedValue); KeyValuePair <string, int> v = (KeyValuePair <string, int>)LBSuppliers.SelectedItem; SuppliersDB.Suppliers.Remove(v); }
// Edit existing supplier - Raymond private void btnEdit_Click_1(object sender, EventArgs e) { frmEditSuppliers editSuppliers = new frmEditSuppliers(suppliersDetails[supplierCount]); DialogResult result = editSuppliers.ShowDialog(); suppliersDetails = SuppliersDB.GetSuppliers(); supplierId.Text = suppliersDetails[supplierCount].SupplierId.ToString(); supplierName.Text = ProcessNullSupplierName(suppliersDetails[supplierCount].SupName); }
//resets the form (useful to update the datagrid for changes/new submissions) private void clearContent() { supIDTextBox.Clear(); supNameTextBox.Clear(); //resets the datagrid suppliers = SuppliersDB.GetSuppliers(); supplierDataGridView.DataSource = suppliers; }
private void DisplayCurrentSupplierData() { if (currentSupplier != null) { txtName.Text = currentSupplier.SupName; } else // null this product does not exist - need to refresh combo box { supplierIds = SuppliersDB.GetSuppliersIds(); } }
private void GetSupplier(int supplierId) { try { supplier = SuppliersDB.GetSupplier(supplierId); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
//method for OK button and to add to database private void btnOK_Click(object sender, EventArgs e) { string name = txtSupName.Text.ToString(); //take input int i = SuppliersDB.AddNewSupplier(name.ToUpper()); //make input all uppercase KeyValuePair <string, int> val = new KeyValuePair <string, int>(name.ToUpper(), i); //create key value pairs SuppliersDB.Suppliers.Add(val); //add value to database MessageBox.Show("Created new supplier.", "Success"); //popup for success message this.Close(); }
// Convenient Method: find if there is a duplicated supplier name in DB, return bool private bool FindDuplicatedSupplierName(string supplierName) { if (SuppliersDB.GetSuppliers().Find(s => s.SupName == supplierName) == null) { return(false); } else { MessageBox.Show("The supplier you input already exists.", "Duplicated Name"); return(true); } }
private void btnSave_Click(object sender, EventArgs e) { frmModifySup addSupplierForm = new frmModifySup(); addSupplierForm.addSuppliers = true; DialogResult result = addSupplierForm.ShowDialog(); if (result == DialogResult.OK) { dataGridView1.DataSource = SuppliersDB.GetSuppliers(); } }
/// <summary> /// On accept button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) // first validate { if (addSupplier) { supplier = new Suppliers(); this.PutSupplierData(supplier); try { if (SuppliersDB.AddSuppliers(supplier)) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("There was an error adding that supplier", "Database Error"); this.DialogResult = DialogResult.Retry; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Suppliers newSupplier = new Suppliers(); newSupplier.SupplierId = supplier.SupplierId; this.PutSupplierData(newSupplier); try { if (!SuppliersDB.UpdateSupplier(supplier, newSupplier)) { MessageBox.Show("Another user has updated or " + "deleted that supplier.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { supplier = newSupplier; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
// load data if a SupplierID is passed from Main form private void loadData() { lstProducts.Items.Clear(); List <Suppliers> supplierDetails = new List <Suppliers>(); List <Products_Suppliers> supplierProducts = new List <Products_Suppliers>(); supplierDetails = SuppliersDB.SupplierDetail((int)supId); txtSupplierID.Text = supplierDetails[0].SupplierId.ToString(); txtSupName.Text = supplierDetails[0].SupName.ToString(); supplierProducts = Products_SuppliersDB.SupplierProducts((int)supId); foreach (Products_Suppliers sprod in supplierProducts) { lstProducts.Items.Add(sprod); } }
//Adding a new supplier - Raymond private void btnNew_Click(object sender, EventArgs e) { frmAddSupplier addSupplier = new frmAddSupplier(); DialogResult result = addSupplier.ShowDialog(); suppliersDetails = SuppliersDB.GetSuppliers(); if (result == DialogResult.OK) { supplierCount = suppliersDetails.Count - 1; } supplierId.Text = suppliersDetails[supplierCount].SupplierId.ToString(); supplierName.Text = ProcessNullSupplierName(suppliersDetails[supplierCount].SupName); }
private void btnAdd_Click(object sender, EventArgs e) { if (IsValidData()) { if (addsupplier) // processing Add { supplier = new Suppliers(); this.PutSupplier(supplier); try { supplier.SupplierId = SuppliersDB.AddSupplier(supplier); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else // processing Modify { suppliers newSupplier = new suppliers { SupplierId = supplier.SupplierId }; this.PutSupplier(newSupplier); try { if (!SuppliersDB.UpdateSupplier(supplier, newSupplier)) { MessageBox.Show("Another user has updated or " + "deleted that supplier ID.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { supplier = newSupplier; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btnAddSupplier_Click(object sender, EventArgs e) { supplier = new Suppliers(); this.PutSupplierData(supplier); try { supplier.SupplierId = SuppliersDB.AddSupplier(supplier); MessageBox.Show("Supplier added", "Success!"); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } this.Close(); }
// display suppliers after getting list by DB method private void DisplaySuppliers() { suppliersList = SuppliersDB.GetSuppliers(); if (suppliersList != null) // if we have product suppliers to display { lstView.Items.Clear(); //start with empty list box foreach (Suppliers sup in suppliersList) { lstView.Items.Add(sup); } } else // null this supplier does not exist - need to refresh combo box { MessageBox.Show("There is no supplier to display."); } }
// ----- 4TH NAV BTN: Suppliers ----- // Tab Four Changed (by using ALL, EDIT, ADD btn): change UI appearance accordingly private void fourTab_SelectedIndexChanged(object sender, EventArgs e) { fourBtnSave.Visible = true; fourBtnAll.BackColor = Color.DarkCyan; fourBtnEdit.BackColor = Color.DarkCyan; fourBtnAdd.BackColor = Color.DarkCyan; if (fourTab.SelectedIndex == 0) { // view ALL mode: hide save btn fourBtnSave.Visible = false; // bind data to gridview's binding source var suppliersList = SuppliersDB.GetSuppliers(); var _sortableSuppliers = new SortableBindingList <Suppliers>(suppliersList); suppliersBindingSource.DataSource = _sortableSuppliers; } }
/// <summary> /// Get all the datat from the database /// </summary> private void getAll() { try { packages = PackagesDB.GetAllPackages(); packages2 = PackagesDB.GetAllPackages(); //Two controls cannot share array data binding products = ProductDB.GetAllProducts(); products2 = ProductDB.GetAllProducts(); //Two controls cannot share array data binding suppliers = SuppliersDB.GetAllSuppliers(); products_suppliers = Products_SupplierDB.GetAllProduct_Suppliers(); } catch (Exception ex) //Any Errors form the database read? { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
/********************************************************** * * Form set-up methods * * * ********************************************************/ //get products from database and load the products in the list box private void LoadProducts(int selectedProductId = -1) { //get the product and supplier lists from database productsList = ProductDB.GetProducts(); supplierList = SuppliersDB.GetSuppliers(); //populate product list box lstProducts.DataSource = productsList; //no currentProduct object exists, create one by selecting first item in the lstProducts if (selectedProductId == -1) { lstProducts.SelectedIndex = 0; currentProduct = ProductDB.getProductById(Convert.ToInt32(lstProducts.SelectedValue)); } }
private void btnAccept_Click_1(object sender, EventArgs e) { if (IsValidData()) { if (addSuppliers) // processing Add { psp = new Suppliers(); PutSuppliers_Data(psp); try { SuppliersDB.AddSuppliers(psp); MessageBox.Show("New Item with Supplier Id of " + psp.SuppliersId + " and SupName " + psp.SupName + " was added"); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else // processing Modify { Suppliers newSuppliers = new Suppliers(); newSuppliers.SupName = txtSupName.Text; PutSuppliers_Data(newSuppliers); try { if (!SuppliersDB.UpdateSuppliers(modifySuppliers, newSuppliers)) { MessageBox.Show("Another user has updated or " + "deleted that Supplier.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { psp = newSuppliers; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
// UPDATE button click, visibility and read-only toggle private void btnProductEdit_Click(object sender, EventArgs e) { List <Products_Suppliers> currentProducts = new List <Products_Suppliers>(); btnAcceptEdit.Visible = true; btnProductEdit.Visible = false; pnlUpdate.Visible = true; txtProdName.ReadOnly = false; txtProdName.Enabled = true; lstSuppliers.Enabled = true; suppliersList = SuppliersDB.GetSuppliers(); foreach (Suppliers sup in suppliersList) { cboSupplier.Items.Add(sup); } }
private void frmAddUpdateProductSupplier_Load(object sender, EventArgs e) { productIds = ProductsDB.GetProductsIds(); cboProdId.DataSource = productIds; supplierIds = SuppliersDB.GetSuppliersIds(); cboSupplierId.DataSource = supplierIds; if (addProductSupplier) { this.Text = "Add Product Supplier"; cboProdId.SelectedIndex = 0; cboSupplierId.SelectedIndex = 0; } else { this.Text = "Update Product Supplier"; this.DisplayCustomer(); } }
private void btnUpdate_Click(object sender, EventArgs e) { var cells = dataGridView1.CurrentRow.Cells; string rowId = cells[0].Value.ToString(); string rowId1 = cells[1].Value.ToString(); //int rowId = Convert.ToInt32(cells[0].Value); var selectedSupplierID = SuppliersDB.GetSuppliers(rowId); frmModifySup modifySupplierFrm = new frmModifySup(); modifySupplierFrm.addSuppliers = false; modifySupplierFrm.modifySuppliers = selectedSupplierID; DialogResult result = modifySupplierFrm.ShowDialog(); if (result == DialogResult.OK) { dataGridView1.DataSource = SuppliersDB.GetSuppliers(); } }