private List <WorkEvent> GetWorkEvents() { var workEvents = new List <WorkEvent>(); string fileNameExcel = FileName; var failInfo = new FileInfo(fileNameExcel); using (var package = new ExcelPackage(failInfo)) { var epWorkbook = package.Workbook; var worksheet = epWorkbook.Worksheets .First(); var end = worksheet.Dimension.End; for (int row = 9; row < end.Row; row++) { var workEvent = new WorkEvent(worksheet.GetValue(row, 1).ToString(), worksheet.GetValue(row, 2).ToString(), worksheet.GetValue(row, 3).ToString(), worksheet.GetValue(row, 4).ToString(), worksheet.GetValue(row, 5)?.ToString(), "", worksheet.GetValue(row, 8)?.ToString() ?? ""); workEvents.Add(workEvent); } } return(workEvents.FindAll(f => !string.IsNullOrEmpty(f.UserName))); }
private List <Person> GetPersons() { var persons = new List <Person>(); var workEvents = GetWorkEvents() ?? new List <WorkEvent>(); while (workEvents.Count > 0) { var person = new Person(workEvents.FirstOrDefault() ?.UserName); person.SetWorkTime(WhoStartOnNineOClock); var personEvents = workEvents.FindAll(e => string.Equals(e.UserName, person.Name, new StringComparison())); workEvents.RemoveAll(e => string.Equals(e.UserName, person.Name, new StringComparison())); while (personEvents.Count > 0) { WorkEvent first = null; foreach (var @event in personEvents) { first = @event; break; } if (first == null) { continue; } var currentDate = first.Date; var currentPersonEvents = personEvents.FindAll(e => DateTime.Equals(e.Date, currentDate)); currentPersonEvents.Sort(); var currentPersoneEventsAfterMidnight = personEvents.FindAll(e => DateTime.Equals(e.Date, currentDate.AddDays(1)) && e.Time > TimeSpan.Zero && e.Time < person.Startday.Subtract(new TimeSpan(4, 0, 0))); currentPersoneEventsAfterMidnight.Sort(); var enter = currentPersonEvents.Any(c => c.Direction == Direction.In) ? currentPersonEvents.FirstOrDefault(c => c.Direction == Direction.In)? .Time ?? (currentPersonEvents.FirstOrDefault() ?.Time ?? TimeSpan.MinValue) : TimeSpan.MinValue; var outgo = currentPersoneEventsAfterMidnight.Any() ? currentPersoneEventsAfterMidnight.LastOrDefault() .Time : (currentPersonEvents.Any(c => c.Direction == Direction.Out || c.Time > person.Endday) ? currentPersonEvents.LastOrDefault(c => c.Direction == Direction.Out || c.Time > person.Endday) ?.Time ?? TimeSpan.MinValue : TimeSpan.MinValue); var description = ""; if (enter == TimeSpan.MinValue && outgo == TimeSpan.MinValue) { description = "Административный"; } //var eventsCurrentDateEnter = personEvents.FindAll(e => DateTime.Equals(e.Date, currentDate) // && e.Direction == Direction.In); //var description = ""; //var eventsCurrentDateOut = personEvents.FindAll(e => // (DateTime.Equals(e.Date, currentDate) || // (DateTime.Equals(e.Date, currentDate.AddDays(1)) // && (e.Time > TimeSpan.Zero && e.Time < person.Startday))) // && e.Direction == Direction.Out); //var enter = TimeSpan.MinValue; //if (eventsCurrentDateEnter.Count == 0) //{ // description = eventsCurrentDateOut.Count == 0 // ? "Административный" // : (eventsCurrentDateOut.Count == 1 // ? "Не отметился, не возможно определить время прихода" // : $"Не отметился, предполагаемое время прихода {TimeSpan.FromMilliseconds(eventsCurrentDateOut.ElementAt(0).Time.TotalMilliseconds - (eventsCurrentDateOut.ElementAt(1).Time.TotalMilliseconds / 2))}" // ); //} //else //{ // enter = eventsCurrentDateEnter.FirstOrDefault() // ?.Time // ?? TimeSpan.MinValue; //} //var outer = TimeSpan.MinValue; //if (eventsCurrentDateOut.Count == 0) //{ // description = eventsCurrentDateEnter.Count == 0 // ? "Административный" // : (eventsCurrentDateEnter.Count == 1 // ? "Не отметился, не возможно определить время ухода" // : $"Не отметился, последний зарегестрированный вход {eventsCurrentDateEnter.Last().Time}"); //} //else //{ // var index = personEvents.IndexOf(eventsCurrentDateOut.Last()); // if (index == personEvents.Count - 1) // { // outer = eventsCurrentDateOut.Last() // .Time; // } // else // { // outer = personEvents.ElementAt(index + 1) // .Direction == Direction.In // ? eventsCurrentDateOut.Last() // .Time // : personEvents.FindAll(p => DateTime.Equals(p.Date, currentDate) || // (DateTime.Equals(p.Date, currentDate.AddDays(1)) && // (p.Time < person.Startday)) && // p.Direction == Direction.Out).Last()?.Time ?? TimeSpan.Zero; // } //} person.VisitList .Add(new Visit(currentDate, enter, outgo, description)); personEvents.RemoveAll(p => currentPersonEvents.Contains(p) || currentPersoneEventsAfterMidnight.Contains(p)); } persons.Add(person); } return(persons); }
private List <Person> GetPersons() { var persons = new List <Person>(); var workEvents = GetWorkEvents() ?? new List <WorkEvent>(); while (workEvents.Count > 0) { var person = new Person(workEvents.FirstOrDefault() ?.UserName); person.SetWorkTime(FiveClockWorkers); var personEvents = workEvents.FindAll(e => string.Equals(e.UserName, person.Name)); workEvents.RemoveAll(e => string.Equals(e.UserName, person.Name)); while (personEvents.Count > 0) { WorkEvent first = null; foreach (var @event in personEvents) { first = @event; break; } if (first == null) { continue; } var currentDate = first.Date; var eventsCurrentDateEnter = personEvents.FindAll(e => DateTime.Equals(e.Date, currentDate) && e.Direction == Direction.In); var description = ""; var eventsCurrentDateOut = personEvents.FindAll(e => (DateTime.Equals(e.Date, currentDate) || (DateTime.Equals(e.Date, currentDate.AddDays(1)) && (e.Time > TimeSpan.Zero && e.Time < person.Startday))) && e.Direction == Direction.Out); var enter = TimeSpan.MinValue; if (eventsCurrentDateEnter.Count == 0) { description = eventsCurrentDateOut.Count == 0 ? "Административный" : (eventsCurrentDateOut.Count == 1 ? "Не отметился, не возможно определить время прихода" : $"Не отметился, предполагаемое время прихода {TimeSpan.FromMilliseconds(eventsCurrentDateOut.ElementAt(0).Time.TotalMilliseconds - (eventsCurrentDateOut.ElementAt(1).Time.TotalMilliseconds / 2))}" ); } else { enter = eventsCurrentDateEnter.FirstOrDefault() ?.Time ?? TimeSpan.MinValue; } var outer = TimeSpan.MinValue; if (eventsCurrentDateOut.Count == 0) { description = eventsCurrentDateEnter.Count == 0 ? "Административный" : (eventsCurrentDateEnter.Count == 1 ? "Не отметился, не возможно определить время ухода" : $"Не отметился, последний зарегестрированный вход {eventsCurrentDateEnter.Last().Time}"); } else { var index = personEvents.IndexOf(eventsCurrentDateOut.Last()); if (index == personEvents.Count - 1) { outer = eventsCurrentDateOut.Last() .Time; } else { outer = personEvents.ElementAt(index + 1) .Direction == Direction.In ? eventsCurrentDateOut.Last() .Time : personEvents.FindAll(p => DateTime.Equals(p.Date, currentDate) || (DateTime.Equals(p.Date, currentDate.AddDays(1)) && (p.Time < person.Startday)) && p.Direction == Direction.Out).Last()?.Time ?? TimeSpan.Zero; } } person.VisitList .Add(new Visit(currentDate, enter, outer, description)); personEvents.RemoveAll(p => DateTime.Equals(p.Date, currentDate)); } persons.Add(person); } return(persons); }