public HttpResponseBase GetProductCommentList() { DataTable store = new DataTable(); string json = string.Empty; string str = string.Empty; try { _proCommentImpl = new ProductCommentMgr(mySqlConnectionString); ProductCommentQuery query = new ProductCommentQuery(); query.Start = Convert.ToInt32(Request["Start"] ?? "0"); if (!string.IsNullOrEmpty(Request["Limit"])) { query.Limit = Convert.ToInt32(Request["Limit"]); } if (!string.IsNullOrEmpty(Request.Params["ddlSel"])) { query.comment_type = Convert.ToInt32(Request.Params["ddlSel"]); } if (!string.IsNullOrEmpty(Request.Params["commentsel"])) { query.commentsel = Request.Params["commentsel"]; } if (!string.IsNullOrEmpty(Request.Params["productName"])) { query.product_name = Request.Params["productName"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["userName"])) { query.user_name = Request.Params["userName"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["userEmail"])) { query.user_email = Request.Params["userEmail"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["brand_name"])) { query.brand_name = Request.Params["brand_name"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["timestart"])) { query.beginTime = Convert.ToInt32(CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["timestart"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"))); } if (!string.IsNullOrEmpty(Request.Params["timeend"])) { query.endTime = Convert.ToInt32(CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["timeend"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"))); } if (!string.IsNullOrEmpty(Request.Params["productId"])) { query.product_id = Convert.ToUInt32(Request.Params["productId"]); } if (!string.IsNullOrEmpty(Request.Params["shopClass"])) { query.productIds = Request.Params["shopClass"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["isReplay"])) { query.isReplay = Convert.ToInt32(Request.Params["isReplay"].ToString()); } int totalCount = 0; store = _proCommentImpl.Query(query, out totalCount); for (int i = 0; i < store.Rows.Count; i++) { if (!string.IsNullOrEmpty(store.Rows[i]["user_name"].ToString())) { store.Rows[i]["user_name"] = store.Rows[i]["user_name"].ToString().Substring(0, 1) + "**"; } store.Rows[i]["user_email"] = store.Rows[i]["user_email"].ToString().Split('@')[0] + "@***"; store.Rows[i]["answer_is_show"] = store.Rows[i]["answer_is_show"].ToString() == "" ? "-1" : store.Rows[i]["answer_is_show"].ToString(); store.Rows[i]["is_show_name"] = store.Rows[i]["is_show_name"].ToString() == "" ? "-1" : store.Rows[i]["is_show_name"].ToString(); } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據 } 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:true,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 匯出評價列表csv表格 /// </summary> public void IndexExport() { string json = string.Empty; StringBuilder sb = new StringBuilder(); try { DataTable store = new DataTable(); #region 前提查詢條件 ProductCommentQuery query = new ProductCommentQuery(); query.Start = Convert.ToInt32(Request["Start"] ?? "0"); if (!string.IsNullOrEmpty(Request["Limit"])) { query.Limit = Convert.ToInt32(Request["Limit"]); } if (!string.IsNullOrEmpty(Request.Params["ddlSel"]) && Request.Params["ddlSel"] != "null") { query.comment_type = Convert.ToInt32(Request.Params["ddlSel"]); } if (!string.IsNullOrEmpty(Request.Params["commentsel"]) && Request.Params["commentsel"] != "null") { query.commentsel = Request.Params["commentsel"]; } if (!string.IsNullOrEmpty(Request.Params["productName"])) { query.product_name = Request.Params["productName"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["userName"])) { query.user_name = Request.Params["userName"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["userEmail"])) { query.user_email = Request.Params["userEmail"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["isReplay"])) { query.isReplay = Convert.ToInt32(Request.Params["isReplay"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["brand_name"])) { query.brand_name = Request.Params["brand_name"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["timestart"]) && Request.Params["timestart"] != "null") { query.beginTime = Convert.ToInt32(CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["timestart"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"))); } if (!string.IsNullOrEmpty(Request.Params["timeend"]) && Request.Params["timeend"] != "null") { query.endTime = Convert.ToInt32(CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["timeend"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"))); } if (!string.IsNullOrEmpty(Request.Params["productId"])) { query.product_id = Convert.ToUInt32(Request.Params["productId"]); } if (!string.IsNullOrEmpty(Request.Params["shopClass"]) && Request.Params["shopClass"] != "null") { query.productIds = Request.Params["shopClass"].ToString(); } query.IsPage = false; #endregion _proCommentImpl = new ProductCommentMgr(mySqlConnectionString); string fileName = "用戶評價信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"; int totalCount = 0; store = _proCommentImpl.Query(query, out totalCount); DataTable dtHZ = new DataTable(); string newExcelName = string.Empty; dtHZ.Columns.Add("編號", typeof(String)); dtHZ.Columns.Add("訂單編號", typeof(String)); dtHZ.Columns.Add("商品編號", typeof(String)); dtHZ.Columns.Add("商品名稱", typeof(String)); dtHZ.Columns.Add("品牌名稱", typeof(String)); dtHZ.Columns.Add("用戶名稱", typeof(String)); //dtHZ.Columns.Add("用戶郵箱", typeof(String)); dtHZ.Columns.Add("留言狀態", typeof(String)); dtHZ.Columns.Add("留言內容", typeof(String));//--處理 dtHZ.Columns.Add("留言回覆", typeof(String)); dtHZ.Columns.Add("回覆是否顯示", typeof(String)); dtHZ.Columns.Add("商品描述相符度", typeof(String)); dtHZ.Columns.Add("商品質量滿意度", typeof(String)); dtHZ.Columns.Add("配送速度滿意度", typeof(String)); dtHZ.Columns.Add("網站整體滿意度", typeof(String)); dtHZ.Columns.Add("回覆人", typeof(String)); dtHZ.Columns.Add("回覆時間", typeof(String)); dtHZ.Columns.Add("狀態", typeof(String)); for (int i = 0; i < store.Rows.Count; i++) { DataRow dr = dtHZ.NewRow(); dr[0] = store.Rows[i]["comment_id"]; string comment_info = store.Rows[i]["product_name"].ToString(); comment_info = comment_info.Replace(',', ','); comment_info = comment_info.Replace("\n", ""); dr[1] = store.Rows[i]["order_id"].ToString() == "" ? "0" : store.Rows[i]["order_id"]; dr[2] = store.Rows[i]["product_id"]; dr[3] = comment_info; comment_info = store.Rows[i]["brand_name"].ToString(); comment_info = comment_info.Replace(',', ','); comment_info = comment_info.Replace("\n", ""); dr[4] = comment_info; dr[5] = store.Rows[i]["user_name"]; //dr[4] = store[i].user_email; comment_info = store.Rows[i]["is_show_name"].ToString(); if (comment_info != "") { dr[6] = Convert.ToInt32(comment_info) == 0 ? "匿名" : "公開";//0-匿名,1-公開 } else { dr[6] = ""; } comment_info = store.Rows[i]["comment_info"].ToString(); comment_info = comment_info.Replace(',', ','); comment_info = comment_info.Replace("\n", ""); dr[7] = comment_info; //dr[6] = store[i].comment_answer; dr[8] = store.Rows[i]["comment_answer"].ToString().Replace(',', ',').Replace("\r", "").Replace("\n", ""); // dtHZ.Columns.Add("留言回覆", typeof(String)); comment_info = store.Rows[i]["answer_is_show"].ToString(); if (comment_info != "") { dr[9] = Convert.ToInt32(comment_info) == 0 ? "隱藏" : "顯示"; } else { dr[9] = ""; } dr[10] = Satisfaction(Convert.ToInt32(store.Rows[i]["product_desc"].ToString() == "" ? "0" : store.Rows[i]["product_desc"].ToString()));//滿意度 dr[11] = Satisfaction(Convert.ToInt32(store.Rows[i]["seller_server"].ToString() == "" ? "0" : store.Rows[i]["seller_server"].ToString())); dr[12] = Satisfaction(Convert.ToInt32(store.Rows[i]["web_server"].ToString() == "" ? "0" : store.Rows[i]["web_server"].ToString())); dr[13] = Satisfaction(Convert.ToInt32(store.Rows[i]["logistics_deliver"].ToString() == "" ? "0" : store.Rows[i]["logistics_deliver"].ToString())); dr[14] = store.Rows[i]["s_reply_user"]; if (!string.IsNullOrEmpty(store.Rows[i]["reply_time"].ToString())) { if (CommonFunction.DateTimeToString(Convert.ToDateTime(store.Rows[i]["reply_time"].ToString())) == "1970-01-01 08:00:00") { dr[15] = ""; } else { dr[15] = CommonFunction.DateTimeToString(Convert.ToDateTime(store.Rows[i]["reply_time"].ToString())); } } else { dr[15] = ""; } comment_info = store.Rows[i]["status"].ToString(); if (comment_info != "") { dr[16] = Convert.ToInt32(comment_info) == 1 ? "開啟" : "關閉";//1,開啟。2.關閉 } else { dr[16] = ""; } dtHZ.Rows.Add(dr); } if (!System.IO.Directory.Exists(Server.MapPath(excelPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(excelPath)); } string newName = string.Empty; newName = Server.MapPath(excelPath) + fileName; if (System.IO.File.Exists(newName)) { //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除 System.IO.File.SetAttributes(newName, FileAttributes.Normal); System.IO.File.Delete(newName); } StringWriter sw = ExcelHelperXhf.SetCsvFromData(dtHZ, fileName); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.ContentType = "application/ms-excel"; Response.ContentEncoding = Encoding.Default; Response.Write(sw); Response.End(); } 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,data:[]}"; } }