public List<IwmsRrecordQuery> GetIwmsRrecordList(IwmsRrecordQuery query, out int totalCount) { query.Replace4MySQL(); StringBuilder sbAll = new StringBuilder(); StringBuilder sbJoin = new StringBuilder(); StringBuilder sbWhr = new StringBuilder(); StringBuilder sbPage = new StringBuilder(); sbAll.Append("SELECT ir.order_id,od.item_id,ir.act_pick_qty,ir.made_dt,ir.cde_dt,ir.create_date,ir.cde_dt_incr,ir.cde_dt_shp,mu.user_username,od.product_name,od.product_spec_name,pii.product_id FROM iwms_record ir "); sbJoin.Append("LEFT JOIN manage_user mu ON ir.create_user_id=mu.user_id "); sbJoin.Append("LEFT JOIN order_detail od ON ir.detail_id=od.detail_id LEFT JOIN product_item pii on pii.item_id =od.item_id where 1=1 "); if (query.item_id.ToString().Trim().Length == 6) { sbWhr.AppendFormat("and od.item_id ='{0}' ", query.item_id); } else if(query.item_id.ToString().Length==5) { sbWhr.AppendFormat(" and pii.product_id = '{0}' ",query.item_id); } if (query.starttime != DateTime.MinValue && query.endtime != DateTime.MinValue) { if (query.datetype != "0") { sbWhr.AppendFormat("and ir.{0} BETWEEN '{1}' and '{2}' ", query.datetype, Common.CommonFunction.DateTimeToString(query.starttime), Common.CommonFunction.DateTimeToString(query.endtime)); } } if (query.product_name != string.Empty) { sbWhr.AppendFormat("and od.product_name like '%{0}%'", query.product_name); } if (query.user_username != string.Empty) { sbWhr.AppendFormat(" and mu.user_username like '%{0}%' ", query.user_username); } sbPage.AppendFormat("LIMIT {0},{1};", query.Start, query.Limit); try { DataTable dt = _accessMySql.getDataTable("select count(ir.order_id) from iwms_record ir " + sbJoin.ToString() + sbWhr.ToString()); totalCount = int.Parse(dt.Rows[0][0].ToString()); return _accessMySql.getDataTableForObj<IwmsRrecordQuery>(sbAll.ToString() + sbJoin.ToString() + sbWhr.ToString() + sbPage.ToString()); } catch (Exception ex) { throw new Exception("IwmsRrecordDao-->GetIwmsRrecordList-->" + ex.Message + sbAll.ToString() + sbJoin.ToString() + sbWhr.ToString() + sbPage.ToString(), ex); } }
public HttpResponseBase GetIwmsRecord() { string json = string.Empty; int totalCount = 0; try { List<IwmsRrecordQuery> list = new List<IwmsRrecordQuery>(); IwmsRrecordQuery query = new IwmsRrecordQuery(); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); if (!string.IsNullOrEmpty(Request.Params["oid"])) { System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$"); string id = Request.Params["oid"].ToString().Trim(); if (rex.IsMatch(id)) { query.item_id = uint.Parse(id); if (!string.IsNullOrEmpty(Request.Params["productname"])) { query.product_name = Request.Params["productname"].ToString().Trim(); } DateTime time; if (DateTime.TryParse(Request.Params["time_start"], out time)) { query.starttime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (DateTime.TryParse(Request.Params["time_end"], out time)) { query.endtime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (!string.IsNullOrEmpty(Request.Params["dateSel"])) { query.datetype = Request.Params["dateSel"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["username"])) { query.user_username = Request.Params["username"].ToString().Trim(); } _IIwmsRrecordMgr = new IwmsRrecordMgr(mySqlConnectionString); list = _IIwmsRrecordMgr.GetIwmsRrecordList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "}";//返回json數據 } else { json = "{success:true}"; } } else { if (!string.IsNullOrEmpty(Request.Params["productname"])) { query.product_name = Request.Params["productname"].ToString().Trim(); } DateTime time; if (DateTime.TryParse(Request.Params["time_start"], out time)) { query.starttime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (DateTime.TryParse(Request.Params["time_end"], out time)) { query.endtime = DateTime.Parse(time.ToString("yyyy-MM-dd HH:mm:ss")); } if (!string.IsNullOrEmpty(Request.Params["dateSel"])) { query.datetype = Request.Params["dateSel"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["username"])) { query.user_username = Request.Params["username"].ToString().Trim(); } _IIwmsRrecordMgr = new IwmsRrecordMgr(mySqlConnectionString); list = _IIwmsRrecordMgr.GetIwmsRrecordList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(list, 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; }