public QuickInputSemesterScoreForm(JHStudentRecord student) : this() { _student = student; JHScoreCalcRuleRecord record = student.ScoreCalcRule; _calculator = new ScoreCalculator(record); _util = new SemesterHistoryUtility(JHSemesterHistory.SelectByStudentID(student.ID)); _semesterScoreRecordList = JHSemesterScore.SelectByStudentID(_student.ID); errorProvider.SetError(cboSchoolYear, "無效的學年度"); errorProvider.SetError(cboSemester, "無效的學期"); }
/// <summary> /// 取得學生學期歷程 /// </summary> /// <returns></returns> private Dictionary <string, HistoryUtil> GetStudentHistories() { Dictionary <string, HistoryUtil> utils = new Dictionary <string, HistoryUtil>(); foreach (JHSemesterHistoryRecord history in JHSemesterHistory.SelectByStudentIDs(AllStudentID)) { if (!utils.ContainsKey(history.RefStudentID)) { utils.Add(history.RefStudentID, new HistoryUtil(history)); } } return(utils); }
//覆寫 public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { wizard.ExportableFields.AddRange("學年度", "學期", "年級", "當時班級", "當時座號", "當時班導師姓名", "上課天數"); wizard.ExportPackage += (sender, e) => { //取得學生清單 List <JHSemesterHistoryRecord> records = JHSemesterHistory.SelectByStudentIDs(e.List); foreach (JHSemesterHistoryRecord record in records) { foreach (K12.Data.SemesterHistoryItem Item in record.SemesterHistoryItems) { RowData row = new RowData(); row.ID = record.RefStudentID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "學年度": row.Add(field, "" + Item.SchoolYear); break; case "學期": row.Add(field, "" + Item.Semester); break; case "年級": row.Add(field, "" + Item.GradeYear); break; case "當時班級": row.Add(field, "" + Item.ClassName); break; case "當時座號": row.Add(field, "" + Item.SeatNo); break; case "當時班導師姓名": row.Add(field, "" + Item.Teacher); break; case "上課天數": row.Add(field, "" + Item.SchoolDayCount); break; } } } e.Items.Add(row); } } }; }
protected override void PrepareDataBackground() { JHClass.RemoveAll(); RatingStudent.SetClassMapping(JHClass.SelectAll()); //快取班級對照資訊。 Dictionary <string, RatingStudent> dicstuds = Students.ToDictionary(); //學期歷程查詢類別。 SemesterHistory = new HistoryQuery(JHSemesterHistory.SelectByStudentIDs(Students.ToKeys())); //將學生的成績清除。 foreach (RatingStudent each in Students) { each.Clear(); } foreach (JHSemesterScoreRecord semsRecord in SemesterScores) { RatingStudent student; if (!dicstuds.TryGetValue(semsRecord.RefStudentID, out student)) { continue; //找不到該學生。 } ScoreCollection subjScores = null, domainScores = null; if (SemesterHistory.Contains(semsRecord.RefStudentID, semsRecord.SchoolYear, semsRecord.Semester)) { //tokne 意思是特定學期的識別字串,例如「一上」。 string token = SemesterHistory.GetToken(semsRecord.RefStudentID, semsRecord.SchoolYear, semsRecord.Semester); //不在使用者選擇的學期中,就不處理。 if (!Tokens.Contains(token)) { continue; } if (!student.Scores.Contains(ScoreType.Subject.Regulation(token))) //如果學生不包含該學期的成績,就加上該學期。 { student.Scores.Add(ScoreType.Subject.Regulation(token), new ScoreCollection()); } if (!student.Scores.Contains(ScoreType.Domain.Regulation(token))) //如果學生不包含該學期的成績,就加上該學期。 { student.Scores.Add(ScoreType.Domain.Regulation(token), new ScoreCollection()); } subjScores = student.Scores[ScoreType.Subject.Regulation(token)]; domainScores = student.Scores[ScoreType.Domain.Regulation(token)]; } else { continue; //沒有該學期的學期歷程就不處理。 } #region 科目 foreach (K12.Data.SubjectScore subjRecord in semsRecord.Subjects.Values) { if (!subjRecord.Score.HasValue) { continue; //沒有成績就不處理。 } ScoreItem subject = new ScoreItem(subjRecord.Subject, ScoreType.Subject); if (!SelectedItems.Contains(subject)) { continue; //不在處理的科目清單中。 } if (subjScores.Contains(subject.Name)) { throw new ArgumentException(string.Format("學生「{0}」在同一學期修習「{1}」科目一次以上。", student.Name, subject.Name)); } subjScores.Add(subject.Name, subjRecord.Score.Value); } #endregion #region 領域 foreach (K12.Data.DomainScore domainRecord in semsRecord.Domains.Values) { if (!domainRecord.Score.HasValue) { continue; //沒有成績就不處理。 } ScoreItem domain = new ScoreItem(domainRecord.Domain, ScoreType.Domain); if (!SelectedItems.Contains(domain)) { continue; //不在處理的領域清單中。 } if (domainScores.Contains(domain.Name)) { throw new ArgumentException(string.Format("學生「{0}」在{1}學年第{2}學期「{3}」領域成績出現一次以上。", student.Name, domainRecord.SchoolYear, domainRecord.Semester, domain.Name)); } domainScores.Add(domain.Name, domainRecord.Score.Value); } if (semsRecord.LearnDomainScore.HasValue) { domainScores.Add("學習領域", semsRecord.LearnDomainScore.Value); } if (semsRecord.CourseLearnScore.HasValue) { domainScores.Add("課程學習", semsRecord.CourseLearnScore.Value); } #endregion } }
void wizard_ImportPackage(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { //根據學生編號、學年度、學期組成主鍵 List <string> keyList = new List <string>(); Dictionary <string, int> schoolYearMapping = new Dictionary <string, int>(); Dictionary <string, int> semesterMapping = new Dictionary <string, int>(); Dictionary <string, string> studentIDMapping = new Dictionary <string, string>(); Dictionary <string, List <RowData> > rowsMapping = new Dictionary <string, List <RowData> >(); //一個學生只會有一筆學期歷程 Dictionary <string, JHSemesterHistoryRecord> studentSemesterHistory = new Dictionary <string, JHSemesterHistoryRecord>(); //掃描每行資料,定出資料的PrimaryKey,並且將PrimaryKey對應到的資料寫成Dictionary foreach (RowData Row in e.Items) { int schoolYear = int.Parse(Row["學年度"]); int semester = int.Parse(Row["學期"]); string studentID = Row.ID; string key = schoolYear + "^_^" + semester + "^_^" + studentID; if (!keyList.Contains(key)) { keyList.Add(key); schoolYearMapping.Add(key, schoolYear); semesterMapping.Add(key, semester); studentIDMapping.Add(key, studentID); rowsMapping.Add(key, new List <RowData>()); } rowsMapping[key].Add(Row); } //一次取得學生學期歷程 List <JHSemesterHistoryRecord> records = JHSemesterHistory.SelectByStudentIDs(studentIDMapping.Values.Distinct()); #region 將學生現有學期歷程做快取 foreach (JHSemesterHistoryRecord var in records) { studentSemesterHistory.Add(var.RefStudentID, var); } #endregion List <JHSemesterHistoryRecord> UpdateRecords = new List <JHSemesterHistoryRecord>(); foreach (string key in keyList) { JHSemesterHistoryRecord record = studentSemesterHistory[studentIDMapping[key]]; List <RowData> Rows = rowsMapping[key]; if (record != null) { for (int i = 0; i < Rows.Count; i++) { string StudentID = Rows[i].ID; string SchoolYear = Rows[i]["學年度"]; string Semester = Rows[i]["學期"]; string GradeYear = Rows[i]["年級"]; string ClassName = Rows[i].ContainsKey("當時班級")?Rows[i]["當時班級"]:string.Empty; string SeatNo = Rows[i].ContainsKey("當時座號")?Rows[i]["當時座號"]:string.Empty; string TeacherName = Rows[i].ContainsKey("當時班導師姓名")?Rows[i]["當時班導師姓名"]:string.Empty; string SchoolDayCount = Rows[i].ContainsKey("上課天數")?Rows[i]["上課天數"]:string.Empty; List <K12.Data.SemesterHistoryItem> Items = record.SemesterHistoryItems.Where(x => x.RefStudentID == StudentID && x.SchoolYear.ToString() == SchoolYear && x.Semester.ToString() == Semester).ToList(); if (Items.Count > 0) { Items[0].GradeYear = K12.Data.Int.Parse(GradeYear); if (Rows[i].ContainsKey("當時班級")) { Items[0].ClassName = ClassName; } if (Rows[i].ContainsKey("當時座號")) { Items[0].SeatNo = K12.Data.Int.ParseAllowNull(SeatNo); } if (Rows[i].ContainsKey("當時班導師姓名")) { Items[0].Teacher = TeacherName; } if (Rows[i].ContainsKey("上課天數")) { Items[0].SchoolDayCount = K12.Data.Int.ParseAllowNull(SchoolDayCount); } } else { K12.Data.SemesterHistoryItem Item = new K12.Data.SemesterHistoryItem(); Item.SchoolYear = K12.Data.Int.Parse(SchoolYear); Item.Semester = K12.Data.Int.Parse(Semester); Item.GradeYear = K12.Data.Int.Parse(GradeYear); Item.ClassName = ClassName; Item.SeatNo = K12.Data.Int.ParseAllowNull(SeatNo); Item.Teacher = TeacherName; Item.SchoolDayCount = K12.Data.Int.ParseAllowNull(SchoolDayCount); record.SemesterHistoryItems.Add(Item); } } UpdateRecords.Add(record); } else { JHSemesterHistoryRecord newrecord = new JHSemesterHistoryRecord(); newrecord.RefStudentID = Rows[0].ID; List <K12.Data.SemesterHistoryItem> Items = new List <K12.Data.SemesterHistoryItem>(); for (int i = 0; i < Rows.Count; i++) { string SchoolYear = Rows[i]["學年度"]; string Semester = Rows[i]["學期"]; string GradeYear = Rows[i].ContainsKey("年級") ? Rows[i]["年級"] : string.Empty; string ClassName = Rows[i].ContainsKey("當時班級") ? Rows[i]["當時班級"] : string.Empty; string SeatNo = Rows[i].ContainsKey("當時座號") ? Rows[i]["當時座號"] : string.Empty; string TeacherName = Rows[i].ContainsKey("當時班導師姓名") ? Rows[i]["當時班導師姓名"] : string.Empty; string SchoolDayCount = Rows[i].ContainsKey("上課天數") ? Rows[i]["上課天數"] : string.Empty; K12.Data.SemesterHistoryItem Item = new K12.Data.SemesterHistoryItem(); Item.SchoolYear = K12.Data.Int.Parse(SchoolYear); Item.Semester = K12.Data.Int.Parse(Semester); Item.GradeYear = K12.Data.Int.Parse(GradeYear); Item.ClassName = ClassName; Item.SeatNo = K12.Data.Int.ParseAllowNull(SeatNo); Item.Teacher = TeacherName; Item.SchoolDayCount = K12.Data.Int.ParseAllowNull(SchoolDayCount); Items.Add(Item); } newrecord.SemesterHistoryItems = Items; UpdateRecords.Add(newrecord); } } if (UpdateRecords.Count > 0) { JHSemesterHistory.Update(UpdateRecords); } }
public DataCache(Options options) { var student_ids = from student in options.Students select student.ID; #region 取得 AutoSummary _autoSummaryCache = new Dictionary <string, AutoSummaryRecord>(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids.ToList <string>(), null)) { if (record.SchoolYear == options.SchoolYear && record.Semester == options.Semester) { if (!_autoSummaryCache.ContainsKey(record.RefStudentID)) { _autoSummaryCache.Add(record.RefStudentID, record); } } } #endregion #region 取得 SemesterScore _semesterScoreCache = new Dictionary <string, JHSemesterScoreRecord>(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids.ToList <string>())) { if (record.SchoolYear == options.SchoolYear && record.Semester == options.Semester) { if (!_semesterScoreCache.ContainsKey(record.RefStudentID)) { _semesterScoreCache.Add(record.RefStudentID, record); } } } #endregion #region 取得 SemesterHistoryItem _historyItemCache = new Dictionary <string, K12.Data.SemesterHistoryItem>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { foreach (var item in record.SemesterHistoryItems) { if (item.SchoolYear == options.SchoolYear && item.Semester == options.Semester) { if (!_historyItemCache.ContainsKey(item.RefStudentID)) { _historyItemCache.Add(item.RefStudentID, item); } } } } #endregion if (Global.Params["Mode"] == "KaoHsiung") { #region 取得社團成績 _assnScoreCache = new Dictionary <string, AssnScore>(); FISCA.UDT.AccessHelper ah = new FISCA.UDT.AccessHelper(); string condition = string.Format("SchoolYear='{0}' and Semester='{1}'", options.SchoolYear, options.Semester); List <AssnCode> list = ah.Select <AssnCode>(condition); foreach (AssnCode record in list) { if (!_assnScoreCache.ContainsKey(record.StudentID)) { XmlElement scores = K12.Data.XmlHelper.LoadXml(record.Scores); XmlElement itemElement = (XmlElement)scores.SelectSingleNode("Item"); if (itemElement != null) { AssnScore assnScore = new AssnScore() { Score = itemElement.GetAttribute("Score"), Effort = itemElement.GetAttribute("Effort"), Text = itemElement.GetAttribute("Text") }; _assnScoreCache.Add(record.StudentID, assnScore); } } } //<Content> //<Item AssociationName="籃球社" Score="" Effort="" Text=""></Item> //</Content> #endregion } }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List <JHPeriodMappingInfo> periodList = JHPeriodMapping.SelectAll(); List <JHAbsenceMappingInfo> absenceList = JHAbsenceMapping.SelectAll(); double total = _config.Students.Count; double count = 0; List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in _config.Students) { student_ids.Add(item.ID); } #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); } } #endregion #region 取得所有科目 Dictionary <string, SubjectScore> subjectDict = new Dictionary <string, SubjectScore>(); foreach (JHSemesterScoreRecord record in JHSemesterScore.SelectByStudentIDs(student_ids)) { foreach (SubjectScore subject in record.Subjects.Values) { string key = Bind(subject.Domain, subject.Subject); if (!subjectDict.ContainsKey(key)) { subjectDict.Add(key, subject); } } } List <SubjectScore> subjectList = new List <SubjectScore>(subjectDict.Values); subjectList.Sort(delegate(SubjectScore x, SubjectScore y) { 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)); } }); #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); Dictionary <string, List <string> > subjects = new Dictionary <string, List <string> >(); if (_config.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 (_config.DomainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, 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>()); } if (!subjects.ContainsKey("")) { subjects.Add("", new List <string>()); } foreach (SubjectScore ss in subjectList) { if (!subjects.ContainsKey(ss.Domain)) { subjects.Add(ss.Domain, new List <string>()); } //很怪 if (domains.ContainsKey(ss.Domain) && domains[ss.Domain] == true) { continue; } if (!subjects[ss.Domain].Contains(ss.Subject)) { subjects[ss.Domain].Add(ss.Subject); } } _config.SetPrintDomains(domains); _config.SetPrintSubjects(subjects); #endregion #region 依節權數設定,在畫面上顯示 DocumentBuilder templateBuilder = new DocumentBuilder(_template); string pcDisplay = string.Empty; if (_config.PrintPeriod && _config.PrintCredit) { pcDisplay = "節/權數"; } else if (_config.PrintPeriod) { pcDisplay = "節數"; } else if (_config.PrintCredit) { pcDisplay = "權數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 務學習時數 Config._SLRDict.Clear(); Config._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in _config.Students) { count++; DocumentBuilder builder = null; #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 Document each = (Document)_template.Clone(true); builder = new DocumentBuilder(each); #region 基本資料 StudentBasicInfo basic = new StudentBasicInfo(); basic.SetStudent(student, semesterHistoryList); each.MailMerge.MergeField += delegate(object sender1, MergeFieldEventArgs e1) { #region 處理照片 if (e1.FieldName == "照片粘貼處") { DocumentBuilder builder1 = new DocumentBuilder(e1.Document); builder1.MoveToField(e1.Field, true); byte[] photoBytes = null; try { photoBytes = Convert.FromBase64String("" + e1.FieldValue); } catch (Exception ex) { builder1.Write("照片粘貼處"); e1.Field.Remove(); return; } if (photoBytes == null || photoBytes.Length == 0) { builder1.Write("照片粘貼處"); e1.Field.Remove(); return; } 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 * 0.9; photoShape.Width = shapeWidth * 0.9; builder1.InsertNode(photoShape); } #endregion }; //each.MailMerge.FieldMergingCallback = new InsertDocumentAtMailMergeHandler(); List <string> fieldName = new List <string>(); fieldName.AddRange(basic.GetFieldName()); List <string> fieldValue = new List <string>(); fieldValue.AddRange(basic.GetFieldValue()); each.MailMerge.Execute(fieldName.ToArray(), fieldValue.ToArray()); #endregion #region 異動資料 List <JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) { updateRecordList = updateRecordCache[student.ID]; } else { updateRecordList = new List <JHUpdateRecordRecord>(); } StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(each); updateRecordProcessor.SetData(updateRecordList); #endregion #region 成績資料 List <JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) { semesterScoreList = semesterScoreCache[student.ID]; } else { semesterScoreList = new List <JHSemesterScoreRecord>(); } StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, _config); semesterScoreProcessor.SetData(semesterScoreList); #endregion List <AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) { autoSummaryList = autoSummaryCache[student.ID]; } else { autoSummaryList = new List <AutoSummaryRecord>(); } #region 獎懲資料 StudentDisciplineProcessor disciplineProcessor = new StudentDisciplineProcessor(builder, map); disciplineProcessor.SetData(autoSummaryList); #endregion #region 缺曠資料 StudentAttendanceProcessor attendanceProcessor = new StudentAttendanceProcessor(builder, map); attendanceProcessor.SetData(autoSummaryList); #endregion #region 日常行為 StudentTextScoreProcessor textScoreProcessor = new StudentTextScoreProcessor(builder, map); textScoreProcessor.SetData(autoSummaryList); #endregion SemesterHistoryProcessor semesterHistoryProcessor = new SemesterHistoryProcessor(builder, map); 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(School.ChineseName); globalFieldName.Add("列印日期"); globalFieldValue.Add(Common.CDate(DateTime.Now.ToString("yyyy/MM/dd")) + " " + DateTime.Now.ToString("HH:mm:ss")); string chancellor, eduDirector, stuDirector; chancellor = eduDirector = stuDirector = string.Empty; XmlElement info = School.Configuration["學校資訊"].PreviousData; XmlElement chancellorElement = (XmlElement)info.SelectSingleNode("ChancellorChineseName"); XmlElement eduDirectorElement = (XmlElement)info.SelectSingleNode("EduDirectorName"); XmlElement stuDirectorElement = (XmlElement)info.SelectSingleNode("StuDirectorName"); if (chancellorElement != null) { chancellor = chancellorElement.InnerText; } if (eduDirectorElement != null) { eduDirector = eduDirectorElement.InnerText; } if (stuDirectorElement != null) { stuDirector = stuDirectorElement.InnerText; } globalFieldName.Add("教務主任"); globalFieldValue.Add(eduDirector); globalFieldName.Add("學務主任"); globalFieldValue.Add(stuDirector); globalFieldName.Add("校長"); globalFieldValue.Add(chancellor); _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); #endregion }
/// <summary> /// 儲存學習歷程項目 /// </summary> /// <param name="SemesterHistoryItemEntityList"></param> public static void SetSemesterHistoryItemEntityList(List <SemesterHistoryItemEntity> SemesterHistoryItemEntityList, List <string> StudntIDList) { Dictionary <string, JHSemesterHistoryRecord> JHSemesterHistoryRecordDic = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (JHSemesterHistoryRecord shr in JHSemesterHistory.SelectByStudentIDs(StudntIDList)) { JHSemesterHistoryRecordDic.Add(shr.RefStudentID, shr); } List <JHSemesterHistoryRecord> UpadteRecList = new List <JHSemesterHistoryRecord>(); foreach (SemesterHistoryItemEntity shie in SemesterHistoryItemEntityList) { K12.Data.SemesterHistoryItem shi = new K12.Data.SemesterHistoryItem(); shi.ClassName = shie.ClassName; shi.GradeYear = shie.GradeYear; shi.SchoolDayCount = shie.SchoolDayCount; shi.SchoolYear = shie.Schoolyear; shi.SeatNo = shie.SeatNo; shi.Semester = shie.Semester; shi.Teacher = shie.TeacherName; if (JHSemesterHistoryRecordDic.ContainsKey(shie.StudentID)) { // 完全沒學習歷程 if (shie.HasSemsterHistoryRec == false && shie.EditMode == SemesterHistoryItemEntity._EditMode.Insert) { JHSemesterHistoryRecordDic[shie.StudentID].SemesterHistoryItems.Add(shi); } // 有學習歷程 if (shie.HasSemsterHistoryRec) { K12.Data.SemesterHistoryItem rmItem = null; foreach (K12.Data.SemesterHistoryItem sh in JHSemesterHistoryRecordDic[shie.StudentID].SemesterHistoryItems) { // 檢查當有同學年度學期移除 if (sh.SchoolYear == shi.SchoolYear && sh.Semester == shi.Semester) { rmItem = sh; } } // 先移除舊的 if (rmItem != null) { JHSemesterHistoryRecordDic[shie.StudentID].SemesterHistoryItems.Remove(rmItem); } if (shie.EditMode == SemesterHistoryItemEntity._EditMode.Insert) { JHSemesterHistoryRecordDic[shie.StudentID].SemesterHistoryItems.Add(shi); } if (shie.EditMode == SemesterHistoryItemEntity._EditMode.Update) { JHSemesterHistoryRecordDic[shie.StudentID].SemesterHistoryItems.Add(shi); } if (shie.EditMode == SemesterHistoryItemEntity._EditMode.Delete) { } } UpadteRecList.Add(JHSemesterHistoryRecordDic[shie.StudentID]); } } JHSemesterHistory.Update(UpadteRecList); }
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 _historyWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progressBar.Value = 100; if (e.Error != null) { MsgBox.Show("檢查學期歷程時發生錯誤。" + e.Error.Message); return; } if (_errorList.Count > 0) { btnExit.Enabled = true; JHSchool.Evaluation.Calculation_for_JHEvaluation.ScoreCalculation.ErrorViewer viewer = new JHSchool.Evaluation.Calculation_for_JHEvaluation.ScoreCalculation.ErrorViewer(); viewer.SetHeader("學生"); foreach (StudentRecord student in _errorList) { viewer.SetMessage(student, new List <string>(new string[] { "學期歷程不完整" })); } viewer.ShowDialog(); pic_loading.Visible = false; return; } else { // 加入這段主要在處理當學期還沒有產生學期歷程,資料可以判斷 UIConfig._StudentSHistoryRecDict.Clear(); Dictionary <string, int> studGradeYearDict = new Dictionary <string, int>(); // 取得學生ID List <string> studIDs = (from data in _students select data.ID).Distinct().ToList(); foreach (JHStudentRecord stud in JHStudent.SelectByIDs(studIDs)) { if (stud.Class != null) { if (stud.Class.GradeYear.HasValue) { if (!studGradeYearDict.ContainsKey(stud.ID)) { studGradeYearDict.Add(stud.ID, stud.Class.GradeYear.Value); } } } } bool checkInsShi = false; // 取得學生學期歷程,並加入學生學習歷程Cache foreach (JHSemesterHistoryRecord rec in JHSemesterHistory.SelectByStudentIDs(studIDs)) { checkInsShi = true; K12.Data.SemesterHistoryItem shi = new K12.Data.SemesterHistoryItem(); shi.SchoolYear = UIConfig._UserSetSHSchoolYear; shi.Semester = UIConfig._UserSetSHSemester; if (studGradeYearDict.ContainsKey(rec.RefStudentID)) { shi.GradeYear = studGradeYearDict[rec.RefStudentID]; } foreach (K12.Data.SemesterHistoryItem shiItem in rec.SemesterHistoryItems) { if (shiItem.SchoolYear == shi.SchoolYear && shiItem.Semester == shi.Semester) { checkInsShi = false; } } if (checkInsShi) { rec.SemesterHistoryItems.Add(shi); } if (!UIConfig._StudentSHistoryRecDict.ContainsKey(rec.RefStudentID)) { UIConfig._StudentSHistoryRecDict.Add(rec.RefStudentID, rec); } } lblProgress.Text = "畢業資格審查中…"; FISCA.LogAgent.ApplicationLog.Log("成績系統.畢業資格審查", "畢業資格審查", "進行畢業資格審查"); _inspectWorker.RunWorkerAsync(); } }
public DataRationalityMessage Execute() { RATRecs.Clear(); // 沒成績 List <CheckStudentSemHistoryScoreRATRec> noScore = new List <CheckStudentSemHistoryScoreRATRec>(); // 沒學期歷程 List <CheckStudentSemHistoryScoreRATRec> noHistory = new List <CheckStudentSemHistoryScoreRATRec>(); // Query: 取得學生有學期成績的學年度、學期 QueryHelper Helper = new QueryHelper(); string strSQL = "select ref_student_id,school_year,semester from sems_subj_score where score_info like '%成績%' order by ref_student_id,school_year,semester"; DataTable dtScore = Helper.Select(strSQL); Dictionary <string, List <string> > studScoreScDict = new Dictionary <string, List <string> >(); Dictionary <string, List <string> > studHistoryScDict = new Dictionary <string, List <string> >(); foreach (DataRow d in dtScore.Rows) { string ID = d[0].ToString(); string val = d[1].ToString() + "," + d[2].ToString(); if (studScoreScDict.ContainsKey(ID)) { studScoreScDict[ID].Add(val); } else { List <string> strList = new List <string>(); strList.Add(val); studScoreScDict.Add(ID, strList); } } // 取得所有學生 List <JHStudentRecord> studRecList = JHStudent.SelectAll(); // 取得學生學習歷程 Dictionary <string, List <K12.Data.SemesterHistoryItem> > SHistoryDict = new Dictionary <string, List <K12.Data.SemesterHistoryItem> >(); foreach (JHSemesterHistoryRecord rec in JHSemesterHistory.SelectAll()) { foreach (K12.Data.SemesterHistoryItem shi in rec.SemesterHistoryItems) { string val = shi.SchoolYear.ToString() + "," + shi.Semester.ToString(); if (studHistoryScDict.ContainsKey(shi.RefStudentID)) { studHistoryScDict[shi.RefStudentID].Add(val); } else { List <string> strList = new List <string>(); strList.Add(val); studHistoryScDict.Add(shi.RefStudentID, strList); } } } DataRationalityMessage retMsg = new DataRationalityMessage(); try { foreach (JHStudentRecord studRec in studRecList) { // 依學期歷程為主 if (studHistoryScDict.ContainsKey(studRec.ID)) { if (studScoreScDict.ContainsKey(studRec.ID)) { foreach (string str in studHistoryScDict[studRec.ID]) { if (!studScoreScDict[studRec.ID].Contains(str)) { CheckStudentSemHistoryScoreRATRec rec1 = new CheckStudentSemHistoryScoreRATRec(); rec1.身分證號 = studRec.IDNumber; rec1.姓名 = studRec.Name; rec1.狀態 = studRec.StatusStr; if (studRec.SeatNo.HasValue) { rec1.座號 = studRec.SeatNo.Value.ToString(); } if (studRec.Class != null) { rec1.班級 = studRec.Class.Name; } rec1.說明 = "有學期歷程沒有成績"; rec1.學生系統編號 = studRec.ID; rec1.學號 = studRec.StudentNumber; string[] ss = str.Split(',').ToArray(); if (ss.Length > 1) { rec1.學年度 = ss[0]; rec1.學期 = ss[1]; } noScore.Add(rec1); } } } } // 依學期成績為主 if (studScoreScDict.ContainsKey(studRec.ID)) { if (studHistoryScDict.ContainsKey(studRec.ID)) { foreach (string str in studScoreScDict[studRec.ID]) { if (!studHistoryScDict[studRec.ID].Contains(str)) { CheckStudentSemHistoryScoreRATRec rec1 = new CheckStudentSemHistoryScoreRATRec(); rec1.身分證號 = studRec.IDNumber; rec1.姓名 = studRec.Name; rec1.狀態 = studRec.StatusStr; if (studRec.SeatNo.HasValue) { rec1.座號 = studRec.SeatNo.Value.ToString(); } if (studRec.Class != null) { rec1.班級 = studRec.Class.Name; } rec1.說明 = "沒有學期歷程有成績"; rec1.學生系統編號 = studRec.ID; rec1.學號 = studRec.StudentNumber; string[] ss = str.Split(',').ToArray(); if (ss.Length > 1) { rec1.學年度 = ss[0]; rec1.學期 = ss[1]; } noHistory.Add(rec1); } } } } } RATRecs.AddRange(noHistory); RATRecs.AddRange(noScore); int no; var sortedRATRecs = from rec in RATRecs orderby rec.狀態, rec.班級, int.TryParse(rec.座號, out no), rec.學年度, rec.學期 select rec; retMsg.Message = "有學期歷程沒有成績共" + noScore.Count + "筆,沒有學期歷程有成績共" + noHistory.Count + "筆。"; retMsg.Data = sortedRATRecs.ToList(); } catch (Exception ex) { retMsg.Message = ex.Message; return(retMsg); } return(retMsg); }
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 }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { double total = Students.Count; double count = 0; _worker.ReportProgress(0); List <string> studentIDs = Students.Select(x => x.ID).ToList(); #region 快取資料 //獎勵 // 1.依學生編號、開始日期、結束日期,取得學生獎勵紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHMeritRecord> > meritCache = new Dictionary <string, List <JHMeritRecord> >(); foreach (JHMeritRecord record in JHMerit.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null, null)) { if (!meritCache.ContainsKey(record.RefStudentID)) { meritCache.Add(record.RefStudentID, new List <JHMeritRecord>()); } meritCache[record.RefStudentID].Add(record); } //懲戒 // 1.依學生編號、開始日期、結束日期,取得學生懲戒紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHDemeritRecord> > demeritCache = new Dictionary <string, List <JHDemeritRecord> >(); foreach (JHDemeritRecord record in JHDemerit.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null, null)) { if (!demeritCache.ContainsKey(record.RefStudentID)) { demeritCache.Add(record.RefStudentID, new List <JHDemeritRecord>()); } demeritCache[record.RefStudentID].Add(record); } //缺曠 // 1.依學生編號、開始日期、結束日期,取得學生缺曠紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHAttendanceRecord> > attendanceCache = new Dictionary <string, List <JHAttendanceRecord> >(); foreach (JHAttendanceRecord record in JHAttendance.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null)) { if (!attendanceCache.ContainsKey(record.RefStudentID)) { attendanceCache.Add(record.RefStudentID, new List <JHAttendanceRecord>()); } attendanceCache[record.RefStudentID].Add(record); } // 建立平時評量與修課成績Idx Key studentID Dictionary <string, List <JHSCAttendRecord> > _studAttendRecDict = new Dictionary <string, List <JHSCAttendRecord> >(); //修課紀錄 // 1.依學生編號、學年度、學期,取得修課紀錄 // 2. List <string> courseIDs = new List <string>(); List <string> attendIDs = new List <string>(); Dictionary <string, List <string> > scCache = new Dictionary <string, List <string> >(); foreach (var attend in JHSCAttend.Select(studentIDs, null, null, "" + _config.SchoolYear, "" + _config.Semester)) { attendIDs.Add(attend.ID); if (!scCache.ContainsKey(attend.RefStudentID)) { scCache.Add(attend.RefStudentID, new List <string>()); } scCache[attend.RefStudentID].Add(attend.RefCourseID); if (!courseIDs.Contains(attend.RefCourseID)) { courseIDs.Add(attend.RefCourseID); } // 建立評量與修課成績 if (_studAttendRecDict.ContainsKey(attend.RefStudentID)) { _studAttendRecDict[attend.RefStudentID].Add(attend); } else { List <JHSCAttendRecord> atten = new List <JHSCAttendRecord>(); atten.Add(attend); _studAttendRecDict.Add(attend.RefStudentID, atten); } } //課程 // 1.依課程編號取得課程紀錄 // 2.略過不列入成績計算的課程 JHCourse.RemoveByIDs(courseIDs); Dictionary <string, JHCourseRecord> courseCache = JHCourse.SelectByIDs(courseIDs).Where(x => x.CalculationFlag != "2").ToDictionary(x => x.ID); //試別資訊: 取得所有試別 Dictionary <string, JHExamRecord> examCache = JHExam.SelectAll().ToDictionary(x => x.ID); // 取得社團ExamID List <string> NExamIDList = new List <string> (); foreach (JHExamRecord rec in JHExam.SelectAll()) { if (rec.Name.IndexOf("社團") > -1) { NExamIDList.Add(rec.ID); } } //評量成績 // 1.依修課記錄及所有試別取得評量成績 // 2.依第1點的評量成績取得試別編號 (實際學生評量成績中的試別編號) // 3.依學生編號進行分群 Dictionary <string, List <KH.JHSCETakeRecord> > sceScoreCache = new Dictionary <string, List <KH.JHSCETakeRecord> >(); List <string> validExamIDs = new List <string>(); // 檢查有修課才讀取成績 if (attendIDs.Count > 0 && examCache.Count > 0) { foreach (JHSCETakeRecord record in JHSCETake.Select(null, null, examCache.Keys, null, attendIDs)) { if (!NExamIDList.Contains(record.RefExamID)) { if (!validExamIDs.Contains(record.RefExamID)) { validExamIDs.Add(record.RefExamID); } } if (!sceScoreCache.ContainsKey(record.RefStudentID)) { sceScoreCache.Add(record.RefStudentID, new List <KH.JHSCETakeRecord>()); } sceScoreCache[record.RefStudentID].Add(new KH.JHSCETakeRecord(record)); } } //將『所有試別編號』與『實際學生評量成績中的試別編號』做交集,以取得使用管理的試別次序 //假設『所有試別編號』為1,4,3,5 //假設『實際學生評量成績中的試別編號』為3,4,1 //交集後的結果為1,4,3 validExamIDs = examCache.Keys.Intersect(validExamIDs).ToList(); validExamIDs.Add("平時評量"); //validExamIDs.Add("課程總成績"); // 取得學生成績計算規則 // 如果學生沒有計算規則一律用預設,預設進位方式取到小數點第2位 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>(); // 取得學生計算規則的ID,建立對照表 // 如果學生身上有指定成績計算規則,就以學生身上成績計算規則為主 // 如果學生身上沒有指定成績計算規則,就以學生所屬班級成績計算規則為主 foreach (JHStudentRecord student in _config.Students) { 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)); } } #endregion #region 判斷領域是否需要展開 //判斷領域是否展開對照表 //Key:領域名稱 //Value:false=展開,true=不展開 //展開: 詳列該領域下所有科目成績 //不展開: 只列該領域成績 Dictionary <string, bool> domains = new Dictionary <string, bool>(); DomainSubjectSetup domainSubjectSetup = _config.DomainSubjectSetup; //使用者設定"只列印領域" if (domainSubjectSetup == DomainSubjectSetup.Domain) { //預設從領域資料管理來的領域名稱皆不展開 foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } //彈性課程一定展開 if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } //使用者設定"只列印科目" else if (domainSubjectSetup == DomainSubjectSetup.Subject) { //預設從領域資料管理來的領域名稱皆展開 foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } //彈性課程一定展開 if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } else { throw new Exception("請重新儲存一次列印設定"); } _config.PrintDomains = domains; #endregion #region 建立節次對照 Dictionary <string, string> periodMapping = JHPeriodMapping.SelectAll().ToDictionary(x => x.Name, y => y.Type); #endregion #region 假別列表 List <string> absenceList = JHAbsenceMapping.SelectAll().Select(x => x.Name).ToList(); #endregion #region 依評量試別重新劃分範本 //如有不懂自求多福 int rowCount = 0; DocumentBuilder templateBuilder = new DocumentBuilder(_template); templateBuilder.MoveToMergeField("各次評量"); Font font = templateBuilder.Font; Cell examsCell = templateBuilder.CurrentParagraph.ParentNode as Cell; Table table = examsCell.ParentRow.ParentTable; double width = examsCell.CellFormat.Width; double examWidth = width / (double)validExamIDs.Count; double scoreWidth = width / (double)validExamIDs.Count / 2.0; //計算有幾個 Score Row foreach (Row row in table.Rows) { if (row.Cells.Count > 3) { rowCount++; } } #region Header Cell //建立評量欄位對照表 Dictionary <string, int> columnMapping = new Dictionary <string, int>(); int columnShift = 3; int columnIndex = 0; table.Rows[0].LastCell.Remove(); table.Rows[1].LastCell.Remove(); foreach (string examID in validExamIDs) { columnMapping.Add(examID, columnIndex + columnShift); Cell topHeaderCell = new Cell(_template); if (examID == "平時評量" || examID == "課程總成績") { WordHelper.Write(topHeaderCell, font, examID); } else { WordHelper.Write(topHeaderCell, font, examCache[examID].Name); } table.Rows[0].Cells.Add(topHeaderCell); Cell subHeaderCell1 = new Cell(_template); WordHelper.Write(subHeaderCell1, font, "分數", "評量"); table.Rows[1].Cells.Add(subHeaderCell1); columnIndex++; Cell subHeaderCell2 = new Cell(_template); WordHelper.Write(subHeaderCell2, font, "努力", "程度"); table.Rows[1].Cells.Add(subHeaderCell2); columnIndex++; topHeaderCell.CellFormat.Width = examWidth; subHeaderCell1.CellFormat.Width = subHeaderCell2.CellFormat.Width = scoreWidth; topHeaderCell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; subHeaderCell1.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; subHeaderCell2.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; } WordHelper.MergeVerticalCell(table.Rows[0].Cells[1], 2); #endregion #region Content Cell int shift = 2; //Header has 2 rows for (int i = 0; i < rowCount; i++) { table.Rows[i + shift].LastCell.Remove(); for (int j = 0; j < validExamIDs.Count * 2; j++) { Cell contentCell = new Cell(_template); contentCell.CellFormat.Width = scoreWidth; contentCell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; table.Rows[i + shift].Cells.Add(contentCell); } } #endregion #endregion #region 依節權數設定,在畫面上顯示 string pcDisplay = string.Empty; if (_config.PrintPeriod && _config.PrintCredit) { pcDisplay = "節/權數"; } else if (_config.PrintPeriod) { pcDisplay = "節數"; } else if (_config.PrintCredit) { pcDisplay = "權數"; } templateBuilder.MoveToMergeField("節權數"); templateBuilder.Write(pcDisplay); #endregion // 取得學期歷程 Config._StudSemesterHistoryItemDict.Clear(); List <JHSemesterHistoryRecord> semHisRec = JHSemesterHistory.SelectByStudents(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); } } } } // 取得學生服務學習時數 Config._SRDict.Clear(); List <string> sidList = (from data in Students select data.ID).ToList(); Config._SRDict = Utility.GetServiceLearningDetail(sidList, _config.SchoolYear, _config.Semester); #region 產生 foreach (JHStudentRecord student in Students) { count++; Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student); #endregion #region 各評量成績 List <KH.JHSCETakeRecord> sceScoreList = null; if (sceScoreCache.ContainsKey(student.ID)) { sceScoreList = sceScoreCache[student.ID]; } else { sceScoreList = new List <KH.JHSCETakeRecord>(); } ScoreCalculator studentCalculator = defaultScoreCalculator; if (calcIDCache.ContainsKey(student.ID) && calcCache.ContainsKey(calcIDCache[student.ID])) { studentCalculator = calcCache[calcIDCache[student.ID]]; } // 課程成績 Dictionary <string, JHSCAttendRecord> attendRecDict = new Dictionary <string, JHSCAttendRecord>(); // 領域成績(平時) Dictionary <string, decimal?> domainScDict = new Dictionary <string, decimal?>(); //// 領域成績(總) //Dictionary<string, decimal> domainScDictTT = new Dictionary<string, decimal>(); if (_studAttendRecDict.ContainsKey(student.ID)) { foreach (JHSCAttendRecord rec in _studAttendRecDict[student.ID]) { if (!attendRecDict.ContainsKey(rec.Course.Subject)) { attendRecDict.Add(rec.Course.Subject, rec); } } List <string> tName = (from xx in _studAttendRecDict[student.ID] select xx.Course.Domain).Distinct().ToList(); foreach (string Name in tName) { decimal?sc = 0, co = 0; foreach (JHSCAttendRecord rec in _studAttendRecDict[student.ID]) { if (rec.Course.Domain == Name) { if (rec.OrdinarilyScore.HasValue && rec.Course.Credit.HasValue) { sc += (rec.OrdinarilyScore.Value * rec.Course.Credit.Value); // 有成績才算入 co += rec.Course.Credit.Value; } } } if (co.HasValue && sc.HasValue) { if (co.Value > 0) { if (!domainScDict.ContainsKey(Name)) { domainScDict.Add(Name, (sc.Value / co.Value)); } } } } } //StudentExamScore examScore = new StudentExamScore(builder, _config, courseCache, attendRecDict,domainScDict,domainScDictTT); StudentExamScore examScore = new StudentExamScore(builder, _config, courseCache, attendRecDict, domainScDict); if (scCache.ContainsKey(student.ID)) { examScore.SetSubjects(scCache[student.ID]); } examScore.SetColumnMap(columnMapping); examScore.SetEffortMapper(_effortMapper); examScore.SetCalculator(studentCalculator); examScore.SetData(sceScoreList); #endregion #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)); } #region 全域 MergeField 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.ToString()); //globalFieldValue.Add(K12.Data.School.DefaultSchoolYear); globalFieldName.Add("學期"); globalFieldValue.Add(_config.Semester.ToString()); //globalFieldValue.Add(K12.Data.School.DefaultSemester); 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"); XmlElement stuDirectorElement = (XmlElement)schoolInfo.SelectSingleNode("StuDirectorName"); if (chancellorElement != null) { chancellor = chancellorElement.InnerText; } if (eduDirectorElement != null) { eduDirector = eduDirectorElement.InnerText; } if (stuDirectorElement != null) { stuDirector = stuDirectorElement.InnerText; } globalFieldName.Add("校長"); globalFieldValue.Add(chancellor); globalFieldName.Add("教務主任"); globalFieldValue.Add(eduDirector); globalFieldName.Add("學務主任"); globalFieldValue.Add(stuDirector); _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); #endregion #endregion }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { double total = Students.Count; double count = 0; _worker.ReportProgress(0); List <string> studentIDs = Students.Select(x => x.ID).ToList(); //List<string> student_ids = new List<string>(); //foreach (JHStudentRecord item in Students) // student_ids.Add(item.ID); #region 快取資料 //獎勵 // 1.依學生編號、開始日期、結束日期,取得學生獎勵紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHMeritRecord> > meritCache = new Dictionary <string, List <JHMeritRecord> >(); foreach (JHMeritRecord record in JHMerit.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null, null)) { if (!meritCache.ContainsKey(record.RefStudentID)) { meritCache.Add(record.RefStudentID, new List <JHMeritRecord>()); } meritCache[record.RefStudentID].Add(record); } //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); //} //懲戒 // 1.依學生編號、開始日期、結束日期,取得學生懲戒紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHDemeritRecord> > demeritCache = new Dictionary <string, List <JHDemeritRecord> >(); foreach (JHDemeritRecord record in JHDemerit.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null, null)) { if (!demeritCache.ContainsKey(record.RefStudentID)) { demeritCache.Add(record.RefStudentID, new List <JHDemeritRecord>()); } demeritCache[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); //} ////缺曠 //// 1.依學生編號、開始日期、結束日期,取得學生缺曠紀錄 //// 2.依學生編號進行分群 //Dictionary<string, List<JHAttendanceRecord>> attendanceCache = new Dictionary<string, List<JHAttendanceRecord>>(); //foreach (JHAttendanceRecord record in JHAttendance.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null)) //{ // if (!attendanceCache.ContainsKey(record.RefStudentID)) // attendanceCache.Add(record.RefStudentID, new List<JHAttendanceRecord>()); // attendanceCache[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> studentIDs = new List<string>(); //foreach (var stu in _config.Students) // studentIDs.Add(stu.ID); //缺曠 // 1.依學生編號、開始日期、結束日期,取得學生缺曠紀錄 // 2.依學生編號進行分群 Dictionary <string, List <JHAttendanceRecord> > attendanceCache = new Dictionary <string, List <JHAttendanceRecord> >(); foreach (JHAttendanceRecord record in JHAttendance.Select(studentIDs, _config.StartDate, _config.EndDate, null, null, null)) { if (!attendanceCache.ContainsKey(record.RefStudentID)) { attendanceCache.Add(record.RefStudentID, new List <JHAttendanceRecord>()); } attendanceCache[record.RefStudentID].Add(record); } //修課紀錄 // 1.依學生編號、學年度、學期,取得修課紀錄 // 2. List <string> courseIDs = new List <string>(); List <string> attendIDs = new List <string>(); Dictionary <string, List <string> > scCache = new Dictionary <string, List <string> >(); foreach (var attend in JHSCAttend.Select(studentIDs, null, null, "" + _config.SchoolYear, "" + _config.Semester)) { attendIDs.Add(attend.ID); if (!scCache.ContainsKey(attend.RefStudentID)) { scCache.Add(attend.RefStudentID, new List <string>()); } scCache[attend.RefStudentID].Add(attend.RefCourseID); if (!courseIDs.Contains(attend.RefCourseID)) { courseIDs.Add(attend.RefCourseID); } } //課程 // 1.依課程編號取得課程紀錄 // 2.略過不列入成績計算的課程 JHCourse.RemoveByIDs(courseIDs); Dictionary <string, JHCourseRecord> courseCache = JHCourse.SelectByIDs(courseIDs).Where(x => x.CalculationFlag != "2").ToDictionary(x => x.ID); //試別資訊: 取得所有試別 Dictionary <string, JHExamRecord> examCache = JHExam.SelectAll().ToDictionary(x => x.ID); // 取得社團ExamID List <string> NExamIDList = new List <string>(); foreach (JHExamRecord rec in JHExam.SelectAll()) { if (rec.Name.IndexOf("社團") > -1) { NExamIDList.Add(rec.ID); } } //評量成績 // 1.依修課記錄及所有試別取得評量成績 // 2.依第1點的評量成績取得試別編號 (實際學生評量成績中的試別編號) // 3.依學生編號進行分群 Dictionary <string, List <HC.JHSCETakeRecord> > sceScoreCache = new Dictionary <string, List <HC.JHSCETakeRecord> >(); List <string> validExamIDs = new List <string>(); // 檢查當有修課紀錄才取成績資料 if (attendIDs.Count > 0 && examCache.Count > 0) { foreach (JHSCETakeRecord record in JHSCETake.Select(null, null, examCache.Keys, null, attendIDs)) { if (!NExamIDList.Contains(record.RefExamID)) { if (!validExamIDs.Contains(record.RefExamID)) { validExamIDs.Add(record.RefExamID); } } if (!sceScoreCache.ContainsKey(record.RefStudentID)) { sceScoreCache.Add(record.RefStudentID, new List <HC.JHSCETakeRecord>()); } sceScoreCache[record.RefStudentID].Add(new HC.JHSCETakeRecord(record)); } } //將『所有試別編號』與『實際學生評量成績中的試別編號』做交集,以取得使用管理的試別次序 //假設『所有試別編號』為1,4,3,5 //假設『實際學生評量成績中的試別編號』為3,4,1 //交集後的結果為1,4,3 validExamIDs = examCache.Keys.Intersect(validExamIDs).ToList(); // 取得學生成績計算規則 // 如果學生沒有計算規則一律用預設,預設進位方式取到小數點第2位 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>(); // 取得學生計算規則的ID,建立對照表 // 如果學生身上有指定成績計算規則,就以學生身上成績計算規則為主 // 如果學生身上沒有指定成績計算規則,就以學生所屬班級成績計算規則為主 foreach (JHStudentRecord student in _config.Students) { 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)); } } ////修課紀錄 //// 1.依學生編號、學年度、學期,取得修課紀錄 //// 2. //List<string> courseIDs = new List<string>(); //foreach (var attend in JHSCAttend.SelectByStudentIDs(studentIDs)) //{ // if (!courseIDs.Contains(attend.RefCourseID)) // courseIDs.Add(attend.RefCourseID); //} //int schoolYear = _config.SchoolYear; //int semester = _config.Semester; //List<JHCourseRecord> courses = JHCourse.SelectByIDs(courseIDs); ////課程 //Dictionary<string, JHCourseRecord> courseCache = new Dictionary<string, JHCourseRecord>(); //foreach (JHCourseRecord record in JHCourse.SelectByIDs(courseIDs)) //{ // if ("" + record.SchoolYear != "" + schoolYear) continue; // if ("" + record.Semester != "" + semester) continue; // if (record.CalculationFlag == "2") continue; // //if (string.IsNullOrEmpty(record.Domain)) continue; //沒有填領域 // if (!courseCache.ContainsKey(record.ID)) // courseCache.Add(record.ID, record); //} ////試別資訊 //Dictionary<string, JHExamRecord> examCache = new Dictionary<string, JHExamRecord>(); //foreach (JHExamRecord exam in JHExam.SelectAll()) //{ // if (!examCache.ContainsKey(exam.ID)) // examCache.Add(exam.ID, exam); //} //List<string> validExamIDs = new List<string>(); ////評量成績 //Dictionary<string, List<HC.JHSCETakeRecord>> sceScoreCache = new Dictionary<string, List<HC.JHSCETakeRecord>>(); //foreach (JHSCETakeRecord record in JHSCETake.SelectByStudentIDs(student_ids)) //{ // if (examCache.ContainsKey(record.RefExamID)) // { // if (!validExamIDs.Contains(record.RefExamID)) // validExamIDs.Add(record.RefExamID); // } // else // continue; // if (!sceScoreCache.ContainsKey(record.RefStudentID)) // sceScoreCache.Add(record.RefStudentID, new List<HC.JHSCETakeRecord>()); // sceScoreCache[record.RefStudentID].Add(new HC.JHSCETakeRecord(record)); //} //// TODO: 這邊的排序有可能再改 //validExamIDs.Sort(delegate(string x, string y) //{ // int ix, iy; // if (!int.TryParse(x, out ix)) // ix = int.MaxValue; // if (!int.TryParse(y, out iy)) // iy = int.MaxValue; // return ix.CompareTo(iy); //}); //學期歷程 //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); // } //} #endregion #region 判斷領域是否需要展開 //判斷領域是否展開對照表 //Key:領域名稱 //Value:false=展開,true=不展開 //展開: 詳列該領域下所有科目成績 //不展開: 只列該領域成績 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); }); DomainSubjectSetup domainSubjectSetup = _config.DomainSubjectSetup; //使用者設定"只列印領域" if (domainSubjectSetup == DomainSubjectSetup.Domain) { //預設從領域資料管理來的領域名稱皆不展開 foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } if (domains.ContainsKey("語文")) { domains["語文"] = DomainSubjectExpand.展開; } //彈性課程一定展開 if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } //if (!domains.ContainsKey("彈性課程")) domains.Add("彈性課程", false); } //使用者設定"只列印科目" else if (domainSubjectSetup == DomainSubjectSetup.Subject) { //預設從領域資料管理來的領域名稱皆展開 foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } //彈性課程一定展開 if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } //if (!domains.ContainsKey("彈性課程")) domains.Add("彈性課程", false); } 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>()); //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)) // subjects[course.Domain].Add(course.Subject); //} //_config.SetPrintDomains(domains); //_config.SetPrintSubjects(subjects); _config.PrintDomains = domains; #endregion #region 建立節次對照 Dictionary <string, string> periodMapping = JHPeriodMapping.SelectAll().ToDictionary(x => x.Name, y => y.Type); //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); //} #endregion #region 假別列表 List <string> absenceList = JHAbsenceMapping.SelectAll().Select(x => x.Name).ToList(); //List<string> absenceList = new List<string>(); //foreach (JHAbsenceMappingInfo info in JHAbsenceMapping.SelectAll()) // absenceList.Add(info.Name); #endregion #region 依評量試別重新劃分範本 int rowCount = 0; DocumentBuilder templateBuilder = new DocumentBuilder(_template); templateBuilder.MoveToMergeField("各次評量"); Font font = templateBuilder.Font; Cell examsCell = templateBuilder.CurrentParagraph.ParentNode as Cell; Table table = examsCell.ParentRow.ParentTable; double width = examsCell.CellFormat.Width; double examWidth = width / (double)validExamIDs.Count; double scoreWidth = width / (double)validExamIDs.Count / 3.0; //計算有幾個 Score Row foreach (Row row in table.Rows) { if (row.Cells.Count > 3) { rowCount++; } } #region Header Cell //建立評量欄位對照表 Dictionary <string, int> columnMapping = new Dictionary <string, int>(); int columnShift = 3; int columnIndex = 0; table.Rows[0].LastCell.Remove(); table.Rows[1].LastCell.Remove(); foreach (string examID in validExamIDs) { columnMapping.Add(examID, columnIndex + columnShift); Cell topHeaderCell = new Cell(_template); WordHelper.Write(topHeaderCell, font, examCache[examID].Name); table.Rows[0].Cells.Add(topHeaderCell); Cell subHeaderCell1 = new Cell(_template); WordHelper.Write(subHeaderCell1, font, "定期", "評量"); table.Rows[1].Cells.Add(subHeaderCell1); columnIndex++; Cell subHeaderCell2 = new Cell(_template); WordHelper.Write(subHeaderCell2, font, "平時", "評量"); table.Rows[1].Cells.Add(subHeaderCell2); columnIndex++; Cell subHeaderCell3 = new Cell(_template); WordHelper.Write(subHeaderCell3, font, "總成績"); table.Rows[1].Cells.Add(subHeaderCell3); columnIndex++; topHeaderCell.CellFormat.Width = examWidth; subHeaderCell1.CellFormat.Width = scoreWidth; subHeaderCell2.CellFormat.Width = scoreWidth; subHeaderCell3.CellFormat.Width = scoreWidth; topHeaderCell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; subHeaderCell1.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; subHeaderCell2.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; subHeaderCell3.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; } WordHelper.MergeVerticalCell(table.Rows[0].Cells[1], 2); #endregion #region Content Cell int shift = 2; //Header has 2 rows for (int i = 0; i < rowCount; i++) { table.Rows[i + shift].LastCell.Remove(); for (int j = 0; j < validExamIDs.Count * 3; j++) { Cell contentCell = new Cell(_template); contentCell.CellFormat.Width = scoreWidth; contentCell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; table.Rows[i + shift].Cells.Add(contentCell); } } #endregion #endregion #region 依節權數設定,在畫面上顯示 string pcDisplay = string.Empty; if (_config.PrintPeriod && _config.PrintCredit) { pcDisplay = "節/權數"; } else if (_config.PrintPeriod) { pcDisplay = "節數"; } else if (_config.PrintCredit) { pcDisplay = "權數"; } templateBuilder.MoveToMergeField("節權數"); templateBuilder.Write(pcDisplay); #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) //{ // 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)); //} //#endregion // 取得學期歷程 Config._StudSemesterHistoryItemDict.Clear(); List <JHSemesterHistoryRecord> semHisRec = JHSemesterHistory.SelectByStudents(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); } } } } // 取得學生服務學習時數 Config._SRDict.Clear(); List <string> sidList = (from data in Students select data.ID).ToList(); Config._SRDict = Utility.GetServiceLearningDetail(sidList, _config.SchoolYear, _config.Semester); #region 產生 foreach (JHStudentRecord student in Students) { count++; 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]]; } try { StudentExamScore examScore = new StudentExamScore(builder, _config, courseCache); if (scCache.ContainsKey(student.ID)) { examScore.SetSubjects(scCache[student.ID]); } examScore.SetColumnMap(columnMapping); examScore.SetCalculator(studentCalculator); examScore.SetData(sceScoreList); } catch (Exception erro) { e.Cancel = true; } #endregion #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)); } #region 全域 MergeField List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("學年度"); //globalFieldValue.Add(K12.Data.School.DefaultSchoolYear); globalFieldValue.Add(_config.SchoolYear.ToString()); globalFieldName.Add("學期"); //globalFieldValue.Add(K12.Data.School.DefaultSemester); globalFieldValue.Add(_config.Semester.ToString()); 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"); XmlElement stuDirectorElement = (XmlElement)schoolInfo.SelectSingleNode("StuDirectorName"); if (chancellorElement != null) { chancellor = chancellorElement.InnerText; } if (eduDirectorElement != null) { eduDirector = eduDirectorElement.InnerText; } if (stuDirectorElement != null) { stuDirector = stuDirectorElement.InnerText; } globalFieldName.Add("校長"); globalFieldValue.Add(chancellor); globalFieldName.Add("教務主任"); globalFieldValue.Add(eduDirector); globalFieldName.Add("學務主任"); globalFieldValue.Add(stuDirector); _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); #endregion #endregion }
/// <summary> /// 檢查學生學期歷程 /// 改寫當學年度、學期、年級加入判斷 /// </summary> /// <param name="students"></param> /// <returns></returns> public List <StudentRecord> CheckSemesterHistories(IEnumerable <StudentRecord> students) { // 檢查是否新增學期歷程 bool chkInsertShi = false; // 取得目前學生班級年級 Dictionary <string, int> studGrYearDic = new Dictionary <string, int>(); foreach (JHStudentRecord stud in JHStudent.SelectByIDs(students.AsKeyList())) { if (stud.Class != null) { if (stud.Class.GradeYear.HasValue) { studGrYearDic.Add(stud.ID, stud.Class.GradeYear.Value); } } } // 取得學生學期歷程 Dictionary <string, JHSemesterHistoryRecord> studentSemesterHistoryRecordDict = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (JHSemesterHistoryRecord record in JHSemesterHistory.SelectByStudentIDs(students.AsKeyList())) { chkInsertShi = true; K12.Data.SemesterHistoryItem shi = new K12.Data.SemesterHistoryItem(); shi.SchoolYear = UIConfig._UserSetSHSchoolYear; shi.Semester = UIConfig._UserSetSHSemester; if (studGrYearDic.ContainsKey(record.RefStudentID)) { shi.GradeYear = studGrYearDic[record.RefStudentID]; } // 檢查是否已經有同學年度學期學期歷程 foreach (K12.Data.SemesterHistoryItem shiItem in record.SemesterHistoryItems) { if (shiItem.SchoolYear == UIConfig._UserSetSHSchoolYear && shiItem.Semester == UIConfig._UserSetSHSemester) { chkInsertShi = false; break; } } // 加入當學年度學期判斷用 if (chkInsertShi) { record.SemesterHistoryItems.Add(shi); } studentSemesterHistoryRecordDict.Add(record.RefStudentID, record); } List <StudentRecord> errorList = new List <StudentRecord>(); // 主要修改成檢查是否有學期歷程與不重複,不推測學期歷程是否合理 foreach (StudentRecord student in students) { // 當學生沒有學期歷程紀錄 if (!studentSemesterHistoryRecordDict.ContainsKey(student.ID)) { errorList.Add(student); continue; } List <string> checkSame = new List <string>(); // 有學期歷程 if (studentSemesterHistoryRecordDict.ContainsKey(student.ID)) { // 當學生有學期歷程,但是筆數是0 if (studentSemesterHistoryRecordDict[student.ID].SemesterHistoryItems.Count == 0) { errorList.Add(student); continue; } checkSame.Clear(); foreach (K12.Data.SemesterHistoryItem shi in studentSemesterHistoryRecordDict[student.ID].SemesterHistoryItems) { // 當資料有疑問 if (shi.SchoolYear < 1 || shi.Semester < 1 || shi.GradeYear < 1) { errorList.Add(student); continue; } // 檢查學期歷程是否有重複(學年度+學期+年級) string key = shi.SchoolYear.ToString() + shi.Semester.ToString() + shi.GradeYear; if (checkSame.Contains(key)) { errorList.Add(student); continue; } checkSame.Add(key); } } } return(errorList); }
protected override void PrepareDataBackground() { JHClass.RemoveAll(); RatingStudent.SetClassMapping(JHClass.SelectAll()); //快取班級對照資訊。 Dictionary <string, RatingStudent> dicstuds = Students.ToDictionary(); //學期歷程查詢類別。 SemesterHistory = new HistoryQuery(JHSemesterHistory.SelectByStudentIDs(Students.ToKeys())); //將學生的成績清除。 foreach (RatingStudent each in Students) { each.Clear(); } foreach (JHSemesterScoreRecord semsRecord in SemesterScores) { RatingStudent student; if (!dicstuds.TryGetValue(semsRecord.RefStudentID, out student)) { continue; //找不到該學生。 } ScoreCollection scores = null; if (SemesterHistory.Contains(semsRecord.RefStudentID, semsRecord.SchoolYear, semsRecord.Semester)) { //tokne 意思是特定學期的識別字串,例如「一上」。 string token = SemesterHistory.GetToken(semsRecord.RefStudentID, semsRecord.SchoolYear, semsRecord.Semester); //不在使用者選擇的學期中,就不處理。 if (!Tokens.Contains(token)) { continue; } if (!student.Scores.Contains(token)) //如果學生不包含該學期的成績,就加上該學期。 { student.Scores.Add(token, new ScoreCollection()); } scores = student.Scores[token]; } else { continue; //沒有該學期的學期歷程就不處理。 } foreach (K12.Data.SubjectScore subjRecord in semsRecord.Subjects.Values) { if (!subjRecord.Score.HasValue) { continue; //沒有成績就不處理。 } string subject = subjRecord.Subject; if (!SelectedSubjects.Contains(subject)) { continue; //不在處理的科目清單中。 } if (scores.Contains(subject)) { throw new ArgumentException(string.Format("學生「{0}」在同一學期修習「{1}」科目一次以上。", student.Name, subject)); } scores.Add(subject, subjRecord.Score.Value); } } }
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 }
/// <summary> /// 讀取學習歷程項目 /// </summary> /// <param name="SchoolYear"></param> /// <param name="Semester"></param> /// <param name="StudentIDList"></param> /// <returns></returns> public static List <SemesterHistoryItemEntity> GetSemesterHistoryItemEntityList(int SchoolYear, int Semester, List <string> StudentIDList) { Dictionary <int, int> SchoolDays = GetInSchoolDayByGardeYear(); List <SemesterHistoryItemEntity> SemesterHistoryItemEntityList = new List <SemesterHistoryItemEntity>(); Dictionary <string, JHSemesterHistoryRecord> studSemesterHistoryRecordDic = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (JHSemesterHistoryRecord shr in JHSemesterHistory.SelectByStudentIDs(StudentIDList)) { studSemesterHistoryRecordDic.Add(shr.RefStudentID, shr); } foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(StudentIDList)) { SemesterHistoryItemEntity shie = new SemesterHistoryItemEntity(); // 預設 shie.HasSemsterHistoryRec = false; shie.EditMode = SemesterHistoryItemEntity._EditMode.Insert; shie.Schoolyear = SchoolYear; shie.Semester = Semester; shie.StudentNumber = studRec.StudentNumber; shie.Name = studRec.Name; if (studSemesterHistoryRecordDic.ContainsKey(studRec.ID)) { if (studSemesterHistoryRecordDic[studRec.ID].SemesterHistoryItems.Count > 0) { shie.HasSemsterHistoryRec = true; shie.EditMode = SemesterHistoryItemEntity._EditMode.Insert; foreach (K12.Data.SemesterHistoryItem shi in studSemesterHistoryRecordDic[studRec.ID].SemesterHistoryItems) { if (shi.SchoolYear == SchoolYear && shi.Semester == Semester) { shie.EditMode = SemesterHistoryItemEntity._EditMode.Update; } } } } // 座號 if (studRec.SeatNo.HasValue) { shie.SeatNo = studRec.SeatNo.Value; } shie.StudentID = studRec.ID; if (studRec.Class != null) { if (studRec.Class.GradeYear.HasValue) { //年級 shie.GradeYear = studRec.Class.GradeYear.Value; if (SchoolDays.ContainsKey(shie.GradeYear)) { // 上課天數 shie.SchoolDayCount = SchoolDays[shie.GradeYear]; } } // 班及名稱 shie.ClassName = studRec.Class.Name; // 班導師 if (studRec.Class.Teacher != null) { shie.TeacherName = studRec.Class.Teacher.Name; } } SemesterHistoryItemEntityList.Add(shie); } return(SemesterHistoryItemEntityList); }
private void DataBuilding(object sender, DoWorkEventArgs e) { _BW.ReportProgress(0); //取得結束時間 並轉成 像是 2018/05/10 格式 String endDate = dateTimeInput1.Value.ToString("yyyy/MM/dd"); SaveSetting(); //MappingData _MappingData = new Dictionary <string, List <string> >(); foreach (DataGridViewRow row in dataGridViewX1.Rows) { if (row.Cells[0].Value != null) { string tagName = row.Cells[0].Value.ToString(); if (!_MappingData.ContainsKey(tagName)) { _MappingData.Add(tagName, new List <string>()); } if (row.Cells[1].Value != null) { string tagText = row.Cells[1].Value.ToString(); if (_Column2Items.ContainsKey(tagText)) { string tagId = _Column2Items[tagText]; if (!_MappingData[tagName].Contains(tagId)) { _MappingData[tagName].Add(tagId); } } } } } Dictionary <string, StudentObj> studentDic = new Dictionary <string, StudentObj>(); List <string> students = K12.Presentation.NLDPanels.Student.SelectedSource; string ids = string.Join("','", students); _BW.ReportProgress(10); //基本資料 DataTable dt = _Q.Select("SELECT student.id,student.name,student.id_number,class.class_name,student.seat_no,student.student_number,student.birthdate,student.contact_phone,student.sms_phone,student.mailing_address,student.permanent_address,class.grade_year FROM student LEFT JOIN class ON ref_class_id = class.id WHERE student.id IN ('" + ids + "')"); foreach (DataRow row in dt.Rows) { StudentObj obj = new StudentObj(row); if (!studentDic.ContainsKey(obj.Id)) { studentDic.Add(obj.Id, obj); } } _BW.ReportProgress(15); //基本資料-TagId dt = _Q.Select("SELECT ref_student_id,ref_tag_id FROM tag_student WHERE ref_student_id IN ('" + ids + "')"); foreach (DataRow row in dt.Rows) { string id = row["ref_student_id"].ToString(); string tagid = row["ref_tag_id"].ToString(); if (studentDic.ContainsKey(id)) { if (!studentDic[id].TagIds.Contains(tagid)) { studentDic[id].TagIds.Add(tagid); } } } _BW.ReportProgress(20); //服務學習紀錄 dt = _Q.Select("SELECT ref_student_id,hours FROM $k12.service.learning.record WHERE ref_student_id IN ('" + ids + "') AND occur_date <= '" + endDate + "' ::timestamp"); foreach (DataRow row in dt.Rows) { string id = row["ref_student_id"].ToString(); if (studentDic.ContainsKey(id)) { studentDic[id].ServiceHours += decimal.Parse(row["hours"].ToString()); } } _BW.ReportProgress(30); //幹部紀錄 dt = _Q.Select("SELECT studentid,schoolyear,semester,cadrename FROM $behavior.thecadre WHERE studentid IN ('" + ids + "')"); List <string> checkList = new List <string>(); foreach (DataRow row in dt.Rows) { string id = row["studentid"].ToString(); string schoolyear = row["schoolyear"].ToString(); string semester = row["semester"].ToString(); string cadrename = row["cadrename"].ToString(); string key = id + "_" + schoolyear + "_" + semester; if (!checkList.Contains(key)) { if (studentDic.ContainsKey(id)) { if (!cadrename.Contains("副")) { studentDic[id].CadreTimes++; checkList.Add(key); continue; } if (cadrename.Contains("副班") || cadrename.Contains("副社")) { studentDic[id].CadreTimes++; checkList.Add(key); continue; } } } } _BW.ReportProgress(40); ////獎懲紀錄 //List<AutoSummaryRecord> records = AutoSummary.Select(students, null); //foreach (AutoSummaryRecord record in records) //{ // string id = record.RefStudentID; // if (studentDic.ContainsKey(id)) // { // studentDic[id].MeritA += record.MeritA; // studentDic[id].MeritB += record.MeritB; // studentDic[id].MeritC += record.MeritC; // studentDic[id].DemeritA += record.DemeritA; // studentDic[id].DemeritB += record.DemeritB; // studentDic[id].DemeritC += record.DemeritC; // } //} // 2018/5/15 穎驊新增,自羿均那邊拿到他調整好 高中職免試入學抓取資料的SQL // 提出其中 獎懲的部分稍作調整,作為新的五專免試入學學生獎懲資料抓取方式 // 其最大的特色是,可以設定截止時間、過濾銷過紀錄、自動加總非明細資料(轉學生適用)、 // 且無論該學期有無學習歷程,只要有計獎懲一律計算,不會因為該學期休學而不計算 List <string> sidList = new List <string>(); foreach (string sid in studentDic.Keys) { sidList.Add("SELECT " + sid + "::BIGINT AS id "); } string target_student_s = String.Join(" UNION ALL ", sidList); string sql = string.Format(@"WITH target_datetime AS( SELECT '{0}'::TIMESTAMP AS end_date ) ,target_student AS( {1} ) ,target_sems_demerit AS( SELECT target_student.id ,CASE WHEN SUM(大過) IS NULL THEN 0 ELSE SUM(大過) END AS 大過支數 ,CASE WHEN SUM(小過) IS NULL THEN 0 ELSE SUM(小過) END AS 小過支數 ,CASE WHEN SUM(警告) IS NULL THEN 0 ELSE SUM(警告) END AS 警告支數 FROM target_student LEFT OUTER JOIN ( SELECT sems_moral_score.ref_student_id , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Demerit/@A'), '^$', '0') AS INTEGER) AS 大過 , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Demerit/@B'), '^$', '0') AS INTEGER) AS 小過 , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Demerit/@C'), '^$', '0') AS INTEGER) AS 警告 FROM sems_moral_score ) AS sems_demerit ON target_student.id = sems_demerit.ref_student_id GROUP BY target_student.id ) ,target_demerit AS( SELECT target_student.id ,CASE WHEN SUM(大過) IS NULL THEN 0 ELSE SUM(大過) END AS 大過支數 ,CASE WHEN SUM(小過) IS NULL THEN 0 ELSE SUM(小過) END AS 小過支數 ,CASE WHEN SUM(警告) IS NULL THEN 0 ELSE SUM(警告) END AS 警告支數 FROM target_student LEFT OUTER JOIN( SELECT discipline.ref_student_id , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@A'), '^$', '0') AS INTEGER) AS 大過 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@B'), '^$', '0') AS INTEGER) AS 小過 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@C'), '^$', '0') AS INTEGER) AS 警告 FROM target_datetime LEFT OUTER JOIN discipline ON discipline.occur_date <= target_datetime.end_date WHERE merit_flag = 0 AND xpath_string(discipline.detail,'/Discipline/Demerit/@Cleared') <> '是' AND ref_student_id IN(SELECT * FROM target_student) UNION ALL SELECT discipline.ref_student_id , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@A'), '^$', '0') AS INTEGER) AS 大過 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@B'), '^$', '0') AS INTEGER) AS 小過 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Demerit/@C'), '^$', '0') AS INTEGER) AS 警告 FROM target_datetime LEFT OUTER JOIN( SELECT * , CASE WHEN xpath_string(discipline.detail,'/Discipline/Demerit/@ClearDate') = '' THEN '1970/1/1'::TIMESTAMP ELSE xpath_string(discipline.detail,'/Discipline/Demerit/@ClearDate')::TIMESTAMP END AS cleardate FROM discipline ) discipline ON discipline.occur_date <= target_datetime.end_date WHERE merit_flag = 0 AND xpath_string(discipline.detail,'/Discipline/Demerit/@Cleared') = '是' AND discipline.cleardate > (SELECT end_date FROM target_datetime) AND ref_student_id IN(SELECT id FROM target_student) ) AS target_discipline ON target_student.id = target_discipline.ref_student_id GROUP BY target_student.id ) ,total_demerit AS( SELECT total.id , CASE WHEN SUM(大過支數) IS NULL THEN 0 ELSE SUM(大過支數) END AS 大過支數 , CASE WHEN SUM(小過支數) IS NULL THEN 0 ELSE SUM(小過支數) END AS 小過支數 , CASE WHEN SUM(警告支數) IS NULL THEN 0 ELSE SUM(警告支數) END AS 警告支數 FROM( SELECT * FROM target_demerit UNION ALL SELECT * FROM target_sems_demerit ) AS total GROUP BY total.id ) ,target_sems_merit AS( SELECT target_student.id ,CASE WHEN SUM(大功) IS NULL THEN 0 ELSE SUM(大功) END AS 大功支數 ,CASE WHEN SUM(小功) IS NULL THEN 0 ELSE SUM(小功) END AS 小功支數 ,CASE WHEN SUM(嘉獎) IS NULL THEN 0 ELSE SUM(嘉獎) END AS 嘉獎支數 FROM target_student LEFT OUTER JOIN ( SELECT sems_moral_score.ref_student_id , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Merit/@A'), '^$', '0') AS INTEGER) AS 大功 , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Merit/@B'), '^$', '0') AS INTEGER) AS 小功 , CAST( regexp_replace( xpath_string(sems_moral_score.initial_summary,'/InitialSummary/DisciplineStatistics/Merit/@C'), '^$', '0') AS INTEGER) AS 嘉獎 FROM sems_moral_score ) AS sems_merit ON target_student.id = sems_merit.ref_student_id GROUP BY target_student.id ) ,target_merit AS( SELECT ref_student_id AS id ,CASE WHEN SUM(大功) IS NULL THEN 0 ELSE SUM(大功) END AS 大功支數 ,CASE WHEN SUM(小功) IS NULL THEN 0 ELSE SUM(小功) END AS 小功支數 ,CASE WHEN SUM(嘉獎) IS NULL THEN 0 ELSE SUM(嘉獎) END AS 嘉獎支數 FROM( SELECT discipline.ref_student_id , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Merit/@A'), '^$', '0') AS INTEGER) AS 大功 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Merit/@B'), '^$', '0') AS INTEGER) AS 小功 , CAST( regexp_replace( xpath_string(discipline.detail,'/Discipline/Merit/@C'), '^$', '0') AS INTEGER) AS 嘉獎 FROM target_datetime LEFT OUTER JOIN discipline ON discipline.occur_date <= target_datetime.end_date WHERE merit_flag = 1 AND ref_student_id IN(SELECT * FROM target_student) ) AS target_discipline GROUP BY ref_student_id ) ,total_merit AS ( SELECT total.id , CASE WHEN SUM(大功支數) IS NULL THEN 0 ELSE SUM(大功支數) END AS 大功支數 , CASE WHEN SUM(小功支數) IS NULL THEN 0 ELSE SUM(小功支數) END AS 小功支數 , CASE WHEN SUM(嘉獎支數) IS NULL THEN 0 ELSE SUM(嘉獎支數) END AS 嘉獎支數 FROM( SELECT * FROM target_merit UNION ALL SELECT * FROM target_sems_merit ) AS total GROUP BY total.id ) SELECT target_student.id ,CASE WHEN total_merit.大功支數 is null THEN 0 ELSE total_merit.大功支數 END as 大功支數 ,CASE WHEN total_merit.小功支數 is null THEN 0 ELSE total_merit.小功支數 END as 小功支數 ,CASE WHEN total_merit.嘉獎支數 is null THEN 0 ELSE total_merit.嘉獎支數 END as 嘉獎支數 ,CASE WHEN total_demerit.大過支數 is null THEN 0 ELSE total_demerit.大過支數 END as 大過支數 ,CASE WHEN total_demerit.小過支數 is null THEN 0 ELSE total_demerit.小過支數 END as 小過支數 ,CASE WHEN total_demerit.警告支數 is null THEN 0 ELSE total_demerit.警告支數 END as 警告支數 FROM target_student LEFT OUTER JOIN total_demerit ON total_demerit.id = target_student.id LEFT OUTER JOIN total_merit ON total_merit.id = target_student.id " , endDate, target_student_s); QueryHelper qh = new QueryHelper(); DataTable dt_discipline = qh.Select(sql); foreach (DataRow row in dt_discipline.Rows) { string id = "" + row["id"]; if (studentDic.ContainsKey(id)) { studentDic[id].MeritA = int.Parse("" + row["大功支數"]); studentDic[id].MeritB = int.Parse("" + row["小功支數"]); studentDic[id].MeritC = int.Parse("" + row["嘉獎支數"]); studentDic[id].DemeritA = int.Parse("" + row["大過支數"]); studentDic[id].DemeritB = int.Parse("" + row["小過支數"]); studentDic[id].DemeritC = int.Parse("" + row["警告支數"]); } } _BW.ReportProgress(45); _BW.ReportProgress(50); //獎懲紀錄功過相抵 foreach (StudentObj obj in studentDic.Values) { obj.MeritDemeritTransfer(); } _BW.ReportProgress(60); //體適能 //先確認UDT存在 dt = _Q.Select("SELECT name FROM _udt_table where name='ischool_student_fitness'"); if (dt.Rows.Count > 0) { dt = _Q.Select("SELECT ref_student_id,sit_and_reach_degree, standing_long_jump_degree, sit_up_degree, cardiorespiratory_degree FROM $ischool_student_fitness WHERE ref_student_id IN ('" + ids + "')"); foreach (DataRow row in dt.Rows) { string id = row["ref_student_id"].ToString(); if (studentDic.ContainsKey(id)) { //擇優判斷 if (GetScore(row) > studentDic[id].SportFitnessScore) { studentDic[id].sit_and_reach_degree = row["sit_and_reach_degree"].ToString(); studentDic[id].sit_up_degree = row["sit_up_degree"].ToString(); studentDic[id].standing_long_jump_degree = row["standing_long_jump_degree"].ToString(); studentDic[id].cardiorespiratory_degree = row["cardiorespiratory_degree"].ToString(); } } } } _BW.ReportProgress(65); //均衡學習-年級對照 Dictionary <string, Dictionary <string, string> > SchoolyearSemesteerToGrade = new Dictionary <string, Dictionary <string, string> >(); foreach (JHSemesterHistoryRecord record in JHSemesterHistory.SelectByStudentIDs(students)) { foreach (SemesterHistoryItem item in record.SemesterHistoryItems) { if (!SchoolyearSemesteerToGrade.ContainsKey(item.RefStudentID)) { SchoolyearSemesteerToGrade.Add(item.RefStudentID, new Dictionary <string, string>()); } string key = item.SchoolYear + "_" + item.Semester; if (!SchoolyearSemesteerToGrade[item.RefStudentID].ContainsKey(key)) { if (item.Semester == 1) { SchoolyearSemesteerToGrade[item.RefStudentID].Add(key, item.GradeYear + "上"); } else if (item.Semester == 2) { SchoolyearSemesteerToGrade[item.RefStudentID].Add(key, item.GradeYear + "下"); } } } } _BW.ReportProgress(70); //均衡學習-領域分數 List <JHSemesterScoreRecord> recs = JHSemesterScore.SelectByStudentIDs(students); foreach (JHSemesterScoreRecord rec in recs) { foreach (DomainScore score in rec.Domains.Values) { string id = score.RefStudentID; string key = score.SchoolYear + "_" + score.Semester; string grade = ""; if (SchoolyearSemesteerToGrade.ContainsKey(id)) { if (SchoolyearSemesteerToGrade[id].ContainsKey(key)) { grade = SchoolyearSemesteerToGrade[id][key]; } } if (studentDic.ContainsKey(id)) { string domain = score.Domain; if ((domain == "健康與體育" || domain == "藝術與人文" || domain == "綜合活動") && !string.IsNullOrWhiteSpace(grade)) { if (!studentDic[id].DomainScores.ContainsKey(domain)) { studentDic[id].DomainScores.Add(domain, new Dictionary <string, decimal>()); } if (!studentDic[id].DomainScores[domain].ContainsKey(grade)) { decimal value = score.Score.HasValue ? score.Score.Value : 0; studentDic[id].DomainScores[domain].Add(grade, value); } } } } } _BW.ReportProgress(80); //排序 List <StudentObj> list = studentDic.Values.ToList(); list.Sort(SortStudent); int progress = 80; decimal per = (decimal)(100 - progress) / studentDic.Count; int count = 0; //Objects轉Table Dictionary <string, int> CloumnIndex = new Dictionary <string, int>(); CloumnIndex.Add("身分證字統一編號", 0); CloumnIndex.Add("學生姓名", 1); CloumnIndex.Add("出生年(民國年)", 2); CloumnIndex.Add("出生月", 3); CloumnIndex.Add("出生日", 4); CloumnIndex.Add("年級", 5); CloumnIndex.Add("班級", 6); CloumnIndex.Add("座號", 7); CloumnIndex.Add("報名資格", 8); CloumnIndex.Add("郵遞區號", 9); CloumnIndex.Add("地址", 10); CloumnIndex.Add("市內電話", 11); CloumnIndex.Add("行動電話", 12); CloumnIndex.Add("特種生加分類別", 13); CloumnIndex.Add("報名費減免身分", 14); CloumnIndex.Add("競賽", 15); CloumnIndex.Add("擔任幹部", 16); CloumnIndex.Add("服務時數", 17); CloumnIndex.Add("服務學習", 18); CloumnIndex.Add("累計嘉獎", 19); CloumnIndex.Add("累計小功", 20); CloumnIndex.Add("累計大功", 21); CloumnIndex.Add("累計警告", 22); CloumnIndex.Add("累計小過", 23); CloumnIndex.Add("累計大過", 24); CloumnIndex.Add("日常生活表現評量", 25); CloumnIndex.Add("肌耐力", 26); CloumnIndex.Add("柔軟度", 27); CloumnIndex.Add("瞬發力", 28); CloumnIndex.Add("心肺耐力", 29); CloumnIndex.Add("體適能", 30); CloumnIndex.Add("多元學習表現", 31); CloumnIndex.Add("技藝教育成績", 32); CloumnIndex.Add("技藝優良", 33); CloumnIndex.Add("弱勢身分", 34); CloumnIndex.Add("弱勢積分", 35); CloumnIndex.Add("健康與體育", 36); CloumnIndex.Add("藝術與人文", 37); CloumnIndex.Add("綜合活動", 38); CloumnIndex.Add("均衡學習", 39); CloumnIndex.Add("家長意見", 40); CloumnIndex.Add("導師意見", 41); CloumnIndex.Add("輔導教師意見", 42); CloumnIndex.Add("適性輔導", 43); CloumnIndex.Add("其他比序項目_全民英檢", 44); CloumnIndex.Add("合計", 45); CloumnIndex.Add("報名「北區」五專學校代碼", 46); CloumnIndex.Add("報名「中區」五專學校代碼", 47); CloumnIndex.Add("報名「南區」五專學校代碼", 48); CloumnIndex.Add("競賽名稱", 49); //CloumnIndex.Add("其他比序項目_多益測驗", 50); int index = 1; Workbook wb = new Workbook(new MemoryStream(Properties.Resources.Template)); Cells cs = wb.Worksheets[0].Cells; foreach (StudentObj obj in list) { cs[index, CloumnIndex["身分證字統一編號"]].PutValue(obj.IdNumber); cs[index, CloumnIndex["學生姓名"]].PutValue(obj.Name); cs[index, CloumnIndex["出生年(民國年)"]].PutValue(obj.Birth_Year.ToString().PadLeft(3, '0')); cs[index, CloumnIndex["出生月"]].PutValue(obj.Birth_Month.ToString().PadLeft(2, '0')); cs[index, CloumnIndex["出生日"]].PutValue(obj.Birth_Day.ToString().PadLeft(2, '0')); cs[index, CloumnIndex["年級"]].PutValue(obj.GradeYear); cs[index, CloumnIndex["班級"]].PutValue(obj.ClassName); cs[index, CloumnIndex["座號"]].PutValue(obj.SeatNo); cs[index, CloumnIndex["報名資格"]].PutValue(CheckTagId(obj.TagIds, 報名資格)); cs[index, CloumnIndex["郵遞區號"]].PutValue(obj.ZipCode); cs[index, CloumnIndex["地址"]].PutValue(obj.Address); cs[index, CloumnIndex["市內電話"]].PutValue(obj.Contact_Phone); cs[index, CloumnIndex["行動電話"]].PutValue(obj.SMS_Phone); cs[index, CloumnIndex["特種生加分類別"]].PutValue(CheckTagId(obj.TagIds, 特種生加分類別)); cs[index, CloumnIndex["報名費減免身分"]].PutValue(CheckTagId(obj.TagIds, 報名費減免身分)); cs[index, CloumnIndex["擔任幹部"]].PutValue(obj.CadreTimesScore); cs[index, CloumnIndex["服務時數"]].PutValue(obj.ServiceHours); cs[index, CloumnIndex["服務學習"]].PutValue(obj.ServiceLearningScore); cs[index, CloumnIndex["累計嘉獎"]].PutValue(obj.MeritC); cs[index, CloumnIndex["累計小功"]].PutValue(obj.MeritB); cs[index, CloumnIndex["累計大功"]].PutValue(obj.MeritA); cs[index, CloumnIndex["累計警告"]].PutValue(obj.DemeritC); cs[index, CloumnIndex["累計小過"]].PutValue(obj.DemeritB); cs[index, CloumnIndex["累計大過"]].PutValue(obj.DemeritA); cs[index, CloumnIndex["日常生活表現評量"]].PutValue(obj.MeritDemeritScore); cs[index, CloumnIndex["肌耐力"]].PutValue(obj.CheckScore("仰臥起坐")); cs[index, CloumnIndex["柔軟度"]].PutValue(obj.CheckScore("坐姿體前彎")); cs[index, CloumnIndex["瞬發力"]].PutValue(obj.CheckScore("立定跳遠")); cs[index, CloumnIndex["心肺耐力"]].PutValue(obj.CheckScore("心肺適能")); cs[index, CloumnIndex["體適能"]].PutValue(obj.SportFitnessScore); int x = index + 1; string formula = "=IF(P" + x + "+S" + x + "+Z" + x + "+AE" + x + ">16,16,P" + x + "+S" + x + "+Z" + x + "+AE" + x + ")"; cs[index, CloumnIndex["多元學習表現"]].Formula = formula; string[] tag = CheckTagId(obj.TagIds); cs[index, CloumnIndex["弱勢身分"]].PutValue(tag[0]); cs[index, CloumnIndex["弱勢積分"]].PutValue(tag[1]); Dictionary <string, decimal> dic = obj.GetDomainScores(); cs[index, CloumnIndex["健康與體育"]].PutValue(dic.ContainsKey("健康與體育") ? dic["健康與體育"] : 0); cs[index, CloumnIndex["藝術與人文"]].PutValue(dic.ContainsKey("藝術與人文") ? dic["藝術與人文"] : 0); cs[index, CloumnIndex["綜合活動"]].PutValue(dic.ContainsKey("綜合活動") ? dic["綜合活動"] : 0); cs[index, CloumnIndex["均衡學習"]].PutValue(obj.DomainItemScore); cs[index, CloumnIndex["其他比序項目_全民英檢"]].PutValue(CheckTagId(obj.TagIds, 其他比序項目_全民英檢)); //cs[index, CloumnIndex["其他比序項目_多益測驗"]].PutValue(CheckTagId(obj.TagIds, 其他比序項目_多益測驗)); formula = "=IF(AF" + x + "+AH" + x + "+AJ" + x + "+AN" + x + "+AR" + x + ">30,30,AF" + x + "+AH" + x + "+AJ" + x + "+AN" + x + "+AR" + x + ")"; cs[index, CloumnIndex["合計"]].Formula = formula; index++; count++; progress += (int)(count * per); _BW.ReportProgress(progress); } //wb.Worksheets[0].AutoFitColumns(); e.Result = wb; }