private void dataGridProdSupp_SelectionChanged(object sender, EventArgs e) { currentProd = (Product)dataGridProdSupp.CurrentRow.DataBoundItem; packageList = ProductsSuppliersDB.GetPackagesWith(currentSupp.SupplierId, currentProd.ProductId); datagridPackages.DataSource = packageList; //store currently selected row data to product Object }
private void Display() { allProdList = ProductsSuppliersDB.GetProducts(); prodSuppList = ProductsSuppliersDB.GetProductSuppBySuppID(currentSupp.SupplierId); dataGridProdSupp.DataSource = prodSuppList; dataGridAllProd.DataSource = allProdList; }
private void frmSuppliers_Load(object sender, EventArgs e) { dataGridSuppliers.DataSource = ProductsSuppliersDB.GetSuppliers(); datagridPackages.DataSource = packageList; FindProductSuppliers(); dataGridSuppliers.Columns[0].Width = 300; dataGridAllProd.Columns[0].Width = 200; dataGridProdSupp.Columns[0].Width = 200; datagridPackages.Columns[0].Width = 100; }
private void GetSuppliersProducts(int supplierId) { try { prodSuppList = ProductsSuppliersDB.GetProductSuppBySuppID(supplierId); allProdList = ProductsSuppliersDB.GetProducts(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void btnAddSupp_Click(object sender, EventArgs e) { frmAddEditSupplier addSuppfrm = new frmAddEditSupplier(); addSuppfrm.AddSuppliers = true; DialogResult res = addSuppfrm.ShowDialog(); if (res == DialogResult.OK) { suppList = ProductsSuppliersDB.GetSuppliers(); dataGridSuppliers.DataSource = suppList; Display(); FindProductSuppliers(); } }
} //delete supplier private void btnAddProdToList_Click(object sender, EventArgs e) //add new products to suppliers { if (dataGridAllProd.SelectedRows.Count == 0) { MessageBox.Show(@"No product/s to add! " + @"Try Again", @"No Product", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int newProdId = ((Product)dataGridAllProd.CurrentRow.DataBoundItem).ProductId; var products = from ps in prodSuppList where ps.ProductId == newProdId select ps; if (products.Count() != 0) { MessageBox.Show(@"This Product is already added!", @"Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Product_Supplier newProdSupp = new Product_Supplier(); try { newProdSupp.ProductId = newProdId; newProdSupp.SupplierId = currentSupp.SupplierId; newProdSupp.ProductSupplierId = ProductsSuppliersDB.AddToProdSupp(newProdSupp); currentSupp = dataGridSuppliers.CurrentRow.DataBoundItem as Supplier; if (currentSupp != null) { GetSuppliersProducts(currentSupp.SupplierId); Display(); } Display(); } catch (Exception ex) { throw ex; } }
private void btnEditSupp_Click(object sender, EventArgs e) { frmAddEditSupplier editSuppfrm = new frmAddEditSupplier(); //Instantiate a new form if (currentSupp != null) { editSuppfrm.supplier = currentSupp; // selected supplier is now the next form's supplier editSuppfrm.AddSuppliers = false; DialogResult res = editSuppfrm.ShowDialog(); if (res == DialogResult.OK) { suppList = ProductsSuppliersDB.GetSuppliers(); dataGridSuppliers.DataSource = suppList; Display(); FindProductSuppliers(); } } }
private void btnEditProd_Click(object sender, EventArgs e) { FrmAddModifyProducts editProdForm = new FrmAddModifyProducts(); editProdForm.AddProducts = false; editProdForm.product = currentAllProd; DialogResult res = editProdForm.ShowDialog(); if (res == DialogResult.OK) { currentProd = editProdForm.product; allProdList = ProductsSuppliersDB.GetProducts(); dataGridAllProd.DataSource = allProdList; Display(); } else { editProdForm.ClearControls(); } }
private void btnDeleteSupp_Click(object sender, EventArgs e) { if (currentSupp != null) { try { if (MessageBox.Show(@"Are you sure you want to delete: " + currentSupp.SupName + @" Supplier?", @"Delete Supplier", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { currentSupp.DeleteSupp(); // delete current supplier suppList = ProductsSuppliersDB.GetSuppliers(); dataGridSuppliers.DataSource = suppList; Display(); FindProductSuppliers(); // find Suppliers } } catch (Exception ex) { MessageBox.Show(@"Cannot delete this supplier, it is currently supplying products!", @"Delete", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //delete supplier
public void RemoveFromSupplier(int SupplierId) { ProductsSuppliersDB.RemoveProdFromSupp(ProductId, SupplierId); }