private void partCancelButton_Click(object sender, EventArgs e) { this.Hide(); InventoryForm inventoryForm = new InventoryForm(); inventoryForm.Show(); }
private void partSaveButton_Click(object sender, EventArgs e) { string messageBuilder = "Please fix the following issues:\n"; bool invalid = false; decimal numberDecimal; int numberMin = -2; int numberMax = -3; int numberInventory; int numberMachineID; //checking each field for validation //name if (string.IsNullOrWhiteSpace(partNameTextBox.Text)) { invalid = true; messageBuilder += "Please enter a part name\n"; } //price if (string.IsNullOrWhiteSpace(partPriceTextBox.Text) || (!Decimal.TryParse(partPriceTextBox.Text, out numberDecimal))) { invalid = true; messageBuilder += "Please enter a valid price\n"; } //min if (string.IsNullOrWhiteSpace(partMinTextBox.Text)) { invalid = true; messageBuilder += "Please enter a min value\n"; } else { if (!Int32.TryParse(partMinTextBox.Text, out numberMin)) { invalid = true; messageBuilder += "Please enter a valid min value\n"; } } //max if (string.IsNullOrWhiteSpace(partMaxTextBox.Text)) { invalid = true; messageBuilder += "Please enter a max value\n"; } else { if (!Int32.TryParse(partMaxTextBox.Text, out numberMax)) { invalid = true; messageBuilder += "Please enter a valid min value\n"; } else { if (numberMax < numberMin) { invalid = true; messageBuilder += "Please enter a max value greater than min value\n"; } } } //instock if (string.IsNullOrWhiteSpace(partInventoryTextBox.Text)) { invalid = true; messageBuilder += "Please enter a inventory value\n"; } else { if (!Int32.TryParse(partInventoryTextBox.Text, out numberInventory)) { invalid = true; messageBuilder += "Please enter a valid inventory number value\n"; } else { if (numberInventory < numberMin || numberInventory > numberMax) { invalid = true; messageBuilder += "Please enter an inventory number between min and max\n"; } } } if (isInhouse == true) { if (string.IsNullOrWhiteSpace(partMachineCompanyTextBox.Text)) { invalid = true; messageBuilder += "Please enter a Machine ID\n"; } else { if (!Int32.TryParse(partMachineCompanyTextBox.Text, out numberMachineID)) { invalid = true; messageBuilder += "Please enter a number in Machine ID"; } } } else { if (string.IsNullOrWhiteSpace(partMachineCompanyTextBox.Text)) { invalid = true; messageBuilder += "Please enter a Company Name"; } } //invalid path with messageBox if (invalid == true) { MessageBox.Show(messageBuilder); } //this path creates a new part or modifies an existing part else { //constructor called for new part and new part assigned to AllParts if (Inventory.CurrentPartIndex < 0) { if (isInhouse == true) { Inventory.addPart(new Inhouse(partNameTextBox.Text, Decimal.Parse(partPriceTextBox.Text), Int32.Parse(partInventoryTextBox.Text), Int32.Parse(partMinTextBox.Text), Int32.Parse(partMaxTextBox.Text), Int32.Parse(partMachineCompanyTextBox.Text))); } else { Inventory.addPart(new Outsourced(partNameTextBox.Text, Decimal.Parse(partPriceTextBox.Text), Int32.Parse(partInventoryTextBox.Text), Int32.Parse(partMinTextBox.Text), Int32.Parse(partMaxTextBox.Text), partMachineCompanyTextBox.Text)); } } //constructor called for existing part and swapped for unmodified part in AllParts else { if (isInhouse == true) { Inventory.updatePart(Inventory.CurrentPartIndex, new Inhouse(Int32.Parse(partIDTextBox.Text), partNameTextBox.Text, Decimal.Parse(partPriceTextBox.Text), Int32.Parse(partInventoryTextBox.Text), Int32.Parse(partMinTextBox.Text), Int32.Parse(partMaxTextBox.Text), Int32.Parse(partMachineCompanyTextBox.Text))); } else { Inventory.updatePart(Inventory.CurrentPartIndex, new Outsourced(Int32.Parse(partIDTextBox.Text), partNameTextBox.Text, Decimal.Parse(partPriceTextBox.Text), Int32.Parse(partInventoryTextBox.Text), Int32.Parse(partMinTextBox.Text), Int32.Parse(partMaxTextBox.Text), partMachineCompanyTextBox.Text)); } } this.Hide(); InventoryForm inventoryForm = new InventoryForm(); inventoryForm.Show(); } }
private void productSaveButton_Click(object sender, EventArgs e) { string messageBuilder = "Please fix the following issues:\n"; bool invalid = false; decimal numberDecimal; int numberMin = -2; int numberMax = -3; int numberInventory; //checking each field for validation //name if (string.IsNullOrWhiteSpace(productNameTextBox.Text)) { invalid = true; messageBuilder += "Please enter a product name\n"; } //price if (string.IsNullOrWhiteSpace(productPriceTextBox.Text) || (!Decimal.TryParse(productPriceTextBox.Text, out numberDecimal))) { invalid = true; messageBuilder += "Please enter a valid price\n"; } //min if (string.IsNullOrWhiteSpace(productMinTextBox.Text)) { invalid = true; messageBuilder += "Please enter a min value\n"; } else { if (!Int32.TryParse(productMinTextBox.Text, out numberMin)) { invalid = true; messageBuilder += "Please enter a valid min value\n"; } } //max if (string.IsNullOrWhiteSpace(productMaxTextBox.Text)) { invalid = true; messageBuilder += "Please enter a max value\n"; } else { if (!Int32.TryParse(productMaxTextBox.Text, out numberMax)) { invalid = true; messageBuilder += "Please enter a valid min value\n"; } else { if (numberMax < numberMin) { invalid = true; messageBuilder += "Please enter a max value greater than min value\n"; } } } //instock if (string.IsNullOrWhiteSpace(productInventoryTextBox.Text)) { invalid = true; messageBuilder += "Please enter a inventory value\n"; } else { if (!Int32.TryParse(productInventoryTextBox.Text, out numberInventory)) { invalid = true; messageBuilder += "Please enter a valid inventory number value\n"; } else { if (numberInventory < numberMin || numberInventory > numberMax) { invalid = true; messageBuilder += "Please enter an inventory number between min and max\n"; } } } //invalid path with messageBox if (invalid == true) { MessageBox.Show(messageBuilder); } //this path creates a new product or modifies an existing product else { //constructor called for new product and new product assigned to Products if (Inventory.CurrentProductIndex < 0) { Inventory.addProduct(new Product(productNameTextBox.Text, Decimal.Parse(productPriceTextBox.Text), Int32.Parse(productInventoryTextBox.Text), Int32.Parse(productMinTextBox.Text), Int32.Parse(productMaxTextBox.Text))); //copying contents of temp.AssociatedParts to new product int index = Inventory.Products.Count - 1; for (int i = 0; i < temp.AssociatedParts.Count; i++) { Inventory.Products[index].addAssociatedPart(temp.AssociatedParts[i]); } } //constructor called for existing part and swapped for unmodified part in AllParts else { Inventory.updateProduct(Inventory.CurrentProductIndex, new Product(Int32.Parse(productIDTextBox.Text), productNameTextBox.Text, Decimal.Parse(productPriceTextBox.Text), Int32.Parse(productInventoryTextBox.Text), Int32.Parse(productMinTextBox.Text), Int32.Parse(productMaxTextBox.Text))); //copying contents of temp.AssociatedParts to modified product for (int i = 0; i < temp.AssociatedParts.Count; i++) { Inventory.Products[Inventory.CurrentProductIndex].addAssociatedPart(temp.AssociatedParts[i]); } } this.Hide(); InventoryForm inventoryForm = new InventoryForm(); inventoryForm.Show(); } }