Beispiel #1
0
        private void bt_next_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                next_topic_id = connect.returnconnection_string("SELECT min(topic_id) FROM Topics WHERE topic_fk_course =" + current_course_id + " AND topic_id > " + topic_id);
                if (next_topic_id.Equals(""))
                {
                    int check = Convert.ToInt32(connect.returnconnection_string("SELECT COUNT(1) FROM Student_Course WHERE student_course_fk_student_uid= " + StudentLogin.student_uid + " AND student_course_fk_course_id=" + current_course_id));
                    if (check == 0)
                    {
                        StudentCourseProvider studentCourseProvider = new StudentCourseProvider();
                        studentCourseProvider.student_course_fk_student_uid = StudentLogin.student_uid;
                        studentCourseProvider.student_course_fk_course_id   = current_course_id;
                        MessageBox.Show("provider");

                        StudentCourseHandler studentCourseHandler = new StudentCourseHandler();
                        string user_message = studentCourseHandler.enroll_student(studentCourseProvider);
                        MessageBox.Show(user_message);
                    }

                    TopicSelector topicSelector = new TopicSelector();
                    topicSelector.Show();
                }
                else
                {
                    load_page(current_course_id);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public string enroll_student(StudentCourseProvider studentCourseProvider)
        {
            string        user_message;
            SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);

            try
            {
                SqlCommand sqlCmd = new SqlCommand("[enroll_student]", sqlConnection);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@student_course_fk_student_uid", SqlDbType.Int).Value = studentCourseProvider.student_course_fk_student_uid;
                sqlCmd.Parameters.Add("@student_course_fk_course_id", SqlDbType.Int).Value   = studentCourseProvider.student_course_fk_course_id;



                sqlConnection.Open();
                sqlCmd.ExecuteNonQuery();
                return(user_message = "You can now take the test for this Course!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(user_message = "Failure!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }