public void Add(IssueDetails issue)
 {
     if (issues.Count == 0)
     {
         issues.Add(issue);
         return;
     }
     foreach (IssueDetails id in issues)
     {
         if ((issue.Raised < id.Raised) && (issue.Resolved <= id.Resolved)) // overlap case 1
         {
             issue.Resolved = id.Raised;
             issues.Add(issue);
             break;
         }
         else if ((issue.Raised >= id.Raised) && (issue.Resolved > id.Resolved)) // overlap case 2
         {
             issue.Raised = id.Resolved;
             issues.Add(issue);
             break;
         }
         else if ((issue.Raised >= id.Raised) && (issue.Raised <= id.Resolved)) //overlap case 3
         {
             continue;
         }
         else
         {
             issues.Add(issue);
             break;
         }
     }
 }
        void generateHourlySummary()
        {
            TimeSpan     temp = new TimeSpan(nextHourlyUpdateTiming.Value.Hour, nextHourlyUpdateTiming.Value.Minute - 6, nextHourlyUpdateTiming.Value.Second);
            int          id;
            Shift        s   = new Shift();
            List <Shift> shl = shifts.getShifts(temp);
            DataTable    dt;

            Availability[] availability = new Availability[lines.Count];
            for (int i = 0; i < lines.Count; i++)
            {
                availability[i] = new Availability();
            }


            foreach (Shift sl in shl)
            {
                if (sl.Name != "GEN SHIFT")
                {
                    s = sl;
                    break;
                }
            }

            Session se = s.getSession(temp);



            DateTime from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, stringtoTS(se.StartTime).Hours,
                                         stringtoTS(se.StartTime).Minutes, stringtoTS(se.StartTime).Seconds);

            DateTime to = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, stringtoTS(se.EndTime).Hours,
                                       stringtoTS(se.EndTime).Minutes, stringtoTS(se.EndTime).Seconds);

            dt = dataAccess.GetReportData(from, to);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                IssueDetails issueDetail = new IssueDetails();
                issueDetail.Line      = (int)dt.Rows[i]["LINE"];
                issueDetail.Station   = (int)dt.Rows[i]["STATION"];
                issueDetail.Tolerance = (int)dt.Rows[i]["Tolerance"];
                issueDetail.Raised    = (TimeSpan)dt.Rows[i]["Raised"];
                if (dt.Rows[i]["Resolved"] == DBNull.Value)
                {
                    issueDetail.Resolved = stringtoTS(se.EndTime);
                }
                else
                {
                    issueDetail.Resolved = (TimeSpan)dt.Rows[i]["Resolved"];
                    if (issueDetail.Resolved > stringtoTS(se.EndTime))
                    {
                        issueDetail.Resolved = stringtoTS(se.EndTime);
                    }
                }

                TimeSpan ToleranceLimit = new TimeSpan(0, issueDetail.Tolerance, 0);
                if (issueDetail.Resolved - issueDetail.Raised > ToleranceLimit)
                {
                    availability[issueDetail.Line - 1].Add(issueDetail);
                }
            }


            ContactCollection cl = dataAccess.getHourlyUpdateContacts();

            String hourlySummary = "Hourly Summary MCB Finishing" + "\r\n";

            for (int i = 0; i < 6; i++)
            {
                hourlySummary += "Line " + lines[i].ID.ToString() + ":" + getHourlyUpdateInfo(i, s.ID, se.ID) + ","
                                 + "Avl-" + (availability[i].getAvailability(stringtoTS(se.StartTime), stringtoTS(se.EndTime))).ToString() + "%";
                hourlySummary += "\r\n";
            }
            foreach (Contact c in cl)
            {
                dataAccess.insertSmsTrigger(c.Number, hourlySummary, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 5);
            }

            hourlySummary = "Hourly Summary " + "\r\n";

            for (int i = 6, j = 1; i < 8; i++, j++)
            {
                hourlySummary += "RCCB Finishing Line " + j.ToString() + ":" + getHourlyUpdateInfo(i, s.ID, se.ID) + ","
                                 + "Avl-" + (availability[i].getAvailability(stringtoTS(se.StartTime), stringtoTS(se.EndTime))).ToString() + "%";
                hourlySummary += "\r\n";
            }

            for (int i = 9, j = 1; i < 11; i++, j++)
            {
                hourlySummary += "TIMNH Finishing Line " + j.ToString() + ":" + getHourlyUpdateInfo(i, s.ID, se.ID) + ","
                                 + "Avl-" + (availability[i].getAvailability(stringtoTS(se.StartTime), stringtoTS(se.EndTime))).ToString() + "%";
                hourlySummary += "\r\n";
            }


            hourlySummary += "ADDITIM Line " + getHourlyUpdateInfo(8, s.ID, se.ID) + ","
                             + "Avl-" + (availability[8].getAvailability(stringtoTS(se.StartTime), stringtoTS(se.EndTime))).ToString() + "%";
            hourlySummary += "\r\n";



            foreach (Contact c in cl)
            {
                dataAccess.insertSmsTrigger(c.Number, hourlySummary, 1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 5);
            }
        }
        public void Add(IssueDetails issue)
        {
            if (issues.Count == 0)
            {
                issues.Add(issue);
                return;
            }
           foreach( IssueDetails id in issues)
           {

               if ((issue.Raised < id.Raised) && (issue.Resolved <= id.Resolved)) // overlap case 1
               {
                   issue.Resolved = id.Raised;
                   issues.Add(issue);
                   break;
               }
               else if ((issue.Raised >= id.Raised) && (issue.Resolved > id.Resolved)) // overlap case 2
               {
                   issue.Raised = id.Resolved;
                   issues.Add(issue);
                   break;
               }
               else if ((issue.Raised >= id.Raised) && (issue.Raised <= id.Resolved)) //overlap case 3
               {
                   continue;
               }
               else
               {
                   issues.Add(issue);
                   break ;
               }
           }
           
        }