using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace JobReportMailService { public partial class fNoScheduleDayWeek : fChildBase { public fNoScheduleDayWeek() { InitializeComponent(); } private void fJobReportDay_Load(object sender, EventArgs e) { task = Task.Run(() => { while (taskrun) { if (taskwait) { if (task != null) task.Wait(1000); continue; } var ts = DateTime.Now - ChkMakeSchDayWeekTime; if (ts.TotalMinutes <= 15) { if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { addmsg("15분 미만이라 동작하지 않습니다"); ConsoleTime = DateTime.Now; } } else if (DateTime.Now.DayOfWeek != DayOfWeek.Monday) { //토,일요일에는 동작하지 않는다 if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { addmsg("월요일에만 동작 합니다"); ConsoleTime = DateTime.Now; } } else if (DateTime.Now.Hour < 10) //10시부터 동작한다 { if ((DateTime.Now - ConsoleTime).TotalHours >= 1.0) { addmsg("9시 이전에는 동작하지 않습니다"); ConsoleTime = DateTime.Now; } } else { ChkMakeSchDayWeekTime = DateTime.Now; try { RunData(); } catch (Exception ex) { addmsg(ex.Message); using (var ta = new DataSet1TableAdapters.MailDataTableAdapter()) { using (var dt = new DataSet1.MailDataDataTable()) { var newdr = dt.NewMailDataRow(); newdr.gcode = "EET1P"; newdr.cate = "ER"; newdr.subject = "[ERROR] 스케쥴없음 메일작성 실패"; newdr.fromlist = "chikyun.kim@amkor.co.kr"; newdr.tolist = "chikyun.kim@amkor.co.kr"; newdr.bcc = string.Empty; newdr.cc = string.Empty; newdr.pdate = DateTime.Now.ToShortDateString(); newdr.body = ex.Message; newdr.wuid = "dev"; newdr.wdate = DateTime.Now; newdr.EndEdit(); dt.AddMailDataRow(newdr); var cnt = ta.Update(dt); } } task.Wait(5000); } } Task.Delay(Delaytime).Wait(); } }); timer1.Start(); if (Pub.setting.autoRunData) btRun.PerformClick(); } void RunData() { addmsg("스케쥴입력(주) 미 작성자 추출 작업을 시작 합니다"); var db = new EEEntities(); //기준일자는 오늘부터 -15일이다 var sd = DateTime.Now.AddDays(-15); var ed = DateTime.Now; var str_sd = sd.ToShortDateString(); var str_ed = ed.ToShortDateString(); var str_dt = DateTime.Now.ToShortDateString(); var gcodelist = db.MailForm.GroupBy(t => t.gcode).ToList(); foreach (var gcodedata in gcodelist) { //메일양식이 지정되어있는지 체크 var vGcode = gcodedata.Key; if (string.IsNullOrEmpty(vGcode)) continue; //메일양식이 지정되어있는지 체크 var MailJD = db.MailForm.AsNoTracking().Where(t => t.gcode == vGcode & t.cate == "SN").FirstOrDefault(); if (MailJD == null) { //토,일요일에는 동작하지 않는다 addmsg($"[{vGcode}] 메일 양식(SN)이 입력되지 않았습니다"); continue; } if (MailJD.exceptmail == null) MailJD.exceptmail = string.Empty; if (MailJD.exceptmailcc == null) MailJD.exceptmailcc = string.Empty; //오늘날짜로 데이터가 등록되어있느지 확인한다. db = new EEEntities(); var Existweek = db.MailData.AsNoTracking().Where(t => t.gcode == vGcode && t.cate == "SN" && t.pdate == str_dt).Any(); if (Existweek) { addmsg($"[{vGcode}] 스케쥴(day)({str_dt}) 보고 메일이 이미 등록되어 있습니다"); continue; } //대상 사용자 목록을 추출한다 //var ta = new DataSet1TableAdapters.vMailingProjectScheduleTableAdapter(); //var users = new DataSet1.vMailingProjectScheduleDataTable(); //ta.Fill(users); db = new EEEntities(); var projects = db.Projects.AsNoTracking().Where(t => t.gcode == vGcode && t.status == "진행" && (t.isdel == null || t.isdel == false)).OrderBy(t => t.sdate).ToList(); // db.vMailingProjectSchedule.ToList();// .vJobReportForUser.Where(t => t.gcode == Pub.vGcode).GroupBy(t => t.id); addmsg($"[{vGcode}] {projects.Count} 건의 데이터가 확인 되었습니다"); //메일데이터 생성 var body = new System.Text.StringBuilder(); body.AppendLine("
| 시작일 | "); body.AppendLine("상태 | "); body.AppendLine("번호 | "); body.AppendLine("Project | "); body.AppendLine("요청 | "); body.AppendLine("Champion | "); body.AppendLine("협업 | "); body.AppendLine("만료일 | "); body.AppendLine("수량 | "); body.AppendLine("외주금액 | "); body.AppendLine("자체금액 | "); body.AppendLine("절감액 | "); body.AppendLine("CR/CF | "); body.AppendLine("
| {row.sdate} | "); body.AppendLine($"{row.status} | "); body.AppendLine($"{row.idx} | "); body.AppendLine($"{row.name} | "); body.AppendLine($"{row.reqstaff} | "); body.AppendLine($"{row.userManager} | "); body.AppendLine($"{row.usermain}/{row.usersub}/{row.userhw2} | "); body.AppendLine($"{row.edate} | "); body.AppendLine($"{row.cnt} | "); body.AppendLine($"{row.costo} | "); body.AppendLine($"{row.costn} | "); body.AppendLine($"{row.costo - row.costn} | "); body.AppendLine($"{row.orderno} | "); body.AppendLine($"