Exemplo n.º 1
0
        // Remove a product from the current package
        private void btnDeleteProd_Supplier_Click(object sender, EventArgs e)
        {
            //Confirm
            DialogResult confirmation = DialogResult.No;

            confirmation = MessageBox.Show("Are you sure you want to remove the selected product(s) from '" +
                                           selectedPackage.Name + "'?", "Confirm Delete", MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (confirmation != DialogResult.Yes)
            {
                return; //Escape if user does not confirm
            }
            int rowCount    = lstPkgProductSuppliers.SelectedIndices.Count;
            int rowsDeleted = 0;

            NamedPackageProductSupplier[] toDelete = new NamedPackageProductSupplier[rowCount];
            for (int i = 0; i < rowCount; i++)
            {
                //Set each selected product to be deleted
                int selectedIndex = lstPkgProductSuppliers.SelectedIndices[i];
                toDelete[i] = selectedPackage.ProductsAndSuppliers[selectedIndex];
            }
            for (int i = 0; i < rowCount; i++)
            {
                //Delete each row selected above
                rowsDeleted += PackageProdSuppDB.Delete(toDelete[i]);
            }

            //Display result
            FillPackageProductList(selectedPackage);
            lblPkgStatus.Text = "Product(s) removed";
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Package == null)
            {
                throw new MissingMemberException("Package is not assigned");
            }

            ProductSupplier prodSup = GetProductSupplier();

            if (prodSup == null)
            {
                MessageBox.Show("Product/Supplier not found in database", "ERROR");
                return;
            }

            // Add ProductPackageSupplier to database
            PackageProdSupplier pkgProdSup = new PackageProdSupplier
            {
                PackageID  = Package.ID,
                ProdSuppID = prodSup.ProductSupplierId
            };

            PackageProdSuppDB.Insert(pkgProdSup);

            //Return
            this.DialogResult = DialogResult.OK;
            this.Close();
        }