public ModifyPart(Outsourced outsourced)
 {
     InitializeComponent();
     inHouseRadioBtn.Checked    = false;
     outsourcedRadioBtn.Checked = true;
     idTextBox.Enabled          = false;
     idTextBox.Text             = outsourced.PartID.ToString();
     nameTextBox.Text           = outsourced.Name;
     inventoryTextBox.Text      = outsourced.InStock.ToString();
     priceTextBox.Text          = outsourced.Price.ToString();
     maxTextBox.Text            = outsourced.Max.ToString();
     minTextBox.Text            = outsourced.Min.ToString();
     machIdLabel.Text           = "Company Name";
     machIdTextBox.Text         = outsourced.CompanyName.ToString();
 }
 private void modifyPartsBtn_Click(object sender, EventArgs e)
 {
     if (partsDataGridView.CurrentRow.DataBoundItem.GetType() == typeof(InHouse))
     {
         InHouse    inHouse    = (InHouse)partsDataGridView.CurrentRow.DataBoundItem;
         ModifyPart modifyPart = new ModifyPart(inHouse);
         modifyPart.ShowDialog();
     }
     else
     {
         Outsourced outsourced = (Outsourced)partsDataGridView.CurrentRow.DataBoundItem;
         ModifyPart modifyPart = new ModifyPart(outsourced);
         modifyPart.ShowDialog();
     }
 }
        /*      // Function to display Parts in datagridview
         *    private void displayPartsDGV()
         *    {
         *        partsDataGridView.AutoGenerateColumns = false;
         *        partsDataGridView.DataSource = Inventory.AllParts;
         *        partsDataGridView.ClearSelection();
         *    }
         *
         *    // Function to display Products in datagridview
         *    private void displayProductsDGV()
         *    {
         *        productsDataGridView.AutoGenerateColumns = false;
         *        productsDataGridView.DataSource = Inventory.Products;
         *        productsDataGridView.ClearSelection();
         *    }
         *
         */

        // Pre-populate inventory data
        private void populateData()
        {
            Part part1 = new InHouse(70001, "Mouse", 60, 4.99m, 200, 2);
            Part part2 = new InHouse(70002, "Keyboard", 60, 14.99m, 200, 2);
            Part part3 = new InHouse(70003, "24\" Monitor", 50, 109.99m, 100, 2);
            Part part4 = new InHouse(70004, "Base Tower", 40, 499.99m, 100, 2);
            Part part5 = new Outsourced(2548, "29\" Ultra-Wide Monitor", 20, 249.99m, 40, 2, "Amajohns");
            Part part6 = new Outsourced(2876, "Premium Tower", 20, 599.99m, 40, 2, "Amajohns");

            Inventory.AllParts.Add(part1);
            Inventory.AllParts.Add(part2);
            Inventory.AllParts.Add(part3);
            Inventory.AllParts.Add(part4);
            Inventory.AllParts.Add(part5);
            Inventory.AllParts.Add(part6);

            Product product1 = new Product(765321, "Base PC", 40, 574.99m, 100, 2);

            product1.AddAssociatedPart(part1);
            product1.AddAssociatedPart(part2);
            product1.AddAssociatedPart(part4);

            Product product2 = new Product(765123, "Base PC /w Monitor", 40, 674.99m, 100, 2);

            product2.AddAssociatedPart(part1);
            product2.AddAssociatedPart(part2);
            product2.AddAssociatedPart(part3);
            product2.AddAssociatedPart(part4);

            Product product3 = new Product(765321, "Premium PC", 20, 674.99m, 40, 2);

            product3.AddAssociatedPart(part1);
            product3.AddAssociatedPart(part2);
            product3.AddAssociatedPart(part6);

            Product product4 = new Product(765321, "Premium PC /w Ultra-Wide Monitor", 20, 899.99m, 40, 2);

            product4.AddAssociatedPart(part1);
            product4.AddAssociatedPart(part2);
            product4.AddAssociatedPart(part5);
            product4.AddAssociatedPart(part6);

            Inventory.Products.Add(product1);
            Inventory.Products.Add(product2);
            Inventory.Products.Add(product3);
            Inventory.Products.Add(product4);
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            int     partID;
            string  name = nameTextBox.Text;
            int     inStock;
            decimal price;
            int     max;
            int     min;
            int     machineID   = 0;
            string  companyName = "";

            try
            {
                partID  = int.Parse(idTextBox.Text);
                inStock = int.Parse(inventoryTextBox.Text);
                price   = decimal.Parse(priceTextBox.Text);
                max     = int.Parse(maxTextBox.Text);
                min     = int.Parse(minTextBox.Text);
                if (inHouseRadioBtn.Checked)
                {
                    machineID = int.Parse(machIdTextBox.Text);
                }
                if (outsourcedRadioBtn.Checked)
                {
                    companyName = machIdTextBox.Text;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show($"Please make sure all fields are filled correctly.{ex.ToString()}");
                return;
            }

            if (inStock > max || inStock < min)
            {
                if (inStock > max)
                {
                    MessageBox.Show("Invalid input. Inventory must be less than Max");
                    return;
                }
                else
                {
                    MessageBox.Show("Invalid input. Inventory must be greater than Min");
                    return;
                }
            }

            if (inHouseRadioBtn.Checked)
            {
                InHouse part = new InHouse(partID, name, inStock, price, max, min, machineID);
                Inventory.UpdatePart(partID, part);
                MessageBox.Show($"{Name} successfully updated.");
                this.Close();
            }

            if (outsourcedRadioBtn.Checked)
            {
                Outsourced part = new Outsourced(partID, name, inStock, price, max, min, companyName);
                Inventory.UpdatePart(partID, part);
                MessageBox.Show($"{name} successfully updated.");
                this.Close();
            }

            this.Hide();
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            string  name = nameTextBox.Text;
            int     inStock;
            decimal price;
            int     max;
            int     min;
            int     machineID   = 0;
            string  companyName = "";

            try
            {
                inStock = int.Parse(inventoryTextBox.Text);
                price   = decimal.Parse(priceTextBox.Text);
                max     = int.Parse(maxTextBox.Text);
                min     = int.Parse(minTextBox.Text);
                if (inHouseRadioBtn.Checked)
                {
                    machineID = int.Parse(machIdTextBox.Text);
                }
                if (outsourcedRadioBtn.Checked)
                {
                    companyName = machIdTextBox.Text;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Please make sure each field has a valid input {ex.ToString()}");
                return;
            }

            if (max < min)
            {
                MessageBox.Show("Min must be less than Max");
                return;
            }
            if (inStock > max || inStock < min)
            {
                if (inStock > max)
                {
                    MessageBox.Show("Invalid Number. Inventory ammount must be less than Max");
                    return;
                }
                else
                {
                    MessageBox.Show("Invalid Number. Inventory ammount must be greater than Min");
                    return;
                }
            }

            if (inHouseRadioBtn.Checked)
            {
                InHouse part = new InHouse(ProductNumber(), name, inStock, price, max, min, machineID);
                Inventory.AddPart(part);
                MessageBox.Show($"{name} was successfully added");
                Close();
            }
            if (outsourcedRadioBtn.Checked)
            {
                Outsourced part = new Outsourced(ProductNumber(), name, inStock, price, max, min, companyName);
                Inventory.AddPart(part);
                MessageBox.Show($"{name} was successfully added");
                Close();
            }
        }