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 - LastUpdateTime; 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 { LastUpdateTime = DateTime.Now; try { RunData(); } catch (Exception ex) { addmsg(ex.Message); task.Wait(5000); } } Task.Delay(Delaytime).Wait(); } }); timer1.Start(); } void RunData() { addmsg("스케쥴입력(주) 미 작성자 추출 작업을 시작 합니다"); var db = new EEEntities(); //메일양식이 지정되어있는지 체크 var MailJD = db.MailForm.AsNoTracking().Where(t => t.gcode == Pub.vGcode & t.cate == "SN").FirstOrDefault(); if (MailJD == null) { //토,일요일에는 동작하지 않는다 addmsg("메일 양식(SN)이 입력되지 않았습니다"); return; } //기준일자는 오늘부터 -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(); //오늘날짜로 데이터가 등록되어있느지 확인한다. db = new EEEntities(); var Existweek = db.MailData.AsNoTracking().Where(t => t.gcode == Pub.vGcode && t.cate == "SN" && t.wuid == "395552" && t.pdate == str_dt).Any(); if (Existweek) { addmsg($"스케쥴(day)({str_dt}) 보고 메일이 이미 등록되어 있습니다"); return; } //대상 사용자 목록을 추출한다 //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 == Pub.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($"{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($" |