public IDictionary<TimeKey, TimeSpan> GetFullDayTimes(int userID) { IDictionary<TimeKey, TimeSpan> dict = new Dictionary<TimeKey, TimeSpan>(); UserTimeCalculator TimesCalc = new UserTimeCalculator(userID); dict[TimeKey.TodayWork] = TimesCalc.GetWorkedTimeWithLunch(DateTime.Today); TimeSpan todayRest = TimesCalc.GetRateWithLunch(DateTime.Today); todayRest -= TimesCalc.GetWorkedTimeWithLunch(DateTime.Today); dict[TimeKey.TodayRest] = todayRest; dict[TimeKey.WeekRest] = TimesCalc.GetRestTimeWithLunch(DateClass.WeekBegin(DateTime.Today), DateClass.WeekBegin(DateTime.Today).AddDays(6)); dict[TimeKey.MonthRest] = TimesCalc.GetRestTimeWithLunch( new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1, 0, 0, 0), new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1, 0, 0, 0).AddDays( DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month) - 1) ); return dict; }
/// <summary> /// Возвращает список информаций о статусах пользователей за указанную дату. /// </summary> /// <param name="date">Дата для получения информации о пользователях.</param> /// <returns>Список информаций о статусах пользователей за указанную дату.</returns> public static UserStatusInfo[] GetStatusesList( DateTime date ) { List<UserStatusInfo> usersList = new List<UserStatusInfo>(); Person[] activeUsers = GetEmployeeList(); if( ( activeUsers == null ) || ( activeUsers.Length == 0 ) ) return usersList.ToArray(); foreach( Person user in activeUsers ) { // Отсеять московских служащих. if( user.EmployeesUlterSYSMoscow ) continue; // Получить последнее событие пользователя. WorkEvent lastEvent = WorkEvent.GetCurrentEventOfDate( user.ID.Value, date, true ); // Для получения времени рабочего периода. WorkEvent workEvent = null; // Получить статус пользователя. UptimeEventType status; if( lastEvent == null ) { // Нет событий за сегодня. Человек не приходил. status = UptimeEventType.GetEventType( (int) WorkEventType.TimeOff ); } else { switch( lastEvent.EventType ) { case WorkEventType.BusinessTrip: case WorkEventType.Ill: case WorkEventType.TrustIll: case WorkEventType.Vacation: status = UptimeEventType.GetEventType( lastEvent.EventTypeID ); break; case WorkEventType.MainWork: workEvent = lastEvent; if( lastEvent.IsOpen ) { status = UptimeEventType.GetEventType( (int) WorkEventType.MainWork ); } else { status = UptimeEventType.GetEventType( (int) WorkEventType.TimeOff ); } break; default: workEvent = WorkEvent.GetMainWorkEvent( user.ID.Value, date ); if( lastEvent.IsOpen ) { status = UptimeEventType.GetEventType( lastEvent.EventTypeID ); } else { if( workEvent == null ) { status = UptimeEventType.GetEventType( (int) WorkEventType.TimeOff ); } else { if( workEvent.IsOpen ) { status = UptimeEventType.GetEventType( (int) WorkEventType.MainWork ); } else { status = UptimeEventType.GetEventType( (int) WorkEventType.TimeOff ); } } } break; } } // Создать информацию о пользователе. String loginName = string.Empty; IList<string> dnNames = user.DomainNames; if( dnNames != null && dnNames.Count > 0 ) { loginName = dnNames[ 0 ]; int startIndex = loginName.LastIndexOf( "\\" ); if( !string.IsNullOrEmpty( loginName ) && ( startIndex > 0 ) ) loginName = loginName.Substring( startIndex + 1, 3 ); } UserStatusInfo info; if( workEvent == null ) info = new UserStatusInfo( user.ID.Value, user.FullName, loginName, status ); else { UserTimeCalculator timesCalc = new UserTimeCalculator( user.ID.Value ); // Время до окончания дня. TimeSpan todayRest = timesCalc.GetRateWithLunch( DateTime.Today ); // Окончание работы (расчётное или фактическое). /* if (workEvent.BeginTime == workEvent.EndTime) workEvent.EndTime = (todayRest.TotalMilliseconds > 0) ? workEvent.BeginTime.Add(todayRest) : DateTime.Now;*/ /*if( todayRest.TotalMilliseconds > 0 ) workEvent.EndTime = DateTime.Now.Add( todayRest ); else workEvent.EndTime = DateTime.Now;*/ info = new UserStatusInfo( user.ID.Value, user.FullName, loginName, status, workEvent.BeginTime, workEvent.EndTime ); } usersList.Add( info ); } return usersList.ToArray(); }
/// <summary> /// Returns string end work time. /// </summary> protected string GetEndTime(Object obj) { try { XMLSerializableUserStatusInfo info = (XMLSerializableUserStatusInfo)obj; UserTimeCalculator timesCalc = new UserTimeCalculator(info.UserID); if (info.EndWork == DateTime.MinValue) return String.Empty; // Время до окончания дня. TimeSpan todayRest = timesCalc.GetRateWithLunch(DateTime.Today); return (info.BeginWork == info.EndWork) ? (info.BeginWork + todayRest).ToShortTimeString() : info.EndWork.ToShortTimeString(); } catch (Exception ex) { Logger.Log.Error(ex.Message, ex); return string.Empty; } }