private void SaveButton_Click(object sender, EventArgs e) { try { if (NameTextBox.Text == "" || PriceCostTextBox.Text == "" || InventoryTextBox.Text == "" || MaxTextBox.Text == "" || MinTextBox.Text == "" || SourceTextBox.Text == "") { MessageBox.Show("Please enter values for all fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Convert.ToInt32(MinTextBox.Text) > Convert.ToInt32(MaxTextBox.Text)) { MessageBox.Show("Your Min cannot exceed your Max", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Convert.ToInt32(InventoryTextBox.Text) > Convert.ToInt32(MaxTextBox.Text)) { MessageBox.Show("Your Inv cannot exceed your Max", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (InHouseRadioButton.Checked) { InHouse newPart = new InHouse (NameTextBox.Text, Convert.ToDouble(PriceCostTextBox.Text), Convert.ToInt32(InventoryTextBox.Text), Convert.ToInt32(MinTextBox.Text), Convert.ToInt32(MaxTextBox.Text), Convert.ToInt32(SourceTextBox.Text)); Inventory.AddPart(newPart); //method to add to the part list } else { Outsourced newPart = new Outsourced (NameTextBox.Text, Convert.ToDouble(PriceCostTextBox.Text), Convert.ToInt32(InventoryTextBox.Text), Convert.ToInt32(MinTextBox.Text), Convert.ToInt32(MaxTextBox.Text), SourceTextBox.Text); Inventory.AddPart(newPart); } BackToMainScreen(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main() { #region prepopulate the dataGridViews //parts InHouse NewPart = new InHouse("Tire", 200.50, 32, 2, 50, 5); Inventory.AddPart(NewPart); //a clean input Inventory.AddPart(new InHouse("Motor", 9000.50, 32, 2, 50, 5)); Inventory.AddPart(new Outsourced("Transmission", 7000.00, 3, 1, 50, "Excel Gear")); Inventory.AddPart(new Outsourced("Seats", 700.25, 5, 1, 50, "Speco")); //products Inventory.Products.Add(new Product("Toyota Tundra", 57000.50, 5, 1, 50)); Inventory.Products.Add(new Product("Ford Mustang", 35000.75, 7, 1, 50)); Inventory.Products.Add(new Product("Toyota Highlander", 45000.50, 7, 1, 50)); Inventory.Products.Add(new Product("Ford Fusion", 20000.50, 7, 1, 50)); #endregion Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainScreenForm()); }
private void FillIn(InHouse P) { SourceTextBox.Text = P.MachineID.ToString(); }
private void FillI(InHouse P) { P.MachineID = Convert.ToInt32(SourceTextBox.Text); }
private void SaveButton_Click(object sender, EventArgs e) { try { if (NameTextBox.Text == "" || PriceCostTextBox.Text == "" || InventoryTextBox.Text == "" || MaxTextBox.Text == "" || MinTextBox.Text == "" || SourceTextBox.Text == "") { MessageBox.Show("Please enter values for all fields", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Convert.ToInt32(MinTextBox.Text) > Convert.ToInt32(MaxTextBox.Text)) { MessageBox.Show("Your Min cannot exceed your Max", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Convert.ToInt32(InventoryTextBox.Text) > Convert.ToInt32(MaxTextBox.Text)) { MessageBox.Show("Your Inv cannot exceed your Max", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //5 takes the modified part and saves it to the same index Inventory.CurrentPart.PartID = Convert.ToInt32(IDTextBox.Text); Inventory.CurrentPart.Name = NameTextBox.Text; Inventory.CurrentPart.InStock = Convert.ToInt32(InventoryTextBox.Text); Inventory.CurrentPart.Price = Convert.ToDouble(PriceCostTextBox.Text); Inventory.CurrentPart.Max = Convert.ToInt32(MaxTextBox.Text); Inventory.CurrentPart.Min = Convert.ToInt32(MinTextBox.Text); if (Inventory.CurrentPart.GetType() == typeof(Outsourced)) { if (!IsOutsourced) { var tempPart = new InHouse(Inventory.CurrentPart.PartID, Inventory.CurrentPart.Name, Inventory.CurrentPart.Price, Inventory.CurrentPart.InStock, Inventory.CurrentPart.Min, Inventory.CurrentPart.Max, 0); //make a method for the mID to input into the constructor FillI(tempPart); Inventory.UpdatePart(Inventory.CurrentPartIndex, tempPart); } else { FillO((Outsourced)Inventory.CurrentPart); Inventory.UpdatePart(Inventory.CurrentPartIndex, Inventory.CurrentPart); } } else { if (IsOutsourced) { var tempPart = new Outsourced(Inventory.CurrentPart.PartID, Inventory.CurrentPart.Name, Inventory.CurrentPart.Price, Inventory.CurrentPart.InStock, Inventory.CurrentPart.Min, Inventory.CurrentPart.Max, "dummy"); FillO(tempPart); Inventory.UpdatePart(Inventory.CurrentPartIndex, tempPart); } else { FillI((InHouse)Inventory.CurrentPart); Inventory.UpdatePart(Inventory.CurrentPartIndex, Inventory.CurrentPart); } } BackToMainScreen(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }