private void Inital() { dgv_addrList.MultiSelect = false; tb_senderPWD.PasswordChar = '*'; btn_delAddress.Enabled = false; btn_alterAddress.Enabled = false; //tb_senderPWD.UseSystemPasswordChar = true; timer = new System.Timers.Timer((double)nud_checkSpan.Value * 1000); timer.Elapsed += new System.Timers.ElapsedEventHandler(timerPro); timer.AutoReset = true; sendM = new sendMail(); //timer.Start(); dgv_addrList.RowPostPaint += new DataGridViewRowPostPaintEventHandler(dgvRowRepaint); canEditRowIndex = 0; using (ksoaContext db = new ksoaContext()) { addr_List = (List <alarm_mailaddr>)(from q in db.alarm_MailAddr where q.IsDeleted == false select q).ToList(); dgv_addrList.DataSource = addr_List;// (from q in db.alarm_MailAddr where q.IsDeleted==false select q).ToList(); dgv_addrList.Columns["ID"].ReadOnly = true; dgv_addrList.Columns["ID"].Visible = false; } dgv_addrList.SelectionChanged += new EventHandler(dgv_addrList_selectChanged); (btn_startWork).Text = bol_running ? "暂停" : "启动"; if (!bol_running) { timer.Stop(); nud_checkSpan.Enabled = true; } else { timer.Start(); nud_checkSpan.Enabled = false; } timerPro(null, null); }
private void btn_addAddress_Click(object sender, EventArgs e) { Button btn = (Button)sender; alarm_mailaddr model = new alarm_mailaddr(); GetOrSetContext(ref model); if (!checkAddrModel(model)) { return; } btn.Enabled = false; using (ksoaContext db = new ksoaContext()) { db.alarm_MailAddr.Add(model); if (0 < db.SaveChanges()) { alarm_mailaddr loc_m = new alarm_mailaddr(); MessageBox.Show("添加成功!", "提示"); GetOrSetContext(ref loc_m, false); dataRefresh(); } else { MessageBox.Show("添加失败!", "提示"); } } btn.Enabled = true; }
private void btn_addNewG_Click(object sender, EventArgs e) { Button btn = (Button)sender; btn.Enabled = false; guid_CurEdit = Guid.Empty; GroupModel gm = new GroupModel(); getOrSetFormModel(ref gm, true, true); using (ksoaContext db = new ksoaContext()) { db.alarmAddr_realations.Add(gm.main); db.alarmAddr_realationsD.AddRange(gm.detials); if (db.SaveChanges() > 0) { MessageBox.Show("添加组成功!", "提示"); dataRefresh(); gm = new GroupModel(); gm.detials = new List <alarmAddr_realationsD>(); gm.main = new alarmAddr_realations(); getOrSetFormModel(ref gm, false); //listViewRefresh(); } else { MessageBox.Show("添加组失败!", "提示"); } } btn.Enabled = true; }
private void btn_delAddress_Click(object sender, EventArgs e) { Button btn = (Button)sender; btn.Enabled = false; if (dgv_addrList.SelectedRows.Count > 0) { var model = addr_List.Find(q => q.ID == int.Parse(dgv_addrList.SelectedRows[0].Cells["ID"].Value.ToString())); using (ksoaContext db = new ksoaContext()) { var query = db.alarm_MailAddr.Find(model.ID); query.IsDeleted = true; if (0 < db.SaveChanges()) { alarm_mailaddr loc_m = new alarm_mailaddr(); MessageBox.Show("删除成功!", "提示"); GetOrSetContext(ref loc_m, false); } else { MessageBox.Show("删除失败!", "提示"); } } dataRefresh(); } btn.Enabled = true; }
private void Inital() { //log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), DateTime.Now.ToString()); cb_isLimitSend.Checked = true; dtp_timeLimit.Format = DateTimePickerFormat.Time; //dtp_timeLimit.CustomFormat = "HH:mm:ss"; dtp_timeLimit.ShowUpDown = true; //MessageBox.Show(DateTime.Parse( dtp_timeLimit.Value.ToLongTimeString()).ToString()); dgv_addrList.MultiSelect = false; tb_senderPWD.PasswordChar = '*'; btn_delAddress.Enabled = false; btn_alterAddress.Enabled = false; //tb_senderPWD.UseSystemPasswordChar = true; timer = new System.Timers.Timer((double)nud_checkSpan.Value * 1000); timer.Elapsed += new System.Timers.ElapsedEventHandler(timerPro); timer.AutoReset = true; sendM = new sendMail(); //timer.Start(); dgv_addrList.RowPostPaint += new DataGridViewRowPostPaintEventHandler(dgvRowRepaint); canEditRowIndex = 0; ArrayList precision = new ArrayList(); precision.Add(new DictionaryEntry("时", DatePart.HOUR)); precision.Add(new DictionaryEntry("分", DatePart.MINUTE)); precision.Add(new DictionaryEntry("秒", DatePart.SECEND)); cb_precision.DataSource = precision; cb_precision.ValueMember = "Value"; cb_precision.DisplayMember = "Key"; cb_precision.SelectedItem = cb_precision.Items[0]; cb_precision.DropDownStyle = ComboBoxStyle.DropDownList; using (ksoaContext db = new ksoaContext()) { addr_List = (List <alarm_mailaddr>)(from q in db.alarm_MailAddr where q.IsDeleted == false select q).ToList(); dgv_addrList.DataSource = addr_List;// (from q in db.alarm_MailAddr where q.IsDeleted==false select q).ToList(); dgv_addrList.Columns["ID"].ReadOnly = true; dgv_addrList.Columns["ID"].Visible = false; } dgv_addrList.SelectionChanged += new EventHandler(dgv_addrList_selectChanged); (btn_startWork).Text = bol_running ? "暂停" : "启动"; if (!bol_running) { timer.Stop(); nud_checkSpan.Enabled = true; } else { timer.Start(); nud_checkSpan.Enabled = false; } //timerPro(null,null); }
/// <summary> /// 刷新数据|同时更新内存中的addr_list /// </summary> private void dataRefresh() { using (ksoaContext db = new ksoaContext()) { addr_List = (List <alarm_mailaddr>)(from q in db.alarm_MailAddr where q.IsDeleted == false select q).ToList(); if (dgv_addrList.InvokeRequired) { this.Invoke(new dosth(() => { dgv_addrList.DataSource = addr_List; })); } else { dgv_addrList.DataSource = addr_List; } } }
private bool checkTimes(DateTime aimTime, string fileBasePath, string fileName, out int gCount, out List <stock_alarm_GSA> goodsList) { gCount = 0; using (ksoaContext db = new ksoaContext()) { var query = from q in db.stock_alarm_GSA where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan select q; var query1 = from q in query where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan from p in db.spkfks from r in db.huoweizls //from s in db.hwsps where q.spid == p.spid && r.hw == q.hw //&&q.spid==s.spid&&q.hw==s.hw select new { //18335768012 462045 ID = q.ID, 商品编号 = q.spbh, 商品名称 = q.spmch, 货位 = r.huowname, 一级分类 = p.yjfl, 二级分类 = p.ejfl, 级分类 = p.sjfl, 预警阈值 = (int)(q.threshold_value), //实时库存= (int)s.hwshl, 计算时库存 = (int)q.amount_static, 近1月总销量 = q.saledIn1Month, 近7天销量 = q.saledIn7Days, 预计五天后库存 = q.stock_5DLatter, 在途数量 = q.stock_transit, 预计补货量 = q.restock_count, 最大库存量 = (int)(q.amount_static + q.restock_count + q.stock_transit - q.delivery_cycle * (q.saledIn7Days / 7.0)), 安全库存量 = (int)(q.safty_days * (0.85 * (q.saledIn7Days / 7.0) + 0.15 * (q.saledIn1Month / 30.0))), 次预警时间 = q.last_alarmDate, 最后统计时间 = q.lastCalcuDate }; goodsList = query.ToList(); gCount = goodsList.Count(); if (gCount > 0) { OpenXmlExcelOper.CreateSpreadSheet(fileBasePath + fileName, "data"); OpenXmlExcelOper.FillAlarmData(fileBasePath + fileName, "data", ListToDataTable(query1.ToList())); } } return(true); }
/// <summary> /// 修改地址配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_alterAddress_Click(object sender, EventArgs e) { Button btn = (Button)sender; alarm_mailaddr model = new alarm_mailaddr(); GetOrSetContext(ref model); if (!checkAddrModel(model)) { return; } btn.Enabled = false; using (ksoaContext db = new ksoaContext()) { var query = db.alarm_MailAddr.Find(model.ID);//query.First() query.mailAddress = model.mailAddress; query.mailBody = model.mailBody; query.notice = model.notice; query.senderAddr = model.senderAddr; query.senderName = model.senderName; query.sendFile = model.sendFile; query.SMTPHost = model.SMTPHost; query.SMTPPass = model.SMTPPass; query.SMTPPuser = model.SMTPPuser; query.subject = model.subject; query.toer = model.toer; query.sendTimeSpan = model.sendTimeSpan; if (0 < db.SaveChanges()) { alarm_mailaddr loc_m = new alarm_mailaddr(); MessageBox.Show("修改成功!", "提示"); GetOrSetContext(ref loc_m, false); } else { MessageBox.Show("修改失败!", "提示"); btn.Enabled = true; } } //btn.Enabled = true; dataRefresh(); }
private bool send2MailGroup(Guid groupId, List <string> files) { try { using (ksoaContext db = new ksoaContext()) { sendMailAddr loc_ar = (from q in db.alarmAddr_realations from p in db.alarm_MailAddr where q.guid == groupId && q.addr_Id_Main == p.ID && q.relation_Type == (int)AddrRealationType.GROUP select new sendMailAddr { ID = q.addr_Id_Main, subject = p.subject, fileBasePath = p.fileBasePath, sendFile = p.sendFile, SMTPHost = p.SMTPHost, SMTPPass = p.SMTPPass, SMTPPuser = p.SMTPPuser, mailBody = p.mailBody, sendTimeSpan = p.sendTimeSpan } ).ToList().First(); loc_ar.list_Toer = (from q in addr_List from p in db.alarmAddr_realationsD where p.guid == groupId && p.addr_Id_attached == q.ID select new tag_terminal { addr = q.mailAddress, showName = q.senderName }).ToList(); loc_ar.from = (from q in addr_List where q.ID == loc_ar.ID select new tag_terminal { addr = q.mailAddress, showName = q.senderName }).First(); loc_ar.list_files = files; sendMail(loc_ar); } } catch (Exception e1) { throw new Exception("Send group mail:" + e1.Message); } return(true); }
private bool checkTimes(DateTime aimTime, string fileBasePath, string fileName, out int gCount, out List <stock_alarm_GSA> goodsList) { gCount = 0; using (ksoaContext db = new ksoaContext()) { var query = from q in db.stock_alarm_GSA where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan select q; var query1 = from q in query where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan from p in db.spkfks from r in db.huoweizls where q.spid == p.spid && r.hw == q.hw select new { ID = q.ID, 商品编号 = q.spbh, 商品名称 = q.spmch, 货位 = r.huowname, 一级分类 = p.yjfl, 二级分类 = p.ejfl, 级分类 = p.sjfl, 预警阈值 = q.threshold_value, 五日后库存 = q.stock_5DLatter, 最后统计时间 = q.lastCalcuDate, 次预警时间 = q.last_alarmDate, 近两个月销量 = q.saledIn2Month, 近一月销量 = q.saledIn1Month, }; goodsList = query.ToList(); gCount = goodsList.Count(); if (gCount > 0) { OpenXmlExcelOper.CreateSpreadSheet(fileBasePath + fileName, "data"); OpenXmlExcelOper.FillAlarmData(fileBasePath + fileName, "data", ListToDataTable(query1.ToList())); } } return(true); }
private void btn_delAddress_Click(object sender, EventArgs e) { Button btn = (Button)sender; btn.Enabled = false; if (dgv_addrList.SelectedRows.Count > 0) { var model = addr_List.Find(q => q.ID == int.Parse(dgv_addrList.SelectedRows[0].Cells["ID"].Value.ToString())); using (ksoaContext db = new ksoaContext()) { var varg = (from q in db.alarmAddr_realationsD from p in db.alarmAddr_realations where q.addr_Id_attached == model.ID && q.guid == p.guid select new { gName = p.show_Name, gGuid = p.guid }).ToList(); if (varg.Count() > 0) { MessageBox.Show("删除失败!\r\n该地址已被分配到邮件组:\r\n\t" + varg[0].gName + "(" + varg[0].gGuid + "),\r\n要删除该地址请先从邮件组中移除!", "提示"); btn.Enabled = true; } var query = db.alarm_MailAddr.Find(model.ID); query.IsDeleted = true; return; if (0 < db.SaveChanges()) { alarm_mailaddr loc_m = new alarm_mailaddr(); MessageBox.Show("删除成功!", "提示"); GetOrSetContext(ref loc_m, false); } else { MessageBox.Show("删除失败!", "提示"); } } dataRefresh(); } btn.Enabled = true; }
private void dataRefresh() { using (ksoaContext db = new ksoaContext()) { List_gm.Clear(); var query1 = (from q in db.alarmAddr_realations select q).ToList(); var query2 = from q in db.alarmAddr_realationsD select q; GroupModel gm;//= new GroupModel(); foreach (var item in query1) { gm = new GroupModel(); gm.detials = new List <alarmAddr_realationsD>(); gm.main = item; gm.detials = query2.Where(q => q.guid == item.guid).ToList(); List_gm.Add(gm); } list_addr = (from q in db.alarm_MailAddr where q.IsDeleted == false select new GroupConfigAddrModel { addr = q.mailAddress, bol_selected = false, bol_mainAddr = false, Id = q.ID }).ToList(); dgv_groupList.DataSource = query1; } }
private void btn_saveAlter_Click(object sender, EventArgs e) { Button btn = (Button)sender; btn.Enabled = false; GroupModel gm = new GroupModel(); getOrSetFormModel(ref gm); alarmAddr_realations ar; using (ksoaContext db = new ksoaContext()) { ar = db.alarmAddr_realations.Find(gm.main.guid, gm.main.relation_Type); ar.show_Name = gm.main.show_Name; ar.addr_Id_Main = gm.main.addr_Id_Main; db.alarmAddr_realationsD.RemoveRange(db.alarmAddr_realationsD.Where(q => q.guid == gm.main.guid)); db.alarmAddr_realationsD.AddRange(gm.detials); if (db.SaveChanges() <= 0) { MessageBox.Show("保存失败!", "提示"); } else { guid_CurEdit = Guid.Empty; MessageBox.Show("保存成功!", "提示"); dataRefresh(); gm = new GroupModel(); gm.detials = new List <alarmAddr_realationsD>(); gm.main = new alarmAddr_realations(); getOrSetFormModel(ref gm, false); //listViewRefresh(); } } btn.Enabled = false; }
private void timerPro(object sender, System.Timers.ElapsedEventArgs e) {//DateTime.Parse(DateTime.Now.ToLongTimeString())>= DateTime.Parse(dtp_timeLimit.Value.ToLongTimeString()) bool onTime = false; if ((precision) == DatePart.HOUR && DateTime.Now.Hour == dtp_timeLimit.Value.Hour) { onTime = true; } else if ((precision) == DatePart.MINUTE && DateTime.Now.Hour == dtp_timeLimit.Value.Hour && DateTime.Now.Minute == dtp_timeLimit.Value.Minute) { onTime = true; } else if ((precision) == DatePart.SECEND && DateTime.Now.Hour == dtp_timeLimit.Value.Hour && DateTime.Now.Minute == dtp_timeLimit.Value.Minute && DateTime.Now.Second == dtp_timeLimit.Value.Second) { onTime = true; } //return; if (bol_running && !bol_alarming && ((cb_isLimitSend.Checked && onTime) || !cb_isLimitSend.Checked)) { bol_alarming = true; string loc_file = ""; int Dcount = 0; StringBuilder sb = new StringBuilder(); Random rand = new Random(DateTime.Now.Second); string loc_fileName = string.Format(fileName, DateTime.Now.ToString("yyyy-MM-dd") + DateTime.Now.Second + rand.Next()); try { using (ksoaContext db = new ksoaContext()) { //var query = (from q in db.alarm_MailAddr where q.IsDeleted==false&& DbFunctions.DiffMinutes(q.lastSendDate, DateTime.Now ) >= q.sendTimeSpan select q).ToList(); var query = addr_List.AsEnumerable().Where(q => q.IsDeleted == false && DateTime.Now.AddMinutes(-q.sendTimeSpan) > q.lastSendDate).ToList(); sendMailAddr loc_addr = new sendMailAddr(); tag_terminal loc_point; List <stock_alarm_GSA> list_goods; Subject = string.Format(Subject, DateTime.Now.ToString("yyyy-MM-dd")); if (query.Count > 0) { var loc_item = query.First(q => !string.IsNullOrEmpty(q.SMTPPuser) && !string.IsNullOrEmpty(q.mailBody) && !string.IsNullOrEmpty(q.senderAddr) && !string.IsNullOrEmpty(q.senderName) && !string.IsNullOrEmpty(q.SMTPHost) && !string.IsNullOrEmpty(q.SMTPPass) && !string.IsNullOrEmpty(q.subject) ); checkTimes(DateTime.Now, loc_item.fileBasePath, loc_fileName, out Dcount, out list_goods); if (Dcount > 0) { loc_file = file = loc_item.fileBasePath + loc_fileName; loc_addr.mailBody = string.Format(loc_item.mailBody, Dcount.ToString()); loc_addr.SMTPHost = loc_item.SMTPHost; loc_addr.SMTPPass = loc_item.SMTPPass; loc_addr.SMTPPuser = loc_item.SMTPPuser; loc_addr.subject = string.Format(loc_item.subject, DateTime.Now.ToString("yyyy-MM-dd")); loc_addr.from.addr = loc_item.senderAddr; loc_addr.from.showName = loc_item.senderName; loc_addr.list_Toer = new List <tag_terminal>(); loc_addr.list_files = new List <string>(); loc_addr.list_files.Add(loc_file); foreach (var item in query) { loc_point = new tag_terminal(); loc_point.addr = item.mailAddress; loc_point.showName = item.toer; loc_addr.list_Toer.Add(loc_point); } // return; if (sendMail(loc_addr)) { //times++; try { alarm_mailaddr loc_ma; //int aapo = 0; //Console.Write(1 / aapo); foreach (var item in query) { loc_ma = db.alarm_MailAddr.Find(item.ID); loc_ma.lastSendDate = DateTime.Now; } foreach (var item in list_goods) { db.stock_alarm_GSA.Find(item.ID).last_alarmDate = (DateTime.Now); } db.SaveChanges(); dataRefresh(); sb = new StringBuilder(); sb.Append(DateTime.Now).Append("|商品库存预警邮件发送成功!共(").Append(Dcount).Append(")个商品."); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); stock_alarm_GSA_his hisModel; foreach (var item in list_goods) { hisModel = new stock_alarm_GSA_his(); hisModel.IDS = item.ID; hisModel.hw = item.hw; hisModel.lastCalcuDate = item.lastCalcuDate; hisModel.last_alarmDate = item.last_alarmDate; hisModel.notice = item.notice; hisModel.ordering_cycle = item.ordering_cycle; hisModel.restock_count = item.restock_count; hisModel.safty_days = item.safty_days; hisModel.saledIn1Month = item.saledIn1Month; hisModel.saledIn7Days = item.saledIn7Days; hisModel.spbh = item.spbh; hisModel.spid = item.spid; hisModel.spmch = item.spmch; hisModel.stock_5DLatter = item.stock_5DLatter; hisModel.stock_transit = item.stock_transit; hisModel.threshold_value = item.threshold_value; hisModel.delivery_cycle = item.delivery_cycle; hisModel.amount_static = item.amount_static; hisModel.alarm_type = item.alarm_type; hisModel.alarm_state = item.alarm_state; hisModel.alarmSpan = item.alarmSpan; hisModel.add_date = item.add_date; db.stock_alarm_GSA_his.Add(hisModel); } db.SaveChanges(); } catch (Exception e1) { sb = new StringBuilder(); sb.Append(DateTime.Now.ToString()).Append(":"). Append(e1.Message).Append("\r\n\t\t"). Append(e1.InnerException == null?"": (e1.InnerException.InnerException == null? e1.InnerException.Message: e1.InnerException.InnerException.Message)); loc_addr.mailBody = sb.ToString(); loc_addr.list_Toer.Clear(); loc_addr.list_Toer.Add(loc_addr.from); sendMail(loc_addr); this.Invoke(new dosth(() => { btn_startWork.PerformClick(); })); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); } } else { dataRefresh(); sb = new StringBuilder(); sb.Append(DateTime.Now).Append("|商品库存预警邮件发送失败!共(").Append(Dcount).Append(")个商品."); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); } } } } } catch (Exception e1) { sb = new StringBuilder(); try { sb.Append(DateTime.Now.ToString()).Append(":").Append(e1.Message).Append("\r\n\t\t").Append(e1.InnerException == null ? "" : e1.InnerException.Message); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); } catch (Exception) { } bol_alarming = false; return; } bol_alarming = false; } }
private void timerPro(object sender, System.Timers.ElapsedEventArgs e) { if (bol_running && !bol_alarming) { bol_alarming = true; string loc_file = ""; int Dcount = 0; Random rand = new Random(DateTime.Now.Second); string loc_fileName = string.Format(fileName, DateTime.Now.ToString("yyyy-MM-dd") + DateTime.Now.Second + rand.Next()); using (ksoaContext db = new ksoaContext()) { //var query = (from q in db.alarm_MailAddr where q.IsDeleted==false&& DbFunctions.DiffMinutes(q.lastSendDate, DateTime.Now ) >= q.sendTimeSpan select q).ToList(); var query = addr_List.AsEnumerable().Where(q => q.IsDeleted == false && DateTime.Now.AddMinutes(-q.sendTimeSpan) > q.lastSendDate).ToList(); sendMailAddr loc_addr = new sendMailAddr(); tag_terminal loc_point; if (query.Count > 0) { List <stock_alarm_GSA> list_goods; Subject = string.Format(Subject, DateTime.Now.ToString("yyyy-MM-dd")); Body = string.Format(Body, Dcount.ToString()); var loc_item = query.First(q => !string.IsNullOrEmpty(q.SMTPPuser) && !string.IsNullOrEmpty(q.mailBody) && !string.IsNullOrEmpty(q.senderAddr) && !string.IsNullOrEmpty(q.senderName) && !string.IsNullOrEmpty(q.SMTPHost) && !string.IsNullOrEmpty(q.SMTPPass) && !string.IsNullOrEmpty(q.subject) ); checkTimes(DateTime.Now, loc_item.fileBasePath, loc_fileName, out Dcount, out list_goods); loc_file = file = loc_item.fileBasePath + loc_fileName; loc_addr.mailBody = string.Format(loc_item.mailBody, Dcount.ToString()); loc_addr.SMTPHost = loc_item.SMTPHost; loc_addr.SMTPPass = loc_item.SMTPPass; loc_addr.SMTPPuser = loc_item.SMTPPuser; loc_addr.subject = string.Format(loc_item.subject, DateTime.Now.ToString("yyyy-MM-dd")); loc_addr.from.addr = loc_item.senderAddr; loc_addr.from.showName = loc_item.senderName; loc_addr.list_Toer = new List <tag_terminal>(); loc_addr.list_files = new List <string>(); loc_addr.list_files.Add(loc_file); foreach (var item in query) { loc_point = new tag_terminal(); loc_point.addr = item.mailAddress; loc_point.showName = item.toer; loc_addr.list_Toer.Add(loc_point); } if (sendMail(loc_addr)) { alarm_mailaddr loc_ma; foreach (var item in query) { loc_ma = db.alarm_MailAddr.Find(item.ID); loc_ma.lastSendDate = DateTime.Now; } foreach (var item in list_goods) { db.stock_alarm_GSA.Find(item.ID).last_alarmDate = (DateTime.Now); } db.SaveChanges(); dataRefresh(); StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now).Append("|商品库存预警邮件发送成功!共(").Append(Dcount).Append(")个商品."); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); } else { dataRefresh(); StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now).Append("|商品库存预警邮件发送失败!共(").Append(Dcount).Append(")个商品."); log_operate.writeLog(string.Format(logFile, DateTime.Now.ToString("yyyy-MM-dd")), sb.ToString()); } } } bol_alarming = false; } }