public HttpResponseBase ProductCommentSave() { string json = string.Empty; int send_mail = 1; int isSave = 0;//保存未成功 ProductCommentQuery query = new ProductCommentQuery(); try { string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From"); SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host"); SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port"); SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName"); SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd"); string EmailFrom = Mail_From.Value;//發件人郵箱 string SmtpHost = Mail_Host.Value;//smtp服务器 string SmtpPort = Mail_Port.Value;//smtp服务器端口 string EmailUserName = Mail_UserName.Value;//郵箱登陸名 string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼 ProductCommentQuery store = new ProductCommentQuery(); _proCommentImpl = new ProductCommentMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["comment_id"])) { query.comment_id = Convert.ToInt32(Request.Params["comment_id"]); } if (!string.IsNullOrEmpty(Request.Params["comment_answer"])) { query.comment_answer = Request.Params["comment_answer"]; query.comment_answer = query.comment_answer.Replace("\\", "\\\\"); } if (!string.IsNullOrEmpty(Request.Params["comment_answer"])) { query.old_comment_answer = Request.Params["old_comment_answer"]; query.old_comment_answer = query.old_comment_answer.Replace("\\", "\\\\"); } if (!string.IsNullOrEmpty(Request.Params["answer_is_show"])) { query.answer_is_show = Convert.ToInt32(Request.Params["answer_is_show"]); } if (!string.IsNullOrEmpty(Request.Params["old_answer_is_show"])) { query.old_answer_is_show = Request.Params["old_answer_is_show"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["isReplay"])) { if (Convert.ToInt32(Request.Params["isReplay"]) == 1) { query.old_answer_is_show = string.Empty; } } if (!string.IsNullOrEmpty(Request.Params["comment_detail_id"])) { query.comment_detail_id = Convert.ToInt32(Request.Params["comment_detail_id"]); } if (!string.IsNullOrEmpty(Request.Params["send_mail"])) { send_mail = Convert.ToInt32(Request.Params["send_mail"]);//0 發送 1 不發送 query.send_mail = Convert.ToInt32(Request.Params["send_mail"]);//0 發送 1 不發送 2 發送失敗 } query.reply_user = (Session["caller"] as Caller).user_id; store = _proCommentImpl.GetUsetInfo(query); string user_email = store.user_email; string user_name = store.user_name; string product_name = store.product_name; string comment_info = store.comment_info; if (_proCommentImpl.ProductCommentSave(query) > 0) { json = "{success:'true',msg:'0'}";//保存成功,但不發送郵件 isSave = 1;//指示保存成功 if (send_mail == 0) { FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/CommentReplay.html"), FileMode.OpenOrCreate, FileAccess.Read); StreamReader sr = new StreamReader(fs, Encoding.UTF8); string strTemp = sr.ReadToEnd(); sr.Close(); fs.Close(); //[email protected] strTemp = strTemp.Replace("{{$username$}}", user_name); strTemp = strTemp.Replace("{{$productName$}}", product_name); strTemp = strTemp.Replace("{{$commentAnwser$}}", Request.Params["comment_answer"]); strTemp = strTemp.Replace("{{$commentInfo$}}", comment_info); if (sendmail(EmailFrom, FromName, user_email, user_name, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord)) { json = "{success:'true',msg:'1'}";//保存成功,郵件發送成功! } else { json = "{success:'true',msg:'2'}";//保存成功,郵件發送失敗! query.send_mail = 2; _proCommentImpl.ProductCommentSave(query); } } } else { json = "{success:'false'}";//保存失敗 } } 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); if (isSave == 1)//保存成功,可能郵件發送失敗! { json = "{success:'true',msg:'2'}";//保存成功,郵件發送失敗! query.send_mail = 2; _proCommentImpl.ProductCommentSave(query); } else//保存失敗 { json = "{success:'false'}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }