Beispiel #1
0
 private void SaveBtn_Click(object sender, EventArgs e)
 {
     if (InhouseRadio.Checked)
     {
         InhouseRadio.Checked = true;
         Inhouse inhousePart = new Inhouse(int.Parse(IDTextBox.Text), NameTextBox.Text, decimal.Parse(PriceCostTextBox.Text), int.Parse(InventoryTextBox.Text), int.Parse(MinTextBox.Text), int.Parse(MaxTextBox.Text), int.Parse(IdentifierLabelTextBox.Text));
         if (String.IsNullOrWhiteSpace(NameTextBox.Text))
         {
             throw new ArgumentNullException("Name cannot be empty");
         }
         if (int.Parse(IDTextBox.Text) != inhousePart.PartID)
         {
             MessageBox.Show("Cannot alter Product's ID");
             return;
         }
         if (int.Parse(InventoryTextBox.Text) > int.Parse(MaxTextBox.Text))
         {
             MessageBox.Show("Inventory stock level cannot exceed Maximum permitted stock level");
             return;
         }
         if (int.Parse(MinTextBox.Text) > int.Parse(MaxTextBox.Text))
         {
             MessageBox.Show("Minimum permitted stock level cannot exceed Maximum permitted stock level");
             return;
         }
         else
         {
             Inventory.AddPart(inhousePart);
         }
     }
     else
     {
         OutsourcedRadio.Checked = true;
         Outsourced outsourcedPart = new Outsourced(int.Parse(IDTextBox.Text), NameTextBox.Text, decimal.Parse(PriceCostTextBox.Text), int.Parse(InventoryTextBox.Text), int.Parse(MinTextBox.Text), int.Parse(MaxTextBox.Text), IdentifierLabelTextBox.Text);
         if (String.IsNullOrWhiteSpace(NameTextBox.Text))
         {
             throw new ArgumentNullException("Name cannot be empty");
         }
         if (int.Parse(IDTextBox.Text) != outsourcedPart.PartID)
         {
             MessageBox.Show("Cannot alter Product's ID");
             return;
         }
         if (int.Parse(InventoryTextBox.Text) > int.Parse(MaxTextBox.Text))
         {
             MessageBox.Show("Inventory stock level cannot exceed Maximum permitted stock level");
             return;
         }
         if (int.Parse(MinTextBox.Text) > int.Parse(MaxTextBox.Text))
         {
             MessageBox.Show("Minimum permitted stock level cannot exceed Maximum permitted stock level");
             return;
         }
         else
         {
             Inventory.AddPart(outsourcedPart);
         }
     }
     Close();
 }
        public ModifyPartForm(Inhouse inhouse)
        {
            InitializeComponent();

            IDTextBox.Text              = Convert.ToString(inhouse.PartID);
            NameTextBox.Text            = inhouse.Name;
            InventoryTextBox.Text       = Convert.ToString(inhouse.InStock);
            PriceCostTextBox.Text       = Convert.ToString(inhouse.Price);
            MinTextBox.Text             = Convert.ToString(inhouse.Min);
            MaxTextBox.Text             = Convert.ToString(inhouse.Max);
            IdentifierLabelTextBox.Text = Convert.ToString(inhouse.MachineID);
            IdentifierLabel.Text        = "Machine ID";
            InhouseRadio.Checked        = true;
        }
Beispiel #3
0
 private void Main_Parts_Modify_Btn_Click(object sender, EventArgs e)
 {
     // bring up instance of Modfy part screen with instance of user type selected by row
     if (MainParts_GridView.CurrentRow.DataBoundItem.GetType() == typeof(Inhouse))
     {
         Inhouse inhousePart = (Inhouse)MainParts_GridView.CurrentRow.DataBoundItem;
         new ModifyPartForm(inhousePart).ShowDialog();
     }
     else if (MainParts_GridView.CurrentRow.DataBoundItem.GetType() == typeof(Outsourced))
     {
         Outsourced outsourcedPart = (Outsourced)MainParts_GridView.CurrentRow.DataBoundItem;
         new ModifyPartForm(outsourcedPart).ShowDialog();
     }
 }
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (InhouseRadio.Checked)
            {
                InhouseRadio.Checked = true;

                // verify fields are not null
                if (String.IsNullOrWhiteSpace(IDTextBox.Text) || String.IsNullOrWhiteSpace(NameTextBox.Text) || String.IsNullOrWhiteSpace(PriceCostTextBox.Text) || String.IsNullOrWhiteSpace(InventoryTextBox.Text) || String.IsNullOrWhiteSpace(MinTextBox.Text) || String.IsNullOrWhiteSpace(MaxTextBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty");
                    return;
                }
                // verify integer fields are of the appropriate type
                if (int.Parse(IDTextBox.Text).GetType() != typeof(int) || int.Parse(InventoryTextBox.Text).GetType() != typeof(int) || int.Parse(MaxTextBox.Text).GetType() != typeof(int) || int.Parse(MaxTextBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("Ensure fields that require integers contain integers");
                    return;
                }
                // verify decimal field is of the appropriate type
                if (decimal.Parse(PriceCostTextBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Ensure Price field entry is in decimal format. Example: 0.00");
                    return;
                }
                // verify inventory level does not exceed max
                if (int.Parse(InventoryTextBox.Text) > int.Parse(MaxTextBox.Text))
                {
                    MessageBox.Show("Inventory stock level cannot exceed Maximum permitted stock level");
                    return;
                }
                // verify that minimum level does not exceed max
                if (int.Parse(MinTextBox.Text) > int.Parse(MaxTextBox.Text))
                {
                    MessageBox.Show("Minimum permitted stock level cannot exceed Maximum permitted stock level");
                    return;
                }
                else
                {
                    // exception handling
                    try
                    {
                        Inhouse inhousePart = new Inhouse(int.Parse(IDTextBox.Text), NameTextBox.Text, decimal.Parse(PriceCostTextBox.Text), int.Parse(InventoryTextBox.Text), int.Parse(MinTextBox.Text), int.Parse(MaxTextBox.Text), int.Parse(IdentifierLabelTextBox.Text));
                        Inventory.UpdatePart(int.Parse(IDTextBox.Text), inhousePart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Something went wrong");
                        throw;
                    }
                    this.Close();
                }
            }
            else
            {
                OutsourcedRadio.Checked = true;

                // verify fields are not null
                if (String.IsNullOrWhiteSpace(IDTextBox.Text) || String.IsNullOrWhiteSpace(NameTextBox.Text) || String.IsNullOrWhiteSpace(PriceCostTextBox.Text) || String.IsNullOrWhiteSpace(InventoryTextBox.Text) || String.IsNullOrWhiteSpace(MinTextBox.Text) || String.IsNullOrWhiteSpace(MaxTextBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty");
                    return;
                }
                // verify integer fields are of the appropriate type
                if (int.Parse(IDTextBox.Text).GetType() != typeof(int) || int.Parse(InventoryTextBox.Text).GetType() != typeof(int) || int.Parse(MaxTextBox.Text).GetType() != typeof(int) || int.Parse(MaxTextBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("Ensure fields that require integers contain integers");
                    return;
                }
                // verify decimal field is of the appropriate type
                if (decimal.Parse(PriceCostTextBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Ensure Price field entry is in decimal format. Example: 0.00");
                    return;
                }
                // verify inventory level does not exceed max
                if (int.Parse(InventoryTextBox.Text) > int.Parse(MaxTextBox.Text))
                {
                    MessageBox.Show("Inventory stock level cannot exceed Maximum permitted stock level");
                    return;
                }
                // verify that minimum level does not exceed max
                if (int.Parse(MinTextBox.Text) > int.Parse(MaxTextBox.Text))
                {
                    MessageBox.Show("Minimum permitted stock level cannot exceed Maximum permitted stock level");
                    return;
                }
                else
                {
                    // exception handling
                    try
                    {
                        Outsourced outsourcedPart = new Outsourced(int.Parse(IDTextBox.Text), NameTextBox.Text, decimal.Parse(PriceCostTextBox.Text), int.Parse(InventoryTextBox.Text), int.Parse(MinTextBox.Text), int.Parse(MaxTextBox.Text), IdentifierLabelTextBox.Text);
                        Inventory.UpdatePart(int.Parse(IDTextBox.Text), outsourcedPart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Something went wrong");
                        throw;
                    }
                    this.Close();
                }
            }
        }