/// <summary> /// 新增 /// </summary> /// <param name="query"></param> /// <returns></returns> public string InsertODM(OrderDetailManagerQuery query) { string json = string.Empty; try { //查看是否重複 DataTable _dt = _ODMDao.IsExist(query); if (_dt.Rows.Count==0)//不重複 { if (_ODMDao.InsertODM(query) > 0) { json = "{success:true}";//新增成功 } else { json = "{success:false}";//新增失敗 } } else { json = "{success:true,msg:'1'}";//數據重複 } return json; } catch (Exception ex) { throw new Exception("OrderDetailManagerMgr-->InsertODM-->" + ex.Message, ex); } }
/// <summary> /// 列表頁 /// </summary> /// <param name="query"></param> /// <param name="totalCount"></param> /// <returns></returns> public List<OrderDetailManagerQuery> GetODMList(OrderDetailManagerQuery query,out int totalCount) { StringBuilder sql = new StringBuilder(); StringBuilder sqlCount = new StringBuilder(); StringBuilder sqlFrom = new StringBuilder(); StringBuilder sqlWhere = new StringBuilder(); totalCount = 0; try { sqlCount.Append("select count(odm.odm_id) as 'totalCount' "); sql.Append("select odm.odm_id,odm.odm_user_id,odm.odm_user_name,odm.odm_status,odm.odm_createdate,odm_createuser,mu.user_username"); sqlFrom.Append(" from order_detail_manager odm "); sqlFrom.Append(" LEFT JOIN manage_user mu on mu.user_id=odm.odm_createuser "); sqlWhere.Append(" where 1=1 "); if (query.odm_status != -1) { sqlWhere.AppendFormat(" and odm.odm_status='{0}' ", query.odm_status); } DataTable _dt = _access.getDataTable(sqlCount.ToString() + sqlFrom.ToString() + sqlWhere.ToString()); if (_dt != null & _dt.Rows.Count > 0) { totalCount = Convert.ToInt32(_dt.Rows[0][0]); } sqlWhere.AppendFormat(" order by odm.odm_createdate desc limit {0},{1}; ",query.Start,query.Limit); return _access.getDataTableForObj<OrderDetailManagerQuery>(sql.ToString() + sqlFrom.ToString() + sqlWhere.ToString()); } catch (Exception ex) { throw new Exception("OrderDetailManagerDao-->GetODMList-->" + sql.ToString() + sqlFrom.ToString() + sqlWhere.ToString()+ex.Message,ex); } }
/// <summary> /// 變更狀態 /// </summary> /// <param name="query"></param> /// <returns></returns> public int UpODMStatus(OrderDetailManagerQuery query) { try { return _ODMDao.UpODMStatus(query); } catch (Exception ex) { throw new Exception("OrderDetailManagerMgr-->UpODMStatus-->" + ex.Message, ex); } }
/// <summary> /// 列表頁 /// </summary> /// <param name="query"></param> /// <param name="totalCount"></param> /// <returns></returns> public List<OrderDetailManagerQuery> GetODMList(OrderDetailManagerQuery query, out int totalCount) { try { return _ODMDao.GetODMList(query, out totalCount); } catch (Exception ex) { throw new Exception("OrderDetailManagerMgr-->GetODMList-->"+ex.Message,ex); } }
/// <summary> ///新增時查重 /// </summary> /// <param name="query"></param> /// <returns></returns> public DataTable IsExist(OrderDetailManagerQuery query) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat("select odm_user_id from order_detail_manager where odm_user_id='{0}';",query.odm_user_id); return _access.getDataTable(sql.ToString()); } catch (Exception ex) { throw new Exception("OrderDetailManagerDao-->IsExist-->" + sql.ToString() + ex.Message, ex); } }
/// <summary> /// 新增 /// </summary> /// <param name="query"></param> /// <returns></returns> public int InsertODM(OrderDetailManagerQuery query) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat("insert into order_detail_manager(odm_user_id,odm_user_name,odm_status,odm_createdate,odm_createuser)values('{0}','{1}','{2}','{3}','{4}');",query.odm_user_id,query.odm_user_name,query.odm_status,CommonFunction.DateTimeToString(DateTime.Now),query.odm_createuser); return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("OrderDetailManagerDao-->InsertODM-->" + sql.ToString()+ ex.Message, ex); } }
//變更狀態 public JsonResult UpODMStatus() { try { OrderDetailManagerQuery query = new OrderDetailManagerQuery(); if (!string.IsNullOrEmpty(Request.Params["odm_id"].ToString())) { query.odm_id = Convert.ToInt32(Request.Params["odm_id"].ToString()); } query.odm_status = Convert.ToInt32(Request.Params["active"]); _orderDetailManagerMgr = new OrderDetailManagerMgr(mySqlConnectionString); int result = _orderDetailManagerMgr.UpODMStatus(query); if (result > 0) { return Json(new { success = "true" }); } else { return Json(new { success = "false" }); } } 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); return Json(new { success = "false" }); } }
//新增 public HttpResponseBase InsertODM() { OrderDetailManagerQuery query = new OrderDetailManagerQuery(); string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Params["odm_user_id"])) { query.odm_user_id = Convert.ToUInt32(Request.Params["odm_user_id"]); } if (!string.IsNullOrEmpty(Request.Params["odm_user_name"])) { query.odm_user_name =Request.Params["odm_user_name"]; } query.odm_status = 1; query.odm_createuser=(Session["caller"] as Caller).user_id; _orderDetailManagerMgr = new OrderDetailManagerMgr(mySqlConnectionString); json = _orderDetailManagerMgr.InsertODM(query); } 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; }
//列表頁 public HttpResponseBase GetODMList() { List<OrderDetailManagerQuery> store = new List<OrderDetailManagerQuery>(); OrderDetailManagerQuery query = new OrderDetailManagerQuery(); string json = string.Empty; try { int totalCount = 0; _orderDetailManagerMgr = new OrderDetailManagerMgr(mySqlConnectionString); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 if(!string.IsNullOrEmpty(Request.Params["odm_status"])) { query.odm_status = Convert.ToInt32(Request.Params["odm_status"]); } store = _orderDetailManagerMgr.GetODMList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}"; } 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; }
/// <summary> /// 更改狀態 /// </summary> /// <param name="query"></param> /// <returns></returns> public int UpODMStatus(OrderDetailManagerQuery query) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat("update order_detail_manager set odm_status='{0}' where odm_id='{1}';",query.odm_status,query.odm_id); return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("OrderDetailManagerDao-->UpODMStatus-->" + sql.ToString() + ex.Message, ex); } }