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();
        }
예제 #2
0
        //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());
            }
        }
 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
     }
 }