public AddModifyPartScreen(int part)
        {
            InitializeComponent();
            creatingNewPartID    = false;
            mainPartsHeader.Text = "Modify Part";
            textBox1.Text        = Inventory.AllParts[part].PartID.ToString();
            textBox2.Text        = Inventory.AllParts[part].Name.ToString();
            textBox3.Text        = Inventory.AllParts[part].InStock.ToString();
            textBox4.Text        = Inventory.AllParts[part].Price.ToString();
            textBox5.Text        = Inventory.AllParts[part].Max.ToString();
            textBox7.Text        = Inventory.AllParts[part].Min.ToString();
            var castPartType = Inventory.AllParts[part];

            if (Inventory.AllParts[part].GetType().Equals(typeof(Inhouse)))
            {
                Inhouse castToInhouse = (Inhouse)castPartType;
                textBox6.Text        = castToInhouse.MachineID.ToString();
                textBox1.ReadOnly    = true;
                textBox1.BackColor   = Color.DarkGray;
                labelPartMachID.Text = "Machine ID";
                inhouseRadio.Checked = true;
            }
            if (Inventory.AllParts[part].GetType().Equals(typeof(Outsourced)))
            {
                Outsourced castToOutsourced = (Outsourced)castPartType;
                textBox6.Text           = castToOutsourced.companyName.ToString();
                textBox1.ReadOnly       = true;
                textBox1.BackColor      = Color.DarkGray;
                labelPartMachID.Text    = "Company Name";
                outsourcedRadio.Checked = true;
            }
        }
Ejemplo n.º 2
0
 public frmModifyPart(Inhouse part) : this()
 {
     tbID.Text          = part.PartId.ToString();
     tbName.Text        = part.Name;
     tbInventory.Text   = part.InStock.ToString();
     tbMinQuantity.Text = part.Min.ToString();
     tbMaxQuantity.Text = part.Max.ToString();
     tbPrice.Text       = part.Price.ToString();
     tbSource.Text      = part.MachineID.ToString();
 }
Ejemplo n.º 3
0
        public Part(Inhouse inPart)
        {
            InitializeComponent();

            idInput.Text        = inPart.PartID.ToString();
            nameInput.Text      = inPart.Name;
            inventoryInput.Text = inPart.InStock.ToString();
            priceInput.Text     = inPart.Price.ToString();
            maxInput.Text       = inPart.Max.ToString();
            minInput.Text       = inPart.Min.ToString();
            machineIDinput.Text = inPart.MachineID.ToString();
        }
        private void modifySavePartButton_Click(object sender, EventArgs e)
        {
            var partToEdit = inventory.GetPartsList().FirstOrDefault(editPart => editPart.partID == Convert.ToInt32(modifyPartIDTextBox.Text));
            int partIndex  = inventory.GetPartsList().IndexOf(partToEdit);
            int minVal     = Convert.ToInt32(modifyPartMinTextBox.Text);
            int maxVal     = Convert.ToInt32(modifyPartMaxTextBox.Text);
            int invVal     = Convert.ToInt32(modifyPartInvTextBox.Text);

            if (minVal > maxVal)
            {
                modifyPartMinTextBox.BackColor = Color.Red;
                MessageBox.Show("Minimum value cannot be greater than maximum value. Please correct.", "Invalid Values");
                return;
            }

            if (invVal < minVal || invVal > maxVal)
            {
                modifyPartInvTextBox.BackColor = Color.Red;
                MessageBox.Show("Inventory value must not be lower than the minimum value or higher than the maximum value.", "Invalid Values");
                return;
            }

            if (modifyInhouseRadioButton.Checked)
            {
                Inhouse modIHPart = new Inhouse();
                modIHPart.partID    = Convert.ToInt32(modifyPartIDTextBox.Text);
                modIHPart.name      = modifyPartNameTextBox.Text;
                modIHPart.inStock   = invVal;
                modIHPart.price     = double.Parse(modifyPartPriceCostTextBox.Text, System.Globalization.NumberStyles.Currency);
                modIHPart.min       = minVal;
                modIHPart.max       = maxVal;
                modIHPart.machineID = Convert.ToInt32(modifyPartCompanyOrMachine.Text);

                inventory.UpdatePart(partIndex, modIHPart);
            }

            if (modifyOutsourcedRadioButton.Checked)
            {
                Outsourced modOsPart = new Outsourced();
                modOsPart.partID      = Convert.ToInt32(modifyPartIDTextBox.Text);
                modOsPart.name        = modifyPartNameTextBox.Text;
                modOsPart.inStock     = invVal;
                modOsPart.price       = double.Parse(modifyPartPriceCostTextBox.Text, System.Globalization.NumberStyles.Currency);
                modOsPart.min         = minVal;
                modOsPart.max         = maxVal;
                modOsPart.companyName = modifyPartCompanyOrMachine.Text;

                inventory.UpdatePart(partIndex, modOsPart);
            }

            this.Close();
        }
        public ModifyPart(Inventory inventoryClass, Inhouse part)
        {
            InitializeComponent();
            inventory = inventoryClass;


            modifyPartIDTextBox.Text             = part.partID.ToString();
            modifyPartNameTextBox.Text           = part.name;
            modifyPartInvTextBox.Text            = part.inStock.ToString();
            modifyPartPriceCostTextBox.Text      = part.price.ToString("C", new System.Globalization.CultureInfo("en-US"));
            modifyPartMinTextBox.Text            = part.min.ToString();
            modifyPartMaxTextBox.Text            = part.max.ToString();
            modifyPartCompanyOrMachine.Text      = part.machineID.ToString();
            modifyPartMachineOrCompanyLabel.Text = "Machine ID";
            modifyInhouseRadioButton.Checked     = true;
        }
Ejemplo n.º 6
0
        private void save_Click(object sender, EventArgs e)
        {
            this.Hide();
            if (machineTxt.Text != "" && companyNameTxt.Text == "")
            {
                Part newPart = new Inhouse(nameText.Text, int.Parse(inventoryText.Text), decimal.Parse(priceText.Text), int.Parse(minText.Text), int.Parse(maxText.Text), int.Parse(machineTxt.Text));
                Inventory.updatePart(int.Parse(idText.Text), newPart);
            }
            else
            {
                Part newPart = new Outsourced(nameText.Text, int.Parse(inventoryText.Text), decimal.Parse(priceText.Text), int.Parse(minText.Text), int.Parse(maxText.Text), companyNameTxt.Text);
                Inventory.updatePart(int.Parse(idText.Text), newPart);
            }
            MainScreen mainScreen = new MainScreen();

            mainScreen.Show();
        }
Ejemplo n.º 7
0
        private void save_Click(object sender, EventArgs e)
        {
            this.Hide();
            if (machineTxt.BackColor == Color.White)
            {
                Part newPart = new Inhouse(nameText.Text, int.Parse(inventoryText.Text), decimal.Parse(priceText.Text), int.Parse(minText.Text), int.Parse(maxText.Text), int.Parse(machineTxt.Text));
                Inventory.addPart(newPart);
            }
            else
            {
                Part newPart = new Outsourced(nameText.Text, int.Parse(inventoryText.Text), decimal.Parse(priceText.Text), int.Parse(minText.Text), int.Parse(maxText.Text), companyNameTxt.Text);
                Inventory.addPart(newPart);
            }
            MainScreen mainScreen = new MainScreen();

            mainScreen.Show();
        }
Ejemplo n.º 8
0
        static void Main()
        {
            //populate sample data here
            Inhouse    part  = new Inhouse(Inventory.GetNextPartID(), "Power Converter", 100, 2, 1, 255, 22);;
            Outsourced part2 = new Outsourced(Inventory.GetNextPartID(), "Warp core ejector coil", 1024, 1, 1, 25, "Academy surplus");
            Outsourced part3 = new Outsourced(Inventory.GetNextPartID(), "Litigating Ligature", 53.09, 1, 1, 8, "Johnnie Cochran Supply");
            Outsourced part4 = new Outsourced(Inventory.GetNextPartID(), "Redudant Rotating Oscillator", 3.50, 1, 1, 25, "redundundundancy inc.");
            Outsourced part5 = new Outsourced(Inventory.GetNextPartID(), "George bushing", 5309, 2005, 2001, 2009, "Whitehouse procurement co.");
            Outsourced part6 = new Outsourced(Inventory.GetNextPartID(), "Over-bearing", 5309, 99, 10, 250, "Inlaws R Us");

            //Inventory.AllParts.Add(part);
            Inventory.addPart(part);
            Inventory.addPart(part2);
            Inventory.addPart(part3);
            Inventory.addPart(part4);
            Inventory.addPart(part5);
            Inventory.addPart(part6);

            //Products sample data
            Product product1 = new Product(1, "Red Bicycle", 11.14, 15, 5, 25);
            Product product2 = new Product(2, "Yellow Bicycle", 9.66, 19, 1, 20);
            Product product3 = new Product(3, "Blue Bicycle", 12.77, 5, 1, 25);

            Inventory.addProduct(product1);
            Inventory.addProduct(product2);
            Inventory.addProduct(product3);

            //Asso Part
            product1.AssociatedParts.Add(part);
            product2.AssociatedParts.Add(part2);
            product3.AssociatedParts.Add(part3);


            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Main main = new Main();

            Application.Run(main);
        }
Ejemplo n.º 9
0
        //Methods for class use
        /// <summary>
        /// Loads 4 initial Part objects and 2 Product objects on startup
        /// </summary>
        private void loadInitialObjects()
        {
            //Create a list of Inhouse Objects, Create Objects, and add them to the list to load with the Application


            //Create Parts, and add them to inventory
            var inhousePart1 = new Inhouse("Motors", 33.29, 6, 1, 15, 33);

            inv.addPart(inhousePart1);

            var inhousePart2 = new Inhouse("Gears", 1.22, 5, 1, 33, 11);

            inv.addPart(inhousePart2);

            var inhousePart3 = new Inhouse("Air Freshners", 0.99, 50, 1, 100, 20);

            inv.addPart(inhousePart3);

            var outsourced1 = new Outsourced("Screamers", 30.22, 5, 1, 10, "Monsters Inc");

            inv.addPart(outsourced1);

            //Create Products, then add them to inventory

            //Create list of Parts for Product
            List <Part> productListofParts1 = new List <Part>();

            productListofParts1.Add(outsourced1);
            productListofParts1.Add(inhousePart1);
            var product1 = new Product("Monster Stuff", 200.00, 3, 1, 10, productListofParts1, inv);

            inv.addProduct(product1);

            List <Part> productListofParts2 = new List <Part>();

            productListofParts2.Add(inhousePart1);
            productListofParts2.Add(inhousePart2);
            productListofParts2.Add(inhousePart3);
            var product2 = new Product("Car Stuff", 400.00, 2, 1, 5, productListofParts2, inv);

            inv.addProduct(product2);


            //Create a datatable to hold the table structure in it.
            dtParts.Columns.Add("Part ID", typeof(int));
            dtParts.Columns.Add("Part Name", typeof(string));
            dtParts.Columns.Add("Inventory Level", typeof(int));
            dtParts.Columns.Add(@"Price/Cost Per Unit", typeof(double));

            //Create a datatable to hold the Product table structure in it.
            dtProducts.Columns.Add("Product ID", typeof(int));
            dtProducts.Columns.Add("Product Name", typeof(string));
            dtProducts.Columns.Add("Inventory Level", typeof(int));
            dtProducts.Columns.Add(@"Price Per Unit", typeof(double));

            //Populate Parts Data Table with inventory object
            repopulatePartsDatatable(dtParts, inv);
            repopulateProductsDatatable(dtProducts, inv);

            //Bind the Parts DataTable to the gridView
            dataGridViewParts.Columns.Clear();
            dataGridViewParts.DataSource = dtParts;

            //bind Products DataTable to gridview
            dataGridViewProducts.Columns.Clear();
            dataGridViewProducts.DataSource = dtProducts;
        }
Ejemplo n.º 10
0
        public MainForm()
        {
            InitializeComponent();

            #region Sample data generation for debugging purposes


            Outsourced newOutsourced = new Outsourced
            {
                partID      = 456,
                name        = "Disc Brake",
                price       = 29.99,
                inStock     = 4,
                min         = 2,
                max         = 10,
                companyName = "Advanced Braking Co."
            };

            Inhouse newInhouse = new Inhouse
            {
                partID    = 197,
                name      = "Front Light",
                price     = 15.99,
                inStock   = 7,
                min       = 5,
                max       = 15,
                machineID = 51347
            };

            inventory.AddPart(newOutsourced);
            inventory.AddPart(newInhouse);

            Product electricScooter = new Product
            {
                productID = 534,
                name      = "Electric Scooter",
                inStock   = 7,
                price     = 149.00,
                min       = 3,
                max       = 10
            };
            electricScooter.AddAssociatedPart(newOutsourced);
            electricScooter.AddAssociatedPart(newInhouse);

            Product chainBicycle = new Product
            {
                productID = 819,
                name      = "Single-Speed Bike",
                inStock   = 5,
                price     = 99,
                min       = 2,
                max       = 8
            };

            chainBicycle.AddAssociatedPart(newInhouse);

            inventory.AddProduct(electricScooter);
            inventory.AddProduct(chainBicycle);
            #endregion

            partListSource.DataSource = inventory.GetPartsList();
            partsDataGrid.DataSource  = partListSource;

            productListSource.DataSource = inventory.GetProductList();
            productsDataGrid.DataSource  = productListSource;

            partsDataGrid.Columns[2].DefaultCellStyle.Format = "C";
            partsDataGrid.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.AllCells;
            partsDataGrid.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            productsDataGrid.Columns[2].DefaultCellStyle.Format = "C";
            productsDataGrid.AutoSizeColumnsMode     = DataGridViewAutoSizeColumnsMode.AllCells;
            productsDataGrid.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Ejemplo n.º 11
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.Hide();

            try
            {
                Convert.ToInt32(minInput.Text);
                Convert.ToInt32(maxInput.Text);
            }
            catch
            {
                maxInput.BackColor = Color.Coral;
                this.Show();
                MessageBox.Show("Invalid field: Please ensure all fields are populated. No input field may be blank");
                return;
            }
            if (String.IsNullOrEmpty(inventoryInput.Text) || String.IsNullOrWhiteSpace(inventoryInput.Text) ||
                String.IsNullOrEmpty(Convert.ToString(minInput.Value)) || String.IsNullOrWhiteSpace(Convert.ToString(minInput.Value)) ||
                String.IsNullOrEmpty(Convert.ToString(maxInput.Value)) || String.IsNullOrWhiteSpace(Convert.ToString(maxInput.Value)
                                                                                                    ))
            {
                buttonSave.Enabled       = false;
                inventoryInput.BackColor = Color.Coral;
                MessageBox.Show("Inventory must be between Min and Max. All fields must be not be empty or blank");
                this.Show();
                return;
            }
            if (Convert.ToInt32(inventoryInput.Text) < Convert.ToInt32(minInput.Text) || string.IsNullOrEmpty(inventoryInput.Text) || string.IsNullOrWhiteSpace(inventoryInput.Text))
            {
                MessageBox.Show("Inventory must be between Min and Max and must not be empty, blank, or non-numeric");
                inventoryInput.BackColor = Color.Coral;

                this.Show();
                return;
            }
            else if (Convert.ToInt32(minInput.Text) > Convert.ToInt32(maxInput.Text) || string.IsNullOrEmpty(inventoryInput.Text) || string.IsNullOrWhiteSpace(inventoryInput.Text))
            {
                MessageBox.Show("Min must be less than Max and must not Be blank, empty or non-numeric");

                this.Show();
                return;
            }
            else if (Convert.ToInt32(inventoryInput.Text) > Convert.ToInt32(maxInput.Text) || string.IsNullOrEmpty(inventoryInput.Text) || string.IsNullOrWhiteSpace(inventoryInput.Text))
            {
                MessageBox.Show("Inventory must be between Min and Max and must not be empty, blank, or non-numeric");
                inventoryInput.BackColor = Color.Coral;

                this.Show();
                return;
            }



            if (Globals.partIsNew)
            {
                if (radioInHouse.Checked)
                {
                    Inventory.addPart(new Inhouse(
                                          (Inventory.AllParts.Count),
                                          nameInput.Text,
                                          Convert.ToDouble(priceInput.Text),
                                          Convert.ToInt32(inventoryInput.Text),
                                          Convert.ToInt32(minInput.Text),
                                          Convert.ToInt32(maxInput.Text),
                                          Convert.ToInt32(machineIDinput.Text)));
                }

                else
                {
                    if (radioOutsourced.Checked)
                    {
                        Inventory.addPart(new Outsourced(
                                              (Inventory.AllParts.Count),
                                              nameInput.Text,
                                              Convert.ToDouble(priceInput.Text),
                                              Convert.ToInt32(inventoryInput.Text),
                                              Convert.ToInt32(minInput.Text),
                                              Convert.ToInt32(maxInput.Text),
                                              machineIDinput.Text));
                    }
                }
            }
            else

            {
                bool isChangingType = Inventory.SourceChange(Convert.ToInt32(idInput.Text), radioOutsourced.Checked);
                if (radioInHouse.Checked & isChangingType == true)
                {
                    int index = Convert.ToInt32(idInput.Text);

                    Inhouse replacementObject = new Inhouse(
                        Convert.ToInt32(idInput.Text),
                        nameInput.Text,
                        Convert.ToDouble(priceInput.Text),
                        Convert.ToInt32(inventoryInput.Text),
                        Convert.ToInt32(minInput.Text),
                        Convert.ToInt32(maxInput.Text),
                        Convert.ToInt32(machineIDinput.Text));


                    Inventory.addPart(replacementObject, index);
                }

                else if (radioOutsourced.Checked & isChangingType == true)
                {
                    int index = Convert.ToInt32(idInput.Text);

                    Outsourced replacementObject = new Outsourced(
                        Convert.ToInt32(idInput.Text),
                        nameInput.Text,
                        Convert.ToDouble(priceInput.Text),
                        Convert.ToInt32(inventoryInput.Text),
                        Convert.ToInt32(minInput.Text),
                        Convert.ToInt32(maxInput.Text),
                        machineIDinput.Text);

                    Inventory.addPart(replacementObject, index);
                }



                else if (radioOutsourced.Checked & isChangingType == false)
                {
                    Inventory.UpdateOutsourced(Convert.ToInt32(idInput.Text), new Outsourced(
                                                   (Inventory.AllParts.Count),
                                                   nameInput.Text,
                                                   Convert.ToDouble(priceInput.Text),
                                                   Convert.ToInt32(inventoryInput.Text),
                                                   Convert.ToInt32(minInput.Text),
                                                   Convert.ToInt32(maxInput.Text),
                                                   machineIDinput.Text)
                                               );
                }
                else
                {
                    int index = Convert.ToInt32(idInput.Text);

                    Inhouse replacementObject = new Inhouse(
                        Convert.ToInt32(idInput.Text),
                        nameInput.Text,
                        Convert.ToDouble(priceInput.Text),
                        Convert.ToInt32(inventoryInput.Text),
                        Convert.ToInt32(minInput.Text),
                        Convert.ToInt32(maxInput.Text),
                        Convert.ToInt32(machineIDinput.Text));


                    Inventory.updatePart(index, replacementObject);
                }
            }

            if (Convert.ToInt32(minInput.Text) > Convert.ToInt32(maxInput.Text))
            {
                MessageBox.Show("Error: Minimum cannot exceed maximum");
                this.Show();
            }
            else if (Convert.ToInt32(inventoryInput.Text) < Convert.ToInt32(minInput.Text))
            {
                MessageBox.Show("Inventory value must be between Min and Max values");
                this.Show();
            }


            else
            {
                Main main = new Main();
                main.Refresh();
                main.Show();
            }
        }
        //save button.
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool entryReady = true;
            bool saveSucess = false;
            int  parsedResult;
            int  j = 0;

            //if chain testing each textbox for content to see if its EntryReady
            //clear boxes when values are corrected
            if (textBox1.Text != "")
            {
                if (!(int.TryParse(textBox1.Text, out parsedResult)))
                {
                    label1.Text = "PartID must be a number";
                    label1.Show();
                    textBox1.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
            }
            else
            {
                label1.Text = "Do not leave blank";
                label1.Show();
                textBox1.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox2.Text == "")
            {
                label2.Text = "Do not leave blank";
                label2.Show();
                textBox2.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox3.Text != "")
            {
                if (!(int.TryParse(textBox3.Text, out parsedResult)))
                {
                    label3.Text = "Inventory must be a number";
                    label3.Show();
                    textBox3.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
            }
            else
            {
                label3.Text = "Do not leave blank";
                label3.Show();
                textBox3.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox4.Text != "")
            {
                decimal parsedDecResult;
                if (!(decimal.TryParse(textBox3.Text, out parsedDecResult)))
                {
                    label4.Text = "Price/Cost must be a number";
                    label4.Show();
                    textBox4.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
            }
            else
            {
                label4.Text = "Do not leave blank";
                label4.Show();
                textBox4.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox5.Text != "")
            {
                if (!(int.TryParse(textBox5.Text, out parsedResult)))
                {
                    label5.Text = "Max must be a number";
                    label5.Show();
                    textBox5.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
                else
                {
                    if (textBox7.Text != "")
                    {
                        if (int.TryParse(textBox7.Text, out parsedResult))
                        {
                            if (int.Parse(textBox5.Text) < int.Parse(textBox7.Text))
                            {
                                label5.Text = "Max must be greater than Min";
                                label5.Show();
                                textBox5.BackColor = Color.DarkRed;
                                textBox7.BackColor = Color.DarkRed;
                                entryReady         = false;
                            }
                            if (textBox3.Text != "" && textBox7.Text != "")
                            {
                                if (int.TryParse(textBox3.Text, out parsedResult) && int.TryParse(textBox7.Text, out parsedResult))
                                {
                                    if (int.Parse(textBox3.Text) < int.Parse(textBox7.Text))
                                    {
                                        label3.Text = "Inventory must be more than Min";
                                        label3.Show();
                                        textBox3.BackColor = Color.DarkRed;
                                        textBox7.BackColor = Color.DarkRed;
                                        entryReady         = false;
                                    }
                                }
                            }
                        }
                    }
                    if (textBox3.Text != "")
                    {
                        if (int.TryParse(textBox3.Text, out parsedResult))
                        {
                            if (int.Parse(textBox5.Text) < int.Parse(textBox3.Text))
                            {
                                label3.Text = "Inventory must be less than Max";
                                label3.Show();
                                textBox3.BackColor = Color.DarkRed;
                                textBox5.BackColor = Color.DarkRed;
                                entryReady         = false;
                            }
                        }
                    }
                }
            }
            else
            {
                label5.Text = "Do not leave blank";
                label5.Show();
                textBox5.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox6.Text != "")
            {
                if (!(int.TryParse(textBox6.Text, out parsedResult)) && ourInhouse == 0)
                {
                    label6.Text = "MachineID must be a number";
                    label6.Show();
                    textBox6.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
            }
            else
            {
                label6.Text = "Do not leave blank";
                label6.Show();
                textBox6.BackColor = Color.DarkRed;
                entryReady         = false;
            }
            if (textBox7.Text != "")
            {
                if (!(int.TryParse(textBox7.Text, out parsedResult)))
                {
                    label7.Text = "Min must be a number";
                    label7.Show();
                    textBox7.BackColor = Color.DarkRed;
                    entryReady         = false;
                }
            }
            else
            {
                label7.Text = "Do not leave blank";
                label7.Show();
                textBox7.BackColor = Color.DarkRed;
                entryReady         = false;
            }

            //checking to see if a new part already has the same partID
            //deleting part if modifying and allowing to create in next statement
            if (entryReady == true)
            {
                for (int i = 0; i < Inventory.AllParts.Count; i++)
                {
                    j = 0;
                    if (Inventory.AllParts[i].PartID == int.Parse(textBox1.Text) && creatingNewPartID == true)
                    {
                        MessageBox.Show("Please choose another PartID. Cannot duplicate PartID.");
                        j++;
                    }
                    else if (Inventory.AllParts[i].PartID == int.Parse(textBox1.Text) && creatingNewPartID == false)
                    {
                        j = 0;
                        Inventory.deletePart(i);
                        break;
                    }
                    if (j > 0)
                    {
                        break;
                    }
                }
            }

            //creating new sub-part if new part has each Textbox filled (EntryReady)
            //and no partID conflicts for new part. Replaces part if from Modify.
            if (j == 0 && ourInhouse == 0 && entryReady == true)
            {
                var tempPart = new Inhouse(int.Parse(textBox6.Text),
                                           int.Parse(textBox1.Text), textBox2.Text,
                                           decimal.Parse(textBox4.Text), int.Parse(textBox3.Text),
                                           int.Parse(textBox7.Text), int.Parse(textBox5.Text));
                Inventory.addPart(tempPart);
                saveSucess = true;
            }
            else if (j == 0 && ourInhouse == 1 && entryReady == true)
            {
                var tempPart = new Outsourced(textBox6.Text,
                                              int.Parse(textBox1.Text), textBox2.Text,
                                              decimal.Parse(textBox4.Text), int.Parse(textBox3.Text),
                                              int.Parse(textBox5.Text), int.Parse(textBox7.Text));
                Inventory.addPart(tempPart);
                saveSucess = true;
            }
            else
            {
                MessageBox.Show("Record save unsuccessful.");
            }
            if (saveSucess)
            {
                MessageBox.Show("Record saved successfully.");
                this.Hide();
                MainScreen MScreen = new MainScreen();
                MScreen.Show();
            }
        }
Ejemplo n.º 13
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            if (!decimal.TryParse(priceInput.Text, out var price) || price <= 0)
            {
                MessageBox.Show("Invalid Price. Price must be a number greater than 0.");
                return;
            }

            int min = 0;

            if (
                !int.TryParse(maxInput.Text, out var max) ||
                !int.TryParse(minInput.Text, out min) ||
                min > max ||
                min < 0 ||
                max <= 0)
            {
                MessageBox.Show("Invalid Min or Max. Both must be whole numbers greater than 0 and min must be less than max");
                return;
            }

            if (!int.TryParse(inventoryInput.Text, out var inStock) || inStock < 0)
            {
                MessageBox.Show("Invalid inventory. Inventory must be a whole number and must not be less than 0.");
                return;
            }

            if (inStock < min || inStock > max)
            {
                MessageBox.Show($"Invalid inventory. Inventory must a number between min ({min}) and max ({max}).");
                return;
            }

            Part newPart;

            if (inhouseRadio.Checked)
            {
                if (!int.TryParse(machineOrCompanyInput.Text, out var machineId) || machineId <= 0)
                {
                    MessageBox.Show("Invalid machine ID. Machine Id must be a whole number greater than 0.");
                    return;
                }
                newPart = new Inhouse()
                {
                    Name      = nameInput.Text,
                    Price     = price,
                    InStock   = inStock,
                    Min       = min,
                    Max       = max,
                    MachineID = int.Parse(machineOrCompanyInput.Text)
                };
            }
            else
            {
                newPart = new Outsourced()
                {
                    Name        = nameInput.Text,
                    Price       = price,
                    InStock     = inStock,
                    Min         = min,
                    Max         = max,
                    CompanyName = machineOrCompanyInput.Text
                };
            }

            if (isModify)
            {
                Inventory.UpdatePart(inputPart.PartID, newPart);
            }
            else
            {
                Inventory.AddPart(newPart);
            }
            Close();
        }