public ActionResult ExportProject()
        {
            var seh = new SenparcExpressionHelper <CompetitionProgram>();

            //seh.ValueCompare.AndAlso(true, z => !z.Flag)
            //    .AndAlso(!projectId.IsNullOrEmpty(), z => z.ScheduleId == projectId)
            //    .AndAlso(!kw.IsNullOrEmpty(), z => z.Name.Contains(kw) || z.Company.Contains(kw) || z.SignNum.Contains(kw) || z.Remark.Contains(kw) || z.Desc.Contains(kw));


            var where = seh.BuildWhereExpression();

            var activies = _activityService.GetFullList(x => x.IsPublish, x => x.IsPublish, OrderingType.Descending).ToList();

            if (activies.Count < 1)
            {
                base.SetMessager(MessageType.danger, "请先完善活动主题");
                return(RedirectToAction("Index"));
            }
            var curactivity = activies.Select(x => x.Id).ToList();

            // List<Schedule> list = new List<Schedule>();

            var clist = _scheduleService.GetFullList(x => curactivity.Contains(x.ActivityId), x => x.Sort, OrderingType.Ascending).ToList().Select(x => x).ToList();


            var modelList = _competitionProgramService.GetObjectList(1, 10000, where, z => z.Id, OrderingType.Descending);

            List <ExportProjectTable> list = new List <ExportProjectTable>();

            int i = 1;

            modelList.OrderBy(x => x.ControlId).ThenBy(x => x.Id).ToList().ForEach(x =>
            {
                //var leader = new ProjectMember();

                //if (!string.IsNullOrEmpty(x.ControlId))
                //{
                //    var cleader = _projectMemberService.GetObject(xp => xp.IsLeader && xp.ProjectId == x.Id);

                //    if (cleader != null)
                //    {
                //        leader = cleader;
                //    }
                //}

                //var strcateName = string.Empty;

                //if (x.Schedule == null)
                //{
                //    x.Schedule = _scheduleService.GetObject(s => s.Id == x.ScheduleId);
                //}

                list.Add(new ExportProjectTable
                {
                    CateName    = CateManager.GetCateName(x.Cate),
                    CompanyId   = x.ControlId,
                    CompanyName = x.Company,
                    ProjectName = x.Name,
                    SignNum     = (string.IsNullOrEmpty(x.SignNum)?"否":x.SignNum),
                    Sort        = i.ToString()
                });

                i++;
            });

            //var vd = new CompetitionProgram_IndexVD()
            //{
            //    CompetitionProgramList = new PagedList<CompetitionProgram_EditVD>(list, pageIndex, modelList.PageCount, modelList.TotalCount, modelList.SkipCount),
            //    kw = kw,
            //    ProjectId = projectId,
            //    Schedules = clist
            //};



            var datatable = DataTableListUtil.ListToDt <ExportProjectTable>(list);

            ExcelHelper excelHelper = new ExcelHelper();
            ExcelConfig excelConfig = new ExcelConfig()
            {
                IsAllSizeColumn = true,
                Title           = "抽签结果表",
                ColumnEntity    = new List <ColumnModel>()
            };
            var props = typeof(ExportProjectTable).GetProperties();
            //   var dt = new DataTable();
            string proName = "";

            excelConfig.ColumnEntity.AddRange(props.Select(p => {
                switch (p.Name)
                {
                case "Sort":
                    proName = "序号";
                    break;

                case "CompanyId":
                    proName = "公司ID";
                    break;

                case "CompanyName":
                    proName = "公司";
                    break;

                case "ProjectName":
                    proName = "参演项目";
                    break;

                case "CateName":
                    proName = "参演项目类型";
                    break;

                case "SignNum":
                    proName = "签号";
                    break;

                default:
                    proName = p.Name;
                    break;
                }

                return(new ColumnModel()
                {
                    Column = p.Name,
                    ExcelColumn = proName,
                });
            }).ToArray());

            return(excelHelper.ExcelDownload(datatable, excelConfig, string.Format("{0}_抽签结果表", DateTime.Now.ToString("yyyyMMddHHmm"))));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult ExportMember()
        {
            var activies = _activityService.GetFullList(x => x.IsPublish, x => x.IsPublish, OrderingType.Descending).ToList();

            if (activies.Count < 1)
            {
                base.SetMessager(MessageType.danger, "请先完善活动主题");
                return(RedirectToAction("Index"));
            }
            var curactivity = activies.Select(x => x.Id).ToList();

            // List<Schedule> list = new List<Schedule>();

            var clist = _scheduleService.GetFullList(x => curactivity.Contains(x.ActivityId), x => x.Sort, OrderingType.Ascending).ToList().Select(x => x.Id).ToList();

            var modellist = _competitionProgramService.GetFullList(x => clist.Contains(x.ScheduleId), x => x.CreateTime, OrderingType.Descending).Select(x => x).ToList();


            var seh = new SenparcExpressionHelper <ProjectMember>();

            //seh.ValueCompare.AndAlso(true, z => !z.Flag)
            //    .AndAlso(!kw.IsNullOrEmpty(), z => z.Name.Contains(kw) || z.Company.Contains(kw) || z.Duty.Contains(kw) || z.Phone.Contains(kw) || z.Nation.Contains(kw));

            //if (!string.IsNullOrEmpty(ProjectId))
            //{
            //    seh.ValueCompare.AndAlso(true, z => z.ProjectId == ProjectId);
            //}

            var where = seh.BuildWhereExpression();


            //var seh = new SenparcExpressionHelper<ProjectMember>();
            //seh.ValueCompare.AndAlso(true, z => !z.Flag)
            //    .AndAlso(!kw.IsNullOrEmpty(), z => z.Name.Contains(kw) || z.Company.Contains(kw) || z.Duty.Contains(kw) || z.Phone.Contains(kw) || z.Nation.Contains(kw));
            //var where = seh.BuildWhereExpression();

            var modelList = _projectMemberService.GetObjectList(1, 20000, where, z => z.Id, OrderingType.Descending);
            List <ProjectMember_EditVD> list = new List <ProjectMember_EditVD>();

            modelList.ForEach(x =>
            {
                var leader = new CompetitionProgram();

                if (!string.IsNullOrEmpty(x.ProjectId))
                {
                    var cleader = _competitionProgramService.GetObject(xp => xp.Id == x.ProjectId);

                    if (cleader != null)
                    {
                        leader = cleader;
                    }
                }

                var strcateName = string.Empty;

                if (leader.Schedule == null)
                {
                    leader.Schedule = _scheduleService.GetObject(s => s.Id == leader.ScheduleId);
                }

                list.Add(new ProjectMember_EditVD
                {
                    ProjectId          = x.ProjectId,
                    Name               = x.Name,
                    Nation             = x.Nation,
                    IdCard             = x.IdCard,
                    Company            = x.Company,
                    Duty               = x.Duty,
                    Gender             = x.Gender,
                    Id                 = x.Id,
                    Phone              = x.Phone,
                    CreateTime         = x.CreateTime,
                    CompetitionProgram = leader,
                    Email              = x.Email,
                    IsLeader           = x.IsLeader,
                    HeadImgUrl         = x.HeadImgUrl,
                    IdCardImgUrl       = x.IdCardImgUrl,
                    UserName           = x.Phone
                });
            });
            List <ExportProMemberTable> exportProMemberTables = new List <ExportProMemberTable>();
            var i = 1;

            list.OrderBy(x => x.ProjectId).ToList().ForEach(x =>
            {
                ExportProMemberTable rowItem = new ExportProMemberTable
                {
                    Sort        = i.ToString(),
                    CompanyId   = x.CompetitionProgram.ControlId,
                    Company     = x.CompetitionProgram.Company,
                    ContactTel  = x.Phone,
                    IdCard      = x.IdCard,
                    Name        = x.Name,
                    Nation      = x.Nation,
                    ProjectName = x.CompetitionProgram.Name,
                    ProjectType = CateManager.GetCateName(x.CompetitionProgram.Cate),
                    WorkCom     = x.Company
                };

                exportProMemberTables.Add(rowItem);
                i++;
            });


            var datatable = DataTableListUtil.ListToDt <ExportProMemberTable>(exportProMemberTables);

            ExcelHelper excelHelper = new ExcelHelper();
            ExcelConfig excelConfig = new ExcelConfig()
            {
                Title           = "参赛者列表",
                ColumnEntity    = new List <ColumnModel>(),
                IsAllSizeColumn = true,
            };
            var props = typeof(ExportProMemberTable).GetProperties();
            //   var dt = new DataTable();
            string proName = "";

            excelConfig.ColumnEntity.AddRange(props.Select(p => {
                switch (p.Name)
                {
                case "Sort":
                    proName = "序号";
                    break;

                case "CompanyId":
                    proName = "公司ID";
                    break;

                case "Company":
                    proName = "公司";
                    break;

                case "ProjectName":
                    proName = "参演项目";
                    break;

                case "ProjectType":
                    proName = "参演项目类型";
                    break;

                case "Name":
                    proName = "姓名";
                    break;

                case "WorkCom":
                    proName = "工作单位";
                    break;

                case "ContactTel":
                    proName = "联系电话";
                    break;

                case "Nation":
                    proName = "民族";
                    break;

                case "IdCard":
                    proName = "身份证号";
                    break;

                default:
                    proName = p.Name;
                    break;
                }

                return(new  ColumnModel()
                {
                    Column = p.Name,
                    ExcelColumn = proName,
                });
            }).ToArray());

            return(excelHelper.ExcelDownload(datatable, excelConfig, string.Format("{0}_参赛者表", DateTime.Now.ToString("yyyyMMddHHmm"))));

            //var vd = new ProjectIndex_EditVD()
            //{
            //    CompetitionProgramList = new PagedList<ProjectMember_EditVD>(list, pageIndex, modelList.PageCount, modelList.TotalCount, modelList.SkipCount),
            //    kw = kw,
            //    ProjectId = ProjectId,
            //    CpList = modellist
            //};
            //   return View(null);
        }