コード例 #1
0
ファイル: Form1.cs プロジェクト: fabestine1/MyThing
        // methods

        ////////////////////////// BEGIN YOUR CODE HERE ///////////////////////////////

        /// <summary>
        /// btnAddParticipant_Click(object sender, EventArgs e)
        /// Button event handler to add a participant with the specified data
        /// to the course that is currently selected in the listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddParticipant_Click(object sender, EventArgs e)
        {
            // To do, assignment 4
            try
            {
                mySchool.AddParticipantToCourse(((Course)lbCourseOverview.SelectedItem).CourseId, Convert.ToInt32(tbParticipantId.Text), tbParticipantName.Text);
                ShowAllCourses();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("You have to select a course.");
            }
            catch (FormatException)
            {
                MessageBox.Show("The format of the participant ID and/or name is incorrect.");
            }
            catch (CourseException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }