public void IplasExcelList() { string json = string.Empty; IplasQuery ilpsQuery = new IplasQuery(); DataTable dtExcel = new DataTable(); try { string content = string.Empty; if (!string.IsNullOrEmpty(Request.Params["search_type"])) { ilpsQuery.serch_type = int.Parse(Request.Params["search_type"]); if (!string.IsNullOrEmpty(Request.Params["searchcontent"]) && Request.Params["searchcontent"].Trim().Length > 0)//有查詢內容就不管時間 { switch (ilpsQuery.serch_type) { case 1: case 2: ilpsQuery.searchcontent = Request.Params["searchcontent"].Trim(); break; case 3: #region 之後的更改 content = Request.Params["searchcontent"].Replace(',', ',').Replace('|', ',').Replace(' ', ',');//.Replace(' ',',') string[] list = content.Split(','); string test = "^[0-9]*$"; int count = 0;//實現最後一個不加, for (int i = 0; i < list.Length; i++) { if (!string.IsNullOrEmpty(list[i])) { if (Regex.IsMatch(list[i], test)) { count = count + 1; if (count == 1) { ilpsQuery.searchcontent = list[i]; } else { ilpsQuery.searchcontent = ilpsQuery.searchcontent + "," + list[i]; } } else { ilpsQuery.searchcontent = ilpsQuery.searchcontent + list[i] + ","; } } } #endregion break; default: break; } } } DateTime time; if (DateTime.TryParse(Request.Params["starttime"].ToString(), out time)) { ilpsQuery.starttime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (DateTime.TryParse(Request.Params["endtime"].ToString(), out time)) { ilpsQuery.endtime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } List<IplasQuery> store = new List<IplasQuery>(); _IiplasMgr = new IplasMgr(mySqlConnectionString); store = _IiplasMgr.GetIplasExportList(ilpsQuery); 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)); for (int i = 0; i < store.Count; i++) { DataRow newRow = dtExcel.NewRow(); newRow[0] = store[i].item_id.ToString(); newRow[1] = store[i].product_name.ToString(); newRow[2] = store[i].loc_id.ToString(); newRow[3] = store[i].loc_stor_cse_cap.ToString(); newRow[4] = store[i].prepaid.ToString() == "0" ? "否" : "是"; newRow[5] = store[i].create_users.ToString(); newRow[6] = store[i].create_dtim.ToString(); dtExcel.Rows.Add(newRow); } if (dtExcel.Rows.Count > 0) { string fileName = "商品指定主料位_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; MemoryStream ms = ExcelHelperXhf.ExportDT(dtExcel, "商品指定主料位_" + DateTime.Now.ToString("yyyyMMddHHmmss")); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(ms.ToArray()); } else { Response.Write("匯出數據不存在"); } } 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); } }