private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (labelTitle.Text == "Add Product")
                {
                    ProductID.Text = (Inventory.Products.Count()).ToString();

                    // Sets the objects attributes
                    _Product.ProductID = int.Parse(ProductID.Text);
                    _Product.Name      = productName.Text;
                    _Product.InStock   = int.Parse(InStock.Text);
                    _Product.Price     = decimal.Parse(Price.Text);
                    _Product.Max       = int.Parse(Max.Text);
                    _Product.Min       = int.Parse(Min.Text);

                    // Adds product to the Product List
                    Inventory.addProduct(_Product);
                }
                else
                {
                    // reassigns the data to the new part
                    updateProduct.ProductID = int.Parse(ProductID.Text);
                    updateProduct.Name      = productName.Text;
                    updateProduct.InStock   = int.Parse(InStock.Text);
                    updateProduct.Price     = decimal.Parse(Price.Text);
                    updateProduct.Max       = int.Parse(Max.Text);
                    updateProduct.Min       = int.Parse(Min.Text);

                    // Passes the part index and the new part
                    Inventory.updateProduct(_productIndex, updateProduct);
                }
                // Makes sure the Min, Max, and inventory values are in the correct parameters.
                if (int.Parse(Max.Text) < int.Parse(Min.Text))
                {
                    MessageBox.Show("The minimum value is greater than the max value.");
                }
                if (int.Parse(Max.Text) < int.Parse(InStock.Text) || int.Parse(Min.Text) > int.Parse(InStock.Text))
                {
                    MessageBox.Show("The Inventory value exceeds the max or minimum value.");
                }
            }
            catch
            {
            }
            // Go back to main screen
            MainScreen mainScreen = new MainScreen();

            mainScreen.Show();
            this.Close();
        }
Example #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // The form will add parts
            if (labelTitle.Text == "Add Part")
            {
                // Checks to see if the Inhouse radio button was checked
                if (InHouse.Checked == true)
                {
                    // Creates instance of a new In-House Part
                    Inhouse InhousePart = new Inhouse();

                    PartID.Text = (Inventory.AllParts.Count()).ToString();

                    // Sets the objects attributes
                    InhousePart.PartID    = int.Parse(PartID.Text);
                    InhousePart.Name      = partName.Text;
                    InhousePart.InStock   = int.Parse(InStock.Text);
                    InhousePart.Price     = decimal.Parse(Price.Text);
                    InhousePart.Max       = int.Parse(Max.Text);
                    InhousePart.Min       = int.Parse(Min.Text);
                    InhousePart.MachineID = int.Parse(textBoxOption.Text);

                    // Adds InhousePart to the AllParts List
                    Inventory.addPart(InhousePart);
                }
                else
                {
                    // Creates instance of a new Outsourced Part
                    Outsourced outsourcedPart = new Outsourced();

                    PartID.Text = (Inventory.AllParts.Count()).ToString();

                    // Sets the objects attributes
                    outsourcedPart.PartID       = int.Parse(PartID.Text);
                    outsourcedPart.Name         = partName.Text;
                    outsourcedPart.InStock      = int.Parse(InStock.Text);
                    outsourcedPart.Price        = decimal.Parse(Price.Text);
                    outsourcedPart.Max          = int.Parse(Max.Text);
                    outsourcedPart.Min          = int.Parse(Min.Text);
                    outsourcedPart.Company_Name = textBoxOption.Text;

                    // Adds OutsourcedPart to the AllParts List
                    Inventory.addPart(outsourcedPart);
                }
            }
            else     // Updates the changes to selected parts
            {
                // Checks to see if the inhouse radio button was checked
                if (InHouse.Checked == true)
                {
                    Inhouse InhousePart = new Inhouse();

                    // reassigns the data to the new part
                    updatePart.PartID    = int.Parse(PartID.Text);
                    updatePart.Name      = partName.Text;
                    updatePart.InStock   = int.Parse(InStock.Text);
                    updatePart.Price     = decimal.Parse(Price.Text);
                    updatePart.Max       = int.Parse(Max.Text);
                    updatePart.Min       = int.Parse(Min.Text);
                    updatePart.MachineID = int.Parse(textBoxOption.Text);

                    // Passes the part index and the new part
                    Inventory.updatePart(_partIndex, updatePart);
                }
                else
                {
                    Outsourced updatePart_Outsourced = new Outsourced();

                    // reassigns the data to the new part
                    updatePart_Outsourced.PartID       = int.Parse(PartID.Text);
                    updatePart_Outsourced.Name         = partName.Text;
                    updatePart_Outsourced.InStock      = int.Parse(InStock.Text);
                    updatePart_Outsourced.Price        = decimal.Parse(Price.Text);
                    updatePart_Outsourced.Max          = int.Parse(Max.Text);
                    updatePart_Outsourced.Min          = int.Parse(Min.Text);
                    updatePart_Outsourced.Company_Name = textBoxOption.Text;


                    // Passes the part index and the new part
                    Inventory.updatePart(_partIndex, updatePart_Outsourced);
                }
            }

            // Checks to see if the min, max, and inventory values are within correct parameters
            if (int.Parse(Max.Text) < int.Parse(Min.Text))
            {
                MessageBox.Show("The minimum value is greater than the max value.");
            }
            if (int.Parse(Max.Text) < int.Parse(InStock.Text) || int.Parse(Min.Text) > int.Parse(InStock.Text))
            {
                MessageBox.Show("The Inventory value exceeds the max or minimum value.");
            }


            InHouse.Checked    = false;
            OutSourced.Checked = false;

            // Goes back to the Main Screen
            MainScreen mainScreen = new MainScreen();

            mainScreen.Show();
            this.Close();
        }