- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
var dt = DateTime.Now;
var strTimeFilter = string.Empty;
switch (filter.TimeTypeId)
{
case 2:
strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-01 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 3:
strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-1).ToString("yyyy-MM-dd hh:mm:ss.fff") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 4:
strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-1).ToString("yyyy-MM-01 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 5:
strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-2).ToString("yyyy-MM-01 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 6:
strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-5).ToString("yyyy-MM-01 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 7:
strTimeFilter = "r.StartDateTime>='" + dt.AddYears(-1).ToString("yyyy-MM-dd hh:mm:ss.fff") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
break;
case 8:
strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-dd 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd 23:59:59.999") + "'";
break;
case 9:
strTimeFilter = "r.StartDateTime>='" + dt.AddDays(1).ToString("yyyy-MM-dd 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + dt.AddDays(1).ToString("yyyy-MM-dd 23:59:59.999") + "'";
break;
case 10:
strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-dd 00:00:00.000") + "'";
break;
case -1:
var fds = filter.FirstTime.ToTrim();
var lds = filter.LastTime.ToTrim();
if (!string.IsNullOrEmpty(fds) && string.IsNullOrEmpty(lds))
{
DateTime fd;
if (DateTime.TryParse(fds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out fd))
{
strTimeFilter = " r.StartDateTime>='" + fd.ToString("yyyy-MM-dd 00:00:00.000") + "' ";
}
}
else if (string.IsNullOrEmpty(fds) && !string.IsNullOrEmpty(lds))
{
DateTime ld;
if (DateTime.TryParse(lds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out ld))
{
strTimeFilter = " r.ExpirationDateTime<='" + ld.ToString("yyyy-MM-dd 23:59:59.999") + "' ";
}
}
else if (!string.IsNullOrEmpty(fds) && !string.IsNullOrEmpty(lds))
{
DateTime fd, ld;
if (DateTime.TryParse(fds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out fd)
&& DateTime.TryParse(lds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out ld))
{
strTimeFilter = "r.StartDateTime>='" + DateTime.Parse(filter.FirstTime, new CultureInfo("ru-RU", false)).ToString("yyyy-MM-dd 00:00:00.000") +
"' AND r.ExpirationDateTime<='" + DateTime.Parse(filter.LastTime, new CultureInfo("ru-RU", false)).ToString("yyyy-MM-dd 23:59:59.999") + "'";
}
}
break;
}
Это часть метода для формирования where-clause SQL-запроса для фильтра данных по дате вида "Сегодня", "Вчера", "За последний месяц", "За последние два месяца" и т. п.