コード例 #1
0
        private void WriteMoralItemRow(Cell cell, MoralItemRow itemRow)
        {
            WriteLines(cell, itemRow.Lines, _builder);
            Row row   = cell.ParentRow;
            int shift = row.IndexOf(cell) + 1;

            foreach (SemesterData sems in itemRow.Items.Keys)
            {
                string text  = itemRow.Items[sems];
                int    index = -1;
                if (_map.SemesterMapping.ContainsKey(sems))
                {
                    index = _map.SemesterMapping[sems];
                }

                if (index < 0)
                {
                    continue;
                }

                index = index + shift;
                WordHelper.Write(row.Cells[index], text, _builder);
            }
        }
        private void WriteMoralItemRow(Cell cell, MoralItemRow itemRow)
        {
            WriteLines(cell, itemRow.Lines, _builder);
            Row row = cell.ParentRow;
            int shift = row.IndexOf(cell) + 1;

            foreach (SemesterData sems in itemRow.Items.Keys)
            {
                string text = itemRow.Items[sems];
                int index = -1;
                if (_map.SemesterMapping.ContainsKey(sems))
                    index = _map.SemesterMapping[sems];

                if (index < 0) continue;

                index = index + shift;
                WordHelper.Write(row.Cells[index], text, _builder);
            }
        }
コード例 #3
0
        private void ProcessMoralScore(List <AutoSummaryRecord> autoSummaryList)
        {
            Dictionary <string, MoralItemRow> items = new Dictionary <string, MoralItemRow>();

            //團體活動
            MoralItemRow groupActivityRow = null;

            //公共服務
            MoralItemRow publicServiceRow = null;

            //校內外特殊表現
            MoralItemRow schoolSpecialRow = null;
            //具體建議
            MoralItemRow recommendRow = null;

            #region 建立適合列印的資料結構
            foreach (AutoSummaryRecord asRecord in autoSummaryList)
            {
                if (asRecord.MoralScore == null)
                {
                    continue;
                }
                JHMoralScoreRecord record   = asRecord.MoralScore;
                SemesterData       semester = new SemesterData("" + record.SchoolYear, "" + record.Semester);

                XmlElement dailyBehavior = (XmlElement)record.TextScore.SelectSingleNode("DailyBehavior");
                if (dailyBehavior != null)
                {
                    foreach (XmlElement item in dailyBehavior.SelectNodes("Item"))
                    {
                        string name   = item.GetAttribute("Name");
                        string index  = item.GetAttribute("Index");
                        string degree = item.GetAttribute("Degree");

                        string[] lines = index.Split(new string[] { ";", ";" }, StringSplitOptions.RemoveEmptyEntries);

                        if (!items.ContainsKey(name))
                        {
                            items.Add(name, new MoralItemRow(lines));
                        }

                        items[name].Add(semester, degree);
                    }
                }

                XmlElement dailyLifeRecommend = (XmlElement)record.TextScore.SelectSingleNode("DailyLifeRecommend");
                if (dailyLifeRecommend != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("DailyLifeRecommend"))
                    {
                        GroupName = Utility.MorItemDict["DailyLifeRecommend"];
                    }

                    if (recommendRow == null)
                    {
                        recommendRow = new MoralItemRow(new string[] { GroupName });
                    }
                    recommendRow.Add(semester, dailyLifeRecommend.GetAttribute("Description"));
                }

                // 團體活動
                XmlElement groupActivity = (XmlElement)record.TextScore.SelectSingleNode("GroupActivity");
                if (groupActivity != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("GroupActivity"))
                    {
                        GroupName = Utility.MorItemDict["GroupActivity"];
                    }

                    if (groupActivityRow == null)
                    {
                        groupActivityRow = new MoralItemRow(new string[] { GroupName });
                    }

                    string text = string.Empty;

                    foreach (XmlElement item in groupActivity.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc   = item.GetAttribute("Description");
                        string name   = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc))
                        {
                            continue;
                        }

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/"))
                        {
                            line = line.Substring(0, line.Length - 1);
                        }
                        text += line;
                    }

                    // 加入社團
                    if (_assnScoreCache.ContainsKey(record.RefStudentID))
                    {
                        string sc = record.SchoolYear.ToString();
                        string ss = record.Semester.ToString();
                        foreach (AssnScore asc in _assnScoreCache[record.RefStudentID])
                        {
                            if (asc.SchoolYear == sc && asc.Semester == ss)
                            {
                                text += "社團活動:" + asc.Score + "," + asc.Effort + "/" + asc.Text;
                            }
                        }
                    }
                    groupActivityRow.Add(semester, text);
                }



                XmlElement publicService = (XmlElement)record.TextScore.SelectSingleNode("PublicService");
                if (publicService != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("PublicService"))
                    {
                        GroupName = Utility.MorItemDict["PublicService"];
                    }

                    if (publicServiceRow == null)
                    {
                        publicServiceRow = new MoralItemRow(new string[] { GroupName });
                    }

                    string text = string.Empty;

                    foreach (XmlElement item in publicService.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc   = item.GetAttribute("Description");
                        string name   = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc))
                        {
                            continue;
                        }

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/"))
                        {
                            line = line.Substring(0, line.Length - 1);
                        }
                        text += line;
                    }

                    publicServiceRow.Add(semester, text);
                }

                XmlElement schoolSpecial = (XmlElement)record.TextScore.SelectSingleNode("SchoolSpecial");
                if (schoolSpecial != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("SchoolSpecial"))
                    {
                        GroupName = Utility.MorItemDict["SchoolSpecial"];
                    }

                    if (schoolSpecialRow == null)
                    {
                        schoolSpecialRow = new MoralItemRow(new string[] { GroupName });
                    }

                    string text = string.Empty;

                    foreach (XmlElement item in schoolSpecial.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc   = item.GetAttribute("Description");
                        string name   = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc))
                        {
                            continue;
                        }

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/"))
                        {
                            line = line.Substring(0, line.Length - 1);
                        }
                        text += line;
                    }

                    schoolSpecialRow.Add(semester, text);
                }
            }
            #endregion

            #region 定位,產生Row
            _builder.MoveToMergeField("日常行為表現");
            Cell  currentCell = _builder.CurrentParagraph.ParentNode as Cell;
            Row   currentRow  = currentCell.ParentRow;
            Table table       = currentRow.ParentTable;

            int rowCount    = items.Count;
            int insertIndex = table.Rows.IndexOf(currentRow) + 1;
            for (int i = 1; i < rowCount; i++)
            {
                table.Rows.Insert(insertIndex, currentRow.Clone(true));
            }
            #endregion

            #region 寫入日常行為表現
            Cell cell = currentCell;

            foreach (string key in items.Keys)
            {
                WordHelper.Write(cell, key, _builder);

                Cell indexCell = WordHelper.GetMoveRightCell(cell, 1);
                WriteMoralItemRow(indexCell, items[key]);

                cell = WordHelper.GetMoveDownCell(cell, 1);
            }
            #endregion

            #region 寫入團體活動表現
            _builder.MoveToMergeField("團體活動");
            if (groupActivityRow != null && groupActivityRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, groupActivityRow);
                if (currentCell.Paragraphs.Count > 0)
                {
                    currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
                }
            }
            else
            {
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            }
            #endregion

            #region 寫入公共服務表現
            _builder.MoveToMergeField("公共服務");
            if (publicServiceRow != null && publicServiceRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, publicServiceRow);
                if (currentCell.Paragraphs.Count > 0)
                {
                    currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
                }
            }
            else
            {
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            }
            #endregion

            #region 寫入校內外特殊表現
            _builder.MoveToMergeField("校內外特殊");
            if (schoolSpecialRow != null && schoolSpecialRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, schoolSpecialRow);
                if (currentCell.Paragraphs.Count > 0)
                {
                    currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
                }
            }
            else
            {
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            }
            #endregion

            #region 寫入具體建議
            _builder.MoveToMergeField("具體建議");
            if (recommendRow != null && recommendRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, recommendRow);
                if (currentCell.Paragraphs.Count > 0)
                {
                    currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
                }
            }
            else
            {
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            }
            #endregion
        }
        private void ProcessMoralScore(List<AutoSummaryRecord> autoSummaryList)
        {
            Dictionary<string, MoralItemRow> items = new Dictionary<string, MoralItemRow>();

            //團體活動
            MoralItemRow groupActivityRow = null;

            //公共服務
            MoralItemRow publicServiceRow = null;

            //校內外特殊表現
            MoralItemRow schoolSpecialRow = null;
            //具體建議
            MoralItemRow recommendRow = null;

            #region 建立適合列印的資料結構
            foreach (AutoSummaryRecord asRecord in autoSummaryList)
            {
                if (asRecord.MoralScore == null) continue;
                JHMoralScoreRecord record = asRecord.MoralScore;
                SemesterData semester = new SemesterData("" + record.SchoolYear, "" + record.Semester);

                XmlElement dailyBehavior = (XmlElement)record.TextScore.SelectSingleNode("DailyBehavior");
                if (dailyBehavior != null)
                {
                    foreach (XmlElement item in dailyBehavior.SelectNodes("Item"))
                    {
                        string name = item.GetAttribute("Name");
                        string index = item.GetAttribute("Index");
                        string degree = item.GetAttribute("Degree");

                        string[] lines = index.Split(new string[] { ";", ";" }, StringSplitOptions.RemoveEmptyEntries);

                        if (!items.ContainsKey(name))
                            items.Add(name, new MoralItemRow(lines));

                        items[name].Add(semester, degree);
                    }
                }

                XmlElement dailyLifeRecommend = (XmlElement)record.TextScore.SelectSingleNode("DailyLifeRecommend");
                if (dailyLifeRecommend != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("DailyLifeRecommend"))
                        GroupName = Utility.MorItemDict["DailyLifeRecommend"];

                    if (recommendRow == null)
                        recommendRow = new MoralItemRow(new string[] { GroupName });
                    recommendRow.Add(semester, dailyLifeRecommend.GetAttribute("Description"));
                }

                // 團體活動
                XmlElement groupActivity = (XmlElement)record.TextScore.SelectSingleNode("GroupActivity");
                if (groupActivity != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("GroupActivity"))
                        GroupName = Utility.MorItemDict["GroupActivity"];

                    if (groupActivityRow == null)
                        groupActivityRow = new MoralItemRow(new string[] { GroupName });

                    string text = string.Empty;
                    
                    foreach (XmlElement item in groupActivity.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc = item.GetAttribute("Description");
                        string name = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc)) continue;

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/")) line = line.Substring(0, line.Length - 1);
                        text += line;
                    }
                    
                    // 加入社團
                    if (_assnScoreCache.ContainsKey(record.RefStudentID))
                    {
                        string sc = record.SchoolYear.ToString();
                        string ss = record.Semester.ToString();
                        foreach (AssnScore asc in _assnScoreCache[record.RefStudentID])
                        {
                            if (asc.SchoolYear == sc && asc.Semester == ss)
                                text += "社團活動:" + asc.Score + "," + asc.Effort +"/"+ asc.Text;
                        }
                    
                    }
                    groupActivityRow.Add(semester, text);
                }



                XmlElement publicService = (XmlElement)record.TextScore.SelectSingleNode("PublicService");
                if (publicService != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("PublicService"))
                        GroupName = Utility.MorItemDict["PublicService"];

                    if (publicServiceRow == null)
                        publicServiceRow = new MoralItemRow(new string[] { GroupName });

                    string text = string.Empty;

                    foreach (XmlElement item in publicService.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc = item.GetAttribute("Description");
                        string name = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc)) continue;

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/")) line = line.Substring(0, line.Length - 1);
                        text += line;
                    }

                    publicServiceRow.Add(semester, text);
                }

                XmlElement schoolSpecial = (XmlElement)record.TextScore.SelectSingleNode("SchoolSpecial");
                if (schoolSpecial != null)
                {
                    string GroupName = "";
                    if (Utility.MorItemDict.ContainsKey("SchoolSpecial"))
                        GroupName = Utility.MorItemDict["SchoolSpecial"];

                    if (schoolSpecialRow == null)
                        schoolSpecialRow = new MoralItemRow(new string[] { GroupName });

                    string text = string.Empty;

                    foreach (XmlElement item in schoolSpecial.SelectNodes("Item"))
                    {
                        string degree = item.GetAttribute("Degree");
                        string desc = item.GetAttribute("Description");
                        string name = item.GetAttribute("Name");

                        if (string.IsNullOrEmpty(degree) && string.IsNullOrEmpty(desc)) continue;

                        string line = name + ":" + (string.IsNullOrEmpty(degree) ? "" : degree + "/") + (string.IsNullOrEmpty(desc) ? "" : desc);
                        if (line.EndsWith("/")) line = line.Substring(0, line.Length - 1);
                        text += line;
                    }

                    schoolSpecialRow.Add(semester, text);
                }
            }
            #endregion

            #region 定位,產生Row
            _builder.MoveToMergeField("日常行為表現");
            Cell currentCell = _builder.CurrentParagraph.ParentNode as Cell;
            Row currentRow = currentCell.ParentRow;
            Table table = currentRow.ParentTable;

            int rowCount = items.Count;
            int insertIndex = table.Rows.IndexOf(currentRow) + 1;
            for (int i = 1; i < rowCount; i++)
                table.Rows.Insert(insertIndex, currentRow.Clone(true));
            #endregion

            #region 寫入日常行為表現
            Cell cell = currentCell;

            foreach (string key in items.Keys)
            {
                WordHelper.Write(cell, key, _builder);

                Cell indexCell = WordHelper.GetMoveRightCell(cell, 1);
                WriteMoralItemRow(indexCell, items[key]);

                cell = WordHelper.GetMoveDownCell(cell, 1);
            }
            #endregion

            #region 寫入團體活動表現
            _builder.MoveToMergeField("團體活動");
            if (groupActivityRow != null && groupActivityRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, groupActivityRow);
                if (currentCell.Paragraphs.Count > 0) currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
            }
            else
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            #endregion

            #region 寫入公共服務表現
            _builder.MoveToMergeField("公共服務");
            if (publicServiceRow != null && publicServiceRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, publicServiceRow);
                if (currentCell.Paragraphs.Count > 0) currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
            }
            else
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            #endregion

            #region 寫入校內外特殊表現
            _builder.MoveToMergeField("校內外特殊");
            if (schoolSpecialRow != null && schoolSpecialRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, schoolSpecialRow);
                if (currentCell.Paragraphs.Count > 0) currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
            }
            else
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            #endregion

            #region 寫入具體建議
            _builder.MoveToMergeField("具體建議");
            if (recommendRow != null && recommendRow.Items.Count > 0)
            {
                currentCell = _builder.CurrentParagraph.ParentNode as Cell;
                WriteMoralItemRow(currentCell, recommendRow);
                if (currentCell.Paragraphs.Count > 0) currentCell.Paragraphs[0].ParagraphFormat.Alignment = ParagraphAlignment.Center;
            }
            else
                (_builder.CurrentParagraph.ParentNode as Cell).ParentRow.Remove();
            #endregion
        }