Ejemplo n.º 1
0
        private void SortRanges_Click(object sender, RoutedEventArgs e)
        {
            if (SortDirection == -1)
            {
                SortDirection = 0;
            }
            else
            {
                SortDirection ^= 1;
            }
            if (SortDirection == 0)
            {
                WorksTimeRanges = WorksTimeRanges.OrderBy(r => r.range.StartTime).ToList();
            }
            else
            {
                WorksTimeRanges = WorksTimeRanges.OrderByDescending(r => r.range.StartTime).ToList();
            }

            NotifyPropertyChanged("WorksTimeRanges");
        }
Ejemplo n.º 2
0
        private void UpdateStatus()
        {
            Dictionary <DateTime, DateTime> brakes = new Dictionary <DateTime, DateTime>();
            var incorrectRanges = WorksTimeRanges.Where(r => r.range.StartTime.Year != 1899 || r.range.EndTime.Year != 1899).ToList();

            incorrectRanges.ForEach(r => r.range.StartTime = new DateTime(1899, 12, 30, r.range.StartTime.Hour, r.range.StartTime.Minute, 0));
            incorrectRanges.ForEach(r => r.range.EndTime   = new DateTime(1899, 12, 30, r.range.EndTime.Hour, r.range.EndTime.Minute, 0));
            WorksTimeRanges = WorksTimeRanges.OrderBy(r => r.range.StartTime).ToList();
            double sumTime = 0;

            if (LastSelected != null)
            {
                LastSelected.Selected = false;
            }
            ReasonText = "";
            DateTime?last = null;

            foreach (var rng in WorksTimeRanges)
            {
                if (last != null)
                {
                    if (rng.range.StartTime < last.Value)
                    {
                        ReasonText   = "Диапазоны перекрываются";
                        rng.Selected = true;
                        LastSelected = rng;
                        IsCorrect    = false;
                        return;
                    }
                    if ((DateTime)last != rng.range.StartTime)
                    {
                        brakes.Add((DateTime)last, rng.range.StartTime);
                    }
                }
                last = rng.range.EndTime;
                var duration = (rng.range.EndTime - rng.range.StartTime);
                sumTime += duration.Hours * 60 + duration.Minutes;
            }
            int cnt = 0;

            foreach (var brakeRange in brakes)
            {
                if (cnt == IdealBrakeRanges.Count || brakeRange.Key.Hour != IdealBrakeRanges[cnt].StartHours || brakeRange.Key.Minute != IdealBrakeRanges[cnt].StartMinutes ||
                    brakeRange.Value.Hour != IdealBrakeRanges[cnt].EndHours || brakeRange.Value.Minute != IdealBrakeRanges[cnt].EndMinutes)
                {
                    ReasonText = "Перерывы не совпадают";
                    var badRange = WorksTimeRanges.FirstOrDefault(r => (r.range.StartTime.Hour == brakeRange.Value.Hour &&
                                                                        r.range.StartTime.Minute == brakeRange.Value.Minute) || (r.range.EndTime.Hour == brakeRange.Key.Hour &&
                                                                                                                                 r.range.EndTime.Minute == brakeRange.Key.Minute));
                    if (badRange != null)
                    {
                        badRange.Selected = true;
                        LastSelected      = badRange;
                    }
                    IsCorrect = false;
                    return;
                }
                cnt++;
            }
            if (cnt < IdealBrakeRanges.Count)
            {
                ReasonText = "Перерывов меньше, чем требуется";
                var breakRange = IdealBrakeRanges[cnt];
                var badRange   = WorksTimeRanges.FirstOrDefault(r => r.range.EndTime.Hour * 60 + r.range.EndTime.Minute > breakRange.StartHours * 60 + breakRange.StartMinutes);
                if (badRange != null)
                {
                    badRange.Selected = true;
                    LastSelected      = badRange;
                }
                IsCorrect = false;
                return;
            }
            if (sumTime != PlanningTime * 60)
            {
                ReasonText = "Планируемое и фактическое время не совпадают";
                IsCorrect  = false;
                return;
            }
            IsCorrect = true;
        }