private void btnQuery_Click(object sender, EventArgs e)
        {
            List <object> Result = new List <object>();

            //將學期科目成績用學生編號做群組
            foreach (var StudentGroup in StudentScores.GroupBy(x => x.RefStudentID))
            {
                //將個別學生學期科目成績用學年度做群組
                foreach (var StudentSchoolYearGroup in StudentGroup.GroupBy(x => x.SchoolYear))
                {
                    //假學生的學年有上下兩筆學期科目成績才進行處理
                    if (StudentSchoolYearGroup.ToList().Count >= 2)
                    {
                        //將資料根據學期加以排序
                        List <SHSemesterScoreRecord> records = StudentSchoolYearGroup.OrderBy(x => x.Semester).ToList();

                        //掃描上學期的每筆學期科目成績
                        foreach (string strSubject in records[0].Subjects.Keys)
                        {
                            //判斷下學期是否有相同的科目名稱
                            if (records[1].Subjects.ContainsKey(strSubject))
                            {
                                //上學期科目成績
                                decimal?UpScore = records[0].Subjects[strSubject].Score;
                                //下學期科目成績
                                decimal?DownScore = records[1].Subjects[strSubject].Score;

                                //判斷是否上學期科目成績大於50小於60,並且下學期科目成績大於60
                                if ((UpScore >= 50 && UpScore < 60) && DownScore > 60)
                                {
                                    decimal?SchoolYearScore = null;

                                    List <SHSchoolYearScoreRecord> SchoolYearScoreRecords = StudentSchoolYearScores.Where(x => x.RefStudentID.Equals(StudentGroup.Key) && x.SchoolYear.Equals(StudentSchoolYearGroup.Key)).ToList();

                                    if (SchoolYearScoreRecords.Count > 0)
                                    {
                                        List <SHSchoolYearScoreSubject> Subjects = SchoolYearScoreRecords[0].Subjects.Where(x => x.Subject.Equals(strSubject)).ToList();

                                        if (Subjects.Count > 0)
                                        {
                                            SchoolYearScore = Subjects[0].Score;
                                        }
                                    }

                                    Result.Add(new { 學號 = records[0].Student.StudentNumber, 姓名 = records[0].Student.Name, 學年度 = records[0].SchoolYear, 學期科目 = (strSubject + records[0].Subjects[strSubject].Level), 學期成績 = records[0].Subjects[strSubject].Score, 學期科目 = (strSubject + records[1].Subjects[strSubject].Level), 學期成績 = records[1].Subjects[strSubject].Score, 學年科目 = strSubject, 學年成績 = SchoolYearScore });
                                }
                            }
                        }
                    }
                }
            }

            grdScore.DataSource = Result;
        }
예제 #2
0
        //[SelectMethod("SchoolYearScoreJudge", "取得選取學生學年科目不及格進校判斷")]
        public static List <SchoolYearScoreJudgeRecord> Select()
        {
            List <SchoolYearScoreJudgeRecord> Result = new List <SchoolYearScoreJudgeRecord>();

            List <string> StudentIDs = K12.Presentation.NLDPanels.Student.SelectedSource;

            if (K12.Data.Utility.Utility.IsNullOrEmpty(StudentIDs))
            {
                return(Result);
            }

            List <SHSchoolYearScoreRecord> StudentSchoolYearScores = SHSchoolYearScore.SelectByStudentIDs(StudentIDs);
            List <SHSemesterScoreRecord>   StudentScores           = SHSemesterScore.SelectByStudentIDs(StudentIDs);

            //將學期科目成績用學生編號做群組
            foreach (var StudentGroup in StudentScores.GroupBy(x => x.RefStudentID))
            {
                //將個別學生學期科目成績用學年度做群組
                foreach (var StudentSchoolYearGroup in StudentGroup.GroupBy(x => x.SchoolYear))
                {
                    //假學生的學年有上下兩筆學期科目成績才進行處理
                    if (StudentSchoolYearGroup.ToList().Count >= 2)
                    {
                        //將資料根據學期加以排序
                        List <SHSemesterScoreRecord> records = StudentSchoolYearGroup.OrderBy(x => x.Semester).ToList();

                        //掃描上學期的每筆學期科目成績
                        foreach (string strSubject in records[0].Subjects.Keys)
                        {
                            //判斷下學期是否有相同的科目名稱
                            if (records[1].Subjects.ContainsKey(strSubject))
                            {
                                //上學期科目成績
                                decimal?UpScore = records[0].Subjects[strSubject].Score;
                                //下學期科目成績
                                decimal?DownScore = records[1].Subjects[strSubject].Score;

                                //判斷是否上學期科目成績大於50小於60,並且下學期科目成績大於60
                                if ((UpScore >= 50 && UpScore < 60) && DownScore > 60)
                                {
                                    decimal?SchoolYearScore = null;

                                    List <SHSchoolYearScoreRecord> SchoolYearScoreRecords = StudentSchoolYearScores.Where(x => x.RefStudentID.Equals(StudentGroup.Key) && x.SchoolYear.Equals(StudentSchoolYearGroup.Key)).ToList();

                                    if (SchoolYearScoreRecords.Count > 0)
                                    {
                                        List <SHSchoolYearScoreSubject> Subjects = SchoolYearScoreRecords[0].Subjects.Where(x => x.Subject.Equals(strSubject)).ToList();

                                        if (Subjects.Count > 0)
                                        {
                                            SchoolYearScore = Subjects[0].Score;
                                        }
                                    }

                                    SchoolYearScoreJudgeRecord record = new SchoolYearScoreJudgeRecord();

                                    record.StudentNumber       = records[0].Student.StudentNumber;
                                    record.Name                = records[0].Student.Name;
                                    record.SchoolYear          = records[0].SchoolYear;
                                    record.UPSemesterSubject   = (strSubject + records[0].Subjects[strSubject].Level);
                                    record.UpScore             = records[0].Subjects[strSubject].Score;
                                    record.DownSemesterSubject = (strSubject + records[1].Subjects[strSubject].Level);
                                    record.DownSemesterScore   = records[1].Subjects[strSubject].Score;
                                    record.SchoolYearSubject   = strSubject;
                                    record.SchoolYearScore     = SchoolYearScore;

                                    Result.Add(record);
                                }
                            }
                        }
                    }
                }
            }

            return(Result);
        }