private void modifyButton1_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow.DataBoundItem.GetType() == typeof(Inhouse))
     {
         Inhouse inhousePart = (Inhouse)dataGridView1.CurrentRow.DataBoundItem;
         new ModifyPartForm(inhousePart).ShowDialog();
     }
     else if (dataGridView1.CurrentRow.DataBoundItem.GetType() == typeof(Outsourced))
     {
         Outsourced outsourcedPart = (Outsourced)dataGridView1.CurrentRow.DataBoundItem;
         new ModifyPartForm(outsourcedPart).ShowDialog();
     }
 }
        public ModifyPartForm(Outsourced outsourced)
        {
            InitializeComponent();

            ModIDBox.Text              = Convert.ToString(outsourced.PartID);
            ModNameBox.Text            = outsourced.Name;
            ModInventoryBox.Text       = Convert.ToString(outsourced.InStock);
            ModPriceBox.Text           = Convert.ToString(outsourced.Price);
            ModMinBox.Text             = Convert.ToString(outsourced.Min);
            ModMaxBox.Text             = Convert.ToString(outsourced.Max);
            ModMachineIDBox.Text       = Convert.ToString(outsourced.CompanyName);
            MachineOrCompanyLabel.Text = "Company Name";
            radioOutsourced.Checked    = true;
        }
Exemple #3
0
        private void AddPartSaveButton_Click(object sender, EventArgs e)
        {
            if (inHouseRadio.Checked)
            {
                inHouseRadio.Checked = true;
                Inhouse inhousePart = new Inhouse(int.Parse(AddPartIDBox.Text), AddPartNameBox.Text, decimal.Parse(AddPartPriceBox.Text), int.Parse(AddPartInventoryBox.Text),
                                                  int.Parse(AddPartMinBox.Text), int.Parse(AddPartMaxBox.Text), int.Parse(AddPartMachOrCompBox.Text));
                if (String.IsNullOrWhiteSpace(AddPartNameBox.Text))
                {
                    throw new ArgumentException("Name cannot be empty.");
                }
                if (int.Parse(AddPartIDBox.Text) != inhousePart.PartID)
                {
                    MessageBox.Show("Cannot alter Product's ID.");
                    return;
                }
                if (int.Parse(AddPartInventoryBox.Text) > int.Parse(AddPartMaxBox.Text))
                {
                    MessageBox.Show("Stock level cannot exceed Maximum stock level.");
                    return;
                }
                if (int.Parse(AddPartMinBox.Text) > int.Parse(AddPartMaxBox.Text))
                {
                    MessageBox.Show("Minimum stock level cannot exceed Maximum stock level.");
                }
                else
                {
                    Inventory.AddPart(inhousePart);
                }
            }
            else
            {
                outsourcedRadio.Checked = true;
                Outsourced outsourcedPart = new Outsourced(int.Parse(AddPartIDBox.Text), AddPartNameBox.Text, decimal.Parse(AddPartPriceBox.Text), int.Parse(AddPartInventoryBox.Text),
                                                           int.Parse(AddPartMinBox.Text), int.Parse(AddPartMaxBox.Text), AddPartMachOrCompBox.Text);
                if (String.IsNullOrWhiteSpace(AddPartNameBox.Text))
                {
                    throw new ArgumentException("Name cannot be empty.");
                }
                if (int.Parse(AddPartIDBox.Text) != outsourcedPart.PartID)
                {
                    MessageBox.Show("Cannot alter Product's ID.");
                    return;
                }
                if (int.Parse(AddPartInventoryBox.Text) > int.Parse(AddPartMaxBox.Text))
                {
                    MessageBox.Show("Stock level cannot exceed Maximum stock level.");
                    return;
                }
                if (int.Parse(AddPartMinBox.Text) > int.Parse(AddPartMaxBox.Text))
                {
                    MessageBox.Show("Minimum stock level cannot exceed Maximum stock level.");
                    return;
                }
                else
                {
                    Inventory.AddPart(outsourcedPart);
                }
            }

            Close();
        }
        private void ModSaveButton_Click(object sender, EventArgs e)
        {
            if (radioInhouse.Checked)
            {
                radioInhouse.Checked = true;

                if (String.IsNullOrWhiteSpace(ModIDBox.Text) || String.IsNullOrWhiteSpace(ModNameBox.Text) || String.IsNullOrWhiteSpace(ModPriceBox.Text) ||
                    String.IsNullOrWhiteSpace(ModInventoryBox.Text) || String.IsNullOrWhiteSpace(ModMinBox.Text) || String.IsNullOrWhiteSpace(ModMaxBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty.");
                    return;
                }

                if (int.Parse(ModIDBox.Text).GetType() != typeof(int) || int.Parse(ModInventoryBox.Text).GetType() != typeof(int) ||
                    int.Parse(ModMinBox.Text).GetType() != typeof(int) || int.Parse(ModMaxBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("These fields require integers.");
                    return;
                }

                if (decimal.Parse(ModPriceBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Your price must be a decimal. Example: 15.00");
                    return;
                }

                if (int.Parse(ModInventoryBox.Text) > int.Parse(ModMaxBox.Text))
                {
                    MessageBox.Show("Your Inventory cannot exceed the Maximumu.");
                    return;
                }

                if (int.Parse(ModMinBox.Text) > int.Parse(ModMaxBox.Text))
                {
                    MessageBox.Show("The Minimum cannot exceed the Maximum.");
                    return;
                }
                else
                {
                    try
                    {
                        Inhouse inhousePart = new Inhouse(int.Parse(ModIDBox.Text), ModNameBox.Text, decimal.Parse(ModPriceBox.Text), int.Parse(ModInventoryBox.Text),
                                                          int.Parse(ModMinBox.Text), int.Parse(ModMaxBox.Text), int.Parse(ModMachineIDBox.Text));
                        Inventory.UpdatePart(int.Parse(ModIDBox.Text), inhousePart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error.");
                        //throw;
                    }
                    this.Close();
                }
            }
            else
            {
                radioOutsourced.Checked = true;

                if (String.IsNullOrWhiteSpace(ModIDBox.Text) || String.IsNullOrWhiteSpace(ModNameBox.Text) || String.IsNullOrWhiteSpace(ModPriceBox.Text) ||
                    String.IsNullOrWhiteSpace(ModInventoryBox.Text) || String.IsNullOrWhiteSpace(ModMinBox.Text) || String.IsNullOrWhiteSpace(ModMaxBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty.");
                    return;
                }

                if (int.Parse(ModIDBox.Text).GetType() != typeof(int) || int.Parse(ModInventoryBox.Text).GetType() != typeof(int) ||
                    int.Parse(ModMinBox.Text).GetType() != typeof(int) || int.Parse(ModMaxBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("These fields require integers.");
                    return;
                }

                if (decimal.Parse(ModPriceBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Your price must be a decimal. Example: 15.00");
                    return;
                }

                if (int.Parse(ModInventoryBox.Text) > int.Parse(ModMaxBox.Text))
                {
                    MessageBox.Show("Your Inventory cannot exceed the Maximum.");
                    return;
                }

                if (int.Parse(ModMinBox.Text) > int.Parse(ModMaxBox.Text))
                {
                    MessageBox.Show("The Minimum cannot exceed the Maximum.");
                    return;
                }
                else
                {
                    try
                    {
                        Outsourced outsourcedPart = new Outsourced(int.Parse(ModIDBox.Text), ModNameBox.Text, decimal.Parse(ModPriceBox.Text), int.Parse(ModInventoryBox.Text),
                                                                   int.Parse(ModMinBox.Text), int.Parse(ModMaxBox.Text), ModMachineIDBox.Text);
                        Inventory.UpdatePart(int.Parse(ModIDBox.Text), outsourcedPart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error.");
                        throw;
                    }
                    this.Close();
                }
            }
        }