private void GetData(HttpContext context, string btn) { if (btn != "show") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int perId = RequestHelper.GetInt("id", 0); BLL.System.sys_Person bll = new BLL.System.sys_Person(); DataTable dt = bll.GetList(perId).Tables[0]; if (dt.Rows.Count == 0) { context.Response.Write("{\"status\":\"0\",\"msg\":\"该条数据已被其他人删除!\"}"); return; } string rowsStr = Utils.ToJson(dt); StringBuilder jsonStr = new StringBuilder(); jsonStr.Append("{\"status\":\"1\",\"msg\":\"获取数据成功!\",\"info\":"); jsonStr.Append(rowsStr); jsonStr.Append("}"); context.Response.Write(jsonStr); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }
private void GetList(HttpContext context, string btn) { if (btn != "show") { context.Response.Write("{\"status\":\"0.2\",\"msg\":\"对不起,您没有操作权限!\"}"); return; } try { int depId = RequestHelper.GetInt("depId", 1); string filterFlag = RequestHelper.GetString("filterFlag"); StringBuilder strWhere = new StringBuilder(); List <SqlParameter> parameterList = new List <SqlParameter>(); SqlParameter tempParameter = new SqlParameter(); if (filterFlag == "") { strWhere.Append("a.DepId=@DepId and "); tempParameter = new SqlParameter("@DepId", SqlDbType.Int, 4); tempParameter.Value = depId; parameterList.Add(tempParameter); } else { string perName = RequestHelper.GetString("perName"); string account = RequestHelper.GetString("account"); string postId = RequestHelper.GetString("postId"); string roleId = RequestHelper.GetString("roleId"); if (perName != "") { strWhere.Append("a.PerName like '%'+ @PerName +'%' and "); tempParameter = new SqlParameter("@PerName", SqlDbType.NVarChar); tempParameter.Value = perName; parameterList.Add(tempParameter); } if (account != "") { strWhere.Append("a.Account like '%'+ @Account +'%' and "); tempParameter = new SqlParameter("@Account", SqlDbType.NVarChar); tempParameter.Value = account; parameterList.Add(tempParameter); } if (postId != "") { strWhere.Append("a.PostId =@PostId and "); tempParameter = new SqlParameter("@PostId", SqlDbType.Int); tempParameter.Value = Utils.StrToInt(postId, 0).ToString(); parameterList.Add(tempParameter); } if (roleId != "") { strWhere.Append("','+a.RoleId+',' like '%,'+ @RoleId +',%' and "); tempParameter = new SqlParameter("@RoleId", SqlDbType.VarChar); tempParameter.Value = roleId; parameterList.Add(tempParameter); } } BLL.System.sys_Person bll = new BLL.System.sys_Person(); DataTable dt = bll.GetList(Utils.DelLastChar(strWhere.ToString(), " and "), parameterList).Tables[0]; string rowsStr = Utils.ToJson(dt); StringBuilder jsonStr = new StringBuilder(); jsonStr.Append("{\"status\":\"1\",\"msg\":\"数据获取成功!\",\"info\":"); jsonStr.Append("{\"total\":" + dt.Rows.Count + ",\"rows\":"); jsonStr.Append(rowsStr); jsonStr.Append("}}"); context.Response.Write(jsonStr); } catch (Exception e) { context.Response.Write("{\"status\":\"0\",\"msg\":\"对不起,系统出错:" + Utils.HtmlEncode(e.Message) + "\"}"); return; } }