コード例 #1
0
        //* Overall button controls *//
        //This method controls the show all button. When this button is clicked all the products and suppliers will be shown in the
        //listboxes
        private void btnShowAll_Click(object sender, EventArgs e)
        {
            products  = ProductsDB.GetProducts();   //All the products are retreived using ProductsDB.GetProducts()
            suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers()

            ReloadListboxes();
        }
コード例 #2
0
        // This method populates the combo box with available Suppliers
        private void LoadSupplierCB()
        {
            int prodId = ProductsDB.getProductId(prodName);

            List <Suppliers> temp         = new List <Suppliers>(); // Temp variable to store in order to convert string to int
            List <Suppliers> supplierList = new List <Suppliers>();

            // Grabs all supplier ID that doesn't have the particular supplier ID in Product_Supplier
            temp = Products_SuppliersDB.GetNotInSuppliersID(prodId);
            try
            {
                foreach (Suppliers supplier in temp)
                {
                    // Converts the Supplier IDs to Supplier Names
                    supplier.SupName = SuppliersDB.getSupName(supplier.SupplierId);
                    supplierList.Add(supplier);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            // Populate the combo box
            try
            {
                cbSupplierName.DataSource    = supplierList;
                cbSupplierName.DisplayMember = "SupName";
                cbSupplierName.ValueMember   = "SupplierId";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
コード例 #3
0
        private void btnGetNext_Click(object sender, EventArgs e)
        {
            int NextID = 0;

            NextID             = SuppliersDB.getNextSupplierId();
            txtSupplierId.Text = NextID.ToString();
        }
コード例 #4
0
        // Deletes the Product_Supplier ID
        private void btnDelete_Click_1(object sender, EventArgs e)
        {
            prodName = cbProdName.Text;
            supName  = cbSupName.Text;

            // Grabs the ID through product and supplier names
            int prodID = ProductsDB.getProductId(prodName);
            int supID  = SuppliersDB.getSupplierId(supName);

            // Confirmation message for delete
            DialogResult result = MessageBox.Show("Are you sure you want to delete link between "
                                                  + prodName + " and " + supName + "?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!Products_SuppliersDB.DeleteProdSup(prodID, supID)) // Checks the DB
                    {
                        MessageBox.Show("Another user has updated or deleted " +
                                        "that customer.", "Database Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Cannot delete current Product Supplier when it is added as a product in\n" +
                                    "a package. Please remove the product from the package first");
                }
            }
            this.Close();
        }
コード例 #5
0
        //This method controls what happens when someone selects a supplier in the supplier listbox. When a supplier is selected
        //the product list box is populated with the products associated with the supplier.
        private void lbSuppliers_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbProducts.Items.Clear();//clear all the items in the list box for the products
            try
            {
                string supName    = lbSuppliers.GetItemText(lbSuppliers.SelectedItem); //get the supplier name for the selected supplier
                int    supplierId = SuppliersDB.getSupplierId(supName);                //get the supplier id from the supplier name
                //use that supplierId to get all the products that are associated with the supplier Id
                List <Products> productsSel = Products_SuppliersDB.GetProdForSup(supplierId);

                //Display the products for the selected supplier
                foreach (Products product in productsSel)
                {
                    lbProducts.Items.Add(product.ProdName);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            // Button controls
            btnModifyProd.Visible   = false;
            btnDeleteProd.Visible   = false;
            btnDeleteData.Visible   = true;
            btnAddSupToProd.Visible = false;
            btnAddProdToSup.Visible = true;
            btnModifySup.Visible    = true;
            btnDeleteSup.Visible    = true;
        }
コード例 #6
0
        private void frmProduct_Supplier_Activated(object sender, EventArgs e)
        {
            products  = ProductsDB.GetProducts();   //All the products are retreived using ProductsDB.GetProducts()
            suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers()

            ReloadListboxes();
        }
コード例 #7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtSupplierId))
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete this supplier?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    bool attempt = false;
                    try
                    {
                        attempt = SuppliersDB.DeleteSupplier(supplierId);
                    }
                    catch
                    {
                        MessageBox.Show("Cannot delete " + supName + " when it is currently linked a Supplier." +
                                        " Please remove all links for " + supName + " in order to delete the product");
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Successfully deleted " + supName);
                        this.Close();
                    }
                }
            }
        }
コード例 #8
0
        // This method populates the combo box with available Products
        private void LoadProductCB()
        {
            int supId = SuppliersDB.getSupplierId(suppName);

            List <Products> temp        = new List <Products>(); // Temp variable to store in order to convert string to int
            List <Products> productList = new List <Products>();

            // Grabs all product ID that doesn't have the particular supplier ID in Product_Supplier
            temp = Products_SuppliersDB.GetNotInProductsID(supId);
            try
            {
                // Converts the Product IDs to Product Names
                foreach (Products products in temp)
                {
                    products.ProdName = ProductsDB.getProdName(products.ProductId);
                    productList.Add(products);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            // Populate the combo box
            try
            {
                cbProductName.DataSource    = productList;
                cbProductName.DisplayMember = "ProdName";
                cbProductName.ValueMember   = "ProductId";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
コード例 #9
0
        private void btnDeleteProduct_Click(object sender, EventArgs e)
        {
            //supName is equal to the selected items at index 0 to text
            string supName = (lvPkgDetails.Items[lvPkgDetails.SelectedItems[0].Index].Text);
            //suppID is equal to the result of the getProductId method taking supName as an argument
            int suppID = ProductsDB.getProductId(supName);

            //prodName is equal to the selected items at index 0, sub-item index 1 to text
            string prodName = lvPkgDetails.SelectedItems[0].SubItems[1].Text;
            //prodID is equal to the result of the getSupplierId method taking prodName as an argument
            int prodID = SuppliersDB.getSupplierId(prodName);

            //productSupplierID is equal to the result of the get_PpsID method taking suppID and prodID as arguments
            int psID = Products_SuppliersDB.Get_PpsID(suppID, prodID);

            // pkgID is equal to the result of the GetPackageIDBy_PsID method taking PsID as an argument
            int pkgID = PackagesDB.GetPackageIDBy_PsID(psID);

            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 = ProductsDB.deleteProductFromPkg(pkgID, psID);
                    //MessageBox.Show("Succesfully deleted");
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("Error modifying package\n" + ex);
                }

                if (attempt)
                {
                    MessageBox.Show("Succesfully deleted");
                    lvPkgDetails.Items.Clear();
                    int i = 0;
                    //int pkgID = lvPackages.Items.IndexOf(lvPackages.SelectedItems[i]); -- this is an old logic used

                    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("Unable to delete");
            }

            btnAddPackage.Visible    = true;
            btnDeleteProduct.Visible = false;
            lvPkgDetails.Items.Clear();
        }
コード例 #10
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);
        }
コード例 #11
0
        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");
            }
        }
コード例 #12
0
 // Opens delete supplier form
 private void btnDeleteSup_Click_1(object sender, EventArgs e)
 {
     supNameSelected    = lbSuppliers.GetItemText(lbSuppliers.SelectedItem);
     supplierIdSelected = SuppliersDB.getSupplierId(supNameSelected);
     using (DeleteSuppliers deletesupplier = new DeleteSuppliers())
     {
         if (deletesupplier.ShowDialog() == DialogResult.OK)
         {
         }
     }
 }
コード例 #13
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //check if the information is valid and present
            if (Validator.IsPresent(txtSupplierId) && Validator.IsPresent(txtSupplierName) &&
                Validator.NonNegativeInt32(txtSupplierId))
            {
                string           supName    = txtSupplierName.Text;
                int              supplierId = Convert.ToInt32(txtSupplierId.Text);
                bool             exists     = false;
                bool             attempt    = false;
                List <Suppliers> suppliers  = SuppliersDB.GetSuppliers();
                //for each supplier in suppliers list, check if the new name is present
                foreach (Suppliers supplier in suppliers)
                {
                    if (supplier.SupName == supName)
                    {
                        exists = true;
                    }
                }

                if (!exists)
                {
                    //if there is no name by the name
                    try
                    {
                        //replace the information
                        attempt = SuppliersDB.UpdateSupplier(supplierId, supName, oldsupplierid, oldsupName);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("Error modifying supplier\n" + ex);
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Successfully modified");
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Supplier name is already in the database");
                }
            }
        }
コード例 #14
0
        //This method is used to get the suppliers for a certain productId. It returns a List of suppliers
        public static List <Suppliers> GetSupForProd(int productId)
        {
            List <Suppliers> supplierList = new List <Suppliers>(); //create a list of suppliers
            Suppliers        supplier     = null;                   //create a supplier and set it to null

            SqlConnection con = TravelExpertsDB.GetConnection();    //Create a connection
            //Create a query that selects all the supplier ID's from the product suppliers where the product ID is given
            string selectQuery = "SELECT SupplierId " +
                                 "FROM Products_Suppliers " +
                                 "WHERE ProductId = @ProductId";
            SqlCommand selectCommand = new SqlCommand(selectQuery, con);    //Create a selectCommand using SqlCommand

            selectCommand.Parameters.AddWithValue("@ProductId", productId); //Bind the given productId to @ProductId

            try
            {
                con.Open();                                          //Open connection
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())                                //read the supplierId's if they exist
                {
                    supplier            = new Suppliers();           //create a new supplier
                    supplier.SupplierId = (int)reader["SupplierId"]; //Add the Id to the supplier
                    supplierList.Add(supplier);                      //Add the supplier to the list of suppliers
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();//Close the connection
            }
            //We now have all the id's for the suppliers but do not have there supplier names
            //Go through each of the suppliers in the supplier list and find there names
            foreach (Suppliers sup in supplierList)
            {
                //use getSupName which is from the SuppliersDB to find the names of the suppliers and add them to there
                //corresponding suppliers.
                sup.SupName = SuppliersDB.getSupName(sup.SupplierId);
            }
            return(supplierList);//return the supplier list
        }
コード例 #15
0
        private void GetProd()
        {
            try
            {
                int supplierId = SuppliersDB.getSupplierId(supName);//get the supplier id from the supplier name
                //use that supplierId to get all the products that are associated with the supplier Id
                List <Products> productsSel = Products_SuppliersDB.GetProdForSup(supplierId);

                //Display the products for the selected supplier
                foreach (Products product in productsSel)
                {
                    cbProdName.Items.Add(product.ProdName);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
コード例 #16
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtSupplierId) && Validator.IsPresent(txtSupplierName) &&
                Validator.NonNegativeInt32(txtSupplierId))
            {
                string supName    = txtSupplierName.Text;
                int    supplierId = Convert.ToInt32(txtSupplierId.Text);
                bool   exists     = false;
                bool   attempt    = false;

                List <Suppliers> suppliers = SuppliersDB.GetSuppliers();
                foreach (Suppliers supplier in suppliers)
                {
                    if (supplier.SupName == supName)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    try
                    {
                        attempt = SuppliersDB.InsertSupplier(supplierId, supName);
                    }
                    catch
                    {
                        MessageBox.Show("Provided Supplier ID already exists, please enter a different one");
                        txtSupplierId.Focus();
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Successfully added " + supName + " to the database");
                        this.Close();
                    }
                }
            }
        }