void DoRepeatSched() { using (SecureDBEntities1 db = new SecureDBEntities1()) { tblSchConfig sch = db.tblSchConfig.Where(n => n.SchID == config.SchID).FirstOrDefault(); if (sch.NextStartTime == null || ((DateTime)sch.NextStartTime).DayOfWeek != DateTime.Now.DayOfWeek) { try { ReportAutoPrint.ReportServer.PrintRoport(config.ReportID); Console.WriteLine("invoke rptid:" + config.ReportID); tblSchLog log = new tblSchLog() { TimeStamp = DateTime.Now, ReportID = sch.ReportID, SchID = sch.SchID, Result = true }; db.tblSchLog.Add(log); // db.SaveChanges(); } catch (Exception ex) { tblSchLog log = new tblSchLog() { TimeStamp = DateTime.Now, ReportID = sch.ReportID, SchID = sch.SchID, Result = false ,Memo=ex.Message}; db.tblSchLog.Add(log); // db.SaveChanges(); } Console.WriteLine("Do report:" + config.ReportID); sch.NextStartTime = DateTime.Now; db.SaveChanges(); } } }
public void CheckSchedule() { if (config.SchType == 0) //執行一次 { if (DateTime.Now >= config.StartTime && config.NextStartTime==null) { config.NextStartTime = config.StartTime; SecureServer.SecureDBEntities1 db = new SecureDBEntities1(); tblSchConfig sch= db.tblSchConfig.Where(n => n.SchID == config.SchID).FirstOrDefault(); if (sch != null) { sch.NextStartTime = config.NextStartTime; // sch.Enable = false; db.SaveChanges(); } try { ReportAutoPrint.ReportServer.PrintRoport(config.ReportID); Console.WriteLine("invoke rptid:" + config.ReportID); tblSchLog log = new tblSchLog() { TimeStamp = DateTime.Now, ReportID = sch.ReportID, SchID = sch.SchID, Result = true }; db.tblSchLog.Add(log); db.SaveChanges(); } catch (Exception ex) { tblSchLog log = new tblSchLog() { TimeStamp = DateTime.Now, ReportID = sch.ReportID, SchID = sch.SchID, Result = false,Memo=ex.Message }; db.tblSchLog.Add(log); db.SaveChanges(); } db.Dispose(); } } else if (config.SchType == 1)//重複執行 { DayOfWeek dayofweek = DateTime.Now.DayOfWeek; double diffmin=DiffMin( ); if(diffmin >=0 && diffmin < 10) DoRepeatSched(); return; if(dayofweek== DayOfWeek.Sunday && config.Week1==true && diffmin >=0 && diffmin < 10) DoRepeatSched(); else if(dayofweek== DayOfWeek.Monday && config.Week2==true && diffmin >=0 && diffmin < 10) DoRepeatSched(); else if(dayofweek== DayOfWeek.Tuesday && config.Week3==true && diffmin >=0 && diffmin < 10) DoRepeatSched(); else if (dayofweek == DayOfWeek.Wednesday&& config.Week4 == true && diffmin >= 0 && diffmin < 10) DoRepeatSched(); else if (dayofweek == DayOfWeek.Thursday && config.Week5 == true && diffmin >= 0 && diffmin < 10) DoRepeatSched(); else if (dayofweek == DayOfWeek.Friday && config.Week6 == true && diffmin >= 0 && diffmin < 10) DoRepeatSched(); else if (dayofweek == DayOfWeek.Saturday && config.Week7 == true && diffmin >= 0 && diffmin < 10) DoRepeatSched(); } }