示例#1
0
 private void AddPartSave_Click_1(object sender, EventArgs e)
 {
     if (InHseBtn.Checked)
     {
         InHseBtn.Checked = true;
         Inhouse inhousePart = new Inhouse(int.Parse(IdBx.Text), NmBx.Text, decimal.Parse(PrBx.Text), int.Parse(InvBx.Text), int.Parse(MnBx.Text), int.Parse(MxBx.Text), int.Parse(MidBx.Text));
         if (String.IsNullOrWhiteSpace(NmBx.Text))
         {
             throw new ArgumentNullException("Name cannot be empty.");
         }
         if (int.Parse(IdBx.Text) != inhousePart.PartID)
         {
             MessageBox.Show("Cannot alter Product ID.");
             return;
         }
         if (int.Parse(InvBx.Text) > int.Parse(MxBx.Text))
         {
             MessageBox.Show("Inventory cannot exceed Maximum level.");
             return;
         }
         if (int.Parse(MnBx.Text) > int.Parse(MxBx.Text))
         {
             MessageBox.Show("Minimum cannot exceed Maximum.");
             return;
         }
         else
         {
             Inventory.AddPart(inhousePart);
         }
     }
     else
     {
         OutBtn.Checked = true;
         Outsourced outsourcedPart = new Outsourced(int.Parse(IdBx.Text), NmBx.Text, decimal.Parse(PrBx.Text), int.Parse(InvBx.Text), int.Parse(MnBx.Text), int.Parse(MxBx.Text), MidBx.Text);
         if (String.IsNullOrWhiteSpace(NmBx.Text))
         {
             throw new ArgumentNullException("Name cannot be empty.");
         }
         if (int.Parse(IdBx.Text) != outsourcedPart.PartID)
         {
             MessageBox.Show("Cannot change Product ID.");
             return;
         }
         if (int.Parse(InvBx.Text) > int.Parse(MxBx.Text))
         {
             MessageBox.Show("Inventory cannot exceed Maximum.");
             return;
         }
         if (int.Parse(MnBx.Text) > int.Parse(MxBx.Text))
         {
             MessageBox.Show("Minimum cannot exceed Maximum.");
             return;
         }
         else
         {
             Inventory.AddPart(outsourcedPart);
         }
     }
     Close();
 }
示例#2
0
 private void PartModButton_Click_1(object sender, EventArgs e)
 {
     //ModPrtIndx = DgPrt.CurrentRow.Index;
     if (DgPrt.CurrentRow.DataBoundItem.GetType() == typeof(Inhouse))
     {
         Inhouse inhousePart = (Inhouse)DgPrt.CurrentRow.DataBoundItem;
         new MdPrt(inhousePart).ShowDialog();
     }
     else if (DgPrt.CurrentRow.DataBoundItem.GetType() == typeof(Outsourced))
     {
         Outsourced outsourcedPart = (Outsourced)DgPrt.CurrentRow.DataBoundItem;
         new MdPrt(outsourcedPart).ShowDialog();
     }
 }
        public MdPrt(Inhouse inhouse)
        {
            InitializeComponent();

            ModPartIDBox.Text      = Convert.ToString(inhouse.PartID);
            ModPartName.Text       = inhouse.Name;
            ModPartInvBox.Text     = Convert.ToString(inhouse.InStock);
            ModPartPriceBox.Text   = Convert.ToString(inhouse.Price);
            ModPartMinBox.Text     = Convert.ToString(inhouse.Min);
            ModPartMaxBox.Text     = Convert.ToString(inhouse.Max);
            MdPrtMac.Text          = Convert.ToString(inhouse.MachineID);
            label7.Text            = "Machine ID";
            ModPartInRadio.Checked = true;
        }
        private void ModPartSave_Click_1(object sender, EventArgs e)
        {
            if (ModPartInRadio.Checked)
            {
                ModPartInRadio.Checked = true;

                if (String.IsNullOrWhiteSpace(ModPartIDBox.Text) || String.IsNullOrWhiteSpace(ModPartName.Text) || String.IsNullOrWhiteSpace(ModPartPriceBox.Text) || String.IsNullOrWhiteSpace(ModPartInvBox.Text) || String.IsNullOrWhiteSpace(ModPartMinBox.Text) || String.IsNullOrWhiteSpace(ModPartMaxBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty.");
                    return;
                }

                if (int.Parse(ModPartIDBox.Text).GetType() != typeof(int) || int.Parse(ModPartInvBox.Text).GetType() != typeof(int) || int.Parse(ModPartMinBox.Text).GetType() != typeof(int) || int.Parse(ModPartMaxBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("Fields that require integers must contain integers.");
                    return;
                }

                if (decimal.Parse(ModPartPriceBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Price must be a decimal. Example: 0.00");
                    return;
                }

                if (int.Parse(ModPartInvBox.Text) > int.Parse(ModPartMaxBox.Text))
                {
                    MessageBox.Show("Inventory cannot exceed Maximum.");
                    return;
                }

                if (int.Parse(ModPartMinBox.Text) > int.Parse(ModPartMaxBox.Text))
                {
                    MessageBox.Show("Minimum cannot exceed Maximum.");
                    return;
                }
                else
                {
                    try
                    {
                        Inhouse inhousePart = new Inhouse(int.Parse(ModPartIDBox.Text), ModPartName.Text, decimal.Parse(ModPartPriceBox.Text), int.Parse(ModPartInvBox.Text), int.Parse(ModPartMinBox.Text), int.Parse(ModPartMaxBox.Text), int.Parse(MdPrtMac.Text));
                        Inventory.UpdatePart(int.Parse(ModPartIDBox.Text), inhousePart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Program Error.");
                        throw;
                    }
                    this.Close();
                }
            }
            else
            {
                ModPartInRadio.Checked = false;

                if (String.IsNullOrWhiteSpace(ModPartIDBox.Text) || String.IsNullOrWhiteSpace(ModPartName.Text) || String.IsNullOrWhiteSpace(ModPartPriceBox.Text) || String.IsNullOrWhiteSpace(ModPartInvBox.Text) || String.IsNullOrWhiteSpace(ModPartMinBox.Text) || String.IsNullOrWhiteSpace(ModPartMaxBox.Text))
                {
                    MessageBox.Show("All fields must have a value.");
                    return;
                }

                if (int.Parse(ModPartIDBox.Text).GetType() != typeof(int) || int.Parse(ModPartInvBox.Text).GetType() != typeof(int) || int.Parse(ModPartMinBox.Text).GetType() != typeof(int) || int.Parse(ModPartMaxBox.Text).GetType() != typeof(int))
                {
                    MessageBox.Show("Fields that require integers must contain integers.");
                    return;
                }

                if (decimal.Parse(ModPartPriceBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Price must be a decimal Example: 0.00.");
                    return;
                }

                if (int.Parse(ModPartInvBox.Text) > int.Parse(ModPartMaxBox.Text))
                {
                    MessageBox.Show("Inventory cannot exceed Maximum.");
                    return;
                }

                if (int.Parse(ModPartMinBox.Text) > int.Parse(ModPartMaxBox.Text))
                {
                    MessageBox.Show("Minimum cannot exceed Maximum.");
                    return;
                }
                else
                {
                    try
                    {
                        Outsourced outsourcedPart = new Outsourced(int.Parse(ModPartIDBox.Text), ModPartName.Text, decimal.Parse(ModPartPriceBox.Text), int.Parse(ModPartInvBox.Text), int.Parse(ModPartMinBox.Text), int.Parse(ModPartMaxBox.Text), MdPrtMac.Text);
                        Inventory.UpdatePart(int.Parse(ModPartIDBox.Text), outsourcedPart);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Program Error.");
                        throw;
                    }
                    this.Close();
                }
            }
        }