public static List<SpecialReportRow> DayReport_Level3(DateTime? startTime, DateTime? endTime, int levelid)
        {
            List<SpecialReportRow> result = new List<SpecialReportRow>();
            List<EventRowWithAllColumns> rows = GetEventRows_Level3(startTime, endTime, levelid);

            if (rows != null)
            {
                DateTime r_starttime, r_endTime;
                r_starttime = (startTime.HasValue ? startTime.Value : rows.Min(o => o.EventStart).Value);
                //查询时结束日期是多一天的
                r_endTime = (endTime.HasValue ? endTime.Value.AddDays(-1) : rows.Max(o => o.EventStart).Value);

                for (var i = 0; i <= r_endTime.Subtract(r_starttime).TotalDays; i++)
                {
                    var q = from o in rows
                            where o.EventStart.Value.ToString(@"MM\/dd\/yyyy") == r_starttime.AddDays(i).ToString(@"MM\/dd\/yyyy")
                            select o;

                    List<EventRowWithAllColumns> r = q.ToList();
                    SpecialReportRow srr = new SpecialReportRow(); ;
                    srr.Title = r_starttime.AddDays(i).ToString(@"MM\/dd");
                    if (r != null)
                    {
                        srr.Minutes = r.Sum(o => o.Minutes);
                        srr.Occurences = r.Count();

                    }
                    else
                    {
                        srr.Minutes = 0;
                        srr.Occurences = 0;

                    }
                    result.Add(srr);
                }
            }

            int occ_total = result.Sum(o => o.Occurences);
            decimal? min_total = result.Sum(o => o.Minutes);
            foreach (SpecialReportRow item in result)
            {
                item.MinutesPercent = min_total == 0 ? 0 : (min_total == 0 ? 0 : item.Minutes.Value / min_total.Value * 100);
                item.OccurencesPercent = occ_total == 0 ? 0 : occ_total == 0 ? 0 : item.Occurences / occ_total * 100;
            }

            return result;
        }
        public static List<SpecialReportRow> HoursReport_Level3(DateTime? startTime, DateTime? endTime, int levelid)
        {
            List<SpecialReportRow> result = new List<SpecialReportRow>();
            List<EventRowWithAllColumns> rows = GetEventRows_Level3(startTime, endTime, levelid);
            if (rows != null)
            {
                for (var i = 0m; i < 24m; i += 0.5m)
                {
                    var q = from o in rows
                            where (o.EventStart.Value.Hour >= i && o.EventStart.Value.Hour < i + 0.5m)
                            select o;

                    List<EventRowWithAllColumns> r = q.ToList();
                    SpecialReportRow srr = new SpecialReportRow(); ;
                    srr.Title = SecondToHoursString(Convert.ToInt32(i * 3600));
                    if (r != null)
                    {
                        srr.Minutes = r.Sum(o => o.Minutes);
                        srr.Occurences = r.Count();

                    }
                    else
                    {
                        srr.Minutes = 0;
                        srr.Occurences = 0;

                    }
                    result.Add(srr);
                }
            }

            int occ_total = result.Sum(o => o.Occurences);
            decimal? min_total = result.Sum(o => o.Minutes);
            foreach (SpecialReportRow item in result)
            {
                item.MinutesPercent = min_total == 0 ? 0 : item.Minutes.Value / min_total.Value * 100;
                item.OccurencesPercent = occ_total == 0 ? 0 : item.Occurences / occ_total * 100;
            }
            return result;
        }
        public static List<SpecialReportRow> YearReport(DateTime? startTime, DateTime? endTime, string level1)
        {
            List<SpecialReportRow> result = new List<SpecialReportRow>();
            List<EventRowWithAllColumns> rows = GetEventRows(startTime, endTime, level1);

            DateTime r_starttime, r_endTime;
            r_starttime = (startTime.HasValue ? startTime.Value : rows.Min(o => o.EventStart).Value);
            //查询时结束日期是多一天的
            r_endTime = (endTime.HasValue ? endTime.Value.AddDays(-1) : rows.Max(o => o.EventStart).Value);
            foreach (var item in DateTimeHelper.SplitYears(r_starttime, r_endTime))
            {
                var q = from o in rows
                        where o.EventStart.Value.ToString(@"yyyy") == item.ToString()
                        select o;

                List<EventRowWithAllColumns> r = q.ToList();
                SpecialReportRow srr = new SpecialReportRow(); ;
                srr.Title = item.ToString();
                if (r != null)
                {
                    srr.Minutes = r.Sum(o => o.Minutes);
                    srr.Occurences = r.Count();

                }
                else
                {
                    srr.Minutes = 0;
                    srr.Occurences = 0;

                }
                result.Add(srr);
            }

            int occ_total = result.Sum(o => o.Occurences);
            decimal? min_total = result.Sum(o => o.Minutes);
            foreach (SpecialReportRow item in result)
            {
                item.MinutesPercent = min_total == 0 ? 0 : item.Minutes.Value / min_total.Value * 100;
                item.OccurencesPercent = occ_total == 0 ? 0 : item.Occurences / occ_total * 100;
            }

            return result;
        }
        public static List<SpecialReportRow> HoursReport_Level3_DateRange(DateTime? startTime, DateTime? endTime, int levelid)
        {
            List<SpecialReportRow> result = new List<SpecialReportRow>();
            List<EventRowWithAllColumns> rows = null;

            if (levelid > 0)
                rows = GetEventRows_Level3(startTime, endTime, levelid);
            else
                rows = GetEventRows(startTime, endTime, "");

            decimal diff = (decimal)startTime.Value.Subtract(endTime.Value).TotalHours;

            if (diff > 0)
                diff = diff * -1;

            rows = rows.OrderBy(o => o.EventStart.Value.Day).ThenBy(o => o.EventStart.Value.Hour).ToList();

            if (rows != null)
            {
                DateTime date = new DateTime(startTime.Value.Year, startTime.Value.Month, startTime.Value.Day, startTime.Value.Hour, 0, 0);

                for (var i = diff; i < 0.00m; i += 1.0m)
                {
                    //decimal num = (decimal)GetHourByNumber((int)i);

                    if (date > endTime.Value)
                        break;

                    List<EventRowWithAllColumns> r = new List<EventRowWithAllColumns>();

                    var q = from o in rows
                            where (o.EventStart.Value.Hour == date.Hour)
                            && (o.EventStart.Value.Day == date.Day)
                            select o;

                    r = q.ToList();

                    SpecialReportRow srr = new SpecialReportRow();

                    string title = string.Empty;

                    int t = (date.Hour == 0 ? 12 : date.Hour);
                    string day = date.Date.ToString("MM/dd");
                    int m = date.Minute;

                    if (date.Hour < 12)
                        title = day + " " + t + ":" + m + " AM";
                    else
                    {
                        t = t - 12;

                        if (t == 0)
                            t = 12;

                        title = day + " " + t + ":" + m + " PM";
                    }

                    srr.Title = title;//SecondToHoursString(Convert.ToInt32(i * 3600));
                    if (r != null)
                    {
                        srr.Minutes = r.Sum(o => o.Minutes);
                        srr.Occurences = r.Count();

                    }
                    else
                    {
                        srr.Minutes = 0;
                        srr.Occurences = 0;

                    }

                    result.Add(srr);

                    if (date.Hour == 23)
                    {
                        date = date.AddDays(1);
                        date = date.AddHours(-23);
                    }
                    else
                        date = date.AddHours(1);
                }
            }

            int occ_total = result.Sum(o => o.Occurences);
            decimal? min_total = result.Sum(o => o.Minutes);
            foreach (SpecialReportRow item in result)
            {
                item.MinutesPercent = min_total == 0 ? 0 : item.Minutes.Value / min_total.Value * 100;
                item.OccurencesPercent = occ_total == 0 ? 0 : item.Occurences / occ_total * 100;
            }
            return result;
        }