/// <summary> /// Lấy thời gian rảnh trong ngày. /// Tính cả constrains giáo viên, dùng khi đổi time của session /// </summary> /// <param name="RollCallID"></param> /// <param name="FromDate"></param> /// <param name="ToDate"></param> /// <returns></returns> public List <TimeSpan> FindAvaibleSessionTime(int RollCallID, DateTime SelectedDate) { RollCallBusiness RollBO = new RollCallBusiness(this.RollSystemDB); var rollCall = RollBO.GetRollCallByID(RollCallID); //Tao 1 danh sach cac thoi gian rarnh List <TimeSpan> TimeList = AllAvailableTime(rollCall.Subject.NumberOfSlot); //Loai tiep nhung slot trong khoang thoi gian dc chon foreach (var Session in rollCall.Class.StudySessions. Where(ss => ss.SessionDate == SelectedDate)) { foreach (var Time in TimeList.ToList()) { if (Time >= Session.StartTime && Time <= Session.EndTime) { TimeList.Remove(Time); } } } foreach (var Session in rollCall.Instructor.StudySessions. Where(ss => ss.SessionDate == SelectedDate)) { foreach (var Time in TimeList.ToList()) { if (Time >= Session.StartTime && Time <= Session.EndTime) { TimeList.Remove(Time); } } } return(TimeList); }
public void FillAbsentAttendance(int RollCallID) { RollCallBusiness RollBO = new RollCallBusiness(this.RollSystemDB); var rollCall = RollBO.GetRollCallByID(RollCallID); //Tim nhung study session trong qua khu, chua co log var PassStudySessions = rollCall.StudySessions.Where(ses => ses.SessionDate < DateTime.Today && !rollCall.AttendanceLogs.Any(log => log.LogDate == ses.SessionDate)).ToList(); //Bat dau ghi log absent toan bo foreach (var PassStudySession in PassStudySessions) { AttendanceLog Log = new AttendanceLog() { RollCallID = RollCallID, LogDate = PassStudySession.GetOriginalDate(), TypeID = 1 }; foreach (var Student in rollCall.Students) { StudentAttendance Attendance = new StudentAttendance() { StudentID = Student.StudentID, IsPresent = false }; Log.StudentAttendances.Add(Attendance); } Insert(Log); } }
public List <Instructor> GetInstructorOfRollCall(int RollCallID) { RollCallBusiness RollBO = new RollCallBusiness(); var rollCall = RollBO.GetRollCallByID(RollCallID); return(rollCall.Subject.SubjectType.Instructors.ToList()); }
public void CreateFailStudentReport(int id, String FileName) { //Tao 1 roll call book rong ExcelPackage Package = new ExcelPackage(); ExcelWorksheet GeneralWorksheet = CreateGeneralWorksheet(id); Package.Workbook.Worksheets.Add(GeneralWorksheet.Name, GeneralWorksheet); RollCallBusiness rc = new RollCallBusiness(); SubjectBusiness sub = new SubjectBusiness(); List<RollCall> rollcalls = new List<RollCall>(); rollcalls = rc.GetList().Where(r => r.SemesterID == id).ToList(); List<Subject> subjectlist = new List<Subject>(); List<int> subj = new List<int>(); foreach (var rollcall in rollcalls) { AttendanceBusiness BO = new AttendanceBusiness(); var AttendanceLogs = BO.GetRollCallAttendanceLog(rollcall.RollCallID); int NumberOfSlot = rollcall.StudySessions.Count; var Students = rollcall.Students; for (int i = 0; i < Students.Count; i++) { int RowIndex = 7 + i; Student CurrentStudent = Students.ElementAt(i); double AbsentSession = CurrentStudent. StudentAttendances.Count(sa => AttendanceLogs.Select(a => a.LogID) .Contains(sa.AttendanceLog.LogID) && !sa.IsPresent); double AbsentRate = AbsentSession / NumberOfSlot * 100; //Neu nghi qua 20% if (AbsentRate > 20) { bool checkfailsubject = subj.Exists(r => r == rollcall.SubjectID); if (!checkfailsubject) { subj.Add(rollcall.SubjectID); var subject = sub.GetSubjectByID(rollcall.SubjectID); subjectlist.Add(subject); } } } } foreach (var subject in subjectlist) { //Tao detail sheet ExcelWorksheet RollWorkSheet = CreateDetailWorksheet(subject.SubjectID, id); Package.Workbook.Worksheets.Add(RollWorkSheet.Name, RollWorkSheet); } ExcelWriter.WriteExcelFile(Package, FileName); Package.Dispose(); }
public List <String> ValidRollCall(RollCall InRollCall, TimeSpan?otherTime) { SubjectBusiness SubBO = new SubjectBusiness(this.RollSystemDB); ClassBusiness ClassBO = new ClassBusiness(this.RollSystemDB); RollCallBusiness RcBO = new RollCallBusiness(this.RollSystemDB); List <string> ErrorList = new List <string>(); //var rollSubject = SubBO.GetSubjectByID(InRollCall.SubjectID); ////Check may cai nhu gio hoc, giao vien dang day v...v trong nay //if ((InRollCall.StartTime.ToString(@"hh\:mm") == "10:30" // || InRollCall.StartTime.ToString(@"hh\:mm") == "16:00") && //rollSubject.NumberOfSlot == 2) //{ // ErrorList.Add("Mon nay 2 slot, gio nay ko phu hop"); //} ////Check thu xem class cua roll call nay co dang hoc roll call nao ko //List<RollCall> ClassRcList = RcBO.GetList().Where(r => r.ClassID == InRollCall.ClassID).ToList(); //Boolean Classflag = true; //foreach (var item in ClassRcList) //{ // if (otherTime.ToString() != "") // { // InRollCall.StartTime = TimeSpan.Parse(otherTime.ToString()); // } // if (item.StartTime == InRollCall.StartTime && item.BeginDate <= InRollCall.BeginDate && InRollCall.BeginDate <= item.EndDate) // { // Classflag = false; // } //} //if (Classflag == false) //{ // ErrorList.Add("class"); //} //Check xem giao vien roll call nay co dang day roll call nao cung gio ko Boolean Insflag = true; List <RollCall> InsRcList = RcBO.GetList().Where(r => r.InstructorID == InRollCall.InstructorID).ToList(); foreach (var item in InsRcList) { if (item.StartTime == otherTime && item.BeginDate < InRollCall.BeginDate && InRollCall.BeginDate < item.EndDate) { Insflag = false; } } if (Insflag == false) { ErrorList.Add("instructor"); } //Nho check luon, start date va end date cua roll call so voi semester return(ErrorList); }
public void ChangeInstructor(int RollCallID, int InstructorID, String Note, DateTime FromDate, DateTime ToDate) { RollCallBusiness RollBO = new RollCallBusiness(this.RollSystemDB); var rollCall = RollBO.GetRollCallByID(RollCallID); int OldInstructorID = 0; foreach (var StudySession in rollCall.StudySessions.ToList()) { if (StudySession.SessionDate >= FromDate && StudySession.SessionDate <= ToDate) { OldInstructorID = StudySession.InstructorID; StudySession.InstructorID = InstructorID; StudySession.SetNote(Note); base.Detach(StudySession); base.Update(StudySession); } } }
public double GetStudentAbsentRate(int StudentID, int RollCallID) { //Dung nhieu nen phai de trong private if (RollBO == null || StuBO == null) { RollBO = new RollCallBusiness(RollSystemDB); StuBO = new StudentBusiness(RollSystemDB); } var AttendanceLogs = GetRollCallAttendanceLog(RollCallID); var Student = StuBO.GetStudentByID(StudentID); var RollCall = RollBO.GetRollCallByID(RollCallID); int NumberOfSlot = RollCall.StudySessions.Count; double AbsentSession = Student.StudentAttendances.Count(sa => AttendanceLogs.Select(rc => rc.LogID) .Contains(sa.AttendanceLog.LogID) && !sa.IsPresent); double AbsentRate = AbsentSession / NumberOfSlot * 100; return(AbsentRate); }
private static FaceRecognizer CreateRollCallRecognizer(int RollCallID) { //Tu rollcall ID, tao face recognizer, train //FaceRecognizer FaceRec = new LBPHFaceRecognizer(1, 8, 8, 8, 75); FaceRecognizer FaceRec = new FisherFaceRecognizer(80, RECOGNIZER_THREEHOLD); List <int> StudentIDs = new List <int>(); List <Image <Gray, byte> > StudentImages = new List <Image <Gray, byte> >(); RollCallBusiness RollBO = new RollCallBusiness(); //Load danh sach student cua roll call RollCall RollCall = RollBO.GetRollCallByID(RollCallID); foreach (var Student in RollCall.Students) { foreach (var Image in Student.StudentImages) { try { //Load ID va anh de train cho bo recognizer String TrainingImagePath = TRAINING_FOLDER_PATH + "/" + Image.ImageLink; Image <Gray, byte> TrainingImage = new Image <Gray, byte>(TrainingImagePath); StudentIDs.Add(Image.StudentID); TrainingImage._EqualizeHist(); StudentImages.Add(TrainingImage); } catch { } } } if (StudentImages.Count == 0 || StudentIDs.Count == 0) { return(null); } FaceRec.Train(StudentImages.ToArray(), StudentIDs.ToArray()); return(FaceRec); }
public List <Event> GetCalendarEvent(int InstructorID) { RollCallBusiness RollBO = new RollCallBusiness(); var CurrentRollCall = RollBO.GetInstructorFutureRollCalls(InstructorID); var TotalCompliation = new List <Event>(); foreach (RollCall rollCall in CurrentRollCall) { var TimeAndClass = rollCall.StudySessions.Where(ss => ss.InstructorID == InstructorID).Select(s => new Event() { id = s.SessionID + "", title = s.StartTime.ToString(@"hh\:mm") + " - " + s.EndTime.ToString(@"hh\:mm") + "\n" + s.Class.ClassName + " - " + rollCall.Subject.ShortName, StartDate = s.SessionDate.Add(s.StartTime), EndDate = s.SessionDate.Add(s.EndTime), start = s.SessionDate.ToString("yyyy-MM-dd") + " " + s.StartTime.ToString(@"hh\:mm"), end = s.SessionDate.ToString("yyyy-MM-dd") + " " + s.EndTime.ToString(@"hh\:mm") }); TotalCompliation.AddRange(TimeAndClass.ToList()); } return(TotalCompliation); }
public List <AttendanceLog> GetRollCallAttendanceLog(int RollCallID) { //Lay roll call ra if (RollBO == null) { RollBO = new RollCallBusiness(this.RollSystemDB); } RollCall RollCall = RollBO.GetRollCallByID(RollCallID); //Fill lai gia tri nhung ngay trong qua khu FillAbsentAttendance(RollCallID); //Lay cac ngay trong roll call var Dates = RollCall.AttendanceLogs.OrderBy(roll => roll.LogDate).Select(roll => roll.LogDate).Distinct(); List <AttendanceLog> AttendanceLogs = new List <AttendanceLog>(); foreach (DateTime Date in Dates) { AttendanceLog Log = GetAttendanceLogAtDate(RollCall.RollCallID, Date); AttendanceLogs.Add(Log); } return(AttendanceLogs); }
public bool Insert(StudySession Session) { RollCallBusiness RollBO = new RollCallBusiness(); var rollCall = RollBO.GetRollCallByID(Session.RollCallID); int NumberOfSlot = rollCall.Subject.NumberOfSlot; //Set thoi gian Session.EndTime = Session.StartTime. Add(TimeSpan.FromMinutes(90 * NumberOfSlot)). Add(TimeSpan.FromMinutes(15 * (NumberOfSlot - 1))); var SameTimeSessions = base.GetList().Where( s => (Session.StartTime >= s.StartTime && Session.StartTime <= s.EndTime) || (Session.EndTime >= s.StartTime && Session.EndTime <= s.EndTime)). Where(s => Session.SessionDate == s.SessionDate && Session.SessionID != s.SessionID); var SameTimeSesion = SameTimeSessions.FirstOrDefault(s => s.InstructorID == Session.InstructorID); //Xet tiep xem gio doi co trung. (Xet trung gio, trung giao vien hoac trung lop if (SameTimeSesion != null) { //Bao la giao vien da day String Request = String.Format("Request: {0} teach class {1} at {2} - {3} on {4}", Session.Instructor.Fullname, Session.Class.ClassName, Session.StartTime.ToString(@"hh\:mm"), Session.EndTime.ToString(@"hh\:mm"), Session.SessionDate.ToString("dd-MM-yyyy")); String Error = String.Format("Error: Instructor {0} is teaching class {1} at {2} - {3} on {4}.", SameTimeSesion.Instructor.Fullname, SameTimeSesion.Class.ClassName, SameTimeSesion.StartTime.ToString(@"hh\:mm"), SameTimeSesion.EndTime.ToString(@"hh\:mm"), SameTimeSesion.SessionDate.ToString("dd-MM-yyyy")); throw new Exception(Request + "\n" + Error); } else { SameTimeSesion = SameTimeSessions.FirstOrDefault(s => s.ClassID == Session.ClassID); if (SameTimeSesion != null) { String Request = String.Format("Request: Class {0} learn {1} at {2} - {3} on {4}", Session.Class.ClassName, Session.RollCall.Subject.FullName, Session.StartTime.ToString(@"hh\:mm"), Session.EndTime.ToString(@"hh\:mm"), Session.SessionDate.ToString("dd-MM-yyyy")); //Bao la lop nay da hoc String Error = String.Format("Error: Class {0} is learning {1} at {2} - {3} on {4}", SameTimeSesion.Class.ClassName, SameTimeSesion.RollCall.Subject.FullName, SameTimeSesion.StartTime.ToString(@"hh\:mm"), SameTimeSesion.EndTime.ToString(@"hh\:mm"), SameTimeSesion.SessionDate.ToString("dd-MM-yyyy")); throw new Exception(Request + "\n" + Error); } else { return(base.Insert(Session)); } } }
private ExcelWorksheet CreateDetailWorksheet(int subjectID, int semesterID) { SubjectBusiness SuBO = new SubjectBusiness(); SemesterBusiness sem = new SemesterBusiness(); //get value semester, student, subject String semestername = sem.GetSemesterByID(semesterID).SemesterName; String subjectname = SuBO.GetSubjectByID(subjectID).FullName; String subshortname = SuBO.GetSubjectByID(subjectID).ShortName; ExcelWorksheet DetailWorkSheet = new ExcelPackage().Workbook.Worksheets.Add(subshortname + "_" + semestername); // get student list absent > 20% RollCallBusiness RoBO = new RollCallBusiness(); AttendanceBusiness BO = new AttendanceBusiness(); List<Student> students = new List<Student>(); List<RollCall> rollcalls = RoBO.GetList().Where(r => r.SubjectID == subjectID && r.SemesterID == semesterID).ToList(); List<int> studentID = new List<int>(); foreach (var rollcall in rollcalls) { var AttendanceLogs = BO.GetRollCallAttendanceLog(rollcall.RollCallID); int NumberOfSlot = rollcall.StudySessions.Count; var Students = rollcall.Students; for (int i = 0; i < Students.Count; i++) { int RowIndex = 7 + i; Student CurrentStudent = Students.ElementAt(i); double AbsentSession = CurrentStudent. StudentAttendances.Count(sa => AttendanceLogs.Select(a => a.LogID) .Contains(sa.AttendanceLog.LogID) && !sa.IsPresent); double AbsentRate = AbsentSession / NumberOfSlot * 100; //Neu nghi qua 20% if (AbsentRate > 20) { // check student is exist in list bool checkstuexit = studentID.Exists(r => r == CurrentStudent.StudentID); if (!checkstuexit) { studentID.Add(CurrentStudent.StudentID); students.Add(CurrentStudent); } } } } //write file DetailWorkSheet.Cells["A:XFD"].Style.Font.Name = "Arial"; DetailWorkSheet.Cells["C2"].Value = "List of student unqualified for examination report"; DetailWorkSheet.Cells["C2"].Style.Font.Size = 18; DetailWorkSheet.Cells["C2"].Style.Font.Bold = true; //semester detail DetailWorkSheet.Cells["C3"].Value = "Semester"; DetailWorkSheet.Cells["C4"].Value = "Subject"; DetailWorkSheet.Cells["C3:C4"].Style.Font.Size = 12; DetailWorkSheet.Cells["C3:C4"].Style.Font.Bold = true; DetailWorkSheet.Cells["D3"].Value = semestername; DetailWorkSheet.Cells["D4"].Value = subjectname; //title table DetailWorkSheet.Cells["B6"].Value = "No."; DetailWorkSheet.Cells["C6"].Value = "Student Name"; DetailWorkSheet.Cells["D6"].Value = "Student Code"; DetailWorkSheet.Cells["E6"].Value = "Class"; DetailWorkSheet.Cells["B6:E6"].Style.Font.Size = 12; DetailWorkSheet.Cells["B6:E6"].Style.Font.Bold = true; //body table var studentlist = students; for (int i = 0; i < studentlist.Count(); i++) { int RowIndex = 7 + i; DetailWorkSheet.Cells["B" + RowIndex].Value = i + 1; DetailWorkSheet.Cells["C" + RowIndex].Value = studentlist.ElementAt(i).FullName; DetailWorkSheet.Cells["D" + RowIndex].Value = studentlist.ElementAt(i).StudentCode; DetailWorkSheet.Cells["E" + RowIndex].Value = studentlist.ElementAt(i).Class.ClassName; } //set border table for (int column = 2; column <= 5; column++) { for (int row = 6; row <= 6 + studentlist.Count(); row++) { DetailWorkSheet.Cells[row, column].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); } } //set height , width DetailWorkSheet.Cells["C2:D2"].Merge = true; DetailWorkSheet.Cells["C2:D2"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; DetailWorkSheet.Column(2).Width = 5; DetailWorkSheet.Column(3).Width = 25; DetailWorkSheet.Column(4).Width = 60; DetailWorkSheet.Column(5).Width = 12; return DetailWorkSheet; }
private ExcelWorksheet CreateGeneralWorksheet(int id) { ExcelWorksheet GeneralWorksheet = new ExcelPackage().Workbook.Worksheets.Add("General Report"); GeneralWorksheet.Cells["A:XFD"].Style.Font.Name = "Arial"; GeneralWorksheet.Cells["C2"].Value = "List of student unqualified for examination report"; GeneralWorksheet.Cells["C2"].Style.Font.Size = 18; GeneralWorksheet.Cells["C2"].Style.Font.Bold = true; //get value semester, student, subject SemesterBusiness sem = new SemesterBusiness(); SubjectBusiness sub = new SubjectBusiness(); String semestername = sem.GetSemesterByID(id).SemesterName; String begindate = sem.GetSemesterByID(id).BeginDate.ToString("dd-MM-yyyy"); String enddate = sem.GetSemesterByID(id).EndDate.ToString("dd-MM-yyyy"); RollCallBusiness rc = new RollCallBusiness(); List<RollCall> rollcalls = new List<RollCall>(); int numsub = 0; int numstu = 0; int numfstu = 0; rollcalls = rc.GetList().Where(r => r.SemesterID == id).ToList(); List<int> subid = new List<int>(); List<int> stuid = new List<int>(); List<int> fstuid = new List<int>(); // list num student absent for each subject List<int> numabsent = new List<int>(); // list check subject list have student relearn. List<int> subj = new List<int>(); List<Subject> subjectlist = new List<Subject>(); foreach (var rollcall in rollcalls) { // check subject is exit in list bool checksub = subid.Exists(r => r == rollcall.SubjectID); if (!checksub) { subid.Add(rollcall.SubjectID); numsub++; } List<Student> students = new List<Student>(); students = rollcall.Students.ToList(); foreach (var student in students) { bool checkstu = stuid.Exists(r => r == student.StudentID); if (!checkstu) { stuid.Add(student.StudentID); numstu++; } } AttendanceBusiness BO = new AttendanceBusiness(); var AttendanceLogs = BO.GetRollCallAttendanceLog(rollcall.RollCallID); int NumberOfSlot = rollcall.StudySessions.Count; var Students = rollcall.Students; for (int i = 0; i < Students.Count; i++) { int RowIndex = 7 + i; Student CurrentStudent = Students.ElementAt(i); double AbsentSession = CurrentStudent. StudentAttendances.Count(sa => AttendanceLogs.Select(a => a.LogID) .Contains(sa.AttendanceLog.LogID) && !sa.IsPresent); double AbsentRate = AbsentSession / NumberOfSlot * 100; //Neu nghi qua 20% if (AbsentRate > 20) { bool checkfstu = fstuid.Exists(r => r == CurrentStudent.StudentID); if (!checkfstu) { fstuid.Add(CurrentStudent.StudentID); numfstu++; } bool checkfailsubject = subj.Exists(r => r == rollcall.SubjectID); if (!checkfailsubject) { subj.Add(rollcall.SubjectID); var subject = sub.GetSubjectByID(rollcall.SubjectID); subjectlist.Add(subject); } numabsent.Add(rollcall.SubjectID); } } } //write file GeneralWorksheet.Cells["C2:D2"].Merge = true; GeneralWorksheet.Cells["C2:D2"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; GeneralWorksheet.Cells["C3"].Value = "Semester "; GeneralWorksheet.Cells["C4"].Value = "Time "; GeneralWorksheet.Cells["C5"].Value = "Total subjects"; GeneralWorksheet.Cells["C6"].Value = "Total students"; GeneralWorksheet.Cells["C7"].Value = "Total students unqualified for examination"; GeneralWorksheet.Cells["C3:C7"].Style.Font.Size = 12; GeneralWorksheet.Cells["C3:C7"].Style.Font.Bold = true; GeneralWorksheet.Cells["D3"].Value = semestername; GeneralWorksheet.Cells["D4"].Value = "From " + begindate + " to " + enddate; GeneralWorksheet.Cells["D5"].Value = numsub; GeneralWorksheet.Cells["D6"].Value = numstu; GeneralWorksheet.Cells["D7"].Value = numfstu; GeneralWorksheet.Cells["B9"].Value = "No."; GeneralWorksheet.Cells["C9"].Value = "Subject"; GeneralWorksheet.Cells["D9"].Value = "Number of students unqualified for examination"; GeneralWorksheet.Cells["B9:D9"].Style.Font.Size = 12; GeneralWorksheet.Cells["B9:D9"].Style.Font.Bold = true; var subjects = subjectlist; for (int i = 0; i < subjects.Count(); i++) { int RowIndex = 10 + i; GeneralWorksheet.Cells["B" + RowIndex].Value = i + 1; GeneralWorksheet.Cells["C" + RowIndex].Value = subjects.ElementAt(i).FullName; GeneralWorksheet.Cells["D" + RowIndex].Value = numabsent.Count(r => r == subjects.ElementAt(i).SubjectID); } //set border table for (int column = 2; column <= 4; column++) { for (int row = 9; row <= 9 + subjects.Count(); row++) { GeneralWorksheet.Cells[row, column].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); } } //set height , width GeneralWorksheet.Cells["C2:D2"].Merge = true; GeneralWorksheet.Cells["C2:D2"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; GeneralWorksheet.Column(2).Width = 8; GeneralWorksheet.Column(3).Width = 47; GeneralWorksheet.Column(4).Width = 53; return GeneralWorksheet; }
public AttendanceLog WriteAttendanceAutoLog(int RollCallID, List <RecognizerResult> RecognizerResults) { if (RecognizerResults.Count == 0) { return(null); } //Tim xem da co log auto cho hom nay chua AttendanceLog Log = GetAttendanceLogAtDate(RollCallID, DateTime.Today, 1); bool LogExist = true; if (Log == null) { Log = new AttendanceLog() { RollCallID = RollCallID, LogDate = DateTime.Today, TypeID = 1 }; LogExist = false; } //Dua danh sach nhan vao, loc ra ID nhung sinh vien co mat HashSet <int> StudentIDs = new HashSet <int>(); foreach (var result in RecognizerResults) { foreach (var face in result.FaceList) { //ID phai khac -1, moi tinh la nhan duoc if (face.StudentID != -1) { StudentIDs.Add(face.StudentID); } } //Save hinh cho log, neu hinh da trung thi ko save if (!Log.LogImages.Any(image => image.ImageLink.Equals(result.ImageLink))) { LogImage LogImg = new LogImage() { ImageLink = result.ImageLink }; Log.LogImages.Add(LogImg); } } //Lay toan bo student cua roll call RollCallBusiness RollBO = new RollCallBusiness(this.RollSystemDB); RollCall rollCall = RollBO.GetRollCallByID(RollCallID); List <int> RollCallStudentIDs = rollCall.Students.Select(s => s.StudentID).ToList(); foreach (int StudentID in RollCallStudentIDs) { //Neu student chua co trong log thi add vao if (!Log.StudentAttendances.Any(attendace => attendace.StudentID == StudentID)) { StudentAttendance Attendance = new StudentAttendance() { StudentID = StudentID, }; //Xem co ten trong list cac id da nhan dc hay ko if (StudentIDs.Contains(StudentID)) { Attendance.IsPresent = true; } else { Attendance.IsPresent = false; } Log.StudentAttendances.Add(Attendance); } else { StudentAttendance Attendance = Log.StudentAttendances.SingleOrDefault(attendance => attendance.StudentID == StudentID); if (StudentIDs.Contains(StudentID)) { Attendance.IsPresent = true; } //Ko chuyen tu true sang false, vi moi lan diem danh co the thieu nguoi } } //Neu log chua co thi them vao, da co thi edit lai if (LogExist) { Update(Log); } else { Insert(Log); } //Tra Log ra de show return(Log); }
private ExcelWorksheet CreateDetailWorksheet(int StudentID, int RollCallID) { RollCallBusiness RollBO = new RollCallBusiness(); var rollCall = RollBO.GetRollCallByID(RollCallID); StudentBusiness StuBO = new StudentBusiness(); var student = StuBO.GetStudentByID(StudentID); AttendanceBusiness AttenBO = new AttendanceBusiness(); List <AttendanceLog> RollCallLogs = AttenBO.GetRollCallAttendanceLog(RollCallID); var StudentAttendances = student.StudentAttendances.Where(sa => sa.AttendanceLog.RollCallID == RollCallID && RollCallLogs.Select(r => r.LogID).Contains(sa.LogID)) .OrderBy(sa => sa.AttendanceLog.LogDate).ToList(); ExcelWorksheet DetailWorkSheet = new ExcelPackage(). Workbook.Worksheets.Add(rollCall.Subject.ShortName + "_" + rollCall.BeginDate.ToString("dd-MM-yyyy")); int Absent = StudentAttendances.Count(sa => !sa.IsPresent); double AbsentRate = (double)Absent / rollCall.StudySessions.Count * 100; DetailWorkSheet.Cells["A:XFD"].Style.Font.Name = "Arial"; DetailWorkSheet.Cells["C2"].Value = "Attendance Report Detail"; DetailWorkSheet.Cells["C2"].Style.Font.Size = 18; DetailWorkSheet.Cells["C2"].Style.Font.Bold = true; //student detail DetailWorkSheet.Cells["C3"].Value = "Subject"; DetailWorkSheet.Cells["C4"].Value = "Date"; DetailWorkSheet.Cells["C5"].Value = "Instructor"; DetailWorkSheet.Cells["C6"].Value = "Total Session"; DetailWorkSheet.Cells["C7"].Value = "Completed Session"; DetailWorkSheet.Cells["C8"].Value = "Absent"; DetailWorkSheet.Cells["C9"].Value = "Absent Rate"; DetailWorkSheet.Cells["C3:C9"].Style.Font.Size = 12; DetailWorkSheet.Cells["C3:C9"].Style.Font.Bold = true; DetailWorkSheet.Cells["D3"].Value = rollCall.Subject.FullName; DetailWorkSheet.Cells["D4"].Value = "From " + rollCall.BeginDate.ToString("dd-MM-yyyy") + " to " + rollCall.EndDate.ToString("dd-MM-yyyy"); DetailWorkSheet.Cells["D5"].Value = rollCall.Instructor.Fullname; DetailWorkSheet.Cells["D6"].Value = rollCall.Subject.NumberOfSession; DetailWorkSheet.Cells["D7"].Value = StudentAttendances.Count(); DetailWorkSheet.Cells["D8"].Value = Absent; DetailWorkSheet.Cells["D9"].Value = String.Format("{0:0}%", AbsentRate); DetailWorkSheet.Cells["D6:D9"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; //title table DetailWorkSheet.Cells["B11"].Value = "No."; DetailWorkSheet.Cells["C11"].Value = "Date"; DetailWorkSheet.Cells["D11"].Value = "Present"; DetailWorkSheet.Cells["E11"].Value = "Note"; DetailWorkSheet.Cells["B11:E11"].Style.Font.Size = 12; DetailWorkSheet.Cells["B11:E11"].Style.Font.Bold = true; for (int i = 0; i < StudentAttendances.Count(); i++) { int RowIndex = 12 + i; DetailWorkSheet.Cells["B" + RowIndex].Value = i + 1; DetailWorkSheet.Cells["C" + RowIndex].Value = StudentAttendances.ElementAt(i).AttendanceLog.LogDate.ToString("dd-MM-yyyy"); if (StudentAttendances.ElementAt(i).IsPresent) { DetailWorkSheet.Cells["D" + RowIndex].Value = "Present"; } else { DetailWorkSheet.Cells["D" + RowIndex].Value = "Absent"; DetailWorkSheet.Cells["D" + RowIndex].Style.Font.Bold = true; } DetailWorkSheet.Cells["E" + RowIndex].Value = StudentAttendances.ElementAt(i).Note; } //set border table for (int column = 2; column <= 5; column++) { for (int row = 11; row <= 11 + StudentAttendances.Count(); row++) { DetailWorkSheet.Cells[row, column].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black); } } //set height , width DetailWorkSheet.Cells["C2:D2"].Merge = true; DetailWorkSheet.Cells["C2:D2"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; DetailWorkSheet.Column(2).Width = 5; DetailWorkSheet.Column(3).Width = 30; DetailWorkSheet.Column(4).Width = 30; DetailWorkSheet.Column(5).Width = 20; return(DetailWorkSheet); }