Пример #1
0
 public JsonResult FarmerList(FarmerSeachModel seachModel)
 {
     using (var result = new ResponseResult <List <FarmerDemandModel> >())
     {
         int totalCount = 0;
         var entitys    = _farmerRequirement.GetAll(seachModel, out totalCount).Select(model => new FarmerDemandModel
         {
             Id           = model.Id,
             City         = string.IsNullOrEmpty(model.City) ? "" : _areaService.GetAreaNamesBy(model.City),
             CreateTime   = model.CreateTime,
             CreateUser   = _userService.GetByKey(model.CreateUserId) == null ? "" : _userService.GetByKey(model.CreateUserId).UserName,
             DemandType   = _sysDictionary.GetByKey(model.DemandTypeId) == null ? "" : _sysDictionary.GetByKey(model.DemandTypeId).DisplayName,
             Province     = string.IsNullOrEmpty(model.Province) ? "" : _areaService.GetAreaNamesBy(model.Province),
             PublishState = _sysDictionary.GetByKey(model.PublishStateId) == null ? "" : _sysDictionary.GetByKey(model.PublishStateId).DisplayName,
             Region       = string.IsNullOrEmpty(model.Region) ? "" : _areaService.GetAreaNamesBy(model.Region),
             IsDeleted    = model.IsDeleted
         }).ToList();
         result.PageIndex = seachModel.pageIndex;
         result.PageSize  = seachModel.pageSize;
         result.TotalNums = totalCount;
         result.Entity    = entitys;
         result.IsSuccess = true;
         return(Json(result));
     }
 }
Пример #2
0
        public ActionResult ExportExcelWithFarmList(FarmerSeachModel model)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);

            RestSharp.RestClient  client  = new RestSharp.RestClient();
            RestSharp.RestRequest request = new RestSharp.RestRequest();
            client.BaseUrl = new Uri(GetCurrentUrl(this));
            Dictionary <string, string> parameters = ModelHelper.GetPropertyDictionary <FarmerSeachModel>(model);

            foreach (var para in parameters)
            {
                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));
        }
Пример #3
0
        public ActionResult FarmerList(FarmerSeachModel model)
        {
            var responseResult = PostStandardWithSameControllerAction <List <DuPont.Models.Dtos.Background.Demand.FarmerDemandViewModel.FarmerDemandModel>, FarmerSeachModel>(this,
                                                                                                                                                                              model);

            if (responseResult != null && responseResult.IsSuccess)
            {
                var roleVerification = new FarmerDemandViewModel();
                roleVerification.Pager            = new PagedList <string>(new string[0], responseResult.PageIndex, responseResult.PageSize, (int)responseResult.TotalNums);
                roleVerification.PendingAuditList = responseResult.Entity;
                roleVerification.Wheremodel       = new FarmerSeachModel
                {
                    DemandTypeId   = model.DemandTypeId.DefaultIfEmpty("0"),
                    PublishStateId = model.PublishStateId.DefaultIfEmpty("0"),
                    ProvinceAid    = model.ProvinceAid.DefaultIfEmpty("0"),
                    CityAid        = model.CityAid.DefaultIfEmpty("0"),
                    RegionAid      = model.RegionAid.DefaultIfEmpty("0"),
                    IsDeleted      = model.IsDeleted
                };
                return(View("FarmerList", roleVerification));
            }
            return(View());
        }
Пример #4
0
        public ActionResult ExportExcelWithFarmList(FarmerSeachModel seachModel)
        {
            CheckPermission();
            if (seachModel.pageSize > 10000)
            {
                seachModel.pageSize = 10000;
            }
            int totalCount = 0;
            var modelList  = _farmerRequirement.GetAll(seachModel, out totalCount).Select(model => new FarmerDemandModel
            {
                Id           = model.Id,
                Province     = model.Province,
                City         = model.City,
                Region       = model.Region,
                Township     = model.Township,
                Village      = model.Village,
                CreateTime   = model.CreateTime,
                CreateUser   = model.CreateUserId.ToString(),
                DemandType   = ((FarmerDemandType)model.DemandTypeId).GetDescription(),
                PublishState = ((PublishState)model.PublishStateId).GetDescription(),
                PhoneNumber  = model.PhoneNumber,
                CropId       = model.CropId,
                AcresId      = model.AcresId,
                Brief        = model.Brief,
                ExpectedDate = model.ExpectedDate
            }).ToList();

            var userIdListDictionary = new Dictionary <long, string>();

            if (modelList.Count > 0)
            {
                var areaCodeDictionary = new Dictionary <string, string>();
                modelList.Select(m =>
                {
                    if (ValidatorAreaCode(m.Province) && !areaCodeDictionary.ContainsKey(m.Province))
                    {
                        areaCodeDictionary.Add(m.Province, string.Empty);
                    }

                    if (ValidatorAreaCode(m.City) && !areaCodeDictionary.ContainsKey(m.City))
                    {
                        areaCodeDictionary.Add(m.City, string.Empty);
                    }

                    if (ValidatorAreaCode(m.Region) && !areaCodeDictionary.ContainsKey(m.Region))
                    {
                        areaCodeDictionary.Add(m.Region, string.Empty);
                    }
                    var userId = int.Parse(m.CreateUser);
                    if (!userIdListDictionary.ContainsKey(userId))
                    {
                        userIdListDictionary.Add(userId, string.Empty);
                    }

                    return(m);
                }).Count();

                var cropIdList   = modelList.Select(p => p.CropId).Distinct().ToList();
                var acresIdList  = modelList.Select(p => p.AcresId).Distinct().ToList();
                var areaCodeList = areaCodeDictionary.Keys.ToList();
                //地区列表集合
                var areaInfoList = _areaService.GetAll(p => areaCodeList.Contains(p.AID));
                var userIdList   = userIdListDictionary.Keys.ToList();
                //用户列表集合
                var userList    = _userService.GetAll(p => userIdList.Contains(p.Id));
                var dicCodeList = new List <int>();
                dicCodeList.AddRange(cropIdList);
                dicCodeList.AddRange(acresIdList);
                //字典信息集合
                var dicInfoList = _sysDictionary.GetAll(p => dicCodeList.Contains(p.Code));

                HSSFWorkbook workbook = new HSSFWorkbook();
                MemoryStream ms       = new MemoryStream();
                // 创建一张工作薄。
                var workSheet = workbook.CreateSheet("大农户需求列表");
                //创建列头文本
                var tableHeaderTexts = new string[] {
                    "需求单编号",
                    "发起人",
                    "发起人用户编号",
                    "发起人手机号",
                    "省",
                    "市",
                    "区/县",
                    "乡",
                    "村",
                    "农作物类型",
                    "需求类型",
                    "亩数",
                    "摘要",
                    "发起时间",
                    "期望日期",
                    "需求状态",
                    "应答人用户编号",
                    "应答人手机号",
                    "应答时间",
                    "收到的评价"
                };
                //设置列头样式
                ICellStyle style = workbook.CreateCellStyle();
                style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
                style.FillPattern         = FillPattern.SolidForeground;

                var headerRow = workSheet.CreateRow(0);
                //生成列头
                for (int i = 0; i < tableHeaderTexts.Length; i++)
                {
                    var currentCell = headerRow.CreateCell(i);
                    currentCell.SetCellValue(tableHeaderTexts[i]);
                    currentCell.CellStyle = style;
                }
                workSheet.CreateFreezePane(0, 1, 0, 1);
                var currentRoeIndex  = 0;
                var dateFormatString = "yyyy.MM.dd HH:mm:ss";

                //给用地区信息赋上说明
                foreach (var demand in modelList)
                {
                    currentRoeIndex++;
                    //创建内容行
                    var sheetRow = workSheet.CreateRow(currentRoeIndex);//创建一行
                    //创建内容列
                    for (int cellIndex = 0; cellIndex < tableHeaderTexts.Length; cellIndex++)
                    {
                        var cell = sheetRow.CreateCell(cellIndex);
                        cell.SetCellType(CellType.String);
                    }

                    //需求单编号
                    sheetRow.Cells[0].SetCellValue(demand.Id);
                    //发起人
                    var demandCreateUserId = int.Parse(demand.CreateUser);
                    var userInfo           = userList.Where(p => p.Id == demandCreateUserId).FirstOrDefault();
                    sheetRow.Cells[1].SetCellValue(userInfo == null ? string.Empty : userInfo.UserName);
                    //发起人用户编号
                    sheetRow.Cells[2].SetCellValue(demand.CreateUser);
                    //发起人手机号
                    sheetRow.Cells[3].SetCellValue(demand.PhoneNumber);
                    //省份
                    var provinceInfo = areaInfoList.Where(p => p.AID == demand.Province).FirstOrDefault();
                    sheetRow.Cells[4].SetCellValue(provinceInfo == null ? string.Empty : provinceInfo.DisplayName);
                    //城市
                    var cityInfo = areaInfoList.Where(p => p.AID == demand.City).FirstOrDefault();
                    sheetRow.Cells[5].SetCellValue(cityInfo == null ? string.Empty : cityInfo.DisplayName);
                    //区县
                    var regionInfo = areaInfoList.Where(p => p.AID == demand.Region).FirstOrDefault();
                    sheetRow.Cells[6].SetCellValue(regionInfo == null ? string.Empty : regionInfo.DisplayName);
                    //乡镇
                    var townshipInfo = areaInfoList.Where(p => p.AID == demand.Township).FirstOrDefault();
                    sheetRow.Cells[7].SetCellValue(townshipInfo == null ? string.Empty : townshipInfo.DisplayName);
                    //村
                    var villageInfo = areaInfoList.Where(p => p.AID == demand.Village).FirstOrDefault();
                    sheetRow.Cells[8].SetCellValue(villageInfo == null ? string.Empty : villageInfo.DisplayName);
                    //农作物类型
                    var cropInfo = dicInfoList.Where(p => p.Code == demand.CropId).FirstOrDefault();
                    sheetRow.Cells[9].SetCellValue(cropInfo == null ? string.Empty : cropInfo.DisplayName);
                    //需求类型
                    sheetRow.Cells[10].SetCellValue(demand.DemandType);
                    //亩数
                    var acresInfo = dicInfoList.Where(p => p.Code == demand.AcresId).FirstOrDefault();
                    sheetRow.Cells[11].SetCellValue(acresInfo == null ? string.Empty : acresInfo.DisplayName);
                    //摘要
                    sheetRow.Cells[12].SetCellValue(demand.Brief ?? string.Empty);
                    //发起时间
                    sheetRow.Cells[13].SetCellValue(demand.CreateTime.ToString(dateFormatString));
                    //期望日期
                    sheetRow.Cells[14].SetCellValue(demand.ExpectedDate ?? string.Empty);
                    //需求状态
                    sheetRow.Cells[15].SetCellValue(demand.PublishState);
                    //应答人用户编号
                    var responseRecord = _farmerRequirement.GetDemandReplyList(demand.Id).FirstOrDefault();
                    if (responseRecord != null)
                    {
                        //应答人用户编号
                        sheetRow.Cells[16].SetCellValue(responseRecord.UserId);
                        //应答人手机号
                        sheetRow.Cells[17].SetCellValue(responseRecord.PhoneNumber);
                        //应答时间
                        sheetRow.Cells[18].SetCellValue(responseRecord.ReplyTime.ToString(dateFormatString));
                        string commentResult = string.Empty;
                        var    scoreString   = "|" + responseRecord.Score + "星";
                        if (responseRecord.Comments.IsNullOrEmpty() == false || responseRecord.Score > 0)
                        {
                            //收到的评价
                            sheetRow.Cells[19].SetCellValue(responseRecord.Comments.IsNullOrEmpty() ? "[未作评论]" + scoreString : responseRecord.Comments + scoreString);
                        }
                    }
                }

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