示例#1
0
        public ActionResult ExportExcelWithQuestionList(SearchQuestionInput 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 <SearchQuestionInput>(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));
        }
示例#2
0
        public JsonResult List(SearchQuestionInput input)
        {
            CheckPermission();

            using (var result = new ResponseResult <List <SearchQutionOutput> >())
            {
                var predicate = PredicateBuilder.True <T_QUESTION>();
                if (!string.IsNullOrEmpty(input.Keywords))
                {
                    predicate = predicate.And(m => m.Title.Contains(input.Keywords));
                }

                if (input.IsOpen.HasValue)
                {
                    predicate = predicate.And(m => m.IsOpen == input.IsOpen);
                }

                if (input.IsDeleted.HasValue)
                {
                    predicate = predicate.And(m => m.IsDeleted == input.IsDeleted);
                }

                long totalCount;
                var  list = _expertQuestionService.GetAll <DateTime>(predicate, null, m => m.CreateTime, input.PageIndex, input.PageSize, out totalCount);
                result.Entity = Mapper.Map <List <SearchQutionOutput> >(list);
                var enumerable = list as T_QUESTION[] ?? list.ToArray();
                if (enumerable.Any())
                {
                    //提取用户编号
                    var userIdList = enumerable.Select(m => m.UserId).Distinct().ToArray();
                    var userList   = _userService.GetAll(m => userIdList.Contains(m.Id));
                    var users      = userList as T_USER[] ?? userList.ToArray();
                    foreach (var question in result.Entity)
                    {
                        var user = users.First(m => m.Id == question.UserId);
                        question.CreateUser = string.IsNullOrEmpty(user.UserName) ? user.LoginUserName : user.UserName;
                    }
                }

                SetJosnResult <List <SearchQutionOutput> >(result, input.PageIndex, input.PageSize,
                                                           totalCount, "获取问题列表成功!");

                return(new JsonResultEx(result));
            }
        }
示例#3
0
        public ActionResult List(SearchQuestionInput input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);

            if (input.PageIndex == 0)
            {
                input.PageIndex = 1;
            }

            if (input.PageSize == 0)
            {
                input.PageSize = 10;
            }

            var parameter = ModelHelper.GetPropertyDictionary <SearchQuestionInput>(input);
            var result    = PostStandardWithSameControllerAction <List <SearchQutionOutput> >(this, parameter);

            var model = new MultiModel <List <SearchQutionOutput> >(result.IsSuccess, input.PageIndex, input.PageSize, (int)result.TotalNums, result.Entity);

            return(View(model));
        }
示例#4
0
        public ActionResult ExportExcelWithQuestionList(SearchQuestionInput input)
        {
            CheckPermission();
            input.PageIndex = 1;
            if (input.PageSize > 10000)
            {
                input.PageSize = 10000;
            }

            var predicate = PredicateBuilder.True <T_QUESTION>();

            if (!string.IsNullOrEmpty(input.Keywords))
            {
                predicate = predicate.And(m => m.Title.Contains(input.Keywords));
            }

            if (input.IsOpen.HasValue)
            {
                predicate = predicate.And(m => m.IsOpen == input.IsOpen);
            }

            if (input.IsDeleted.HasValue)
            {
                predicate = predicate.And(m => m.IsDeleted == input.IsDeleted);
            }

            long totalCount;
            var  list = _expertQuestionService.GetAll <DateTime>(predicate, null, m => m.CreateTime, input.PageIndex, input.PageSize, out totalCount);
            List <SearchQutionOutput> questionListOutput = Mapper.Map <List <SearchQutionOutput> >(list);
            var enumerable = list as T_QUESTION[] ?? list.ToArray();

            if (enumerable.Any())
            {
                //提取用户编号
                var userIdList = enumerable.Select(m => m.UserId).Distinct().ToArray();
                var userList   = _userService.GetAll(m => userIdList.Contains(m.Id));
                var users      = userList as T_USER[] ?? userList.ToArray();

                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 question in questionListOutput)
                {
                    currentRoeIndex++;
                    var user = users.First(m => m.Id == question.UserId);
                    question.CreateUser = string.IsNullOrEmpty(user.UserName) ? user.LoginUserName : user.UserName;
                    var dataRow         = workSheet.CreateRow(currentRoeIndex);
                    var idCell          = dataRow.CreateCell(0);
                    var titleCell       = dataRow.CreateCell(1);
                    var contentCell     = dataRow.CreateCell(2);
                    var openStateCell   = dataRow.CreateCell(3);
                    var deleteStateCell = dataRow.CreateCell(4);
                    var questionerCell  = dataRow.CreateCell(5);
                    var createTimeCell  = dataRow.CreateCell(6);
                    var updateTimeCell  = dataRow.CreateCell(7);

                    idCell.SetCellValue(question.Id);
                    titleCell.SetCellValue(question.Title);
                    contentCell.SetCellValue(question.Description);
                    openStateCell.SetCellValue(question.IsOpen?"已开放":"未开放");
                    deleteStateCell.SetCellValue(question.IsDeleted?"已删除":"正常");
                    questionerCell.SetCellValue(question.CreateUser);
                    createTimeCell.SetCellValue(question.CreateTime.ToString("yyyy.MM.dd"));
                    updateTimeCell.SetCellValue(question.LastModifiedTime.ToString("yyyy.MM.dd"));
                }
                workbook.Write(ms);
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename=QuestionList" + (DateTime.Now.ToString("yyyyMMddHHmmss")) + ".xls"));
                Response.BinaryWrite(ms.ToArray()); workbook = null;
                return(File(ms, "application/ms-excel"));
            }
            else
            {
                return(Content("no data"));
            }
        }