Example #1
0
        public ActionResult ExportExcelWithBackgroundUserList(SearchBackgroundUserListInput input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);
            RestSharp.RestClient  client  = new RestSharp.RestClient();
            RestSharp.RestRequest request = new RestSharp.RestRequest();
            client.BaseUrl = new Uri(GetCurrentUrl(this));

            foreach (var para in ModelHelper.GetPropertyDictionary <SearchBackgroundUserListInput>(input))
            {
                request.AddParameter(para.Key, para.Value.IsNullOrEmpty() ? null : para.Value);
            }

            if (request.Parameters.Count(p => p.Name == DataKey.UserId) == 0)
            {
                request.AddParameter(DataKey.UserId, GetLoginInfo().User.Id.ToString());
            }

            var responseResult = client.ExecuteAsGet(request, "GET");

            if (responseResult.Content == "no data")
            {
                return(Content("<script>alert('没有符合条件的数据可被导出!');history.go(-1)</script>"));
            }
            var contentDispositionHeader = responseResult.Headers.First(p => p.Name == "Content-Disposition").Value.ToString().Replace(" ", string.Empty);
            var attachFileName           = contentDispositionHeader.Replace("attachment;filename=", string.Empty);

            return(File(responseResult.RawBytes, responseResult.ContentType, attachFileName));
        }
Example #2
0
        public ActionResult BackgroundUserList(SearchBackgroundUserListInput input)
        {
            CheckPermission();
            using (var result = new ResponseResult <List <SearchBackgroundUserListOutput> >())
            {
                var predicate = PredicateBuilder.True <T_ADMIN_USER>();
                if (input.Province.IsNullOrEmpty() == false)
                {
                    predicate = predicate.And(p => p.Province == input.Province);
                }

                if (input.City.IsNullOrEmpty() == false)
                {
                    predicate = predicate.And(p => p.City == input.City);
                }

                if (input.Region.IsNullOrEmpty() == false)
                {
                    predicate = predicate.And(p => p.Region == input.Region);
                }

                if (input.RegStartTime.HasValue)
                {
                    predicate = predicate.And(p => p.CreateTime >= input.RegStartTime.Value);
                }

                if (input.RegEndTime.HasValue)
                {
                    predicate = predicate.And(p => p.CreateTime <= input.RegEndTime.Value);
                }

                if (input.IsLock.HasValue)
                {
                    predicate = predicate.And(p => p.IsLock == input.IsLock.Value);
                }

                if (input.UserName.IsNullOrEmpty() == false)
                {
                    predicate = predicate.And(p => p.UserName == input.UserName);
                }

                int            totalCount   = 0;
                var            userList     = _adminUserRepository.GetBackgroundUserList(predicate, input.RoleType, input.PageIndex.Value, input.PageSize.Value, out totalCount);
                var            areaCodeList = GetBackgroundUserAreaCodeListBy(userList);
                IList <T_AREA> areaList     = null;
                if (areaCodeList != null && areaCodeList.Count > 0)
                {
                    areaList = _areaRepository.GetAll(p => areaCodeList.Contains(p.AID));
                    var backgroundUserListOutput = Mapper.Map <List <SearchBackgroundUserListOutput> >(userList);
                    SetSearchBackgroundUserListAreaName(backgroundUserListOutput, areaList);
                    result.Entity = backgroundUserListOutput;
                }


                SetJosnResult <List <SearchBackgroundUserListOutput> >(result, input.PageIndex.Value, input.PageSize.Value, totalCount, "获取" + input.RoleType.GetDescription() + "列表成功!");

                return(new JsonResultEx(result));
            }
        }
Example #3
0
        public ActionResult BackgroundUserList(SearchBackgroundUserListInput input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);

            var parameters  = ModelHelper.GetPropertyDictionary <SearchBackgroundUserListInput>(input);
            var result      = PostStandardWithSameControllerAction <List <SearchBackgroundUserListOutput> >(this, parameters);
            var searchModel = new SearchModel <SearchBackgroundUserListInput, List <SearchBackgroundUserListOutput> >(result.IsSuccess, input, result.Entity, (int)result.TotalNums);

            return(View(searchModel));
        }
Example #4
0
        public ActionResult ExportExcelWithBackgroundUserList(SearchBackgroundUserListInput input)
        {
            CheckPermission();
            if (input.PageSize.Value > 10000)
            {
                input.PageSize = 10000;
            }
            var predicate = PredicateBuilder.True <T_ADMIN_USER>();

            if (input.Province.IsNullOrEmpty() == false)
            {
                predicate = predicate.And(p => p.Province == input.Province);
            }

            if (input.City.IsNullOrEmpty() == false)
            {
                predicate = predicate.And(p => p.City == input.City);
            }

            if (input.Region.IsNullOrEmpty() == false)
            {
                predicate = predicate.And(p => p.Region == input.Region);
            }

            if (input.RegStartTime.HasValue)
            {
                predicate = predicate.And(p => p.CreateTime >= input.RegStartTime.Value);
            }

            if (input.RegEndTime.HasValue)
            {
                predicate = predicate.And(p => p.CreateTime <= input.RegEndTime.Value);
            }

            if (input.IsLock.HasValue)
            {
                predicate = predicate.And(p => p.IsLock == input.IsLock.Value);
            }

            if (input.UserName.IsNullOrEmpty() == false)
            {
                predicate = predicate.And(p => p.UserName == input.UserName);
            }

            int            totalCount   = 0;
            var            userList     = _adminUserRepository.GetBackgroundUserList(predicate, input.RoleType, input.PageIndex.Value, input.PageSize.Value, out totalCount);
            var            areaCodeList = GetBackgroundUserAreaCodeListBy(userList);
            IList <T_AREA> areaList     = null;
            List <SearchBackgroundUserListOutput> backgroundUserListOutput = null;

            if (areaCodeList != null && areaCodeList.Count > 0)
            {
                areaList = _areaRepository.GetAll(p => areaCodeList.Contains(p.AID));
                backgroundUserListOutput = Mapper.Map <List <SearchBackgroundUserListOutput> >(userList);
                SetSearchBackgroundUserListAreaName(backgroundUserListOutput, areaList);
            }

            if (userList.Count > 0)
            {
                HSSFWorkbook workbook = new HSSFWorkbook();
                MemoryStream ms       = new MemoryStream();
                // 创建一张工作薄。
                var        workSheet        = workbook.CreateSheet("注册会员列表");
                var        headerRow        = workSheet.CreateRow(0);
                var        tableHeaderTexts = new string[] { "用户编号", "角色", "真实姓名", "登录账号名", "省", "市", "区/县", "注册时间", "账户状态" };
                ICellStyle style            = workbook.CreateCellStyle();
                style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
                style.FillPattern         = FillPattern.SolidForeground;


                //生成列头
                for (int i = 0; i < tableHeaderTexts.Length; i++)
                {
                    var currentCell = headerRow.CreateCell(i);

                    currentCell.SetCellValue(tableHeaderTexts[i]);
                    currentCell.CellStyle = style;
                }

                var currentRoeIndex = 0;
                foreach (var bgUser in backgroundUserListOutput)
                {
                    currentRoeIndex++;
                    var dataRow          = workSheet.CreateRow(currentRoeIndex);
                    var userIdCell       = dataRow.CreateCell(0);
                    var roleCell         = dataRow.CreateCell(1);
                    var userNameCell     = dataRow.CreateCell(2);
                    var loginUserName    = dataRow.CreateCell(3);
                    var provinceCell     = dataRow.CreateCell(4);
                    var cityCell         = dataRow.CreateCell(5);
                    var regionCell       = dataRow.CreateCell(6);
                    var registryTimeCell = dataRow.CreateCell(7);
                    var accountStateCell = dataRow.CreateCell(8);

                    userIdCell.SetCellValue(bgUser.Id);
                    roleCell.SetCellValue(bgUser.RoleName);
                    userNameCell.SetCellValue(bgUser.RealName);
                    loginUserName.SetCellValue(bgUser.LoginUserName);
                    provinceCell.SetCellValue(bgUser.ProvinceName);
                    cityCell.SetCellValue(bgUser.CityName);
                    regionCell.SetCellValue(bgUser.RegionName);
                    registryTimeCell.SetCellValue(bgUser.RegisterTime.ToString("yyyy.MM.dd"));
                    accountStateCell.SetCellValue(bgUser.IsLocked ? "已锁定" : "正常");
                }

                workbook.Write(ms);
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename=BackgroundUserList" + (DateTime.Now.ToString("yyyyMMddHHmmss")) + ".xls"));
                Response.BinaryWrite(ms.ToArray()); workbook = null;
                return(File(ms, "application/ms-excel"));
            }
            else
            {
                return(Content("no data"));
            }
        }