Esempio n. 1
0
        // This method copies the selected record from the available courses datagrid
        // and copies it to the qualification courses table. Then it updates the
        // qualification courses datagrid.
        private void btnAddC_Click(object sender, EventArgs e)
        {
            try
            {
                // Store the current selected Combo value so that it
                // can be selected after the process is finished.
                var theQualificationID = cmbQualificationIDC.SelectedIndex;

                //Select the selected Course ID from the Course datagrid
                int rowSelected            = dgvAvailableCoursesC.CurrentCell.RowIndex;
                var selectedCourseIDNumber = dgvAvailableCoursesC.Rows[rowSelected].Cells[0].Value.ToString();

                // Check that it is not already been added to the
                // selected Qualification
                var cidList = (from q in DB.Qualification_Courses
                               where q.QCode == cmbQualificationIDC.Text
                               select q.CID).ToList();

                foreach (int c in cidList)
                {
                    if (c == int.Parse(selectedCourseIDNumber))
                    {
                        MessageBox.Show("The selected course has already been added");
                        return;
                    }
                }

                // Use the selected Qualification Code and Course ID to
                // create a new Qualification_Course record
                var newQualificationCourse = new Qualification_Course();
                newQualificationCourse.QCode = cmbQualificationIDC.SelectedValue.ToString();
                newQualificationCourse.CID   = int.Parse(selectedCourseIDNumber);

                DB.Qualification_Courses.InsertOnSubmit(newQualificationCourse);
                DB.SubmitChanges();

                MessageBox.Show("Course added to Qualification");

                updateData(updated);

                // Recall the selected combo value
                cmbQualificationIDC.SelectedIndex = theQualificationID;
            }

            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Esempio n. 2
0
        // This method adds data to the Courses table
        private void btnAddA_Click(object sender, EventArgs e)
        {
            try
            {
                // Indicate that this is the Add Tab for Error Message control
                string theTab = "Add";

                // Test that a valid course number has been entered
                if (!ValidCourseID(txtCourseIDA.Text))
                {
                    return;
                }

                // Test that a unique Course number has been entered
                if (!validUniqueCourseNumber(txtCourseIDA.Text))
                {
                    return;
                }

                // Test that a course name has been entered
                if (!ValidCourseName(txtCourseNameA.Text, theTab))
                {
                    return;
                }

                // Test that a year has been selected
                if (!ValidYear(cmbYearA.Text))
                {
                    return;
                }

                // Test that a semester has been selected
                if (!ValidSemester(cmbSemesterA.Text))
                {
                    return;
                }

                // Create a new Courses object and add its properties
                var newCourse = new Course();
                newCourse.CID      = int.Parse(txtCourseIDA.Text.ToString());
                newCourse.CName    = txtCourseNameA.Text.Trim();
                newCourse.Year     = int.Parse(cmbYearA.SelectedItem.ToString());
                newCourse.Semester = cmbSemesterA.SelectedItem.ToString();
                newCourse.TID      = int.Parse(cmbTeacherIDA.SelectedItem.ToString());

                // Add the new course to the database
                DB.Courses.InsertOnSubmit(newCourse);
                DB.SubmitChanges();

                // Create a new Qualification_Courses object and
                // add its properties
                var newQualCourse = new Qualification_Course();
                newQualCourse.QCode = cmbQualificationCodeA.SelectedItem.ToString();
                newQualCourse.CID   = int.Parse(txtCourseIDA.Text.ToString());

                // Add the new record to the database
                DB.Qualification_Courses.InsertOnSubmit(newQualCourse);
                DB.SubmitChanges();

                lblCoursesMessageA.Text = "Course ID " + txtCourseIDA.Text + " added";

                updateData(updated);
            }

            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }