public static void AddCourseStatus(string CourseCode, string Session, Boolean Status)
        {
            ProjectDB db     = new ProjectDB();
            Course    Course = db.Courses.Where(dp => dp.Course_code == CourseCode).FirstOrDefault();

            if (Course == null)
            {
                return;
            }

            CourseStatus OldCourseStatus = db.CourseStatus.Where(dp => dp.Course_code == Course.Course_code && dp.UnderSession == Session).FirstOrDefault();

            if (OldCourseStatus != null)
            {
                return;
            }

            CourseStatus CourseStatus = new CourseStatus();

            CourseStatus.Course_code             = Course.Course_code;
            CourseStatus.Course_title            = Course.Course_title;
            CourseStatus.Credit_hour             = Course.Credit_hour;
            CourseStatus.Semester                = Course.Semester;
            CourseStatus.UnderFaculty            = Course.UnderFaculty;
            CourseStatus.UnderDepartment         = Course.UnderDepartment;
            CourseStatus.CourseTeacherID         = Course.CourseTeacherID;
            CourseStatus.CourseTeacherName       = Course.CourseTeacherName;
            CourseStatus.CourseTeacherDepartment = Course.CourseTeacherDepartment;
            CourseStatus.CourseTeacherFaculty    = Course.CourseTeacherFaculty;
            CourseStatus.UnderSession            = Session;
            CourseStatus.Status = Status;

            db.CourseStatus.Add(CourseStatus);
            db.SaveChanges();
        }
        public static Boolean UpdateCourseStatus(string CourseCode, string Session, Boolean Status)
        {
            ProjectDB    db           = new ProjectDB();
            CourseStatus CourseStatus = db.CourseStatus.Where(dp => dp.Course_code == CourseCode && dp.UnderSession == Session).FirstOrDefault();

            if (CourseStatus == null)
            {
                return(false);
            }

            CourseStatus.Status          = Status;
            db.Entry(CourseStatus).State = EntityState.Modified;
            db.SaveChanges();

            return(true);
        }
Пример #3
0
        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);
        }