/* 編輯的預覽按鈕和列表頁的預覽都訪問這個方法 * 1. * */ public HttpResponseBase GetPreviewHtml() { string html = string.Empty; string replaceStr = string.Empty; string contentStr = string.Empty; string templateStr = string.Empty; string recommendStr = string.Empty; string previewStr = string.Empty; string editStr = string.Empty; try { _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString); EdmContentNew query = new EdmContentNew(); //將傳過來的html加上根據當前登入者的id獲得的推薦html替換掉content_url中的替換符 if (!string.IsNullOrEmpty(Request.Params["content_id"])) { query.content_id = Convert.ToInt32(Request.Params["content_id"]); string content_url = _edmContentNewMgr.GetContentUrlByContentId(query.content_id); if (!string.IsNullOrEmpty(content_url)) { #region 獲取網頁內容 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(content_url); httpRequest.Timeout = 9000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); contentStr = sr.ReadToEnd(); #endregion } else { contentStr = ""; } } //列表頁的預覽按鈕不進這個方法 if (!string.IsNullOrEmpty(Request.Params["template_id"])) { query.template_id = Convert.ToInt32(Request.Params["template_id"]); edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString); if (edmtemplatemgr.GetStaticTemplate(query.template_id)) { recommendStr = string.Empty; } else { recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id)); } } //獲取template_data(編輯器中的內容或者是表中的template_data) if (!string.IsNullOrEmpty(Request.Params["template_data"])) { templateStr = Request.Params["template_data"]; } else { templateStr = _edmContentNewMgr.GetHtml(query); } //編輯的預覽按鈕不進這個方法 //根據user_id獲得精準推薦 if (!string.IsNullOrEmpty(Request.Params["static_template"])) { if (Request.Params["static_template"] == "0")// 動態範本,精準推薦 { recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id)); } else { recommendStr = string.Empty; } } //替換符 DataTable _dt = _edmContentNewMgr.GetPraraData(1); if (_dt != null && _dt.Rows.Count > 0) { replaceStr = _dt.Rows[0][0].ToString(); } else { replaceStr = " "; } //分隔符 DataTable _dtEdit = _edmContentNewMgr.GetPraraData(3); if (_dtEdit != null && _dtEdit.Rows.Count > 0) { editStr = _dtEdit.Rows[0][0].ToString(); } else { editStr = " "; } templateStr = templateStr.Replace(editStr,"") + recommendStr; if (Request.Params["checked"] == "true") { if (!string.IsNullOrEmpty(contentStr)) { previewStr = contentStr.Replace(replaceStr, templateStr) + subscribe_url; } else { previewStr = templateStr + subscribe_url; } } else { if (!string.IsNullOrEmpty(contentStr)) { previewStr = contentStr.Replace(replaceStr, templateStr); } else { previewStr = templateStr; } } } 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); previewStr = ""; } this.Response.Clear(); this.Response.Write(previewStr); this.Response.End(); return this.Response; }
/*public HttpResponseBase GetContentUrl() { string json = string.Empty; string template_data = string.Empty; string contentJson = string.Empty; string replaceStr = string.Empty; string editStr = string.Empty; try { _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["content_url"])) { #region 獲取網頁內容方法 string url = Request.Params["content_url"].ToString(); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Timeout = 9000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); contentJson = sr.ReadToEnd(); #endregion } else { int template_id = Convert.ToInt32(Request.Params["template_id"]); string url = _edmContentNewMgr.GetContentUrl(template_id); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Timeout = 9000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); contentJson = sr.ReadToEnd(); } if (!string.IsNullOrEmpty(Request.Params["template_data"])) { template_data = Request.Params["template_data"]; } DataTable _dt = _edmContentNewMgr.GetPraraData(1); if (_dt != null && _dt.Rows.Count > 0) { replaceStr = _dt.Rows[0][0].ToString(); } else { replaceStr = " "; } DataTable _dtEdit = _edmContentNewMgr.GetPraraData(3); if (_dtEdit != null && _dtEdit.Rows.Count > 0) { editStr = _dtEdit.Rows[0][0].ToString(); } else { editStr = " "; } template_data = template_data.Replace(editStr,""); contentJson=contentJson.Replace(replaceStr,template_data); json = contentJson; } 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); json = "獲取網頁出現異常!"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }*/ #endregion #region 發送電子報 (測試發送/正式發送) public HttpResponseBase SendEdm() { string json = string.Empty; EdmSendLog eslQuery = new EdmSendLog(); MailRequest mQuery = new MailRequest(); try { _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["content_id"])) { eslQuery.content_id = mQuery.content_id = Convert.ToInt32(Request.Params["content_id"]); } if (!string.IsNullOrEmpty(Request.Params["group_id"])) { mQuery.group_id = Convert.ToInt32(Request.Params["group_id"]); } if (!string.IsNullOrEmpty(Request.Params["sender_email"])) { mQuery.sender_address = Request.Params["sender_email"]; } if (!string.IsNullOrEmpty(Request.Params["sender_name"])) { mQuery.sender_name = Request.Params["sender_name"]; } if (!string.IsNullOrEmpty(Request.Params["subject"])) { mQuery.subject = Request.Params["subject"]; } if (!string.IsNullOrEmpty(Request.Params["template_id"])) { mQuery.template_id = Convert.ToInt32(Request.Params["template_id"]); } if (!string.IsNullOrEmpty(Request.Params["static_template"])) { mQuery.static_template = Convert.ToUInt64(Request.Params["static_template"]); } eslQuery.create_userid = (Session["caller"] as Caller).user_id; mQuery.user_id = 0; if (!string.IsNullOrEmpty(Request.Params["testSend"])) { if (Request.Params["testSend"] == "true")// { eslQuery.test_send_end = true; #region 字段賦值 eslQuery.test_send = 1; eslQuery.receiver_count = 1; eslQuery.schedule_date = DateTime.Now; eslQuery.expire_date = eslQuery.schedule_date.AddHours(1); eslQuery.createdate = eslQuery.schedule_date; mQuery.schedule_date = eslQuery.schedule_date; mQuery.valid_until_date = eslQuery.expire_date; mQuery.retry_count = 0; mQuery.next_send = eslQuery.schedule_date; mQuery.max_retry = 1; if (!string.IsNullOrEmpty(Request.Params["test_send_list"])) { string[] test_send_arr = Request.Params["test_send_list"].ToString().TrimEnd('\n').Split('\n'); for (int i = 0; i < test_send_arr.Length; i++) { if (test_send_arr[i] != "") { mQuery.receiver_address = test_send_arr[i]; eslQuery.receiver_count = test_send_arr.Length; if (!string.IsNullOrEmpty(Request.Params["body"])) { if (mQuery.static_template == 0)//非靜態範本,需動態生成推薦 { mQuery.bodyData = Request.Params["body"] + _edmContentNewMgr.GetRecommendHtml(0); } else//靜態範本 { mQuery.bodyData = Request.Params["body"]; } #region 得到電子報整體內容 string replaceStr = string.Empty; string editStr = string.Empty; string content_url = _edmContentNewMgr.GetContentUrlByContentId(eslQuery.content_id); if (!string.IsNullOrEmpty(content_url)) { #region 獲取網頁內容 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(content_url); httpRequest.Timeout = 9000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); string contentStr = sr.ReadToEnd(); DataTable _dt = _edmContentNewMgr.GetPraraData(1); if (_dt != null && _dt.Rows.Count > 0) { replaceStr = _dt.Rows[0][0].ToString(); } else { replaceStr = " "; } DataTable _dtEdit = _edmContentNewMgr.GetPraraData(3); if (_dtEdit != null && _dtEdit.Rows.Count > 0) { editStr = _dtEdit.Rows[0][0].ToString(); } else { editStr = " "; } if (mQuery.bodyData.IndexOf(subscribe) > 0)//找到了埋的那個code,證明是點擊了訂閱電子報 { mQuery.bodyData = contentStr.Replace(replaceStr, mQuery.bodyData.Replace(subscribe, "\n").Replace(editStr,"") ) + subscribe_url; ; } else { mQuery.bodyData = contentStr.Replace(replaceStr, mQuery.bodyData.Replace(editStr, "")); } #endregion } #endregion } MailHelper mail = new MailHelper(); mail.SendMailAction(test_send_arr[i], mQuery.subject, mQuery.bodyData + " "); json = _edmContentNewMgr.MailAndRequest(eslQuery, mQuery); } } } else { MailHelper mail = new MailHelper(); mQuery.bodyData = Request.Params["body"]; if (mQuery.bodyData.IndexOf(subscribe) > 0)//找到了埋的那個code,證明是點擊了訂閱電子報 { mQuery.bodyData = mQuery.bodyData.Replace(subscribe, "\n") + _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id)) + subscribe_url; } mail.SendMailAction((Session["caller"] as Caller).user_email, mQuery.subject, mQuery.bodyData + " "); json = _edmContentNewMgr.MailAndRequest(eslQuery, mQuery); } #endregion } else//正式發送,寫入排程所用表 { if (!string.IsNullOrEmpty(Request.Params["body"])) { mQuery.body = Request.Params["body"]; } eslQuery.test_send_end = false; eslQuery.test_send = 0; //eslQuery.receiver_count=""; 經計算後寫入 if (!string.IsNullOrEmpty(Request.Params["schedule_date"])) { eslQuery.schedule_date = Convert.ToDateTime(Request.Params["schedule_date"]); mQuery.schedule_date = eslQuery.schedule_date; } if (!string.IsNullOrEmpty(Request.Params["email_group_id"])) { eslQuery.email_group_id = Convert.ToInt32(Request.Params["email_group_id"]); } if (!string.IsNullOrEmpty(Request.Params["expire_date"])) { eslQuery.expire_date = Convert.ToDateTime(Convert.ToDateTime(Request.Params["expire_date"]).ToString("yyyy-MM-dd 23:59:59")); mQuery.valid_until_date = eslQuery.expire_date; } eslQuery.createdate = DateTime.Now; if (!string.IsNullOrEmpty(Request.Params["elcm_id"])) { eslQuery.elcm_id = Convert.ToInt32(Request.Params["elcm_id"]); } if (!string.IsNullOrEmpty(Request.Params["extra_send"])) { mQuery.extra_send = Request.Params["extra_send"]; } if (!string.IsNullOrEmpty(Request.Params["extra_no_send"])) { mQuery.extra_no_send = Request.Params["extra_no_send"]; } if (!string.IsNullOrEmpty(Request.Params["is_outer"])) { if (Request.Params["is_outer"] == "true") { mQuery.is_outer = true; } else { mQuery.is_outer = false; } } json = _edmContentNewMgr.MailAndRequest(eslQuery, mQuery); } } } 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); json = "{success:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }