private void candidatePartsAddButton_Click(object sender, EventArgs e) { if (upperIdx >= 0) { candidatePartsGridView.ClearSelection(); int i = 0; bool exists = false; foreach (Part p in Inventory.Products[Inventory.SelectedProductProductID].AssociatedParts) { if (Inventory.Products[Inventory.SelectedProductProductID].AssociatedParts[i].PartID == Inventory.SelectedPart.PartID) { exists = true; } i++; } if (!exists) { Product.AddAssociatedPart(Inventory.SelectedPart); } upperIdx = -1; productSaveButton.Enabled = enableSave(); } else { MessageBox.Show("No part is selected."); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { if (IsValid) { if (IsNewProduct) { Product = new Product { ProductId = ProductId, Name = ProductName, Price = decimal.Parse(ProductCost), InStock = int.Parse(ProductCount), Max = int.Parse(ProductMax), Min = int.Parse(ProductMin) }; CurrentModel.AddProduct(Product); foreach (var part in ProductAssociatedParts) { Product.AddAssociatedPart(part); } } else { Product.Name = ProductName; Product.Price = decimal.Parse(ProductCost); Product.InStock = int.Parse(ProductCount); Product.Max = int.Parse(ProductMax); Product.Min = int.Parse(ProductMin); Product.AssociatedParts = ProductAssociatedParts; CurrentModel.UpdateProduct(Product.ProductId, Product); } this.Close(); mainWindow.Products = mainWindow.GetUpdatedProducts(); mainWindow.Opacity = 1; } else { MessageBox.Show( "You must correct the product errors before saving.", "Save Error", MessageBoxButton.OK, MessageBoxImage.Error ); } }
private void AddPart_Click(object sender, EventArgs e) { Console.WriteLine(dataGridViewList.SelectedRows[0].Cells[0].Value.ToString()); Part tempPart = mainObjects.myInventory.LookUpPart(int.Parse(dataGridViewList.SelectedRows[0].Cells[0].Value.ToString())); string[] tempArray = new string[7]; tempArray[0] = tempPart.PartID.ToString(); tempArray[1] = tempPart.Name; tempArray[2] = tempPart.InStock.ToString(); tempArray[3] = tempPart.Price.ToString(); dataGridViewAddedPart.Rows.Add(tempArray); tempProduct.AddAssociatedPart(tempPart); }
private void saveProductButton_Click(object sender, EventArgs e) { int minVal = Convert.ToInt32(productMinTextBox.Text); int maxVal = Convert.ToInt32(productMaxTextBox.Text); int invVal = Convert.ToInt32(productInvTextBox.Text); if (minVal > maxVal) { productMinTextBox.BackColor = Color.Red; MessageBox.Show("Minimum value cannot be greater than maximum value. Please correct.", "Invalid Values"); return; } if (invVal < minVal || invVal > maxVal) { productInvTextBox.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 (partSelections.Count() == 0) { MessageBox.Show("A product must have at least one associated part.", "No Parts Selected"); return; } Product newProduct = new Product { productID = inventory.AssignID(), name = productNameTextBox.Text, inStock = invVal, price = double.Parse(productPriceCostTextBox.Text, System.Globalization.NumberStyles.Currency), min = minVal, max = maxVal }; foreach (Part part in partSelections) { newProduct.AddAssociatedPart(part); } inventory.AddProduct(newProduct); this.Close(); }
private void modifySaveProductButton_Click(object sender, EventArgs e) { var productToEdit = inventory.GetProductList().FirstOrDefault(editProduct => editProduct.productID == Convert.ToInt32(modifyProductIDTextBox.Text)); int productIndex = inventory.GetProductList().IndexOf(productToEdit); int minVal = Convert.ToInt32(modifyProductMinTextBox.Text); int maxVal = Convert.ToInt32(modifyProductMaxTextBox.Text); int invVal = Convert.ToInt32(modifyProductInvTextBox.Text); if (minVal > maxVal) { modifyProductMinTextBox.BackColor = Color.Red; MessageBox.Show("Minimum value cannot be greater than maximum value. Please correct.", "Invalid Values"); return; } if (invVal < minVal || invVal > maxVal) { modifyProductInvTextBox.BackColor = Color.Red; MessageBox.Show("Inventory value must not be lower than the minimum value or higher than the maximum value.", "Invalid Values"); return; } Product newProduct = new Product { productID = Convert.ToInt32(modifyProductIDTextBox.Text), name = modifyProductNameTextBox.Text, inStock = invVal, price = double.Parse(modifyProductPriceCostTextBox.Text, System.Globalization.NumberStyles.Currency), min = minVal, max = maxVal }; foreach (Part part in productParts) { newProduct.AddAssociatedPart(part); } inventory.UpdateProduct(productIndex, newProduct); this.Close(); }
public static void InitializeInventory() { Inhouse first = new Inhouse { PartID = 1254, Name = "Wrench", Max = 100, Min = 10, Price = 100, InStock = 50, MachineID = 022214 }; Outsourced second = new Outsourced { PartID = 2222, Name = "bolt", Max = 100, Min = 10, Price = 100, InStock = 40, CompanyName = "Umbrella" }; Product third = new Product(); third.ProductID = 333; third.Name = "Motor"; third.Max = 100; third.Min = 10; third.Price = 1000; third.ProductID = 33546; third.AddAssociatedPart(first); myInventory.AddPart(first); myInventory.AddPart(second); myInventory.AddProduct(third); }
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; }
private void saveButton_Click(object sender, EventArgs e) { //if (HasSpecialChars(priceInput.Text) is true) //{ // buttonSave.Enabled = false; // priceInput.BackColor = Color.Coral; // MessageBox.Show("The price input field must be in USD Currency Format and cannot contain any alpha or special characters"); // return; //} if (inventoryInput.Text == "") { // If the value in the numeric updown is an empty string, replace with 0. inventoryInput.Text = "0"; } bool IV = InputValidation(); if (IV is false) { MessageBox.Show("Please check that all fields are completed correctly and try again."); return; } this.Hide(); // if its blank prompt user if (String.IsNullOrWhiteSpace(nameInput.Text) || String.IsNullOrWhiteSpace(Convert.ToString(inventoryInput.Value)) || String.IsNullOrWhiteSpace(priceInput.Text) || String.IsNullOrWhiteSpace(minInput.Text) || String.IsNullOrWhiteSpace(maxInput.Text) || String.IsNullOrEmpty(nameInput.Text) || String.IsNullOrEmpty(Convert.ToString(inventoryInput.Value)) || String.IsNullOrEmpty(priceInput.Text) || String.IsNullOrEmpty(minInput.Text) || String.IsNullOrEmpty(maxInput.Text)) { MessageBox.Show("Please fill out all fields. May not be empty."); InputValidation(); return; } if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Max cannot be less than Min"); this.Show(); return; } else if (Enumerable.Range(Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text)).Contains(Convert.ToInt32(inventoryInput.Text)) == false) { MessageBox.Show("Inventory must be between Min and Max values."); this.Show(); return; } if (associatedPartsDGV.RowCount == 0 && modifyOrNew == 0) // and product is new { MessageBox.Show("Product must contain atleast one associated part."); this.Show(); return; } else if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Max cannot be less than Min"); this.Show(); return; } else { Product updatedProduct = new Product(Convert.ToInt32(IDinput.Text), nameInput.Text, Convert.ToDouble(priceInput.Text.Replace("$", "").Replace("$", "")), Convert.ToInt32(inventoryInput.Text), Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text)); //foreach (Classes.Part part in DGVAssoParts) //{ // updatedProduct.AssociatedParts.Add(part); //} // Classes.Product productObject = Classes.Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); foreach (Classes.Part part in DGVAssoParts) { Debug.WriteLine(part.Name); updatedProduct.AddAssociatedPart(part); Debug.WriteLine("Product name" + updatedProduct.Name); foreach (Classes.Part x in updatedProduct.AssociatedParts) { Debug.WriteLine(x.Name); } // updatedProduct.AssociatedParts.Add(part); } Inventory.updateProduct(Convert.ToInt32(IDinput.Text), updatedProduct); if (Convert.ToInt32(maxInput.Text) < Convert.ToInt32(minInput.Text)) { MessageBox.Show("Your minimum exceeds your maximum."); } else if (modifyOrNew == 1) //modify { //lookup the newly made product make a product object Product thatNewProd = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); //update that objects properties //{ // if (each.ProductID == Convert.ToInt32(IDinput.Text)) //was productID? // { thatNewProd.Name = nameInput.Text; thatNewProd.Price = Convert.ToDouble(priceInput.Text.Replace("$", "")); thatNewProd.InStock = Convert.ToInt32(inventoryInput.Text); thatNewProd.Min = Convert.ToInt32(minInput.Text); thatNewProd.Max = Convert.ToInt32(maxInput.Text); foreach (Classes.Part part in holdingAreaParts) { Classes.Product workingProduct = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); workingProduct.AddAssociatedPart(part); } // } //} //this.Hide(); Main main = new Main(); main.ShowDialog(); return; } else { Inventory.addProduct(new Product( nameInput.Text, Convert.ToDouble(priceInput.Text.Replace("$", "")), Convert.ToInt32(inventoryInput.Text), Convert.ToInt32(minInput.Text), Convert.ToInt32(maxInput.Text))); //commit parts from holding area foreach (Classes.Part part in holdingAreaParts) { Classes.Product workingProduct = Inventory.lookupProduct(Convert.ToInt32(IDinput.Text)); workingProduct.AddAssociatedPart(part); } this.Close(); Main main = new Main(); main.Show(); } } }