Esempio n. 1
0
 static void WorkOnDates(ILinqDbQueryable <LogEntry> res, int range, DateTime?from, DateTime?to)
 {
     if (range == 0)
     {
         from = DateTime.Now.AddDays(-1);
         to   = DateTime.Now;
     }
     else if (range == 1)
     {
         from = DateTime.Now.AddDays(-7);
         to   = DateTime.Now;
     }
     else if (range == 2)
     {
         from = DateTime.Now.AddMonths(-1);
         to   = DateTime.Now;
     }
     if (from != null || to != null)
     {
         if (from == null)
         {
             var first = Utils.Utils.db.Table <LogEntry>().OrderBy(f => f.Time).Take(1).Select(f => new { Time = f.Time }).FirstOrDefault();
             from = first == null ? DateTime.Now : first.Time;
         }
         if (to == null)
         {
             var last = Utils.Utils.db.Table <LogEntry>().OrderByDescending(f => f.Time).Take(1).Select(f => new { Time = f.Time }).FirstOrDefault();
             to = last == null ? DateTime.Now : last.Time;
         }
         if (((DateTime)to - (DateTime)from).TotalDays < 1)
         {
             res.Between(f => f.Time, (DateTime)from, (DateTime)to, BetweenBoundaries.BothInclusive);
         }
         else
         {
             var next = from.Value.AddDays(1);
             res.Between(f => f.Time, (DateTime)from, new DateTime(next.Year, next.Month, next.Day), BetweenBoundaries.BothInclusive);
             var      last_day = new DateTime(to.Value.Year, to.Value.Month, to.Value.Day);
             DateTime d;
             for (d = new DateTime(next.Year, next.Month, next.Day); d < last_day; d = d.AddDays(1))
             {
                 res.Or().Search(f => f.Day_string, d.ToString("yyyyMMdd"));
             }
             res.Or().Between(f => f.Time, d, (DateTime)to, BetweenBoundaries.BothInclusive);
         }
     }
 }
Esempio n. 2
0
 static void WorkOnDates(ILinqDbQueryable<LogEntry> res, int range, DateTime? from, DateTime? to)
 {
     if (range == 0)
     {
         from = DateTime.Now.AddDays(-1);
         to = DateTime.Now;
     }
     else if (range == 1)
     {
         from = DateTime.Now.AddDays(-7);
         to = DateTime.Now;
     }
     else if (range == 2)
     {
         from = DateTime.Now.AddMonths(-1);
         to = DateTime.Now;
     }
     if (from != null || to != null)
     {
         if (from == null)
         {
             var first = Utils.Utils.db.Table<LogEntry>().OrderBy(f => f.Time).Take(1).Select(f => new { Time = f.Time }).FirstOrDefault();
             from = first == null ? DateTime.Now : first.Time;
         }
         if (to == null)
         {
             var last = Utils.Utils.db.Table<LogEntry>().OrderByDescending(f => f.Time).Take(1).Select(f => new { Time = f.Time }).FirstOrDefault();
             to = last == null ? DateTime.Now : last.Time;
         }
         if (((DateTime)to - (DateTime)from).TotalDays < 1)
         {
             res.Between(f => f.Time, (DateTime)from, (DateTime)to, BetweenBoundaries.BothInclusive);
         }
         else
         {
             var next = from.Value.AddDays(1);
             res.Between(f => f.Time, (DateTime)from, new DateTime(next.Year, next.Month, next.Day), BetweenBoundaries.BothInclusive);
             DateTime d;
             for (d = new DateTime(next.Year, next.Month, next.Day); d <= to.Value.AddDays(-1); d = d.AddDays(1))
             {
                 res.Or().Search(f => f.Day_string, d.ToString("yyyyMMdd"));
             }
             d = d.AddDays(-1);
             res.Or().Between(f => f.Time, d, (DateTime)to, BetweenBoundaries.BothInclusive);
         }
     }
 }