Exemplo n.º 1
0
        private void DeletePackage(Package pkg)
        {
            DialogResult result = MessageBox.Show("Delete the Package " + pkg.PkgName + "?", "Confirm Delete",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                // creates the other table objects
                List <Packages_Products_Suppliers> newpack_prod_sup = new List <Packages_Products_Suppliers>();
                try              // tries to delete the table records
                {
                    // gets the data for the tasble records that need to be deleted
                    newpack_prod_sup = Packages_Products_SuppliersDB.GetList(pkg.PackageId);
                    // deletes each productsuppliers table record
                    foreach (Packages_Products_Suppliers ps in newpack_prod_sup)
                    {
                        Packages_Products_SuppliersDB.DeletePackProdSup(ps);
                    }
                    // deletes the suppliercontacts record
                    PackagesDB.DeletePackage(pkg);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                RefreshPackages();
            }
        }
Exemplo n.º 2
0
        // button to delete a package from the DB
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvPackages.SelectedRows.Count > 0)
            {
                // sets the object to delete
                int index = dgvPackages.SelectedRows[0].Index;
                package = packages[index];

                // asks user if they are sure
                DialogResult result = MessageBox.Show("Delete the Package " + package.PkgName + "?", "Confirm Delete",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    // creates the other table objects
                    List <Packages_Products_Suppliers> newpack_prod_sup = new List <Packages_Products_Suppliers>();
                    try              // tries to delete the table records
                    {
                        // gets the data for the tasble records that need to be deleted
                        newpack_prod_sup = Packages_Products_SuppliersDB.GetList(package.PackageId);
                        // deletes each productsuppliers table record
                        foreach (Packages_Products_Suppliers ps in newpack_prod_sup)
                        {
                            Packages_Products_SuppliersDB.DeletePackProdSup(ps);
                        }

                        // deltes the suppliercontacts record
                        PackagesDB.DeletePackage(package);

                        // deltes the supplier record

                        // redisplays the dgv
                        packages = PackagesDB.GetAll();

                        refreshDGV();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }

            else
            {
                MessageBox.Show("Please select a Product");
            }
        }
        // removes a product supplier from the list
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvProducts.SelectedRows.Count > 0)
            {
                if (add)
                {
                    pack_prod_sup.RemoveAt(this.dgvProducts.SelectedRows[0].Index);
                    RedisplayList();
                }
                else
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to delete this Product in the Package?",
                                                          "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        int index = this.dgvProducts.SelectedRows[0].Index;
                        try
                        {
                            if (!Packages_Products_SuppliersDB.DeletePackProdSup(pack_prod_sup[index]))
                            {
                                MessageBox.Show("That product has been updated or deleted already.", "Database Error");
                            }
                            else
                            {
                                pack_prod_sup = Packages_Products_SuppliersDB.GetList(package.PackageId);

                                this.RedisplayList();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, ex.GetType().ToString());
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select a Product");
            }
        }