Ejemplo n.º 1
0
        /// <summary>
        /// Modify the current selected product in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// @Author - Rohit
        private void btnModifyProducts_Click(object sender, EventArgs e)
        {
            products = ProductsDB.GetAllProducts();

            if (products.FindIndex(prod => prod.ProductName == txtProductName.Text) >= 0)
            {
                MessageBox.Show("That product is already added.");
            }
            else
            {
                try
                {
                    int    ProdID   = Convert.ToInt32(ComProductId.SelectedItem);
                    string ProdName = txtProductName.Text;
                    if (string.IsNullOrEmpty(ProdName) || ComProductId.SelectedItem == null) // validation for null product name
                    {
                        MessageBox.Show("Please enter product name and select product ID.", "Incorrect Value");
                    }
                    else // if the product name is not null then use the modify method form database access class to modify the product
                    {
                        ProductsDB.ModifyProducts(ProdName, ProdID);
                        MessageBox.Show("Product name updated successfully", "Update"); // message pop up
                        clear();                                                        // clears the fields after modifying
                        ShowProductsInProductsTab();                                    // updates the datagridview after modifying the products
                    }
                }
                catch (FormatException)                                                     // catches any format issues and null value exceptions
                {
                    MessageBox.Show("Null values are not allowed", "Null Value Exception"); // message pop up
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add button adds new products to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// @Author - Rohit
        private void btnAddProducts_Click(object sender, EventArgs e)
        {
            products = ProductsDB.GetAllProducts();

            if (products.FindIndex(prod => prod.ProductName == txtProductName.Text) >= 0)
            {
                MessageBox.Show("That product is already added.");
            }
            else
            {
                try
                {
                    ComProductId.Enabled = false;                                               // disables the product id textbox (not required while adding products)
                    string ProdName = txtProductName.Text;
                    if (ProdName == "")                                                         // null value validation on product name
                    {
                        MessageBox.Show("Null and Dublicate values are not allowed.", "Error"); // message box pop uo
                    }
                    else // if product name is not null add the new product using Add product method
                    {
                        ProductsDB.AddProducts(ProdName);
                        ShowProductsInProductsTab();                                      // Updates data grid view
                        LoadComboBox();                                                   // updates combo box to view the added product immediately
                        MessageBox.Show("New product succesfully added.", "Add Product"); // message box pop up
                        clear();                                                          // clears the fields after adding new product
                    }
                    ComProductId.Enabled = true;                                          // After the product is added, enable the product id textbox
                }
                catch (FormatException)                                                   // catches any format issues and null value exceptions
                {
                    MessageBox.Show("Null values are not allowed, Type correct information.", "Null Value / Incorrect Format");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Once the products tab is selected, populate the combo box and datagrid view
        /// </summary>
        /// @Author - Rohit
        private void LoadComboBox()
        {
            ComProductId.Items.Clear();                                 // clear the grid view
            List <Products> dispProducts = ProductsDB.GetAllProducts(); // get products from database

            ViewProducts.DataSource = dispProducts;                     // display them

            // loop through products and add ids to drop down
            foreach (Products prod in dispProducts)
            {
                ComProductId.Items.Add(prod.ProductID.ToString());
            }
        }
Ejemplo n.º 4
0
        // Load data for main form (first tab - Packages).
        private void loadMainFormData()
        {
            try
            {
                // access packages from db in thread (ASYNCHRONOUS) - Probably uneccessary

                /*Thread pkgWork = new Thread(() =>
                 * Thread pkgWork = new Thread(() =>
                 * {
                 *  packages = PackageDB.GetPackages();
                 * });
                 *
                 * // access all products from db in thread
                 * Thread prodWork = new Thread(() =>
                 * {
                 *  products = ProductsDB.GetAllProducts();
                 * });
                 *
                 * pkgWork.Start();
                 * prodWork.Start();
                 *
                 * pkgWork.Join();
                 * prodWork.Join();*/
                packages = PackageDB.GetPackages();
                products = ProductsDB.GetAllProducts();

                // access products and suppliers associated with current package
                PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps);

                ShowPackages();
                ShowAllProducts();
                ShowPkgProducts(pkgProducts, pkgProdSupps);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while loading data.\n\n" + ex.Message,
                                ex.GetType().ToString());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the data grid view after modifying or adding a new product
        /// </summary>
        /// @Author - Rohit
        private void ShowProductsInProductsTab()
        {
            List <Products> dispProducts = ProductsDB.GetAllProducts();

            ViewProducts.DataSource = dispProducts;
        }