示例#1
0
        public DateTime?GetNextTime(DateTime current)
        {
            if (SecondType == CronFieldType.Specified && !Seconds.Any())
            {
                throw new ArgumentException("Seconds are Empty.");
            }
            if (MinuteType == CronFieldType.Specified && !Minutes.Any())
            {
                throw new ArgumentException("Minutes are Empty.");
            }
            if (HourType == CronFieldType.Specified && !Hours.Any())
            {
                throw new ArgumentException("Hours are Empty.");
            }
            if (DayType == CronFieldType.Specified && !Days.Any())
            {
                throw new ArgumentException("Days are Empty.");
            }
            if (MonthType == CronFieldType.Specified && !Months.Any())
            {
                throw new ArgumentException("Months are Empty.");
            }
            if (DayOfWeekType == CronFieldType.Specified && !DayOfWeeks.Any())
            {
                throw new ArgumentException("DayOfWeeks are Empty.");
            }
            if (YearType == CronFieldType.Specified && !Years.Any())
            {
                throw new ArgumentException("Years are Empty.");
            }

            return(NextSecond(current.Year, current.Month, current.Day, current.Hour, current.Minute, current.Second));
        }
示例#2
0
        public HoursOfMonth(string UserId, int Year, int Month)
        {
            this.Year = Year;
            this.Month = Month;

            // Verifico se il mese e congelato
            this.Frozen = db.MonthsFrozen.Any(x => x.Year == Year && x.Month == Month);

            //Carico le ore annuali
            this.HoursOfYear = new HoursOfYear(UserId, Year);

            var wtExcludes = new WorkType[] { WorkType.Default, WorkType.Lavoro, WorkType.Straordinario, WorkType.Viaggio, WorkType.PermessoRetribuito };
            var report = Hours.Where(x => ! wtExcludes.Contains(x.WorkTypeRegular))
                    .GroupBy(x => x.WorkTypeRegular)
                    .Select(x => new HoursReport
                    {
                        Id = (int)x.Key,
                        Description = x.Key.Description(),
                        Value = GetReport(x)
                    }).ToList();
            // Aggiungo ordinario previsto
            report.Add(new HoursReport
            {
                Id = 0,
                Description = "Ordinario Previsto",
                Value = TimeSpan.FromSeconds(Hours.Sum(x => x.Ordinary.TotalSeconds))
            });
            // Aggiungo ordinario effettuato
            report.Add(new HoursReport
            {
                Id = 1,
                Description = "Ordinario Svolto",
                Value = TimeSpan.FromSeconds(Hours.Sum(x => x.WorkTimeOrdinary.TotalSeconds))
            });
            // Aggiungo Straordinario
            if (Hours.Any(x => x.ExtraRegular > TimeSpan.Zero))
            {
                report.Add(new HoursReport
                {
                    Id = 2,
                    Description = WorkType.Straordinario.Description(),
                    Value = TimeSpan.FromSeconds(Hours.Sum(x => x.ExtraRegular.TotalSeconds))
                });
            }

            // Aggiungo le Presenze
            report.Add(new HoursReport
            {
                Id = 997,
                Description = "Presenze",
                Value = Hours.Count(x => x.Presence)
            });
            // Aggiungo la Trasferta
            var trasf = Hours.Where(x => x.OffSite);
            if (trasf.Any())
            {
                report.Add(new HoursReport
                {
                    Id = 997,
                    Description = "Trasferta",
                    Value = trasf.Count()
                });
            }
            // Aggiungo Viaggio
            if (Hours.Any(x => x.OrdersTimeTravel > TimeSpan.Zero))
            {
                report.Add(new HoursReport
                {
                    Id = 999,
                    Description = WorkType.Viaggio.Description(),
                    Value = TimeSpan.FromSeconds(Hours.Sum(x => x.OrdersTimeTravel.TotalSeconds))
                });
            }
            // Permesso retribuito
            var permes = Hours.Where(x => x.Holiday != null && x.Holiday == Holiday.Holiday_Type.Permesso);
            if (permes.Any())
            {
                report.Add(new HoursReport
                {
                    Id = 5,
                    Description = WorkType.PermessoRetribuito.Description(),
                    Value = TimeSpan.FromSeconds(permes.Sum(x => x.HolidayTime.TotalSeconds))
                });
            }
            Report = report.OrderBy(x => x.Id).ToArray();
        }