コード例 #1
0
        private void searchBtn_Click(object sender, EventArgs e)
        {
            {
                //Open search form
                var search = new CourseSearchForm();

                //get SelectClicked event result from searchform as int id
                search.SelectClicked += (o, args) =>
                {
                    if (!(o is int id))
                    {
                        return;
                    }

                    //id = courseId
                    courseId             = id;
                    instructorLabel.Text = courseId.ToString();
                    // First comd is used to get instructor name and course title for labels above the datagridview
                    using (conn = new SqlConnection(connectionstring))
                        using (SqlCommand comd = new SqlCommand("SELECT employee.employeeId as [eId], firstName + ' ' + lastName AS [instructorName], course.title FROM employee " +
                                                                "JOIN course ON course.employeeId = employee.employeeId WHERE courseId = @courseId", conn))
                            using (SqlDataAdapter adapter = new SqlDataAdapter(comd))
                            {
                                comd.Parameters.AddWithValue("@courseId", courseId);
                                DataTable gradesTable = new DataTable();
                                adapter.Fill(gradesTable);
                                DataRow dr = gradesTable.Rows[0];
                                instructorLabel.Text = dr["eId"].ToString() + " " + dr["instructorName"].ToString();
                                titleLabel.Text      = dr["title"].ToString();
                            }
                    //second comd is used to populate datagridview with student names and grades
                    using (conn = new SqlConnection(connectionstring))
                        using (SqlCommand comd = new SqlCommand("SELECT courseXstudent.studentId as [Student ID], student.firstName + ' ' + student.lastName AS [Student Name], grade FROM courseXstudent " +
                                                                "JOIN student ON courseXstudent.studentId = student.studentId WHERE courseId = @courseId", conn))
                            using (SqlDataAdapter adapter = new SqlDataAdapter(comd))
                            {
                                comd.Parameters.AddWithValue("@courseId", courseId);
                                DataTable gradesTable = new DataTable();
                                adapter.Fill(gradesTable);
                                gradesDataGrid.DataSource = gradesTable;
                            }
                };

                search.ShowDialog(this);
            }
        }
コード例 #2
0
        private void advSearchButton_Click(object sender, EventArgs e)
        {
            {
                //Open search form
                var search = new Forms.Admin.CourseSearchForm();

                //get SelectClicked event result from searchform as int id
                search.SelectClicked += (o, args) =>
                {
                    if (!(o is int id))
                    {
                        return;
                    }

                    courseId = id;
                    // Manage Course Form find button connection and Qry
                    // finds information off course Id search
                    using (conn = new SqlConnection(connectionString))
                        using (SqlCommand comd = new SqlCommand(
                                   "SELECT course.courseId, course.title, course.employeeId, course.seats, course.maxSeats, course.isAvailable, " +
                                   "employee.employeeId, employee.firstName + ' ' + employee.lastName AS 'Name', employee.isAdmin FROM course JOIN employee " +
                                   "ON course.employeeId = employee.employeeId WHERE course.courseId = @courseId", conn))
                            using (SqlDataAdapter adapter = new SqlDataAdapter(comd))
                            {
                                comd.Parameters.AddWithValue("@courseId", courseId);
                                DataTable courseTable = new DataTable();
                                adapter.Fill(courseTable);
                                if (courseTable.Rows.Count < 1)
                                {
                                    // displays no course found when no course is found and
                                    // unenables textboxes etc.
                                    ResetForm();
                                    currentCourseLabel.Text = "No Course Found.";
                                }
                                else
                                {
                                    DataRow dr = courseTable.Rows[0];
                                    courseId = int.Parse(dr["courseId"].ToString());
                                    currentCourseLabel.Text  = dr["title"].ToString();
                                    maxSeatingLabel.Text     = dr["maxSeats"].ToString();
                                    employeeIdLabel.Text     = dr["employeeId"].ToString();
                                    InstructorNameLabel.Text = dr["Name"].ToString();
                                    // if statement to display the isAvailable bool to radiobuttons
                                    // courtesy to Zachary for the help
                                    if (dr["isAvailable"].ToString() == "True")
                                    {
                                        yesRadioButton.Checked = true;
                                    }
                                    else
                                    {
                                        noRadioButton.Checked = true;
                                    }
                                    // enables textboxes and buttons once it finds a course by Id
                                    updatedmaxSeatingTextBox.Enabled = true;
                                    newCourseTitleTextBox.Enabled    = true;
                                    deleteButton.Enabled             = true;
                                    updateButton.Enabled             = true;
                                    newInstructorComboBox.Enabled    = true;
                                }
                            }
                };

                search.ShowDialog(this);
            }
        }