/// <summary>
 /// Raises the SaveCoachTimetable event safely.
 /// </summary>
 /// <param name="coachTimetable"></param>
 private void RaiseSaveCoachTimetableEvent(CoachTimetable coachTimetable)
 {
     if (SaveCoachTimetable != null)
     {
         SaveCoachTimetable(coachTimetable);
     }
 }
        /// <summary>
        /// Initialises a new instance of the Tennis_Management_Software.TimetableInputForm class.
        /// </summary>
        public TimetableInputForm(CoachTimetable coachTimetable)
        {
            InitializeComponent();
            InitializeRadioButtons();
            this.personType = PersonType.Coach;
            this.lessonType = coachTimetable.TypeOfLesson;
            coachPanel.Hide();
            studentsInLessonLabel.Text = "Students in group lesson: ";
            FillInformation(coachTimetable);

            switch (lessonType)
            {
            case LessonType.Private:
                if (studentListBox.Items.Count == 1)
                {
                    addButton.Enabled           = false;
                    studentBrowseButton.Enabled = false;
                }
                else
                {
                    addButton.Enabled           = true;
                    studentBrowseButton.Enabled = true;
                }
                break;

            case LessonType.SemiPrivate:
                if (studentListBox.Items.Count == 2)
                {
                    addButton.Enabled           = false;
                    studentBrowseButton.Enabled = false;
                }
                else
                {
                    addButton.Enabled           = true;
                    studentBrowseButton.Enabled = true;
                }
                break;

            case LessonType.Group:
                addButton.Enabled           = true;
                studentBrowseButton.Enabled = true;
                break;

            default:
                break;
            }
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            if (AreFieldsComplete())
            {
                Time fromTime = new Time(fromTimePicker.Value.Hour, fromTimePicker.Value.Minute);
                Time toTime   = new Time(toTimePicker.Value.Hour, toTimePicker.Value.Minute);

                List <string> studentNameList = new List <string>();
                for (int i = 0; i < studentListBox.Items.Count; i++)
                {
                    studentNameList.Add(studentListBox.GetItemText(studentListBox.Items[i]));
                }


                switch (personType)
                {
                case PersonType.Student:
                    StudentTimetable studentTimetable;
                    switch (lessonType)
                    {
                    case LessonType.Private:
                        studentTimetable = new StudentTimetable((DayOfWeek)dayCbox.SelectedIndex, fromTime, toTime, (byte)tennisCourtNumUpDown.Value, InputInformation.CorrectInputFormat(coachNameSurnameTbox.Text), lessonType);
                        RaiseSaveStudentTimetableEvent(studentTimetable);
                        break;

                    case LessonType.Group:
                        studentTimetable = new StudentTimetable((DayOfWeek)dayCbox.SelectedIndex, fromTime, toTime, (byte)tennisCourtNumUpDown.Value, studentNameList, InputInformation.CorrectInputFormat(coachNameSurnameTbox.Text), lessonType);
                        RaiseSaveStudentTimetableEvent(studentTimetable);
                        break;

                    case LessonType.SemiPrivate:
                        studentTimetable = new StudentTimetable((DayOfWeek)dayCbox.SelectedIndex, fromTime, toTime, (byte)tennisCourtNumUpDown.Value, studentNameList, InputInformation.CorrectInputFormat(coachNameSurnameTbox.Text), lessonType);
                        RaiseSaveStudentTimetableEvent(studentTimetable);
                        break;
                    }
                    break;

                case PersonType.Coach:
                    CoachTimetable coachTimetable = new CoachTimetable((DayOfWeek)dayCbox.SelectedIndex, fromTime, toTime, (byte)tennisCourtNumUpDown.Value, studentNameList, lessonType);
                    RaiseSaveCoachTimetableEvent(coachTimetable);
                    break;
                }

                this.Close();
            }
        }