예제 #1
0
 public static string EmployeeTimeToString(EmployeeTimeRange range)
 {
     if (range.Absence != null)
     {
         return(AbsenceTimeRangeToString(range.Begin, range.End, range.Absence.CharID));
     }
     else
     {
         return(TimeRangeToString(range.Begin, range.End));
     }
 }
예제 #2
0
        public static bool IsEqual(EmployeeTimeRange left, EmployeeTimeRange right)
        {
            if (left == null)
            {
                throw new ArgumentNullException();
            }
            if (right == null)
            {
                throw new ArgumentNullException();
            }

            return((left.EmployeeID == right.EmployeeID) &&
                   (left.Date == right.Date) &&
                   (left.AbsenceID == right.AbsenceID) &&
                   (left.Begin == right.Begin) &&
                   (left.End == right.End));
        }
예제 #3
0
        public static bool InsertTimeRange(EmployeeDay day, EmployeeTimeRange newrange)
        {
            List <IEmployeeTimeRange> ranges = new List <IEmployeeTimeRange>();

            if (day.TimeList != null)
            {
                foreach (EmployeeTimeRange r in day.TimeList)
                {
                    ranges.Add(r);
                }
            }
            ranges.Sort();
            // if newrange is part of exists range - return
            foreach (IEmployeeTimeRange range in ranges)
            {
                if (range.AbsenceID == newrange.AbsenceID && range.Begin <= newrange.Begin && newrange.End <= range.End)
                {
                    return(false);
                }
            }
            //ranges.Add(newrange);
            ranges.Sort();


            foreach (IEmployeeTimeRange range in ranges)
            {
                if (DateTimeHelper.IsIntersectInc(range.Begin, range.End, newrange.Begin, newrange.End))
                {
                    // if old range part of new range - mark as delete
                    if (newrange.Begin <= range.Begin && range.End <= newrange.End)
                    {
                        range.Begin = range.End;
                    }
                    else if (range.Begin <= newrange.Begin && newrange.Begin <= range.End)
                    {
                        range.End = (short)(newrange.Begin - 1);
                    }
                    else if (range.Begin <= newrange.End && newrange.End <= range.End)
                    {
                        range.Begin = (short)(newrange.End + 1);
                    }
                }
            }
            if (day.TimeList == null)
            {
                day.TimeList = new List <EmployeeTimeRange>(1);
            }
            if (day.TimeList != null)
            {
                day.TimeList.Add(newrange);
            }

            day.TimeList.Sort();
            for (int i = day.TimeList.Count - 1; i >= 0; i--)
            {
                if (day.TimeList[i].Begin >= day.TimeList[i].End)
                {
                    day.TimeList.RemoveAt(i);
                }
            }

            for (int i = day.TimeList.Count - 1; i >= 1; i--)
            {
                if (day.TimeList[i].AbsenceID == day.TimeList[i - 1].AbsenceID &&
                    day.TimeList[i].Begin - 1 == day.TimeList[i - 1].End)
                {
                    day.TimeList[i - 1].End = day.TimeList[i].End;
                    day.TimeList.RemoveAt(i);
                }
            }
            return(true);
        }
예제 #4
0
        private List <EmployeeTimeRange> GetRecordingTimeRanges(long employeeid, DateTime date)
        {
            List <EmployeeTimeRange> result = new List <EmployeeTimeRange> ();

            EmployeeTimeRange range = null;
            int i = 0;

            while (i < MAXRANGES)
            {
                if (!_recordingTimes[i].Empty)
                {
                    range            = new EmployeeTimeRange();
                    range.EmployeeID = employeeid;
                    range.Date       = date;
                    range.Begin      = (short)(i * 15);
                    range.End        = (short)(range.Begin + 15);

                    if (_recordingTimes[i].Absenced)
                    {
                        range.Absence = _recordingTimes[i].AbsenceEntity;
                        if (range.Absence != null)
                        {
                            range.AbsenceID = range.Absence.ID;
                        }
                        i++;
                        while (i < MAXRANGES)
                        {
                            if (range.Absence == _recordingTimes[i].AbsenceEntity)
                            {
                                range.End += 15;
                            }
                            else
                            {
                                range.Time = (short)(range.End - range.Begin);
                                result.Add(range);
                                range = null;
                                break;
                            }
                            i++;
                        }
                        continue;
                    }
                    else
                    {
                        i++;
                        while (i < MAXRANGES)
                        {
                            if (_recordingTimes[i].Worked)
                            {
                                range.End += 15;
                            }
                            else
                            {
                                range.Time = (short)(range.End - range.Begin);
                                result.Add(range);
                                range = null;
                                break;
                            }
                            i++;
                        }
                        continue;
                    }
                }
                i++;
            }
            if (range != null)
            {
                range.Time = (short)(range.End - range.Begin);
                result.Add(range);
            }

            if (result.Count == 0)
            {
                return(null);
            }

            return(result);
        }