コード例 #1
0
        //delete key is pressed for the products supplier table in the product tab on the main form
        private void btnDeletePackProdSup_Click(object sender, EventArgs e)
        {
            //shows confrim delete message box
            DialogResult result = MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            SelectedRowPackage();
            SelectedRowProdSupPackages();
            //if user picks yes
            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!Packages_Products_SuppliersDB.Delete(packProdSup, package))//if delete unsuccessful in database
                    {
                        MessageBox.Show("Another user has updated or deleted Product " + product.ProdName + " and " + supplier.SupName, "Datebase Error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                this.DisplayPackages();
                this.DisplayPackageProdSup();
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (ValidData())           //making sure data is valid
            {
                if (addPackageProdSup) // if user clciked the add button
                {
                    productSupplier = new Product_Supplier();
                    this.ProductSupplierData(productSupplier);
                    try
                    {
                        productSupplier.ProductSupplierID = Product_SupplierDB.AddProduct_Supplier(productSupplier);
                        Packages_Products_SuppliersDB.Add(productSupplier, package);
                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else //if user clicks modify button
                {
                    Product_Supplier newProductSupplier = new Product_Supplier();
                    newProductSupplier.ProductSupplierID = packProdSup.ProductSupplerID;
                    this.ProductSupplierData(newProductSupplier);
                    try
                    {
                        if (!Product_SupplierDB.UpdateProduct_Supplier_Packages(packProdSup, newProductSupplier)) //if product update was unsuccessful
                        {
                            MessageBox.Show("Another user has updated or " +
                                            "deleted that customer.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// On clicking add product to package button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddProdtoPack_Click(object sender, EventArgs e)
        {
            int               rowIndexSec      = dgProd.CurrentRow.Index;                           //needed to preserve state of tables
            Products          selectedProduct  = products[rowIndexSec];                             //selected product from product array
            int               rowIndex         = dgPackageProductSuppliers.CurrentRow.Index;        //needed to preserve state
            Package           selectedPackage  = packages[rowIndex];                                // selected package array to add to
            Products_Supplier selectedSupplier = selectedProduct.Suppliers[dgSup.CurrentRow.Index]; //selected product supplier to add to package
            DialogResult      result           = MessageBox.Show(                                   //confirm add?
                "You are about to add the product " + selectedProduct.ProdName + " by \n\n" +
                selectedSupplier.SupName + " to "
                + selectedPackage.Name, "Add to Package?",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                try
                {
                    Packages_Products_SuppliersDB.AddPackages_Products_Supplier(selectedPackage, selectedSupplier);
                }
                catch (SqlException ex)
                {
                    switch (ex.Errors[0].Number)
                    {
                    //if primary key error is encountered
                    case 2627:
                        MessageBox.Show("You already added this Product", "Duplicate Error");
                        break;
                    }
                }
                catch (Exception ex) // catch any other issus
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                finally
                {
                    //display all, and keep state
                    this.displayAll(rowIndex, rowIndexSec, true);
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// On clicking drop products from packages
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDropPro_Click(object sender, EventArgs e)
 {
     //only activate button if that datagrid view has some elements
     if (dgViewSubPack.Rows.Count > 0)
     {
         int     rowIndex        = dgPackageProductSuppliers.CurrentRow.Index;                                              //needed to preserve state
         int     rowIndexSec     = dgProd.CurrentRow.Index;                                                                 //Just to preserve state
         Package selectedPackage = packages[rowIndex];                                                                      //Package to drop from
         Packages_Products_Supplier package_product_supplier = packages[rowIndex].packProd[dgViewSubPack.CurrentRow.Index]; //product supplier to drop
         DialogResult resultPackageProductSupplier           = MessageBox.Show("You are about to remove the product "
                                                                               + package_product_supplier.ProdName +
                                                                               " by \n\n" + package_product_supplier.SupName + " from " + selectedPackage.Name + " ? ",
                                                                               "Confirm Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (resultPackageProductSupplier == DialogResult.Yes)
         {
             try
             {   //if not concurrent
                 if (!Packages_Products_SuppliersDB.DeletePackages_Products_Supplier(package_product_supplier))
                 {
                     MessageBox.Show("Another user has updated or deleted " +
                                     "that product.", "Database Error");
                 }
                 //else refresh page
                 else
                 {
                     this.displayAll(rowIndex, rowIndexSec, true);
                 }
             }
             //Catch any other error
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }
コード例 #5
0
 //dispaly prodcut supplier info for certain package
 private void DisplayPackageProdSup()
 {
     SelectedRowPackage();
     packProdSups = Packages_Products_SuppliersDB.GetAllPackagesProductsSuppliers(package);
     packages_Products_SuppliersDataGridView.DataSource = packProdSups;
 }