예제 #1
0
        /// <summary>
        /// 取得學期歷程資料。
        /// </summary>
        /// <param name="students"></param>
        public static void FillSemesterHistory(this List <StudentExcess> students)
        {
            Dictionary <string, XElement> dicSemsHistory = GetSemesterHistory(students);

            students.ForEach(x => //將學生的學期歷程 Xml 轉換為 SemesterDataCollection。
            {
                SemesterDataCollection semester = new SemesterDataCollection();

                if (dicSemsHistory.ContainsKey(x.StudentID))
                {
                    XElement xmlsems = dicSemsHistory[x.StudentID];

                    foreach (XElement sems in xmlsems.Elements("History"))
                    {
                        //<History GradeYear="2" SchoolYear="96" Semester="2"/>
                        int sy = int.Parse(sems.Attribute("SchoolYear").Value);
                        int ss = int.Parse(sems.Attribute("Semester").Value);
                        int gy = int.Parse(sems.Attribute("GradeYear").Value);

                        semester.Add(new SemesterData(gy, sy, ss));
                    }
                }

                x.Semesters = semester;
            });
        }
예제 #2
0
        public decimal?GetScore(ReportStudent student)
        {
            SemesterDataCollection semesters = new SemesterDataCollection();

            foreach (SemesterData each in student.SHistory.GetGradeYearSemester().GetSemesters(RequestSemesters))
            {
                semesters.Add(new SemesterData(0, each.SchoolYear, each.Semester));
            }

            if (student.SemestersScore.AvgLearningDomainScore(semesters).HasValue)
            {
                //return student.SemestersScore.AvgLearningDomainScore(semesters).Value;
                // 修改讀取成績計算規則進位方式
                if (student.CalculationRule == null)
                {
                    return(student.SemestersScore.AvgLearningDomainScore(semesters).Value);
                }
                else
                {
                    return(student.CalculationRule.ParseLearnDomainScore(student.SemestersScore.AvgLearningDomainScore(semesters).Value));
                }
            }
            else
            {
                return(0);
            }
            //SemesterDataCollection semesters = new SemesterDataCollection();
            //foreach (SemesterData each in student.SHistory.GetGradeYearSemester().GetSemesters(RequestSemesters))
            //    semesters.Add(new SemesterData(0, each.SchoolYear, each.Semester));

            //return student.SemestersScore.AvgLearningDomainScore(semesters);
        }
예제 #3
0
            public HistoryUtil(JHSemesterHistoryRecord historyRecord)
            {
                _sems = new SemesterDataCollection();

                foreach (SemesterHistoryItem item in historyRecord.SemesterHistoryItems)
                {
                    _sems.Add(new SemesterData(item.GradeYear, item.SchoolYear, item.Semester));
                }

                _sems = _sems.GetGradeYearSemester();

                SemesterData last   = SemesterData.Empty;
                bool         delete = false;

                foreach (SemesterData sem in _sems)
                {
                    if (sem.GradeYear == 3 && sem.Semester == 2)
                    {
                        last   = sem;
                        delete = true;
                    }
                }
                if (delete)
                {
                    _sems.Remove(last);
                }
            }
예제 #4
0
        public decimal?GetScore(ReportStudent student)
        {
            SemesterDataCollection semesters = new SemesterDataCollection();

            foreach (SemesterData each in student.SHistory.GetGradeYearSemester().GetSemesters(RequestSemesters))
            {
                semesters.Add(new SemesterData(0, each.SchoolYear, each.Semester));
            }

            return(student.SemestersScore.AvgLearningDomainScore(semesters));
        }
        private void PrintSubjectOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印科目
            UniqueSet<RowHeader> RowIndexs = new UniqueSet<RowHeader>();

            #region 列印 RowHeader
            Dictionary<string, string> subjToDomain = new Dictionary<string, string>();
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                if (!student.SemestersScore.Contains(sysems)) continue;

                SemesterScore semsscore = student.SemestersScore[sysems];

                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (!subjToDomain.ContainsKey(strSubject))
                        subjToDomain.Add(strSubject, subject.Domain);

                    RowHeader header = new RowHeader(subjToDomain[strSubject], strSubject);
                    header.IsDomain = false;

                    if (!RowIndexs.Contains(header))
                        RowIndexs.Add(header);
                }
            }

            List<RowHeader> sortedHeaders = RowIndexs.ToList();
            sortedHeaders.Sort(delegate(RowHeader x, RowHeader y)
            {
                Subj xx = new JHSchool.Evaluation.Subject(x.Subject, x.Domain);
                Subj yy = new JHSchool.Evaluation.Subject(y.Subject, y.Domain);

                return xx.CompareTo(yy);
            });

            //產生 Row。
            List<RowHeader> indexHeaders = new List<RowHeader>();
            Row current = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                string gn = "";
                //Additional Classes

                string subjCName = header.Subject;
                string subjEName = Subj.GetSubjectEnglish(header.Subject);
                string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : " " + subjEName);

                datarow.Cells[0].Write(builder, subjString);

                //if (IsFlexible(header.Domain))
                //{
                //    gn = "彈性課程\nAdditional Classes";
                //    //把空白的領域當成「彈性課程」。
                //    datarow.Cells[0].Write(builder, gn);
                //    datarow.Cells[1].Write(builder, subjString);
                //}
                //else
                //{
                //}
            }
            #endregion

            #region 填資料
            //填資料
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems)) continue;
                    if (!student.HeaderList.ContainsKey(sysems)) continue;

                    int columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore = student.SemestersScore[sysems];

                    decimal? score = null;
                    decimal? weight = null;

                    //if (header.IsDomain)
                    //{
                    //    if (semsscore.Domain.Contains(header.Domain))
                    //    {
                    //        score = semsscore.Domain[header.Domain].Value;
                    //        weight = semsscore.Domain[header.Domain].Weight;
                    //    }
                    //}
                    //else
                    //{
                    if (semsscore.Subject.Contains(header.Subject))
                    {
                        score = semsscore.Subject[header.Subject].Value;
                        weight = semsscore.Subject[header.Subject].Weight;
                    }
                    //}

                    if (!score.HasValue) continue;
                    if (!weight.HasValue) weight = 0;

                    if (PrintScore)
                        row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    else
                        row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                }
            }
            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                Row row = table.Rows[header.Index + DataRowOffset];

                //if (IsFlexible(header.Domain))
                //{
                //    if (previousCellDomain == row.Cells[0].ToTxt())
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                //    else
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;
                //}
                //else
                {
                    row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                    row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
        private void PrintDomainOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印領域
            UniqueSet<RowHeader> RowIndexs = new UniqueSet<RowHeader>();

            #region 列印 RowHeader
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);

                //如果不包含該學期成績資料,就跳過。
                if (!student.SemestersScore.Contains(sysems)) continue;

                SemesterScore semsscore = student.SemestersScore[sysems];

                //準備彈性課程的科目(要詳列出來)。
                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (DetailDomain.Contains(subject.Domain))
                    {
                        RowHeader header = new RowHeader(subject.Domain, strSubject);
                        header.IsDomain = false;

                        if (!RowIndexs.Contains(header))
                            RowIndexs.Add(header);
                    }
                }

                //準備領域資料。
                foreach (string strDomain in semsscore.Domain)
                {
                    if (!Subj.Domains.Contains(strDomain)) continue;

                    SemesterDomainScore domain = semsscore.Domain[strDomain];

                    if (!DetailDomain.Contains(strDomain))
                    {
                        RowHeader header = new RowHeader(strDomain, string.Empty);
                        header.IsDomain = true;

                        if (!RowIndexs.Contains(header))
                            RowIndexs.Add(header);
                    }
                }
            }

            List<RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList());

            //產生 Row。
            List<RowHeader> indexHeaders = new List<RowHeader>();
            Row current = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);
                bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                if (header.IsDomain)
                {
                    string domainCName = header.Domain;
                    string domainEName = Subj.GetDomainEnglish(header.Domain);
                    string domainString = domainCName + (string.IsNullOrEmpty(domainEName) ? "" : domainEName);

                    if (hasGroup)
                    {
                        string gn = groupName;

                        if (groupName == "語文")
                            gn = "語文\nLanguage";

                        datarow.Cells[0].Write(builder, gn);
                        datarow.Cells[1].Write(builder, domainString);
                    }
                    else
                        datarow.Cells[0].Write(builder, domainString);
                }
                else
                {
                    string gn = "";
                    //Additional Classes

                    if (IsFlexible(header.Domain))
                        gn = "彈性課程\nAdditional Classes";
                    else
                        gn = header.Domain;

                    string subjCName = header.Subject;
                    string subjEName = Subj.GetSubjectEnglish(header.Subject);
                    string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : "\n" + subjEName);

                    //把空白的領域當成「彈性課程」。
                    string domain = gn;
                    datarow.Cells[0].Write(builder, domain);
                    datarow.Cells[1].Write(builder, subjString);
                }
            }
            #endregion

            #region 填資料
            //Row RatingRow = null;
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems)) continue;
                    if (!student.HeaderList.ContainsKey(sysems)) continue;

                    int columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore = student.SemestersScore[sysems];

                    decimal? score = null;
                    decimal? weight = null;

                    if (header.IsDomain)
                    {
                        if (semsscore.Domain.Contains(header.Domain))
                        {
                            score = semsscore.Domain[header.Domain].Value;
                            weight = semsscore.Domain[header.Domain].Weight;
                        }
                    }
                    else
                    {
                        if (semsscore.Subject.Contains(header.Subject))
                        {
                            score = semsscore.Subject[header.Subject].Value;
                            weight = semsscore.Subject[header.Subject].Weight;
                        }
                    }

                    if (!score.HasValue) continue;
                    if (!weight.HasValue) weight = 0;

                    if (PrintScore)
                        row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    else
                        row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                }

            }

            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row row = table.Rows[header.Index + DataRowOffset];

                if (previousCellDomain == row.Cells[0].ToTxt())
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                else
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;

                if (header.IsDomain)
                {
                    if (!hasGroup)
                    {
                        row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                        row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                    }
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
예제 #7
0
        private void PrintDomainOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印領域
            UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>();

            #region 列印 RowHeader
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);

                //如果不包含該學期成績資料,就跳過。
                if (!student.SemestersScore.Contains(sysems))
                {
                    continue;
                }

                SemesterScore semsscore = student.SemestersScore[sysems];

                //準備彈性課程的科目(要詳列出來)。
                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (DetailDomain.Contains(subject.Domain))
                    {
                        RowHeader header = new RowHeader(subject.Domain, strSubject);
                        header.IsDomain = false;

                        if (!RowIndexs.Contains(header))
                        {
                            RowIndexs.Add(header);
                        }
                    }
                }

                //準備領域資料。
                foreach (string strDomain in semsscore.Domain)
                {
                    if (!Subj.Domains.Contains(strDomain))
                    {
                        continue;
                    }

                    SemesterDomainScore domain = semsscore.Domain[strDomain];

                    if (!DetailDomain.Contains(strDomain))
                    {
                        RowHeader header = new RowHeader(strDomain, string.Empty);
                        header.IsDomain = true;

                        if (!RowIndexs.Contains(header))
                        {
                            RowIndexs.Add(header);
                        }
                    }
                }
            }

            List <RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList());

            //產生 Row。
            List <RowHeader> indexHeaders = new List <RowHeader>();
            Row current  = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);
                bool   hasGroup  = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                if (header.IsDomain)
                {
                    string domainCName = header.Domain;
                    //string domainEName = Subj.GetDomainEnglish(header.Domain);
                    string domainEName  = _SubjDomainEngNameMapping.GetDomainEngName(header.Domain);
                    string domainString = domainCName + (string.IsNullOrEmpty(domainEName) ? "" : domainEName);

                    if (hasGroup)
                    {
                        string gn = groupName;

                        if (groupName == "語文")
                        {
                            gn = "語文\nLanguage";
                        }

                        datarow.Cells[0].Write(builder, gn);
                        datarow.Cells[1].Write(builder, domainString);
                    }
                    else
                    {
                        datarow.Cells[0].Write(builder, domainString);
                    }
                }
                else
                {
                    string gn = "";
                    //Additional Classes

                    if (IsFlexible(header.Domain))
                    {
                        gn = "彈性課程\nAdditional Classes";
                    }
                    else
                    {
                        gn = header.Domain;
                    }

                    string subjCName = header.Subject;
                    //string subjEName = Subj.GetSubjectEnglish(header.Subject);
                    string subjEName  = _SubjDomainEngNameMapping.GetSubjectEngName(header.Subject);
                    string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : "\n" + subjEName);

                    //把空白的領域當成「彈性課程」。
                    string domain      = gn;
                    string domainEName = _SubjDomainEngNameMapping.GetDomainEngName(domain);
                    domain += string.IsNullOrWhiteSpace(domainEName) ? "" : "\n" + domainEName;
                    datarow.Cells[0].Write(builder, domain);
                    datarow.Cells[1].Write(builder, subjString);
                }
            }
            #endregion

            #region 填資料
            //Row RatingRow = null;
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems))
                    {
                        continue;
                    }
                    if (!student.HeaderList.ContainsKey(sysems))
                    {
                        continue;
                    }

                    int           columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore   = student.SemestersScore[sysems];

                    decimal?score  = null;
                    decimal?weight = null;

                    if (header.IsDomain)
                    {
                        if (semsscore.Domain.Contains(header.Domain))
                        {
                            score  = semsscore.Domain[header.Domain].Value;
                            weight = semsscore.Domain[header.Domain].Weight;
                        }
                    }
                    else
                    {
                        if (semsscore.Subject.Contains(header.Subject))
                        {
                            score  = semsscore.Subject[header.Subject].Value;
                            weight = semsscore.Subject[header.Subject].Weight;
                        }
                    }

                    if (!score.HasValue)
                    {
                        continue;
                    }
                    if (!weight.HasValue)
                    {
                        weight = 0;
                    }

                    //if (PrintScore)
                    //    row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    //else
                    //    row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));

                    if (PrintScore)
                    {
                        if (Global.ShowCredit)
                        {
                            row.Cells[columnIndex * 2 + 2].Write(builder, score.Value + "");
                            row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + "");
                        }
                        else
                        {
                            row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                        }
                    }
                    else
                    {
                        if (Global.ShowCredit)
                        {
                            row.Cells[columnIndex * 2 + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                            row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + "");
                        }
                        else
                        {
                            row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                        }
                    }
                }
            }

            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                bool   hasGroup  = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                string groupName = Subj.GetDomainGroup(header.Domain);

                Row row = table.Rows[header.Index + DataRowOffset];

                if (previousCellDomain == row.Cells[0].ToTxt())
                {
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                }
                else
                {
                    row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;
                }

                if (header.IsDomain)
                {
                    if (!hasGroup)
                    {
                        row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                        row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                    }
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
예제 #8
0
        private void PrintSubjectOnly(DocumentBuilder builder, ReportStudent student, Row template, Table table)
        {
            #region 列印科目
            UniqueSet <RowHeader> RowIndexs = new UniqueSet <RowHeader>();

            #region 列印 RowHeader
            Dictionary <string, string> subjToDomain = new Dictionary <string, string>();
            foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
            {
                SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                if (!student.SemestersScore.Contains(sysems))
                {
                    continue;
                }

                SemesterScore semsscore = student.SemestersScore[sysems];

                foreach (string strSubject in semsscore.Subject)
                {
                    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                    if (!subjToDomain.ContainsKey(strSubject))
                    {
                        subjToDomain.Add(strSubject, subject.Domain);
                    }

                    RowHeader header = new RowHeader(subjToDomain[strSubject], strSubject);
                    header.IsDomain = false;

                    if (!RowIndexs.Contains(header))
                    {
                        RowIndexs.Add(header);
                    }
                }
            }

            List <RowHeader> sortedHeaders = RowIndexs.ToList();
            sortedHeaders.Sort(delegate(RowHeader x, RowHeader y)
            {
                Subj xx = new JHSchool.Evaluation.Subject(x.Subject, x.Domain);
                Subj yy = new JHSchool.Evaluation.Subject(y.Subject, y.Domain);

                return(xx.CompareTo(yy));
            });

            //產生 Row。
            List <RowHeader> indexHeaders = new List <RowHeader>();
            Row current  = template;
            int rowIndex = 0;
            foreach (RowHeader header in sortedHeaders)
            {
                RowHeader indexH = header;
                indexH.Index = rowIndex++;
                indexHeaders.Add(indexH);

                Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                string gn = "";
                //Additional Classes

                string subjCName = header.Subject;
                //string subjEName = Subj.GetSubjectEnglish(header.Subject);
                string subjEName = _SubjDomainEngNameMapping.GetSubjectEngName(header.Subject);

                string subjString = header.Subject + (string.IsNullOrEmpty(subjEName) ? "" : " " + subjEName);

                datarow.Cells[0].Write(builder, subjString);

                //if (IsFlexible(header.Domain))
                //{
                //    gn = "彈性課程\nAdditional Classes";
                //    //把空白的領域當成「彈性課程」。
                //    datarow.Cells[0].Write(builder, gn);
                //    datarow.Cells[1].Write(builder, subjString);
                //}
                //else
                //{
                //}
            }
            #endregion

            #region 填資料
            //填資料
            foreach (RowHeader header in indexHeaders)
            {
                SemesterDataCollection semesters = new SemesterDataCollection();
                Row row = table.Rows[header.Index + DataRowOffset];
                foreach (SemesterData semester in student.SHistory.GetGradeYearSemester())
                {
                    SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                    semesters.Add(sysems);

                    if (!student.SemestersScore.Contains(sysems))
                    {
                        continue;
                    }
                    if (!student.HeaderList.ContainsKey(sysems))
                    {
                        continue;
                    }

                    int           columnIndex = student.HeaderList[sysems];
                    SemesterScore semsscore   = student.SemestersScore[sysems];

                    decimal?score  = null;
                    decimal?weight = null;

                    //if (header.IsDomain)
                    //{
                    //    if (semsscore.Domain.Contains(header.Domain))
                    //    {
                    //        score = semsscore.Domain[header.Domain].Value;
                    //        weight = semsscore.Domain[header.Domain].Weight;
                    //    }
                    //}
                    //else
                    //{
                    if (semsscore.Subject.Contains(header.Subject))
                    {
                        score  = semsscore.Subject[header.Subject].Value;
                        weight = semsscore.Subject[header.Subject].Weight;
                    }
                    //}

                    if (!score.HasValue)
                    {
                        continue;
                    }
                    if (!weight.HasValue)
                    {
                        weight = 0;
                    }

                    //if (PrintScore)
                    //    row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                    //else
                    //    row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                    if (PrintScore)
                    {
                        if (Global.ShowCredit)
                        {
                            row.Cells[columnIndex * 2 + 2].Write(builder, score.Value + "");
                            row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + "");
                        }
                        else
                        {
                            row.Cells[columnIndex + 2].Write(builder, score.Value + "");
                        }
                    }
                    else
                    {
                        if (Global.ShowCredit)
                        {
                            row.Cells[columnIndex * 2 + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                            row.Cells[columnIndex * 2 + 3].Write(builder, weight.Value + "");
                        }
                        else
                        {
                            row.Cells[columnIndex + 2].Write(builder, Util.GetDegreeEnglish(score.Value));
                        }
                    }
                }
            }
            #endregion

            #region 合併相關欄位。
            string previousCellDomain = string.Empty;
            foreach (RowHeader header in indexHeaders)
            {
                Row row = table.Rows[header.Index + DataRowOffset];

                //if (IsFlexible(header.Domain))
                //{
                //    if (previousCellDomain == row.Cells[0].ToTxt())
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                //    else
                //        row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;
                //}
                //else
                {
                    row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                    row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                }

                previousCellDomain = row.Cells[0].ToTxt();
            }
            #endregion

            #endregion
        }
예제 #9
0
        //最好這程式有人能維護的了.......
        private void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
        {
            //不是 Fix 開頭的合併欄位不處理。
            if (!e.FieldName.ToUpper().StartsWith("Fix".ToUpper())) return;

            DocumentBuilder builder = new DocumentBuilder(e.Document);

            ReportStudent student = e.FieldValue as ReportStudent;

            //如果合併值不是 ReportStudent 就跳過...意思是有問題...。
            if (student == null) return;

            builder.MoveToField(e.Field, true);
            e.Field.Remove();

            if (e.FieldName == "Fix:年級學期")
            {
                #region 列印年級學期資訊(有點複雜)。
                SemesterDataCollection semesters = student.SHistory.GetGradeYearSemester().GetSemesters(PrintSetting.PrintSemesters);
                Row SemesterRow = builder.CurrentParagraph.ParentNode.ParentNode.NextSibling as Row; //下一個 Row。
                Paragraph originParagraph = builder.CurrentParagraph;

                int count = 0, offset = 1;

                foreach (SemesterData each in semesters)
                {
                    string currentGradeyear = Util.GetGradeyearString(each.GradeYear.ToString());

                    //如果沒有年級,就跳過。
                    if (string.IsNullOrEmpty(currentGradeyear)) continue;

                    builder.Write(currentGradeyear + "年級");
                    Paragraph nextPh = Util.NextCell(builder.CurrentParagraph);
                    if (nextPh == null) break; //沒有下一個 Cell ,就不印資料了。
                    builder.MoveTo(nextPh);

                    Paragraph resetParagraph = builder.CurrentParagraph;
                    SemesterRow.Cells[count + offset].Write(builder, GetSemesterString(each));

                    SemesterData semester = new SemesterData(0, each.SchoolYear, each.Semester);
                    if (!student.HeaderList.ContainsKey(semester))
                        student.HeaderList.AddRaw(each, count); //不要懷疑,這是對的。

                    builder.MoveTo(resetParagraph);
                    count++;
                }

                builder.MoveTo(originParagraph);
                (originParagraph.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                Paragraph nextParagrap = originParagraph;
                string previousGradeyear = GetText(originParagraph);
                while ((nextParagrap = Util.NextCell(nextParagrap)) != null)
                {
                    if (GetText(nextParagrap) == previousGradeyear && !string.IsNullOrEmpty(previousGradeyear))
                    {
                        (nextParagrap.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;
                        (nextParagrap.ParentNode as Cell).Paragraphs[0].Runs.Clear();
                    }
                    else
                        (nextParagrap.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;

                    previousGradeyear = GetText(nextParagrap);
                }
                #endregion
            }
            else if (e.FieldName == "Fix:科目資訊")
            {
                #region 列印科目資料(爆炸複雜)

                Row template = builder.CurrentParagraph.ParentNode.ParentNode as Row;
                Table table = template.ParentNode as Table;

                if (PrintSetting.ListMethod == ListMethod.DomainOnly)
                {
                    #region 列印領域
                    UniqueSet<RowHeader> RowIndexs = new UniqueSet<RowHeader>();
                    //Environment.OSVersion.Platform
                    #region 列印 RowHeader
                    foreach (SemesterData semester in student.SHistory.GetGradeYearSemester().GetSemesters(PrintSetting.PrintSemesters))
                    {
                        SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);

                        //如果不包含該學期成績資料,就跳過。
                        if (!student.SemestersScore.Contains(sysems)) continue;

                        SemesterScore semsscore = student.SemestersScore[sysems];

                        ////準備彈性課程的科目(要詳列出來)。
                        //foreach (string strSubject in semsscore.Subject)
                        //{
                        //    SemesterSubjectScore subject = semsscore.Subject[strSubject];

                        //    if (DetailDomain.Contains(subject.Domain))
                        //    {
                        //        RefineDomain(subject);

                        //        RowHeader header = new RowHeader(subject.Domain, strSubject);
                        //        header.IsDomain = false;

                        //        if (!RowIndexs.Contains(header))
                        //            RowIndexs.Add(header);
                        //    }
                        //}

                        //準備領域資料。
                        foreach (string strDomain in semsscore.Domain)
                        {
                            if (!Subj.Domains.Contains(strDomain)) continue;

                            SemesterDomainScore domain = semsscore.Domain[strDomain];

                            if (!DetailDomain.Contains(strDomain))
                            {
                                RowHeader header = new RowHeader(strDomain, string.Empty);
                                header.IsDomain = true;

                                if (!RowIndexs.Contains(header))
                                    RowIndexs.Add(header);
                            }
                        }
                    }

                    RowHeader lheader = new RowHeader(LearningDomainName, string.Empty);
                    RowHeader lheader1 = new RowHeader(LearningDomainNameSpcAdd, string.Empty);
                    RowHeader lheader2 = new RowHeader(LearningDomainNameP, string.Empty);
                    RowHeader lheader3 = new RowHeader(LearningDomainNameSpcAddP, string.Empty);
                    RowHeader lheader4 = new RowHeader(CalcMessage, string.Empty);

                    lheader.IsDomain = true;
                    lheader1.IsDomain = true;
                    lheader2.IsDomain = true;
                    lheader3.IsDomain = true;
                    lheader4.IsDomain = true;
                    RowIndexs.Add(lheader);
                    RowIndexs.Add(lheader1);
                    RowIndexs.Add(lheader2);
                    RowIndexs.Add(lheader3);
                    RowIndexs.Add(lheader4);

                    List<RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList());

                    //產生 Row。
                    List<RowHeader> indexHeaders = new List<RowHeader>();
                    Row current = template;
                    int rowIndex = 0;
                    foreach (RowHeader header in sortedHeaders)
                    {
                        RowHeader indexH = header;
                        indexH.Index = rowIndex++;
                        indexHeaders.Add(indexH);
                        bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                        string groupName = Subj.GetDomainGroup(header.Domain);

                        Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                        //if (header.Domain == LearningDomainName)
                        //{
                        //    string headerName = string.Empty;

                        //    if (PrintSetting.PrintRank)
                        //        headerName = "學期成績平均排名";

                        //    if (PrintSetting.PrintRankPercentage)
                        //        headerName = "學期成績平均百分比";

                        //    if (PrintSetting.PrintRank && PrintSetting.PrintRankPercentage)
                        //        headerName = "學期成績平均排名/百分比";

                        //    if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                        //    {
                        //        Row lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                        //        lrow.Cells[0].Write(builder, headerName);
                        //        rowIndex++;
                        //    }
                        //}

                        //if (header.Domain == LearningDomainNameSpcAdd)
                        //{
                        //    string headerName = string.Empty;

                        //    if (PrintSetting.PrintRank)
                        //        headerName = "特種身分加分後之學期成績平均排名";

                        //    if (PrintSetting.PrintRankPercentage)
                        //        headerName = "特種身分加分後之學期成績平均百分比";

                        //    if (PrintSetting.PrintRank && PrintSetting.PrintRankPercentage)
                        //        headerName = "特種身分加分後之學期成績平均排名/百分比";

                        //    if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                        //    {
                        //        Row lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                        //        lrow.Cells[0].Write(builder, headerName);
                        //        rowIndex++;
                        //    }
                        //}

                        if (header.IsDomain)
                        {
                            if (hasGroup)
                            {
                                datarow.Cells[0].Write(builder, groupName);
                                datarow.Cells[1].Write(builder, header.Domain);
                            }
                            else
                            {
                                datarow.Cells[0].Write(builder, header.Domain);
                            }
                        }
                        else
                        {
                            if (header.Domain == LearningDomainNameP)
                            {
                                string headerName = string.Empty;

                                if (PrintSetting.PrintRank)
                                    headerName = "學期成績平均排名";

                                if (PrintSetting.PrintRankPercentage)
                                    headerName = "學期成績平均百分比";

                                if (PrintSetting.PrintRank && PrintSetting.PrintRankPercentage)
                                    headerName = "學期成績平均排名/百分比";

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    Row lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                                    lrow.Cells[0].Write(builder, headerName);
                                    rowIndex++;
                                }
                            }

                            if (header.Domain == LearningDomainNameSpcAddP)
                            {
                                string headerName = string.Empty;

                                if (PrintSetting.PrintRank)
                                    headerName = "特種身分加分後之學期成績平均排名";

                                if (PrintSetting.PrintRankPercentage)
                                    headerName = "特種身分加分後之學期成績平均百分比";

                                if (PrintSetting.PrintRank && PrintSetting.PrintRankPercentage)
                                    headerName = "特種身分加分後之學期成績平均排名/百分比";

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    Row lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                                    lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                                    lrow.Cells[0].Write(builder, headerName);
                                    rowIndex++;
                                }
                            }

                            //把空白的領域當成「彈性課程」。
                            string domain = IsFlexible(header.Domain) ? "彈性課程" : header.Domain;

                            // 修改不需要彈性課程,標頭
                            datarow.Cells[0].Write(builder, "^^");
                            datarow.Cells[1].Write(builder, "^_^");
                        }
                    }
                    #endregion

                    #region 填資料
                    Row RatingRow = null;
                    // 用在加分後
                    Row RatingRowAdd = null;
                    // 是否已有年排名資料
                    List<DAL.UserDefData> uddList = new List<JointAdmissionModule.DAL.UserDefData>();
                    if (_StudRankData.ContainsKey(student.StudentID))
                        uddList = _StudRankData[student.StudentID];

                    foreach (RowHeader header in indexHeaders)
                    {
                        SemesterDataCollection semesters = new SemesterDataCollection();
                        Row row = table.Rows[header.Index + 3];
                        foreach (SemesterData semester in student.SHistory.GetGradeYearSemester().GetSemesters(PrintSetting.PrintSemesters))
                        {
                            SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                            semesters.Add(sysems);

                            if (!student.SemestersScore.Contains(sysems)) continue;
                            if (!student.HeaderList.ContainsKey(sysems)) continue;

                            int columnIndex = student.HeaderList[sysems];
                            SemesterScore semsscore = student.SemestersScore[sysems];

                            decimal? score = null;
                            decimal? weight = null;

                            if (header.IsDomain)
                            {
                                if (semsscore.Domain.Contains(header.Domain))
                                {
                                    score = semsscore.Domain[header.Domain].Value;
                                    weight = semsscore.Domain[header.Domain].Weight;
                                }
                            }
                            else
                            {
                                // 這段在顯示彈性課程成績,先註。
                                //if (semsscore.Subject.Contains(header.Subject))
                                //{
                                //    score = semsscore.Subject[header.Subject].Value;
                                //    weight = semsscore.Subject[header.Subject].Weight;
                                //}
                            }

                            if (header.Domain == LearningDomainName)
                            {
                                score = semsscore.LearnDomainScore;

                                row.Cells[columnIndex * 3 + 2].CellFormat.FitText = false;
                                row.Cells[columnIndex * 3 + 2].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[columnIndex * 3 + 3].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (!score.HasValue) continue;

                                row.Cells[columnIndex * 3 + 2].Write(builder, ((double)score) + "");
                                row.Cells[columnIndex * 3 + 4].Write(builder, (Util.GetDegree(score.Value)));

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    RatingRow = row.NextSibling as Row;
                                    RatingRow = RatingRow.NextSibling as Row;
                                }
                            }
                            else if (header.Domain == LearningDomainNameSpcAdd)
                            {
                                // 加分後填入值
                                score = semsscore.LearnDomainScore;

                                row.Cells[columnIndex * 3 + 2].CellFormat.FitText = false;
                                row.Cells[columnIndex * 3 + 2].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[columnIndex * 3 + 3].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (!score.HasValue) continue;
                                // 處理加分
                                decimal sc = score.Value;
                                if (student.AddWeight.HasValue)
                                    sc = Math.Round(sc * student.AddWeight.Value, 2,MidpointRounding.AwayFromZero); ;

                                // 一般生填空白
                                if (string.IsNullOrEmpty(student.SpcStudTypeName))
                                {
                                    row.Cells[columnIndex * 3 + 2].Write(builder, "");
                                    row.Cells[columnIndex * 3 + 4].Write(builder, "");
                                }
                                else
                                {
                                    // 特種身
                                    row.Cells[columnIndex * 3 + 2].Write(builder, sc + "");
                                    row.Cells[columnIndex * 3 + 4].Write(builder, (Util.GetDegree(sc)));
                                }

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    if (RatingRow != null)
                                    {
                                        RatingRowAdd = RatingRow.NextSibling as Row;

                                    }
                                }
                            }
                            else
                            {
                                if (!score.HasValue) continue;
                                if (!weight.HasValue) weight = 0;

                                row.Cells[columnIndex * 3 + 2].Write(builder, ((double)weight) + "");
                                row.Cells[columnIndex * 3 + 3].Write(builder, ((double)score) + "");
                                row.Cells[columnIndex * 3 + 4].Write(builder, (Util.GetDegree(score.Value)));
                            }
                        }

                        //算平均...
                        decimal? avgScore = null;
                        if (header.IsDomain)
                        {
                            if (header.Domain == LearningDomainName)
                            {
                                avgScore = student.SemestersScore.AvgLearningDomainScore(semesters);

                                if (!avgScore.HasValue) continue;

                                if (student.CalculationRule == null)
                                    avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                                else
                                    avgScore = student.CalculationRule.ParseLearnDomainScore(avgScore.Value);
                            }
                            else
                            {
                                avgScore = student.SemestersScore.AvgDomainScore(semesters, header.Domain);

                                if (!avgScore.HasValue) continue;

                                if (student.CalculationRule == null)
                                    avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                                else
                                    avgScore = student.CalculationRule.ParseDomainScore(avgScore.Value);
                            }
                        }
                        else
                        {
                            // 這段在處理彈性課程平均,先註。
                            //avgScore = student.SemestersScore.AvgSubjectScore(semesters, header.Subject);

                            //if (!avgScore.HasValue) continue;

                            //if (student.CalculationRule == null)
                            //    avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                            //else
                            //    avgScore = student.CalculationRule.ParseSubjectScore(avgScore.Value);
                        }

                        if (avgScore.HasValue)
                        {
                            row.Cells[20].Write(builder, (double)avgScore + "");
                            row.Cells[21].Write(builder, Util.GetDegree(avgScore.Value));
                            //decimal scAddScore = 0;
                            //// 特種身分
                            //if (student.AddWeight.HasValue)
                            //{
                            //    Row RowSp = row.NextSibling as Row;
                            //    scAddScore = student.AddWeight.Value * avgScore.Value;
                            //    RowSp.Cells[20].Write(builder, (double)scAddScore + "");
                            //    RowSp.Cells[21].Write(builder, Util.GetDegree(scAddScore));

                            //}
                        }
                    }

                    // 處理特種分身平均顯示
                    decimal scAddScore = 0;
                    // 特種身分
                    int rrIdx = 0;
                    foreach(RowHeader rh in indexHeaders)
                    {
                        if (rh.Domain == LearningDomainNameSpcAdd)
                        {
                            rrIdx = rh.Index + 3;
                            break;
                        }
                    }

                    if (student.AddWeight.HasValue && rrIdx >0)
                    {
                        // 顯示平均
                        if (student.Places.NS("年排名").Contains("學習領域"))
                        {
                            scAddScore = Math.Round(student.Places.NS("年排名")["學習領域"].Score * student.AddWeight.Value,2,MidpointRounding.AwayFromZero);
                            table.Rows[rrIdx].Cells[20].Write(builder, (double)scAddScore + "");
                            table.Rows[rrIdx].Cells[21].Write(builder, Util.GetDegree(scAddScore));
                        }

                    }

                    // 處理年排名與百分比
                    if (RatingRow != null)
                    {
                        PlaceCollection places = student.Places.NS("年排名");

                        foreach (SemesterData semsIndex in student.HeaderList.Keys)
                        {
                            SemesterData raw = student.HeaderList.GetSRaw(semsIndex);

                            if (raw == SemesterData.Empty) continue;

                            string placeKey = SLearningDomainParser.GetSemesterString(raw);

                            Cell datacell = RatingRow.Cells[student.HeaderList[semsIndex] * 3 + 2];

                            bool UseRatingRank = true;
                            // 處理已有年排名(在UDT有存資料)
                            if (uddList.Count > 0 && student.LastEnterSemester.HasValue)
                            {
                                foreach (DAL.UserDefData udd in uddList)
                                {
                                    if (udd.SchoolYear == semsIndex.SchoolYear && udd.Semester == semsIndex.Semester)
                                    {
                                        datacell.Write(builder, GetPlaceString2(udd.GradeRank, udd.GradeRankPercent));
                                        UseRatingRank = false;
                                    }
                                }
                            }

                            // 判斷轉入生
                            if (student.LastEnterGradeYear.HasValue && student.LastEnterSchoolyear.HasValue)
                            {
                                if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                {

                                        bool clear = true;

                                        // 當有資料
                                        foreach (DAL.UserDefData udd in (from data in uddList where data.SchoolYear== semsIndex.SchoolYear && data.Semester== semsIndex.Semester select data))
                                                clear = false;

                                        if (clear)
                                        {
                                            // 和異動同年同學期不動
                                            if (semsIndex.SchoolYear == student.LastEnterSchoolyear && semsIndex.Semester == student.LastEnterSemester)
                                                clear = false;
                                        }

                                        if (clear)
                                        {
                                            // 當同一學年第2學期,如果維持不清空
                                            if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester == 2)
                                                clear = false;
                                        }

                                        if (clear)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }

                                }

                                if (uddList.Count == 0)
                                {
                                    if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                    {
                                        if (semsIndex.SchoolYear < student.LastEnterSchoolyear.Value)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                        else if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester < student.LastEnterSemester)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                    }
                                }
                            }

                            // 使用即時運算排名與百分比
                            if(UseRatingRank)
                                if (places.Contains(placeKey))
                                    datacell.Write(builder, GetPlaceString(places, placeKey));
                        }

                        // 顯示平均
                        if (places.Contains("學習領域"))
                            RatingRow.Cells[20].Write(builder, GetPlaceString(places, "學習領域"));
                    }

                    int? LevelAdd=null,PercentageAdd=null;
                    // 處理年排名與百分比(加分後)
                    if (RatingRowAdd != null)
                    {
                        PlaceCollection places = student.Places.NS("年排名");

                        foreach (SemesterData semsIndex in student.HeaderList.Keys)
                        {
                            SemesterData raw = student.HeaderList.GetSRaw(semsIndex);

                            if (raw == SemesterData.Empty) continue;

                            string placeKey = SLearningDomainParser.GetSemesterString(raw);

                            //if (!places.Contains(placeKey))
                            //    continue;

                            Cell datacell = RatingRowAdd.Cells[student.HeaderList[semsIndex] * 3 + 2];

                            // 如果是一般生直接填空白
                            if (string.IsNullOrEmpty(student.SpcStudTypeName))
                            {
                                datacell.Write(builder, "");
                                continue;
                            }
                            int Level=1,Percentage=1;

                            // 處理加分後
                            if (places.Contains(placeKey))
                            {
                                if (student.AddWeight.HasValue)
                                {
                                    List<Place> PList = new List<Place>();
                                    decimal sc = places[placeKey].Score * student.AddWeight.Value;
                                    if (DAL.DALTransfer.StudRankScoreDict.ContainsKey(student.GradeYear))
                                    {
                                        if (DAL.DALTransfer.StudRankScoreDict[student.GradeYear].ContainsKey(placeKey))
                                        {
                                            PList = (from data in DAL.DALTransfer.StudRankScoreDict[student.GradeYear][placeKey] where data.Place.Score >= sc orderby data.Place.Score ascending select data.Place).ToList();
                                            if (PList.Count > 0)
                                            {
                                                PList.OrderBy(x => x.Score);
                                                Level = PList[0].Level;
                                                Percentage = PList[0].Percentage;
                                            }
                                            else
                                            {
                                                Level = 1;
                                                Percentage = 1;
                                            }
                                        }
                                    }
                                }
                            }

                            bool UseRatingRank = true;
                            // 處理已有年排名(UDT)
                            if (uddList.Count > 0 && student.LastEnterSemester.HasValue)
                            {
                                foreach (DAL.UserDefData udd in uddList)
                                {
                                    if (udd.SchoolYear == semsIndex.SchoolYear && udd.Semester == semsIndex.Semester)
                                    {
                                        datacell.Write(builder, GetPlaceString2(udd.GradeRankAdd, udd.GradeRankPercentAdd));
                                        UseRatingRank = false;
                                    }
                                }
                            }

                            // 判斷轉入生
                            if (student.LastEnterGradeYear.HasValue && student.LastEnterSchoolyear.HasValue)
                            {
                                if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                {

                                    bool clear = true;

                                    // 當有資料
                                    foreach (DAL.UserDefData udd in (from data in uddList where data.SchoolYear == semsIndex.SchoolYear && data.Semester == semsIndex.Semester select data))
                                        clear = false;

                                    if (clear)
                                    {
                                        // 和異動同年同學期不動
                                        if (semsIndex.SchoolYear == student.LastEnterSchoolyear && semsIndex.Semester == student.LastEnterSemester)
                                            clear = false;
                                    }

                                    if (clear)
                                    {
                                        // 當同一學年第2學期,如果維持不清空
                                        if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester == 2)
                                            clear = false;
                                    }

                                    if (clear)
                                    {
                                        datacell.Write(builder, "");
                                        UseRatingRank = false;
                                    }

                                }

                                if (uddList.Count == 0)
                                {
                                    if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                    {
                                        if (semsIndex.SchoolYear < student.LastEnterSchoolyear.Value)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                        else if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester < student.LastEnterSemester)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                    }
                                }
                            }

                            //// 使用即時運算排名與百分比
                            if (UseRatingRank)
                            {
                                if (places.Contains(placeKey))
                                {
                                    if (student.AddWeight.HasValue)
                                        datacell.Write(builder, GetPlaceString2(Level, Percentage));
                                    else
                                        datacell.Write(builder, GetPlaceString(places, placeKey));

                                }
                            }

                            //// 每學期加分後
                            //if (places.Contains(placeKey))
                            //    datacell.Write(builder, "^_^");

                        }

                        //這是加分後平均
                        //if (places.Contains(LearningDomainNameSpcAddP))
                        //    RatingRowAdd.Cells[20].Write(builder, GetPlaceString(places, LearningDomainNameSpcAddP));

                        // 加分後
                        if (student.AddWeight.HasValue)
                        {
                            decimal sc1=0;
                            PercentageAdd = null; LevelAdd = null;
                            List<Place> PList = new List<Place>();
                            if(places.Contains("學習領域"))
                                sc1 = places["學習領域"].Score * student.AddWeight.Value;
                            if (DAL.DALTransfer.StudRankScoreDict.ContainsKey(student.GradeYear))
                            {
                                if (DAL.DALTransfer.StudRankScoreDict[student.GradeYear].ContainsKey("學期總平均"))
                                {
                                    PList = (from data in DAL.DALTransfer.StudRankScoreDict[student.GradeYear]["學期總平均"] where data.Place.Score >= sc1 orderby data.Place.Score ascending select data.Place).ToList();
                                    if (PList.Count > 0)
                                    {
                                        PList.OrderBy(x => x.Score);
                                        LevelAdd = PList[0].Level;
                                        PercentageAdd = PList[0].Percentage;
                                    }
                                    else
                                    {
                                        LevelAdd = 1;
                                        PercentageAdd = 1;
                                    }
                                }
                                if(LevelAdd.HasValue && PercentageAdd.HasValue )
                                    RatingRowAdd.Cells[20].Write(builder, GetPlaceString2(LevelAdd.Value, PercentageAdd.Value));
                            }
                        }

                    }

                    // 樂學計分方式
                    if(RatingRowAdd !=null )
                    {
                        //string str = "單一學期學習領域成績計分=100-(名次百分比)×100+1";
                        Row RowStr = RatingRowAdd.NextSibling as Row;
                        //RowStr.Cells[2].Write(builder, str);

                        PlaceCollection places = student.Places.NS("年排名");
                        foreach (SemesterData semsIndex in student.HeaderList.Keys)
                        {
                            SemesterData raw = student.HeaderList.GetSRaw(semsIndex);

                            if (raw == SemesterData.Empty) continue;

                            string placeKey = SLearningDomainParser.GetSemesterString(raw);

                            Cell datacell = RowStr.Cells[student.HeaderList[semsIndex] * 3 + 2];

                            bool UseRatingRank = true;

                            // 處理已有年排名(在UDT有存資料)
                            if (uddList.Count > 0 && student.LastEnterSemester.HasValue)
                            {
                                foreach (DAL.UserDefData udd in uddList)
                                {
                                    if (udd.SchoolYear == semsIndex.SchoolYear && udd.Semester == semsIndex.Semester)
                                    {
                                        if(student.AddWeight.HasValue )
                                            datacell.Write(builder, GetPlaceString3(udd.GradeRankPercentAdd));
                                        else
                                            datacell.Write(builder, GetPlaceString3(udd.GradeRankPercent));
                                        UseRatingRank = false;
                                    }
                                }
                            }

                            // 判斷轉入生
                            if (student.LastEnterGradeYear.HasValue && student.LastEnterSchoolyear.HasValue )
                            {
                                if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                {

                                    bool clear = true;

                                    // 當有資料
                                    foreach (DAL.UserDefData udd in (from data in uddList where data.SchoolYear == semsIndex.SchoolYear && data.Semester == semsIndex.Semester select data))
                                        clear = false;

                                    if (clear)
                                    {
                                        // 和異動同年同學期不動
                                        if (semsIndex.SchoolYear == student.LastEnterSchoolyear && semsIndex.Semester == student.LastEnterSemester)
                                            clear = false;
                                    }

                                    if (clear)
                                    {
                                        // 當同一學年第2學期,如果維持不清空
                                        if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester == 2)
                                            clear = false;
                                    }

                                    if (clear)
                                    {
                                        datacell.Write(builder, "");
                                        UseRatingRank = false;
                                    }

                                }

                                if (uddList.Count == 0)
                                {
                                    if (semsIndex.SchoolYear <= student.LastEnterSchoolyear.Value)
                                    {
                                        if (semsIndex.SchoolYear < student.LastEnterSchoolyear.Value)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                        else if (semsIndex.SchoolYear == student.LastEnterSchoolyear.Value && semsIndex.Semester < student.LastEnterSemester)
                                        {
                                            datacell.Write(builder, "");
                                            UseRatingRank = false;
                                        }
                                    }
                                }
                            }

                            if (UseRatingRank)
                            {

                                // 處理樂學計算
                                if (student.AddWeight.HasValue == false)
                                    if (places.Contains(placeKey))
                                        datacell.Write(builder, GetPlaceString3(places[placeKey].Percentage));

                                int Level = 1, Percentage = 1;

                                // 處理加分後
                                if (places.Contains(placeKey))
                                {
                                    if (student.AddWeight.HasValue)
                                    {
                                        List<Place> PList = new List<Place>();
                                        decimal sc = places[placeKey].Score * student.AddWeight.Value;
                                        if (DAL.DALTransfer.StudRankScoreDict.ContainsKey(student.GradeYear))
                                        {
                                            if (DAL.DALTransfer.StudRankScoreDict[student.GradeYear].ContainsKey(placeKey))
                                            {
                                                PList = (from data in DAL.DALTransfer.StudRankScoreDict[student.GradeYear][placeKey] where data.Place.Score >= sc orderby data.Place.Score ascending select data.Place).ToList();
                                                if (PList.Count > 0)
                                                {
                                                    PList.OrderBy(x => x.Score);
                                                    Level = PList[0].Level;
                                                    Percentage = PList[0].Percentage;
                                                }
                                                else
                                                {
                                                    Level = 1;
                                                    Percentage = 1;
                                                }
                                            }
                                        }
                                        datacell.Write(builder, GetPlaceString3(Percentage));
                                    }
                                }
                            }

                        }

                        //// 顯示平均
                        //Place p;
                        //if (places.Contains("學習領域"))
                        //{
                            //if (student.AddWeight.HasValue)
                            //{
                            //    if(PercentageAdd.HasValue )
                            //        RowStr.Cells[20].Write(builder, GetPlaceString3(PercentageAdd.Value));
                            //}
                            //else
                            //{
                        //        p = places["學習領域"];
                        //        RowStr.Cells[20].Write(builder, GetPlaceString3(p.Percentage));
                        //    //}
                        //}
                    }
                    #endregion

                    #region 合併相關欄位。
                    string previousCellDomain = string.Empty;
                    foreach (RowHeader header in indexHeaders)
                    {
                        bool hasGroup = !string.IsNullOrEmpty(Subj.GetDomainGroup(header.Domain));
                        string groupName = Subj.GetDomainGroup(header.Domain);

                        Row row = table.Rows[header.Index + 3];

                        if (previousCellDomain == row.Cells[0].ToTxt())
                            row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                        else
                            row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;

                        if (header.IsDomain)
                        {
                            if (header.Domain == LearningDomainName)
                            {
                                #region 學習領域
                                // 這段在處理 header
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

                                #endregion
                            }
                            else if (header.Domain == LearningDomainNameSpcAdd)
                            {
                                #region 學習領域(加分後)
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

                                #endregion
                            }
                            else if (header.Domain == LearningDomainNameP)
                            {
                                // 學成成績排名與百分比
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {

                                    //Row lrow = row.NextSibling as Row;
                                    Row lrow = row;
                                    lrow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                    lrow.Cells[0].CellFormat.FitText = false;
                                    lrow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                    Paragraph mp = lrow.Cells[2].Paragraphs[0];
                                    for (int i = 0; i < (3 * 6); i++)
                                    {
                                        if (i % 3 == 0)
                                        {
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                            (mp.ParentNode as Cell).CellFormat.FitText = false;
                                        }
                                        else
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                                        mp = Util.NextCell(mp as Paragraph);
                                    }
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                    mp = Util.NextCell(mp as Paragraph);
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;
                                }

                            }
                            else if (header.Domain == LearningDomainNameSpcAddP)
                            {
                                // 學習成績排名與百分比(加分後)
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    //Row lrow = row.NextSibling as Row;

                                    Row lrow = row;
                                    lrow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                    lrow.Cells[0].CellFormat.FitText = false;
                                    lrow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                    Paragraph mp = lrow.Cells[2].Paragraphs[0];
                                    for (int i = 0; i < (3 * 6); i++)
                                    {
                                        if (i % 3 == 0)
                                        {
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                            (mp.ParentNode as Cell).CellFormat.FitText = false;
                                        }
                                        else
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                                        mp = Util.NextCell(mp as Paragraph);
                                    }
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                    mp = Util.NextCell(mp as Paragraph);
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;
                                }

                            }
                            else if (header.Domain==CalcMessage)
                            {
                                // 文字字串
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                Row lrow = row;
                                lrow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                lrow.Cells[0].CellFormat.FitText = false;
                                lrow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                Paragraph mp = lrow.Cells[2].Paragraphs[0];
                                for (int i = 0; i < (3 * 6); i++)
                                {
                                   // if (i % 18 == 0)
                                        if (i % 3 == 0)
                                        {
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                            (mp.ParentNode as Cell).CellFormat.FitText = false;
                                        }
                                        else
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                                    mp = Util.NextCell(mp as Paragraph);
                                }
                                (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                mp = Util.NextCell(mp as Paragraph);
                                (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                            }
                            else
                            {
                                if (!hasGroup)
                                {
                                    row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                    row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                }
                            }
                        }

                        previousCellDomain = row.Cells[0].ToTxt();
                    }
                    #endregion

                    #endregion
                }
                else if (PrintSetting.ListMethod == ListMethod.SubjectOnly)
                {
                    #region 列印科目
                    UniqueSet<RowHeader> RowIndexs = new UniqueSet<RowHeader>();

                    foreach (SemesterData semester in student.SHistory.GetGradeYearSemester().GetSemesters(PrintSetting.PrintSemesters))
                    {
                        SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                        if (!student.SemestersScore.Contains(sysems)) continue;

                        SemesterScore semsscore = student.SemestersScore[sysems];

                        foreach (string strSubject in semsscore.Subject)
                        {
                            SemesterSubjectScore subject = semsscore.Subject[strSubject];

                            RowHeader header;
                            if (IsFlexible(subject.Domain))
                                header = new RowHeader("彈性課程", strSubject);
                            else
                                header = new RowHeader(subject.Domain, strSubject);

                            header.IsDomain = false;

                            if (!RowIndexs.Contains(header))
                                RowIndexs.Add(header);
                        }
                    }

                    RowHeader lheader = new RowHeader(LearningDomainName, string.Empty);
                    lheader.IsDomain = true;
                    //RowIndexs.Add(lheader);

                    //List<RowHeader> sortedHeaders = SortHeader(RowIndexs.ToList());
                    List<RowHeader> sortedHeaders = RowIndexs.ToList();

                    sortedHeaders.Sort(delegate(RowHeader x, RowHeader y)
                    {
                        Subj xx = new JHSchool.Evaluation.Subject(x.Subject, x.Domain);
                        Subj yy = new JHSchool.Evaluation.Subject(y.Subject, y.Domain);

                        return xx.CompareTo(yy);
                    });
                    //sortedHeaders.Sort(Util.SortSubject);
                    //sortedHeaders.Sort(Util.SortDomain);

                    //把學習領域放在正確的地方。
                    foreach (RowHeader eachHeader in sortedHeaders.ToArray())
                    {
                        if (IsFlexible(eachHeader.Domain))
                        {
                            int index = sortedHeaders.IndexOf(eachHeader);
                            sortedHeaders.Insert(index, lheader);
                            break;
                        }
                    }
                    if (sortedHeaders.IndexOf(lheader) < 0)
                        sortedHeaders.Add(lheader);

                    //產生 Row。
                    List<RowHeader> indexHeaders = new List<RowHeader>();
                    Row current = template;
                    int rowIndex = 0;
                    foreach (RowHeader header in sortedHeaders)
                    {
                        RowHeader indexH = header;
                        indexH.Index = rowIndex++;
                        indexHeaders.Add(indexH);

                        Row datarow = table.InsertBefore(template.Clone(true), current) as Row;

                        if (header.Domain == LearningDomainName)
                        {
                            string headerName = string.Empty;

                            if (PrintSetting.PrintRank)
                                headerName = "學習領域排名";

                            if (PrintSetting.PrintRankPercentage)
                                headerName = "學習領域百分比";

                            if (PrintSetting.PrintRank && PrintSetting.PrintRankPercentage)
                                headerName = "學習領域排名/百分比";

                            if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                            {
                                Row lrow = table.InsertAfter(template.Clone(true), datarow) as Row;
                                lrow.Cells[0].Write(builder, headerName);
                                rowIndex++;
                            }
                        }

                        if (IsFlexible(header.Domain))
                        {
                            datarow.Cells[0].Write(builder, header.Domain);
                            datarow.Cells[1].Write(builder, header.Subject);
                        }
                        else if (header.Domain == LearningDomainName)
                            datarow.Cells[0].Write(builder, header.Domain);
                        else
                            datarow.Cells[0].Write(builder, header.Subject);
                    }

                    //填資料
                    Row RatingRow = null;
                    foreach (RowHeader header in indexHeaders)
                    {
                        SemesterDataCollection semesters = new SemesterDataCollection();
                        Row row = table.Rows[header.Index + 3];
                        foreach (SemesterData semester in student.SHistory.GetGradeYearSemester().GetSemesters(PrintSetting.PrintSemesters))
                        {
                            SemesterData sysems = new SemesterData(0, semester.SchoolYear, semester.Semester);
                            semesters.Add(sysems);

                            if (!student.SemestersScore.Contains(sysems)) continue;
                            if (!student.HeaderList.ContainsKey(sysems)) continue;

                            int columnIndex = student.HeaderList[sysems];
                            SemesterScore semsscore = student.SemestersScore[sysems];

                            decimal? score = null;
                            decimal? weight = null;

                            if (header.IsDomain)
                            {
                                if (semsscore.Domain.Contains(header.Domain))
                                {
                                    score = semsscore.Domain[header.Domain].Value;
                                    weight = semsscore.Domain[header.Domain].Weight;
                                }
                            }
                            else
                            {
                                if (semsscore.Subject.Contains(header.Subject))
                                {
                                    score = semsscore.Subject[header.Subject].Value;
                                    weight = semsscore.Subject[header.Subject].Weight;
                                }
                            }

                            if (header.Domain == LearningDomainName)
                            {
                                score = semsscore.LearnDomainScore;

                                row.Cells[columnIndex * 3 + 2].CellFormat.FitText = false;
                                row.Cells[columnIndex * 3 + 2].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[columnIndex * 3 + 3].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (!score.HasValue) continue;

                                row.Cells[columnIndex * 3 + 2].Write(builder, ((double)score) + "");
                                row.Cells[columnIndex * 3 + 4].Write(builder, (Util.GetDegree(score.Value)));

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                    RatingRow = row.NextSibling as Row;
                            }
                            else
                            {
                                if (!score.HasValue) continue;
                                if (!weight.HasValue) weight = 0;

                                row.Cells[columnIndex * 3 + 2].Write(builder, ((double)weight) + "");
                                row.Cells[columnIndex * 3 + 3].Write(builder, ((double)score) + "");
                                row.Cells[columnIndex * 3 + 4].Write(builder, (Util.GetDegree(score.Value)));
                            }
                        }

                        //算平均...
                        decimal? avgScore = null;
                        if (header.IsDomain)
                        {
                            if (header.Domain == LearningDomainName)
                            {
                                avgScore = student.SemestersScore.AvgLearningDomainScore(semesters);

                                if (!avgScore.HasValue) continue;

                                if (student.CalculationRule == null)
                                    avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                                else
                                    avgScore = student.CalculationRule.ParseLearnDomainScore(avgScore.Value);
                            }
                            else
                            {
                                avgScore = student.SemestersScore.AvgDomainScore(semesters, header.Domain);

                                if (!avgScore.HasValue) continue;

                                if (student.CalculationRule == null)
                                    avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                                else
                                    avgScore = student.CalculationRule.ParseDomainScore(avgScore.Value);
                            }
                        }
                        else
                        {
                            avgScore = student.SemestersScore.AvgSubjectScore(semesters, header.Subject);

                            if (!avgScore.HasValue) continue;

                            if (student.CalculationRule == null)
                                avgScore = Math.Round(avgScore.Value, 2, MidpointRounding.AwayFromZero);
                            else
                                avgScore = student.CalculationRule.ParseSubjectScore(avgScore.Value);
                        }

                        row.Cells[20].Write(builder, (double)avgScore + "");
                        row.Cells[21].Write(builder, Util.GetDegree(avgScore.Value));
                    }
                    if (RatingRow != null)
                    {
                        PlaceCollection places = student.Places.NS("年排名");

                        foreach (SemesterData semsIndex in student.HeaderList.Keys)
                        {
                            SemesterData raw = student.HeaderList.GetSRaw(semsIndex);

                            if (raw == SemesterData.Empty) continue;

                            string placeKey = SLearningDomainParser.GetSemesterString(raw);

                            Cell datacell = RatingRow.Cells[student.HeaderList[semsIndex] * 3 + 2];

                            if (places.Contains(placeKey))
                                datacell.Write(builder, GetPlaceString(places, placeKey));
                        }

                        if (places.Contains(LearningDomainName))
                            RatingRow.Cells[20].Write(builder, GetPlaceString(places, LearningDomainName));
                    }

                    //合併相關欄位。
                    string previousCellDomain = string.Empty;
                    foreach (RowHeader header in indexHeaders)
                    {
                        Row row = table.Rows[header.Index + 3];

                        if (header.IsDomain)
                        {
                            if (header.Domain == LearningDomainName)
                            {
                                row.Cells[0].CellFormat.FitText = false;
                                row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;

                                if (PrintSetting.PrintRank || PrintSetting.PrintRankPercentage)
                                {
                                    Row lrow = row.NextSibling as Row;
                                    lrow.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                                    lrow.Cells[0].CellFormat.FitText = false;
                                    lrow.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                                    Paragraph mp = lrow.Cells[2].Paragraphs[0];
                                    for (int i = 0; i < (3 * 6); i++)
                                    {
                                        if (i % 3 == 0)
                                        {
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                            (mp.ParentNode as Cell).CellFormat.FitText = false;
                                        }
                                        else
                                            (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;

                                        mp = Util.NextCell(mp as Paragraph);
                                    }
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.First;
                                    mp = Util.NextCell(mp as Paragraph);
                                    (mp.ParentNode as Cell).CellFormat.HorizontalMerge = CellMerge.Previous;
                                }
                            }
                        }
                        else if (IsFlexible(header.Domain))
                        {
                            if (previousCellDomain == header.Domain)
                                row.Cells[0].CellFormat.VerticalMerge = CellMerge.Previous;
                            else
                                row.Cells[0].CellFormat.VerticalMerge = CellMerge.First;

                            previousCellDomain = header.Domain;
                        }
                        else
                        {
                            //row.Cells[0].CellFormat.FitText = true;
                            row.Cells[0].CellFormat.HorizontalMerge = CellMerge.First;
                            row.Cells[1].CellFormat.HorizontalMerge = CellMerge.Previous;
                        }
                    }
                    #endregion
                }

                template.NextSibling.Remove();
                template.Remove();
                #endregion
            }
            else if (e.FieldName == "Fix:缺曠獎懲")
            {
                #region 列印獎懲資料
                int Offset = 2;
                Row MeritA = builder.CurrentParagraph.ParentNode.ParentNode as Row;
                Row MeritB = MeritA.NextSibling as Row;
                Row MeritC = MeritB.NextSibling as Row;
                Row DemeritA = MeritC.NextSibling as Row;
                Row DemeritB = DemeritA.NextSibling as Row;
                Row DemeritC = DemeritB.NextSibling as Row;
                Row DisciplineSet = DemeritC.NextSibling as Row;
                Row DisciplineNormal = DisciplineSet.NextSibling as Row;

                foreach (SemesterData each in student.Summaries.Keys)
                {
                    XmlElement summary = student.Summaries[each];

                    if (!student.HeaderList.ContainsKey(each)) continue;

                    int ColumnIndex = student.HeaderList[each];

                    XmlElement xmlmerit = summary.SelectSingleNode("DisciplineStatistics/Merit") as XmlElement;
                    XmlElement xmldemerit = summary.SelectSingleNode("DisciplineStatistics/Demerit") as XmlElement;

                    if (xmlmerit != null)
                    {
                        if (!string.IsNullOrEmpty(GetString(xmlmerit.GetAttribute("A"))))
                            MeritA.Cells[Offset + ColumnIndex].Write(builder, GetString(xmlmerit.GetAttribute("A")));
                        if (!string.IsNullOrEmpty(GetString(xmlmerit.GetAttribute("B"))))
                            MeritB.Cells[Offset + ColumnIndex].Write(builder, GetString(xmlmerit.GetAttribute("B")));
                        if (!string.IsNullOrEmpty(GetString(xmlmerit.GetAttribute("C"))))
                            MeritC.Cells[Offset + ColumnIndex].Write(builder, GetString(xmlmerit.GetAttribute("C")));
                    }

                    if (xmldemerit != null)
                    {
                        if (!string.IsNullOrEmpty(GetString(xmldemerit.GetAttribute("A"))))
                            DemeritA.Cells[Offset + ColumnIndex].Write(builder, GetString(xmldemerit.GetAttribute("A")));
                        if (!string.IsNullOrEmpty(GetString(xmldemerit.GetAttribute("B"))))
                            DemeritB.Cells[Offset + ColumnIndex].Write(builder, GetString(xmldemerit.GetAttribute("B")));
                        if (!string.IsNullOrEmpty(GetString(xmldemerit.GetAttribute("C"))))
                            DemeritC.Cells[Offset + ColumnIndex].Write(builder, GetString(xmldemerit.GetAttribute("C")));
                    }

                    StringBuilder normalString = new StringBuilder();
                    StringBuilder setString = new StringBuilder();

                    foreach (XmlElement absence in summary.SelectNodes("AttendanceStatistics/Absence"))
                    {
                        string count = absence.GetAttribute("Count");
                        string periodType = absence.GetAttribute("PeriodType");
                        string periodName = absence.GetAttribute("Name");

                        if (string.IsNullOrEmpty(count)) continue;
                        if (!PrintAbsences.ContainsKey(periodType)) continue;
                        if (!PrintAbsences[periodType].Contains(periodName)) continue;

                        if (periodType == "一般")
                        {
                            if (normalString.Length > 0) normalString.AppendLine();
                            normalString.Append(periodName + ":" + count);
                        }
                        else if (periodType == "集會")
                        {
                            if (setString.Length > 0) setString.AppendLine();
                            setString.Append(periodName + ":" + count);
                        }
                    }

                    DisciplineNormal.Cells[Offset + ColumnIndex].Write(builder, normalString.ToString());
                    DisciplineSet.Cells[Offset + ColumnIndex].Write(builder, setString.ToString());
                }
                #endregion
            }
        }