using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JobReportMailService { partial class Program { static CSetting setting = new CSetting(); static DateTime ChkAutoDate = DateTime.Now.AddDays(-1); static string vGcode = "EET1P"; static bool cn = false; static DateTime LastUpdateTime = DateTime.Now.AddHours(-1); static DateTime ConsoleTime = DateTime.Now.AddDays(-1); static void Main(string[] args) { setting = new CSetting(); setting.Load(); if (setting.Xml.Exist() == false) { Console.WriteLine("new setting file make"); setting.Save(); } while (true) { //등록된 날짜를 확인하여, 해당 일자가 일반 평일 이라면 8시간 체크해서 메일을 보낸다. //등록된 날짜가 토,일은 제외한다. var ts = DateTime.Now - LastUpdateTime; if (ts.TotalMinutes <= 15) { //15분 미만이면 동작하지 않는다 if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { Console.WriteLine("15분 미만이라 동작하지 않습니다"); ConsoleTime = DateTime.Now; } } else if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday) { //토,일요일에는 동작하지 않는다 if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { Console.WriteLine("토/일에는 동작하지 않습니다"); ConsoleTime = DateTime.Now; } } else if (DateTime.Now.Hour < 9) { if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { Console.WriteLine("9시 이전에는 동작하지 않습니다"); ConsoleTime = DateTime.Now; } } else { LastUpdateTime = DateTime.Now; try { WorkDay(); } catch (Exception ex) { Console.WriteLine("일간업무알림 실패: " + ex.Message); } try { WorkWeek(); } catch (Exception ex) { Console.WriteLine("주간업무알림 실패: " +ex.Message); } } System.Threading.Thread.Sleep(60000); //1분단위로 체크한다 } } static string MailSort(string addr, string except) { if (string.IsNullOrEmpty(except)) return addr; var alist = addr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var elist = except.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var item in elist) alist.Remove(item); if (alist.Count < 1) return string.Empty; return string.Join(";", alist); } } }