Esempio n. 1
0
        /*Adding Swimmer to the Form*/
        private void btnAddSwimmer_Click(object sender, EventArgs e)
        {
            //Sound
            sog.AddAssign();

            /*Checking All fields for the Swimmers*/
            //Checking the Name
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please Enter your Name", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking Province
            if (string.IsNullOrEmpty(txtPro.Text))
            {
                MessageBox.Show("Please Enter your Province", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking the postal Code
            if (string.IsNullOrEmpty(txtPostCode.Text))
            {
                MessageBox.Show("Please Enter your Postcode", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking the Street
            if (string.IsNullOrEmpty(txtStreet.Text))
            {
                MessageBox.Show("Please Enter your Street", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checcking City
            if (string.IsNullOrEmpty(txtCity.Text))
            {
                MessageBox.Show("Please Enter your City", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Chacking the Phone
            long phoneNo;

            try
            {
                phoneNo = long.Parse(txtPhNo.Text);
            }
            catch
            {
                MessageBox.Show("Please Check your Phone number", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                //Adding Swimmer to the List
                if (!string.IsNullOrEmpty(txtName.Text) || !string.IsNullOrEmpty(txtCity.Text) ||
                    !string.IsNullOrEmpty(txtPro.Text) || !string.IsNullOrEmpty(txtPostCode.Text) ||
                    !string.IsNullOrEmpty(txtStreet.Text))
                {
                    Swimmer newSwimmer = new Swimmer(txtName.Text, new DateTime(dtpDOB.Value.Year, dtpDOB.Value.Month, dtpDOB.Value.Day),
                                                     new Address(txtStreet.Text, txtCity.Text, txtPro.Text, txtPostCode.Text), phoneNo);

                    Swimmers.Add(newSwimmer);

                    home          = new Home();
                    home.Swimmers = Swimmers;
                    lbSwimmers.Items.Add(newSwimmer.Name);
                    //Displaying Message
                    MessageBox.Show($"Swimmer {newSwimmer.Name} Added Sucessfully", "SUCCESS",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Make Sure that you have entered all of the fields", "WAIT...", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }

                //set default value
                DefaultValues();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Cannot Add the Swimmer\n" + exception.Message,
                                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /*Add Coach to the list*/
        private void btnAddCoach_Click(object sender, EventArgs e)
        {
            sog.AddAssign();
            //Checking the Name
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please Enter your Name", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // Checking the Credential
            if (string.IsNullOrEmpty(txtCredential.Text))
            {
                MessageBox.Show("Please Enter your Credentials", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //Checking Province
            if (string.IsNullOrEmpty(txtPro.Text))
            {
                MessageBox.Show("Please Enter your Province", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking the postal Code
            if (string.IsNullOrEmpty(txtPostCode.Text))
            {
                MessageBox.Show("Please Enter your Postcode", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking the Street
            if (string.IsNullOrEmpty(txtStreet.Text))
            {
                MessageBox.Show("Please Enter your Street", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Checking City
            if (string.IsNullOrEmpty(txtCity.Text))
            {
                MessageBox.Show("Please Enter your City", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            /*Checking All fields for the Swimmers*/
            long phoneNo;

            try
            {
                phoneNo = long.Parse(txtPhNo.Text);
            }
            catch
            {
                MessageBox.Show("Please Check your Phone number", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                //Creating New Caoch
                Coach newCoach = new Coach(txtName.Text, new DateTime(dtpDOB.Value.Year, dtpDOB.Value.Month, dtpDOB.Value.Day),
                                           new Address(txtStreet.Text, txtCity.Text, txtPro.Text, txtPostCode.Text), phoneNo);
                newCoach.Credentials = txtCredential.Text;

                //Checkign whether all fields are filled if filled then add the coach to the list
                //Adding Swimmer to the List
                if (!string.IsNullOrEmpty(txtName.Text) || (!string.IsNullOrEmpty(txtCredential.Text)) || !string.IsNullOrEmpty(txtCity.Text) ||
                    !string.IsNullOrEmpty(txtPro.Text) || !string.IsNullOrEmpty(txtPostCode.Text) ||
                    !string.IsNullOrEmpty(txtStreet.Text))
                {
                    Coaches.Add(newCoach);
                    home         = new Home();
                    home.Coaches = Coaches;
                    lbCoaches.Items.Add(newCoach.Name);
                    //Displaying Message
                    MessageBox.Show($"Caoch {newCoach.Name} is Added Sucessfully", "SUCCESS",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Make Sure that you have entered all of the fields", "WAIT...", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Cannot Add the Coach\n" + exception.Message,
                                "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }