Пример #1
0
        // DELETE a supplier to current product click
        private void btnRemove_Click(object sender, EventArgs e)
        {
            string i = lstSuppliers.SelectedItem.ToString();

            string[]           s                 = i.Split('|');
            int                prodSupId         = Int32.Parse(s[0].Trim());
            Products_Suppliers productsSuppliers = new Products_Suppliers();

            if (prodSupId < 1) // no selection
            {
                MessageBox.Show("Please select supplier to add");
            }
            else // user selected a product to add
            {
                try
                {
                    this.DialogResult = DialogResult.OK;
                    Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(prodSupId);
                    Products_SuppliersDB.DeleteProductSupplier(ps);
                    MessageBox.Show("Supplier deleted", "Success!");
                    loadData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Пример #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                DialogResult result = MessageBox.Show("Delete " + currentProd.ProdName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductsDB.DeleteProduct(currentProd))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product.", "Database Error");
                            currentProd = ProductsDB.GetProductById(currentProd.ProductId);
                            if (currentProd != null)
                            {
                                this.DisplayProductData();
                            }
                        }
                        else
                        {
                            this.DisplayProductData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete " + currentSupplier.SupName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(currentSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that supplier.", "Database Error");
                            currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId);
                            if (currentSupplier != null)
                            {
                                this.DisplaySupplierData();
                            }
                        }
                        else
                        {
                            this.DisplaySupplierData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete Product Supplier " + currentProductSupplier.ProductSupplierId + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!Products_SuppliersDB.DeleteProductSupplier(currentProductSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product_supplier.", "Database Error");
                            currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
                            if (currentProductSupplier != null)
                            {
                                this.DisplayCurrentProductSupplierData();
                            }
                            this.DisplayProductSupplierData();
                        }
                        else
                        {
                            this.DisplayCurrentProductSupplierData();
                        }
                        this.DisplayProductSupplierData();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Packages")
            {
                DialogResult result = MessageBox.Show("Delete Packages " + currentPackage.PkgName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(currentPackage))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId);
                            if (currentPackage != null)
                            {
                                //this.DisplayCurrentProductSupplierData();
                                this.DisplayProductSupplierData();
                            }
                        }
                        else
                        {
                            //this.DisplayCurrentProductSupplierData();
                            this.DisplayPackages();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }