Пример #1
0
 private void PerEditButton_Click(object sender, EventArgs e)
 {
     if (DgPer.CurrentRow.DataBoundItem.GetType() == typeof(Agency))
     {
         Agency agencyPersonnel = (Agency)DgPer.CurrentRow.DataBoundItem;
         new EditPersonnel(agencyPersonnel).ShowDialog();
     }
     else if (DgPer.CurrentRow.DataBoundItem.GetType() == typeof(Outsourced))
     {
         Outsourced outsourcedPersonnel = (Outsourced)DgPer.CurrentRow.DataBoundItem;
         new EditPersonnel(outsourcedPersonnel).ShowDialog();
     }
 }
        public EditPersonnel(Outsourced outsourced)
        {
            InitializeComponent();

            PerIdBox.Text                 = Convert.ToString(outsourced.PersonnelId);
            PerNameBox.Text               = outsourced.Name;
            PerCityBox.Text               = Convert.ToString(outsourced.City);
            PerPhoneBox.Text              = Convert.ToString(outsourced.Phone);
            PerPositionBox.Text           = Convert.ToString(outsourced.Position);
            PerRateBox.Text               = Convert.ToString(outsourced.Rate);
            AffiliationBox.Text           = Convert.ToString(outsourced.AgencyContact);
            AffiliationLabel.Text         = "Hiring Agency Contact";
            OutsourcedRadioButton.Checked = true;
        }
 private void SaveButton_Click_1(object sender, EventArgs e)
 {
     if (AgencyButton.Checked)
     {
         AgencyButton.Checked = true;
         Agency agencyPersonnel = new Agency(int.Parse(PerIdBox.Text), PerNameBox.Text, PerPositionBox.Text, PerPhoneBox.Text, PerCityBox.Text, decimal.Parse(PerRateBox.Text), int.Parse(AffiliationBox.Text));
         if (String.IsNullOrWhiteSpace(PerNameBox.Text))
         {
             throw new ArgumentNullException("Name cannot be empty.");
         }
         if (int.Parse(PerIdBox.Text) != agencyPersonnel.PersonnelId)
         {
             MessageBox.Show("Cannot alter Personnel ID.");
             return;
         }
         else
         {
             Inventory.AddPersonnel(agencyPersonnel);
         }
     }
     else
     {
         OutsourcedButton.Checked = true;
         Outsourced outsourcedPersonnel = new Outsourced(int.Parse(PerIdBox.Text), PerNameBox.Text, PerPositionBox.Text, PerPhoneBox.Text, PerCityBox.Text, decimal.Parse(PerRateBox.Text), AffiliationBox.Text);
         if (String.IsNullOrWhiteSpace(PerNameBox.Text))
         {
             throw new ArgumentNullException("Name cannot be empty.");
         }
         if (int.Parse(PerIdBox.Text) != outsourcedPersonnel.PersonnelId)
         {
             MessageBox.Show("Cannot change Personnel ID.");
             return;
         }
         else
         {
             Inventory.AddPersonnel(outsourcedPersonnel);
         }
     }
     Close();
 }
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (AgencyRadioButton.Checked)
            {
                AgencyRadioButton.Checked = true;

                if (String.IsNullOrWhiteSpace(PerIdBox.Text) || String.IsNullOrWhiteSpace(PerNameBox.Text) || String.IsNullOrWhiteSpace(PerCityBox.Text) || String.IsNullOrWhiteSpace(PerPhoneBox.Text) || String.IsNullOrWhiteSpace(PerPositionBox.Text) || String.IsNullOrWhiteSpace(PerRateBox.Text))
                {
                    MessageBox.Show("Fields cannot be empty.");
                    return;
                }

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

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

                else
                {
                    try
                    {
                        Agency agencyPersonnel = new Agency(int.Parse(PerIdBox.Text), PerNameBox.Text, PerCityBox.Text, PerPhoneBox.Text, PerPositionBox.Text, decimal.Parse(PerRateBox.Text), int.Parse(AffiliationBox.Text));
                        Inventory.UpdatePersonnel(int.Parse(PerIdBox.Text), agencyPersonnel);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Program Error.");
                        throw;
                    }
                    this.Close();
                }
            }
            else
            {
                AgencyRadioButton.Checked = false;

                if (String.IsNullOrWhiteSpace(PerIdBox.Text) || String.IsNullOrWhiteSpace(PerNameBox.Text) || String.IsNullOrWhiteSpace(PerCityBox.Text) || String.IsNullOrWhiteSpace(PerPhoneBox.Text) || String.IsNullOrWhiteSpace(PerPositionBox.Text) || String.IsNullOrWhiteSpace(PerRateBox.Text))
                {
                    MessageBox.Show("All fields must have a value.");
                    return;
                }

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

                if (decimal.Parse(PerRateBox.Text).GetType() != typeof(decimal))
                {
                    MessageBox.Show("Rate must be a decimal Example: 0.00.");
                    return;
                }
                else
                {
                    try
                    {
                        Outsourced outsourcedPersonnel = new Outsourced(int.Parse(PerIdBox.Text), PerNameBox.Text, PerCityBox.Text, PerPhoneBox.Text, PerPositionBox.Text, decimal.Parse(PerRateBox.Text), AffiliationBox.Text);
                        Inventory.UpdatePersonnel(int.Parse(PerIdBox.Text), outsourcedPersonnel);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Program Error.");
                        throw;
                    }
                    this.Close();
                }
            }
        }