public ScoreWriter() { _config = new ReportConfiguration(Global.ReportName); _printPeriod = _config.GetBoolean("列印節數", true); _printCredit = _config.GetBoolean("列印權數", false); _printLearnDomain = _config.GetBoolean("列印學習領域總成績", true); _domainsWithoutDetail = new List <string>(); _degreeMapper = new DegreeMapper(); _warned = false; _domainText = new Dictionary <string, string>(); string printScore = _config.GetString("領域科目設定", "Domain"); if (printScore == "Domain") { List <string> list = Global.GetDomainList(); if (Global.Params["Mode"] == "HsinChu") //新竹市,語文跟彈性科目分列 { if (list.Contains("語文")) { list.Remove("語文"); } } if (list.Contains("彈性課程")) { list.Remove("彈性課程"); } _domainsWithoutDetail.AddRange(list); //_domainsWithoutDetail.AddRange(new string[] { "數學", "社會", "藝術與人文", "自然與生活科技", "健康與體育", "綜合活動" }); } }
public ReportPreference(string configName, byte[] defTemplateData) { _config = new ReportConfiguration(configName); DefaultTemplateData = defTemplateData; //SubjectOnly、DomainOnly、SubjectDomain。 string pt = _config.GetString("PrintType", ListMethod.DomainOnly.ToString()); ListMethod = (ListMethod)Enum.Parse(typeof(ListMethod), pt); PrintRank = _config.GetBoolean("PrintRank", false); PrintRankPercentage = _config.GetBoolean("PrintRankPercentage", false); AcceptAbsences = _config.GetString("AcceptAbsences", string.Empty); EntranceDate = _config.GetString("EntranceDate", ""); GraduateDate = _config.GetString("GraduateDate", ""); FilterRankScope = _config.GetBoolean("FilterRankScope", false); RankStart = _config.GetInteger("RankStart", 1); RankEnd = _config.GetInteger("RankEnd", 10); ConvertToPDF = _config.GetBoolean("ConvertToPDF", false); PrintSemesters = new List<int>(); string[] semses = _config.GetString("PrintSemesters", "1,2,3,4,5,6").Split(','); foreach (string each in semses) { if (string.IsNullOrEmpty(each)) continue; PrintSemesters.Add(int.Parse(each)); } }
public ReportPreference(string configName, byte[] defTemplateData) { _config = new ReportConfiguration(configName); DefaultTemplateData = defTemplateData; //SubjectOnly、DomainOnly、SubjectDomain。 string pt = _config.GetString("PrintType", ListMethod.DomainOnly.ToString()); ListMethod = (ListMethod)Enum.Parse(typeof(ListMethod), pt); PrintRank = _config.GetBoolean("PrintRank", false); PrintRankPercentage = _config.GetBoolean("PrintRankPercentage", false); AcceptAbsences = _config.GetString("AcceptAbsences", string.Empty); EntranceDate = _config.GetString("EntranceDate", ""); GraduateDate = _config.GetString("GraduateDate", ""); FilterRankScope = _config.GetBoolean("FilterRankScope", false); RankStart = _config.GetInteger("RankStart", 1); RankEnd = _config.GetInteger("RankEnd", 10); ConvertToPDF = _config.GetBoolean("ConvertToPDF", false); PrintSemesters = new List <int>(); string[] semses = _config.GetString("PrintSemesters", "1,2,3,4,5,6").Split(','); foreach (string each in semses) { if (string.IsNullOrEmpty(each)) { continue; } PrintSemesters.Add(int.Parse(each)); } }
private void MainForm_Load(object sender, EventArgs e) { this.MaximumSize = this.MinimumSize = this.Size; int schoolYear, semester; cbxScoreType.Items.Add(_SelScoreItem1); cbxScoreType.Items.Add(_SelScoreItem2); cbxScoreType.DropDownStyle = ComboBoxStyle.DropDownList; cbxScoreType.Text = _config.GetString("成績類型", _SelScoreItem1); chkReScore.Checked = _config.GetBoolean("只產生有補考成績學生", true); txtReExammark.Text = _config.GetString("補考成績加註", "*"); _schoolYear = int.TryParse(K12.Data.School.DefaultSchoolYear, out schoolYear) ? schoolYear : 0; _semester = int.TryParse(K12.Data.School.DefaultSemester, out semester) ? semester : 0; for (int i = -2; i <= 2; i++) { cboSchoolYear.Items.Add(_schoolYear + i); } cboSemester.Items.Add(1); cboSemester.Items.Add(2); cboSchoolYear.Text = _schoolYear + ""; cboSemester.Text = _semester + ""; }
public StudentSemesterScoreProcessor(DocumentBuilder builder, SemesterMap map, string type, Dictionary <string, bool> domains, K12.Data.GradScoreRecord StudGradScore) { builder.MoveToMergeField("成績"); _builder = builder; _manager = new DomainRowManager(type); _cell = builder.CurrentParagraph.ParentNode as Cell; _run = new Run(_cell.Document); _run.Font.Name = builder.Font.Name; _run.Font.Size = builder.Font.Size; _run.Text = string.Empty; _map = map; _domains = domains; _StudGradScore = StudGradScore; _config = new ReportConfiguration(Global.ReportName); PrintPeriod = _config.GetBoolean("列印節數", false); PrintCredit = _config.GetBoolean("列印權數", false); }
private void LoadConfig() { string print = _config.GetString("領域科目設定", string.Empty); if (print == "Domain") { rbDomain.Checked = true; } else if (print == "Subject") { rbSubject.Checked = true; } chkLearnDomain.Checked = _config.GetBoolean("列印學習領域總成績", true); chkPeriod.Checked = _config.GetBoolean("列印節數", true); chkCredit.Checked = _config.GetBoolean("列印權數", false); }
//private void SetupDefaultTemplate() //{ // //如果設定中沒有範本,使用預設範本。 // if (_config.Template == null) // { // ReportTemplate template = new ReportTemplate(Properties.Resources.國中學籍表, TemplateType.Word); // _config.Template = template; // } //} private void LoadConfig() { string print = _config.GetString("領域科目設定", string.Empty); if (print == "Domain") { rbDomain.Checked = true; } else if (print == "Subject") { rbSubject.Checked = true; } chkPeriod.Checked = _config.GetBoolean("列印節數", false); chkCredit.Checked = _config.GetBoolean("列印權數", false); chkText.Checked = _config.GetBoolean("列印文字評語", true); checkBoxX1.Checked = _Dylanconfig.GetBoolean("單檔儲存", false); }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(School.ChineseName); globalFieldName.Add("列印時間"); globalFieldValue.Add(Global.CDate(DateTime.Now.ToString("yyyy/MM/dd")) + " " + DateTime.Now.ToString("HH:mm:ss")); ReportConfiguration _Dylanconfig = new ReportConfiguration(Global.OneFileSave); OneFileSave = _Dylanconfig.GetBoolean("單檔儲存", false); StudentDoc = new Dictionary <string, Document>(); List <JHPeriodMappingInfo> periodList = JHPeriodMapping.SelectAll(); List <JHAbsenceMappingInfo> absenceList = JHAbsenceMapping.SelectAll(); double total = Options.Students.Count; double count = 0; List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in Options.Students) { student_ids.Add(item.ID); } DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 變更節權數顯示 string pcDisplay = string.Empty; bool printPeriod = Config.GetBoolean("列印節數", false); bool printCredit = Config.GetBoolean("列印權數", false); if (printPeriod && printCredit) { pcDisplay = "節/權數"; } else if (printPeriod) { pcDisplay = "節數"; } else if (printCredit) { pcDisplay = "權數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 快取資料 // 取得學生缺曠 Dictionary <string, List <AutoSummaryRecord> > autoSummaryCache = new Dictionary <string, List <AutoSummaryRecord> >(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids, null)) { if (!autoSummaryCache.ContainsKey(record.RefStudentID)) { autoSummaryCache.Add(record.RefStudentID, new List <AutoSummaryRecord>()); } autoSummaryCache[record.RefStudentID].Add(record); } // 取得學生異動 Dictionary <string, List <JHUpdateRecordRecord> > updateRecordCache = new Dictionary <string, List <JHUpdateRecordRecord> >(); foreach (var record in JHUpdateRecord.SelectByStudentIDs(student_ids)) { if (!updateRecordCache.ContainsKey(record.StudentID)) { updateRecordCache.Add(record.StudentID, new List <JHUpdateRecordRecord>()); } updateRecordCache[record.StudentID].Add(record); } // 取得學生學期成績 Dictionary <string, List <JHSemesterScoreRecord> > semesterScoreCache = new Dictionary <string, List <JHSemesterScoreRecord> >(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids)) { if (!semesterScoreCache.ContainsKey(record.RefStudentID)) { semesterScoreCache.Add(record.RefStudentID, new List <JHSemesterScoreRecord>()); } semesterScoreCache[record.RefStudentID].Add(record); } // 取得學生學期歷程 Dictionary <string, JHSemesterHistoryRecord> semesterHistoryCache = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { if (!semesterHistoryCache.ContainsKey(record.RefStudentID)) { semesterHistoryCache.Add(record.RefStudentID, record); } } // 取得學生畢業成績 Dictionary <string, K12.Data.GradScoreRecord> StudGradScoreDic = new Dictionary <string, GradScoreRecord>(); foreach (GradScoreRecord score in GradScore.SelectByIDs <GradScoreRecord>(student_ids)) { StudGradScoreDic.Add(score.RefStudentID, score); } #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, true); } if (domains.ContainsKey("語文")) { domains["語文"] = false; } if (domains.ContainsKey("彈性課程")) { domains["彈性課程"] = false; } if (!domains.ContainsKey("")) { domains.Add("", false); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, false); } if (!domains.ContainsKey("")) { domains.Add("", false); } } else { throw new Exception("請重新儲存列印設定"); } //string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); //if (domainSubjectSetup == "Domain") //{ // foreach (var domain in JHSchool.Evaluation.Subject.Domains) // domains.Add(domain, DomainSubjectExpand.不展開); // if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); //} //else if (domainSubjectSetup == "Subject") //{ // foreach (var domain in JHSchool.Evaluation.Subject.Domains) // domains.Add(domain, DomainSubjectExpand.展開); // if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); //} //else // throw new Exception("請重新儲存一次列印設定"); #endregion #region 務學習時數 Global._SLRDict.Clear(); Global._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in Options.Students) { count++; DocumentBuilder builder = null; Document each = (Document)_template.Clone(true); #region 建立學期歷程對照 List <SemesterHistoryItem> semesterHistoryList = null; if (semesterHistoryCache.ContainsKey(student.ID)) { semesterHistoryList = semesterHistoryCache[student.ID].SemesterHistoryItems; } else { semesterHistoryList = new List <SemesterHistoryItem>(); } SemesterMap map = new SemesterMap(); map.SetData(semesterHistoryList); #endregion #region Part1 builder = new DocumentBuilder(each); StudentBasicInfo basic = new StudentBasicInfo(); basic.SetStudent(student, semesterHistoryList); StudentSemesterHistory history = new StudentSemesterHistory(); history.SetData(semesterHistoryList); each.MailMerge.MergeField += delegate(object sender1, MergeFieldEventArgs e1) { #region 處理照片 if (e1.FieldName == "照片") { byte[] photoBytes = null; try { photoBytes = Convert.FromBase64String("" + e1.FieldValue); } catch (Exception ex) { e1.Field.Remove(); return; } if (photoBytes == null || photoBytes.Length == 0) { e1.Field.Remove(); return; } DocumentBuilder builder1 = new DocumentBuilder(e1.Document); builder1.MoveToField(e1.Field, true); e1.Field.Remove(); Shape photoShape = new Shape(e1.Document, ShapeType.Image); photoShape.ImageData.SetImage(photoBytes); photoShape.WrapType = WrapType.Inline; #region AutoResize double origHWRate = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints; double shapeHeight = (builder1.CurrentParagraph.ParentNode.ParentNode as Row).RowFormat.Height * 6; double shapeWidth = (builder1.CurrentParagraph.ParentNode as Cell).CellFormat.Width; if ((shapeHeight / shapeWidth) < origHWRate) { shapeWidth = shapeHeight / origHWRate; } else { shapeHeight = shapeWidth * origHWRate; } #endregion photoShape.Height = shapeHeight; photoShape.Width = shapeWidth; builder1.InsertNode(photoShape); } #endregion }; List <string> fieldName = new List <string>(); fieldName.AddRange(basic.GetFieldName()); fieldName.AddRange(history.GetFieldName()); List <string> fieldValue = new List <string>(); fieldValue.AddRange(basic.GetFieldValue()); fieldValue.AddRange(history.GetFieldValue()); each.MailMerge.Execute(fieldName.ToArray(), fieldValue.ToArray()); builder.MoveToMergeField("異動"); List <JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) { updateRecordList = updateRecordCache[student.ID]; } else { updateRecordList = new List <JHUpdateRecordRecord>(); } StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(builder); updateRecordProcessor.SetData(updateRecordList); builder.MoveToMergeField("成績"); List <JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) { semesterScoreList = semesterScoreCache[student.ID]; } else { semesterScoreList = new List <JHSemesterScoreRecord>(); } // 學生畢業成績 K12.Data.GradScoreRecord studGradScore = new GradScoreRecord(); if (StudGradScoreDic.ContainsKey(student.ID)) { studGradScore = StudGradScoreDic[student.ID]; } StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, domainSubjectSetup, domains, studGradScore); semesterScoreProcessor.DegreeMapper = _degreeMapper; semesterScoreProcessor.PrintPeriod = printPeriod; semesterScoreProcessor.PrintCredit = printCredit; semesterScoreProcessor.SetData(semesterScoreList); #endregion #region Part2 //builder = new DocumentBuilder(each); builder.MoveToMergeField("領域文字描述"); if (Config.GetBoolean("列印文字評語", true)) { StudentDomainTextProcessor domainTextProcessor = new StudentDomainTextProcessor(builder, map); domainTextProcessor.SetData(semesterScoreList); } else { Section deleteSection = builder.CurrentSection; each.Sections.Remove(deleteSection); } #endregion #region Part3 //Document part3 = (Document)_template_part3.Clone(true); //builder = new DocumentBuilder(each); builder.MoveToMergeField("日常行為"); StudentMoralProcessor moralProcessor = new StudentMoralProcessor(builder, map, periodList, absenceList); List <AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) { autoSummaryList = autoSummaryCache[student.ID]; } else { autoSummaryList = new List <AutoSummaryRecord>(); } moralProcessor.SetData(autoSummaryList); // 處理多出來 table row Cell cel = moralProcessor.GetCurrentCell(); Table table = cel.ParentRow.ParentTable; for (int i = 47; i >= 20; i--) { bool rm = true; foreach (Aspose.Words.Cell cell in table.Rows[i].Cells) { if (cell.GetText() != "\a") { rm = false; break; } } if (rm) { table.Rows[i].Remove(); } } #endregion if (OneFileSave) { each.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); string fileName = ""; fileName = student.StudentNumber; fileName += "_" + student.IDNumber; if (!string.IsNullOrEmpty(student.RefClassID)) { fileName += "_" + student.Class.Name; } else { fileName += "_"; } fileName += "_" + (student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""); fileName += "_" + student.Name; if (!StudentDoc.ContainsKey(fileName)) { StudentDoc.Add(fileName, each); } } else { foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } if (!OneFileSave) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("列印日期"); globalFieldValue.Add(DateConvert.CDate(DateTime.Now.ToString("yyyy/MM/dd"))); globalFieldName.Add("列印時間"); globalFieldValue.Add(DateTime.Now.ToString("HH:mm:ss")); ReportConfiguration _Dylanconfig = new ReportConfiguration(Global.OneFileSave); OneFileSave = _Dylanconfig.GetBoolean("單檔儲存", false); StudentDoc = new Dictionary <string, Document>(); double total = _students.Count; double count = 0; List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in _students) { student_ids.Add(item.ID); } #region 快取資料 //取得異動資料 Dictionary <string, List <JHUpdateRecordRecord> > updateRecordCache = new Dictionary <string, List <JHUpdateRecordRecord> >(); foreach (var record in JHUpdateRecord.SelectByStudentIDs(student_ids)) { if (!updateRecordCache.ContainsKey(record.StudentID)) { updateRecordCache.Add(record.StudentID, new List <JHUpdateRecordRecord>()); } updateRecordCache[record.StudentID].Add(record); } //取得缺曠獎懲資料 Dictionary <string, List <AutoSummaryRecord> > autoSummaryCache = new Dictionary <string, List <AutoSummaryRecord> >(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids, null)) { if (!autoSummaryCache.ContainsKey(record.RefStudentID)) { autoSummaryCache.Add(record.RefStudentID, new List <AutoSummaryRecord>()); } autoSummaryCache[record.RefStudentID].Add(record); } //取得學期歷程 Dictionary <string, JHSemesterHistoryRecord> semesterHistoryCache = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { if (!semesterHistoryCache.ContainsKey(record.RefStudentID)) { semesterHistoryCache.Add(record.RefStudentID, record); } } //取得學期成績 Dictionary <string, List <JHSemesterScoreRecord> > semesterScoreCache = new Dictionary <string, List <JHSemesterScoreRecord> >(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids)) { if (!semesterScoreCache.ContainsKey(record.RefStudentID)) { semesterScoreCache.Add(record.RefStudentID, new List <JHSemesterScoreRecord>()); } semesterScoreCache[record.RefStudentID].Add(record); } // 取得畢業成績 Dictionary <string, K12.Data.GradScoreRecord> StudGradScoreDic = new Dictionary <string, GradScoreRecord>(); foreach (GradScoreRecord score in GradScore.SelectByIDs <GradScoreRecord>(student_ids)) { StudGradScoreDic.Add(score.RefStudentID, score); } ////課程 //JHCourse.RemoveAll(); //Dictionary<string, JHCourseRecord> courseCache = new Dictionary<string, JHCourseRecord>(); //foreach (JHCourseRecord record in JHCourse.SelectAll()) //{ // if (!courseCache.ContainsKey(record.ID)) // courseCache.Add(record.ID, record); //} #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); //Dictionary<string, List<string>> subjects = new Dictionary<string, List<string>>(); //List<JHCourseRecord> courseList = new List<JHCourseRecord>(courseCache.Values); //courseList.Sort(delegate(JHCourseRecord x, JHCourseRecord y) //{ // return JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject); //}); string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } else { throw new Exception("請重新儲存一次列印設定"); } //foreach (var domain in JHSchool.Evaluation.Subject.Domains) // subjects.Add(domain, new List<string>()); //if (!subjects.ContainsKey("")) subjects.Add("", new List<string>()); //foreach (var course in courseList) //{ // if (!subjects.ContainsKey(course.Domain)) // subjects.Add(course.Domain, new List<string>()); // if (!subjects[course.Domain].Contains(course.Subject) && // domains.ContainsKey(course.Domain) && // domains[course.Domain] == false) // { // subjects[course.Domain].Add(course.Subject); // } //} #endregion DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 節權數顯示 string pcDisplay = string.Empty; bool printPeriod = Config.GetBoolean("列印節數", true); bool printCredit = Config.GetBoolean("列印權數", false); if (printPeriod && printCredit) { pcDisplay = "節" + Environment.NewLine + "權" + Environment.NewLine + "數"; } else if (printPeriod) { pcDisplay = "節" + Environment.NewLine + "數"; } else if (printCredit) { pcDisplay = "權" + Environment.NewLine + "數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 文字評語是否列印 bool printText = Config.GetBoolean("列印文字評語", true); if (printText == false) { templateBuilder.MoveToMergeField("學習領域評量"); (templateBuilder.CurrentParagraph.ParentNode as Cell).ParentRow.ParentTable.Remove(); } #endregion #region 務學習時數 Global._SLRDict.Clear(); Global._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in _students) { count++; Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 建立學期歷程對照 List <SemesterHistoryItem> semesterHistoryList = null; if (semesterHistoryCache.ContainsKey(student.ID)) { semesterHistoryList = semesterHistoryCache[student.ID].SemesterHistoryItems; } else { semesterHistoryList = new List <SemesterHistoryItem>(); } SemesterMap map = new SemesterMap(); map.SetData(semesterHistoryList); #endregion #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student, semesterHistoryList); #endregion #region 異動資料 List <JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) { updateRecordList = updateRecordCache[student.ID]; } else { updateRecordList = new List <JHUpdateRecordRecord>(); } StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(builder); updateRecordProcessor.SetData(updateRecordList); #endregion #region 日常表現 List <AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) { autoSummaryList = autoSummaryCache[student.ID]; } else { autoSummaryList = new List <AutoSummaryRecord>(); } StudentMoralProcessor moralProcessor = new StudentMoralProcessor(builder, map); moralProcessor.SetData(autoSummaryList); #endregion #region 學期歷程 StudentHistoryProcessor history = new StudentHistoryProcessor(builder, map, (semesterHistoryCache.ContainsKey(student.ID) ? semesterHistoryCache[student.ID] : null)); #endregion #region 學期成績 List <JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) { semesterScoreList = semesterScoreCache[student.ID]; } else { semesterScoreList = new List <JHSemesterScoreRecord>(); } // 畢業成績 K12.Data.GradScoreRecord StudGradScore = new GradScoreRecord(); if (StudGradScoreDic.ContainsKey(student.ID)) { StudGradScore = StudGradScoreDic[student.ID]; } StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, domainSubjectSetup, domains, StudGradScore); semesterScoreProcessor.DegreeMapper = _degreeMapper; semesterScoreProcessor.PrintPeriod = printPeriod; semesterScoreProcessor.PrintCredit = printCredit; semesterScoreProcessor.SetData(semesterScoreList); #endregion #region 學習領域評量 if (printText == true) { StudentTextProcessor text = new StudentTextProcessor(builder, map); text.SetData(semesterScoreList); } #endregion if (OneFileSave) { each.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); string fileName = ""; fileName = student.StudentNumber; fileName += "_" + student.IDNumber; if (!string.IsNullOrEmpty(student.RefClassID)) { fileName += "_" + student.Class.Name; } else { fileName += "_"; } fileName += "_" + (student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""); fileName += "_" + student.Name; if (!StudentDoc.ContainsKey(fileName)) { StudentDoc.Add(fileName, each); } } else { foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } if (!OneFileSave) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { double total = _config.Students.Count; double count = 0; _worker.ReportProgress(0); List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in _config.Students) { student_ids.Add(item.ID); } #region 快取資料 //獎勵 Dictionary <string, List <JHMeritRecord> > meritCache = new Dictionary <string, List <JHMeritRecord> >(); foreach (JHMeritRecord record in JHMerit.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!meritCache.ContainsKey(record.RefStudentID)) { meritCache.Add(record.RefStudentID, new List <JHMeritRecord>()); } meritCache[record.RefStudentID].Add(record); } //懲戒 Dictionary <string, List <JHDemeritRecord> > demeritCache = new Dictionary <string, List <JHDemeritRecord> >(); foreach (JHDemeritRecord record in JHDemerit.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!demeritCache.ContainsKey(record.RefStudentID)) { demeritCache.Add(record.RefStudentID, new List <JHDemeritRecord>()); } demeritCache[record.RefStudentID].Add(record); } //缺曠 Dictionary <string, List <JHAttendanceRecord> > attendanceCache = new Dictionary <string, List <JHAttendanceRecord> >(); foreach (JHAttendanceRecord record in JHAttendance.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!attendanceCache.ContainsKey(record.RefStudentID)) { attendanceCache.Add(record.RefStudentID, new List <JHAttendanceRecord>()); } attendanceCache[record.RefStudentID].Add(record); } List <string> course_ids = new List <string>(); foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDs(student_ids)) { if (!course_ids.Contains(record.RefCourseID)) { course_ids.Add(record.RefCourseID); } } //課程 JHCourse.RemoveAll(); int schoolYear = _config.SchoolYear; int semester = _config.Semester; Dictionary <string, JHCourseRecord> courseCache = new Dictionary <string, JHCourseRecord>(); foreach (JHCourseRecord record in JHCourse.SelectByIDs(course_ids)) { if ("" + record.SchoolYear != "" + schoolYear) { continue; } if ("" + record.Semester != "" + semester) { continue; } // 過濾使用者所選課程才放入 if (Global._selectCourseIDList.Contains(record.ID)) { if (!courseCache.ContainsKey(record.ID)) { courseCache.Add(record.ID, record); } } } //修課記錄 Dictionary <string, List <string> > scCache = new Dictionary <string, List <string> >(); //foreach (JHSCAttendRecord sc in JHSCAttend.Select(student_ids, course_ids, new string[] { }, "" + _config.SchoolYear, "" + _config.Semester)) foreach (JHSCAttendRecord sc in JHSCAttend.SelectByStudentIDAndCourseID(student_ids, course_ids)) { if (!courseCache.ContainsKey(sc.RefCourseID)) { continue; } if (!scCache.ContainsKey(sc.RefStudentID)) { scCache.Add(sc.RefStudentID, new List <string>()); } // 過濾使用者不選 if (Global._selectCourseIDList.Contains(sc.RefCourseID)) { scCache[sc.RefStudentID].Add(sc.RefCourseID); } } //評量成績 Dictionary <string, List <HC.JHSCETakeRecord> > sceScoreCache = new Dictionary <string, List <HC.JHSCETakeRecord> >(); foreach (JHSCETakeRecord record in JHSCETake.SelectByStudentAndCourse(student_ids, course_ids)) { if (record.RefExamID != _config.Exam.ID) { continue; } if (!sceScoreCache.ContainsKey(record.RefStudentID)) { sceScoreCache.Add(record.RefStudentID, new List <HC.JHSCETakeRecord>()); } sceScoreCache[record.RefStudentID].Add(new HC.JHSCETakeRecord(record)); } //學期歷程 Dictionary <string, K12.Data.SemesterHistoryItem> historyCache = new Dictionary <string, K12.Data.SemesterHistoryItem>(); foreach (JHSemesterHistoryRecord record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { foreach (K12.Data.SemesterHistoryItem item in record.SemesterHistoryItems) { if ("" + item.SchoolYear != K12.Data.School.DefaultSchoolYear) { continue; } if ("" + item.Semester != K12.Data.School.DefaultSemester) { continue; } if (!historyCache.ContainsKey(record.RefStudentID)) { historyCache.Add(record.RefStudentID, item); } } } //取得所有教師,為了Cache下來 JHTeacher.SelectAll(); #endregion #region 建立節次對照及假別列表 Dictionary <string, string> periodMapping = new Dictionary <string, string>(); foreach (JHPeriodMappingInfo info in JHPeriodMapping.SelectAll()) { if (!periodMapping.ContainsKey(info.Name)) { periodMapping.Add(info.Name, info.Type); } } List <string> absenceList = new List <string>(); foreach (JHAbsenceMappingInfo info in JHAbsenceMapping.SelectAll()) { absenceList.Add(info.Name); } #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); Dictionary <string, List <string> > subjects = new Dictionary <string, List <string> >(); List <JHCourseRecord> courseList = new List <JHCourseRecord>(courseCache.Values); courseList.Sort(delegate(JHCourseRecord x, JHCourseRecord y) { return(JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject)); //List<string> list = new List<string>(new string[] { "國語文", "國文", "英文", "英語", "數學", "歷史", "地理", "公民", "理化", "生物" }); //int ix = list.IndexOf(x.Subject); //int iy = list.IndexOf(y.Subject); //if (ix >= 0 && iy >= 0) // return ix.CompareTo(iy); //else if (ix >= 0) // return -1; //else if (iy >= 0) // return 1; //else // return x.Subject.CompareTo(y.Subject); }); string domainSubjectSetup = _rc.GetString("領域科目設定", "Domain"); _config.DomainSubjectSetup = domainSubjectSetup; if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, true); } //domains.Add("彈性課程", false); if (domains.ContainsKey("語文")) { domains["語文"] = false; } if (!domains.ContainsKey("")) { domains.Add("", false); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, false); } //domains.Add("彈性課程", false); if (!domains.ContainsKey("")) { domains.Add("", false); } } else { throw new Exception("請重新儲存一次列印設定"); } foreach (var domain in JHSchool.Evaluation.Subject.Domains) { subjects.Add(domain, new List <string>()); } //subjects.Add("彈性課程", new List<string>()); subjects.Add("", new List <string>()); //foreach (JHCourseRecord course in courseList) //{ // if (!domains.ContainsKey(course.Domain)) continue; // if (!subjects.ContainsKey(course.Domain)) // subjects.Add(course.Domain, new List<string>()); // //很怪 // if (domains[course.Domain] == true) continue; // if (!subjects[course.Domain].Contains(course.Subject)) // subjects[course.Domain].Add(course.Subject); //} _config.SetPrintDomains(domains); _config.SetPrintSubjects(subjects); #endregion DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 判斷是否列印文字評語 templateBuilder.MoveToMergeField("文字評語"); if (_rc.GetBoolean("列印文字評語", true)) { templateBuilder.Write("文字評語"); } else { Cell first = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = first.CellFormat.Width; Table table = first.ParentRow.ParentTable; foreach (Row row in table.Rows) { if (row.ChildNodes.Count == 1) { break; } row.RemoveChild(row.LastCell); int lastIndex = row.ChildNodes.Count - 1; row.Cells[lastIndex--].CellFormat.Width += (width / 3f); row.Cells[lastIndex--].CellFormat.Width += (width / 3f); row.Cells[lastIndex].CellFormat.Width += (width / 3f); } } #endregion #region 依節權數設定,在畫面上顯示 string pcDisplay = string.Empty; bool p = _rc.GetBoolean("列印節數", false); bool c = _rc.GetBoolean("列印權數", false); if (p && c) { pcDisplay = "節/權數"; } else if (p) { pcDisplay = "節數"; } else if (c) { pcDisplay = "權數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 如果使用者不印定期評量,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("定期評量"); if (_rc.GetBoolean("列印定期評量", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 3]); lastIndex = eachRow.ChildNodes.Count - 3; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("定期評量"); } #endregion #region 如果使用者不印平時評量,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("平時評量"); if (_rc.GetBoolean("列印平時評量", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 2]); lastIndex = eachRow.ChildNodes.Count - 2; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("平時評量"); } #endregion #region 如果使用者不印定期學習評量總成績,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("定期學習評量總成績"); if (_rc.GetBoolean("列印定期學習評量總成績", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 2]); lastIndex = eachRow.ChildNodes.Count - 2; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("定期學習評量總成績"); } #endregion #region 取得學生成績計算規則 ScoreCalculator defaultScoreCalculator = new ScoreCalculator(null); //key: ScoreCalcRuleID Dictionary <string, ScoreCalculator> calcCache = new Dictionary <string, ScoreCalculator>(); //key: StudentID, val: ScoreCalcRuleID Dictionary <string, string> calcIDCache = new Dictionary <string, string>(); List <string> scoreCalcRuleIDList = new List <string>(); foreach (JHStudentRecord student in _config.Students) { //calcCache.Add(student.ID, new ScoreCalculator(student.ScoreCalcRule)); string calcID = string.Empty; if (!string.IsNullOrEmpty(student.OverrideScoreCalcRuleID)) { calcID = student.OverrideScoreCalcRuleID; } else if (student.Class != null && !string.IsNullOrEmpty(student.Class.RefScoreCalcRuleID)) { calcID = student.Class.RefScoreCalcRuleID; } if (!string.IsNullOrEmpty(calcID)) { calcIDCache.Add(student.ID, calcID); } } foreach (JHScoreCalcRuleRecord record in JHScoreCalcRule.SelectByIDs(calcIDCache.Values)) { if (!calcCache.ContainsKey(record.ID)) { calcCache.Add(record.ID, new ScoreCalculator(record)); } } //MsgBox.Show("" + (Environment.TickCount - t)); #endregion #region 檢查學生成績是否超出可列印行數 foreach (JHStudentRecord student in _config.Students) { if (scCache.ContainsKey(student.ID)) { int checkCount = 0; if (_config.DomainSubjectSetup == "Subject") { checkCount = scCache[student.ID].Count; } else { List <string> checkDomains = new List <string>(); foreach (string courseID in scCache[student.ID]) { JHCourseRecord course = courseCache[courseID]; if (string.IsNullOrEmpty(course.Domain)) { checkCount++; } else if (!checkDomains.Contains(course.Domain)) { checkDomains.Add(course.Domain); } } checkCount += checkDomains.Count; } if (checkCount > _rowCount) { _overStudentList.Add(student.ID); } } } //有學生資料超出範圍 if (_overStudentList.Count > 0) { //K12.Presentation.NLDPanels.Student.AddToTemp(overStudentList); System.Windows.Forms.DialogResult result = MsgBox.Show("有 " + _overStudentList.Count + " 位學生評量成績資料超出範本可列印範圍,已將學生加入待處理。\n是否繼續列印?", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { e.Result = "Cancel"; } } #endregion // 取得學生課程ID對照 Dictionary <string, List <string> > studCourseID = new Dictionary <string, List <string> >(); List <string> sid = (from stud in _config.Students select stud.ID).ToList(); foreach (JHSCAttendRecord attend in JHSCAttend.SelectByStudentIDs(sid)) { if (attend.Course.SchoolYear.HasValue && attend.Course.Semester.HasValue) { if (attend.Course.SchoolYear == _config.SchoolYear && attend.Course.Semester == _config.Semester) { if (studCourseID.ContainsKey(attend.RefStudentID)) { studCourseID[attend.RefStudentID].Add(attend.RefCourseID); } else { List <string> coid = new List <string>(); coid.Add(attend.RefCourseID); studCourseID.Add(attend.RefStudentID, coid); } } } } // 取得學期歷程 Config._StudSemesterHistoryItemDict.Clear(); List <JHSemesterHistoryRecord> semHisRec = JHSemesterHistory.SelectByStudents(_config.Students); // 當畫面學期歷程內的學年度學期與畫面上設定相同,加入 foreach (JHSemesterHistoryRecord rec in semHisRec) { foreach (K12.Data.SemesterHistoryItem shi in rec.SemesterHistoryItems) { if (shi.SchoolYear == _config.SchoolYear && shi.Semester == _config.Semester) { if (!Config._StudSemesterHistoryItemDict.ContainsKey(shi.RefStudentID)) { Config._StudSemesterHistoryItemDict.Add(shi.RefStudentID, shi); } } } } // 取得評量比例 Utility.ScorePercentageHSDict.Clear(); Utility.ScorePercentageHSDict = Utility.GetScorePercentageHS(); #region 產生 foreach (JHStudentRecord student in _config.Students) { count++; if (_overStudentList.Contains(student.ID)) { continue; } Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student); #endregion #region 班導師 builder.MoveToMergeField("班導師"); if (historyCache.ContainsKey(student.ID)) { builder.Write(historyCache[student.ID].Teacher); } else { builder.Write(string.Empty); } #endregion #region 成績 List <HC.JHSCETakeRecord> sceScoreList = null; if (sceScoreCache.ContainsKey(student.ID)) { sceScoreList = sceScoreCache[student.ID]; } else { sceScoreList = new List <HC.JHSCETakeRecord>(); } ScoreCalculator studentCalculator = defaultScoreCalculator; if (calcIDCache.ContainsKey(student.ID) && calcCache.ContainsKey(calcIDCache[student.ID])) { studentCalculator = calcCache[calcIDCache[student.ID]]; } // 過濾 courseCache studid Dictionary <string, JHCourseRecord> courseCache1 = new Dictionary <string, JHCourseRecord>(); foreach (KeyValuePair <string, JHCourseRecord> val in courseCache) { // 從學生修課來對應到課程 if (studCourseID.ContainsKey(student.ID)) { if (studCourseID[student.ID].Contains(val.Value.ID)) { courseCache1.Add(val.Key, val.Value); } } } StudentExamScore examScore = new StudentExamScore(builder, _config, courseCache1); examScore.PrintPeriod = _rc.GetBoolean("列印節數", false); examScore.PrintCredit = _rc.GetBoolean("列印權數", false); examScore.PrintText = _rc.GetBoolean("列印文字評語", true); examScore.PrintScore = _rc.GetBoolean("列印定期評量", true); examScore.PrintAssScore = _rc.GetBoolean("列印平時評量", true); examScore.PrintTotalScore = _rc.GetBoolean("列印定期學習評量總成績", true); examScore.SetScoreCalculator(studentCalculator); if (scCache.ContainsKey(student.ID)) { examScore.SetSubjects(scCache[student.ID]); } examScore.SetData(sceScoreList); #endregion if (_config.DomainSubjectSetup == "Subject") { // 科目定期評量加權平均 if (builder.MoveToMergeField("加權平均") || builder.MoveToMergeField("定期評量加權平均")) { if (examScore.SubjAvgScore > 0) { builder.Write(examScore.SubjAvgScore.ToString()); } else { builder.Write(""); } } // 科目平時評量加權平均 if (builder.MoveToMergeField("平時評量加權平均")) { if (examScore.SubjAvgAssignmentScore > 0) { builder.Write(examScore.SubjAvgAssignmentScore.ToString()); } else { builder.Write(""); } } // 科目學習總分加權平均 if (builder.MoveToMergeField("定期學習評量總成績加權平均")) { if (examScore.SubjAvgFinalScore > 0) { builder.Write(examScore.SubjAvgFinalScore.ToString()); } else { builder.Write(""); } } } else { // 領域定期評量加權平均 if (builder.MoveToMergeField("加權平均") || builder.MoveToMergeField("定期評量加權平均")) { if (examScore.DomainAvgScore > 0) { builder.Write(examScore.DomainAvgScore.ToString()); } else { builder.Write(""); } } // 領域平時評量加權平均 if (builder.MoveToMergeField("平時評量加權平均")) { if (examScore.DomainAvgAssignmentScore > 0) { builder.Write(examScore.DomainAvgAssignmentScore.ToString()); } else { builder.Write(""); } } // 領域學習總分加權平均 if (builder.MoveToMergeField("定期學習評量總成績加權平均")) { if (examScore.DomainAvgFinalScore > 0) { builder.Write(examScore.DomainAvgFinalScore.ToString()); } else { builder.Write(""); } } } #region 日常表現 List <JHMeritRecord> meritList = null; List <JHDemeritRecord> demeritList = null; List <JHAttendanceRecord> attendanceList = null; meritList = (meritCache.ContainsKey(student.ID)) ? meritCache[student.ID] : new List <JHMeritRecord>(); demeritList = (demeritCache.ContainsKey(student.ID)) ? demeritCache[student.ID] : new List <JHDemeritRecord>(); attendanceList = (attendanceCache.ContainsKey(student.ID)) ? attendanceCache[student.ID] : new List <JHAttendanceRecord>(); StudentMoralScore moral = new StudentMoralScore(builder, _config, periodMapping, absenceList); moral.SetData(meritList, demeritList, attendanceList); #endregion foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("學年度"); globalFieldValue.Add(_config.SchoolYear); globalFieldName.Add("學期"); globalFieldValue.Add(_config.Semester); globalFieldName.Add("評量名稱"); globalFieldValue.Add(_config.Exam.Name); globalFieldName.Add("統計期間"); globalFieldValue.Add(_config.StartDate.ToShortDateString() + " ~ " + _config.EndDate.ToShortDateString()); globalFieldName.Add("列印日期"); globalFieldValue.Add(DateConvert.CDate(DateTime.Now.ToString("yyyy/MM/dd")) + " " + DateTime.Now.ToString("HH:mm:ss")); string chancellor, eduDirector, stuDirector; chancellor = eduDirector = stuDirector = string.Empty; XmlElement schoolInfo = K12.Data.School.Configuration["學校資訊"].PreviousData; XmlElement chancellorElement = (XmlElement)schoolInfo.SelectSingleNode("ChancellorChineseName"); XmlElement eduDirectorElement = (XmlElement)schoolInfo.SelectSingleNode("EduDirectorName"); if (chancellorElement != null) { chancellor = chancellorElement.InnerText; } if (eduDirectorElement != null) { eduDirector = eduDirectorElement.InnerText; } globalFieldName.Add("教務主任"); globalFieldValue.Add(eduDirector); globalFieldName.Add("校長"); globalFieldValue.Add(chancellor); globalFieldName.Add("成績校正日期"); globalFieldValue.Add(_rc.GetString("成績校正日期", string.Empty)); if (_config.Students.Count > _overStudentList.Count) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
/// <summary> /// 未達畢業標準通知單 /// </summary> private void ExportDoc() { if (_students.Count == 0) { return; } _doc.Sections.Clear(); if (_rc.Template == null) { _rc.Template = new ReportTemplate(Properties.Resources.未達畢業標準通知單樣板, TemplateType.Word); } _template = _rc.Template.ToDocument(); string UserSelAddresseeAddress = _rc.GetString(PrintConfigForm.setupAddresseeAddress, "聯絡地址"); string UserSelAddresseeName = _rc.GetString(PrintConfigForm.setupAddresseeName, "監護人"); _UserSelExportStudentList = _rc.GetBoolean(PrintConfigForm.setupExportStudentList, false); string UserSeldtDate = ""; DateTime dt; if (DateTime.TryParse(_rc.GetString(PrintConfigForm.setupdtDocDate, ""), out dt)) { UserSeldtDate = ConvertDate1(dt); } else { UserSeldtDate = ConvertDate1(DateTime.Now); } List <StudentGraduationPredictData> StudentGraduationPredictDataList = new List <StudentGraduationPredictData>(); // 取得學生ID,製作 Dict 用 List <string> StudIDList = (from data in _students select data.ID).ToList(); // Student Address,Key:StudentID Dictionary <string, JHAddressRecord> AddressDict = new Dictionary <string, JHAddressRecord>(); // Student Parent,Key:StudentID Dictionary <string, JHParentRecord> ParentDict = new Dictionary <string, JHParentRecord>(); // 地址 foreach (JHAddressRecord rec in JHAddress.SelectByStudentIDs(StudIDList)) { if (!AddressDict.ContainsKey(rec.RefStudentID)) { AddressDict.Add(rec.RefStudentID, rec); } } // 父母監護人 foreach (JHParentRecord rec in JHParent.SelectByStudentIDs(StudIDList)) { if (!ParentDict.ContainsKey(rec.RefStudentID)) { ParentDict.Add(rec.RefStudentID, rec); } } // 資料轉換 .. foreach (StudentRecord StudRec in _students) { if (!_result.ContainsKey(StudRec.ID)) { continue; } //處理年級為0的資料 List <ResultDetail> zeroGrades = new List <ResultDetail>(); StudentGraduationPredictData sgpd = new StudentGraduationPredictData(); if (StudRec.Class != null) { sgpd.ClassName = StudRec.Class.Name; } sgpd.Name = StudRec.Name; sgpd.SchoolAddress = K12.Data.School.Address; sgpd.SchoolName = K12.Data.School.ChineseName; sgpd.SchoolPhone = K12.Data.School.Telephone; sgpd.SeatNo = StudRec.SeatNo; sgpd.StudentNumber = StudRec.StudentNumber; // 文字 if (_result.ContainsKey(StudRec.ID)) { int GrYear; foreach (ResultDetail rd in _result[StudRec.ID]) { if (int.TryParse(rd.GradeYear, out GrYear)) { //if (GrYear == 0) continue; //後續處理 if (GrYear == 0) { zeroGrades.Add(rd); } // 組訊息 string Detail = ""; if (rd.Details.Count > 0) { Detail = string.Join(",", rd.Details.ToArray()); } // 一年級 if (GrYear == 1 || GrYear == 7) { if (rd.Semester.Trim() == "1") { sgpd.Text11 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text12 = Detail; } } // 二年級 if (GrYear == 2 || GrYear == 8) { if (rd.Semester.Trim() == "1") { sgpd.Text21 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text22 = Detail; } } // 三年級 if (GrYear == 3 || GrYear == 9) { if (rd.Semester.Trim() == "1") { sgpd.Text31 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text32 = Detail; } } } } } // 地址 if (AddressDict.ContainsKey(StudRec.ID)) { if (UserSelAddresseeAddress == "聯絡地址") { sgpd.AddresseeAddress = AddressDict[StudRec.ID].MailingAddress; } if (UserSelAddresseeAddress == "戶籍地址") { sgpd.AddresseeAddress = AddressDict[StudRec.ID].PermanentAddress; } } // 父母監護人 if (ParentDict.ContainsKey(StudRec.ID)) { if (UserSelAddresseeName == "父親") { sgpd.AddresseeName = ParentDict[StudRec.ID].FatherName; } if (UserSelAddresseeName == "母親") { sgpd.AddresseeName = ParentDict[StudRec.ID].MotherName; } if (UserSelAddresseeName == "監護人") { sgpd.AddresseeName = ParentDict[StudRec.ID].CustodianName; } } sgpd.DocDate = UserSeldtDate; foreach (ResultDetail rd in zeroGrades) { sgpd.Text += string.Join(",", rd.Details); } StudentGraduationPredictDataList.Add(sgpd); } // 產生Word 套印 Dictionary <string, object> FieldData = new Dictionary <string, object>(); // 班座排序 StudentGraduationPredictDataList = (from data in StudentGraduationPredictDataList orderby data.ClassName, data.SeatNo.PadLeft(3, '0') ascending select data).ToList(); foreach (StudentGraduationPredictData sgpd in StudentGraduationPredictDataList) { FieldData.Clear(); FieldData.Add("學校名稱", sgpd.SchoolName); FieldData.Add("學校電話", sgpd.SchoolPhone); FieldData.Add("學校地址", sgpd.SchoolAddress); FieldData.Add("收件人地址", sgpd.AddresseeAddress); FieldData.Add("收件人姓名", sgpd.AddresseeName); FieldData.Add("班級", sgpd.ClassName); FieldData.Add("座號", sgpd.SeatNo); FieldData.Add("姓名", sgpd.Name); FieldData.Add("學號", sgpd.StudentNumber); FieldData.Add("一上文字", sgpd.Text11); FieldData.Add("一下文字", sgpd.Text12); FieldData.Add("二上文字", sgpd.Text21); FieldData.Add("二下文字", sgpd.Text22); FieldData.Add("三上文字", sgpd.Text31); FieldData.Add("三下文字", sgpd.Text32); FieldData.Add("發文日期", sgpd.DocDate); FieldData.Add("所有說明", sgpd.Text); Aspose.Words.Document each = (Aspose.Words.Document)_template.Clone(true); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(each); // 合併 if (FieldData.Count > 0) { builder.Document.MailMerge.Execute(FieldData.Keys.ToArray(), FieldData.Values.ToArray()); } foreach (Aspose.Words.Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } // 產生學生清單 if (_UserSelExportStudentList) { _wbStudentList = new Workbook(); _wbStudentList.Worksheets[0].Cells[0, 0].PutValue("班級"); _wbStudentList.Worksheets[0].Cells[0, 1].PutValue("座號"); _wbStudentList.Worksheets[0].Cells[0, 2].PutValue("學號"); _wbStudentList.Worksheets[0].Cells[0, 3].PutValue("學生姓名"); _wbStudentList.Worksheets[0].Cells[0, 4].PutValue("收件人姓名"); _wbStudentList.Worksheets[0].Cells[0, 5].PutValue("地址"); //班級 座號 學號 學生姓名 收件人姓名 地址 int rowIdx = 1; foreach (StudentGraduationPredictData sgpd in StudentGraduationPredictDataList) { _wbStudentList.Worksheets[0].Cells[rowIdx, 0].PutValue(sgpd.ClassName); _wbStudentList.Worksheets[0].Cells[rowIdx, 1].PutValue(sgpd.SeatNo); _wbStudentList.Worksheets[0].Cells[rowIdx, 2].PutValue(sgpd.StudentNumber); _wbStudentList.Worksheets[0].Cells[rowIdx, 3].PutValue(sgpd.Name); _wbStudentList.Worksheets[0].Cells[rowIdx, 4].PutValue(sgpd.AddresseeName); _wbStudentList.Worksheets[0].Cells[rowIdx, 5].PutValue(sgpd.AddresseeAddress); rowIdx++; } _wbStudentList.Worksheets[0].AutoFitColumns(); } }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { K12.Presentation.NLDPanels.Student.AddToTemp(_overStudentList); if (e.Error != null) { MsgBox.Show("產生報表時發生錯誤。" + e.Error.Message); return; } if ("" + e.Result == "Cancel") { MotherForm.SetStatusBarMessage(""); return; } bool pdf = _rc.GetBoolean("輸出成PDF格式", false); //PDF及WORD儲存路徑 string path1 = System.Windows.Forms.Application.StartupPath + "\\Reports\\" + Global.ReportName + ".pdf"; string path2 = System.Windows.Forms.Application.StartupPath + "\\Reports\\" + Global.ReportName + ".doc"; //PDF重覆檔名判斷 int i = 1; while (File.Exists(path1)) { path1 = System.Windows.Forms.Application.StartupPath + "\\Reports\\" + Global.ReportName + i + ".pdf"; i++; } //WORD重覆檔名判斷 i = 1; while (File.Exists(path2)) { path2 = System.Windows.Forms.Application.StartupPath + "\\Reports\\" + Global.ReportName + i + ".doc"; i++; } if (pdf) { bool done = false; MotherForm.SetStatusBarMessage("轉換成 PDF 格式中..."); //ReportSaver.SaveDocument(_doc, Global.ReportName, ReportSaver.OutputType.PDF); MotherForm.SetStatusBarMessage(Global.ReportName + "產生完成"); try { _doc.Save(path1, Aspose.Words.SaveFormat.Pdf); done = true; } catch { MsgBox.Show("檔案儲存失敗"); } if (done) { if (DialogResult.OK == MessageBox.Show(path1 + "產生完成,是否立刻開啟?", "ischool", MessageBoxButtons.OKCancel)) { try { System.Diagnostics.Process.Start(path1); } catch { MsgBox.Show(path1 + " 檔案開啟失敗"); } } } } else { bool done = false; MotherForm.SetStatusBarMessage(Global.ReportName + "產生完成"); //ReportSaver.SaveDocument(_doc, Global.ReportName); try { _doc.Save(path2, Aspose.Words.SaveFormat.Doc); done = true; } catch { MsgBox.Show("檔案儲存失敗"); } if (done) { if (DialogResult.OK == MessageBox.Show(path2 + "產生完成,是否立刻開啟?", "ischool", MessageBoxButtons.OKCancel)) { try { System.Diagnostics.Process.Start(path2); } catch { MsgBox.Show(path2 + " 檔案開啟失敗"); } } } } }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List<string> globalFieldName = new List<string>(); List<object> globalFieldValue = new List<object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("列印日期"); globalFieldValue.Add(DateConvert.CDate(DateTime.Now.ToString("yyyy/MM/dd"))); globalFieldName.Add("列印時間"); globalFieldValue.Add(DateTime.Now.ToString("HH:mm:ss")); ReportConfiguration _Dylanconfig = new ReportConfiguration(Global.OneFileSave); OneFileSave = _Dylanconfig.GetBoolean("單檔儲存", false); StudentDoc = new Dictionary<string, Document>(); double total = _students.Count; double count = 0; List<string> student_ids = new List<string>(); foreach (JHStudentRecord item in _students) student_ids.Add(item.ID); #region 快取資料 //取得異動資料 Dictionary<string, List<JHUpdateRecordRecord>> updateRecordCache = new Dictionary<string, List<JHUpdateRecordRecord>>(); foreach (var record in JHUpdateRecord.SelectByStudentIDs(student_ids)) { if (!updateRecordCache.ContainsKey(record.StudentID)) updateRecordCache.Add(record.StudentID, new List<JHUpdateRecordRecord>()); updateRecordCache[record.StudentID].Add(record); } //取得缺曠獎懲資料 Dictionary<string, List<AutoSummaryRecord>> autoSummaryCache = new Dictionary<string, List<AutoSummaryRecord>>(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids, null)) { if (!autoSummaryCache.ContainsKey(record.RefStudentID)) autoSummaryCache.Add(record.RefStudentID, new List<AutoSummaryRecord>()); autoSummaryCache[record.RefStudentID].Add(record); } //取得學期歷程 Dictionary<string, JHSemesterHistoryRecord> semesterHistoryCache = new Dictionary<string, JHSemesterHistoryRecord>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { if (!semesterHistoryCache.ContainsKey(record.RefStudentID)) semesterHistoryCache.Add(record.RefStudentID, record); } //取得學期成績 Dictionary<string, List<JHSemesterScoreRecord>> semesterScoreCache = new Dictionary<string, List<JHSemesterScoreRecord>>(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids)) { if (!semesterScoreCache.ContainsKey(record.RefStudentID)) semesterScoreCache.Add(record.RefStudentID, new List<JHSemesterScoreRecord>()); semesterScoreCache[record.RefStudentID].Add(record); } // 取得畢業成績 Dictionary<string, K12.Data.GradScoreRecord> StudGradScoreDic = new Dictionary<string, GradScoreRecord>(); foreach (GradScoreRecord score in GradScore.SelectByIDs<GradScoreRecord>(student_ids)) StudGradScoreDic.Add(score.RefStudentID, score); ////課程 //JHCourse.RemoveAll(); //Dictionary<string, JHCourseRecord> courseCache = new Dictionary<string, JHCourseRecord>(); //foreach (JHCourseRecord record in JHCourse.SelectAll()) //{ // if (!courseCache.ContainsKey(record.ID)) // courseCache.Add(record.ID, record); //} #endregion #region 判斷要列印的領域科目 Dictionary<string, bool> domains = new Dictionary<string, bool>(); //Dictionary<string, List<string>> subjects = new Dictionary<string, List<string>>(); //List<JHCourseRecord> courseList = new List<JHCourseRecord>(courseCache.Values); //courseList.Sort(delegate(JHCourseRecord x, JHCourseRecord y) //{ // return JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject); //}); string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) domains.Add(domain, DomainSubjectExpand.不展開); if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) domains.Add(domain, DomainSubjectExpand.展開); if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); } else throw new Exception("請重新儲存一次列印設定"); //foreach (var domain in JHSchool.Evaluation.Subject.Domains) // subjects.Add(domain, new List<string>()); //if (!subjects.ContainsKey("")) subjects.Add("", new List<string>()); //foreach (var course in courseList) //{ // if (!subjects.ContainsKey(course.Domain)) // subjects.Add(course.Domain, new List<string>()); // if (!subjects[course.Domain].Contains(course.Subject) && // domains.ContainsKey(course.Domain) && // domains[course.Domain] == false) // { // subjects[course.Domain].Add(course.Subject); // } //} #endregion DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 節權數顯示 string pcDisplay = string.Empty; bool printPeriod = Config.GetBoolean("列印節數", true); bool printCredit = Config.GetBoolean("列印權數", false); if (printPeriod && printCredit) pcDisplay = "節權數"; else if (printPeriod) pcDisplay = "節數"; else if (printCredit) pcDisplay = "權數"; while (templateBuilder.MoveToMergeField("節權數")) templateBuilder.Write(pcDisplay); #endregion #region 文字評語是否列印 bool printText = Config.GetBoolean("列印文字評語", true); if (printText == false) { templateBuilder.MoveToMergeField("學習領域評量"); (templateBuilder.CurrentParagraph.ParentNode as Cell).ParentRow.ParentTable.Remove(); } #endregion #region 服務學習時數 Global._SLRDict.Clear(); Global._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in _students) { count++; Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 建立學期歷程對照 List<SemesterHistoryItem> semesterHistoryList = null; if (semesterHistoryCache.ContainsKey(student.ID)) semesterHistoryList = semesterHistoryCache[student.ID].SemesterHistoryItems; else semesterHistoryList = new List<SemesterHistoryItem>(); SemesterMap map = new SemesterMap(); map.SetData(semesterHistoryList); #endregion #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student, semesterHistoryList); #endregion #region 異動資料 List<JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) updateRecordList = updateRecordCache[student.ID]; else updateRecordList = new List<JHUpdateRecordRecord>(); StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(builder); updateRecordProcessor.SetData(updateRecordList); #endregion #region 日常表現 List<AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) autoSummaryList = autoSummaryCache[student.ID]; else autoSummaryList = new List<AutoSummaryRecord>(); StudentMoralProcessor moralProcessor = new StudentMoralProcessor(builder, map); moralProcessor.SetData(autoSummaryList); #endregion #region 學期歷程 StudentHistoryProcessor history = new StudentHistoryProcessor(builder, map, (semesterHistoryCache.ContainsKey(student.ID) ? semesterHistoryCache[student.ID] : null)); #endregion #region 學期成績 List<JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) semesterScoreList = semesterScoreCache[student.ID]; else semesterScoreList = new List<JHSemesterScoreRecord>(); // 畢業成績 K12.Data.GradScoreRecord StudGradScore = new GradScoreRecord(); if (StudGradScoreDic.ContainsKey(student.ID)) StudGradScore = StudGradScoreDic[student.ID]; StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, domainSubjectSetup, domains, StudGradScore); semesterScoreProcessor.DegreeMapper = _degreeMapper; semesterScoreProcessor.PrintPeriod = printPeriod; semesterScoreProcessor.PrintCredit = printCredit; semesterScoreProcessor.SetData(semesterScoreList); #endregion #region 學習領域評量 if (printText == true) { StudentTextProcessor text = new StudentTextProcessor(builder, map); text.SetData(semesterScoreList); } #endregion if (OneFileSave) { each.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); string fileName = ""; fileName = student.StudentNumber; if (!string.IsNullOrEmpty(student.RefClassID)) fileName += "_" + student.Class.Name; else fileName += "_"; fileName += "_" + (student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""); fileName += "_" + student.Name; if (!StudentDoc.ContainsKey(fileName)) { StudentDoc.Add(fileName, each); } } else { foreach (Section sec in each.Sections) _doc.Sections.Add(_doc.ImportNode(sec, true)); } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } if (!OneFileSave) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }