zoukankan      html  css  js  c++  java
  • 根据某个分数来计算排名

    linq:OrderByDescending 按指定表达式对集合倒序排序;延迟

    第一步:查询出学生成绩表中的数据

    using (var db = new SMSPModel.SMSPEntities())
                {
                    db.CommandTimeout = 0;
                    var tb = (from p in db.tbExamMark
                              where p.tbExamCourse.ID == this.DrplstExamCourse1.ExamCourseId
                              && p.RecordStatus == decimal.One
                              && p.tbExamCourse.RecordStatus == decimal.One
                              && p.tbExamCourse.tbExamBasis.ID == this.DrplstExam1.ExamId
                              && p.tbExamCourse.tbCourseBasis.RecordStatus == decimal.One
                              && p.tbExamCourse.tbCourseBasis.tbSubjectBasis.RecordStatus == decimal.One
                              && p.tbExamCourse.tbCourseBasis.tbSubjectBasis.tbAreaBasis.RecordStatus == decimal.One
                              && p.tbStudentBasis.RecordStatus == decimal.One
                              && p.tbStudentBasis.StudentStatus == decimal.One
                              orderby p.tbStudentBasis.StudentCode
                              select new ExamMark
                                     {
                                         StudentId = p.tbStudentBasis.ID,
                                         StudentCode = p.tbStudentBasis.StudentCode,
                                         StudentName = p.tbStudentBasis.StudentName,
                                         ClassName = (from p0 in db.tbClassStudent
                                                      where p0.RecordStatus == decimal.One &&
                                                            p0.tbStudentBasis.ID == p.tbStudentBasis.ID &&
                                                            p0.tbClassBasis.tbYear.FromDate <= p.tbExamCourse.tbExamBasis.tbYear.FromDate &&
                                                            p0.tbClassBasis.tbYear.ToDate >= p.tbExamCourse.tbExamBasis.tbYear.ToDate &&
                                                            p0.tbClassBasis.tbYear.tbYearGroup.GroupNo == decimal.One
                                                      select p0.tbClassBasis.ClassName).FirstOrDefault(),
                                         AppraiseMark = p.AppraiseMark == decimal.MinusOne ? null : (decimal?)p.AppraiseMark,
                                         Mark1 = p.Mark1 == decimal.MinusOne ? null : (decimal?)p.Mark1,
                                         Mark2 = p.Mark2 == decimal.MinusOne ? null : (decimal?)p.Mark2,
                                         TotalMark = p.TotalMark == decimal.MinusOne ? null : (decimal?)p.TotalMark,
                                         TotalGradeRank = p.TotalGradeRank == decimal.MinusOne ? null : (decimal?)p.TotalGradeRank,
                                         SegmentMark = p.SegmentMark == decimal.MinusOne ? null : (decimal?)p.SegmentMark,
                                         SegmentGradeRank = p.SegmentGradeRank == decimal.MinusOne ? null : (decimal?)p.SegmentGradeRank,
                                         LevelName = p.tbExamLevel.LevelName,
                                         GetPoint = p.tbExamLevel.LevelValue > decimal.Zero ? p.tbExamCourse.tbCourseBasis.CoursePoint : decimal.Zero,
                                         StudyPoint = p.tbExamCourse.tbCourseBasis.CoursePoint * (p.tbExamLevel.LevelName == "---" ? decimal.Zero : p.tbExamLevel.LevelValue)
                                     }).Distinct().OrderByDescending(c => c.SegmentMark).ToList();
    

    第二步,根据SegmentMark  综合分 进行排名

     //重新排名(综合分排名)
                    var studentScoresRankList = (from p in tb
                                                 select new ExamMark
                                                 {
                                                     StudentId = p.StudentId,
                                                     StudentCode = p.StudentCode,
                                                     StudentName = p.StudentName,
                                                     ClassName = p.ClassName,
                                                     AppraiseMark = p.AppraiseMark,
                                                     Mark1 = p.Mark1,
                                                     Mark2 = p.Mark2,
                                                     TotalMark = p.TotalMark,
                                                     TotalGradeRank = p.TotalGradeRank,
                                                     SegmentMark = p.SegmentMark,
                                                     LevelName = p.LevelName,
                                                     GetPoint = p.GetPoint,
                                                     StudyPoint = p.StudyPoint,
                                                     SegmentGradeRank = tb.Select(c => c.SegmentMark).ToList().IndexOf(p.SegmentMark) + 1,
                                                 }).OrderBy(c => c.TotalGradeRank).ToList();
    
    
                    return studentScoresRankList;
    

      然后排名就出来了,然后重新绑定就可以了。

  • 相关阅读:
    .NET 开源工作流: Slickflow流程引擎基础介绍(六)--模块化架构设计和实践
    .NET 开源工作流: Slickflow流程引擎基础介绍(五) -- 会签加签高级特性介绍
    vue实现Excel文件的上传与下载
    库存商品计算成本的几种方法
    如果有一天不做程序员了,还能入什么行业?
    C#使用EF连接PGSql数据库
    回顾2018,展望2019
    Git命令使用大全
    使用VSCode配置简单的vue项目
    SqlServer的两种插入方式效率对比
  • 原文地址:https://www.cnblogs.com/kksguijiao/p/4705197.html
Copyright © 2011-2022 走看看