public ActionResult Create(RollCall rollcall, int MajorID, int ClassID, TimeSpan?otherTime, String begindate)
        {
            List <string> ErrorList = RollBO.ValidRollCall(rollcall, otherTime);

            if (ErrorList.Count == 0)
            {
                if (otherTime.ToString() != "")
                {
                    rollcall.StartTime = TimeSpan.Parse(otherTime.ToString());
                }
                String[] tmp = begindate.Split('-');
                String   bgd = tmp[1] + "-" + tmp[0] + "-" + tmp[2];
                rollcall.BeginDate = Convert.ToDateTime(bgd);
                RollBO.Insert(rollcall);
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var Error in ErrorList)
                {
                    ModelState.AddModelError(String.Empty, Error);
                }
            }
            ViewBag.InstructorID = SlFactory.MakeSelectList <Instructor>("InstructorID", "FullName", rollcall.InstructorID);
            ViewBag.MajorID      = SlFactory.MakeSelectList <Major>("MajorID", "FullName", MajorID);
            ViewBag.ClassID      = new SelectList(ClaBO.GetClassByMajor(MajorID),
                                                  "ClassID", "ClassName", rollcall.ClassID);
            //Mac dinh, lay semester moi nhat
            List <Semester> semester = SeBO.GetList().Where(s => s.EndDate > DateTime.Now).ToList();

            ViewBag.SemesterID = semester;
            ViewBag.SubjectID  = new SelectList(SubBO.GetSubjectByMajor(MajorID), "SubjectID", "FullName", rollcall.SubjectID);
            return(View(rollcall));
        }
        public ActionResult Index_Home()
        {
            //Neu bam vao mon dang day, moi ra index
            //Tim instructor da dang nhạp vao

            string     Username             = this.HttpContext.User.Identity.Name;
            User       User                 = AccBO.GetUserByUsername(Username);
            Instructor AuthorizedInstructor = InsBO.GetInstructorByUserID(User.UserID);

            //Nhung mon ma instructor nay dang day, sau nay phai check status
            var RollCalls = RollBO.GetInstructorCurrentRollCalls(AuthorizedInstructor.InstructorID);

            //Mon dang day vao thoi diem dang nhap
            RollCall CurrentRollCall = null;
            TimeSpan CurrentTime     = DateTime.Now.TimeOfDay;

            if (RollCalls.Count() > 0)
            {
                CurrentRollCall = RollCalls.FirstOrDefault(r => r.StartTime <= CurrentTime && r.EndTime >= CurrentTime);
            }

            InstructorViewModel model = new InstructorViewModel();

            model.AuthorizedInstructor = AuthorizedInstructor;
            model.CurrentRollCall      = CurrentRollCall;
            model.TeachingRollCall     = RollCalls;
            return(View(model));
        }
        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)
                {
                    //Load ID va anh de train cho bo recognizer
                    StudentIDs.Add(Image.StudentID);
                    String             TrainingImagePath = TRAINING_FOLDER_PATH + "/" + Image.ImageLink;
                    Image <Gray, byte> TrainingImage     = new Image <Gray, byte>(TrainingImagePath);

                    TrainingImage._EqualizeHist();
                    StudentImages.Add(TrainingImage);
                }
            }

            FaceRec.Train(StudentImages.ToArray(), StudentIDs.ToArray());

            return(FaceRec);
        }
        public ActionResult Edit(RollCall rollcall, TimeSpan?otherTime)
        {
            if (ModelState.IsValid)
            {
                List <string> ErrorList = RollBO.ValidRollCall(rollcall, otherTime);
                if (ErrorList.Count == 0)
                {
                    // Kiem tra xem co doi giao vien hay ko
                    RollBO.Update(rollcall);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var Error in ErrorList)
                    {
                        ModelState.AddModelError(String.Empty, Error);
                    }
                }
            }
            var rollCall = RollBO.GetRollCallByID(rollcall.RollCallID);
            int MajorID  = rollCall.Class.MajorID;

            ViewBag.InstructorID = SlFactory.MakeSelectList <Instructor>("InstructorID", "FullName", rollcall.InstructorID);
            ViewBag.MajorID      = SlFactory.MakeSelectList <Major>("MajorID", "FullName", MajorID);
            ViewBag.ClassID      = new SelectList(ClaBO.GetClassByMajor(MajorID),
                                                  "ClassID", "ClassName", rollcall.ClassID);
            //Mac dinh, lay semester moi nhat
            ViewBag.SemesterID = SlFactory.MakeSelectList <Semester>("SemesterID", "SemesterName", rollcall.SemesterID);
            ViewBag.SubjectID  = new SelectList(SubBO.GetSubjectByMajor(MajorID), "SubjectID", "FullName", rollcall.SubjectID);
            ViewBag.Semester   = rollcall.SemesterID;
            ViewBag.Subject    = rollcall.SubjectID;
            return(View(rollcall));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            RollCall rollcall = RollBO.GetRollCallByID(id);

            RollBO.Delete(rollcall);
            return(RedirectToAction("Index"));
        }
Пример #6
0
        /// <summary>
        /// Мост
        /// </summary>
        public static void GoBridgeStartWar()
        {
            Platoon platoon = new Platoon("2СИ-15");

            platoon.AddSolder("Халилов ", "Старший стрелок");
            platoon.AddSolder("Одилов  ", "Гранатометчик");
            platoon.AddSolder("Шарков  ", "Помощник гранатометчика");
            platoon.AddSolder("Лепезин ", "Стрелок");
            platoon.AddSolder("Дадашев ", "Стрелок");
            platoon.AddSolder("Нагель  ", "Пулеметчик");
            platoon.AddSolder("Андрюков", "Снайпер");

            RollCall rollCall = new RollCall();

            Print(rollCall.Begin(platoon));

            Console.WriteLine("\nВзвод {0} готов к войне:\n", platoon.title);

            War war = new GoodConditions(new PlanA());

            Print(war.plan.Greeting);
            Print(war.Greeting);
            Print(war.Attack());
            Print(war.Respite());
            Print(war.BearALoss());
            war.plan = new PlanB();
            Print(war.plan.Greeting);
            Print(war.Greeting);
            Print(war.Respite());
            Print(war.Attack());
            Print(war.Report());

            Console.ReadKey();
        }
        public ActionResult GetCurrentRollCalls(int InstructorID)
        {
            //Nhung mon ma instructor nay dang day, sau nay phai check status, instructor teaching phai them ngay thang
            RollCallBusiness RollBO = new RollCallBusiness();

            var RollCalls = RollBO.GetInstructorCurrentRollCalls(InstructorID);
            //Mon dang day vao thoi diem dang nhap
            RollCall CurrentRollCall = null;
            TimeSpan CurrentTime     = DateTime.Now.TimeOfDay;

            if (RollCalls.Count() > 0)
            {
                CurrentRollCall = RollCalls.FirstOrDefault(r => r.StartTime <= CurrentTime && r.EndTime >= CurrentTime);
            }

            var RollCallJson = RollCalls.ToList().Select(r => new
            {
                rollID  = r.RollCallID,
                subject = r.Subject.FullName,
                classes = r.Class.ClassName,
                time    = r.StartTime.Equals(new TimeSpan(0, 0, 0)) ?
                          "No Slot" : r.StartTime.ToString(@"hh\:mm") + " - " + r.EndTime.ToString(@"hh\:mm"),
                date           = r.BeginDate.ToString("dd-MM-yyyy") + " to " + r.EndDate.ToString("dd-MM-yyyy"),
                isCurrent      = CurrentRollCall != null && CurrentRollCall == r ? true : false,
                attendanceDate = r.AttendanceDate().ToString("MM-dd-yyyy")
            });

            return(Json(RollCallJson, JsonRequestBehavior.AllowGet));
        }
        //remove student from studenrlist of the rollcall
        public ActionResult DeleteStudent(int RollCallID, int StudentID)
        {
            RollCall rollcall = RollBO.GetRollCallByID(RollCallID);
            var      Student  = rollcall.Students.Single(a => a.StudentID == StudentID);

            rollcall.Students.Remove(Student);
            RollBO.Update(rollcall);
            return(RedirectToAction("RollCallStudentList", new { RollCallID = RollCallID }));
        }
        public ActionResult GetRollCallInfo(int RollCallID)
        {
            RollCallBusiness RollBO   = new RollCallBusiness();
            RollCall         rollcall = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness AttenBO = new AttendanceBusiness();
            var AttendLog = AttenBO.GetRollCallAttendanceLog(RollCallID);

            var ReturnLog = AttendLog.Where(log => log.LogDate >= DateTime.Today.AddDays(-1)).ToList();//.OrderByDescending(log => log.LogDate);

            //Truong hop hom nay la thu 2
            if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
            {
                //Tim log thu 6 hoac thu 7
                DateTime LastSaturday    = DateTime.Today.AddDays(-2);
                var      LastSaturdayLog = AttendLog.FirstOrDefault(log => log.LogDate == LastSaturday);
                if (LastSaturdayLog != null)
                {
                    ReturnLog.Add(LastSaturdayLog);
                }
                else
                {
                    DateTime LastFriday    = DateTime.Today.AddDays(-3);
                    var      LastFridayLog = AttendLog.FirstOrDefault(log => log.LogDate == LastFriday);
                    if (LastFridayLog != null)
                    {
                        ReturnLog.Add(LastFridayLog);
                    }
                }
            }

            var RollJson = new
            {
                rollID  = rollcall.RollCallID,
                subject = rollcall.Subject.FullName,
                classes = rollcall.Class.ClassName,
                time    = rollcall.StartTime.ToString(@"hh\:mm") + " - " + rollcall.EndTime.ToString(@"hh\:mm"),
                date    = rollcall.BeginDate.ToString("dd-MM-yyyy") + " to " + rollcall.EndDate.ToString("dd-MM-yyyy"),

                studentList = rollcall.Students.Select(st => new
                {
                    studentID   = st.StudentID,
                    studentCode = st.StudentCode,
                    studentName = st.FullName,
                    percentRate = String.Format("{0:0.00}%", AttenBO.GetStudentAbsentRate(st.StudentID, RollCallID))
                }),
                logList = ReturnLog.OrderByDescending(log => log.LogDate).Select(log => new
                {
                    rollID     = log.RollCallID,
                    logID      = log.LogID,
                    logDate    = log.LogDate.ToString("dd-MM-yyyy"),
                    logPresent = log.StudentAttendances.Count(attend => attend.IsPresent) + "/" + log.RollCall.Students.Count,
                }),
            };

            return(Json(RollJson, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RollCall(int id)
        {
            RollCall RollCall = db.RollCalls.First(r => r.RollCallID == id);
            String   FileName = RollCall.Class.ClassName.Trim() + "_" + RollCall.Subject.ShortName
                                + "_" + DateTime.Today.ToString("dd-MM-yyyy") + ".xlsx";

            RollCallBusiness BO       = new RollCallBusiness();
            String           FilePath = Server.MapPath("~/Content/Temp/" + FileName);

            BO.CreateRollCallReport(id, FilePath);

            return(File(FilePath, ExcelMimeType, FileName));
        }
        //remove student from studenrlist of the rollcall
        public ActionResult AddStudent(int?RollCallID, String StudentID)
        {
            RollCall rollcall = RollBO.GetRollCallByID(RollCallID.Value);

            String[] tmp = StudentID.Split(',');
            for (int i = 0; i < tmp.Length; i++)
            {
                int test    = int.Parse(tmp[i]);
                var Student = StuBO.GetStudentByID(test);
                rollcall.Students.Add(Student);
                RollBO.Update(rollcall);
            }
            return(RedirectToAction("RollCallStudentList", new { RollCallID = RollCallID }));
        }
        public ActionResult GetStudySession(int id)
        {
            RollCall rollCall    = RollBO.GetRollCallByID(id);
            var      TimeAndName = rollCall.StudySessions.Select(s => new
            {
                id    = s.SessionID,
                title = s.StartTime.ToString(@"hh\:mm") + " - " + s.EndTime.ToString(@"hh\:mm") + "\n"
                        + "Ins:" + s.Instructor.Fullname,
                start = s.SessionDate.ToString("yyyy-MM-dd") + " " + s.StartTime.ToString(@"hh\:mm"),
                end   = s.SessionDate.ToString("yyyy-MM-dd") + " " + s.EndTime.ToString(@"hh\:mm"),
                note  = "abc"
            });

            return(Json(TimeAndName.ToList(), JsonRequestBehavior.AllowGet));
        }
Пример #13
0
        public void OnGet(string date, string placeOfEntry)
        {
            DateTime dt;

            if (date == null ||
                !DateTime.TryParse(date, out dt))
            {
                dt            = DateTime.Now.Date;
                this.RollCall = this._rollCallService.GetByEntryAndDate(placeOfEntry, dt);
            }
            else
            {
                this.RollCall = this._rollCallService.GetByEntryAndDate(placeOfEntry, dt.Date);
            }
        }
        public ActionResult RollCallDetail(int id)
        {
            RollCall RollCall = RollBO.GetRollCallByID(id);

            //Lay danh sach nhung log cua roll call nay, tu luc bat dau
            AttendanceBusiness   AttenBO        = new AttendanceBusiness();
            List <AttendanceLog> AttendanceLogs = AttenBO.GetRollCallAttendanceLog(id);

            RollCallDetailViewModel Model = new RollCallDetailViewModel();

            Model.RollCall     = RollCall;
            Model.RollCallLogs = AttendanceLogs;

            return(View(Model));
        }
        // GET: /RollCall/Details/5

        //view attendance roll call
        public ViewResult ViewAttendance(int RollCallID)
        {
            RollCall RollCall = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness AttendanceBO = new AttendanceBusiness();
            //Lay danh sach nhung log cua roll call nay, tu luc bat dau
            List <AttendanceLog> AttendanceLogs = AttendanceBO.GetRollCallAttendanceLog(RollCallID);


            RollCallDetailViewModel Model = new RollCallDetailViewModel();

            Model.RollCall     = RollCall;
            Model.RollCallLogs = AttendanceLogs;

            return(View(Model));
        }
        public ActionResult LogDetail(int RollCallID, DateTime Date)
        {
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            //1 ngay, 1 roll call co the co 2 loai log, log manual va auto, do do phai lay ca 2
            AttendanceLog AutoLog = AttenBO.GetAttendanceLogAtDate(RollCallID, Date, 1);

            AttendanceLog ManualLog = AttenBO.GetAttendanceLogAtDate(RollCallID, Date, 2);
            RollCall      RollCall  = RollBO.GetRollCallByID(RollCallID);

            LogDetailViewModel Model = new LogDetailViewModel();

            Model.RollCall  = RollCall;
            Model.AutoLog   = AutoLog;
            Model.ManualLog = ManualLog;
            return(PartialView("_LogDetail", Model));
        }
        public ActionResult ChangeSchedule(int id)
        {
            RollCall rollCall = RollBO.GetRollCallByID(id);

            //Fill lai gia tri nhung ngay trong qua khu
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            AttenBO.FillAbsentAttendance(id);


            ViewBag.RollCallID         = id;
            ViewBag.LastAttendanceDate = RollBO.LastAttendanceDate(id);

            //ViewBag.HasAttendance = RollBO.RollCallHasAttendance(id);


            return(View("RollCallSchedule", rollCall));
        }
Пример #18
0
        /// <summary>
        /// Итератор
        /// </summary>
        public static void GoIteratorPlatoonRollCall()
        {
            Platoon platoon = new Platoon("2СИ-15");

            platoon.AddSolder("Халилов ", "Старший стрелок");
            platoon.AddSolder("Одилов  ", "Гранатометчик");
            platoon.AddSolder("Шарков  ", "Помощник гранатометчика");
            platoon.AddSolder("Лепезин ", "Стрелок");
            platoon.AddSolder("Дадашев ", "Стрелок");
            platoon.AddSolder("Нагель  ", "Пулеметчик");
            platoon.AddSolder("Андрюков", "Снайпер");

            RollCall rollCall = new RollCall();

            Print(rollCall.Begin(platoon));

            Console.ReadKey();
        }
        public ActionResult CheckAttendanceAuto(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles)
        {
            RollCall rollCall = RollBO.GetRollCallByID(RollCallID);

            List <String> ImagePaths = new List <string>();

            foreach (HttpPostedFileBase file in ImageFiles)
            {
                //Save file anh xuong
                String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName);
                file.SaveAs(OldPath);

                //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop
                String NewPath = Server.MapPath("~/Content/Log/"
                                                + rollCall.Class.ClassName + "_"
                                                + rollCall.Subject.ShortName + "_"
                                                + file.FileName);
                FaceBusiness.ResizeImage(OldPath, NewPath);
                ImagePaths.Add(NewPath);
            }
            //Nhan dien tung khuon mat trong anh
            List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths);
            //Dua reseult nay cho AttendanceBO xu ly
            AttendanceBusiness AttenBO = new AttendanceBusiness();
            AttendanceLog      Log     = AttenBO.WriteAttendanceAutoLog(RollCallID, Result);


            //Danh sach sinh vien trong log
            StudentBusiness StuBO    = new StudentBusiness();
            List <Student>  Students = StuBO.Find(stu => stu.StudentAttendances.
                                                  Any(attend => attend.LogID == Log.LogID && attend.IsPresent)).ToList();
            RollCall CurrentRollCall = RollBO.GetRollCallByID(RollCallID);

            //Tao model de show trong view
            AttendanceViewModel model = new AttendanceViewModel();

            model.CurrentRollCall = CurrentRollCall;
            model.PresentStudents = Students;
            model.RecognizeResult = Result;

            return(View(model));
        }
        //
        // GET: /RollCall/Edit/5

        public ActionResult Edit(int id)
        {
            RollCall rollcall = RollBO.GetRollCallByID(id);

            int MajorID      = rollcall.Class.MajorID;
            int InstructorID = rollcall.InstructorID;

            ViewBag.InstructorID = SlFactory.MakeSelectList <Instructor>("InstructorID", "FullName", InstructorID);
            ViewBag.MajorID      = SlFactory.MakeSelectList <Major>("MajorID", "FullName", MajorID);
            ViewBag.ClassID      = new SelectList(ClaBO.GetClassByMajor(MajorID),
                                                  "ClassID", "ClassName", rollcall.ClassID);
            //Mac dinh, lay semester moi nhat
            ViewBag.SemesterID = SlFactory.MakeSelectList <Semester>("SemesterID", "SemesterName", rollcall.SemesterID);
            ViewBag.BeginDate  = rollcall.BeginDate.ToString("dd-MM-yyyy");
            ViewBag.StartTime  = rollcall.StartTime.ToString(@"hh\:mm");
            ViewBag.SubjectID  = rollcall.SubjectID.ToString();
            ViewBag.Semester   = rollcall.SemesterID;
            ViewBag.Subject    = rollcall.SubjectID;
            ViewBag.ID         = InstructorID;
            return(View(rollcall));
        }
Пример #21
0
        public RollCall GetByEntryAndDate(string entry, DateTime date)
        {
            var result = new RollCall();

            result.Entry     = entry;
            result.Date      = date;
            result.Presences = new List <RollCallPerson>();

            var people = this._personRepository.GetAll();

            if (people == null)
            {
                throw new Exception("Could not fetch people for roll call");
            }

            var rollCallPeople =
                people.Where(p => p.Presences != null).Select(p =>
                                                              new
            {
                Person        = p,
                PresenceEntry = p.Presences.FirstOrDefault(presence =>
                                                           presence.Called && presence.Date == date &&
                                                           p.PlaceOfConvocation != null &&
                                                           p.PlaceOfConvocation.IndexOf(entry, StringComparison.InvariantCultureIgnoreCase) >= 0)
            }).Where(o => o.PresenceEntry != null)
                .Select(o => new RollCallPerson
            {
                FirstName = o.Person.FirstName,
                LastName  = o.Person.LastName,
                Presence  = o.PresenceEntry.Presence
            });

            var withoutRest = rollCallPeople.Where(rp =>
                                                   rp.Presence == null || rp.Presence.IndexOf("R", StringComparison.InvariantCultureIgnoreCase) < 0);

            result.Presences = withoutRest.ToList();

            return(result);
        }
Пример #22
0
        public ActionResult RollAttendance(int RollCallID, int StudentID)
        {
            Student  Stu  = StuBO.GetStudentByID(StudentID);
            RollCall Roll = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness   AttenBO      = new AttendanceBusiness();
            List <AttendanceLog> RollCallLogs = AttenBO.GetRollCallAttendanceLog(RollCallID);

            //Tim nhung attendance cua student, nam trong log, co rollcallID bang RollcallID dua vao
            var StudentAttendances = Stu.StudentAttendances.Where(sa => sa.AttendanceLog.RollCallID == RollCallID &&
                                                                  RollCallLogs.Select(r => r.LogID).Contains(sa.LogID))
                                     .OrderBy(sa => sa.AttendanceLog.LogDate).ToList();


            StudentAttendanceViewModel Model = new StudentAttendanceViewModel();

            Model.InStudent          = Stu;
            Model.InRollCall         = Roll;
            Model.StudentAttendances = StudentAttendances;

            return(PartialView("_RollAttendance", Model));
        }
        public ActionResult Index()
        {
            //Tim instructor da dang nhạp vao
            string     Username             = this.HttpContext.User.Identity.Name;
            User       User                 = AccBO.GetUserByUsername(Username);
            Instructor AuthorizedInstructor = InsBO.GetInstructorByUserID(User.UserID);

            //Nhung mon ma instructor nay dang day, sau nay phai check status
            DateTime Today     = DateTime.Now;
            var      RollCalls = RollBO.GetInstructorCurrentRollCalls(AuthorizedInstructor.InstructorID);

            //Mon dang day vao thoi diem dang nhap
            RollCall CurrentRollCall = null;
            TimeSpan CurrentTime     = DateTime.Now.TimeOfDay;

            if (RollCalls.Count() > 0)
            {
                CurrentRollCall = RollCalls.FirstOrDefault(r => r.StartTime <CurrentTime && r.EndTime> CurrentTime);
            }

            //Neu co mon dang day, lay luon attendanlog log cua mon do
            AttendanceLog CurrentAttendanceLog = null;

            if (CurrentRollCall != null)
            {
                AttendanceBusiness AttendanceBO = new AttendanceBusiness();
                CurrentAttendanceLog = AttendanceBO.GetAttendanceLogAtDate(CurrentRollCall.RollCallID, DateTime.Today);
            }

            InstructorViewModel model = new InstructorViewModel();

            model.AuthorizedInstructor = AuthorizedInstructor;
            model.CurrentRollCall      = CurrentRollCall;
            model.TeachingRollCall     = RollCalls;
            model.CurrentAttendanceLog = CurrentAttendanceLog;
            return(View(model));
        }
        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);
        }
Пример #25
0
        /// <summary>
        /// Собрать роту
        /// </summary>
        public List <string> Equip()
        {
            List <string>  vs             = new List <string>();
            PlatoonFactory platoonFactory = new PlatoonFactory();
            RollCall       rollCall       = new RollCall();
            Composite      tank           = new Composite();

            tank.AddItem(new Ammo());
            tank.AddItem(new Fuel());
            tank.AddItem(new ZIP());

            Platoon p2si13 = new Platoon();

            p2si13 = platoonFactory.GetPlatoonClear("Танкисты");
            vs.Add(p2si13.SetTitleAndConnect("2СИ-13"));

            p2si13.AddItem(tank);
            p2si13.AddItem(tank);
            p2si13.AddItem(tank);

            p2si13.AddSolder("Барсуков", "Механик водитель 1-го танка");
            p2si13.AddSolder("Горбунцов", "Наводчик 1-го танка");
            p2si13.AddSolder("Бердюгин", "Командир экипажа 1-го танка");

            p2si13.AddSolder("Алексеев", "Механик водитель 2-го танка");
            p2si13.AddSolder("Крыловский", "Наводчик 2-го танка");
            p2si13.AddSolder("Астапов", "Командир экипажа 2-го танка");

            p2si13.AddSolder("Рудько", "Механик водитель 3-го танка");
            p2si13.AddSolder("Чеконов", "Наводчик 3-го танка");
            p2si13.AddSolder("Татьков", "Командир экипажа 3-го танка");
            vs.AddRange(rollCall.Begin(p2si13));

            sq.Add(p2si13);

            Platoon p1t16 = new Platoon();

            p1t16 = platoonFactory.GetPlatoonClear("Танкисты");
            vs.Add(p1t16.SetTitleAndConnect("1Т-16"));

            p1t16.AddItem(tank);
            p1t16.AddItem(tank);
            p1t16.AddItem(tank);

            p1t16.AddSolder("Худяков", "Механик водитель 1-го танка");
            p1t16.AddSolder("Попцов", "Наводчик 1-го танка");
            p1t16.AddSolder("Логинов", "Командир экипажа 1-го танка");

            p1t16.AddSolder("Михельсон", "Механик водитель 2-го танка");
            p1t16.AddSolder("Дроздов", "Наводчик 2-го танка");
            p1t16.AddSolder("Вяткин", "Командир экипажа 2-го танка");

            p1t16.AddSolder("Андреев", "Механик водитель 3-го танка");
            p1t16.AddSolder("Гринько", "Наводчик 3-го танка");
            p1t16.AddSolder("Свиридов", "Командир экипажа 3-го танка");

            vs.AddRange(rollCall.Begin(p1t16));
            sq.Add(p1t16);

            Platoon p2si15 = new Platoon();

            p2si15 = platoonFactory.GetPlatoonClear("Танкисты");
            vs.Add(p2si15.SetTitleAndConnect("2СИ-15"));

            p2si15.AddItem(tank);
            p2si15.AddItem(tank);
            p2si15.AddItem(tank);

            p2si15.AddSolder("Халилов", "Механик водитель 1-го танка");
            p2si15.AddSolder("Нагель", "Наводчик 1-го танка");
            p2si15.AddSolder("Черных", "Командир экипажа 1-го танка");

            p2si15.AddSolder("Красненко", "Механик водитель 2-го танка");
            p2si15.AddSolder("Рысьянов", "Наводчик 2-го танка");
            p2si15.AddSolder("Рыжков", "Командир экипажа 2-го танка");

            p2si15.AddSolder("Тычков", "Механик водитель 3-го танка");
            p2si15.AddSolder("Маркевцев", "Наводчик 3-го танка");
            p2si15.AddSolder("Даулетович", "Командир экипажа 3-го танка");

            vs.AddRange(rollCall.Begin(p2si15));
            sq.Add(p2si15);

            foreach (var item in sq)
            {
                vs.AddRange(item.Take());
            }
            return(vs);
        }
        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);
        }
        public ViewResult Details(int id)
        {
            RollCall rollcall = RollBO.GetRollCallByID(id);

            return(View(rollcall));
        }
Пример #28
0
        public ApiResult <RollCall> ChangeRollCall(int classScheduleId, int studentId)
        {
            var r             = new ApiResult <RollCall>();
            var classSchedule = RCSContext.ClassSchedules.Where(cs => cs.Id == classScheduleId).FirstOrDefault();

            if (classSchedule == null)
            {
                r.Messages.Add("Không tìm thấy lớp học.");
                return(r);
            }
            if (classSchedule.Status == (int)EClassStatus.Schedule)
            {
                r.Messages.Add("Lớp chưa mở, bạn không thể điểm danh vào lúc này.");
                return(r);
            }
            var studying = RCSContext.Studyings.Where(s => s.ClassId == classSchedule.ClassId && s.StudentId == studentId).FirstOrDefault();

            if (studying == null)
            {
                r.Messages.Add("Học sinh không thuộc lớp học này.");
                return(r);
            }
            var rollCall = RCSContext.RollCalls.Where(rc => rc.StudentId == studentId && rc.ClassScheduleId == classScheduleId).FirstOrDefault();

            if (rollCall == null)
            {
                rollCall = new RollCall
                {
                    ClassScheduleId = classScheduleId,
                    StudentId       = studentId,
                    CreatedDate     = DateTime.Now,
                    Type            = (int)ERollCallType.Manually,
                    IsActive        = true
                };
                RCSContext.RollCalls.Add(rollCall);
            }
            else
            {
                rollCall.IsActive    = !rollCall.IsActive;
                rollCall.CreatedDate = DateTime.Now;
                rollCall.Type        = (int)ERollCallType.Manually;
            }
            try
            {
                RCSContext.SaveChanges();
                if (rollCall.IsActive == true)
                {
                    r.Messages.Add("Điểm danh thành công.");
                }
                else
                {
                    r.Messages.Add("Hủy điểm danh thành công");
                }
            }
            catch (Exception e)
            {
                r.Messages.Add(e.Message);
                return(r);
            }
            var rl = (from rc in RCSContext.RollCalls
                      where (rc.ClassScheduleId == classScheduleId && rc.StudentId == studentId)
                      join st in RCSContext.Students on rc.StudentId equals st.Id into st1
                      from st in st1.DefaultIfEmpty()
                      select new { rc, st }).FirstOrDefault().rc;

            rl.Student.RollCalls      = null;
            rl.Student.Studyings      = null;
            rl.ClassSchedule          = null;
            rl.Student.TrainingImages = null;
            r.IsSuccess = true;
            r.Data      = rl;
            return(r);
        }
Пример #29
0
        public ApiResult <RollCallReponseModel> RollCall(RollCallModel model)
        {
            var r = new ApiResult <RollCallReponseModel>();

            r.Data             = new RollCallReponseModel();
            r.Data.Base64Image = model.Base64Image;
            var rollCallData  = new ApiResult <List <RollCall> >();
            var classSchedule = RCSContext.ClassSchedules.Where(cs => cs.Id == model.ClassScheduleId).FirstOrDefault();

            //check thông tin lớp học
            if (classSchedule == null)
            {
                r.Messages.Add("Lớp học không tồn tại.");
                return(r);
            }
            if (classSchedule.Status == (int)EClassStatus.Schedule)
            {
                r.Messages.Add("Lớp học chưa mở.");
                return(r);
            }
            if (classSchedule.Status == (int)EClassStatus.Closed)
            {
                r.Messages.Add("Lớp học đã kết thúc");
                return(r);
            }
            var imageGray      = model.Base64Image.base64ToImageGray();
            var image          = model.Base64Image.base64ToImage();
            var bitmap         = new Bitmap(image);
            var bitmapResponse = new Bitmap(bitmap);

            imageGray._EqualizeHist();
            var rectangles = DetectService.DetectFaceRollCall(imageGray);

            if (rectangles.Count() == 0)
            {
                r.Messages.Add("Không có sinh viên nào trong ảnh.");
                return(r);
            }
            var classId      = RCSContext.ClassSchedules.Where(cs => cs.Id == model.ClassScheduleId).FirstOrDefault().ClassId;
            var studyings    = RCSContext.Studyings.Where(st => st.ClassId == classId).ToList();
            var newRollCalls = new List <RollCall>();
            var oldRollCalls = new List <RollCall>();

            //Detect khuôn mặt
            rectangles.ForEach(rec =>
            {
                var face      = bitmap.cropAtRect(rec);
                var faceGray  = new Image <Gray, byte>(face);
                var studentId = DetectService.RecognizeFace(faceGray);
                if (studentId == -1)
                {
                    var faceGrayFlip = faceGray.Flip(FlipType.Horizontal);
                    studentId        = DetectService.RecognizeFace(faceGrayFlip);
                }
                if (studentId != -1)
                {
                    if (studyings.Any(st => st.StudentId == studentId))
                    {
                        bitmapResponse = drawFaceAndNoteOnBitmap(bitmapResponse, rec, studentId.ToString(), Color.Green);
                        var rc         = RCSContext.RollCalls.Where(i => i.StudentId == studentId && i.ClassScheduleId == model.ClassScheduleId).FirstOrDefault();
                        var fileData   = new FileData
                        {
                            Data = face.bitmapToByteArr(),
                        };
                        var fileAttachment = new FileAttachment
                        {
                            CreateDate = DateTime.Now,
                            Height     = face.Height,
                            Width      = face.Width,
                            Extension  = "jpg",
                            Type       = (int)EFileType.ImageJPG,
                            Name       = Guid.NewGuid().ToString(),
                            FileData   = fileData
                        };
                        if (rc == null)
                        {
                            var rollCall = new RollCall();
                            rollCall     = new RollCall
                            {
                                ClassScheduleId = model.ClassScheduleId,
                                StudentId       = studentId,
                                CreatedDate     = DateTime.Now,
                                Type            = (int)ERollCallType.Auto,
                                IsActive        = true
                            };
                            newRollCalls.Add(rollCall);
                        }
                        else
                        {
                            rc.IsActive       = true;
                            rc.CreatedDate    = DateTime.Now;
                            rc.FileAttachment = fileAttachment;
                            oldRollCalls.Add(rc);
                        }
                    }
                }
                else
                {
                    bitmapResponse = drawFaceAndNoteOnBitmap(bitmapResponse, rec, "unknown", Color.Red);
                }
            });
            if (newRollCalls.Count == 0 && oldRollCalls.Count == 0)
            {
                r.Messages.Add("Các sinh viên không thuộc lớp này.");
                r.Data.Base64Image = Convert.ToBase64String(bitmapResponse.bitmapToByteArr());
                return(r);
            }
            RCSContext.RollCalls.AddRange(newRollCalls);
            try
            {
                RCSContext.SaveChanges();
            }
            catch (Exception e) { r.Messages.Add(e.Message); return(r); }
            newRollCalls.AddRange(oldRollCalls);
            newRollCalls.ForEach(i =>
            {
                i.ClassSchedule.RollCalls = null;
                i.FileAttachment          = null;
                i.Student = null;
                i.Image   = null;
            });
            r.Messages.Add("Điểm danh thành công.");
            r.IsSuccess        = true;
            r.Data.Base64Image = Convert.ToBase64String(bitmapResponse.bitmapToByteArr());
            r.Data.RollCalls   = newRollCalls;
            return(r);
        }