예제 #1
0
        public int GetActivity(DateTime when)
        {
            WorkdayModel day = WorkdayModel.Load(HoursUtil.GetConnection(), Id, when);

            if (day == null)
            {
                if (when.DayOfWeek == DayOfWeek.Sunday || when.DayOfWeek == DayOfWeek.Saturday)
                {
                    return(WEEKEND);
                }
                return(NOT_WORKING);
            }
            else
            {
                if (day.IsHoliday)
                {
                    return(HOLIDAY);
                }
                if (day.IsPaidTimeOff)
                {
                    return(PAID_TIME_OFF);
                }

                // the load function uses DateTime.MaxValue if the entry hasn't been created yet.
                // that is, in the database, if there's a value for StartIn, but the others are all
                // null, they will be represented as DateTime.MaxValue.
                if (when < day.StartIn)
                {
                    return(NOT_WORKING);
                }
                // if there's a punch out time, it doesn't matter whether lunch occurred.
                if (when >= day.EndOut)
                {
                    return(DONE);
                }

                if (when == day.StartIn || when < day.LunchOut)
                {
                    return(MORNING);
                }
                if (when == day.LunchOut || when < day.LunchIn)
                {
                    return(LUNCH);
                }
                if (when == day.LunchIn || when < day.EndOut)
                {
                    return(AFTERNOON);
                }
                return(NOT_WORKING);
            }
        }
예제 #2
0
        public static WorkdayModel LoadFromReader(SQLiteDataReader reader)
        {
            WorkdayModel result = new WorkdayModel();
            UserModel    user   = UserModel.LoadFromReader(reader);

            result.User          = user;
            result.Day           = reader["day"] == DBNull.Value ? DateTime.MaxValue : ((DateTime)reader["day"]).Date;
            result.StartIn       = reader["startIn"] == DBNull.Value ? DateTime.MaxValue : (DateTime)reader["startIn"];
            result.LunchOut      = reader["lunchOut"] == DBNull.Value ? DateTime.MaxValue : (DateTime)reader["lunchOut"];
            result.LunchIn       = reader["lunchIn"] == DBNull.Value ? DateTime.MaxValue : (DateTime)reader["lunchIn"];
            result.EndOut        = reader["endOut"] == DBNull.Value ? DateTime.MaxValue : (DateTime)reader["endOut"];
            result.IsPaidTimeOff = ((byte)reader["isPaidTimeOff"]) > 0;
            result.IsHoliday     = ((byte)reader["isHoliday"]) > 0;
            return(result);
        }
예제 #3
0
        public void Punch(SQLiteConnection conn, DateTime when, String activity)
        {
            WorkdayModel day = WorkdayModel.Load(HoursUtil.GetConnection(), Id, when);

            if (day == null)
            {
                day      = new WorkdayModel();
                day.Day  = when.Date;
                day.User = this;
                if (activity != PUNCH_START_IN)
                {
                    string message = string.Format("Record for new day {0} should begin with starting work, not '{1}'", when.ToShortDateString(), activity);
                    throw new ArgumentException(message);
                }
            }
            switch (activity)
            {
            case PUNCH_START_IN:
                day.StartIn = when;
                break;

            case PUNCH_LUNCH_OUT:
                day.LunchOut = when;
                break;

            case PUNCH_LUNCH_IN:
                day.LunchIn = when;
                break;

            case PUNCH_END_OUT:
                day.EndOut = when;
                break;

            default:
                throw new ArgumentException("don't recognize punch activity: " + activity);
            }
            day.Save(conn);
        }