public static string CheckRemarks(string Faculty, int StudentId, string Remarks) { if (Faculty != null || StudentId <= 0 || Remarks == null) { return(""); } string CheckedRemarks = ""; string[] Courses = Remarks.Split(','); foreach (string CourseCode in Courses) { Marks mark = new Marks().GetMark(Faculty, CourseCode, StudentId); if (mark != null) { float TotalMark = 0; if (mark.Mid != -1) { TotalMark += mark.Mid; } if (mark.Assignment != -1) { TotalMark += mark.Assignment; } if (mark.Attendence != -1) { TotalMark += mark.Attendence; } if (mark.Final != -1) { TotalMark += mark.Final; } if (!Marks.IsPassed(TotalMark)) { CheckedRemarks += CourseCode + ","; } } } if (CheckedRemarks != "") { CheckedRemarks = CheckedRemarks.Substring(0, CheckedRemarks.Length - 1); } return(CheckedRemarks); }
public static Boolean CalculateResult(List <StudentInfo> Students, int Semester, List <Course> Courses) { if (Students == null || Semester == 0 || Courses == null) { return(false); } ProjectDB db = new ProjectDB(); JavaScriptSerializer js = new JavaScriptSerializer(); foreach (StudentInfo Student in Students) { Result Result = new Result(); Result.Name = Student.Name; Result.StudentId = Student.StudentId; Result.RegNo = Student.Reg; Result.Faculty = Student.Faculty; Result.Session = Student.Session; Result.Semester = Semester; Result.Degree = ""; float TotalCHGP = 0, TotalCH = 0; string Remarks = ""; List <CourseResult> CourseResults = new List <CourseResult>(); foreach (Course Course in Courses) { Marks mark = new Marks().GetMark(Course.UnderFaculty, Course.Course_code, Student.StudentId); if (mark != null) { float TotalMark = 0; if (mark.Mid != -1) { TotalMark += mark.Mid; } if (mark.Assignment != -1) { TotalMark += mark.Assignment; } if (mark.Attendence != -1) { TotalMark += mark.Attendence; } if (mark.Final != -1) { TotalMark += mark.Final; } CourseResult CourseResult = new CourseResult(); CourseResult.CourseCode = Course.Course_code; CourseResult.CourseTitle = Course.Course_title; CourseResult.CreditHours = Course.Credit_hour; CourseResult.TotalMark = TotalMark; CourseResult.LetterGrade = Marks.CalculateLetterGrade(TotalMark); float GP = Marks.WrapToFloatPoint3(Marks.CalculateGP(TotalMark)); CourseResult.GP = GP; Boolean IsPassed = Marks.IsPassed(TotalMark); CourseResult.IsPassed = IsPassed; CourseResults.Add(CourseResult); if (IsPassed) { TotalCHGP += (Course.Credit_hour * GP); TotalCH += Course.Credit_hour; } else { Remarks += Course.Course_code + ","; } } } float GPA = 0; if (CourseResults != null) { Result.CourseResults = js.Serialize(CourseResults); } if (TotalCHGP != 0 && TotalCH != 0) { GPA = Marks.WrapToFloatPoint3(TotalCHGP / TotalCH); } Result.GPA = GPA; if (Remarks != "") { Remarks = Remarks.Substring(0, Remarks.Length - 1); } if (Semester == 1) { Result.PrevCGPA = 0; Result.PrevCCH = 0; Result.CGPA = GPA; Result.CCH = TotalCH; Result.Remarks = Remarks; if (Remarks == "") { Result.IsMeritListed = true; } else { Result.IsMeritListed = false; } } else { int PrevSem = Semester - 1; Result PrevRes = db.FinalResults.Where(fr => fr.StudentId == Result.StudentId && fr.Semester == PrevSem).FirstOrDefault(); if (PrevRes != null) { Result.PrevCGPA = PrevRes.CGPA; Result.PrevCCH = PrevRes.CCH; Result.CGPA = Marks.WrapToFloatPoint3(Marks.CalculateCGPA(GPA, TotalCH, PrevRes.CGPA, PrevRes.CCH)); Result.CCH = TotalCH + PrevRes.CCH; if (PrevRes.Remarks == "") { Result.Remarks = Remarks; } else { string PrevRemarks = Course.CheckRemarks(Student.Faculty, Student.StudentId, PrevRes.Remarks); if (Remarks != "") { if (PrevRemarks != "" || PrevRemarks != null) { Result.Remarks = PrevRes.Remarks + "," + Remarks; } else { Result.Remarks = Remarks; } } else { Result.Remarks = PrevRes.Remarks; } } if (!PrevRes.IsMeritListed) { Result.IsMeritListed = false; } else { if (Remarks == "") { Result.IsMeritListed = true; } else { Result.IsMeritListed = false; } } } } Result OldRes = db.FinalResults.Where(fr => fr.StudentId == Result.StudentId && fr.Semester == Semester).FirstOrDefault(); if (OldRes != null) { db.FinalResults.Remove(OldRes); } db.FinalResults.Add(Result); db.SaveChanges(); } return(true); }