public HttpResponseBase ExportFile() { int totalCount = 0; string json = "false"; try { VendorBrandQuery query = new VendorBrandQuery(); _vendorBrand = new VendorBrandMgr(connectionString); query.IsPage = false; query.isExport = true; // query.searchContent = Request.Params["searchContent"]; if (!string.IsNullOrEmpty(Request.Params["searchContent"])) { //支持空格,中英文逗號隔開 string content = Regex.Replace(Request.Params["searchContent"].Trim(), "(\\s+)|(,)|(\\,)", ","); string[] contents = content.Split(','); int pid = 0; for (int i = 0; i < contents.Length; i++) { if (!string.IsNullOrEmpty(contents[i].Trim())) { if (query.searchContent == "") { if (int.TryParse(contents[i], out pid)) { query.searchContent += Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } else { query.searchContent += Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } } else { if (int.TryParse(contents[i], out pid)) { query.searchContent += "," + Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } else { query.searchContent += "," + Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } } } else { continue; } } } query.story_createname = Request.Params["createname"]; if (!string.IsNullOrEmpty(Request.Params["searchVendor"])) { if (Request.Params["searchVendor"] != "undefined") { query.Vendor_Id = uint.Parse(Request.Params["searchVendor"]); } } if (!string.IsNullOrEmpty(Request.Params["brandid"])) { if (Request.Params["brandid"] != "undefined") { query.Brand_Id = uint.Parse(Request.Params["brandid"]); } } // query.searchState = Convert.ToInt32(Request.Params["searchState"]); if (!string.IsNullOrEmpty(Request.Params["start_date"])) { query.date_start = Convert.ToDateTime(Request.Params["start_date"]); } if (!string.IsNullOrEmpty(Request.Params["end_date"])) { query.date_end = Convert.ToDateTime(Request.Params["end_date"]); } if (Request.Params["searchState"] == "0") { query.Brand_Story_Text = string.Empty; } else if (Request.Params["searchState"] == "1") { query.Brand_Story_Text = "1"; } else if (Request.Params["searchState"] == "2") { query.Brand_Story_Text = "2"; } #region 供應商狀態、品牌狀態 if (!string.IsNullOrEmpty(Request.Params["vendorState"])) { query.vendorState = Convert.ToInt32(Request.Params["vendorState"]); } if (!string.IsNullOrEmpty(Request.Params["brandState"])) { query.Brand_Status = Convert.ToUInt32(Request.Params["brandState"]); } #endregion query.IsPage = false; 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)); DataTable _dt = _vendorBrand.GetVendorBrandStory(query, out totalCount); foreach (DataRow dr_v in _dt.Rows) { DataRow dr = dtHZ.NewRow(); dr[0] = dr_v["vendor_id"].ToString(); dr[1] = dr_v["vendor_name_full"].ToString(); dr[2] = dr_v["brand_id"].ToString(); dr[3] = dr_v["brand_name"].ToString(); dr[4] = dr_v["story_createname"].ToString(); dr[5] = dr_v["story_createdate"].ToString(); dr[6] = dr_v["story_updatename"].ToString(); dr[7] = dr_v["story_updatedate"].ToString(); dtHZ.Rows.Add(dr); } string[] colname = new string[dtHZ.Columns.Count]; string filename = "vendorbrand_story" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; newExcelName = Server.MapPath(excelPath_export) + filename; for (int i = 0; i < dtHZ.Columns.Count; i++) { colname[i] = dtHZ.Columns[i].ColumnName; } if (System.IO.File.Exists(newExcelName)) { System.IO.File.Delete(newExcelName); } ExcelHelperXhf.ExportDTtoExcel(dtHZ, "", newExcelName); //CsvHelper.ExportDataTableToCsv(_dt, newExcelName, columnName, true); json = "{success:true,ExcelName:\'" + filename + "\'}"; } 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetVendorBrandStory() { string json = string.Empty; DataTable stores = new DataTable(); try { VendorBrandQuery query = new VendorBrandQuery(); _vendorBrand = new VendorBrandMgr(connectionString); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 // query.searchContent = Request.Params["searchContent"].Trim(); if (!string.IsNullOrEmpty(Request.Params["searchContent"])) { //支持空格,中英文逗號隔開 string content = Regex.Replace(Request.Params["searchContent"].Trim(), "(\\s+)|(,)|(\\,)", ","); string[] contents = content.Split(','); int pid = 0; for (int i = 0; i < contents.Length; i++) { if (!string.IsNullOrEmpty(contents[i].Trim())) { if (query.searchContent == "") { if (int.TryParse(contents[i], out pid)) { query.searchContent += Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } else { query.searchContent += Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } } else { if (int.TryParse(contents[i], out pid)) { query.searchContent += "," + Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } else { query.searchContent += "," + Regex.Replace(contents[i].Trim(), "(\\s+)|(,)|(\\,)", ","); } } } else { continue; } } } query.story_createname = Request.Params["createname"].Trim(); query.story_createname = query.story_createname.Trim(); if (!string.IsNullOrEmpty(Request.Params["searchVendor"])) { query.Vendor_Id = uint.Parse(Request.Params["searchVendor"]); } if (!string.IsNullOrEmpty(Request.Params["brandid"])) { query.Brand_Id = uint.Parse(Request.Params["brandid"]); } // query.searchState = Convert.ToInt32(Request.Params["searchState"]); if (!string.IsNullOrEmpty(Request.Params["start_date"])) { query.date_start = Convert.ToDateTime(Request.Params["start_date"]); } if (!string.IsNullOrEmpty(Request.Params["end_date"])) { query.date_end = Convert.ToDateTime(Request.Params["end_date"]); } if (Request.Params["searchState"] == "0") { query.Brand_Story_Text = string.Empty; } else if (Request.Params["searchState"] == "1") { query.Brand_Story_Text = "1"; } else if (Request.Params["searchState"] == "2") { query.Brand_Story_Text = "2"; } #region 供應商狀態、品牌狀態 if (!string.IsNullOrEmpty(Request.Params["vendorState"])) { query.vendorState = Convert.ToInt32(Request.Params["vendorState"]); } if (!string.IsNullOrEmpty(Request.Params["brandState"])) { query.Brand_Status = Convert.ToUInt32(Request.Params["brandState"]); } #endregion int totalCount = 0; stores = _vendorBrand.GetVendorBrandStory(query, out totalCount); foreach (DataRow dr in stores.Rows) { dr["Brand_Story_Text"] = dr["Brand_Story_Text"].ToString().Replace("<br/>", "\n"); } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Newtonsoft.Json.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:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }