private void btnAddToList_Click(object sender, EventArgs e) { try { foreach (DataGridViewRow row in dgvSuppliers.SelectedRows)//get each row from dgvSuppliers { selectedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()); //get value from row and assign it to selected supplier productSupplier = new ProductSupplier(selectedProduct.ProductId, selectedSupplier.SupplierId); //get value from row and assign it to selected product supplier ProductSupplierDB.InsertProductSupplier(productSupplier); //call insertProductSupplier editedProductSuppliers = ProductDB.GetProductSuppliersByProduct(selectedProduct); //call GetProductSupplierByProduct //suppliers.Remove(selectedSupplier); suppliers = SupplierDB.GetSuppliersNotInList(selectedProduct); //call GetSupplierNotInList function } UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString());//show exception if there any } // only select the last row dgvProductSuppliers.ClearSelection();//clear dgvProductSuppliers int index = editedProductSuppliers.Count - 1; dgvProductSuppliers.Rows[index].Selected = true; txtSName.Clear(); }
//on selection change, updates dgvProducts to show corresponding products for this supplier private void dgvSuppliers_SelectionChanged(object sender, EventArgs e) { Supplier selectedSupplier = null; try { foreach (DataGridViewRow row in dgvSuppliers.SelectedRows) { selectedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()); } if (productSuppliers == null) { productSuppliers = SupplierDB.GetProductSuppliersBySupplier(selectedSupplier); UpdateBinding(); frmProduct.ProductListFormat(dgvProducts); } else { productSuppliers = SupplierDB.GetProductSuppliersBySupplier(selectedSupplier); UpdateBinding(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
//delete the selected product_supplier from the detail list(Packages_Products_Suppliers table) private void btnRemove_Click(object sender, EventArgs e) { try { foreach (DataGridViewRow row in dgvPackageDetail.SelectedRows) { Product p = ProductDB.GetProductByName(row.Cells[3].Value.ToString()); Supplier s = SupplierDB.GetSupplierByName(row.Cells[4].Value.ToString()); int pkgId; bool pkgOK = Int32.TryParse(cobPackages.SelectedValue.ToString(), out pkgId); Package pkg = PackageDB.GetPackageById(pkgId); string message = "Are you sure you want to remove [" + p.ProdName + " : " + s.SupName + "] from package [" + pkg.PkgName + "]?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplierById(p.ProductId, s.SupplierId); ProductSupplierDB.DeletePackageDetail(productSupplier, pkg); details = PackageDB.GetProductSuppliersByPackage(pkg); } } UpdateBinding(); dgvPackageDetail.ClearSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
//deletes selected supplier in DB, updates dgv private void btnDelete_Click(object sender, EventArgs e) { try { Supplier selectedSupplier = null; foreach (DataGridViewRow row in dgvSuppliers.SelectedRows) { selectedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()); string message = "Are you sure you want to delete " + selectedSupplier.SupName + " ?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { SupplierDB.DeleteSupplier(selectedSupplier); suppliers = SupplierDB.GetAllSuppliers(); UpdateBinding(); txtSuppName.Clear(); } } } catch (Exception ex) { //MessageBox.Show(ex.Message, ex.GetType().ToString()); MessageBox.Show("Deleting this supplier will cause you to lose a record in your booking history. \nThe delete action has been suspended. \nPlease contact DBA."); } }
//opens AddSupplier form, receives newly added suppliers, inserts to DB and updates dgv, scrolls down to latest new supplier added private void btnAdd_Click(object sender, EventArgs e) { frmAddSuppliers newForm = new frmAddSuppliers(); List <Supplier> newSuppliers = newForm.GetNewSuppliers(); try { if (newSuppliers != null) { foreach (Supplier ns in newSuppliers) { SupplierDB.InsertSupplier(ns); } } suppliers = SupplierDB.GetAllSuppliers(); UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } txtSuppName.Clear(); //select on the last row of the list dgvSuppliers.ClearSelection(); int rowIndex = dgvSuppliers.Rows.Count - 1; dgvSuppliers.Rows[rowIndex].Selected = true; //scroll down as well dgvSuppliers.FirstDisplayedScrollingRowIndex = rowIndex; }
//as user enters search string, corresponding suppliers are displayed as text is entered private void txtSuppName_TextChanged(object sender, EventArgs e) { try { suppliers = SupplierDB.GetSuppliersByName(txtSuppName.Text); UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void btnClear_Click(object sender, EventArgs e) { try { suppliers = SupplierDB.GetAllSuppliers();//call function to get all suppliers UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString());//show exception if there any } txtSName.Clear();//for clear textBox txtSName.Select(); }
//resets everything to default private void btnClear_Click(object sender, EventArgs e) { try { suppliers = SupplierDB.GetAllSuppliers(); UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } txtSuppName.Clear(); txtSuppName.Select(); }
//opens EditSupplier form, receives edited supplier, updates DB, selects edited supplier in dgv private void btnEdit_Click(object sender, EventArgs e) { Supplier editedSupplier = null; Supplier newSupplier = null; foreach (DataGridViewRow row in dgvSuppliers.SelectedRows) { editedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()); } frmEditSupplier newForm = new frmEditSupplier(); //this.Hide(); newSupplier = newForm.GetEditSupplier(editedSupplier); //this.Show(); try { SupplierDB.UpdateSupplier(editedSupplier, newSupplier); suppliers = SupplierDB.GetAllSuppliers(); UpdateBinding(); txtSuppName.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } //set the modified row to be selected dgvSuppliers.ClearSelection(); int rowIndex = -1; foreach (DataGridViewRow row in dgvSuppliers.Rows) { if (row.Cells[0].Value.ToString().Equals(editedSupplier.SupplierId.ToString())) { rowIndex = row.Index; break; } } dgvSuppliers.Rows[rowIndex].Selected = true; dgvSuppliers.FirstDisplayedScrollingRowIndex = rowIndex; }
private void txtSName_TextChanged(object sender, EventArgs e) { try { if (txtSName.Text != "") //check if text s name empty { suppliers = SupplierDB.GetSuppliersByName(txtSName.Text); //function call to GetSupplierByName UpdateBinding(); } else { suppliers = SupplierDB.GetAllSuppliers();//function calls to GetAllSuppliers UpdateBinding(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString());//show exception if there any } }
private void EditProductSuppliers_Load(object sender, EventArgs e) { txtProdName.Text = selectedProduct.ProdName; try { suppliers = SupplierDB.GetSuppliersNotInList(selectedProduct);//function call to GetSuppliersNotInList UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } frmSupplier.SuppliersListFormat(dgvSuppliers); //function calls to suppliersListFormat frmSupplier.SuppliersListFormat(dgvProductSuppliers); //function call to SupplierListFormat txtSName.Select(); //move cursor to textbox }
private void btnRemove_Click(object sender, EventArgs e) { try { foreach (DataGridViewRow row in dgvProductSuppliers.SelectedRows)//get each row from dgvProductSuppliers { selectedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()), row.Cells[1].Value.ToString()); //get value from row and assign it to selected supplier productSupplier = new ProductSupplier(selectedProduct.ProductId, selectedSupplier.SupplierId); //get value from row and assign it to selected product ProductSupplierDB.DeleteProductSupplier(productSupplier); //call DeleteProductSupplier editedProductSuppliers = ProductDB.GetProductSuppliersByProduct(selectedProduct); //call GetProductSuppliersByProduct function suppliers = SupplierDB.GetSuppliersNotInList(selectedProduct); //call GetSuppliersNotInList function } UpdateBinding(); dgvProductSuppliers.ClearSelection(); } catch (Exception ex) { MessageBox.Show("Deleting this supplier will cause you to lose a record in your booking history. \nThe delete action has been suspended. \nPlease contact DBA.");//show exception if there any } }
private void SupplierForm_Load(object sender, EventArgs e) { this.ControlBox = false; this.MaximizeBox = false; this.MinimizeBox = false; try { // load the products table data suppliers = SupplierDB.GetAllSuppliers(); UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } SuppliersListFormat(dgvSuppliers); frmProduct.ProductListFormat(dgvProducts); txtSuppName.Select(); }
//add the selected product and supplier from combox to the detail list(Packages_Products_Suppliers table) private void btnAdd_Click(object sender, EventArgs e) { try { int pId; bool pOk = Int32.TryParse(cobProducts.SelectedValue.ToString(), out pId); Product p = ProductDB.GetProductById(pId); int sId; bool sOk = Int32.TryParse(cobSuppliers.SelectedValue.ToString(), out sId); Supplier s = SupplierDB.GetSupplierById(sId); int pkgId; bool pkgOK = Int32.TryParse(cobPackages.SelectedValue.ToString(), out pkgId); Package pkg = PackageDB.GetPackageById(pkgId); PackageDB.InsertDetail(p, s, pkg); details = PackageDB.GetProductSuppliersByPackage(pkg); UpdateBinding(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }