public bool Start(string schedule_code) { DataTable table = UpdateAddress(); if(table.Rows.Count>0) { string mailBody = GetHtmlByDataTable(table); MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } } MailHelper mail = new MailHelper(mailModel); return mail.SendToGroup(GroupCode, MailTitle, mailBody, false, true); } return true; }
public bool Start(string schedule_code) { bool result = false; try { if (string.IsNullOrEmpty(schedule_code)) { return result; } string GroupCode = string.Empty; string MailTitle = string.Empty; StringBuilder strbody = new StringBuilder(); MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region FTP參數賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } } #endregion MailHelper mail = new MailHelper(mailModel); OrderMasterQuery query = new OrderMasterQuery(); query.order_date_pay_endTime = DateTime.Now; query.order_date_pay_startTime = query.order_date_pay_endTime.AddHours(-1); StringBuilder sbMailBody = new StringBuilder(); try { bool isSHow = false; string html =GetBigAmountMailBody(query,out isSHow); if (isSHow) { sbMailBody.AppendLine(html); } } catch (Exception ex) { throw new Exception("CheckOrderAmountMgr-->GetBigAmountMailBody-->" + "大金額訂單排程:" + ex.Message); } try { bool isSHow = false; string html = GetBigOrderNumbersMailBody(query, out isSHow); if (isSHow) { sbMailBody.AppendLine(html); } } catch (Exception ex) { throw new Exception("CheckOrderAmountMgr-->GetBigOrderNumbersMailBody-->"+"一小時多次付款客戶異常訂單付款通知:"+ ex.Message); } try { bool isSHow = false; string html = FirstBuyEmail(query, out isSHow); if (isSHow) { sbMailBody.AppendLine(html); } } catch (Exception ex) { throw new Exception("CheckOrderAmountMgr-->OtherTWPay-->" + "首購超過5000訂單付款檢查:" + ex.Message); } try { bool isSHow = false; string html = OtherTWPay(query, out isSHow); if (isSHow) { sbMailBody.AppendLine(html); } } catch (Exception ex) { throw new Exception("CheckOrderAmountMgr-->OtherTWPay-->" + "異地信用卡付款付款訂單通知:" + ex.Message); } if (!String.IsNullOrEmpty(sbMailBody.ToString())) { mail.SendToGroup(GroupCode, MailTitle, sbMailBody.ToString(), false, true);//發送郵件給群組 } result= true; } catch (Exception ex) { throw new Exception("CheckOrderAmount-->Start-->" + ex.Message); } return result; }
public bool Start(string schedule_code) { if (string.IsNullOrEmpty(schedule_code)) { return false; } MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; bool IsSeparate = false; bool IsDisplyName = true; string requestUrl = string.Empty; try { //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region mailhelp賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("requestUrl")) { requestUrl = item.value; } //else if (item.parameterCode.Equals("MailBody")) //{ // MailBody = item.value; //} //else if (item.parameterCode.Equals("IsSeparate")) //{ // if (item.value.ToString().Trim().ToLower() == "false") // { // IsSeparate = false; // } // else if (item.value.ToString().Trim().ToLower() == "true") // { // IsSeparate = true; // } //} //else if (item.parameterCode.Equals("IsDisplyName")) //{ // if (item.value.ToString().Trim().ToLower() == "false") // { // IsDisplyName = false; // } // else if (item.value.ToString().Trim().ToLower() == "true") // { // IsDisplyName = true; // } //} } #endregion int result = 0; int resultmes = 0; StringBuilder str = new StringBuilder(); StringBuilder sqlstrall = new StringBuilder(); InvoiceWinningNumberDao invoiceWinningNumberDao = new InvoiceWinningNumberDao(mySqlConnectionString); #region 獲取網頁里的數據,轉化成json字符串 string urlone = "https://www.einvoice.nat.gov.tw/PB2CAPIVAN/invapp/InvApp?version=0.2&action=QryWinningList&invTerm="; string urltwo = "&appID=EINV5201502271601"; string dateone = string.Empty; if (DateTime.Now.Month >= 10) { if (DateTime.Now.Month == 11) { dateone = (DateTime.Now.Year - 1911).ToString() + (DateTime.Now.Month - 1); } else { dateone = (DateTime.Now.Year - 1911).ToString() + DateTime.Now.Month; } } else if (DateTime.Now.Month == 1) { dateone = (DateTime.Now.AddMonths(-1).Year - 1911).ToString() + "12"; } else { if (DateTime.Now.Month % 2 == 1) { dateone = (DateTime.Now.Year - 1911).ToString() + "0" + (DateTime.Now.Month - 1); } else { dateone = (DateTime.Now.Year - 1911).ToString() + "0" + DateTime.Now.Month; } } string url = string.Empty; if (requestUrl.Trim() == string.Empty) { url = urlone + dateone + urltwo; } else { url = requestUrl; } string json = GetPage(url, "utf-8"); ResultClass rc = new ResultClass(); #endregion MailHelper mail = new MailHelper(mailModel); int year = 0; int month = 0; string[,] strarray = new string[,]{}; bool isHaveInfo = false; try//判斷如果出錯發郵件 { rc = JsonConvert.DeserializeObject<ResultClass>(json); year = Convert.ToInt32(rc.invoYm.Substring(0, 3)); month = Convert.ToInt32(rc.invoYm.Substring(3, 2)); strarray = new string[20,2] { { "superPrizeNo", rc.superPrizeNo }, { "spcPrizeNo", rc.spcPrizeNo }, { "spcPrizeNo2", rc.spcPrizeNo2 }, { "spcPrizeNo3", rc.spcPrizeNo3 }, { "firstPrizeNo1", rc.firstPrizeNo1 }, { "firstPrizeNo2", rc.firstPrizeNo2 }, { "firstPrizeNo3", rc.firstPrizeNo3 }, { "firstPrizeNo4", rc.firstPrizeNo4 }, { "firstPrizeNo5", rc.firstPrizeNo5 }, { "firstPrizeNo6", rc.firstPrizeNo6 }, { "firstPrizeNo7", rc.firstPrizeNo7 }, { "firstPrizeNo8", rc.firstPrizeNo8 }, { "firstPrizeNo9", rc.firstPrizeNo9 }, { "firstPrizeNo10", rc.firstPrizeNo10 }, { "sixthPrizeNo1", rc.sixthPrizeNo1 }, { "sixthPrizeNo2", rc.sixthPrizeNo2 }, { "sixthPrizeNo3", rc.sixthPrizeNo3 }, { "sixthPrizeNo4", rc.sixthPrizeNo4 }, { "sixthPrizeNo5", rc.sixthPrizeNo5 }, { "sixthPrizeNo6", rc.sixthPrizeNo6 } }; isHaveInfo = true; } catch (Exception ex) { MailBody = "<p/><a href=" + url + ">" + url + "</a>" + " 該鏈接中未讀到數據!"; mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); //throw new Exception(ex.Message); } if (isHaveInfo)//如果從鏈接中讀到數據 { for (int i = 0; i < strarray.GetLength(0); i++) { sqlstrall.AppendFormat(invoiceWinningNumberDao.ReturnInsertSql(year, month, strarray[i, 0].ToString(), strarray[i, 1].ToString())); } if (!string.IsNullOrEmpty(sqlstrall.ToString())) { result = invoiceWinningNumberDao.ResultOfExeInsertSql(sqlstrall.ToString()); } else { resultmes = 1;//設置其大於0 } if (result > 0) { MailBody = "<p/>執行成功"; mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); } else { if (resultmes > 0) { MailBody = "<p/>數據都已經存在"; mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); } } } } catch (Exception ex) { MailHelper mail = new MailHelper(mailModel); MailBody = "<p/>執行失敗"; mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); throw new Exception("WinningInvoiceSynchronismMgr-->Start-->" + ex.Message); } return true; }
public bool Start(string schedule_code) { if (string.IsNullOrEmpty(schedule_code)) { return false; } PromotionsAmountGiftDao giftDao = new PromotionsAmountGiftDao(mySqlConnectionString); try { DataTable dtProd = giftDao.GetProdStock(); StringBuilder str = new StringBuilder(); if (dtProd.Rows.Count > 0) { str.Append("<style>.wid100{width:100px;text-align: right;} td{padding:2px;}</style>"); str.AppendFormat("當前贈品庫存狀態"); str.Append("<table cellspacing='1' cellpadding='3' border='1' style='border-collapse: collapse'>"); str.AppendFormat("<tr style='text-align: center; background-color: #f4faff; color: #0076c8; font-weight: bold;'><th>活動編號</th><th style='background-color: #db7093;'>活動名稱</th><th style='background-color: #EEEE00;' >商品編號</th><th style='background-color: #b4eeb4;' >商品細項編號</th><th style='background-color:#AEEEEE'>庫存數量</th></tr>"); foreach (DataRow row in dtProd.Rows) { str.AppendFormat("<tr><td style='width:100px;text-align: center;'>{0}</td><td>{1}</td><td class='wid100'>{2}</td><td class='wid100'>{3}</td><td class='wid100'>{4}</td></tr>", row["id"], row["event_name"], row["product_id"], row["item_id"], GetString(row["kucun"].ToString())); } str.AppendFormat("</table>"); } //else //{ // str.Append("<span style='color:red;'><b>沒有適合條件的數據<b></span>"); //} List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); string GroupCode = string.Empty; string EmailTile = string.Empty; MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { EmailTile = item.value; } } MailHelper mHelper = new MailHelper(mailModel); if (str.ToString().Length > 0) { if (mHelper.SendToGroup(GroupCode, EmailTile, str.ToString()+" ", false, true)) { return true; } else { return false; } } return true; } catch (Exception ex) { throw new Exception("PromotionsAmountGiftMgr-->Start-->" + ex.Message); } }
public bool Start(string schedule_code) { if (string.IsNullOrEmpty(schedule_code)) { return false; } try { MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; bool IsSeparate = true; bool IsDisplyName = true; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region mailhelp賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } //else if (item.parameterCode.Equals("MailBody")) //{ // MailBody = item.value; //} //else if (item.parameterCode.Equals("IsSeparate")) //{ // if (item.value.ToString().Trim().ToLower() == "false") // { // IsSeparate = false; // } // else if (item.value.ToString().Trim().ToLower() == "true") // { // IsSeparate = true; // } //} //else if (item.parameterCode.Equals("IsDisplyName")) //{ // if (item.value.ToString().Trim().ToLower() == "false") // { // IsDisplyName = false; // } // else if (item.value.ToString().Trim().ToLower() == "true") // { // IsDisplyName = true; // } //} } #endregion ///獲取用戶登陸信息 long login_start = 0; long login_end = 0; int errorCount = 0; login_start = CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy/MM/dd HH:00:00")); login_end = CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy/MM/dd HH:59:59")); errorCount = 2;//登錄錯誤次數 string start_time = CommonFunction.GetNetTime(login_start).ToString("yyyy/MM/dd HH:mm:ss"); string end_time = CommonFunction.GetNetTime(login_end).ToString("yyyy/MM/dd HH:mm:ss"); StringBuilder sql = new StringBuilder(); sql.AppendFormat(@" select login_ipfrom,login_mail,t.parameterName as login_error_from,count(login_type) as total from user_login_attempts ula left join (select parameterName,parameterCode from t_parametersrc where parameterType ='user_login_type') t on ula.login_type=t.parameterCode where login_createdate>='{0}' and login_createdate<='{1}' and ula.login_ipfrom in (select login_ipfrom from user_login_attempts where login_createdate>='{0}' and login_createdate<='{1}' GROUP BY login_ipfrom HAVING count(login_ipfrom)>='{2}') GROUP BY login_ipfrom,login_type,login_mail ;", login_start, login_end, errorCount); DataTable _dt = _accessMySql.getDataTable(sql.ToString()); DataTable _newDt = new DataTable(); DataRow dr; _newDt.Columns.Add("異常IP", typeof(string)); _newDt.Columns.Add("登入帳號", typeof(string)); _newDt.Columns.Add("失敗次數", typeof(string)); _newDt.Columns.Add("錯誤登入來源", typeof(string)); _newDt.Columns.Add("登入日期區間", typeof(string)); if (_dt.Rows.Count > 0) { for (int i = 0; i < _dt.Rows.Count; i++) { dr = _newDt.NewRow(); dr["異常IP"] = _dt.Rows[i]["login_ipfrom"]; dr["登入帳號"] = _dt.Rows[i]["login_mail"]; dr["失敗次數"] = _dt.Rows[i]["total"]; dr["錯誤登入來源"] = _dt.Rows[i]["login_error_from"]; dr["登入日期區間"] = start_time + " ~ " + end_time; _newDt.Rows.Add(dr); } } if (_newDt.Rows.Count > 0) { MailBody = GetHtmlByDataTable(_newDt); //MailBody = "<br/><font size=\"4\"> 在 " + "<font color=\"#FF0000\" >" + start_time + " ~ " + end_time + "</font>" + " 的一個小時里,用戶登錄異常記錄如下:</font><br/><p/>" + GetHtmlByDataTable(_newDt); MailHelper mail = new MailHelper(mailModel); // mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); } else { //MailBody = "<br/><p><font size=\"4\"> 在 <font color=\"#FF0000\" >" + start_time + " ~ " + end_time + "</font> 的一個小時里,沒有用戶登錄異常的記錄!</font><p/>"; } } catch (Exception ex) { throw new Exception("CheckUnsafeLoginMgr-->Start-->" + ex.Message); } return true; }
public string DesignRequestEdit(DesignRequestQuery query) { string json = string.Empty; query.Replace4MySQL(); query.dr_resource_path = query.dr_resource_path.Replace("\\", "\\\\"); query.dr_document_path = query.dr_document_path.Replace("\\", "\\\\"); List<DisableKeywords> list = new List<DisableKeywords>(); try { int j = 0; list = _DesignRequestDao.GetKeyWordsList(); for (int i = 0; i < list.Count; i++) { if (query.dr_content_text.Contains(list[i].dk_string)) { j = 1; } } if (query.dr_id == 0) {//新增 if (query.product_id != 0 && query.dr_type == 4 && j != 1) { _DesignRequestDao.UpdateProductDetailText(query); } if (j == 1) { query.dr_status = 1; MailHelper mail = new MailHelper(); string sbHtml = "你好,派工系統申請的文案包含有禁用的關鍵字,還請前去查看新建立的項目 "; mail.SendToGroup("job", "派工系統", sbHtml.ToString(), false, true); } else { query.dr_status = 2;//已審核 if (GetExpected(query) > 0 && j != 1) {//已審核的文件直接算出期望完成時間 int day = Getday(query); //query.dr_expected = DateTime.Now.AddDays(day); query.day = day; } } int res = _DesignRequestDao.InsertDesignRequest(query); if (res > 0) { json = "{success:true,type:1,msg:1}";//type=1表示新增,msg=1表示新增成功 } else { json = "{success:true,type:1,msg:0}";//type=1表示新增,msg=0表示新增失敗 } } else { //編輯 query.dr_status = 1; DesignRequestQuery OldModel = new DesignRequestQuery(); OldModel = _DesignRequestDao.GetSingleDesignRequest(query); if (!string.IsNullOrEmpty(query.dr_type_tostring)) { query.dr_type = OldModel.dr_type; } if (query.product_id != 0 && query.dr_type == 4 && j != 1) { _DesignRequestDao.UpdateProductDetailText(query); } if (j == 1) { query.dr_status = 1; MailHelper mail = new MailHelper(); string sbHtml = "你好,派工系統申請的文案包含有禁用的關鍵字,還請前去查看新建立的項目 "; mail.SendToGroup("job", "派工系統", sbHtml.ToString(), false, true); } else { query.dr_status = 2; if (GetExpected(query) > 0 && j != 1) {//已審核的文件直接算出期望完成時間 int day = Getday(query); //query.dr_expected = DateTime.Now.AddDays(day); query.day = day; } } int res = _DesignRequestDao.UpdateDesignRequest(query); if (res > 0) { json = "{success:true,type:2,msg:1}";//type=2表示編輯,msg=1表示編輯成功 } else { json = "{success:true,type:2,msg:0}";//type=2表示編輯,msg=0表示編輯失敗 } } return json; } catch (Exception ex) { throw new Exception("DesignRequestMgr.DesignRequestEdit-->" + ex.Message, ex); } }
public bool Start(string schedule_code) { if (string.IsNullOrEmpty(schedule_code)) { return false; } try { MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; string requestUrl = string.Empty; //bool IsSeparate = true; //bool IsDisplyName = true; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region mailhelp賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("requestUrl")) { requestUrl = item.value; } } #endregion StreamReader sr; HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(requestUrl); httpRequest.Timeout = 10000; httpRequest.Method = "GET"; HttpWebResponse httpResponse; try { httpResponse = (HttpWebResponse)httpRequest.GetResponse(); } catch (Exception ex) { MailBody = "URL請求失敗,失敗原因:" + ex.Message; MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); throw new Exception(ex.Message); } if (httpResponse.StatusCode == HttpStatusCode.OK) { sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8); string result = sr.ReadToEnd(); result = result.Trim(); if (result == "success") { MailBody = "更新成功"; MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); } else if (result == "error") { MailBody = "更新失敗"; MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); } else { MailBody = "請求遠端返回的值不為 success 或者 error "; MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); } } else { MailBody = "URL請求失敗,失敗原因:遠端響應狀態為 " + httpResponse.StatusCode; MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); } } catch (Exception ex) { throw new Exception("CheckUrlResultMgr-->Start-->" + ex.Message); } return true; }
public Boolean SendMail(MailModel mailModel, string GroupCode, string MailTitle, string MailBody, Boolean IsSeparate = false, Boolean IsDisplyName = false) { Boolean result = false; try { mailModel = GetDeafultMailConfig(mailModel); MailHelper mail = new MailHelper(mailModel); MailBody = MailBody + " "; mail.SendToGroup(GroupCode, MailTitle, MailBody, IsSeparate, IsDisplyName); //根據群組代碼獲取收件人信息 } catch (Exception ex) { throw new Exception(" ScheduleServiceMgr-->SendMail-->" + ex.Message, ex); } return result; }
public void SendMail(string schedule_code, string info) { MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; bool IsSeparate = false; bool IsDisplyName = true; try { //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region mailModel賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } } MailBody = info; #endregion MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName); } catch (Exception ex) { throw new Exception("SendOrderInfoToBlackCatFTPMgr-->SendMail-->" + ex.Message); } }
public bool Start(string schedule_code) { bool result = false; FileManagement _fileHelper = new FileManagement(); try { if (string.IsNullOrEmpty(schedule_code)) { return result; } string GroupCode = string.Empty; string MailTitle = string.Empty; StringBuilder strbody = new StringBuilder(); MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region FTP參數賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("filepath")) { stockExcelsavePath = item.value.Trim().ToLower();; } } stockExcelsavePathSuccess = Path.Combine(stockExcelsavePath, "success"); stockExcelsavePathFail = Path.Combine(stockExcelsavePath, "fail"); stockExcelsavePathIgnore = Path.Combine(stockExcelsavePath, "ignore"); #endregion MailHelper mail = new MailHelper(mailModel); string[] files = _fileHelper.GetAllFiles(stockExcelsavePath, @"*.*"); string consoleFile = String.Empty; string lastFile = files.Max<String>(); if (files.Length < 1) { mail.SendToGroup(GroupCode, MailTitle, "今日沒有文件倒入", false, true);//發送郵件給群組 } #region 創建四個Datata來保存數據 DataTable _dtSucess = new DataTable();//更新成功的數據 _dtSucess.Columns.Add("商品編號", typeof(string)); _dtSucess.Columns.Add("商品細項編號", typeof(string)); _dtSucess.Columns.Add("商品ERP編號", typeof(string)); _dtSucess.Columns.Add("商品名稱", typeof(string)); _dtSucess.Columns.Add("規格", typeof(string)); _dtSucess.Columns.Add("庫存", typeof(string)); DataTable _dtFail = new DataTable();//更新失敗的數據 _dtFail.Columns.Add("商品編號", typeof(string)); _dtFail.Columns.Add("商品細項編號", typeof(string)); _dtFail.Columns.Add("商品ERP編號", typeof(string)); _dtFail.Columns.Add("商品名稱", typeof(string)); _dtFail.Columns.Add("規格", typeof(string)); _dtFail.Columns.Add("庫存", typeof(string)); DataTable _dtIgnore = new DataTable();//跳過更新的數據 _dtIgnore.Columns.Add("商品ERP編號", typeof(string)); DataTable _dtErrorTable = new DataTable();//打不開Excel文件的數據 _dtErrorTable.Columns.Add("路徑", typeof(string)); _dtErrorTable.Columns.Add("描述", typeof(string)); #endregion foreach (string file in files) { if (lastFile == file)//只操作最新的文件 { int num = 0; StringBuilder errorLog = GetStockMessageFromFile(file, ref _dtSucess, ref _dtFail, ref _dtIgnore, ref _dtIgnore); if (String.IsNullOrEmpty(errorLog.ToString())) { string newFileName = file.Substring(file.LastIndexOf("\\")); _fileHelper.MoveOneFile(file, stockExcelsavePathSuccess, newFileName); MailTitle = "ERP庫存更新提醒"; mail.SendToGroup(GroupCode, MailTitle, "更新成功數量:" + num + "文件名称:" + newFileName, false, true);//發送郵件給群組 } else { string newFileName = file.Substring(file.LastIndexOf("\\")); string errorNewFileName = newFileName.Substring(0, newFileName.LastIndexOf(".")) + "_err.xls"; string errorlogNewFileName = stockExcelsavePathFail + newFileName.Substring(0, newFileName.LastIndexOf(".")) + "_err.txt"; _fileHelper.MoveOneFile(file, stockExcelsavePathFail, errorNewFileName); SaveErrorLog(errorLog, errorlogNewFileName, newFileName); MailTitle = "ERP庫存更新異常提醒"; StringBuilder sbMailBody = new StringBuilder(); if (_dtSucess.Rows.Count > 0) { sbMailBody.AppendLine("更新成功商品"); sbMailBody.AppendLine(GetHtmlByDataTable(_dtSucess)); } if (_dtFail.Rows.Count > 0) { sbMailBody.AppendLine("更新失敗商品"); sbMailBody.AppendLine(GetHtmlByDataTable(_dtFail)); } if (_dtIgnore.Rows.Count > 0) { sbMailBody.AppendLine("跳過更新商品"); sbMailBody.AppendLine(GetHtmlByDataTable(_dtIgnore)); } if (_dtErrorTable.Rows.Count > 0) { sbMailBody.AppendLine("打不開Excel文件的數據"); sbMailBody.AppendLine(GetHtmlByDataTable(_dtErrorTable)); } mail.SendToGroup(GroupCode, MailTitle, sbMailBody.ToString(), false, true);//發送郵件給群組 } } else//忽略過時文件 { string newFileName = file.Substring(file.LastIndexOf("\\")); _fileHelper.MoveOneFile(file, stockExcelsavePathIgnore, newFileName); } } // StringBuilder sbMailBody = new StringBuilder(); result = true; } catch (Exception ex) { throw new Exception("CheckOrderAmount-->Start-->" + ex.Message); } return result; }
public bool ModifyOrderMsaterForDeliver(OrderModifyModel order) { try { OrderMaster omModel = _orderMasterDao.GetOrderMasterByOrderId4Change(order.order_id); StringBuilder sbSql = new StringBuilder(); sbSql.Append(@" om.order_status = 2, os.slave_status=2, od.detail_status=2, om.order_date_cancel=0, om.money_cancel=0, om.export_flag=1,"); sbSql.AppendFormat("om.order_date_pay ={0}", Common.CommonFunction.GetPHPTime()); if (!isCanModifyForDeliver(order.order_id)) { return false; } //1、是否寫入對帳 if (order.isBilling_checked) { sbSql.Append(",om.billing_checked=1,"); sbSql.AppendFormat("om.money_collect_date={0}", Common.CommonFunction.GetPHPTime()); } //2、紅利折抵 if (order.deduct_card_bonus != 0) { if (omModel.Order_Amount < order.deduct_card_bonus) { return false; } sbSql.AppendFormat(",om.deduct_card_bonus={0},", order.deduct_card_bonus); sbSql.AppendFormat("om.order_amount={0}", omModel.Order_Amount - order.deduct_card_bonus); } //3、要不要扣除消費者抵用購物金 if (order.isCash_record_bonus) { order.user_id = Convert.ToInt32(omModel.user_id); //order.bonus_num = order.bonus_num = Convert.ToInt32(omModel.Deduct_Bonus); order.record_note = "強制轉單扣點"; order.record_writer = "server"; AddBonusRecord(order);//扣除 } #region //4、要不要給hg點或購物金 if (order.isHGBonus) { #region 購物金 if (omModel.Accumulated_Bonus > 0) { //訂單取消後,回撥購物金的使用日期限制 int nExpire_Day = 90; DateTime nMaster_Start = DateTime.Now.Date; DateTime nMaster_End = DateTime.Now.AddDays(omModel.BonusExpireDay).Date.AddSeconds(-1); // DateTime nMaster_End = DateTime.Now.AddDays(1).Date.AddSeconds(-1); //OrderModifyModel orderModifyModel = new OrderModifyModel(); ////$amego_bonus->bonus_master_add($aOrder['user_id'], 30, $aOrder['accumulated_bonus'], $nMaster_Start, $nMaster_End, $aOrder['order_id'], '商品回饋購物金' , 1); //orderModifyModel.user_id =Convert.ToInt32( omModel.User_Id); //orderModifyModel.order_id = Convert.ToInt32(omModel.Order_Id); //orderModifyModel.bonus_num = Convert.ToInt32(omModel.Deduct_Bonus); //orderModifyModel.use_note ="強制轉單扣點"; //orderModifyModel.use_writer = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; // 會員目前可用購物金 BonusMasterQuery query = new BonusMasterQuery(); query.user_id = omModel.User_Id; query.type_id = 30; query.master_total = Convert.ToUInt32(omModel.Accumulated_Bonus); query.master_balance = omModel.Accumulated_Bonus; query.smaster_start = nMaster_Start; query.smaster_end = nMaster_End; query.smaster_createtime = DateTime.Now; query.smaster_updatedate = DateTime.Now; query.master_writer = string.Format("Writer:{0}", (System.Web.HttpContext.Current.Session["caller"] as Caller).user_username); query.bonus_type = 1; query.master_note = "商品回饋購物金"; //Serial ser = _serialDao.GetSerialById(27); //ser.Serial_Value = ser.Serial_Value+1; //_serialDao.Update(ser); //query.master_id = Convert.ToUInt32(ser.Serial_Value); query.master_ipfrom = order.ip_from; List<BonusMasterQuery> queryList = new List<BonusMasterQuery>(); queryList.Add(query); _bonusMasterMgr.BonusMasterAdd(queryList); //bonusMasterDao.InsertBonusMaster(query); } #endregion #region hg點 if (omModel.Accumulated_Happygo > 0) { if (_happyGoMgr.GetHGDeductList(omModel.Order_Id).Count > 0) { //有則進行點數累積,無則發信通知 } else { MailHelper mailHelper = new MailHelper(); string MailTitle = "HG累點失敗"; string MailBody = string.Format("{0}無HG資料,無法累點。", omModel.Order_Id); mailHelper.SendToGroup("BonusFailure", MailTitle, MailBody); } } #endregion } #endregion //更新條件 StringBuilder sql = new StringBuilder(); sql.Append(@"update order_master om,order_slave os,order_detail od set "); sql.Append(sbSql); sql.AppendFormat(@" where om.order_id={0} AND om.order_id = os.order_id AND os.slave_id = od.slave_id ", order.order_id); try { _orderMasterDao.UpdateOrderMaster(sql.ToString()); return true; } catch (Exception ex) { throw new Exception("OrderMasterMgr-->ModifyOrderMsaterForDeliver-->" + ex.Message, ex); } } catch (Exception ex) { throw new Exception("OrderMasterMgr-->ModifyOrderMsaterForDeliver-->" + ex.Message, ex); } }
public bool Start(string schedule_code) { string b = @"{'code':0,'data':{'country':'\u4e2d\u56fd','country_id':'CN','area':'\u534e\u4e2d','area_id':'400000','region':'\u6cb3\u5357\u7701','region_id':'410000','city':'\u90d1\u5dde\u5e02','city_id':'410100','county':'','county_id':'-1','isp':'\u8054\u901a','isp_id':'100026','ip':'115.60.75.15'}}"; string source = "\u534e\u4e2d\u4e2d\u56fd"; //string ip = "60.249.127.62"; string cd = source; //GetMessageByIP(ip); DataTable userOtherLogin = GetUserLoginDataTable(); string mailBody = GetHtmlByDataTable(userOtherLogin); CodeData codeData = JsonConvert.DeserializeObject<CodeData>(b); IPMessage ipMessage = JsonConvert.DeserializeObject<IPMessage>(codeData.data.ToString()); MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } } MailHelper mail = new MailHelper(mailModel); if (userOtherLogin.Rows.Count>0) { return mail.SendToGroup(GroupCode, MailTitle,mailBody, false, true); } return true; }
public bool Start(string schedule_code,DateTime startTime) { DeliverStatusDao dsDao = new DeliverStatusDao(mySqlConnectionString); // DateTime startTime = DateTime.Now; string HourNum = string.Empty; MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; //bool IsSeparate = false; //bool IsDisplyName = true; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("HourNum")) { HourNum = item.value; } else if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("MailFormPwd")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailBody")) { MailBody = item.value; } } IDeliverMasterImplMgr DeliverMaster = new DeliverMasterMgr(mySqlConnectionString); DataTable table = DeliverMaster.GetDeliverMaster(HourNum); int delNumber = table.Rows.Count; int updateNumber = 0; if (delNumber > 0) { DeliveryInfo Model; LogisticsTcatSodDao LTSDao=new LogisticsTcatSodDao(mySqlConnectionString); for (int i = 0; i < table.Rows.Count; i++) { table.Rows[i]["gettime"] = ""; Model =LTSDao.GetLogisticsTcatSod(table.Rows[i]["delivery_code"].ToString()); if (Model.Status == "順利送達") { table.Rows[i]["gettime"] = Model.CreateTime; updateNumber++; DeliverStatus dsmodel = new DeliverStatus(); dsmodel.freight_type = 11;//物流配送模式 dsmodel.Logistics_providers = 1;//物流商 dsmodel.deliver_id = Int64.Parse(table.Rows[i]["deliver_id"].ToString()); dsmodel.state = 99; dsmodel.settime = Model.CreateTime; dsmodel.endtime = Model.CreateTime; dsDao.InsertDeliverStatus(dsmodel); } } } DateTime endTime = DateTime.Now; TimeSpan ts = endTime - startTime; double Second = ts.TotalSeconds; int num1 = 0;//期望到貨日<運達時間的物流單個數 int num2 = 0;//期望到貨日>今天的物流單個數 MailHelper mail = new MailHelper(mailModel); StringBuilder sbmailBody = new StringBuilder(); string tablestr = GetHtmlByDataTable(GetSendTable(table), out num1, out num2); sbmailBody.Append("物流狀態抓取排程執行成功<br/>"); sbmailBody.Append("更新<span style=\"font-size:large;\">" + delNumber + "</span>個出貨單<br/>"); sbmailBody.Append("更新<span style=\"font-size:large;\">" + updateNumber + "</span>個物流單<br/>"); sbmailBody.Append("期望到貨日小於運達時間的物流單個數:<span style=\"font-size:large;\">" + num1 + "</span><br/>"); sbmailBody.Append("期望到貨日小於今天的物流單個數:<span style=\"font-size:large;\">" + num2 + "</span><br/>"); sbmailBody.Append("共耗時<span style=\"font-size:large;\">" + Second + "</span>秒<br/>"); sbmailBody.Append("更新出貨單詳情如下:<br/><br/>"); sbmailBody.Append(tablestr); return mail.SendToGroup(GroupCode, MailTitle,sbmailBody.ToString(), false, true); }
public HttpResponseBase SendMailByGroup() { string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig Food_Product_Consult = _siteConfigMgr.GetConfigByName("Food_Product_Consult"); SiteConfig Use_Product_Consult = _siteConfigMgr.GetConfigByName("Use_Product_Consult"); SiteConfig Other_Product_Consult = _siteConfigMgr.GetConfigByName("Other_Product_Consult"); string jsonStr = String.Empty; ProductConsultQuery query = new ProductConsultQuery(); _productconsultMgr = new ProductConsultMgr(mySqlConnectionString); try { if (!string.IsNullOrEmpty(Request["zixunType"])) { query.consult_type = Convert.ToInt32(Request["zixunType"]); } switch (query.consult_type) { case 1: query.consultType = "商品諮詢"; break; case 2: query.consultType = "庫存及配送"; break; case 3: query.consultType = "支付問題"; break; case 4: query.consultType = "發票及保修"; break; case 5: query.consultType = "促銷及贈品"; break; } if (!string.IsNullOrEmpty(Request.Params["ckShopClass"])) { query.ckShopClass = Request.Params["ckShopClass"].ToString(); } if (!string.IsNullOrEmpty(Request["consult_id"])) { query.consult_id = Convert.ToInt32(Request["consult_id"]); } if (!string.IsNullOrEmpty(Request["consult_info"])) { query.consult_info = Request["consult_info"].ToString(); } if (!string.IsNullOrEmpty(Request["user_name"])) { query.user_name = Request["user_name"].ToString(); } if (!string.IsNullOrEmpty(Request["create_date"])) { query.create_date = Convert.ToDateTime(Request["create_date"]); } FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/productConsultKeFu.html"), FileMode.OpenOrCreate, FileAccess.Read); StreamReader sr = new StreamReader(fs, Encoding.UTF8); string strTemp = sr.ReadToEnd(); sr.Close(); fs.Close(); strTemp = strTemp.Replace("{{$s_username$}}", query.user_name); strTemp = strTemp.Replace("{{$s_datetime$}}", query.create_date.ToString()); strTemp = strTemp.Replace("{{$consultInfo$}}", query.consult_info); strTemp = strTemp.Replace("{{$consultType$}}", query.consultType); if (query.ckShopClass == "ckShopClass1" && query.consult_type == 1)//食品館商品諮詢 { query.group_code = Food_Product_Consult.Value.ToString(); } if (query.ckShopClass == "ckShopClass2" && query.consult_type == 1)//用品館商品諮詢 { query.group_code = Use_Product_Consult.Value.ToString(); } if (query.consult_type != 1)//其他諮詢類型問題 { query.group_code = Other_Product_Consult.Value.ToString(); } int i = _productconsultMgr.UpdateConsultType(query); if (i > 0) { DataTable dt = _productconsultMgr.QueryMailGroup(query); MailHelper mHelper = new MailHelper(); if (dt.Rows.Count > 0) { for (int j = 0; j < dt.Rows.Count; j++) { if (!string.IsNullOrEmpty(dt.Rows[j]["row_id"].ToString())) { mHelper.SendToGroup(Convert.ToInt32(dt.Rows[j]["row_id"]), "吉甲地市集【商品諮詢】通知信", strTemp.ToString(), true, true); } } } } jsonStr = "{success:true }"; } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); jsonStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; }
public bool Start(string schedule_code) { bool result = false; try { if (string.IsNullOrEmpty(schedule_code)) { return result; } productItemMgr = new ProductItemMgr(mySqlConnectionString); _paraMgr = new ParameterMgr(mySqlConnectionString); ProductItemQuery query = new ProductItemQuery(); ArrivalNotice arriva = new ArrivalNotice(); MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string MailBody = string.Empty; string NOSuggestCountMsg = "今天沒有要採購的商品";//沒有要採購的商品提示 string sumDays = "60";//採購總天數 string periodDays = "1";//採購週期天數 ScheduleServiceMgr _secheduleServiceMgr; //獲取該排程參數 List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); #region FTP參數賦值 foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("MailBody")) { MailBody = item.value; } else if (item.parameterCode.Equals("sumDays")) { sumDays = item.value; } else if (item.parameterCode.Equals("periodDays")) { periodDays = item.value; } else if (item.parameterCode.Equals("NOSuggestCountMsg")) { NOSuggestCountMsg = item.value; } } #endregion Parametersrc p = new Parametersrc(); List<Parametersrc> list = new List<Parametersrc>(); p.ParameterType = "Food_Articles"; list = _paraMgr.GetAllKindType(p.ParameterType); for (int i = 0; i < list.Count; i++)/*要禁用的食品錧和用品館的商品*/ { if (!string.IsNullOrEmpty(list[i].ParameterCode)) { query.category_ID_IN += list[i].ParameterCode + ","; } } query.sumDays = int.Parse(sumDays); query.periodDays = int.Parse(periodDays); query.category_ID_IN = query.category_ID_IN.TrimEnd(','); query.sale_status = 100; query.Is_pod = 0; query.stockScope = 2; query.prepaid = -1; query.IsPage = false; int totalCount = 0; DataTable dt = productItemMgr.GetSuggestPurchaseInfo(query, out totalCount); MailHelper mail = new MailHelper(mailModel); if (dt.Rows.Count > 0) { DataTable dtExcel = new DataTable(); dtExcel.Columns.Add("行號", typeof(String)); dtExcel.Columns.Add("供應商編號", typeof(String)); dtExcel.Columns.Add("供應商名稱", typeof(String));// dtExcel.Columns.Add("商品編號", typeof(String)); dtExcel.Columns.Add("商品細項編號", typeof(String)); dtExcel.Columns.Add("商品ERP編號", typeof(String)); dtExcel.Columns.Add("商品名稱", typeof(String)); //dtExcel.Columns.Add("商品狀態", typeof(String)); //dtExcel.Columns.Add("販售狀態", typeof(String)); dtExcel.Columns.Add("規格", typeof(String)); // dtExcel.Columns.Add("規格二", typeof(String)); dtExcel.Columns.Add("庫存量", typeof(String)); dtExcel.Columns.Add("後台庫存量", typeof(String)); dtExcel.Columns.Add("安全存量", typeof(String)); dtExcel.Columns.Add("建議採購量", typeof(String));//ipo_qty dtExcel.Columns.Add("未驗收數量", typeof(String)); dtExcel.Columns.Add("補貨通知人數", typeof(String)); dtExcel.Columns.Add("成本", typeof(String)); dtExcel.Columns.Add("價格", typeof(String)); dtExcel.Columns.Add("上架時間", typeof(String)); dtExcel.Columns.Add("下架時間", typeof(String)); for (int i = 0; i < dt.Rows.Count; i++) { #region DataRow newRow = dtExcel.NewRow(); newRow[0] = i + 1; newRow[1] = Convert.ToInt64(dt.Rows[i]["vendor_id"]); newRow[2] = dt.Rows[i]["vendor_name_full"]; newRow[3] = dt.Rows[i]["product_id"]; newRow[4] = dt.Rows[i]["item_id"]; newRow[5] = dt.Rows[i]["erp_id"]; newRow[6] = dt.Rows[i]["product_name"]; //newRow[7] = dt.Rows[i]["product_status_string"]; //newRow[8] = dt.Rows[i]["sale_name"]; newRow[7] = dt.Rows[i]["spec_title_1"]; newRow[8] = dt.Rows[i]["item_stock"]; newRow[9] = dt.Rows[i]["iinvd_stock"]; newRow[10] = dt.Rows[i]["item_alarm"]; if (string.IsNullOrEmpty(dt.Rows[i]["sum_total"].ToString())) { newRow[11] = 0; } #region else { double sum_total = 0; int safe_stock_amount = 0; int item_stock = 0; int item_alarm = 0; int procurement_days = 0; if (double.TryParse(dt.Rows[i]["sum_total"].ToString(), out sum_total)) { sum_total = Convert.ToDouble(dt.Rows[i]["sum_total"]); } if (int.TryParse(dt.Rows[i]["safe_stock_amount"].ToString(), out safe_stock_amount)) { safe_stock_amount = Convert.ToInt32(dt.Rows[i]["safe_stock_amount"]); } if (int.TryParse(dt.Rows[i]["item_stock"].ToString(), out item_stock)) { item_stock = Convert.ToInt32(dt.Rows[i]["item_stock"]); } if (int.TryParse(dt.Rows[i]["item_alarm"].ToString(), out item_alarm)) { item_alarm = Convert.ToInt32(dt.Rows[i]["item_alarm"]); } if (int.TryParse(dt.Rows[i]["procurement_days"].ToString(), out procurement_days)) { procurement_days = Convert.ToInt32(dt.Rows[i]["procurement_days"]); } if (item_stock - procurement_days * sum_total / query.sumDays * query.periodDays <= item_alarm) { //建議採購量:供應商的進貨天數*採購調整系數*近3個月的平均每周銷售數量(最小值為1) double suggestPurchaseTemp = (procurement_days + safe_stock_amount) * (sum_total / query.sumDays) * query.periodDays + ((item_alarm - item_stock) > 0 ? (item_alarm - item_stock) : 0); if (suggestPurchaseTemp <= int.Parse(dt.Rows[i]["min_purchase_amount"].ToString())) //最小值為1 { newRow[11] = dt.Rows[i]["min_purchase_amount"]; } else { int suggestPurchase = Convert.ToInt32(suggestPurchaseTemp); if (suggestPurchase < suggestPurchaseTemp) { newRow[11] = Convert.ToInt32(suggestPurchaseTemp) + 1; } else { newRow[11] = Convert.ToInt32(suggestPurchaseTemp); } } } } #endregion newRow[12] = dt.Rows[i]["ipo_qty"]; newRow[13] = dt.Rows[i]["NoticeGoods"]; newRow[14] = dt.Rows[i]["item_cost"]; newRow[15] = dt.Rows[i]["item_money"]; newRow[16] = string.IsNullOrEmpty(dt.Rows[i]["product_start"].ToString()) ? " " : DateTime.Parse(dt.Rows[i]["product_start"].ToString()).ToString("yyyy-MM-dd hh:mm:ss"); newRow[17] = string.IsNullOrEmpty(dt.Rows[i]["product_end"].ToString()) ? "" : DateTime.Parse(dt.Rows[i]["product_end"].ToString()).ToString("yyyy-MM-dd hh:mm:ss"); dtExcel.Rows.Add(newRow); #endregion } string EmailContent = GetMail(dtExcel); mail.SendToGroup(GroupCode, MailTitle, EmailContent, false, true);//發送郵件給群組 } else { mail.SendToGroup(GroupCode, MailTitle, NOSuggestCountMsg, false, true);//發送郵件給群組 } result = true; } catch (Exception ex) { throw new Exception("SendOrderInfoToBlackCatFTPMgr-->Start-->" + ex.Message); } return result; }
public bool Start(string schedule_code) { string json = string.Empty; if (string.IsNullOrEmpty(schedule_code)) { return false; } try { MailModel mailModel = new MailModel(); mailModel.MysqlConnectionString = mySqlConnectionString; string GroupCode = string.Empty; string MailTitle = string.Empty; string filepath = string.Empty; string ftpuser = string.Empty; string ftppassword = string.Empty; string EmptyFilesPrompt = string.Empty; string ExistFilesPrompt = string.Empty; string NotExistDirectory = string.Empty; //string NotExistFtpDirectory = string.Empty; int isEmpty = -1; List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>(); ScheduleConfigQuery query_config = new ScheduleConfigQuery(); query_config.schedule_code = schedule_code; _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString); store_config = _secheduleServiceMgr.GetScheduleConfig(query_config); foreach (ScheduleConfigQuery item in store_config) { if (item.parameterCode.Equals("MailFromAddress")) { mailModel.MailFromAddress = item.value; } else if (item.parameterCode.Equals("MailHost")) { mailModel.MailHost = item.value; } else if (item.parameterCode.Equals("MailPort")) { mailModel.MailPort = item.value; } else if (item.parameterCode.Equals("MailFromUser")) { mailModel.MailFromUser = item.value; } else if (item.parameterCode.Equals("EmailPassWord")) { mailModel.MailFormPwd = item.value; } else if (item.parameterCode.Equals("GroupCode")) { GroupCode = item.value; } else if (item.parameterCode.Equals("MailTitle")) { MailTitle = item.value; } else if (item.parameterCode.Equals("filepath")) { filepath = item.value; } else if (item.parameterCode.Equals("ftpuser")) { ftpuser = item.value.Trim(); } else if (item.parameterCode.Equals("ftppassword")) { ftppassword = item.value.Trim(); } else if (item.parameterCode.Equals("EmptyFilesPrompt")) { EmptyFilesPrompt = item.value.Trim(); } else if (item.parameterCode.Equals("ExistFilesPrompt")) { ExistFilesPrompt = item.value.Trim(); } else if (item.parameterCode.Equals("NotExistDirectory")) { NotExistDirectory = item.value.Trim(); } //else if (item.parameterCode.Equals("NotExistFtpDirectory")) //{ // NotExistFtpDirectory = item.value.Trim(); //} } string mailBody = string.Empty; #region 統計目錄內容 string[] filepaths = filepath.Split(';'); for (int i = 0; i < filepaths.Length; i++) { if (string.IsNullOrEmpty(filepaths[i].Trim())) { continue; } //判斷是否為FTP路徑 if (filepaths[i].Trim().ToLower().ToString().Contains("ftp:")) { if (string.IsNullOrEmpty(ftpuser) || string.IsNullOrEmpty(ftppassword)) { mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + "需要的FTP賬號或密碼沒有設定!" + "</h3>"; //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + "需要的FTP賬號或密碼沒有設定!" + "<br>"; } else { mailBody += GetFtpContent(filepaths[i].Trim(), ftpuser, ftppassword, i, EmptyFilesPrompt, ExistFilesPrompt, NotExistDirectory, out isEmpty); } } //判斷路徑是否正確 else if (!Directory.Exists(filepaths[i])) { mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + NotExistDirectory + "</h3>"; //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + NotExistDirectory + "<br>"; isEmpty = -1; } //判斷路徑下是否有文件 else if (Directory.GetFiles(filepaths[i]).Length == 0) { mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + EmptyFilesPrompt + "</h3>"; //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + EmptyFilesPrompt + "<br>"; isEmpty = 1; } else if (Directory.GetFiles(filepaths[i]).Length > 0) { string Content = "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + ExistFilesPrompt + "</h3>"; //string Content = "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + ExistFilesPrompt + "<br>"; string[] files = Directory.GetFiles(filepaths[i]); for (int j = 0; j < files.Length; j++) { FileInfo info = new FileInfo(files[j]); files[j] = info.Name; Content += "<h5>" + "(" + (j + 1).ToString() + ")" + files[j] + "</h5>"; //Content += "(" + (j + 1).ToString() + ")" + files[j] + "<br>"; } mailBody += Content; isEmpty = 0; } } #endregion if (isEmpty == 0 && string.IsNullOrEmpty(ExistFilesPrompt)) { } else if (isEmpty == 1 && string.IsNullOrEmpty(EmptyFilesPrompt)) { } else { MailHelper mail = new MailHelper(mailModel); mail.SendToGroup(GroupCode, MailTitle, mailBody+" ", false, false);//發送郵件 } } catch (Exception ex) { throw new Exception("SetConfigXmlMgr-->Start-->" + ex.Message); } return true; }