Exemplo n.º 1
0
        internal bool AddCoach()
        {
            bool res = false;

            if ((Coach.CC != 0))
            {
                if (Coach.Create())
                {
                    Coaches.Add(Coach);
                    res = true;
                }
            }
            return(res);
        }
        /*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);
            }
        }