Ejemplo n.º 1
0
        // Grabbing the data needed to insert into Products_Suppliers Table
        private Products_Suppliers PutInSuppToProd(Products_Suppliers prodSupp)
        {
            prodSupp.ProductSupplierId = Convert.ToInt32(txtProdSuppId.Text);
            prodSupp.ProductId         = ProductsDB.getProductId(txtProdName.Text);      // Grabbing Product Id through Product name
            prodSupp.SupplierId        = SuppliersDB.getSupplierId(cbSupplierName.Text); // Grabbing Supplier Id through Supplier name

            return(prodSupp);
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (cBSupplier.SelectedText != "")
            {
                string prodNameSelected = cBProduct.GetItemText(cBProduct.SelectedItem); //Get the product name for the selected product
                int    prodIdSelected   = ProductsDB.getProductId(prodNameSelected);     //find the productId of the selected item
                                                                                         // get thee supplier name from the combo box selection
                string supNameSelected = cBSupplier.GetItemText(cBSupplier.SelectedItem);
                // get the supplierID from the suppliername using the method in SuppliersDB
                int supplierIdSelected = SuppliersDB.getSupplierId(supNameSelected);
                // product supplier ID is equal to a method that retrieves it in a SQL Query
                int ppsID = Products_SuppliersDB.Get_PpsID(prodIdSelected, supplierIdSelected);
                // pkgID is equal to the selected ITEM at the index clicked to maintain consistency
                int pkgID = Convert.ToInt32(lvPackages.Items[lvPackages.SelectedItems[0].Index].Text);

                bool exists  = false;
                bool attempt = false;

                if (!exists) // if it does not exist, do this
                {
                    try
                    {
                        // attempt = add product to package method, taking product supplier id and package id as arguments
                        attempt = PackagesDB.AddProdToPackage(ppsID, pkgID);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("Error modifying package\n" + ex);
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Succesfully modified");
                        int i = 0;
                        lvPkgDetails.Items.Clear();
                        List <Package_Product_Suppliers> pps_o = PackagesDB.GetProductSuppliersByPackage(pkgID);
                        foreach (Package_Product_Suppliers pps in pps_o)
                        {
                            lvPkgDetails.Items.Add(pps.ProdName);
                            lvPkgDetails.Items[i].SubItems.Add(pps.SupName);
                            i += 1;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Package is already in the database");
                }
            }
            else
            {
                MessageBox.Show("Please choose a valid supplier");
            }
        }
Ejemplo n.º 3
0
 // Opens Delete product form
 private void btnDeleteProd_Click(object sender, EventArgs e)
 {
     prodNameSelected = lbProducts.GetItemText(lbProducts.SelectedItem);
     prodIdSelected   = ProductsDB.getProductId(prodNameSelected);
     using (DeleteProducts deleteproduct = new DeleteProducts())
     {
         if (deleteproduct.ShowDialog() == DialogResult.OK)
         {
         }
     }
 }
Ejemplo n.º 4
0
 // Opens Modify product form
 private void btnModifyProd_Click(object sender, EventArgs e)
 {
     prodNameSelected = lbProducts.GetItemText(lbProducts.SelectedItem);
     prodIdSelected   = ProductsDB.getProductId(prodNameSelected);
     using (frmModifyProd modifyproduct = new frmModifyProd())
     {
         if (modifyproduct.ShowDialog() == DialogResult.OK)
         {
         }
     }
 }
Ejemplo n.º 5
0
        private void GetSup()
        {
            try
            {
                int productId = ProductsDB.getProductId(prodName);//find the productId of the selected item
                //Get a list of supppiers for the selected product
                List <Suppliers> suppliersSel = Products_SuppliersDB.GetSupForProd(productId);

                //Display the suppliers for the selected product
                foreach (Suppliers supplier in suppliersSel)
                {
                    cbSupName.Items.Add(supplier.SupName);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }