public HttpResponseBase GetIPlasList() { string json = string.Empty; IplasQuery iplas = new IplasQuery(); iplas.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 iplas.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 //iplas.searchcontent = Request.Params["searchcontent"]; try { #region 修改之前 //if (!string.IsNullOrEmpty(Request.Params["searchcontent"])) //{ // iplas.searchcontent = Request.Params["searchcontent"].ToString().ToUpper();//輸入的內容 // if (iplas.searchcontent.Length > 10) // { // _iinvd = new IinvdMgr(mySqlConnectionString); // DataTable dt = new DataTable(); // dt = _iinvd.Getprodubybar(Request.Params["searchcontent"].ToString()); // if (dt.Rows.Count > 0) // { // iplas.searchcontent = dt.Rows[0]["item_id"].ToString(); // } // } //} #endregion #region 修改之後 string content = string.Empty; if (!string.IsNullOrEmpty(Request.Params["search_type"])) { iplas.serch_type = int.Parse(Request.Params["search_type"]); if (!string.IsNullOrEmpty(Request.Params["searchcontent"]) && Request.Params["searchcontent"].Trim().Length > 0)//有查詢內容就不管時間 { switch (iplas.serch_type) { case 1: case 2: iplas.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) { iplas.searchcontent = list[i]; } else { iplas.searchcontent = iplas.searchcontent + "," + list[i]; } } else { iplas.searchcontent = iplas.searchcontent + list[i] + ","; } } } #endregion break; default: break; } } } DateTime time; if (DateTime.TryParse(Request.Params["starttime"].ToString(), out time)) { iplas.starttime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (DateTime.TryParse(Request.Params["endtime"].ToString(), out time)) { iplas.endtime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } #endregion //DateTime time; //if (DateTime.TryParse(Request.Params["starttime"].ToString(), out time)) //{ // iplas.starttime = time; //} //if (DateTime.TryParse(Request.Params["endtime"].ToString(), out time)) //{ // iplas.endtime = time; //} List<IplasQuery> store = new List<IplasQuery>(); _IiplasMgr = new IplasMgr(mySqlConnectionString); // _IiplasMgr.UpIplas(iplas); int totalCount = 0; store = _IiplasMgr.GetIplas(iplas, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; foreach (var item in store) { item.product_name += GetProductSpec(item.item_id.ToString()); } json = "{success:true,'msg':'user',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:false,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }