private void fillSubjectScore(StudentScoreInfo studScore, DataRow row)
        {
            // find subjects he tales
            List <SubjectScoreFSceTake> subjScores = studScore.DicSubjectScoreFScAttend.Values.ToList <SubjectScoreFSceTake>();

            subjScores.Sort(new SubjectScoreComparaer(
                                "國文"
                                , "英文"
                                , "數學"
                                , "理化"
                                , "生物"
                                , "社會"
                                , "物理"
                                , "化學"
                                , "歷史"
                                , "地理"
                                , "公民"
                                ));
            int     rowNo            = 1;
            decimal totalScore       = 0;
            decimal totalCredits     = 0;
            int     failSubjectCount = 0;
            decimal failCredits      = 0;


            try
            {
                foreach (SubjectScoreFSceTake subjScoreFSceTake in subjScores)
                {
                    //如果科目筆數 > 15 加入錯誤訊息裡 _ListErrors
                    if (rowNo > 15)
                    {
                        if (!_ListErrors.Any(x => x.StudentID == studScore.StudentID))
                        {
                            ErrorInfo errorInfo = new ErrorInfo();
                            errorInfo.Type          = "科目數大於15";
                            errorInfo.Detail        = $"本次定期評量列印科目數大於15,列印樣板不適用";
                            errorInfo.StudentID     = studScore.StudentID;
                            errorInfo.StudentNumber = studScore.StudnetNumber;
                            errorInfo.ListError.Add(errorInfo);
                            _ListErrors.Add(errorInfo);
                        }
                        continue;
                    }

                    String levelString = getLevelString(subjScoreFSceTake.Level);
                    row[$"科目{rowNo}"] = $"{subjScoreFSceTake.SubjectName}{levelString}";
                    row[$"學分{rowNo}"] = subjScoreFSceTake.Credit;

                    if (subjScoreFSceTake.Score == "" || subjScoreFSceTake.Score == "-1") //"" 為沒有輸入成績 && "-1"為缺考 (畫面顯示為"缺");
                    {
                        if (subjScoreFSceTake.Score == "")
                        {
                            row[$"成績{rowNo}"] = "未輸入";
                        }

                        else if (subjScoreFSceTake.Score == "-1")
                        {
                            row[$"成績{rowNo}"] = "缺考";
                        }
                    }
                    else
                    {//如果有分數 在判斷是否及格
                        row[$"成績{rowNo}"] = subjScoreFSceTake.IsPassing == "true" ? subjScoreFSceTake.Score : "*" + subjScoreFSceTake.Score;
                    }


                    if (studScore.DicSubjectRankInfo.ContainsKey(subjScoreFSceTake.SubjectName))
                    {
                        SubjectScoreInfos subjScoreInfo = studScore.DicSubjectRankInfo[subjScoreFSceTake.SubjectName];

                        //填入班級名次  如果沒有成績就填入""
                        if (subjScoreFSceTake.Score == "" || subjScoreFSceTake.Score == "-1")
                        {
                            row[$"班級名次{rowNo}"] = "";
                        }
                        else
                        {
                            row[$"班級名次{rowNo}"] = subjScoreInfo.ClassRank;
                        }

                        //填入科組名次  如果有沒有成績就填 ""
                        if (subjScoreFSceTake.Score == "" || subjScoreFSceTake.Score == "-1")
                        {
                            row[$"科組名次{rowNo}"] = "";
                        }
                        else //如果有成績就填 有類排就填類排。
                        {
                            if (subjScoreInfo.TeamOrDeptRank.ContainsKey("類別1排名"))
                            {
                                row[$"科組名次{rowNo}"] = subjScoreInfo.TeamOrDeptRank["類別1排名"];
                            }
                            else if (subjScoreInfo.TeamOrDeptRank.ContainsKey("科排名"))
                            {
                                row[$"科組名次{rowNo}"] = subjScoreInfo.TeamOrDeptRank["科排名"];
                            }
                        }

                        row[$"年級名次{rowNo}"]  = subjScoreInfo.GradeRank;
                        row[$"班級平均{rowNo}"]  = Math.Round(double.Parse(subjScoreInfo.Avg), 2);
                        row[$"及格人數{rowNo}"]  = subjScoreFSceTake.PassingCount;
                        row[$"不及格人數{rowNo}"] = subjScoreFSceTake.NotPassingCount;
                    }
                    decimal score  = (String.IsNullOrWhiteSpace(subjScoreFSceTake.Score) ? 0 : decimal.Parse(subjScoreFSceTake.Score));
                    decimal credit = (String.IsNullOrWhiteSpace(subjScoreFSceTake.Credit) || String.IsNullOrWhiteSpace(subjScoreFSceTake.Score)) ? 0 : decimal.Parse(subjScoreFSceTake.Credit);
                    if (subjScoreFSceTake.Score == "")
                    {
                        Console.WriteLine("缺考");
                    }

                    totalScore   += score * credit;
                    totalCredits += credit;

                    //如果成績大是及格
                    if (subjScoreFSceTake.IsPassing == "false")
                    {
                        failCredits      += credit;
                        failSubjectCount += 1;
                    }
                    rowNo++;
                }

                row["加權總分"]   = totalScore;
                row["加權平均"]   = (totalCredits == 0) ? "" : Math.Round(totalScore / totalCredits, 1).ToString();
                row["不及格學分數"] = failCredits;
                row["不及格科目數"] = failSubjectCount;
                row["修習學分數"]  = totalCredits;

                if (_ListErrors.Count > 0)
                {
                    ErrorInfo err = new ErrorInfo();
                    // = _ListErrors;
                    this.onError(_ListErrors);
                }
            }
            catch (Exception ex)
            {
                if (this.onError != null)
                {
                    ErrorInfo err = new ErrorInfo();
                    err.Type   = "Exception";
                    err.Detail = ex.Message;
                    this._ListErrors.Add(err);
                    this.onError(_ListErrors);
                }
            }
        }
        /// <summary>
        ///  取得學生排名(固定排名中 【rank_matrix】)(識別)
        /// </summary>
        private void loadSubjectScore()
        {
            string sql = @"

WITH   rank_matrix_sp_semester   AS (
	SELECT 
		*
	FROM 
		rank_matrix
	WHERE
		is_alive =true
		AND  item_type ='定期評量/科目成績'
		AND (rank_type ='班排名' OR rank_type ='類別1排名' OR rank_type ='科排名' OR rank_type ='年排名')
		AND ref_exam_id ={3}
		AND school_year ='{1}'
		AND semester ='{2}'
)SELECT
		rank_matrix_sp_semester.school_year
		,rank_matrix_sp_semester.semester
		,rank_matrix_sp_semester.matrix_count
		,rank_matrix_sp_semester.rank_type
		,rank_matrix_sp_semester.rank_name
		,rank_matrix_sp_semester.item_name
		,rank_matrix_sp_semester.item_type
        ,rank_matrix_sp_semester.level_lt10
        ,rank_matrix_sp_semester.level_10
        ,rank_matrix_sp_semester.level_20
        ,rank_matrix_sp_semester.level_30
        ,rank_matrix_sp_semester.level_40
        ,rank_matrix_sp_semester.level_50
        ,rank_matrix_sp_semester.level_60
        ,rank_matrix_sp_semester.level_70
        ,rank_matrix_sp_semester.level_80
        ,rank_matrix_sp_semester.level_90
        ,rank_matrix_sp_semester.level_gte100
        ,rank_matrix_sp_semester.avg_top_25
        ,rank_matrix_sp_semester.avg_top_50
		,rank_matrix_sp_semester.avg
        ,rank_matrix_sp_semester.avg_bottom_50
        ,rank_matrix_sp_semester.avg_bottom_25
		,rank_detail.*
	FROM  rank_matrix_sp_semester
		LEFT JOIN  rank_detail 
		ON rank_detail.ref_matrix_id =rank_matrix_sp_semester .id
WHERE 
ref_student_id IN 
(
{0}
)

";

            sql = String.Format(sql, String.Join(",", this.studentIDs), SchoolYear, Semester, ExamID);

            DataTable dt = tool._Q.Select(sql);

            foreach (DataRow dr in dt.Rows)
            {
                string rankType = "" + dr["rank_type"];

                string studentID = "" + dr["ref_student_id"];

                string subjectName = "" + dr["item_name"];



                //學生資料的 Dictionary 有該學生資料
                if (this._DicStudentScoreInfo.ContainsKey(studentID))
                {
                    SubjectScoreInfos subjectScoreInfo;


                    //如果取出該*學生並檢查期存放科目成績的Dictionay 是否有此*科目
                    //如果沒有該科目
                    if (!_DicStudentScoreInfo[studentID].DicSubjectRankInfo.ContainsKey(subjectName))
                    {
                        subjectScoreInfo = new SubjectScoreInfos(subjectName);

                        subjectScoreInfo.Subject          = "" + dr["item_name"];
                        subjectScoreInfo.Score            = "" + dr["score"];
                        subjectScoreInfo.ClassMatrixCount = "" + dr["matrix_count"];

                        //級距
                        subjectScoreInfo.level_lt10   = "" + dr["level_lt10"];
                        subjectScoreInfo.level_10     = "" + dr["level_10"];
                        subjectScoreInfo.level_20     = "" + dr["level_20"];
                        subjectScoreInfo.level_30     = "" + dr["level_30"];
                        subjectScoreInfo.level_40     = "" + dr["level_40"];
                        subjectScoreInfo.level_50     = "" + dr["level_50"];
                        subjectScoreInfo.level_60     = "" + dr["level_60"];
                        subjectScoreInfo.level_70     = "" + dr["level_70"];
                        subjectScoreInfo.level_80     = "" + dr["level_80"];
                        subjectScoreInfo.level_90     = "" + dr["level_90"];
                        subjectScoreInfo.level_gte100 = "" + dr["level_gte100"];

                        subjectScoreInfo.AvgTop25     = "" + dr["avg_top_25"];
                        subjectScoreInfo.AvgTop50     = "" + dr["avg_top_50"];
                        subjectScoreInfo.Avg          = "" + dr["avg"];
                        subjectScoreInfo.AvgButtom_50 = "" + dr["avg_bottom_50"];
                        subjectScoreInfo.AvgButtom_25 = "" + dr["avg_bottom_25"];

                        if (rankType == "班排名")
                        {
                            subjectScoreInfo.ClassRank     = "" + dr["rank"];
                            subjectScoreInfo.RankClassName = "" + dr["rank_name"];
                        }
                        else if (rankType == "年排名")
                        {
                            subjectScoreInfo.GradeRank = "" + dr["rank"];
                        }
                        else if (rankType == "科排名" || rankType == "類別1排名")
                        {
                            if (rankType == "類別1排名")
                            {
                                subjectScoreInfo.TeamName = "" + dr["rank_name"];
                            }

                            if (rankType == "科排名")
                            {
                                subjectScoreInfo.TeamName = "" + dr["rank_name"];
                            }

                            if (!subjectScoreInfo.TeamOrDeptRank.ContainsKey(rankType))
                            {
                                subjectScoreInfo.TeamOrDeptRank.Add("" + dr["rank_type"], "" + dr["rank"]);
                            }
                            else
                            {
                                Console.WriteLine("= =?");
                            }
                        }

                        _DicStudentScoreInfo[studentID].DicSubjectRankInfo.Add(subjectName, subjectScoreInfo);
                    }

                    else
                    {
                        //如果已經有此科目
                        subjectScoreInfo = this._DicStudentScoreInfo[studentID].DicSubjectRankInfo[subjectName];

                        if (rankType == "班排名")
                        {
                            subjectScoreInfo.ClassRank     = "" + dr["rank"];
                            subjectScoreInfo.RankClassName = "" + dr["rank_name"];
                        }
                        else if (rankType == "年排名")
                        {
                            subjectScoreInfo.GradeRank = "" + dr["rank"];
                        }
                        else if (rankType == "科排名" || rankType == "類別1排名")
                        {
                            if (rankType == "類別1排名")
                            {
                                subjectScoreInfo.TeamName = "" + dr["rank_name"];
                            }

                            if (rankType == "科排名")
                            {
                                subjectScoreInfo.TeamName = "" + dr["rank_name"];
                            }

                            if (!subjectScoreInfo.TeamOrDeptRank.ContainsKey(rankType))
                            {
                                subjectScoreInfo.TeamOrDeptRank.Add("" + dr["rank_type"], "" + dr["rank"]);
                            }
                            else
                            {
                            }
                        }
                    }
                }
                else
                {
                }
            }
        }