public static void UpdatePart(int partID, Part part) { for (int i = 0; i < AllParts.Count; i++) { if (AllParts[i].GetType() == typeof(InHouse)) { InHouse newInhouse = (InHouse)AllParts[i]; if (newInhouse.PartID == partID) { newInhouse.PartID = part.PartID; newInhouse.Name = part.Name; newInhouse.Price = part.Price; newInhouse.InStock = part.InStock; newInhouse.Min = part.Min; newInhouse.Max = part.Max; } } else if (AllParts[i].GetType() == typeof(Outsourced)) { Outsourced newOutsource = (Outsourced)AllParts[i]; if (newOutsource.PartID == partID) { newOutsource.PartID = part.PartID; newOutsource.Name = part.Name; newOutsource.Price = part.Price; newOutsource.InStock = part.InStock; newOutsource.Min = part.Min; newOutsource.Max = part.Max; } } } }
public ModifyPart(InHouse housePart) { InitializeComponent(); modPartIDTextBox.Text = housePart.PartID.ToString(); modNameTextBox.Text = housePart.Name.ToString(); modInventoryTextBox.Text = housePart.InStock.ToString(); modPriceTextBox.Text = housePart.Price.ToString(); modMaxTextBox.Text = housePart.Max.ToString(); modMinTextBox.Text = housePart.Min.ToString(); modMachineIDTextBox.Text = housePart.MachineID.ToString(); partMachineIDLabel.Text = "Machine ID"; InHouseRadButton.Checked = true; }
public static void PopulateList() { // add mach ids and comp names Part examplePart1 = new InHouse(1, "Spark Plug", 4.99m, 76, 16, 100, 9001); Part examplePart2 = new InHouse(2, "Air Filter", 18.99m, 12, 10, 30, 9002); Part examplePart3 = new InHouse(3, "Oil Filter", 6.99m, 39, 10, 50, 9003); Part examplePart4 = new InHouse(4, "Plug Wire", 3.99m, 41, 16, 50, 9004); Part examplePart5 = new Outsourced(7, "Intake Manifold", 249.99m, 11, 3, 20, "Edelbrock"); Part examplePart6 = new Outsourced(8, "Carburetor", 399.99m, 5, 3, 20, "Holley"); AllParts.Add(examplePart1); AllParts.Add(examplePart2); AllParts.Add(examplePart3); AllParts.Add(examplePart4); AllParts.Add(examplePart5); AllParts.Add(examplePart6); Product ExampleProduct1 = new Product(1, "8 Spark Plug Wire Kit", 30.99m, 12, 5, 30); Product ExampleProduct2 = new Product(2, "6 Spark Plug Wire Kit", 23.99m, 8, 5, 30); Product ExampleProduct3 = new Product(3, "4 Spark Plug Wire Kit", 15.99m, 5, 5, 30); Product ExampleProduct4 = new Product(4, "4 Cylinder Tune Up Kit", 35.99m, 15, 5, 30); // Add parts to products for (int i = 0; i < 8; i++) { ExampleProduct1.AddAssociatedPart(examplePart1); } for (int i = 0; i < 6; i++) { ExampleProduct2.AddAssociatedPart(examplePart1); } for (int i = 0; i < 4; i++) { ExampleProduct3.AddAssociatedPart(examplePart1); } ExampleProduct4.AddAssociatedPart(examplePart1); ExampleProduct4.AddAssociatedPart(examplePart1); ExampleProduct4.AddAssociatedPart(examplePart1); ExampleProduct4.AddAssociatedPart(examplePart1); ExampleProduct4.AddAssociatedPart(examplePart2); ExampleProduct4.AddAssociatedPart(examplePart3); Products.Add(ExampleProduct1); Products.Add(ExampleProduct2); Products.Add(ExampleProduct3); Products.Add(ExampleProduct4); }
//** Opens a new form to modify an existing part based on the type of object and update main screen **// private void ModifyPartButton_Click(object sender, EventArgs e) { if (Inventory.AllParts.Count > 0) { if (partsDataGridView.CurrentRow.DataBoundItem.GetType() == typeof(InHouse)) { InHouse housePart = (InHouse)partsDataGridView.CurrentRow.DataBoundItem; new ModifyPart(housePart).ShowDialog(); } else if (partsDataGridView.CurrentRow.DataBoundItem.GetType() == typeof(Outsourced)) { Outsourced outsidePart = (Outsourced)partsDataGridView.CurrentRow.DataBoundItem; new ModifyPart(outsidePart).ShowDialog(); } } this.Refresh(); }
private void VerifyPartSave() { if (InHouseRadButton.Checked) { InHouse inHousePart = new InHouse(int.Parse(modPartIDTextBox.Text), modNameTextBox.Text, decimal.Parse(modPriceTextBox.Text), int.Parse(modInventoryTextBox.Text), int.Parse(modMinTextBox.Text), int.Parse(modMaxTextBox.Text), int.Parse(modMachineIDTextBox.Text)); Inventory.UpdatePart(int.Parse(modPartIDTextBox.Text), inHousePart); InHouseRadButton.Checked = true; } else if (OutsourcedRadButton.Checked) { Outsourced outsourcedPart = new Outsourced(int.Parse(modPartIDTextBox.Text), modNameTextBox.Text, decimal.Parse(modPriceTextBox.Text), int.Parse(modInventoryTextBox.Text), int.Parse(modMinTextBox.Text), int.Parse(modMaxTextBox.Text), modMachineIDTextBox.Text); Inventory.UpdatePart(int.Parse(modPartIDTextBox.Text), outsourcedPart); OutsourcedRadButton.Checked = true; } this.Close(); }
//** Verifies if entered information is correct and creates either inhouse or outsourced part **// private void VerifyPartSave() { int partID = Inventory.AssignPartID(); if (addPartInHouseRadio.Checked) { InHouse inHouse = new InHouse(partID, addPartNameTextBox.Text, decimal.Parse(addPriceTextBox.Text), int.Parse(addInvTextBox.Text), int.Parse(addPartMinTextBox.Text), int.Parse(addPartMaxTextBox.Text), int.Parse(IDNameTextBox.Text)); Inventory.AddPart(inHouse); } else { Outsourced outsourcedPart = new Outsourced(partID, addPartNameTextBox.Text, decimal.Parse(addPriceTextBox.Text), int.Parse(addInvTextBox.Text), int.Parse(addPartMinTextBox.Text), int.Parse(addPartMaxTextBox.Text), IDNameTextBox.Text); Inventory.AddPart(outsourcedPart); } this.Close(); }