Exemplo n.º 1
0
        public void GetAllUsers()
        {
            //用于序列化实体类的对象
            JavaScriptSerializer jss = new JavaScriptSerializer();

            //请求中携带的条件
            string order     = HttpContext.Request.Params["order"];
            string sort      = HttpContext.Request.Params["sort"];
            string searchKey = HttpContext.Request.Params["search"];
            int    offset    = Convert.ToInt32(HttpContext.Request.Params["offset"]); //0
            int    pageSize  = Convert.ToInt32(HttpContext.Request.Params["limit"]);

            string userType = HttpContext.Request.Params["searchUserType"];

            int                   total = 0;
            UserInfoManager       um    = new UserInfoManager();
            List <UserInfoEntity> list  = um.GetSearch(searchKey, userType, sort, order, offset, pageSize, out total);

            List <UserViewModel> listView = new List <UserViewModel>();

            foreach (var item in list)
            {
                listView.Add(new UserViewModel {
                    ID           = item.ID,
                    Code         = item.Code,
                    Name         = item.Name,
                    Type         = item.Type,
                    Group        = item.Group,
                    Company      = item.Company,
                    Department   = item.Department,
                    PositionID   = item.PositionID,
                    PositionName = item.PositionName,
                    Sex          = item.Sex,
                    Birthday     = item.Birthday == null ? "" : ((DateTime)item.Birthday).ToString("yyyy-MM-dd"),
                    Email        = item.Email,
                    Phone        = item.Phone,
                    Address      = item.Address,
                    UpdateTime   = item.UpdateTime
                });
            }

            //给分页实体赋值
            PageModels <UserViewModel> model = new PageModels <UserViewModel>();

            model.total = total;
            if (total % pageSize == 0)
            {
                model.page = total / pageSize;
            }
            else
            {
                model.page = (total / pageSize) + 1;
            }

            model.rows = listView;

            //将查询结果返回
            HttpContext.Response.Write(jss.Serialize(model));
        }
Exemplo n.º 2
0
        public string GetAll(string searchKey, string userType, string order, string sort, int offset, int pageSize)
        {
            int                   total   = 0;
            UserInfoManager       manager = new UserInfoManager();
            List <UserInfoEntity> list    = manager.GetSearch(searchKey, userType, sort, order, offset, pageSize, out total);

            //给分页实体赋值
            PageModels <UserInfoEntity> model = new PageModels <UserInfoEntity>();

            model.total = total;
            if (total % pageSize == 0)
            {
                model.page = total / pageSize;
            }
            else
            {
                model.page = (total / pageSize) + 1;
            }

            model.rows = list;

            //将查询结果返回
            return(new JavaScriptSerializer().Serialize(model));
        }