private List <GradScoreRecord> ReadGraduateScore() { List <string> studIds = Students.Values.ToKeys(); FunctionSpliter <string, GradScoreRecord> spliter = new FunctionSpliter <string, GradScoreRecord>(300, Util.MaxThread); spliter.Function = delegate(List <string> ps) { return(GradScore.SelectByIDs <GradScoreRecord>(ps)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取畢業成績資料...", Util.CalculatePercentage(studIds.Count, progress)); }; return(spliter.Execute(studIds)); }
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 }