internal GradScoreRecordEditor(GradScoreRecord info) { GradScoreRecord = info; RefStudentID = info.RefStudentID; LearnDomainScore = info.LearnDomainScore; CourseLearnScore = info.CourseLearnScore; Dictionary <string, GradDomainScore> domainList = new Dictionary <string, GradDomainScore>(); foreach (var domain in info.Domains.Values) { domainList.Add(domain.Domain, domain.Clone() as GradDomainScore); } Domains = domainList; }
private void InitializeBackgroundWorker() { _worker = new BackgroundWorker(); _worker.DoWork += delegate(object sender, DoWorkEventArgs e) { GradScore.Instance.SyncDataBackground(PrimaryKey); e.Result = GradScore.Instance.Items[PrimaryKey]; }; _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (_RunningID != PrimaryKey) { _RunningID = PrimaryKey; _worker.RunWorkerAsync(_RunningID); return; } if (e.Result != null) { _record = e.Result as GradScoreRecord; FillData(); } }; }
internal static List <GradScoreRecord> GetGradScores(IEnumerable <string> primaryKeys) { DSXmlHelper helper = new DSXmlHelper("Request"); helper.AddElement("Field"); helper.AddElement("Field", "ID"); helper.AddElement("Field", "GradScore"); helper.AddElement("Condition"); foreach (var each in primaryKeys) { helper.AddElement("Condition", "ID", each); } DSResponse rsp = FISCA.Authentication.DSAServices.CallService("SmartSchool.Student.GetDetailList", new DSRequest(helper)); List <GradScoreRecord> result = new List <GradScoreRecord>(); foreach (XmlElement element in rsp.GetContent().GetElements("Student")) { GradScoreRecord record = new GradScoreRecord(element); result.Add(record); } return(result); }
public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { //SmartSchool.API.PlugIn.VirtualCheckBox filterRepeat = new SmartSchool.API.PlugIn.VirtualCheckBox("自動略過重讀成績", true); //wizard.Options.Add(filterRepeat); wizard.ExportableFields.AddRange("領域", "分數評量"); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { #region ExportPackage List <JHStudentRecord> students = JHStudent.SelectByIDs(e.List); GradScore.Instance.SyncDataBackground(e.List); foreach (JHStudentRecord stu in students) { GradScoreRecord record = GradScore.Instance.Items[stu.ID]; if (record == null) { continue; } foreach (GradDomainScore domain in record.Domains.Values) { RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "領域": row.Add(field, "" + domain.Domain); break; case "分數評量": row.Add(field, "" + domain.Score); break; } } } e.Items.Add(row); } foreach (string item in new string[] { "學習領域", "課程學習" }) { RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "領域": row.Add(field, item); break; case "分數評量": if (item == "學習領域") { row.Add("分數評量", "" + record.LearnDomainScore); } else if (item == "課程學習") { row.Add("分數評量", "" + record.CourseLearnScore); } break; } } } e.Items.Add(row); } } #endregion FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出畢業成績", "總共匯出" + e.Items.Count + "筆畢業成績。"); }; }
public static GradScoreRecordEditor GetEditor(this GradScoreRecord gradScoreRecord) { return(new GradScoreRecordEditor(gradScoreRecord)); }
public void Save() { List <GradScoreRecord> updateSemsScore = new List <GradScoreRecord>(); DomainScoreLogFormater logFormater = new DomainScoreLogFormater(); foreach (StudentScore student in Students) { GraduateScoreCollection gscore = student.GraduateScore; //畢業成績(自定 Object)。 GradScoreRecord grecord = gscore.RawScore; //畢業成績記錄(DAL)。 //如果該筆成績沒有對應的畢業成績,就新增一筆。 if (grecord == null) { grecord = new GradScoreRecord(); grecord.RefStudentID = student.Id; } #region 複製領域成績。 foreach (string strDomain in gscore) { GraduateScore gs = gscore[strDomain]; if (!grecord.Domains.ContainsKey(strDomain)) { grecord.Domains.Add(strDomain, new GradDomainScore(strDomain)); } gscore.Log.Add(new LogData(strDomain, grecord.Domains[strDomain].Score + "", gs.Value + "")); grecord.Domains[strDomain].Score = gs.Value; } foreach (LogData each in gscore.Log) { each.Formater = logFormater; } gscore.LearningLog.Formater = logFormater; gscore.LearningLog.OriginValue = grecord.LearnDomainScore + ""; gscore.LearningLog.NewValue = gscore.LearnDomainScore + ""; gscore.CourseLog.Formater = logFormater; gscore.CourseLog.OriginValue = grecord.CourseLearnScore + ""; gscore.CourseLog.NewValue = gscore.CourseLearnScore + ""; grecord.LearnDomainScore = gscore.LearnDomainScore; grecord.CourseLearnScore = gscore.CourseLearnScore; #endregion //新增到「更新」清單中。 updateSemsScore.Add(grecord); } #region 更新科目成績 FunctionSpliter <GradScoreRecord, GradScoreRecord> updateData = new FunctionSpliter <GradScoreRecord, GradScoreRecord>(300, 5); updateData.Function = delegate(List <GradScoreRecord> ps) { GradScore.Update(ps); return(new List <GradScoreRecord>()); }; updateData.ProgressChange = delegate(int progress) { Reporter.Feedback("更新畢業成績...", Util.CalculatePercentage(updateSemsScore.Count, progress)); }; updateData.Execute(updateSemsScore); #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(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 }
public static void Calculate(List <StudentRecord> students) { const string LearnDomain = "學習領域"; const string CourseLearn = "課程學習"; ScoreCalcRule.Instance.SyncAllBackground(); //SemesterScore.Instance.SyncAllBackground(); Dictionary <string, List <JHSemesterScoreRecord> > studentSemesterScoreRecordCache = new Dictionary <string, List <JHSchool.Data.JHSemesterScoreRecord> >(); foreach (JHSemesterScoreRecord record in JHSemesterScore.SelectByStudentIDs(students.AsKeyList())) { if (!studentSemesterScoreRecordCache.ContainsKey(record.RefStudentID)) { studentSemesterScoreRecordCache.Add(record.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>()); } studentSemesterScoreRecordCache[record.RefStudentID].Add(record); } List <GradScoreRecordEditor> editors = new List <GradScoreRecordEditor>(); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; MultiThreadBackgroundWorker <GradScoreRecordEditor> multiWorker = new MultiThreadBackgroundWorker <GradScoreRecordEditor>(); multiWorker.WorkerReportsProgress = true; multiWorker.AutoReportsProgress = true; multiWorker.PackageSize = 50; multiWorker.Loading = MultiThreadLoading.Light; worker.DoWork += delegate { Dictionary <string, ScoreCalculator> calc = new Dictionary <string, ScoreCalculator>(); double studentTotal = students.Count; double studentCount = 0; foreach (StudentRecord student in students) { studentCount++; #region 取得成績計算規則 string calcID = string.Empty; ScoreCalcRuleRecord calcRecord = student.GetScoreCalcRuleRecord(); if (calcRecord != null) { calcID = calcRecord.ID; if (!calc.ContainsKey(calcID)) { JHScoreCalcRuleRecord record = null; List <JHScoreCalcRuleRecord> list = JHScoreCalcRule.SelectByIDs(new string[] { calcRecord.ID }); if (list.Count > 0) { record = list[0]; } calc.Add(calcID, new ScoreCalculator(record)); } } else { if (!calc.ContainsKey(string.Empty)) { calc.Add(string.Empty, new ScoreCalculator(null)); } } #endregion #region 取得各學期成績 List <JHSemesterScoreRecord> semesterScoreRecordList; if (studentSemesterScoreRecordCache.ContainsKey(student.ID)) { semesterScoreRecordList = studentSemesterScoreRecordCache[student.ID]; } else { semesterScoreRecordList = new List <JHSemesterScoreRecord>(); } Dictionary <string, List <decimal> > domainScores = new Dictionary <string, List <decimal> >(); foreach (JHSemesterScoreRecord record in semesterScoreRecordList) { foreach (K12.Data.DomainScore domain in record.Domains.Values) { if (!domainScores.ContainsKey(domain.Domain)) { domainScores.Add(domain.Domain, new List <decimal>()); } if (domain.Score.HasValue) { domainScores[domain.Domain].Add(domain.Score.Value); } } if (!domainScores.ContainsKey(LearnDomain)) { domainScores.Add(LearnDomain, new List <decimal>()); } if (record.LearnDomainScore.HasValue) { domainScores[LearnDomain].Add(record.LearnDomainScore.Value); } if (!domainScores.ContainsKey(CourseLearn)) { domainScores.Add(CourseLearn, new List <decimal>()); } if (record.CourseLearnScore.HasValue) { domainScores[CourseLearn].Add(record.CourseLearnScore.Value); } } #endregion #region 產生畢業成績資料 GradScoreRecordEditor editor; GradScoreRecord gradScoreRecord = GradScore.Instance.Items[student.ID]; if (gradScoreRecord != null) { editor = gradScoreRecord.GetEditor(); } else { editor = new GradScoreRecordEditor(student); } editor.LearnDomainScore = null; editor.CourseLearnScore = null; editor.Domains.Clear(); foreach (string domain in domainScores.Keys) { decimal total = 0; decimal count = domainScores[domain].Count; if (count <= 0) { continue; } foreach (decimal score in domainScores[domain]) { total += score; } total = total / count; total = calc[calcID].ParseGraduateScore(total); if (domain == LearnDomain) { editor.LearnDomainScore = total; } else if (domain == CourseLearn) { editor.CourseLearnScore = total; } else { if (!editor.Domains.ContainsKey(domain)) { editor.Domains.Add(domain, new GradDomainScore(domain)); } editor.Domains[domain].Score = total; } } editors.Add(editor); #endregion worker.ReportProgress((int)(studentCount * 100 / studentTotal)); } }; worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) { FISCA.Presentation.MotherForm.SetStatusBarMessage("計算畢業成績中", e.ProgressPercentage); }; worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MsgBox.Show("計算畢業成績時發生錯誤。" + e.Error.Message); editors.Clear(); } else { multiWorker.RunWorkerAsync(editors); } }; multiWorker.DoWork += delegate(object sender, PackageDoWorkEventArgs <GradScoreRecordEditor> e) { IEnumerable <GradScoreRecordEditor> list = e.Items; list.SaveAllEditors(); }; multiWorker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) { FISCA.Presentation.MotherForm.SetStatusBarMessage("上傳畢業成績中", e.ProgressPercentage); }; multiWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MsgBox.Show("上傳畢業成績時發生錯誤。" + e.Error.Message); } else { FISCA.Presentation.MotherForm.SetStatusBarMessage("上傳畢業成績完成"); } }; worker.RunWorkerAsync(); }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { Dictionary <string, int> _ID_SchoolYear_Semester_GradeYear = new Dictionary <string, int>(); Dictionary <string, List <string> > _ID_SchoolYear_Semester_Subject = new Dictionary <string, List <string> >(); Dictionary <string, JHStudentRecord> _StudentCollection = new Dictionary <string, JHStudentRecord>(); Dictionary <JHStudentRecord, Dictionary <int, decimal> > _StudentPassScore = new Dictionary <JHStudentRecord, Dictionary <int, decimal> >(); wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange("領域", "分數評量"); wizard.RequiredFields.AddRange("領域", "分數評量"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { #region ValidateStart _ID_SchoolYear_Semester_GradeYear.Clear(); _ID_SchoolYear_Semester_Subject.Clear(); _StudentCollection.Clear(); List <JHStudentRecord> list = JHStudent.SelectByIDs(e.List); MultiThreadWorker <JHStudentRecord> loader = new MultiThreadWorker <JHStudentRecord>(); loader.MaxThreads = 3; loader.PackageSize = 250; loader.PackageWorker += delegate(object sender1, PackageWorkEventArgs <JHStudentRecord> e1) { GradScore.Instance.SyncDataBackground(e.List); }; loader.Run(list); foreach (JHStudentRecord stu in list) { if (!_StudentCollection.ContainsKey(stu.ID)) { _StudentCollection.Add(stu.ID, stu); } } #endregion }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { #region ValidateRow int t; decimal d; JHStudentRecord student; if (_StudentCollection.ContainsKey(e.Data.ID)) { student = _StudentCollection[e.Data.ID]; } else { e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID; return; } bool inputFormatPass = true; #region 驗各欄位填寫格式 foreach (string field in e.SelectFields) { string value = e.Data[field]; switch (field) { default: break; case "領域": //if (value == "") //{ // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須填寫"); //} //else if (!Domains.Contains(value)) //{ // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須為七大領域、學習領域、課程學習"); //} break; case "分數評量": if (value != "" && !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; } } #endregion //輸入格式正確才會針對情節做檢驗 if (inputFormatPass) { string errorMessage = ""; string key = e.Data.ID; string skey = e.Data["領域"]; if (!_ID_SchoolYear_Semester_Subject.ContainsKey(key)) { _ID_SchoolYear_Semester_Subject.Add(key, new List <string>()); } if (_ID_SchoolYear_Semester_Subject[key].Contains(skey)) { errorMessage += (errorMessage == "" ? "" : "\n") + "同一學生不允許多筆相同畢業領域的資料"; } else { _ID_SchoolYear_Semester_Subject[key].Add(skey); } e.ErrorMessage = errorMessage; } #endregion }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { #region ImportPackage Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); #region 分包裝 foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } #endregion Dictionary <string, GradScoreRecordEditor> gradDict = new Dictionary <string, GradScoreRecordEditor>(); //交叉比對各學生資料 #region 交叉比對各學生資料 foreach (string id in id_Rows.Keys) { JHStudentRecord studentRec = _StudentCollection[id]; GradScoreRecord record = GradScore.Instance.Items[studentRec.ID]; GradScoreRecordEditor editor = null; if (record != null) { editor = record.GetEditor(); } else { editor = new GradScoreRecordEditor(Student.Instance.Items[studentRec.ID]); } if (!gradDict.ContainsKey(studentRec.ID)) { gradDict.Add(studentRec.ID, editor); } //要匯入的學期科目成績 Dictionary <string, RowData> importScoreDictionary = new Dictionary <string, RowData>(); #region 整理要匯入的資料 foreach (RowData row in id_Rows[id]) { int t; string domain = row["領域"]; if (!importScoreDictionary.ContainsKey(domain)) { importScoreDictionary.Add(domain, row); } } #endregion //開始處理ImportScore foreach (string domain in importScoreDictionary.Keys) { RowData data = importScoreDictionary[domain]; if (domain == "學習領域") { decimal d; if (decimal.TryParse(data["分數評量"], out d)) { editor.LearnDomainScore = d; } else { editor.LearnDomainScore = null; } } else if (domain == "課程學習") { decimal d; if (decimal.TryParse(data["分數評量"], out d)) { editor.CourseLearnScore = d; } else { editor.CourseLearnScore = null; } } else { if (!editor.Domains.ContainsKey(domain)) { editor.Domains.Add(domain, new GradDomainScore(domain)); } decimal d; if (decimal.TryParse(data["分數評量"], out d)) { editor.Domains[domain].Score = d; } else { editor.Domains[domain].Score = null; } } } } #endregion if (gradDict.Values.Count > 0) { #region 分批次兩路上傳 List <List <GradScoreRecordEditor> > updatePackages = new List <List <GradScoreRecordEditor> >(); List <List <GradScoreRecordEditor> > updatePackages2 = new List <List <GradScoreRecordEditor> >(); { List <GradScoreRecordEditor> package = null; int count = 0; foreach (GradScoreRecordEditor var in gradDict.Values) { if (count == 0) { package = new List <GradScoreRecordEditor>(30); count = 30; if ((updatePackages.Count & 1) == 0) { updatePackages.Add(package); } else { updatePackages2.Add(package); } } package.Add(var); count--; } } Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(updateSemesterSubjectScore)); threadUpdateSemesterSubjectScore.IsBackground = true; threadUpdateSemesterSubjectScore.Start(updatePackages); Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(updateSemesterSubjectScore)); threadUpdateSemesterSubjectScore2.IsBackground = true; threadUpdateSemesterSubjectScore2.Start(updatePackages2); threadUpdateSemesterSubjectScore.Join(); threadUpdateSemesterSubjectScore2.Join(); #endregion } FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入畢業成績", "總共匯入" + gradDict.Values.Count + "筆畢業成績。"); #endregion }; wizard.ImportComplete += delegate { //EventHub.Instance.InvokScoreChanged(new List<string>(_StudentCollection.Keys).ToArray()); }; }