public byte[] GetExcel(AddmissionContext _context)
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            NPOI.SS.UserModel.ISheet sheet = wb.CreateSheet("录取学生表");
            var students = _context.Admissions.Include(a => a.AcceptedStudent).Where(a => a.Uname == userName).ToList();

            NPOI.SS.UserModel.IRow row;
            row = sheet.CreateRow(0);
            row.CreateCell(0).SetCellValue("考号");
            row.CreateCell(1).SetCellValue("姓名");
            row.CreateCell(2).SetCellValue("总分");
            row.CreateCell(3).SetCellValue("毕业学校");
            row.CreateCell(4).SetCellValue("录取方式");
            int count = 1;//行号游标

            foreach (var student in students)
            {
                row = sheet.CreateRow(count);
                row.CreateCell(0).SetCellValue(student.Sid);
                row.CreateCell(1).SetCellValue(student.AcceptedStudent.Sname);
                row.CreateCell(2).SetCellValue(student.AcceptedStudent.TotalGrade);
                row.CreateCell(3).SetCellValue(student.AcceptedStudent.GraduateSchool);
                row.CreateCell(4).SetCellValue(student.AdmissionMethod);
                count++;
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            wb.Write(ms);
            return(ms.ToArray());
        }
示例#2
0
 public bool ExecuteFileDelivery(AddmissionContext _context)
 {
     try
     {
         var delivery = _context.DeliverFiles;
         foreach (var deliverFile in delivery)
         {
             _context.Remove(deliverFile);
         }
         _context.SaveChanges();//清空投档表
         var applications = _context.Applications
                            .Include(s => s.UnacceptedStudent)
                            .GroupBy(s => s.UnacceptedStudent)
                            .OrderByDescending(s => s.Key.TotalGrade);
         var   colleges = _context.Universities.ToList();
         int[] remaning = new int[colleges.Count];
         for (int i = 0; i < remaning.Length; i++)//初始化各高校剩余名额
         {
             remaning[i] = (int)(colleges[i].ExpandRate * colleges[i].Enrollment);
         }
         foreach (var application in applications)                                    //对每个考生
         {
             var tempStudentApplication = application.GroupBy(s => s.Uname).ToList(); //该生志愿按学校组织
             foreach (var tempMajorApplication in tempStudentApplication)             //该生每个学校的相应志愿,tempMajorApplication为当前学校下的志愿集
             {
                 int index = colleges.IndexOf(colleges.Find(u => u.Uname == tempMajorApplication.Key));
                 if (remaning[index] > 0)                                           //若该校还能投档
                 {
                     var majors = tempMajorApplication.OrderBy(m => m.No).ToList(); //获取该生填报的具体到专业志愿
                     foreach (var major in majors)                                  //对每个志愿都插入到投档表中
                     {
                         var file = new DeliverFile {
                             Sid = major.Sid, Uname = major.Uname, Mid = major.Mid
                         };
                         _context.Add(file);
                     }
                     remaning[index]--; //能投入该校的考生减1
                     break;             //该生投档完成并结束循环
                 }
             }
         }
         foreach (var a in _context.Applications)//清空申请表
         {
             _context.Remove(a);
         }
         _context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#3
0
 public GenarateResultController(IResultRepo resultRepo, IAdmissionRepo <SelectedCandidate> repo, AddmissionContext context)
 {
     _resultRepo  = resultRepo;
     _repo        = repo;
     this.context = context;
 }
 public StudentController(AddmissionContext context, ILogger <Program> logger)
 {
     _context = context;
     _logger  = logger;
 }
 public OfficeController(AddmissionContext context, ILogger <OfficeController> logger)
 {
     _context = context;
     _logger  = logger;
 }
示例#6
0
 public SqlAdmissionRepo(AddmissionContext context)
 {
     _context = context;
 }
 public SqlResultRepo(AddmissionContext context)
 {
     _context = context;
 }
示例#8
0
 public UserController(AddmissionContext _dbContext)
 {
     dbContext = _dbContext;
 }