public ViewResult GetSubjectCGPA(string regNo)
 {
     int NoOfenrollCourse = 1;
     int noOfRemaningCourse = 0;
     float remaningCredit = 0;
     double TotalGpa = 0;
     ViewResult aViewResult = new ViewResult();
     List<ViewCourseGradeAndCredit> viewCourseGradeAndCreditList = new List<ViewCourseGradeAndCredit>();
     viewCourseGradeAndCreditList = GetCourseResult(regNo);
     foreach (ViewCourseGradeAndCredit viewCourseGradeAndCreditObj in viewCourseGradeAndCreditList)
     {
         aViewResult.SubjectCgpa = GradePointCalculator.GetPoint(viewCourseGradeAndCreditObj.GradeLetter) *
                            viewCourseGradeAndCreditObj.Credit;
         TotalGpa += aViewResult.SubjectCgpa;
         aViewResult.EnrolledCredit += viewCourseGradeAndCreditObj.Credit;
         aViewResult.NoOfEnrolledCourses += NoOfenrollCourse;
         NoOfenrollCourse++;
         if (viewCourseGradeAndCreditObj.GradeLetter == "F" || viewCourseGradeAndCreditObj.GradeLetter == "On Going..")
         {
             noOfRemaningCourse++;
             remaningCredit += viewCourseGradeAndCreditObj.Credit;
         }
     }
     aViewResult.Cgpa = GradePointCalculator.CGPA(TotalGpa, (aViewResult.EnrolledCredit - remaningCredit));
     aViewResult.GradeLetter = GradePointCalculator.GetGradeLetter(aViewResult.Cgpa);
     aViewResult.CompletedCredit = aViewResult.EnrolledCredit - remaningCredit;
     aViewResult.NoOfCompletedCourses = aViewResult.NoOfEnrolledCourses - noOfRemaningCourse;
     return aViewResult;
 }
        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;
            }
        }