private bool DoesThisSubjectExist(StudentResult aStudentResult)
 {
     List<Course> courses = new List<Course>();
     aStudentManager = new StudentManager();
     courses = aStudentManager.GetStudentCourses(aStudentResult.RegistationNo);
     foreach (Course course in courses)
     {
         if (course.CourseId == aStudentResult.CourseId)
         {
             return true;
         }
     }
     return false;
 }
        private bool DoesThisSubjectExist(StudentResult aStudentResult)
        {
            List <Course> courses = new List <Course>();

            aStudentManager = new StudentManager();
            courses         = aStudentManager.GetStudentCourses(aStudentResult.RegistationNo);
            foreach (Course course in courses)
            {
                if (course.CourseId == aStudentResult.CourseId)
                {
                    return(true);
                }
            }
            return(false);
        }
        protected void enrollButton_Click(object sender, EventArgs e)
        {
            if(!IsValid)
            {
                return;
            }

            try
            {
                StudentCourse aStudentCourse = new StudentCourse();
                aStudentCourse.RegistrationNo = registationNoTextBox.Text;
                aStudentCourse.EnrollDate = dateTextBox.Text;
                aStudentCourse.CourseId = Convert.ToInt16(enrollDropDownList.Text);
                aStudentCourse.Status = 0;
                StudentManager aStudentManager = new StudentManager();
                string msg = aStudentManager.SaveStudentCourse(aStudentCourse);
                if(msg=="Saved")
                {
                    msgLabel.ForeColor = Color.Green;
                    msgLabel.Text = msg;
                    ShowStudentAndCourseInfo();
                }
                else
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Text = msg;
                }

            }
            catch (SqlException sqlException)
            {
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text = "Database error.See details error: " + sqlException.Message;

            }
            catch (Exception exception)
            {
                msgLabel.ForeColor = Color.Red;
                string errorMessage = "Unknow error occured.";
                errorMessage += exception.Message;
                if (exception.InnerException != null)
                {
                    errorMessage += exception.InnerException.Message;
                }
                msgLabel.Text = errorMessage;
            }
        }
        private void ShowStudentAndCourseInfo()
        {
            try
            {
                StudentManager aStudentManager = new StudentManager();
                string regNo = registationNoTextBox.Text;
                ViewStudentInformation aViewStudentInformation = new ViewStudentInformation();
                aViewStudentInformation = aStudentManager.GetStudentInfo(regNo);
                if(aViewStudentInformation.Name==null)
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Text = "Invalid registation Number";
                    return;
                }
                nameTextBox.Text = aViewStudentInformation.Name;
                emailTextBox.Text = aViewStudentInformation.Email;
                departmentTextBox.Text = aViewStudentInformation.DepartmentName;
                Course aCourse = new Course();
                List<Course> courses = new List<Course>();
                courses = aStudentManager.GetStudentCourses(regNo);
                enrollsubjectGridView.DataSource = courses;
                enrollsubjectGridView.DataBind();
                List<Course> courseList = new List<Course>();
                courseList = aStudentManager.GetAllcourses(aViewStudentInformation);
                enrollDropDownList.DataSource = courseList;
                enrollDropDownList.DataBind();

            }
            catch (Exception exception)
            {

                throw exception;
            }
        }
        protected void showAllCourseOfUniversityButton_Click(object sender, EventArgs e)
        {
            try
            {
                string departmentCode = departmentTextBox.Text;
                string regNo = registationNoTextBox.Text;
                StudentManager aStudentManager = new StudentManager();

                List<Course> courseList = new List<Course>();
                courseList = aStudentManager.GetStudentMinorCourses(departmentCode, regNo);
                enrollDropDownList.DataSource = courseList;
                enrollDropDownList.DataBind();
            }
            catch (SqlException sqlException)
            {
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text = "Database error.See details error: " + sqlException.Message;

            }
            catch (Exception exception)
            {
                msgLabel.ForeColor = Color.Red;
                string errorMessage = "Unknow error occured.";
                errorMessage += exception.Message;
                if (exception.InnerException != null)
                {
                    errorMessage += exception.InnerException.Message;
                }
                msgLabel.Text = errorMessage;
            }
        }
        protected void searchButton_Click(object sender, EventArgs e)
        {
            if(!IsValid)
            {
                return;

            }

            try
            {
                string regNo = regNoTextBox.Value;
                int depeartmentId = Convert.ToInt16(departmentDropDownList.Text);
                StudentManager aStudentManager = new StudentManager();
                Student aStudent = new Student();
                aStudent = aStudentManager.GetStudentInformation(regNo, depeartmentId);
                if (aStudent.RegistationNo == null)
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Text = "Invalid Registation Number";
                }
                nameTextBox.Value = aStudent.Name;
                emailTextBox.Value = aStudent.Email;
            }
            catch (SqlException sqlException)
            {
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text = "Database error.See details error: " + sqlException.Message;

            }
            catch (Exception exception)
            {
                msgLabel.ForeColor = Color.Red;
                string errorMessage = "Unknow error occured.";
                errorMessage += exception.Message;
                if (exception.InnerException != null)
                {
                    errorMessage += exception.InnerException.Message;
                }
                msgLabel.Text = errorMessage;
            }
        }
        private void GetResult(string regNo)
        {
            try
            {
                StudentManager aStudentManager = new StudentManager();
                ResultManager aResultManager = new ResultManager();
                ViewStudentInformation aViewStudentInformation = new ViewStudentInformation();
                aViewStudentInformation = aStudentManager.GetStudentInformation(regNo);

                if (aViewStudentInformation.Name ==null)
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Text = "Invalid Registation Number";
                    return;
                }

                nameTextBox.Value = aViewStudentInformation.Name;
                emailTextBox.Value = aViewStudentInformation.Email;
                departmentTextBox.Value = aViewStudentInformation.DepartmentName;
                ViewResult aViewResult = new ViewResult();
                List<ViewCourseGradeAndCredit> viewCourseGradeAndCreditList = new List<ViewCourseGradeAndCredit>();
                viewCourseGradeAndCreditList = aResultManager.GetCourseResult(regNo);
                detailsResultGridView.DataSource = viewCourseGradeAndCreditList;
                detailsResultGridView.DataBind();
                aViewResult = aResultManager.GetSubjectCGPA(regNo);
                noOfEnrolledCoursesTextBox.Value = aViewResult.NoOfEnrolledCourses.ToString();
                noOfRemainingCoursesTextBox.Value =
                    (aViewResult.NoOfEnrolledCourses - aViewResult.NoOfCompletedCourses).ToString();
                noOfCompletedCoursesTextBox.Value = aViewResult.NoOfCompletedCourses.ToString();
                totalCreditEnrolledCoursesTextBox.Value = aViewResult.EnrolledCredit.ToString();
                completedCreditTextBox.Value = aViewResult.CompletedCredit.ToString();
                remainingCreditTextBox.Value = (aViewResult.EnrolledCredit - aViewResult.CompletedCredit).ToString();
                gradeLetterTextBox.Value = aViewResult.GradeLetter;
                cgpaTextBox.Value = aViewResult.Cgpa.ToString();
                if (aViewResult.NoOfEnrolledCourses != aViewResult.NoOfCompletedCourses||aViewResult.NoOfCompletedCourses==0)

                {
                    resultLabel.ForeColor = Color.Red;
                    resultLabel.Text = "You are not eligible to get the certificate";
                }

                else
                {
                    resultLabel.ForeColor = Color.Green;
                    resultLabel.Text = "You are  eligible to get the certificate";
                }

            }
            catch (SqlException sqlException)
            {
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text = "Database error.See details error: " + sqlException.Message;

            }
            catch (Exception exception)
            {
                msgLabel.ForeColor = Color.Red;
                string errorMessage = "Unknow error occured.";
                errorMessage += exception.Message;
                if (exception.InnerException != null)
                {
                    errorMessage += exception.InnerException.Message;
                }
                msgLabel.Text = errorMessage;
            }
        }
        private Student GetStudentInfo()
        {
            try
            {
                aStudentManager = new StudentManager();
                aStudent = new Student();
                aStudent.Name = nameText.Value;
                aStudent.Email = emailText.Value;
                aStudent.ContactNo = contactNoText.Value;
                aStudent.DepartmentId = departmentDropDownList.Text;
                aStudent.RegistationDate = dateText.Value;
                string year = aStudentManager.GetYear(dateText.Value);
                aStudent.Address = addressText.Value;
                string id = aStudentManager.GetStudentRegistationNO(aStudent);
                aStudent.RegistationNo = year + departmentDropDownList.SelectedItem.Text + id;
                return aStudent;
            }

            catch (Exception exception)
            {

                throw exception;
            }
        }
        protected void registerButton_Click(object sender, EventArgs e)
        {
            if(!IsValid)
            {
                return;
            }
            try
            {
                aStudentManager = new StudentManager();
                Student aStudent = (Student)Session["aStudent"];
                certificates = (List<Certificate>)ViewState["Certificates"];
                aStudent.Certificates = certificates;
                string msg = aStudentManager.SaveStudent(aStudent);
                if (msg == "Saved")
                {
                    msgLabel.ForeColor = Color.Green;
                    Response.Redirect("~/UI/ShowStudentRegistationNoUI.aspx");
                }

                else
                {
                    msgLabel.ForeColor = Color.Red;
                    msgLabel.Text = msg;
                }

            }
            catch (SqlException sqlException)
            {
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text = "Database error.See details error: " + sqlException.Message;

            }
            catch (Exception exception)
            {
                msgLabel.ForeColor = Color.Red;
                string errorMessage = "Unknow error occured.";
                errorMessage += exception.Message;
                if (exception.InnerException != null)
                {
                    errorMessage += exception.InnerException.Message;
                }
                msgLabel.Text = errorMessage;
            }
        }