public static void updatePart(int id, Outsourced partUpdate) { for (int i = 0; i < Parts.Count; i++) { if (Parts[i].PartID == id) { Parts.RemoveAt(i); Parts.Insert(i, partUpdate); MessageBox.Show($"{partUpdate.Name} updated!"); } } }
public ModifyPartForm(Outsourced outsourced) { InitializeComponent(); outsourcedRadio.Checked = true; variableLabel.Text = "Company Name"; idBox.Text = outsourced.PartID.ToString(); nameInput.Text = outsourced.Name; inventoryInput.Text = outsourced.InStock.ToString(); priceInput.Text = outsourced.Price.ToString(); minInput.Text = outsourced.Min.ToString(); maxInput.Text = outsourced.Max.ToString(); variableInput.Text = outsourced.CompanyName; }
private void partModifyButton_Click(object sender, EventArgs e) { int partID = int.Parse(partDataGrid.Rows[partDataGrid.CurrentCell.RowIndex].Cells[0].Value.ToString()); if (Inventory.lookupPart(partID).GetType() == Inventory.sampleInsource.GetType()) { Inhouse selectPart = (Inhouse)Inventory.lookupPart(partID); new ModifyPartForm(selectPart).ShowDialog(); } else { Outsourced selectPart = (Outsourced)Inventory.lookupPart(partID); new ModifyPartForm(selectPart).ShowDialog(); } }
private void partAddButton_Click(object sender, EventArgs e) { int partIndex = partsDataGrid.CurrentCell.RowIndex; if (partsDataGrid.CurrentRow.DataBoundItem.GetType() == Inventory.sampleInsource.GetType()) { Inhouse selectPart = (Inhouse)partsDataGrid.CurrentRow.DataBoundItem; Inventory.lookupProduct(mainID).addAssociatedPart(selectPart); tempAllParts.RemoveAt(partIndex); } else { Outsourced selectPart = (Outsourced)partsDataGrid.CurrentRow.DataBoundItem; Inventory.lookupProduct(mainID).addAssociatedPart(selectPart); tempAllParts.RemoveAt(partIndex); } }
private void removePart_Click(object sender, EventArgs e) { int partID = int.Parse(associatedPartsDataGrid.Rows[associatedPartsDataGrid.CurrentCell.RowIndex].Cells[0].Value.ToString()); if (associatedPartsDataGrid.CurrentRow.DataBoundItem.GetType() == Inventory.sampleInsource.GetType()) { Inhouse selectPart = (Inhouse)associatedPartsDataGrid.CurrentRow.DataBoundItem; tempAllParts.Add(selectPart); Inventory.lookupProduct(mainID).removeAssociatedPart(partID); } else { Outsourced selectPart = (Outsourced)associatedPartsDataGrid.CurrentRow.DataBoundItem; tempAllParts.Add(selectPart); Inventory.lookupProduct(mainID).removeAssociatedPart(partID); } }
private void removePart_Click(object sender, EventArgs e) { int partIndex = associatedPartsDataGrid.CurrentCell.RowIndex; if (associatedPartsDataGrid.CurrentRow.DataBoundItem.GetType() == Inventory.sampleInsource.GetType()) { Inhouse selectPart = (Inhouse)associatedPartsDataGrid.CurrentRow.DataBoundItem; tempAllParts.Add(selectPart); tempAssParts.RemoveAt(partIndex); } else { Outsourced selectPart = (Outsourced)associatedPartsDataGrid.CurrentRow.DataBoundItem; tempAllParts.Add(selectPart); tempAssParts.RemoveAt(partIndex); } }
public static Part lookupPart(int id) { bool found = false; foreach (Part part in Parts) { if (part.PartID == id) { found = true; return(part); } } if (found == false) { MessageBox.Show("Error: Part not found."); } Part partNotFound = new Outsourced(); return(partNotFound); }
//Populate data grid public static void populateMainScreenDGV() { if (Products.Count == 0) { //Create products and add to list Product loadProd1 = new Product(11, "Purple Bike", 12, 80, 1, 40); Product loadProd2 = new Product(12, "Green Bike", 10, 60, 1, 60); Product loadProd3 = new Product(13, "Orange Bike", 12, 70, 1, 50); Products.Add(loadProd1); Products.Add(loadProd2); Products.Add(loadProd3); //Create parts and add to list Part loadPart1 = new Inhouse(101, "Handlebars", 24, 5, 6, 80, 201); Part loadPart2 = new Inhouse(102, "Bike Chain", 15, 3, 6, 80, 301); Part loadPart3 = new Outsourced(103, "Bike Frame", 26, 20, 6, 80, "Bicycle Etc."); Part loadPart4 = new Outsourced(104, "Bike Tire", 49, 9, 12, 160, "Spokes and Wheels LLC"); Parts.Add(loadPart1); Parts.Add(loadPart2); Parts.Add(loadPart3); Parts.Add(loadPart4); //Associate parts with products loadProd1.AssociatedParts.Add(loadPart1); loadProd1.AssociatedParts.Add(loadPart2); loadProd1.AssociatedParts.Add(loadPart3); loadProd1.AssociatedParts.Add(loadPart4); loadProd2.AssociatedParts.Add(loadPart1); loadProd2.AssociatedParts.Add(loadPart2); loadProd2.AssociatedParts.Add(loadPart3); loadProd2.AssociatedParts.Add(loadPart4); loadProd3.AssociatedParts.Add(loadPart1); loadProd3.AssociatedParts.Add(loadPart2); loadProd3.AssociatedParts.Add(loadPart3); loadProd3.AssociatedParts.Add(loadPart4); } }
private void saveProduct_Click(object sender, EventArgs e) { bool checkDigits(string s) => int.TryParse(s, out int i); bool invNum = checkDigits(inventoryInput.Text); bool maxNum = checkDigits(maxInput.Text); bool minNum = checkDigits(minInput.Text); bool priceNum = checkDigits(priceInput.Text); if (nameInput.Text == "") { MessageBox.Show("Please provide a name for the new product in the Name field."); } else if (inventoryInput.Text == "") { MessageBox.Show("Please provide how many products are currently in stock in the Inventory field."); } else if (priceInput.Text == "") { MessageBox.Show("Please provide a price for the new product."); } else if (maxInput.Text == "") { MessageBox.Show("Please provide a maximum amount of units in the Max field."); } else if (minInput.Text == "") { MessageBox.Show("Please provide a minimum amount of units in the Min field."); } else if (!invNum || !maxNum || !minNum || !priceNum) { MessageBox.Show("Inventory, Max, Min, and Price fields all must be numbers."); } else if (int.Parse(maxInput.Text) < int.Parse(minInput.Text)) { MessageBox.Show("Maximum amount cannot be less than Minimum amount."); } else if (int.Parse(maxInput.Text) < int.Parse(inventoryInput.Text) || (int.Parse(minInput.Text) > int.Parse(inventoryInput.Text))) { MessageBox.Show("Inventory level must be between the Minimum and Maximum amounts."); } else { this.Hide(); int newID = (Inventory.Products[Inventory.Products.Count - 1].ProductID + 1); Product newProduct = new Product(newID, nameInput.Text, int.Parse(inventoryInput.Text), decimal.Parse(priceInput.Text), int.Parse(minInput.Text), int.Parse(maxInput.Text)); Inventory.addProduct(newProduct); for (int i = 0; i < tempAssParts.Count; i++) { if (tempAssParts[i].GetType() == Inventory.sampleInsource.GetType()) { Inhouse currentPart = (Inhouse)tempAssParts[i]; Inventory.lookupProduct(newID).addAssociatedPart(currentPart); } else { Outsourced currentPart = (Outsourced)tempAssParts[i]; Inventory.lookupProduct(newID).addAssociatedPart(currentPart); } } this.Close(); MessageBox.Show($"{newProduct.Name} added!"); } }
//Associated Part methods public void addAssociatedPart(Outsourced part) { AssociatedParts.Add(part); }
private void savePart_Click(object sender, EventArgs e) { bool checkDigits(string s) => int.TryParse(s, out int i); bool invNum = checkDigits(inventoryInput.Text); bool maxNum = checkDigits(maxInput.Text); bool minNum = checkDigits(minInput.Text); bool priceNum = checkDigits(priceInput.Text); if (inhouseRadio.Checked && variableInput.Text != "") { bool machineNum = checkDigits(variableInput.Text); if (!machineNum) { MessageBox.Show("Machine ID must be a number"); } } if (nameInput.Text == "") { MessageBox.Show("Please provide a name."); } else if (inventoryInput.Text == "") { MessageBox.Show("Please provide how many parts are currently in stock in the Inventory field."); } else if (priceInput.Text == "") { MessageBox.Show("Please provide a price for the part."); } else if (maxInput.Text == "") { MessageBox.Show("Please provide a maximum amount of units in the Max field."); } else if (minInput.Text == "") { MessageBox.Show("Please provide a minimum amount of units in the Min field."); } else if (!invNum || !maxNum || !minNum || !priceNum) { MessageBox.Show("Inventory, Max, Min, and Price fields all must be numbers."); } else if (int.Parse(maxInput.Text) < int.Parse(minInput.Text)) { MessageBox.Show("Maximum amount cannot be less than Minimum amount."); } else if (int.Parse(maxInput.Text) < int.Parse(inventoryInput.Text) || (int.Parse(minInput.Text) > int.Parse(inventoryInput.Text))) { MessageBox.Show("Inventory level must be between the Minimum and Maximum amounts."); } else if (inhouseRadio.Checked && variableInput.Text == "") { MessageBox.Show("Please provide a Machine ID"); } else if (outsourcedRadio.Checked && variableInput.Text == "") { MessageBox.Show("Please provide a company name"); } else { if (inhouseRadio.Checked) { Inhouse newInhouse = new Inhouse(int.Parse(idBox.Text), nameInput.Text, int.Parse(inventoryInput.Text), decimal.Parse(priceInput.Text), int.Parse(minInput.Text), int.Parse(maxInput.Text), int.Parse(variableInput.Text)); Inventory.updatePart(newInhouse.PartID, newInhouse); this.Close(); } else { Outsourced newOutsourced = new Outsourced(int.Parse(idBox.Text), nameInput.Text, int.Parse(inventoryInput.Text), decimal.Parse(priceInput.Text), int.Parse(minInput.Text), int.Parse(maxInput.Text), variableInput.Text); Inventory.updatePart(newOutsourced.PartID, newOutsourced); this.Close(); } } }