コード例 #1
0
        ///<summary>Updates the employee's ClockStatus if necessary based on their clock events. This method handles future clock events as having
        ///already occurred. Ex: If I clock out for home at 6:00 but edit my time card to say 7:00, at 6:30 my status will say Home.</summary>
        public static void UpdateClockStatus(long employeeNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), employeeNum);
                return;
            }
            //Get the last clockevent for the employee. Will include clockevent with "in" before NOW, and "out" anytime before 23:59:59 of TODAY.
            string command = @"SELECT * FROM clockevent 
				WHERE TimeDisplayed2<="                 + DbHelper.DateAddSecond(DbHelper.DateAddDay(DbHelper.Curdate(), "1"), "-1") + " AND TimeDisplayed1<=" + DbHelper.Now() + @"
				AND EmployeeNum="                 + POut.Long(employeeNum) + @"
				ORDER BY IF(YEAR(TimeDisplayed2) < 1880,TimeDisplayed1,TimeDisplayed2) DESC"                ;

            command = DbHelper.LimitOrderBy(command, 1);
            ClockEvent clockEvent  = Crud.ClockEventCrud.SelectOne(command);
            Employee   employee    = GetEmp(employeeNum);
            Employee   employeeOld = employee.Copy();

            if (clockEvent != null && clockEvent.TimeDisplayed2 > DateTime.Now)         //Future time manual clock out.
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Manual Entry");
            }
            else if (clockEvent == null ||       //Employee has never clocked in
                     (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Home))            //Clocked out for home
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Home.ToString());
            }
            else if (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Lunch)           //Clocked out for lunch
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Lunch.ToString());
            }
            else if (clockEvent.TimeDisplayed1.Year > 1880 && clockEvent.TimeDisplayed2.Year < 1880 && clockEvent.ClockStatus == TimeClockStatus.Break)
            {
                employee.ClockStatus = Lans.g("enumTimeClockStatus", TimeClockStatus.Break.ToString());
            }
            else if (clockEvent.TimeDisplayed2.Year > 1880 && clockEvent.ClockStatus == TimeClockStatus.Break)           //Clocked back in from break
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Working");
            }
            else              //The employee has not clocked out yet.
            {
                employee.ClockStatus = Lans.g("ContrStaff", "Working");
            }
            Crud.EmployeeCrud.Update(employee, employeeOld);
        }