/// <summary> /// 取得學生畢業資訊 /// </summary> /// <param name="StudentIDList"></param> /// <returns></returns> public static Dictionary <string, JHLeaveInfoRecord> GetStudentLeaveInfoDic(List <string> StudentIDList) { Dictionary <string, JHLeaveInfoRecord> StudLIR = new Dictionary <string, JHLeaveInfoRecord>(); foreach (JHLeaveInfoRecord rec in JHLeaveIfno.SelectByStudentIDs(StudentIDList)) { if (!StudLIR.ContainsKey(rec.RefStudentID)) { StudLIR.Add(rec.RefStudentID, rec); } } return(StudLIR); }
public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { wizard.ExportableFields.AddRange(ExportItemList); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { // 取得畢業相關資訊 List <JHLeaveInfoRecord> JHLeaveInfoRecordList = JHLeaveIfno.SelectByStudentIDs(e.List); foreach (JHLeaveInfoRecord lir in JHLeaveInfoRecordList) { RowData row = new RowData(); row.ID = lir.RefStudentID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "畢業學年度": if (lir.SchoolYear.HasValue) { row.Add(field, lir.SchoolYear.Value.ToString()); } break; case "畢業資格": row.Add(field, lir.Reason); break; case "畢業證書字號": row.Add(field, lir.DiplomaNumber); break; case "畢業相關訊息": row.Add(field, lir.Memo); break; } } } e.Items.Add(row); } PermRecLogProcess prlp = new PermRecLogProcess(); prlp.SaveLog("學生.匯出畢業資訊", "匯出", "共匯出" + K12.Presentation.NLDPanels.Student.SelectedSource.Count + "筆學生類別資料."); }; }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { // 學生 Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); // 畢業資訊 Dictionary <string, JHLeaveInfoRecord> StudJHLeaveInfoRecordDic = new Dictionary <string, JHLeaveInfoRecord>(); // 可匯入項目 List <string> ImportItemList = new List <string>(); ImportItemList.Add("畢業學年度"); ImportItemList.Add("畢業資格"); ImportItemList.Add("畢業證書字號"); ImportItemList.Add("畢業相關訊息"); // 取得可加入學生 TagName wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange(ImportItemList); wizard.RequiredFields.AddRange(); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { // 取得學生資料 students = JHStudent.SelectByIDs(e.List).ToDictionary(x => x.ID); // 取得畢業資訊 StudJHLeaveInfoRecordDic = JHLeaveIfno.SelectByStudentIDs(e.List).ToDictionary(x => x.RefStudentID); }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i = 0; // 檢查學生是否存在 JHStudentRecord studRec = null; if (students.ContainsKey(e.Data.ID)) { studRec = students[e.Data.ID]; } else { e.ErrorMessage = "沒有這位學生" + e.Data.ID; return; } }; 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 <JHLeaveInfoRecord> UpdateList = new List <JHLeaveInfoRecord>(); foreach (string id in id_Rows.Keys) { if (StudJHLeaveInfoRecordDic.ContainsKey(id)) { foreach (RowData data in id_Rows[id]) { foreach (string field in e.ImportFields) { if (field == "畢業學年度") { int SchoolYear; if (int.TryParse(data[field], out SchoolYear)) { StudJHLeaveInfoRecordDic[id].SchoolYear = SchoolYear; } else { StudJHLeaveInfoRecordDic[id].SchoolYear = null; } } if (field == "畢業資格") { StudJHLeaveInfoRecordDic[id].Reason = data[field]; } if (field == "畢業證書字號") { StudJHLeaveInfoRecordDic[id].DiplomaNumber = data[field]; } if (field == "畢業相關訊息") { StudJHLeaveInfoRecordDic[id].Memo = data[field]; } } } } } UpdateList = StudJHLeaveInfoRecordDic.Values.ToList(); try { if (UpdateList.Count > 0) { Update(UpdateList); } JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess(); prlp.SaveLog("學生.匯入畢業資訊", "匯入學生畢業資訊", "匯入學生畢業資訊:共更新:" + UpdateList.Count + "筆資料"); JHSchool.Student.Instance.SyncAllBackground(); JHSchool.StudentTag.Instance.SyncAllBackground(); JHSchool.Data.JHStudent.RemoveAll(); JHSchool.Data.JHStudent.SelectAll(); } catch (Exception ex) { } }; }
public static List <StudInfoEntity> GetStudentEntityList(List <string> StudentIDList) { Dictionary <string, string> StudTagDic = new Dictionary <string, string>(); Dictionary <string, string> StudItemDic = new Dictionary <string, string>(); Global._tempPhomeDict.Clear(); // 取得對照表 XmlDocument doc = StudSBTManager.GetDataFormSystem(); if (doc != null) { if (doc.SelectSingleNode("Data") != null) { foreach (XmlElement xe in doc.SelectSingleNode("Data")) { string StudTags = xe.GetAttribute("StudTag").Trim(); StudTags = StudTags.Replace(',', ','); StudTags = StudTags.Replace(':', ':'); string[] StudTagsArr = StudTags.Split(','); if (!string.IsNullOrEmpty(StudTags)) { foreach (string str in StudTagsArr) { if (!StudTagDic.ContainsKey(str)) { StudTagDic.Add(str, xe.GetAttribute("FieldName") + xe.GetAttribute("ItemName")); } } } if (!string.IsNullOrEmpty(xe.GetAttribute("FieldName")) && !string.IsNullOrEmpty(xe.GetAttribute("ItemName"))) { string Item = xe.GetAttribute("FieldName") + xe.GetAttribute("ItemName"); if (!StudItemDic.ContainsKey(Item)) { StudItemDic.Add(Item, xe.GetAttribute("ItemValue")); } } } } } List <StudInfoEntity> StudInfoEntityList = new List <StudInfoEntity>(); // 建立相關讀取用到資訊 Dictionary <string, JHLeaveInfoRecord> LeaveInfoRecordDic = new Dictionary <string, JHLeaveInfoRecord>(); Dictionary <string, List <string> > StudentTagRecordDic = new Dictionary <string, List <string> >(); Dictionary <string, JHPhoneRecord> PhoneRecordDic = new Dictionary <string, JHPhoneRecord>(); Dictionary <string, JHParentRecord> ParentRecordDic = new Dictionary <string, JHParentRecord>(); Dictionary <string, JHAddressRecord> AddressRecordDic = new Dictionary <string, JHAddressRecord>(); // 畢業資訊 foreach (JHLeaveInfoRecord lir in JHLeaveIfno.SelectByStudentIDs(StudentIDList)) { if (!LeaveInfoRecordDic.ContainsKey(lir.RefStudentID)) { LeaveInfoRecordDic.Add(lir.RefStudentID, lir); } } // 學生 Tag foreach (JHStudentTagRecord str in JHStudentTag.SelectByStudentIDs(StudentIDList)) { string strS = str.FullName; if (StudentTagRecordDic.ContainsKey(str.RefStudentID)) { StudentTagRecordDic[str.RefStudentID].Add(strS); } else { List <string> strList = new List <string>(); strList.Add(strS); StudentTagRecordDic.Add(str.RefStudentID, strList); } } // 電話資訊 foreach (JHPhoneRecord pr in JHPhone.SelectByStudentIDs(StudentIDList)) { if (!PhoneRecordDic.ContainsKey(pr.RefStudentID)) { PhoneRecordDic.Add(pr.RefStudentID, pr); } if (!Global._tempPhomeDict.ContainsKey(pr.RefStudentID)) { Global._tempPhomeDict.Add(pr.RefStudentID, new Dictionary <string, string>()); } Global._tempPhomeDict[pr.RefStudentID].Add("戶籍電話", pr.Permanent); Global._tempPhomeDict[pr.RefStudentID].Add("聯絡電話", pr.Contact); } // 父母及監護人資訊 foreach (JHParentRecord pr in JHParent.SelectByStudentIDs(StudentIDList)) { if (!ParentRecordDic.ContainsKey(pr.RefStudentID)) { ParentRecordDic.Add(pr.RefStudentID, pr); } if (!Global._tempPhomeDict.ContainsKey(pr.RefStudentID)) { Global._tempPhomeDict.Add(pr.RefStudentID, new Dictionary <string, string>()); } Global._tempPhomeDict[pr.RefStudentID].Add("父親電話", pr.FatherPhone); Global._tempPhomeDict[pr.RefStudentID].Add("母親電話", pr.MotherPhone); Global._tempPhomeDict[pr.RefStudentID].Add("監護人電話", pr.CustodianPhone); } // 地址 foreach (JHAddressRecord ar in JHAddress.SelectByStudentIDs(StudentIDList)) { if (!AddressRecordDic.ContainsKey(ar.RefStudentID)) { AddressRecordDic.Add(ar.RefStudentID, ar); } } foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(StudentIDList)) { if (studRec.Status == K12.Data.StudentRecord.StudentStatus.一般 || studRec.Status == K12.Data.StudentRecord.StudentStatus.輟學) { StudInfoEntity sie = new StudInfoEntity(); // 初始 sie.ClassName = sie.SeatNo = string.Empty; if (studRec.Class != null) { sie.ClassName = string.Format("{0:00}", studRec.Class.Name); } sie.Gender = studRec.Gender; sie.IDNumber = studRec.IDNumber; sie.Name = studRec.Name; if (studRec.SeatNo.HasValue) { sie.SeatNo = string.Format("{0:00}", studRec.SeatNo.Value); } sie.StudentID = studRec.ID; sie.StudentNumber = string.Format("{0:00000000}", studRec.StudentNumber); // 填入資料 if (!string.IsNullOrEmpty(JHSchool.Data.JHSchoolInfo.Code)) { string strSchoolCode = JHSchoolInfo.Code; if (strSchoolCode.Length >= 6) { strSchoolCode = strSchoolCode.Substring(0, 6); } sie.SetDataCellEntity("學校代碼", 6, strSchoolCode); sie.SetDataCellEntity("畢業學校代碼", 6, strSchoolCode); } string strNum; if (sie.StudentNumber.Length >= 8) { strNum = sie.StudentNumber.Substring(0, 8); } else { strNum = sie.StudentNumber; for (int i = 0; i < (8 - sie.StudentNumber.Length); i++) { strNum = "0" + strNum; } } sie.SetDataCellEntity("學號", 8, strNum); if (!string.IsNullOrEmpty(sie.ClassName)) { if (sie.ClassName.Length >= 3) { sie.ClassName = sie.ClassName.Substring(1, 2); } if (sie.ClassName.Length >= 2) { sie.SetDataCellEntity("班級", 2, sie.ClassName.Substring(0, 2)); } else { sie.SetDataCellEntity("班級", 2, "0" + sie.ClassName); } } if (!string.IsNullOrEmpty(sie.SeatNo)) { if (sie.SeatNo.Length > 0) { sie.SetDataCellEntity("座號", 2, sie.SeatNo.Substring(0, 2)); } else { sie.SetDataCellEntity("座號", 2, "0" + sie.SeatNo); } } string StudName = sie.Name.Trim(); if (StudName.Length == 2) { StudName = StudName.Substring(0, 1) + " " + StudName.Substring(1, 1); } sie.SetDataCellEntity("學生姓名", 20, StudName); sie.SetDataCellEntity("身分證號", 10, sie.IDNumber); if (studRec.Gender == "男") { sie.SetDataCellEntity("性別", 1, "1"); } if (studRec.Gender == "女") { sie.SetDataCellEntity("性別", 1, "2"); } if (studRec.Birthday.HasValue) { sie.SetDataCellEntity("出生年", 2, string.Format("{0:00}", studRec.Birthday.Value.Year - 1911)); sie.SetDataCellEntity("出生月", 2, string.Format("{0:00}", studRec.Birthday.Value.Month)); sie.SetDataCellEntity("出生日", 2, string.Format("{0:00}", studRec.Birthday.Value.Day)); } if (LeaveInfoRecordDic.ContainsKey(studRec.ID)) { if (LeaveInfoRecordDic[studRec.ID].SchoolYear.HasValue) { sie.SetDataCellEntity("畢業年度", 2, LeaveInfoRecordDic[studRec.ID].SchoolYear.Value + ""); } if (LeaveInfoRecordDic[studRec.ID].Reason == "畢業") { sie.SetDataCellEntity("畢肄業", 1, "1"); } if (LeaveInfoRecordDic[studRec.ID].Reason == "修業") { sie.SetDataCellEntity("畢肄業", 1, "0"); } } if (ParentRecordDic.ContainsKey(studRec.ID)) { string ParentName = ParentRecordDic[studRec.ID].CustodianName.Trim(); if (ParentName.Length == 2) { ParentName = ParentName.Substring(0, 1) + " " + ParentName.Substring(1, 1); } sie.SetDataCellEntity("家長姓名", 20, ParentName); //// 戶籍 //string strPhone=ParentRecordDic[studRec.ID].CustodianPhone.Replace ("(",""); //strPhone = strPhone.Replace(")", ""); //strPhone = strPhone.Replace("-", ""); string strPhone = ""; if (Global._tempPhomeDict.ContainsKey(sie.StudentID)) { if (Global._tempPhomeDict[sie.StudentID].ContainsKey(Global.SelectPhoneType)) { strPhone = Global._tempPhomeDict[sie.StudentID][Global.SelectPhoneType].Replace("(", "");; strPhone = strPhone.Replace(")", ""); strPhone = strPhone.Replace("-", ""); } } sie.SetDataCellEntity("緊急連絡電話", 20, strPhone); } if (AddressRecordDic.ContainsKey(studRec.ID)) { string strAddress = ""; if (_UseMailAddress) { sie.SetDataCellEntity("郵遞區號", 3, AddressRecordDic[studRec.ID].MailingZipCode); strAddress = AddressRecordDic[studRec.ID].MailingCounty + AddressRecordDic[studRec.ID].MailingTown + AddressRecordDic[studRec.ID].MailingDistrict + AddressRecordDic[studRec.ID].MailingArea + AddressRecordDic[studRec.ID].MailingDetail; } else { sie.SetDataCellEntity("郵遞區號", 3, AddressRecordDic[studRec.ID].PermanentZipCode); strAddress = AddressRecordDic[studRec.ID].PermanentCounty + AddressRecordDic[studRec.ID].PermanentTown + AddressRecordDic[studRec.ID].PermanentDistrict + AddressRecordDic[studRec.ID].PermanentArea + AddressRecordDic[studRec.ID].PermanentDetail; } sie.SetDataCellEntity("地址", 80, strAddress); } if (PhoneRecordDic.ContainsKey(studRec.ID)) { sie.SetDataCellEntity("手機", 10, PhoneRecordDic[studRec.ID].Cell); } // default value sie.SetDataCellEntity("學生身分", 1, "0"); sie.SetDataCellEntity("身心障礙", 1, "0"); sie.SetDataCellEntity("中低收入戶", 1, "0"); sie.SetDataCellEntity("低收入戶", 1, "0"); sie.SetDataCellEntity("失業勞工子女", 1, "0"); if (StudentTagRecordDic.ContainsKey(studRec.ID)) { foreach (string str in StudentTagRecordDic[studRec.ID]) { if (StudTagDic.ContainsKey(str)) { if (StudItemDic.ContainsKey(StudTagDic[str])) { if (StudTagDic[str].IndexOf("學生身分") > -1) { sie.SetDataCellEntity("學生身分", 1, StudItemDic[StudTagDic[str]]); } if (StudTagDic[str].IndexOf("身心障礙") > -1) { sie.SetDataCellEntity("身心障礙", 1, StudItemDic[StudTagDic[str]]); } if (StudTagDic[str].IndexOf("低收入戶") == 0) { sie.SetDataCellEntity("低收入戶", 1, StudItemDic[StudTagDic[str]]); } //if (StudTagDic[str].IndexOf("中低收入戶") > -1) // sie.SetDataCellEntity("中低收入戶", 1, StudItemDic[StudTagDic[str]]); if (StudTagDic[str].IndexOf("失業勞工子女") > -1) { sie.SetDataCellEntity("失業勞工子女", 1, StudItemDic[StudTagDic[str]]); } } } } } StudInfoEntityList.Add(sie); } } return(StudInfoEntityList); }
private void _writeWorker_DoWork(object sender, DoWorkEventArgs e) { #region 寫入離校資訊 try { List <JHLeaveInfoRecord> leaveInfoRecordList = new List <JHLeaveInfoRecord>(); foreach (JHLeaveInfoRecord record in JHLeaveIfno.SelectByStudentIDs(_students.AsKeyList())) { if (!_passList.ContainsKey(record.RefStudentID)) { continue; } leaveInfoRecordList.Add(record); if (_passList[record.RefStudentID] == true) { record.Reason = "畢業"; record.Memo = string.Empty; } else { record.Reason = "修業"; StringBuilder builder = new StringBuilder(); _result[record.RefStudentID].Sort(); foreach (ResultDetail rd in _result[record.RefStudentID]) { string semester = rd.GradeYear + (rd.Semester.Equals("1") ? "上" : "下") + ":"; string details = string.Empty; foreach (string detail in rd.Details) { details += detail + ","; } if (details.EndsWith(",")) { details = details.Substring(0, details.Length - 1); } builder.AppendLine(semester + details); } record.Memo = builder.ToString(); } // 系統目前預設學年度 int SchoolYear; int.TryParse(JHSchool.School.DefaultSchoolYear, out SchoolYear); record.SchoolYear = SchoolYear; } JHLeaveIfno.Update(leaveInfoRecordList); } catch (Exception ex) { BugReporter.ReportException(ex, false); } #endregion #region 寫入類別(Tags) string FailurePrefix = "未達畢業標準"; try { List <JHTagConfigRecord> tagList = JHTagConfig.SelectByCategory(K12.Data.TagCategory.Student); TagConfigRecordComparer tagComparer = new TagConfigRecordComparer(); StudentTagRecordComparer studentTagComparer = new StudentTagRecordComparer(); #region 製作各種未達畢業標準的標籤 List <JHTagConfigRecord> tagConfigRecordList = new List <JHSchool.Data.JHTagConfigRecord>(); foreach (StudentRecord student in _students) { //如果學生通過畢業審查 if (_passList[student.ID]) { continue; } //如果審查結果沒有該學生編號則跳到下一筆 (這應該不會發生才對) if (!_result.ContainsKey(student.ID)) { continue; } List <ResultDetail> rdList = _result[student.ID]; foreach (ResultDetail rd in rdList) { foreach (string msg in rd.Messages) { JHTagConfigRecord tagConfigRecord = new JHTagConfigRecord(); tagConfigRecord.Prefix = FailurePrefix; tagConfigRecord.Name = msg; tagConfigRecord.Category = "Student"; if (!tagList.Contains(tagConfigRecord, tagComparer)) { tagConfigRecordList.Add(tagConfigRecord); tagList.Add(tagConfigRecord); //foreach (string tag_id in JHSchool.Data.TagConfig.Insert(tagConfigRecord)) //{ // if (!tagIDs.ContainsKey(tagConfigRecord.FullName)) // tagIDs.Add(tagConfigRecord.FullName, tag_id); //} } } } } JHTagConfig.Insert(tagConfigRecordList); tagList = JHTagConfig.SelectByCategory(K12.Data.TagCategory.Student); #endregion #region 貼上標籤 List <JHStudentTagRecord> studentTagsList = new List <JHStudentTagRecord>(); List <JHStudentTagRecord> deleteList = new List <JHStudentTagRecord>(); foreach (StudentRecord student in _students) { //如果學生通過畢業審查,應該把標籤拿下來 if (_passList[student.ID]) { foreach (JHStudentTagRecord student_tag in JHStudentTag.SelectByStudentID(student.ID)) { if (student_tag.Prefix == FailurePrefix) { deleteList.Add(student_tag); } } continue; } if (!_result.ContainsKey(student.ID)) { continue; } Dictionary <string, JHStudentTagRecord> studentTags = new Dictionary <string, JHStudentTagRecord>(); foreach (JHStudentTagRecord student_tag in JHStudentTag.SelectByStudentID(student.ID)) { if (!studentTags.ContainsKey(student_tag.RefTagID)) { studentTags.Add(student_tag.RefTagID, student_tag); } } List <ResultDetail> rdList = _result[student.ID]; foreach (ResultDetail rd in rdList) { foreach (string msg in rd.Messages) { string fullname = FailurePrefix + ":" + msg; foreach (JHTagConfigRecord record in tagList) { if (record.FullName == fullname && !studentTags.ContainsKey(record.ID)) { JHStudentTagRecord r = new JHStudentTagRecord(); r.RefTagID = record.ID; r.RefEntityID = student.ID; if (!studentTagsList.Contains(r, studentTagComparer)) { studentTagsList.Add(r); } } } } } } JHStudentTag.Insert(studentTagsList); JHStudentTag.Delete(deleteList); #endregion } catch (Exception ex) { BugReporter.ReportException(ex, false); } #endregion }