public static GoalReportRow GetGoals(DateTime startTime, DateTime endTime)
        {
            using (DB db = new DB())
            {
                var q = from o in db.GoalSet
                        where o.StartTime <= startTime && o.EndTime >= endTime
                        && o.CLIENT==Filter_Client
                        && o.LINE==Filter_Line
                        select o;
                int? totalOcc = null;
                try
                {
                    totalOcc = q.Sum(o => o.Occuring);
                }
                catch (Exception)
                {

                    //throw;
                }

                decimal? totalTime = null;
                try
                {
                    totalTime = q.Sum(o => o.Dowmtime);
                }
                catch (Exception)
                {

                    // throw;
                }

                if (!totalOcc.HasValue) totalOcc = 0;
                if (!totalTime.HasValue) totalTime = 0;

                decimal totalDays = 0;//Math.Abs(Convert.ToDecimal( endTime.Subtract(startTime).TotalDays));

                foreach (var item in q.ToList())
                {
                    totalDays += Convert.ToDecimal(item.EndTime.Subtract(item.StartTime).TotalDays);
                }

                if (totalDays == 0) totalDays = 1m;
                GoalReportRow grr = new GoalReportRow();
                grr.Downtimes.Hour = totalTime.Value / (totalDays * 24);
                grr.Downtimes.Day = totalTime.Value / totalDays;
                grr.Downtimes.Week = totalTime.Value / (totalDays / 7);
                grr.Downtimes.Month = totalTime.Value / (totalDays / 30);
                grr.Downtimes.Year = totalTime.Value / (totalDays / 365);

                grr.Occurences.Hour = Convert.ToInt32(totalOcc.Value / (totalDays * 24));
                grr.Occurences.Day = Convert.ToInt32(totalOcc.Value / totalDays);
                grr.Occurences.Week = Convert.ToInt32(totalOcc.Value / (totalDays / 7));
                grr.Occurences.Month = Convert.ToInt32(totalOcc.Value / (totalDays / 30));
                grr.Occurences.Year = Convert.ToInt32(totalOcc.Value / (totalDays / 365));

                return grr;
            }
        }
        public static GoalReportRow GetGoals(DateTime startTime, DateTime endTime)
        {
            using (DB db = new DB(DBHelper.GetConnectionString(Filter_Client)))
            {
                var q = from o in db.GoalSet
                        where o.StartTime >= startTime
                        && o.EndTime < endTime
                        && o.CLIENT == Filter_Client
                        && o.LINE == Filter_Line
                        select o;

                List<Goal> list = new List<Goal>();

                if (q.Any())
                    list = q.ToList();

                int totalOcc = 0;
                decimal totalTime = 0m;

                decimal totalDays = 0;//Math.Abs(Convert.ToDecimal( endTime.Subtract(startTime).TotalDays));

                foreach (var item in list)
                {
                    totalDays += Convert.ToDecimal(item.EndTime.Subtract(item.StartTime).TotalDays);
                    totalOcc += item.Occuring;
                    totalTime += item.Dowmtime;
                }

                if (totalDays == 0) totalDays = 1m;
                GoalReportRow grr = new GoalReportRow();
                grr.Downtimes.Hour = totalTime / (totalDays * 24);
                grr.Downtimes.Day = totalTime / totalDays;
                grr.Downtimes.Week = totalTime / (totalDays / 7);
                grr.Downtimes.Month = totalTime / (totalDays / 30);
                grr.Downtimes.Year = totalTime / (totalDays / 365);

                grr.Occurences.Hour = Convert.ToInt32(totalOcc / (totalDays * 24));
                grr.Occurences.Day = Convert.ToInt32(totalOcc / totalDays);
                grr.Occurences.Week = Convert.ToInt32(totalOcc / (totalDays / 7));
                grr.Occurences.Month = Convert.ToInt32(totalOcc / (totalDays / 30));
                grr.Occurences.Year = Convert.ToInt32(totalOcc / (totalDays / 365));

                return grr;
            }
        }