Beispiel #1
0
        public Person(string name, int id, BirthData bd)
        {
            Name = name;
            if (id < 0)
            {
                throw new Exception("Invalid ID Number, please enter a positive 9-digit integer number");
            }


            this.id = id;
            this.bd = bd;
        }
Beispiel #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (counter < numOfDancers)
            {
                try
                {
                    try
                    {
                        if ((txtDancerName.Text == "") || (txtIdNum.Text == "") || (txtHospital.Text == "") || (txtCountry.Text == "") || (txtYear.Text == "") || (txtMomCountry.Text == "") || (txtMomHos.Text == "") || (txtMomYear.Text == "") || (cboxType.Text == "") || (txtPerNum.Text == ""))
                        {
                            throw new Exception("Some details are missing! \r\nPlease fill in all fields");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                    string currentName = txtDancerName.Text;
                    try
                    {
                        currentId = int.Parse(txtIdNum.Text);
                        if (txtIdNum.Text.Length != 9)
                        {
                            throw new Exception("Invalid ID Number, please enter a positive 9 - digit integer number ");
                        }
                    }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Invalid ID Number, please enter a positive 9 - digit integer number ");
                        return;
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Invalid ID Number, please enter a positive 9 - digit integer number ");
                        return;
                    }

                    string currentDanceType = cboxType.SelectedItem.ToString();


                    try
                    {
                        currentYear = int.Parse(txtYear.Text);
                    }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Please enter year between 1900 and 2100");
                        return;
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Invalid Year!\r\nPlease try again");
                        return;
                    }
                    try
                    {
                        currentPerformanceNum = int.Parse(txtPerNum.Text);
                    }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Invalid number of performances.\r\nPlease try again");
                        return;
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Invalid number of performances.\r\nPlease enter only integer numbers");
                        return;
                    }
                    string currentCountry  = txtCountry.Text;
                    string currentHospital = txtHospital.Text;
                    string momHospital     = txtMomHos.Text;
                    string momCountry      = txtMomCountry.Text;
                    try
                    {
                        momYear = int.Parse(txtMomYear.Text);
                    }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Please enter year between 1900 and 2100");
                        return;
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Invalid Year!\r\nPlease try again");
                        return;
                    }


                    if (momYear >= currentYear)
                    {
                        throw new Exception("Sorry\r\nA mother can not be younger than her son!\r\nPlease Enter a valid mother's birth year");
                    }
                    BirthData bdmama   = new BirthData(momYear, momHospital, momCountry);
                    BirthData dancerBd = new BirthData(currentYear, currentHospital, currentCountry);
                    Dancer    dancer   = new Dancer(currentDanceType, currentPerformanceNum, bdmama, currentName, currentId, dancerBd);
                    ds.intUpdate(counter);
                    if ((counter != 0) && (ds.Equals(dancer) != false))
                    {
                        throw new Exception("The dancer already exists in the system\r\n");
                    }
                    ds.DancerArr[counter] = dancer;
                    counter++;
                    CleanField();
                }
                catch (OverflowException ex)
                {
                    MessageBox.Show(ex.Message);
                }

                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show("Please choose a type of dance");
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Sorry!\r\nThere is no more available space!");
            }
        }
Beispiel #3
0
 public Dancer(string danceType, int performanceNum, BirthData bdMom, string name, int id, BirthData bd) : base(name, id, bd)
 {
     DanceType      = danceType;
     PerformanceNum = performanceNum;
     this.bdMom     = bdMom;
 }