void restTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            ///[Timer elapsed]
            m_attendanceTime = null;

            EmguCVHelper.CaptureImageIsRefreshed += RefreshImage;
            m_restTimer.Stop();
            if (Rejected)
            {
                DetectedEmployee  = null;
                EnteredEmployeeID = null;
                RaisePropertyChanged(() => IsEmployeeDetected);
            }
            else
            {
                m_attendanceTime = AutomatedAttendanceSystem.RegisterAttendance(DetectedEmployee);

                showSubmitAttendanceMessage();
                RaisePropertyChanged(() => IsRegistered);
            }
            Rejected          = false;
            DetectedEmployee  = null;
            EnteredEmployeeID = null;
            saveLogs();
            RaisePropertyChanged(() => IsEmployeeDetected);
            ///[Timer elapsed]
        }
Ejemplo n.º 2
0
 public void SetAttendanceTime(string time)
 {
     SwitchToFrame();
     AttendanceTime.Clear();
     AttendanceTime.SendKeys(time);
     SwitchToParent();
 }
        public async Task <RepResult <DayVM> > GetDayData(AttendanceTime attendanceTime)
        {
            if (dbContext != null)
            {
                var qDay = from d in dbContext.Days
                           where d.PersonnelId == attendanceTime.PersonnelId &&
                           d.Date.Date == attendanceTime.DateTime.Date
                           select d;

                if (await qDay.AnyAsync())
                {
                    var day = await qDay.FirstOrDefaultAsync();

                    var res = await GetDayData(day.PersonnelId, day.Date);

                    if (res.Successed)
                    {
                        return new RepResult <DayVM> {
                                   Successed = true, ResultObject = res.ResultObject
                        }
                    }
                    ;
                }

                return(new RepResult <DayVM> {
                    Successed = true, ResultObject = null
                });
            }

            return(new RepResult <DayVM>());
        }
Ejemplo n.º 4
0
        /// <summary>
        ///ثبت ساعت ورودی
        /// </summary>
        /// <param name="employee">کارمند</param>
        /// <returns>زمان حضور</returns>
        public AttendanceTime RegisterEmployeeEntryTime(Employee employee)
        {
            ///[Registering entry time]
            AttendanceTime attendanceTime = new AttendanceTime()
            {
                Employee  = employee,
                EntryTime = DateTime.Now,
            };

            return(PersistenceObjectRepository <AttendanceTime> .Create(attendanceTime));

            ///[Registering entry time]
        }
        public void RegisterEmployeeEntryTime_WhenCalled_RegistersEntryTimeInDatabase()
        {
            ContactInformation contactInformation = null;
            Employee           employee           = null;

            Expect(() => { contactInformation = AutomatedAttendanceSystem.CreateContactInformation(CommonTestCaseSourceProvider.newContactInformationSample()); }, Throws.Nothing);
            Expect(() => { employee = AutomatedAttendanceSystem.CreateEmployee(CommonTestCaseSourceProvider.newEmployeeSample(contactInformation)); }, Throws.Nothing);

            DateTime       entryTime      = DateTime.Now;
            AttendanceTime attendanceTime = null;

            Expect(() => { attendanceTime = AutomatedAttendanceSystem.RegisterEmployeeEntryTime(employee); }, Throws.Nothing);
            Expect(() => attendanceTime.ID, Is.Not.EqualTo(Guid.Empty));
            Expect(() => AutomatedAttendanceSystem.RetrieveAttendanceTimes().Count, Is.EqualTo(1));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 添加打卡记录
        /// </summary>
        public CheckInOut AddCheckInOut(int userId)
        {
            var time = new AttendanceTime(GetAttendanceGroup(userId));

            if (!time.IsCheckTime(DateTime.Now))
            {
                throw new Exception("该时间段签到无效");
            }
            var model = new CheckInOut {
                UserId = userId
            };

            DB.CheckInOuts.Add(model);
            DB.SaveChanges();
            UpdateAttendance(model.UserId, time, model.CreateTime.Date);
            return(model);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// ثبت ساعت خروج
        /// </summary>
        /// <param name="employee">کارمند</param>
        /// <returns>زمان خروج</returns>
        public AttendanceTime RegisterEmployeeExitTime(Employee employee)
        {
            if (employee == null)
            {
                return(null);
            }
            ///[Registering exit time]
            AttendanceTime attendanceTime = new AttendanceTime();

            attendanceTime = RetrieveAttendanceTimes().Where((at) => at.Employee == employee).Last();
            attendanceTime.Employee.ProfilePicture = m_profilePictureRepository.Read(attendanceTime.Employee.ID.ToString());
            attendanceTime.ExitTime = DateTime.Now;

            return(PersistenceObjectRepository <AttendanceTime> .Update(attendanceTime));

            ///[Registering exit time]
        }
Ejemplo n.º 8
0
        public static AttendanceTime newAttendanceTimeSample(Employee employee = null)
        {
            WorkSchedule workHours = new WorkSchedule();
            DateTime     entryTime = new DateTime(2014, 10, 11, 09, 0, 0);
            DateTime     exitTime  = new DateTime(2014, 10, 11, 17, 0, 0);

            workHours.DefineRange(entryTime.DayOfWeek, 09, 17, WorkSchedule.State.Work);
            AttendanceTime attendanceTime = new AttendanceTime()
            {
                Employee  = employee,
                EntryTime = entryTime,
                ExitTime  = exitTime,
                //  AttendanceHours = workHours
            };

            return(attendanceTime);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// ثبت ورود/خروج
        /// این متد به طور خورکار ورود و خروج را ثبت می کند
        /// </summary>
        /// <param name="employee">کارمند</param>
        /// <returns>زمان حضور</returns>
        public AttendanceTime RegisterAttendance(Employee employee)
        {
            ///[Registering attendance]
            AttendanceTime attendanceTime = null;

            if (!m_attendedEmployees.Contains(employee) || m_attendedEmployees.Count == 0)
            {
                attendanceTime = RegisterEmployeeEntryTime(employee);
                m_attendedEmployees.Add(employee);
            }
            else
            {
                attendanceTime = RegisterEmployeeExitTime(employee);
                m_attendedEmployees.Remove(employee);
            }

            return(attendanceTime);
            ///[Registering attendance]
        }
        public void RegisterEmployeeExitTime_WhenCalled_CalculatesWorkHoursAndRegisterExitTimeInDatabase()
        {
            //Entry time is registered
            Employee       employee            = util_createSampleEmployeeAndContactInformation();
            AttendanceTime entryAttendanceTime = null;

            Expect(() => { entryAttendanceTime = AutomatedAttendanceSystem.RegisterEmployeeEntryTime(employee); }, Throws.Nothing);
            Expect(() => entryAttendanceTime.ID, Is.Not.EqualTo(Guid.Empty));

            //Mock Time?


            //Exit time is registered
            AttendanceTime exitAttendanceTime = null;

            Expect(() => { exitAttendanceTime = AutomatedAttendanceSystem.RegisterEmployeeExitTime(employee); }, Throws.Nothing);
            Expect(() => exitAttendanceTime.ID, Is.EqualTo(entryAttendanceTime.ID));
            //    Expect(() => exitAttendanceTime.AttendanceHours, Is.EqualTo(WorkSchedule.MinValue));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 更新考勤状态
        /// </summary>
        public void UpdateAttendance(int userId, AttendanceTime time, DateTime date)
        {
            var tomorrow = date.AddDays(1);
            var model    = DB.Attendances.FirstOrDefault(e => e.UserId == userId && e.Date == date);

            if (model == null)
            {
                model = new Attendance
                {
                    UserId = userId,
                    Date   = date,
                };
                DB.Attendances.Add(model);
            }
            var leaves = DB.FormInfoExtend1s.Where(e => e.ApprovalUserId == userId && e.Result.HasValue && e.ScheduleBeginTime <= date && e.ScheduleEndTime > date).ToList();
            var logs   = DB.CheckInOuts.Where(e => e.UserId == userId && e.CreateTime > date && e.CreateTime < tomorrow).OrderBy(e => e.CreateTime).ToList();

            model.Check(logs, leaves, time);
            DB.SaveChanges();
        }
Ejemplo n.º 12
0
        public ContentResult TimeOut(FormCollection form)
        {
            // time outJObject json = new JObject();
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            Employee emp = null;

            DBHandler db = new DBHandler();

            if (this.GetAccount() != null && this.GetAccount().Type != AccountType.Applicant)
            {
                emp = ((Employee)this.GetAccount().Profile);
            }
            else
            {
                if (form.GetValue("code") != null)
                {
                    string code = form.GetValue("code").AttemptedValue;
                    Dictionary <string, dynamic> param = new Dictionary <string, dynamic>();
                    param.Add("@Code", code);
                    using (DataTable dt = db.Execute <DataTable>(
                               CRUD.READ,
                               "SELECT EmployeeID FROM Employee E INNER JOIN Account A ON E.Profile = A.Profile WHERE E.Code = @Code AND (A.Type ="
                               + ((int)AccountType.Employee) + " OR A.Type = " + ((int)AccountType.DepartmentHead) + ")", param))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            try
                            {
                                emp = new Employee(Int32.Parse(dt.Rows[0]["EmployeeID"].ToString()), byPrimary: true);
                            }
                            catch (Exception e)
                            {
                                emp = null;
                            }
                        }
                    }
                }
            }

            if (emp != null && this.GetAccount() == null || (this.GetAccount() != null &&
                                                             (this.CheckLogin(AccountType.Employee) || this.CheckLogin(AccountType.DepartmentHead))))
            {
                try
                {
                    Attendance at = new Attendance().Find(
                        emp.EmployeeID,
                        DateTime.Now,
                        recursive: true,
                        byPrimary: false);

                    AttendanceTime aTime = new AttendanceTime();
                    try
                    {
                        aTime.Find(at.AttendanceID, DateTime.Now, recursive: false, byPrimary: false);

                        if (aTime.TimeIn.HasValue && !aTime.TimeOut.HasValue)
                        {
                            aTime.Attendance = at;
                            aTime.TimeOut    = DateTime.Now;

                            aTime.Update(false);

                            DateTime callTime = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd") + " "
                                                                    + "08:00 AM", "yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture);
                            DateTime endTime = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd") + " "
                                                                   + "05:00 PM", "yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture);

                            json["message"] = "Successfully Timed Out today.";

                            if (DateTime.Compare(aTime.TimeOut.Value, endTime) < 0)
                            {
                                at.Undertime   += 1;
                                json["message"] = "Successfully Timed Out today. However you've timed out early (Undertime)";
                            }
                            else if (DateTime.Compare(aTime.TimeOut.Value, endTime.AddMinutes(30)) > 0 &&
                                     !(DateTime.Compare(aTime.TimeIn.Value, endTime) >= 0))
                            {
                                at.Overtime    += 1;
                                json["message"] = "Successfully Timed Out today. However you've timed out late (Overtime)";
                            }

                            if (DateTime.Compare(aTime.TimeIn.Value, callTime) >= 0 && DateTime.Compare(aTime.TimeIn.Value, endTime) < 0)
                            {
                                at.Present += 1;
                            }

                            at.Update(false);
                        }
                        else
                        {
                            json["error"]   = true;
                            json["message"] = "You've already timed out today";
                        }
                    }
                    catch (Exception e)
                    {
                        json["error"]   = true;
                        json["message"] = "You haven't timed in today";
                    }
                }
                catch (Exception e)
                {
                    json["error"]   = true;
                    json["message"] = e.Message;
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "You are not authorized to continue";
            }

            return(Content(json.ToString(), "application/json"));
        }
Ejemplo n.º 13
0
        public ContentResult GetAttendanceToday()
        {
            JObject json = new JObject();

            json["attendance"] = null;

            if (this.GetAccount() != null)
            {
                if (!this.CheckLogin(AccountType.Applicant))
                {
                    try
                    {
                        Attendance at = new Attendance().Find(
                            ((Employee)this.GetAccount().Profile).EmployeeID,
                            DateTime.Now,
                            recursive: false,
                            byPrimary: false);

                        AttendanceTime aTime = new AttendanceTime(at.AttendanceID, recursive: true, byPrimary: false);
                        json["attendance"] = JObject.FromObject(aTime);
                    }
                    catch (Exception e)
                    {
                        json["attendance"] = null;
                    }
                }
            }
            else
            {
                json["error"]   = false;
                json["message"] = "";

                if (Request.QueryString["code"] != null)
                {
                    string    code = Request.QueryString["code"].ToString();
                    DBHandler db   = new DBHandler();

                    Dictionary <string, dynamic> param = new Dictionary <string, dynamic>();
                    param.Add("@Code", code);
                    using (DataTable dt = db.Execute <DataTable>(
                               CRUD.READ,
                               "SELECT EmployeeID, A.Image FROM Employee E INNER JOIN Account A ON E.Profile = A.Profile WHERE E.Code = @Code AND (A.Type ="
                               + ((int)AccountType.Employee) + " OR A.Type = " + ((int)AccountType.DepartmentHead) + ")", param))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            json["error"]   = false;
                            json["message"] = "Succesfully found your employee data";
                            json["image"]   = dt.Rows[0]["Image"].ToString();

                            try
                            {
                                Attendance at = new Attendance().Find(
                                    Int32.Parse(dt.Rows[0]["EmployeeID"].ToString()),
                                    DateTime.Now,
                                    recursive: true,
                                    byPrimary: false);

                                json["employee"] = JObject.FromObject(at.Employee);
                                try
                                {
                                    AttendanceTime aTime = new AttendanceTime(
                                        at.AttendanceID,
                                        recursive: true,
                                        byPrimary: false);
                                    json["attendance"] = JObject.FromObject(aTime);
                                }
                                catch (Exception e) {}

                                json["onleave"] = at.Employee.OnLeave(DateTime.Now);
                            }
                            catch (Exception e)
                            {
                                json["error"]   = true;
                                json["message"] =
                                    "<b>Error: </b> You do not have an attendance sheet for this month yet, please contact the HR department.";
                            }
                        }
                        else
                        {
                            json["error"]   = true;
                            json["message"] = "That is not a valid employee code";
                        }
                    }
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "Form is incomplete";
                }
            }

            return(Content(json.ToString(), "application/json"));
        }
        private void filterEmployees()
        {
            IEnumerable <Employee> l_matchingEmployees = null;

            if (!FilterMode)
            {
                l_matchingEmployees = m_employees;
            }
            else
            {
                DateTime dateTime = CurrentDateFilter;


                IEnumerable <Employee> l_presentEmployees = null;
                IEnumerable <Employee> l_absentEmployees  = null;

                if (CurrentDateFilter.Date <= DateTime.Now.Date)
                {
                    l_presentEmployees = (from at in m_attendanceTimes
                                          where AttendanceTime.IsPresent(at, CurrentDateFilter)
                                          select at.Employee).Distinct();


                    l_absentEmployees = m_employees.Except(l_presentEmployees, new EntityComparer <Employee>()).Distinct();
                }

                else
                {
                    l_presentEmployees = new List <Employee>();
                    l_absentEmployees  = new List <Employee>();
                }


                switch (CurrentAttendanceStatusFitler)
                {
                case AttendanceStatus.Present:
                    l_matchingEmployees = l_presentEmployees;

                    break;

                case AttendanceStatus.Absent:
                    l_matchingEmployees = l_absentEmployees;

                    break;
                }
            }
            string text = SearchQueryFilter ?? string.Empty;

            if (l_matchingEmployees.Count() > 0)
            {
                l_matchingEmployees = (from Employee employee in l_matchingEmployees
                                       where
                                       employee != null &&
                                       (

                                           employee.FirstName.ToLower().Contains(text.ToLower()) ||
                                           employee.LastName.ToLower().Contains(text.ToLower()) ||
                                           employee.EmployeeID.ToString().Contains(text) ||
                                           employee.NationalID.ToString().Contains(text) ||
                                           employee.IdentityNumber.ToString().Contains(text)
                                       )
                                       select employee).ToList();
            }

            FilteredEmployees = new ObservableCollection <Employee>(l_matchingEmployees.ToList <Employee>());
        }