public DataRationalityMessage Execute() { CanAutoCorrectStudentIDs.Clear(); LogBuilder = new StringBuilder(); LogBuilder.AppendLine("學生系統編號,身分證號,學號,班級,座號,姓名,狀態,學年度,學期,異動類別,原因及事項,異動日期,轉出後學校"); DataRationalityMessage Message = new DataRationalityMessage(); List <JHStudentRecord> Students = JHStudent.SelectAll().Where(x => x.Status == K12.Data.StudentRecord.StudentStatus.一般).ToList(); List <JHUpdateRecordRecord> UpdateRecords = JHUpdateRecord.SelectByStudentIDs(Students.Select(x => x.ID)).Where(x => x.UpdateCode.Equals("4")).ToList(); StringBuilder strBuilder = new StringBuilder(); strBuilder.AppendLine("檢查學生筆數:" + Students.Count); strBuilder.AppendLine("問題學生筆數:" + UpdateRecords.Count); if (UpdateRecords.Count > 0) { strBuilder.AppendLine("建議修正方案:"); strBuilder.AppendLine("1.將學生加入至待處理,手動變更學生的狀態為『畢業或離校』或『刪除』。"); strBuilder.AppendLine("2.運用本合理性檢查自動修正功能,將學生的狀態批次變更為『刪除』。"); strBuilder.AppendLine("3.若您運用本合理性檢查自動修正功能,建議先單選1位學生進行嘗試,確認正確變更為『刪除』狀態再進行批次作業。"); } var StudentUpdateRecords = UpdateRecords.Join(Students, UpdateRecord => UpdateRecord.StudentID, Student => Student.ID, (UpdateRecord, Student) => new { 學生系統編號 = Student.ID, 身分證號 = Student.IDNumber, 學號 = Student.StudentNumber, 班級 = Student.Class != null ? Student.Class.Name : string.Empty, 座號 = K12.Data.Int.GetString(Student.SeatNo), 姓名 = Student.Name, 狀態 = Student.StatusStr, 學年度 = K12.Data.Int.GetString(UpdateRecord.SchoolYear), 學期 = K12.Data.Int.GetString(UpdateRecord.Semester), 異動類別 = "轉出", 原因及事項 = UpdateRecord.UpdateDescription, 異動日期 = UpdateRecord.UpdateDate, 轉出後學校 = UpdateRecord.ImportExportSchool, }); foreach (var r in StudentUpdateRecords) { LogBuilder.AppendLine(r.學生系統編號 + "," + r.身分證號 + "," + r.學號 + "," + r.班級 + "," + r.座號 + "," + r.姓名 + "," + r.狀態 + "," + r.學年度 + "," + r.學期 + "," + r.異動類別 + "," + r.原因及事項 + "," + r.異動日期 + "," + r.轉出後學校); } Message.Data = StudentUpdateRecords.ToList(); Message.Message = strBuilder.ToString(); CanAutoCorrectStudentIDs.AddRange(UpdateRecords.Select(x => x.StudentID).Distinct()); return(Message); }
public static void ReadUpdateRecordDate(this IEnumerable <ReportStudent> students, IStatusReporter reporter) { int t1 = Environment.TickCount; Dictionary <string, ReportStudent> dicstudents = students.ToDictionary(); List <string> keys = students.ToSC().ToKeys(); Campus.FunctionSpliter <string, JHUpdateRecordRecord> selectData = new Campus.FunctionSpliter <string, JHUpdateRecordRecord>(500, 5); selectData.Function = delegate(List <string> ps) { return(JHUpdateRecord.SelectByStudentIDs(ps)); }; List <JHUpdateRecordRecord> updaterecords = selectData.Execute(keys); Dictionary <string, List <JHUpdateRecordRecord> > dicupdaterecords = new Dictionary <string, List <JHUpdateRecordRecord> >(); string ValidCodes = "1:2"; //新生:1 轉入:3 復學:6,畢業:2 foreach (JHUpdateRecordRecord each in updaterecords) { //不是要處理的代碼,就跳過。 if (ValidCodes.IndexOf(each.UpdateCode) < 0) { continue; } if (!dicupdaterecords.ContainsKey(each.StudentID)) { dicupdaterecords.Add(each.StudentID, new List <JHUpdateRecordRecord>()); } dicupdaterecords[each.StudentID].Add(each); } foreach (KeyValuePair <string, List <JHUpdateRecordRecord> > each in dicupdaterecords) { each.Value.Sort(delegate(JHUpdateRecordRecord x, JHUpdateRecordRecord y) { DateTime xx, yy; if (!DateTime.TryParse(x.UpdateDate, out xx)) { xx = DateTime.MinValue; } if (!DateTime.TryParse(y.UpdateDate, out yy)) { yy = DateTime.MinValue; } return(xx.CompareTo(yy)); }); } string ECodes = "1"; //入學 string GCodes = "2"; //畢業 foreach (KeyValuePair <string, List <JHUpdateRecordRecord> > each in dicupdaterecords) { if (!dicstudents.ContainsKey(each.Key)) { continue; } ReportStudent student = dicstudents[each.Key]; JHUpdateRecordRecord e = each.Value[0]; JHUpdateRecordRecord g = each.Value[each.Value.Count - 1]; if (ECodes.IndexOf(e.UpdateCode) >= 0) { DateTime dt; if (DateTime.TryParse(e.UpdateDate, out dt)) { student.EntranceDate = string.Format("{0}/{1}/{2}", dt.Year - 1911, dt.Month, dt.Day); student.EngEntranceDate = dt.ToString(Util.EnglishFormat, Util.USCulture); } } if (GCodes.IndexOf(g.UpdateCode) >= 0) { DateTime dt; if (DateTime.TryParse(g.UpdateDate, out dt)) { student.GraduateDate = string.Format("{0}/{1}/{2}", dt.Year - 1911, dt.Month, dt.Day); student.EngGraduateDate = dt.ToString(Util.EnglishFormat, Util.USCulture); } } } Console.WriteLine(Environment.TickCount - t1); }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { // 取得學生資料 Dictionary <string, JHStudentRecord> Students = new Dictionary <string, JHStudentRecord>(); // 取得異動資料 Dictionary <string, List <JHUpdateRecordRecord> > UpdateRecs = new Dictionary <string, List <JHUpdateRecordRecord> >(); wizard.PackageLimit = 3000; //wizard.ImportableFields.AddRange("學年度", "學期", "異動年級", "異動日期", "入學年月", "畢業年月", "畢修業別", "備註", "學籍核准日期", "學籍核准文號", "畢業證書字號", "異動班級", "異動姓名", "異動身分證號", "異動出生地", "異動學號", "異動性別", "異動生日", "核准日期", "核准文號", "異動類別", "畢(結)業證書字號"); //wizard.RequiredFields.AddRange("異動類別", "異動日期", "學年度", "學期"); wizard.ImportableFields.AddRange("學年度", "學期", "異動年級", "異動日期", "入學年月", "畢業年月", "畢修業別", "備註", "學籍核准日期", "學籍核准文號", "畢業證書字號", "異動班級", "異動姓名", "異動身分證號", "異動出生地", "異動學號", "異動性別", "異動生日", "核准日期", "核准文號", "畢(結)業證書字號"); wizard.RequiredFields.AddRange("異動日期", "學年度", "學期"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { Students.Clear(); UpdateRecs.Clear(); // 取得學生資料 foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(e.List)) { if (!Students.ContainsKey(studRec.ID)) { Students.Add(studRec.ID, studRec); } } foreach (string str in Students.Keys) { List <JHUpdateRecordRecord> UpdRecList = new List <JHUpdateRecordRecord>(); UpdateRecs.Add(str, UpdRecList); } // 取得異動 MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>(); loader1.MaxThreads = 3; loader1.PackageSize = 250; loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1) { foreach (JHUpdateRecordRecord UpdRec in JHUpdateRecord.SelectByStudentIDs(e.List)) { // 畢業 if (UpdRec.UpdateCode == "2") { if (UpdateRecs.ContainsKey(UpdRec.StudentID)) { UpdateRecs[UpdRec.StudentID].Add(UpdRec); } } } }; loader1.Run(e.List); }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i = 0; DateTime dt; // 檢查學生是否存在 JHStudentRecord studRec = null; if (Students.ContainsKey(e.Data.ID)) { studRec = Students[e.Data.ID]; } else { e.ErrorMessage = "沒有這位學生" + e.Data.ID; return; } // 驗證格式資料 bool InputFormatPass = true; CheckHasData = false; foreach (string field in e.SelectFields) { string value = e.Data[field].Trim(); //// 驗證$無法匯入 //if (value.IndexOf('$') > -1) //{ // e.ErrorFields.Add(field, "儲存格有$無法匯入."); // break; //} // 檢查系統內是否已經有畢業異動 if (CheckHasData == false) { if (UpdateRecs.ContainsKey(e.Data.ID)) { if (UpdateRecs[e.Data.ID].Count > 0) { e.WarningFields.Add(field, "系統內已有畢業異動,匯入將會取代系統內畢業異動"); CheckHasData = true; } } } switch (field) { default: break; //case "異動類別": // if (value != "畢業") // { // InputFormatPass &= false; // e.ErrorFields.Add(field, "必須填入畢業"); // } // if (value == "畢業") // { // if (UpdateRecs.ContainsKey(e.Data.ID)) // if (UpdateRecs[e.Data.ID].Count > 0) // { // e.WarningFields.Add(field, "系統內已有畢業異動,匯入將會取代系統內畢業異動"); // } // } // break; case "學年度": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } break; case "學期": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } if (i > 2) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數,1或2"); } break; case "異動年級": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.WarningFields.Add(field, "請填入整數"); } break; case "異動日期": if (string.IsNullOrEmpty(value) || DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } break; case "入學年月": int.TryParse(value, out i); if (!string.IsNullOrEmpty(value) && i < 1) { e.WarningFields.Add(field, "必須填入年月格式,例如200901"); } break; case "畢業年月": int.TryParse(value, out i); if (!string.IsNullOrEmpty(value) && i < 1) { e.WarningFields.Add(field, "必須填入年月格式,例如200901"); } break; case "異動生日": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "學籍核准日期": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "核准日期": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "異動性別": if (value == "男" || value == "女" || value == "") { } else { e.WarningFields.Add(field, "請填入男或女"); } break; } } }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData> ()); } id_Rows[data.ID].Add(data); } List <JHUpdateRecordRecord> InsertList = new List <JHUpdateRecordRecord>(); List <JHUpdateRecordRecord> UpdateList = new List <JHUpdateRecordRecord>(); List <JHUpdateRecordRecord> DelList = new List <JHUpdateRecordRecord>(); foreach (string id in id_Rows.Keys) { int schoolYear, Semester; string GrYear = ""; DateTime dt; foreach (RowData data in id_Rows[id]) { if (!UpdateRecs.ContainsKey(id)) { continue; } int.TryParse(data["學年度"], out schoolYear); int.TryParse(data["學期"], out Semester); DateTime.TryParse(data["異動日期"], out dt); if (data.ContainsKey("異動年級")) { GrYear = data["異動年級"]; } JHUpdateRecordRecord updateRec = null; foreach (JHUpdateRecordRecord urr in UpdateRecs[id]) { if (urr.UpdateCode == "2") { DelList.Add(urr); } //if (urr.SchoolYear == schoolYear && urr.Semester == Semester && urr.GradeYear == GrYear) //{ // DateTime dt1; // DateTime.TryParse(urr.UpdateDate, out dt1); // if (dt == dt1) // updateRec = urr; //} } bool isInsert = true; if (updateRec == null) { updateRec = new JHUpdateRecordRecord(); updateRec.StudentID = id; } else { isInsert = false; } updateRec.UpdateCode = "2"; // 當已經有畢業異動使用新增方式 if (CheckHasData) { isInsert = true; } bool checkData = false; foreach (string field in e.ImportFields) { string value = data[field].Trim(); switch (field) { //case "異動類別": // if (value == "畢業") // { // updateRec.UpdateCode = "2"; // checkData = true; // } // break; case "學年度": int scYear; if (int.TryParse(value, out scYear)) { updateRec.SchoolYear = scYear; checkData = true; } break; case "學期": int Sems; if (int.TryParse(value, out Sems)) { updateRec.Semester = Sems; checkData = true; } break; case "異動年級": updateRec.GradeYear = GrYear; break; case "異動日期": DateTime dtd; if (DateTime.TryParse(value, out dtd)) { updateRec.UpdateDate = dtd.ToShortDateString(); } break; case "入學年月": if (string.IsNullOrEmpty(value)) { updateRec.EnrollmentSchoolYear = string.Empty; } else { updateRec.EnrollmentSchoolYear = value; } break; case "畢業年月": if (string.IsNullOrEmpty(value)) { updateRec.GraduateSchoolYear = string.Empty; } else { updateRec.GraduateSchoolYear = value; } break; case "畢修業別": updateRec.Graduate = value; break; case "備註": updateRec.Comment = value; break; case "學籍核准日期": DateTime dtLD; if (DateTime.TryParse(value, out dtLD)) { updateRec.LastADDate = dtLD.ToShortDateString(); } break; case "學籍核准文號": updateRec.LastADNumber = value; break; case "畢業證書字號": updateRec.GraduateCertificateNumber = value; break; case "畢(結)業證書字號": updateRec.GraduateCertificateNumber = value; break; case "異動班級": updateRec.OriginClassName = value; break; case "異動姓名": updateRec.StudentName = value; break; case "異動身分證號": updateRec.IDNumber = value; break; case "異動出生地": updateRec.BirthPlace = value; break; case "異動學號": updateRec.StudentNumber = value; break; case "異動性別": if (value == "男" || value == "女" || value == "") { updateRec.Gender = value; } break; case "異動生日": DateTime dtb; if (DateTime.TryParse(value, out dtb)) { updateRec.Birthdate = dtb.ToShortDateString(); } break; case "核准日期": DateTime dtAd; if (DateTime.TryParse(value, out dtAd)) { updateRec.ADDate = dtAd.ToShortDateString(); } break; case "核准文號": updateRec.ADNumber = value; break; } } if (string.IsNullOrEmpty(updateRec.StudentID) || string.IsNullOrEmpty(updateRec.UpdateDate) || string.IsNullOrEmpty(updateRec.UpdateCode)) { continue; } else { if (isInsert) { InsertList.Add(updateRec); } else { UpdateList.Add(updateRec); } } } } try { // 先清空舊 if (DelList.Count > 0) { Delete(DelList); } if (InsertList.Count > 0) { Insert(InsertList); } if (UpdateList.Count > 0) { Update(UpdateList); } JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess(); prlp.SaveLog("學生.匯入異動", "匯入畢業異動", "匯入畢業異動:共新增" + InsertList.Count + "筆資料,共更新:" + UpdateList.Count + "筆資料"); JHSchool.Student.Instance.SyncAllBackground(); } catch (Exception ex) {} }; }
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 }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(School.ChineseName); globalFieldName.Add("列印時間"); globalFieldValue.Add(Global.CDate(DateTime.Now.ToString("yyyy/MM/dd")) + " " + DateTime.Now.ToString("HH:mm:ss")); ReportConfiguration _Dylanconfig = new ReportConfiguration(Global.OneFileSave); OneFileSave = _Dylanconfig.GetBoolean("單檔儲存", false); StudentDoc = new Dictionary <string, Document>(); List <JHPeriodMappingInfo> periodList = JHPeriodMapping.SelectAll(); List <JHAbsenceMappingInfo> absenceList = JHAbsenceMapping.SelectAll(); double total = Options.Students.Count; double count = 0; List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in Options.Students) { student_ids.Add(item.ID); } DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 變更節權數顯示 string pcDisplay = string.Empty; bool printPeriod = Config.GetBoolean("列印節數", false); bool printCredit = Config.GetBoolean("列印權數", false); if (printPeriod && printCredit) { pcDisplay = "節/權數"; } else if (printPeriod) { pcDisplay = "節數"; } else if (printCredit) { pcDisplay = "權數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 快取資料 // 取得學生缺曠 Dictionary <string, List <AutoSummaryRecord> > autoSummaryCache = new Dictionary <string, List <AutoSummaryRecord> >(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids, null)) { if (!autoSummaryCache.ContainsKey(record.RefStudentID)) { autoSummaryCache.Add(record.RefStudentID, new List <AutoSummaryRecord>()); } autoSummaryCache[record.RefStudentID].Add(record); } // 取得學生異動 Dictionary <string, List <JHUpdateRecordRecord> > updateRecordCache = new Dictionary <string, List <JHUpdateRecordRecord> >(); foreach (var record in JHUpdateRecord.SelectByStudentIDs(student_ids)) { if (!updateRecordCache.ContainsKey(record.StudentID)) { updateRecordCache.Add(record.StudentID, new List <JHUpdateRecordRecord>()); } updateRecordCache[record.StudentID].Add(record); } // 取得學生學期成績 Dictionary <string, List <JHSemesterScoreRecord> > semesterScoreCache = new Dictionary <string, List <JHSemesterScoreRecord> >(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids)) { if (!semesterScoreCache.ContainsKey(record.RefStudentID)) { semesterScoreCache.Add(record.RefStudentID, new List <JHSemesterScoreRecord>()); } semesterScoreCache[record.RefStudentID].Add(record); } // 取得學生學期歷程 Dictionary <string, JHSemesterHistoryRecord> semesterHistoryCache = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { if (!semesterHistoryCache.ContainsKey(record.RefStudentID)) { semesterHistoryCache.Add(record.RefStudentID, record); } } // 取得學生畢業成績 Dictionary <string, K12.Data.GradScoreRecord> StudGradScoreDic = new Dictionary <string, GradScoreRecord>(); foreach (GradScoreRecord score in GradScore.SelectByIDs <GradScoreRecord>(student_ids)) { StudGradScoreDic.Add(score.RefStudentID, score); } #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, true); } if (domains.ContainsKey("語文")) { domains["語文"] = false; } if (domains.ContainsKey("彈性課程")) { domains["彈性課程"] = false; } if (!domains.ContainsKey("")) { domains.Add("", false); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, false); } if (!domains.ContainsKey("")) { domains.Add("", false); } } else { throw new Exception("請重新儲存列印設定"); } //string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); //if (domainSubjectSetup == "Domain") //{ // foreach (var domain in JHSchool.Evaluation.Subject.Domains) // domains.Add(domain, DomainSubjectExpand.不展開); // if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); //} //else if (domainSubjectSetup == "Subject") //{ // foreach (var domain in JHSchool.Evaluation.Subject.Domains) // domains.Add(domain, DomainSubjectExpand.展開); // if (!domains.ContainsKey("")) domains.Add("", DomainSubjectExpand.展開); //} //else // throw new Exception("請重新儲存一次列印設定"); #endregion #region 務學習時數 Global._SLRDict.Clear(); Global._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in Options.Students) { count++; DocumentBuilder builder = null; Document each = (Document)_template.Clone(true); #region 建立學期歷程對照 List <SemesterHistoryItem> semesterHistoryList = null; if (semesterHistoryCache.ContainsKey(student.ID)) { semesterHistoryList = semesterHistoryCache[student.ID].SemesterHistoryItems; } else { semesterHistoryList = new List <SemesterHistoryItem>(); } SemesterMap map = new SemesterMap(); map.SetData(semesterHistoryList); #endregion #region Part1 builder = new DocumentBuilder(each); StudentBasicInfo basic = new StudentBasicInfo(); basic.SetStudent(student, semesterHistoryList); StudentSemesterHistory history = new StudentSemesterHistory(); history.SetData(semesterHistoryList); each.MailMerge.MergeField += delegate(object sender1, MergeFieldEventArgs e1) { #region 處理照片 if (e1.FieldName == "照片") { byte[] photoBytes = null; try { photoBytes = Convert.FromBase64String("" + e1.FieldValue); } catch (Exception ex) { e1.Field.Remove(); return; } if (photoBytes == null || photoBytes.Length == 0) { e1.Field.Remove(); return; } DocumentBuilder builder1 = new DocumentBuilder(e1.Document); builder1.MoveToField(e1.Field, true); e1.Field.Remove(); Shape photoShape = new Shape(e1.Document, ShapeType.Image); photoShape.ImageData.SetImage(photoBytes); photoShape.WrapType = WrapType.Inline; #region AutoResize double origHWRate = photoShape.ImageData.ImageSize.HeightPoints / photoShape.ImageData.ImageSize.WidthPoints; double shapeHeight = (builder1.CurrentParagraph.ParentNode.ParentNode as Row).RowFormat.Height * 6; double shapeWidth = (builder1.CurrentParagraph.ParentNode as Cell).CellFormat.Width; if ((shapeHeight / shapeWidth) < origHWRate) { shapeWidth = shapeHeight / origHWRate; } else { shapeHeight = shapeWidth * origHWRate; } #endregion photoShape.Height = shapeHeight; photoShape.Width = shapeWidth; builder1.InsertNode(photoShape); } #endregion }; List <string> fieldName = new List <string>(); fieldName.AddRange(basic.GetFieldName()); fieldName.AddRange(history.GetFieldName()); List <string> fieldValue = new List <string>(); fieldValue.AddRange(basic.GetFieldValue()); fieldValue.AddRange(history.GetFieldValue()); each.MailMerge.Execute(fieldName.ToArray(), fieldValue.ToArray()); builder.MoveToMergeField("異動"); List <JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) { updateRecordList = updateRecordCache[student.ID]; } else { updateRecordList = new List <JHUpdateRecordRecord>(); } StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(builder); updateRecordProcessor.SetData(updateRecordList); builder.MoveToMergeField("成績"); List <JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) { semesterScoreList = semesterScoreCache[student.ID]; } else { semesterScoreList = new List <JHSemesterScoreRecord>(); } // 學生畢業成績 K12.Data.GradScoreRecord studGradScore = new GradScoreRecord(); if (StudGradScoreDic.ContainsKey(student.ID)) { studGradScore = StudGradScoreDic[student.ID]; } StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, domainSubjectSetup, domains, studGradScore); semesterScoreProcessor.DegreeMapper = _degreeMapper; semesterScoreProcessor.PrintPeriod = printPeriod; semesterScoreProcessor.PrintCredit = printCredit; semesterScoreProcessor.SetData(semesterScoreList); #endregion #region Part2 //builder = new DocumentBuilder(each); builder.MoveToMergeField("領域文字描述"); if (Config.GetBoolean("列印文字評語", true)) { StudentDomainTextProcessor domainTextProcessor = new StudentDomainTextProcessor(builder, map); domainTextProcessor.SetData(semesterScoreList); } else { Section deleteSection = builder.CurrentSection; each.Sections.Remove(deleteSection); } #endregion #region Part3 //Document part3 = (Document)_template_part3.Clone(true); //builder = new DocumentBuilder(each); builder.MoveToMergeField("日常行為"); StudentMoralProcessor moralProcessor = new StudentMoralProcessor(builder, map, periodList, absenceList); List <AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) { autoSummaryList = autoSummaryCache[student.ID]; } else { autoSummaryList = new List <AutoSummaryRecord>(); } moralProcessor.SetData(autoSummaryList); // 處理多出來 table row Cell cel = moralProcessor.GetCurrentCell(); Table table = cel.ParentRow.ParentTable; for (int i = 47; i >= 20; i--) { bool rm = true; foreach (Aspose.Words.Cell cell in table.Rows[i].Cells) { if (cell.GetText() != "\a") { rm = false; break; } } if (rm) { table.Rows[i].Remove(); } } #endregion if (OneFileSave) { each.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); string fileName = ""; fileName = student.StudentNumber; fileName += "_" + student.IDNumber; if (!string.IsNullOrEmpty(student.RefClassID)) { fileName += "_" + student.Class.Name; } else { fileName += "_"; } fileName += "_" + (student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""); fileName += "_" + student.Name; if (!StudentDoc.ContainsKey(fileName)) { StudentDoc.Add(fileName, each); } } else { foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } if (!OneFileSave) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("列印日期"); globalFieldValue.Add(DateConvert.CDate(DateTime.Now.ToString("yyyy/MM/dd"))); globalFieldName.Add("列印時間"); globalFieldValue.Add(DateTime.Now.ToString("HH:mm:ss")); ReportConfiguration _Dylanconfig = new ReportConfiguration(Global.OneFileSave); OneFileSave = _Dylanconfig.GetBoolean("單檔儲存", false); StudentDoc = new Dictionary <string, Document>(); double total = _students.Count; double count = 0; List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in _students) { student_ids.Add(item.ID); } #region 快取資料 //取得異動資料 Dictionary <string, List <JHUpdateRecordRecord> > updateRecordCache = new Dictionary <string, List <JHUpdateRecordRecord> >(); foreach (var record in JHUpdateRecord.SelectByStudentIDs(student_ids)) { if (!updateRecordCache.ContainsKey(record.StudentID)) { updateRecordCache.Add(record.StudentID, new List <JHUpdateRecordRecord>()); } updateRecordCache[record.StudentID].Add(record); } //取得缺曠獎懲資料 Dictionary <string, List <AutoSummaryRecord> > autoSummaryCache = new Dictionary <string, List <AutoSummaryRecord> >(); foreach (AutoSummaryRecord record in AutoSummary.Select(student_ids, null)) { if (!autoSummaryCache.ContainsKey(record.RefStudentID)) { autoSummaryCache.Add(record.RefStudentID, new List <AutoSummaryRecord>()); } autoSummaryCache[record.RefStudentID].Add(record); } //取得學期歷程 Dictionary <string, JHSemesterHistoryRecord> semesterHistoryCache = new Dictionary <string, JHSemesterHistoryRecord>(); foreach (var record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { if (!semesterHistoryCache.ContainsKey(record.RefStudentID)) { semesterHistoryCache.Add(record.RefStudentID, record); } } //取得學期成績 Dictionary <string, List <JHSemesterScoreRecord> > semesterScoreCache = new Dictionary <string, List <JHSemesterScoreRecord> >(); foreach (var record in JHSemesterScore.SelectByStudentIDs(student_ids)) { if (!semesterScoreCache.ContainsKey(record.RefStudentID)) { semesterScoreCache.Add(record.RefStudentID, new List <JHSemesterScoreRecord>()); } semesterScoreCache[record.RefStudentID].Add(record); } // 取得畢業成績 Dictionary <string, K12.Data.GradScoreRecord> StudGradScoreDic = new Dictionary <string, GradScoreRecord>(); foreach (GradScoreRecord score in GradScore.SelectByIDs <GradScoreRecord>(student_ids)) { StudGradScoreDic.Add(score.RefStudentID, score); } ////課程 //JHCourse.RemoveAll(); //Dictionary<string, JHCourseRecord> courseCache = new Dictionary<string, JHCourseRecord>(); //foreach (JHCourseRecord record in JHCourse.SelectAll()) //{ // if (!courseCache.ContainsKey(record.ID)) // courseCache.Add(record.ID, record); //} #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); //Dictionary<string, List<string>> subjects = new Dictionary<string, List<string>>(); //List<JHCourseRecord> courseList = new List<JHCourseRecord>(courseCache.Values); //courseList.Sort(delegate(JHCourseRecord x, JHCourseRecord y) //{ // return JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject); //}); string domainSubjectSetup = Config.GetString("領域科目設定", "Domain"); if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, DomainSubjectExpand.展開); } if (!domains.ContainsKey("")) { domains.Add("", DomainSubjectExpand.展開); } } else { throw new Exception("請重新儲存一次列印設定"); } //foreach (var domain in JHSchool.Evaluation.Subject.Domains) // subjects.Add(domain, new List<string>()); //if (!subjects.ContainsKey("")) subjects.Add("", new List<string>()); //foreach (var course in courseList) //{ // if (!subjects.ContainsKey(course.Domain)) // subjects.Add(course.Domain, new List<string>()); // if (!subjects[course.Domain].Contains(course.Subject) && // domains.ContainsKey(course.Domain) && // domains[course.Domain] == false) // { // subjects[course.Domain].Add(course.Subject); // } //} #endregion DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 節權數顯示 string pcDisplay = string.Empty; bool printPeriod = Config.GetBoolean("列印節數", true); bool printCredit = Config.GetBoolean("列印權數", false); if (printPeriod && printCredit) { pcDisplay = "節" + Environment.NewLine + "權" + Environment.NewLine + "數"; } else if (printPeriod) { pcDisplay = "節" + Environment.NewLine + "數"; } else if (printCredit) { pcDisplay = "權" + Environment.NewLine + "數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 文字評語是否列印 bool printText = Config.GetBoolean("列印文字評語", true); if (printText == false) { templateBuilder.MoveToMergeField("學習領域評量"); (templateBuilder.CurrentParagraph.ParentNode as Cell).ParentRow.ParentTable.Remove(); } #endregion #region 務學習時數 Global._SLRDict.Clear(); Global._SLRDict = Utility.GetServiceLearningDetail(student_ids); #endregion #region 產生 foreach (JHStudentRecord student in _students) { count++; Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 建立學期歷程對照 List <SemesterHistoryItem> semesterHistoryList = null; if (semesterHistoryCache.ContainsKey(student.ID)) { semesterHistoryList = semesterHistoryCache[student.ID].SemesterHistoryItems; } else { semesterHistoryList = new List <SemesterHistoryItem>(); } SemesterMap map = new SemesterMap(); map.SetData(semesterHistoryList); #endregion #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student, semesterHistoryList); #endregion #region 異動資料 List <JHUpdateRecordRecord> updateRecordList = null; if (updateRecordCache.ContainsKey(student.ID)) { updateRecordList = updateRecordCache[student.ID]; } else { updateRecordList = new List <JHUpdateRecordRecord>(); } StudentUpdateRecordProcessor updateRecordProcessor = new StudentUpdateRecordProcessor(builder); updateRecordProcessor.SetData(updateRecordList); #endregion #region 日常表現 List <AutoSummaryRecord> autoSummaryList = null; if (autoSummaryCache.ContainsKey(student.ID)) { autoSummaryList = autoSummaryCache[student.ID]; } else { autoSummaryList = new List <AutoSummaryRecord>(); } StudentMoralProcessor moralProcessor = new StudentMoralProcessor(builder, map); moralProcessor.SetData(autoSummaryList); #endregion #region 學期歷程 StudentHistoryProcessor history = new StudentHistoryProcessor(builder, map, (semesterHistoryCache.ContainsKey(student.ID) ? semesterHistoryCache[student.ID] : null)); #endregion #region 學期成績 List <JHSemesterScoreRecord> semesterScoreList = null; if (semesterScoreCache.ContainsKey(student.ID)) { semesterScoreList = semesterScoreCache[student.ID]; } else { semesterScoreList = new List <JHSemesterScoreRecord>(); } // 畢業成績 K12.Data.GradScoreRecord StudGradScore = new GradScoreRecord(); if (StudGradScoreDic.ContainsKey(student.ID)) { StudGradScore = StudGradScoreDic[student.ID]; } StudentSemesterScoreProcessor semesterScoreProcessor = new StudentSemesterScoreProcessor(builder, map, domainSubjectSetup, domains, StudGradScore); semesterScoreProcessor.DegreeMapper = _degreeMapper; semesterScoreProcessor.PrintPeriod = printPeriod; semesterScoreProcessor.PrintCredit = printCredit; semesterScoreProcessor.SetData(semesterScoreList); #endregion #region 學習領域評量 if (printText == true) { StudentTextProcessor text = new StudentTextProcessor(builder, map); text.SetData(semesterScoreList); } #endregion if (OneFileSave) { each.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); string fileName = ""; fileName = student.StudentNumber; fileName += "_" + student.IDNumber; if (!string.IsNullOrEmpty(student.RefClassID)) { fileName += "_" + student.Class.Name; } else { fileName += "_"; } fileName += "_" + (student.SeatNo.HasValue ? student.SeatNo.Value.ToString() : ""); fileName += "_" + student.Name; if (!StudentDoc.ContainsKey(fileName)) { StudentDoc.Add(fileName, each); } } else { foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } if (!OneFileSave) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { // 取得學生資料 Dictionary <string, JHStudentRecord> Students = new Dictionary <string, JHStudentRecord>(); // 取得異動資料 Dictionary <string, List <JHUpdateRecordRecord> > UpdateRecs = new Dictionary <string, List <JHUpdateRecordRecord> >(); wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange("學年度", "學期", "異動學號", "異動姓名", "異動生日", "異動身分證號", "異動性別", "異動類別", "異動日期", "原因及事項", "轉入前學校", "轉出後學校", "學籍核准日期", "學籍核准文號", "核准日期", "核准文號", "備註", "新生日", "新身分證號", "新姓名", "新性別", "出生地", "異動年級", "異動地址", "異動班級", "異動座號"); wizard.RequiredFields.AddRange("異動類別", "異動日期", "學年度", "學期"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { Students.Clear(); UpdateRecs.Clear(); // 取得學生資料 foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(e.List)) { if (!Students.ContainsKey(studRec.ID)) { Students.Add(studRec.ID, studRec); } } foreach (string str in Students.Keys) { List <JHUpdateRecordRecord> UpdRecList = new List <JHUpdateRecordRecord>(); UpdateRecs.Add(str, UpdRecList); } // 取得異動 MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>(); loader1.MaxThreads = 3; loader1.PackageSize = 250; loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1) { foreach (JHUpdateRecordRecord UpdRec in JHUpdateRecord.SelectByStudentIDs(e.List)) { // 非新生或畢業濾除 if (UpdRec.UpdateCode == "1" || UpdRec.UpdateCode == "2") { continue; } if (UpdateRecs.ContainsKey(UpdRec.StudentID)) { UpdateRecs[UpdRec.StudentID].Add(UpdRec); } } }; loader1.Run(e.List); }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i = 0; DateTime dt; // 檢查學生是否存在 JHStudentRecord studRec = null; if (Students.ContainsKey(e.Data.ID)) { studRec = Students[e.Data.ID]; } else { e.ErrorMessage = "沒有這位學生" + e.Data.ID; return; } // 驗證格式資料 bool InputFormatPass = true; foreach (string field in e.SelectFields) { string value = e.Data[field].Trim(); //// 驗證$無法匯入 //if (value.IndexOf('$') > -1) //{ // e.ErrorFields.Add(field, "儲存格有$無法匯入."); // break; //} switch (field) { default: break; case "異動類別": // 對應不到時 if (DAL.DALTransfer2.GetUpdateRecCodeByString39(value) == "") { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入正確異動類別"); } break; case "學年度": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } break; case "學期": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } if (i > 2) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數,1或2"); } break; case "異動年級": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { InputFormatPass &= false; e.WarningFields.Add(field, "請填入整數"); } break; case "異動座號": int.TryParse(value, out i); if (string.IsNullOrEmpty(value) || i < 1) { e.WarningFields.Add(field, "請填入整數"); } break; case "異動日期": if (string.IsNullOrEmpty(value) || DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } break; case "異動生日": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "學籍核准日期": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "核准日期": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "異動新生日": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "異動新性別": if (value == "男" || value == "女" || value == "") { } else { e.WarningFields.Add(field, "請填入男或女"); } break; case "異動性別": if (value == "男" || value == "女" || value == "") { } else { e.WarningFields.Add(field, "請填入男或女"); } break; case "新生日": if (!string.IsNullOrEmpty(value)) { if (DateTime.TryParse(value, out dt) == false) { InputFormatPass &= false; e.ErrorFields.Add(field, "必須填入日期,例如2009/1/1"); } } break; case "新性別": if (value == "男" || value == "女" || value == "") { } else { e.WarningFields.Add(field, "請填入男或女"); } break; } } }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } List <JHUpdateRecordRecord> InsertList = new List <JHUpdateRecordRecord>(); List <JHUpdateRecordRecord> UpdateList = new List <JHUpdateRecordRecord>(); foreach (string id in id_Rows.Keys) { int schoolYear, Semester; string GrYear = ""; DateTime dt; foreach (RowData data in id_Rows[id]) { if (!UpdateRecs.ContainsKey(id)) { continue; } int.TryParse(data["學年度"], out schoolYear); int.TryParse(data["學期"], out Semester); DateTime.TryParse(data["異動日期"], out dt); if (data.ContainsKey("異動年級")) { GrYear = data["異動年級"]; } // 異動類別 string UpdateType = string.Empty; if (data.ContainsKey("異動類別")) { UpdateType = data["異動類別"]; } // 取得原因及事項 string UpdateDesc = string.Empty; if (data.ContainsKey("原因及事項")) { UpdateDesc = data["原因及事項"]; } //// 檢查更正學籍 //string checkUpdateCode09Str=string.Empty; //if (data.ContainsKey("新生日")) // checkUpdateCode09Str += data["新生日"].Trim(); //if (data.ContainsKey("新身分證號")) // checkUpdateCode09Str += data["新身分證號"].Trim(); //if (data.ContainsKey("新姓名")) // checkUpdateCode09Str += data["新姓名"].Trim(); //if (data.ContainsKey("新性別")) // checkUpdateCode09Str += data["新性別"].Trim(); JHUpdateRecordRecord updateRec = null; // 判斷學年度+學期+異動日期+異動類別 (如果相同有當更新,不同就新增) foreach (JHUpdateRecordRecord urr in UpdateRecs[id]) { string UpdateStr = DAL.DALTransfer2.GetUpdateRecCodeString(urr.UpdateCode); if (urr.SchoolYear == schoolYear && urr.Semester == Semester && UpdateType == UpdateStr) { DateTime dt1; DateTime.TryParse(urr.UpdateDate, out dt1); if (dt == dt1) { // 使用原因及事項當作Key if (UpdateDesc == urr.UpdateDescription) { updateRec = urr; } ////判斷當異動類別是更正學籍,加入(新生日、新身分證號、新姓名、新性別)判斷,四項內容只要有一個不同就當作新的一筆可匯入。 //if (urr.UpdateCode == "9") //{ // string strKey = urr.NewBirthday.Trim() + urr.NewIDNumber.Trim() + urr.NewName.Trim() + urr.NewGender.Trim (); // if (checkUpdateCode09Str == strKey) // updateRec = urr; //} //else // updateRec = urr; } } } bool isInsert = true; if (updateRec == null) { updateRec = new JHUpdateRecordRecord(); updateRec.StudentID = id; } else { isInsert = false; } bool checkData = false; string Ur03School = "", Ur04School = ""; foreach (string field in e.ImportFields) { string value = data[field].Trim(); switch (field) { case "異動類別": string UrCode = DAL.DALTransfer2.GetUpdateRecCodeByString39(value); if (UrCode != "") { updateRec.UpdateCode = UrCode; } break; case "學年度": int scYear; if (int.TryParse(value, out scYear)) { updateRec.SchoolYear = scYear; checkData = true; } break; case "學期": int Sems; if (int.TryParse(value, out Sems)) { updateRec.Semester = Sems; checkData = true; } break; case "異動年級": updateRec.GradeYear = GrYear; break; case "異動日期": DateTime dtd; if (DateTime.TryParse(value, out dtd)) { updateRec.UpdateDate = dtd.ToShortDateString(); } break; case "備註": updateRec.Comment = value; break; case "學籍核准日期": DateTime dtLD; if (DateTime.TryParse(value, out dtLD)) { updateRec.LastADDate = dtLD.ToShortDateString(); } break; case "學籍核准文號": updateRec.LastADNumber = value; break; case "異動班級": updateRec.OriginClassName = value; break; case "異動姓名": updateRec.StudentName = value; break; case "異動身分證號": updateRec.IDNumber = value; break; case "異動學號": updateRec.StudentNumber = value; break; case "異動性別": if (value == "男" || value == "女" || value == "") { updateRec.Gender = value; } break; case "異動生日": DateTime dtb; if (DateTime.TryParse(value, out dtb)) { updateRec.Birthdate = dtb.ToShortDateString(); } break; case "異動座號": int no; if (int.TryParse(value, out no)) { updateRec.SeatNo = no + ""; } break; case "核准日期": DateTime dtAd; if (DateTime.TryParse(value, out dtAd)) { updateRec.ADDate = dtAd.ToShortDateString(); } break; case "核准文號": updateRec.ADNumber = value; break; case "異動新生日": DateTime dtNB; if (DateTime.TryParse(value, out dtNB)) { updateRec.NewBirthday = dtNB.ToShortDateString(); } break; case "異動新身分證號": updateRec.NewIDNumber = value; break; case "異動新姓名": updateRec.NewName = value; break; case "異動新性別": if (value == "男" || value == "女" || value == "") { updateRec.NewGender = value; } break; case "新生日": DateTime dtNB1; if (DateTime.TryParse(value, out dtNB1)) { updateRec.NewBirthday = dtNB1.ToShortDateString(); } break; case "新身分證號": updateRec.NewIDNumber = value; break; case "新姓名": updateRec.NewName = value; break; case "新性別": if (value == "男" || value == "女" || value == "") { updateRec.NewGender = value; } break; case "出生地": updateRec.BirthPlace = value; break; case "原因及事項": updateRec.UpdateDescription = value; break; case "異動地址": updateRec.OriginAddress = value; break; case "轉入前學校": Ur03School = value; break; case "轉出後學校": Ur04School = value; break; } } // 轉換轉出入學校 if (updateRec.UpdateCode == "3") { updateRec.ImportExportSchool = Ur03School; } if (updateRec.UpdateCode == "4") { updateRec.ImportExportSchool = Ur04School; } if (string.IsNullOrEmpty(updateRec.StudentID) || string.IsNullOrEmpty(updateRec.UpdateDate) || string.IsNullOrEmpty(updateRec.UpdateCode)) { continue; } else { if (isInsert) { InsertList.Add(updateRec); } else { UpdateList.Add(updateRec); } } } } try { if (InsertList.Count > 0) { Insert(InsertList); } if (UpdateList.Count > 0) { Update(UpdateList); } JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess(); prlp.SaveLog("學生.匯入異動", "匯入學籍異動", "匯入學籍異動:共新增" + InsertList.Count + "筆資料,共更新:" + UpdateList.Count + "筆資料"); JHSchool.Student.Instance.SyncAllBackground(); } catch (Exception ex) { } }; }
public DataRationalityMessage Execute() { RATRecords.Clear(); DataRationalityMessage Message = new DataRationalityMessage(); int UpdateRecordCount = 0; //取得學生資料及建立資料物件 foreach (JHStudentRecord student in JHStudent.SelectAll()) { if (!Dic.ContainsKey(student.ID)) { Dic.Add(student.ID, new SuperObj_new(student)); } } foreach (JHUpdateRecordRecord each in JHUpdateRecord.SelectByStudentIDs(Dic.Keys)) { if (each.UpdateCode == "3") //轉入異動代碼為"3" { if (Dic.ContainsKey(each.StudentID)) //包含於清單內 { Dic.Remove(each.StudentID); //將其移除 UpdateRecordCount++; } } } //取得所有懲戒明細,並加入學生資料物件內 foreach (JHDemeritRecord demerit in JHDemerit.SelectAll()) { if (Dic.ContainsKey(demerit.RefStudentID)) { Dic[demerit.RefStudentID].DemeritList.Add(demerit); } } //取得(971,972,981,982)自動統計,排除目前學年度/學期 List <SchoolYearSemester> SysList = new List <SchoolYearSemester>(); SysList.Add(new SchoolYearSemester(97, 1)); SysList.Add(new SchoolYearSemester(97, 2)); SysList.Add(new SchoolYearSemester(98, 1)); SysList.Add(new SchoolYearSemester(98, 2)); SysList.Add(new SchoolYearSemester(99, 1)); SysList.Add(new SchoolYearSemester(99, 2)); List <AutoSummaryRecord> AutoSummaryList = AutoSummary.Select(Dic.Keys, SysList, SummaryType.Discipline, true); foreach (AutoSummaryRecord autoSummary in AutoSummaryList) { if (!Dic[autoSummary.RefStudentID].AutoSummaryDic.Contains(autoSummary)) { Dic[autoSummary.RefStudentID].AutoSummaryDic.Add(autoSummary); } } foreach (string each in Dic.Keys) { //if (Dic[each].IsCleadDmmerit()) //{ if (Dic[each].DetailAndSummary(97, 1)) { SetValue(Dic[each], 97, 1); } if (Dic[each].DetailAndSummary(97, 2)) { SetValue(Dic[each], 97, 2); } if (Dic[each].DetailAndSummary(98, 1)) { SetValue(Dic[each], 98, 1); } if (Dic[each].DetailAndSummary(98, 2)) { SetValue(Dic[each], 98, 2); } if (Dic[each].DetailAndSummary(99, 1)) { SetValue(Dic[each], 99, 1); } if (Dic[each].DetailAndSummary(99, 2)) { SetValue(Dic[each], 99, 2); } //} } //錯誤說明 StringBuilder strBuilder = new StringBuilder(); strBuilder.AppendLine("檢查(非明細統計)筆數:" + AutoSummaryList.Count()); strBuilder.AppendLine("檢查(非明細統計)不為0筆數:" + RATRecords.Count); strBuilder.AppendLine("具有(轉入異動)記錄之學生共" + UpdateRecordCount + "名,未列入檢查範圍!"); strBuilder.AppendLine("(非明細定義於:僅轉入生可以有值)"); var SortedRATRecords = from RATRecord in RATRecords orderby RATRecord.班級, K12.Data.Int.ParseAllowNull(RATRecord.座號), RATRecord.學年度, RATRecord.學期 select RATRecord; Message.Data = SortedRATRecords.ToList(); Message.Message = strBuilder.ToString(); if (RATRecords.Count == 0) { MsgBox.Show("未檢查到錯誤資料!!"); } return(Message); }