public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { //學生資訊 key: studentID Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHSchool.Data.JHStudentRecord>(); //學生修課資訊 studentID -> List:SCAttendRecord Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSchool.Data.JHSCAttendRecord> >(); //學生修習的課程 courseID -> CourseRecord Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHSchool.Data.JHCourseRecord>(); //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord) Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHSchool.Data.JHCourseRecord> >(); //學生修習的課程對應的評量設定細節 Dictionary <string, List <HC.JHAEIncludeRecord> > courseAe = new Dictionary <string, List <HC.JHAEIncludeRecord> >(); //學生的評量成績記錄 Dictionary <string, List <HC.JHSCETakeRecord> > existSces = new Dictionary <string, List <HC.JHSCETakeRecord> >(); //所有試別 Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>(); //評量成績缺考暨免試設定 PluginMain.ScoreTextMap.Clear(); PluginMain.ScoreValueMap.Clear(); wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange("學年度", "學期", "課程名稱", "評量名稱", "定期分數", "平時分數", "文字描述"); wizard.RequiredFields.AddRange("學年度", "學期", "課程名稱", "評量名稱"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { #region 取得學生資訊 foreach (JHStudentRecord stu in JHStudent.SelectByIDs(e.List)) { if (!students.ContainsKey(stu.ID)) { students.Add(stu.ID, stu); } } #endregion #region 取得修課記錄 MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>(); loader1.MaxThreads = 3; loader1.PackageSize = 250; loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1) { foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e1.List, new string[] { })) { if (!scattends.ContainsKey(record.RefStudentID)) { scattends.Add(record.RefStudentID, new List <JHSCAttendRecord>()); } scattends[record.RefStudentID].Add(record); if (!courses.ContainsKey(record.RefCourseID)) { courses.Add(record.RefCourseID, null); } } }; loader1.Run(e.List); #endregion #region 取得課程資訊 MultiThreadWorker <string> loader2 = new MultiThreadWorker <string>(); loader2.MaxThreads = 3; loader2.PackageSize = 250; loader2.PackageWorker += delegate(object sender2, PackageWorkEventArgs <string> e2) { foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(e2.List))) { if (courses.ContainsKey(record.ID)) { courses[record.ID] = record; } } }; loader2.Run(courses.Keys); foreach (JHCourseRecord course in JHCourse.SelectAll()) { string key = course.SchoolYear + "_" + course.Semester; if (!allcourses.ContainsKey(key)) { allcourses.Add(key, new Dictionary <string, JHCourseRecord>()); } if (!allcourses[key].ContainsKey(course.Name)) { allcourses[key].Add(course.Name, course); } } #endregion #region 取得目前評量成績記錄 MultiThreadWorker <string> loader3 = new MultiThreadWorker <string>(); loader3.MaxThreads = 3; loader3.PackageSize = 250; loader3.PackageWorker += delegate(object sender3, PackageWorkEventArgs <string> e3) { foreach (HC.JHSCETakeRecord sce in JHSCETake.SelectByStudentIDs(e3.List).AsHCJHSCETakeRecords()) { if (!existSces.ContainsKey(sce.RefSCAttendID)) { existSces.Add(sce.RefSCAttendID, new List <HC.JHSCETakeRecord>()); } existSces[sce.RefSCAttendID].Add(sce); } }; loader3.Run(e.List); #endregion #region 取得評量設定 foreach (HC.JHAEIncludeRecord ae in JHAEInclude.SelectAll().AsHCJHAEIncludeRecords()) { if (!courseAe.ContainsKey(ae.RefAssessmentSetupID)) { courseAe.Add(ae.RefAssessmentSetupID, new List <HC.JHAEIncludeRecord>()); } courseAe[ae.RefAssessmentSetupID].Add(ae); } #endregion #region 取得試別 foreach (JHExamRecord exam in JHExam.SelectAll()) { if (!exams.ContainsKey(exam.ID)) { exams.Add(exam.ID, exam); } } #endregion #region 取得評量成績缺考暨免試設定 Framework.ConfigData cd = JHSchool.School.Configuration["評量成績缺考暨免試設定"]; if (!string.IsNullOrEmpty(cd["評量成績缺考暨免試設定"])) { XmlElement element = Framework.XmlHelper.LoadXml(cd["評量成績缺考暨免試設定"]); foreach (XmlElement each in element.SelectNodes("Setting")) { var UseText = each.SelectSingleNode("UseText").InnerText; var AllowCalculation = bool.Parse(each.SelectSingleNode("AllowCalculation").InnerText); decimal Score; decimal.TryParse(each.SelectSingleNode("Score").InnerText, out Score); var Active = bool.Parse(each.SelectSingleNode("Active").InnerText); var UseValue = decimal.Parse(each.SelectSingleNode("UseValue").InnerText); if (Active) { if (!PluginMain.ScoreTextMap.ContainsKey(UseText)) { PluginMain.ScoreTextMap.Add(UseText, new ScoreMap { UseText = UseText, AllowCalculation = AllowCalculation, Score = Score, Active = Active, UseValue = UseValue, }); } if (!PluginMain.ScoreValueMap.ContainsKey(UseValue)) { PluginMain.ScoreValueMap.Add(UseValue, new ScoreMap { UseText = UseText, AllowCalculation = AllowCalculation, Score = Score, Active = Active, UseValue = UseValue, }); } } } } #endregion }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i; decimal d; #region 檢查學生是否存在 JHStudentRecord student = null; if (students.ContainsKey(e.Data.ID)) { student = students[e.Data.ID]; } else { e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID; return; } #endregion #region 驗證各個欄位格式 bool inputFormatPass = true; foreach (string field in e.SelectFields) { string value = e.Data[field]; switch (field) { default: break; case "學年度": case "學期": if (value == "" || !int.TryParse(value, out i)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } break; case "課程名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入課程名稱"); } break; case "評量名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入評量名稱"); } break; case "定期分數": case "平時分數": if (value != "" && !decimal.TryParse(value, out d)) { if (PluginMain.ScoreTextMap.Keys.Count > 0) { if (!PluginMain.ScoreTextMap.ContainsKey(value)) { inputFormatPass &= false; e.ErrorFields.Add(field, "僅允許空白、數值或「" + string.Join("、", PluginMain.ScoreTextMap.Keys) + "」"); } } else { inputFormatPass &= false; e.ErrorFields.Add(field, "僅允許空白或數值"); } } break; //case "努力程度": // if (value != "" && !int.TryParse(value, out i)) // { // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須填入空白或整數"); // } // break; case "文字描述": break; } } #endregion //輸入格式正確才會針對情節做檢驗 #region 驗證各種情節 if (inputFormatPass) { string errorMessage = ""; string sy = e.Data["學年度"]; string se = e.Data["學期"]; string key = e.Data.ID + "_" + sy + "_" + se; string courseName = e.Data["課程名稱"]; string semsKey = sy + "_" + se; string examName = e.Data["評量名稱"]; //int schoolyear = Framework.Int.ParseInt(sy); //int semester = Framework.Int.ParseInt(se); #region 檢查課程是否存在系統中 bool noCourse = false; if (!allcourses.ContainsKey(semsKey)) { noCourse = true; errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else if (!allcourses[semsKey].ContainsKey(courseName)) { noCourse = true; errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else { } #endregion #region 檢查學生是否有修此課程 & 評量是否存在 bool attended = false; JHCourseRecord attendCourse = null; if (scattends.ContainsKey(e.Data.ID)) { foreach (JHSCAttendRecord record in scattends[e.Data.ID]) { //if (courses[record.RefCourseID].Name == courseName) // attendCourse = courses[record.RefCourseID]; bool HasRec = false; // 當有學年度學期課程名稱相同 if (courses[record.RefCourseID].Name == courseName && courses[record.RefCourseID].SchoolYear.HasValue && courses[record.RefCourseID].Semester.HasValue) { if ((courses[record.RefCourseID].SchoolYear.Value.ToString().Trim() == sy.Trim()) && courses[record.RefCourseID].Semester.Value.ToString().Trim() == se.Trim()) { HasRec = true; } } if (HasRec && courses.ContainsKey(record.RefCourseID)) { attendCourse = courses[record.RefCourseID]; } } } else //學生沒修半堂課 { } if (attendCourse == null && !noCourse) { if (!e.ErrorFields.ContainsKey("無修課記錄")) { e.ErrorFields.Add("無修課記錄", "學生在此學期並無修習此課程"); } } else if (attendCourse != null) { #region 驗證評量是否存在 if (string.IsNullOrEmpty(attendCourse.RefAssessmentSetupID)) { if (!e.ErrorFields.ContainsKey("無評量設定")) { e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定"); } } else { if (!courseAe.ContainsKey(attendCourse.RefAssessmentSetupID)) { if (!e.ErrorFields.ContainsKey("無評量設定")) { e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定"); } } else { bool examValid = false; foreach (HC.JHAEIncludeRecord ae in courseAe[attendCourse.RefAssessmentSetupID]) { if (!exams.ContainsKey(ae.RefExamID)) { continue; } if (exams[ae.RefExamID].Name == examName) { examValid = true; } } if (!examValid) { if (!e.ErrorFields.ContainsKey("評量名稱無效")) { e.ErrorFields.Add("評量名稱無效", "評量名稱(" + examName + ")不存在系統中"); } } } } #endregion } #endregion e.ErrorMessage = errorMessage; } #endregion }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); #region 分包裝 foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } #endregion List <HC.JHSCETakeRecord> insertList = new List <HC.JHSCETakeRecord>(); List <HC.JHSCETakeRecord> updateList = new List <HC.JHSCETakeRecord>(); //交叉比對各學生資料 #region 交叉比對各學生資料 foreach (string id in id_Rows.Keys) { JHStudentRecord studentRec = students[id]; foreach (RowData data in id_Rows[id]) { string examName = data["評量名稱"]; string courseName = data["課程名稱"]; string SchoolYear = data["學年度"]; string Semester = data["學期"]; if (!scattends.ContainsKey(id)) { continue; } foreach (JHSCAttendRecord record in scattends[id]) { if (!courses.ContainsKey(record.RefCourseID)) { continue; } JHCourseRecord course = courses[record.RefCourseID]; //if (course.Name != courseName) continue; HC.JHSCETakeRecord currentSCE = null; string sy = "", ss = ""; if (course.SchoolYear.HasValue) { sy = course.SchoolYear.Value.ToString(); } if (course.Semester.HasValue) { ss = course.Semester.Value.ToString(); } if (SchoolYear != sy || Semester != ss || courseName != course.Name) { continue; } if (SchoolYear == sy && Semester == ss && course.Name == courseName) { if (existSces.ContainsKey(record.ID)) { foreach (HC.JHSCETakeRecord sce in existSces[record.ID]) { if (!exams.ContainsKey(sce.RefExamID)) { continue; } if (exams[sce.RefExamID].Name == examName) { currentSCE = sce; } } } } if (currentSCE != null) { bool changed = false; #region 填入資料 foreach (string field in e.ImportFields) { string value = data[field]; switch (field) { case "定期分數": if ("" + currentSCE.Score != value) { decimal d; if (decimal.TryParse(value, out d)) { currentSCE.Score = d; } else { if (PluginMain.ScoreTextMap.ContainsKey(value)) { currentSCE.Score = PluginMain.ScoreTextMap[value].UseValue; } else { currentSCE.Score = null; } } changed = true; } break; case "平時分數": if ("" + currentSCE.AssignmentScore != value) { decimal d; if (decimal.TryParse(value, out d)) { currentSCE.AssignmentScore = d; } else { if (PluginMain.ScoreTextMap.ContainsKey(value)) { currentSCE.AssignmentScore = PluginMain.ScoreTextMap[value].UseValue; } else { currentSCE.AssignmentScore = null; } } changed = true; } break; //case "努力程度": // if ("" + currentSCE.Effort != value) // { // int i; // if (int.TryParse(value, out i)) // currentSCE.Effort = i; // else // currentSCE.Effort = null; // changed = true; // } // break; case "文字描述": if (currentSCE.Text != value) { currentSCE.Text = value; changed = true; } break; } } #endregion if (changed) { updateList.Add(currentSCE); } } else { HC.JHSCETakeRecord newSCE = new HC.JHSCETakeRecord(new JHSCETakeRecord()); newSCE.RefStudentID = id; newSCE.RefSCAttendID = record.ID; newSCE.RefCourseID = record.RefCourseID; foreach (JHExamRecord exam in exams.Values) { if (exam.Name == examName) { newSCE.RefExamID = exam.ID; } } #region 填入資料 foreach (string field in e.ImportFields) { string value = data[field]; switch (field) { case "定期分數": if (value != "") { decimal d; if (decimal.TryParse(value, out d)) { newSCE.Score = d; } else { if (PluginMain.ScoreTextMap.ContainsKey(value)) { newSCE.Score = PluginMain.ScoreTextMap[value].UseValue; } else { newSCE.Score = null; } } } else { newSCE.Score = null; } break; case "平時分數": if (value != "") { decimal d; if (decimal.TryParse(value, out d)) { newSCE.AssignmentScore = d; } else { if (PluginMain.ScoreTextMap.ContainsKey(value)) { newSCE.AssignmentScore = PluginMain.ScoreTextMap[value].UseValue; } else { newSCE.AssignmentScore = null; } } } else { newSCE.AssignmentScore = null; } break; case "文字描述": newSCE.Text = value; break; } } #endregion if (newSCE.RefExamID != "") { insertList.Add(newSCE); } } } } } try { if (updateList.Count > 0) { #region 分批次兩路上傳 List <List <HC.JHSCETakeRecord> > updatePackages = new List <List <HC.JHSCETakeRecord> >(); List <List <HC.JHSCETakeRecord> > updatePackages2 = new List <List <HC.JHSCETakeRecord> >(); { List <HC.JHSCETakeRecord> package = null; int count = 0; foreach (HC.JHSCETakeRecord var in updateList) { if (count == 0) { package = new List <HC.JHSCETakeRecord>(30); count = 30; if ((updatePackages.Count & 1) == 0) { updatePackages.Add(package); } else { updatePackages2.Add(package); } } package.Add(var); count--; } } Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore.IsBackground = true; threadUpdateSemesterSubjectScore.Start(updatePackages); Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore2.IsBackground = true; threadUpdateSemesterSubjectScore2.Start(updatePackages2); threadUpdateSemesterSubjectScore.Join(); threadUpdateSemesterSubjectScore2.Join(); #endregion } } catch (Exception ex) { } if (insertList.Count > 0) { #region 分批次兩路上傳 List <List <HC.JHSCETakeRecord> > insertPackages = new List <List <HC.JHSCETakeRecord> >(); List <List <HC.JHSCETakeRecord> > insertPackages2 = new List <List <HC.JHSCETakeRecord> >(); { List <HC.JHSCETakeRecord> package = null; int count = 0; foreach (HC.JHSCETakeRecord var in insertList) { if (count == 0) { package = new List <HC.JHSCETakeRecord>(30); count = 30; if ((insertPackages.Count & 1) == 0) { insertPackages.Add(package); } else { insertPackages2.Add(package); } } package.Add(var); count--; } } Thread threadInsertSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore.IsBackground = true; threadInsertSemesterSubjectScore.Start(insertPackages); Thread threadInsertSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore2.IsBackground = true; threadInsertSemesterSubjectScore2.Start(insertPackages2); threadInsertSemesterSubjectScore.Join(); threadInsertSemesterSubjectScore2.Join(); #endregion } FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入評量成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆評量成績。"); #endregion }; }
public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { SmartSchool.API.PlugIn.VirtualCheckBox filterRepeat = new SmartSchool.API.PlugIn.VirtualCheckBox("自動略過重讀成績", true); wizard.Options.Add(filterRepeat); //wizard.ExportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記"); //wizard.ExportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "文字描述", "註記"); //2015.1.27 Cloud新增 wizard.ExportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記"); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { List <JHStudentRecord> students = JHStudent.SelectByIDs(e.List); Dictionary <string, List <JHSemesterScoreRecord> > semsDict = new Dictionary <string, List <JHSemesterScoreRecord> >(); foreach (JHSemesterScoreRecord record in JHSemesterScore.SelectByStudentIDs(e.List)) { if (!semsDict.ContainsKey(record.RefStudentID)) { semsDict.Add(record.RefStudentID, new List <JHSemesterScoreRecord>()); } semsDict[record.RefStudentID].Add(record); } foreach (JHStudentRecord stu in students) { if (!semsDict.ContainsKey(stu.ID)) { continue; } foreach (JHSemesterScoreRecord record in semsDict[stu.ID]) { foreach (K12.Data.SubjectScore subject in record.Subjects.Values) { RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "領域": row.Add(field, "" + subject.Domain); break; case "科目": row.Add(field, subject.Subject); break; case "學年度": row.Add(field, "" + record.SchoolYear); break; case "學期": row.Add(field, "" + record.Semester); break; case "權數": row.Add(field, "" + subject.Credit); break; case "節數": row.Add(field, "" + subject.Period); break; //case "分數評量": row.Add(field, "" + subject.Score); break; //2015.1.27 Cloud新增 case "成績": row.Add(field, "" + subject.Score); break; case "原始成績": row.Add(field, "" + subject.ScoreOrigin); break; case "補考成績": row.Add(field, "" + subject.ScoreMakeup); break; //case "努力程度": row.Add(field, "" + subject.Effort); break; case "文字描述": row.Add(field, subject.Text); break; case "註記": row.Add(field, subject.Comment); break; } } } e.Items.Add(row); } } } FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出學期科目成績", "總共匯出" + e.Items.Count + "筆學期科目成績。"); }; }
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); }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { Dictionary <string, int> _ID_SchoolYear_Semester_GradeYear = new Dictionary <string, int>(); Dictionary <string, List <string> > _ID_SchoolYear_Semester_Subject = new Dictionary <string, List <string> >(); Dictionary <string, JHStudentRecord> _StudentCollection = new Dictionary <string, JHStudentRecord>(); Dictionary <JHStudentRecord, Dictionary <int, decimal> > _StudentPassScore = new Dictionary <JHStudentRecord, Dictionary <int, decimal> >(); Dictionary <string, List <JHSemesterScoreRecord> > semsDict = new Dictionary <string, List <JHSemesterScoreRecord> >(); wizard.PackageLimit = 3000; //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記"); //wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "分數評量", "文字描述", "註記"); //2015.1.27 Cloud新增 //2017/6/16 穎驊新增,因應[02-02][06] 計算學期科目成績新增清空原成績模式 項目, 新增 "刪除"欄位,使使用者能匯入 刪除成績資料 wizard.ImportableFields.AddRange("領域", "科目", "學年度", "學期", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除"); wizard.RequiredFields.AddRange("領域", "科目", "學年度", "學期"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { #region ValidateStart _ID_SchoolYear_Semester_GradeYear.Clear(); _ID_SchoolYear_Semester_Subject.Clear(); _StudentCollection.Clear(); List <JHStudentRecord> list = JHStudent.SelectByIDs(e.List); MultiThreadWorker <JHStudentRecord> loader = new MultiThreadWorker <JHStudentRecord>(); loader.MaxThreads = 3; loader.PackageSize = 250; loader.PackageWorker += delegate(object sender1, PackageWorkEventArgs <JHStudentRecord> e1) { foreach (var item in JHSemesterScore.SelectByStudents(e1.List)) { if (!semsDict.ContainsKey(item.RefStudentID)) { semsDict.Add(item.RefStudentID, new List <JHSchool.Data.JHSemesterScoreRecord>()); } semsDict[item.RefStudentID].Add(item); } }; loader.Run(list); foreach (JHStudentRecord stu in list) { if (!_StudentCollection.ContainsKey(stu.ID)) { _StudentCollection.Add(stu.ID, stu); } } #endregion }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { #region ValidateRow int t; decimal d; JHStudentRecord student; if (_StudentCollection.ContainsKey(e.Data.ID)) { student = _StudentCollection[e.Data.ID]; } else { e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID; return; } bool inputFormatPass = true; #region 驗各欄位填寫格式 foreach (string field in e.SelectFields) { string value = e.Data[field]; switch (field) { default: break; case "領域": //if (value == "") //{ // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須填寫"); //} //else if (!Domains.Contains(value)) //{ // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須為七大領域"); //} break; case "科目": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填寫"); } break; case "學年度": if (value == "" || !int.TryParse(value, out t)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入學年度"); } break; case "權數": case "節數": if (value == "" || !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入數值"); } break; //case "成績年級": // if (value == "" || !int.TryParse(value, out t)) // { // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須填入整數"); // } // break; case "學期": if (value == "" || !int.TryParse(value, out t) || t > 2 || t < 1) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入1或2"); } break; //case "分數評量": // if (value != "" && !decimal.TryParse(value, out d)) // { // inputFormatPass &= false; // e.ErrorFields.Add(field, "必須填入空白或數值"); // } // break; //2015.1.27 Cloud新增 case "成績": if (value != "" && !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; //2015.1.27 Cloud新增 case "原始成績": if (value != "" && !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; //2015.1.27 Cloud新增 case "補考成績": if (value != "" && !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; case "努力程度": if (value != "" && !int.TryParse(value, out t)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; case "刪除": if (value != "" && value != "是") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或 '是'"); } break; } } #endregion //輸入格式正確才會針對情節做檢驗 if (inputFormatPass) { string errorMessage = ""; string subject = e.Data["科目"]; string schoolYear = e.Data["學年度"]; string semester = e.Data["學期"]; int? sy = null; int? se = null; if (int.TryParse(schoolYear, out t)) { sy = t; } if (int.TryParse(semester, out t)) { se = t; } if (sy != null && se != null) { string key = e.Data.ID + "_" + sy + "_" + se; #region 驗證新增科目成績 List <JHSemesterScoreRecord> semsList; if (semsDict.ContainsKey(student.ID)) { semsList = semsDict[student.ID]; } else { semsList = new List <JHSemesterScoreRecord>(); } foreach (JHSemesterScoreRecord record in semsList) { if (record.SchoolYear != sy) { continue; } if (record.Semester != se) { continue; } bool isNewSubjectInfo = true; string message = ""; foreach (K12.Data.SubjectScore s in record.Subjects.Values) { if (s.Subject == subject) { isNewSubjectInfo = false; } } if (isNewSubjectInfo) { if (!e.WarningFields.ContainsKey("查無此科目")) { e.WarningFields.Add("查無此科目", "學生在此學期並無此筆科目成績資訊,將會新增此科目成績"); } foreach (string field in new string[] { "領域", "科目", "學年度", "學期", "權數", "節數" }) { if (!e.SelectFields.Contains(field)) { message += (message == "" ? "發現此學期無此科目,\n將會新增成績\n缺少成績必要欄位" : "、") + field; } } if (message != "") { errorMessage += (errorMessage == "" ? "" : "\n") + message; } } } #endregion #region 驗證重複科目資料 //string skey = subject + "_" + le; string skey = subject; if (!_ID_SchoolYear_Semester_Subject.ContainsKey(key)) { _ID_SchoolYear_Semester_Subject.Add(key, new List <string>()); } if (_ID_SchoolYear_Semester_Subject[key].Contains(skey)) { errorMessage += (errorMessage == "" ? "" : "\n") + "同一學期不允許多筆相同科目的資料"; } else { _ID_SchoolYear_Semester_Subject[key].Add(skey); } #endregion } e.ErrorMessage = errorMessage; } #endregion }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { #region ImportPackage Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); #region 分包裝 foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } #endregion List <JHSemesterScoreRecord> insertList = new List <JHSemesterScoreRecord>(); List <JHSemesterScoreRecord> updateList = new List <JHSemesterScoreRecord>(); //交叉比對各學生資料 #region 交叉比對各學生資料 foreach (string id in id_Rows.Keys) { XmlDocument doc = new XmlDocument(); JHStudentRecord studentRec = _StudentCollection[id]; //該學生的學期科目成績 Dictionary <SemesterInfo, JHSemesterScoreRecord> semesterScoreDictionary = new Dictionary <SemesterInfo, JHSemesterScoreRecord>(); #region 整理現有的成績資料 List <JHSchool.Data.JHSemesterScoreRecord> semsList; if (semsDict.ContainsKey(studentRec.ID)) { semsList = semsDict[studentRec.ID]; } else { semsList = new List <JHSchool.Data.JHSemesterScoreRecord>(); } foreach (JHSemesterScoreRecord var in semsList) { SemesterInfo info = new SemesterInfo(); info.SchoolYear = var.SchoolYear; info.Semester = var.Semester; if (!semesterScoreDictionary.ContainsKey(info)) { semesterScoreDictionary.Add(info, var); } //string key = var.Subject + "_" + var.Level; //if (!semesterScoreDictionary.ContainsKey(var.SchoolYear)) // semesterScoreDictionary.Add(var.SchoolYear, new Dictionary<int, Dictionary<string, SemesterSubjectScoreInfo>>()); //if (!semesterScoreDictionary[var.SchoolYear].ContainsKey(var.Semester)) // semesterScoreDictionary[var.SchoolYear].Add(var.Semester, new Dictionary<string, SemesterSubjectScoreInfo>()); //if (!semesterScoreDictionary[var.SchoolYear][var.Semester].ContainsKey(key)) // semesterScoreDictionary[var.SchoolYear][var.Semester].Add(key, var); } #endregion //要匯入的學期科目成績 Dictionary <SemesterInfo, Dictionary <string, RowData> > semesterImportScoreDictionary = new Dictionary <SemesterInfo, Dictionary <string, RowData> >(); #region 整理要匯入的資料 foreach (RowData row in id_Rows[id]) { string subject = row["科目"]; string schoolYear = row["學年度"]; string semester = row["學期"]; int sy = int.Parse(schoolYear); int se = int.Parse(semester); SemesterInfo info = new SemesterInfo(); info.SchoolYear = sy; info.Semester = se; if (!semesterImportScoreDictionary.ContainsKey(info)) { semesterImportScoreDictionary.Add(info, new Dictionary <string, RowData>()); } if (!semesterImportScoreDictionary[info].ContainsKey(subject)) { semesterImportScoreDictionary[info].Add(subject, row); } } #endregion //學期年級重整 //Dictionary<SemesterInfo, int> semesterGradeYear = new Dictionary<SemesterInfo, int>(); //要變更成績的學期 List <SemesterInfo> updatedSemester = new List <SemesterInfo>(); //在變更學期中新增加的成績資料 Dictionary <SemesterInfo, List <RowData> > updatedNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >(); //要增加成績的學期 Dictionary <SemesterInfo, List <RowData> > insertNewSemesterScore = new Dictionary <SemesterInfo, List <RowData> >(); //開始處理ImportScore #region 開始處理ImportScore foreach (SemesterInfo info in semesterImportScoreDictionary.Keys) { foreach (string subject in semesterImportScoreDictionary[info].Keys) { RowData data = semesterImportScoreDictionary[info][subject]; //如果是本來沒有這筆學期的成績就加到insertNewSemesterScore if (!semesterScoreDictionary.ContainsKey(info)) { if (!insertNewSemesterScore.ContainsKey(info)) { insertNewSemesterScore.Add(info, new List <RowData>()); } insertNewSemesterScore[info].Add(data); } else { bool hasChanged = false; //修改已存在的資料 if (semesterScoreDictionary[info].Subjects.ContainsKey(subject)) { JHSemesterScoreRecord record = semesterScoreDictionary[info]; #region 直接修改已存在的成績資料的Detail foreach (string field in e.ImportFields) { K12.Data.SubjectScore score = record.Subjects[subject]; string value = data[field]; //"分數評量", "努力程度", "文字描述", "註記" switch (field) { default: break; case "領域": if (score.Domain != value) { score.Domain = value; hasChanged = true; } break; case "權數": if ("" + score.Credit != value) { score.Credit = decimal.Parse(value); hasChanged = true; } break; case "節數": if ("" + score.Period != value) { score.Period = decimal.Parse(value); hasChanged = true; } break; //case "成績年級": // int gy = int.Parse(data["成績年級"]); // if (record.GradeYear != gy) // { // semesterGradeYear[info] = gy; // hasChanged = true; // } // break; //case "分數評量": // if ("" + score.Score != value) // { // decimal d; // if (decimal.TryParse(value, out d)) // score.Score = d; // else // score.Score = null; // hasChanged = true; // } // break; //2015.1.27 Cloud新增 case "成績": if ("" + score.Score != value) { decimal d; if (decimal.TryParse(value, out d)) { score.Score = d; } else { score.Score = null; } hasChanged = true; } break; //2015.1.27 Cloud新增 case "原始成績": if ("" + score.ScoreOrigin != value) { decimal d; if (decimal.TryParse(value, out d)) { score.ScoreOrigin = d; } else { score.ScoreOrigin = null; } hasChanged = true; } break; //2015.1.27 Cloud新增 case "補考成績": if ("" + score.ScoreMakeup != value) { decimal d; if (decimal.TryParse(value, out d)) { score.ScoreMakeup = d; } else { score.ScoreMakeup = null; } hasChanged = true; } break; case "努力程度": if ("" + score.Effort != value) { int i; if (int.TryParse(value, out i)) { score.Effort = i; } else { score.Effort = null; } hasChanged = true; } break; case "文字描述": if ("" + score.Text != value) { score.Text = value; hasChanged = true; } break; case "註記": if (score.Comment != value) { score.Comment = value; hasChanged = true; } break; case "刪除": if (value == "是") { record.Subjects.Remove(subject); hasChanged = true; } break; } } #endregion } else//加入新成績至已存在的學期 { if (!updatedNewSemesterScore.ContainsKey(info)) { updatedNewSemesterScore.Add(info, new List <RowData>()); } updatedNewSemesterScore[info].Add(data); hasChanged = true; } //真的有變更 if (hasChanged) { #region 登錄有變更的學期 if (!updatedSemester.Contains(info)) { updatedSemester.Add(info); } #endregion } } } } #endregion //處理已登錄要更新的學期成績 #region 處理已登錄要更新的學期成績 foreach (SemesterInfo info in updatedSemester) { //Dictionary<int, Dictionary<int, string>> semeScoreID = (Dictionary<int, Dictionary<int, string>>)studentRec.Fields["SemesterSubjectScoreID"]; //string semesterScoreID = semeScoreID[sy][se];//從學期抓ID //int gradeyear = semesterGradeYear[info];//抓年級 //XmlElement subjectScoreInfo = doc.CreateElement("SemesterSubjectScoreInfo"); #region 產生該學期科目成績的XML //foreach (SemesterSubjectScoreInfo scoreInfo in semesterScoreDictionary[sy][se].Values) //{ // subjectScoreInfo.AppendChild(doc.ImportNode(scoreInfo.Detail, true)); //} updateList.Add(semesterScoreDictionary[info]); //if (updatedNewSemesterScore.ContainsKey(sy) && updatedNewSemesterScore[sy].ContainsKey(se)) if (updatedNewSemesterScore.ContainsKey(info)) { foreach (RowData row in updatedNewSemesterScore[info]) { //XmlElement newScore = doc.CreateElement("Subject"); K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore(); bool contain_deleted_words = false; #region 建立newScore //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" }) foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除" }) { if (e.ImportFields.Contains(field)) { decimal d; #region 填入科目資訊 string value = row[field]; switch (field) { default: break; case "領域": subjectScore.Domain = value; break; case "科目": subjectScore.Subject = value; break; case "權數": subjectScore.Credit = decimal.Parse(value); break; case "節數": subjectScore.Period = decimal.Parse(value); break; //case "分數評量": // decimal d; // if (decimal.TryParse(value, out d)) // subjectScore.Score = d; // else // subjectScore.Score = null; // break; //2015.1.27 Cloud新增 case "成績": if (decimal.TryParse(value, out d)) { subjectScore.Score = d; } else { subjectScore.Score = null; } break; //2015.1.27 Cloud新增 case "原始成績": if (decimal.TryParse(value, out d)) { subjectScore.ScoreOrigin = d; } else { subjectScore.ScoreOrigin = null; } break; //2015.1.27 Cloud新增 case "補考成績": if (decimal.TryParse(value, out d)) { subjectScore.ScoreMakeup = d; } else { subjectScore.ScoreMakeup = null; } break; case "努力程度": int i; if (int.TryParse(value, out i)) { subjectScore.Effort = i; } else { subjectScore.Effort = null; } break; case "文字描述": subjectScore.Text = value; break; case "註記": subjectScore.Comment = value; break; case "刪除": if (value == "是") { contain_deleted_words = true; } break; } #endregion } } #endregion //subjectScoreInfo.AppendChild(newScore); if (!contain_deleted_words) { JHSemesterScoreRecord record = semesterScoreDictionary[info]; if (!record.Subjects.ContainsKey(subjectScore.Subject)) { record.Subjects.Add(subjectScore.Subject, subjectScore); } else { record.Subjects[subjectScore.Subject] = subjectScore; } updateList.Add(record); } } } #endregion //updateList.Add(new SmartSchool.Feature.Score.EditScore.UpdateInfo(semesterScoreID, gradeyear, subjectScoreInfo)); } #endregion //處理新增成績學期 #region 處理新增成績學期 foreach (SemesterInfo info in insertNewSemesterScore.Keys) { //int gradeyear = semesterGradeYear[info];//抓年級 foreach (RowData row in insertNewSemesterScore[info]) { K12.Data.SubjectScore subjectScore = new K12.Data.SubjectScore(); bool contain_deleted_words = false; //foreach (string field in new string[] { "領域", "科目", "權數", "節數", "分數評量", "努力程度", "文字描述", "註記" }) foreach (string field in new string[] { "領域", "科目", "權數", "節數", "成績", "原始成績", "補考成績", "努力程度", "文字描述", "註記", "刪除" }) { if (e.ImportFields.Contains(field)) { decimal d; string value = row[field]; switch (field) { default: break; case "領域": subjectScore.Domain = value; break; case "科目": subjectScore.Subject = value; break; case "權數": subjectScore.Credit = decimal.Parse(value); break; case "節數": subjectScore.Period = decimal.Parse(value); break; //case "分數評量": // decimal d; // if (decimal.TryParse(value, out d)) // subjectScore.Score = d; // else // subjectScore.Score = null; // break; //2015.1.27 Cloud新增 case "成績": if (decimal.TryParse(value, out d)) { subjectScore.Score = d; } else { subjectScore.Score = null; } break; //2015.1.27 Cloud新增 case "原始成績": if (decimal.TryParse(value, out d)) { subjectScore.ScoreOrigin = d; } else { subjectScore.ScoreOrigin = null; } break; //2015.1.27 Cloud新增 case "補考成績": if (decimal.TryParse(value, out d)) { subjectScore.ScoreMakeup = d; } else { subjectScore.ScoreMakeup = null; } break; case "努力程度": int i; if (int.TryParse(value, out i)) { subjectScore.Effort = i; } else { subjectScore.Effort = null; } break; case "文字描述": subjectScore.Text = value; break; case "註記": subjectScore.Comment = value; break; case "刪除": if (value == "是") { contain_deleted_words = true; } break; } } } //subjectScoreInfo.AppendChild(newScore); JHSemesterScoreRecord record = new JHSemesterScoreRecord(); record.SchoolYear = info.SchoolYear; record.Semester = info.Semester; record.RefStudentID = studentRec.ID; //record.GradeYear = gradeyear; if (!record.Subjects.ContainsKey(subjectScore.Subject)) { record.Subjects.Add(subjectScore.Subject, subjectScore); } else { record.Subjects[subjectScore.Subject] = subjectScore; } if (!contain_deleted_words) { insertList.Add(record); } } //insertList.Add(new SmartSchool.Feature.Score.AddScore.InsertInfo(studentRec.StudentID, "" + sy, "" + se, gradeyear, "", subjectScoreInfo)); } #endregion } #endregion Dictionary <string, JHSemesterScoreRecord> iList = new Dictionary <string, JHSemesterScoreRecord>(); Dictionary <string, JHSemesterScoreRecord> uList = new Dictionary <string, JHSemesterScoreRecord>(); foreach (var record in insertList) { string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester; if (!iList.ContainsKey(key)) { iList.Add(key, new JHSemesterScoreRecord()); } JHSemesterScoreRecord newRecord = iList[key]; newRecord.RefStudentID = record.RefStudentID; newRecord.SchoolYear = record.SchoolYear; newRecord.Semester = record.Semester; foreach (var subject in record.Subjects.Keys) { if (!newRecord.Subjects.ContainsKey(subject)) { newRecord.Subjects.Add(subject, record.Subjects[subject]); } if (newRecord.Subjects[subject].Text.Contains("\b")) { newRecord.Subjects[subject].Text = newRecord.Subjects[subject].Text.Replace("\b", ""); } } } foreach (var record in updateList) { string key = record.RefStudentID + "_" + record.SchoolYear + "_" + record.Semester; if (!uList.ContainsKey(key)) { uList.Add(key, record); } JHSemesterScoreRecord newRecord = uList[key]; newRecord.RefStudentID = record.RefStudentID; newRecord.SchoolYear = record.SchoolYear; newRecord.Semester = record.Semester; newRecord.ID = record.ID; foreach (var subject in record.Subjects.Keys) { if (!newRecord.Subjects.ContainsKey(subject)) { newRecord.Subjects.Add(subject, record.Subjects[subject]); } if (newRecord.Subjects[subject].Text.Contains("\b")) { newRecord.Subjects[subject].Text = newRecord.Subjects[subject].Text.Replace("\b", ""); } } } List <string> ids = new List <string>(id_Rows.Keys); Dictionary <string, JHSemesterScoreRecord> origs = new Dictionary <string, JHSemesterScoreRecord>(); foreach (var record in JHSemesterScore.SelectByStudentIDs(ids)) { if (!origs.ContainsKey(record.ID)) { origs.Add(record.ID, record); } } foreach (var record in uList.Values) { if (origs.ContainsKey(record.ID)) { foreach (var domain in origs[record.ID].Domains.Keys) { if (!record.Domains.ContainsKey(domain)) { record.Domains.Add(domain, origs[record.ID].Domains[domain]); } } } } //FunctionSpliter<JHSemesterScoreRecord, int> splitInsert = new FunctionSpliter<JHSemesterScoreRecord, int>(200, 3); //splitInsert.Function = delegate(List<JHSemesterScoreRecord> part) //{ // JHSemesterScore.Insert(part); // return null; //}; //splitInsert.Execute(new List<JHSemesterScoreRecord>(iList.Values)); //FunctionSpliter<JHSemesterScoreRecord, int> splitUpdate= new FunctionSpliter<JHSemesterScoreRecord, int>(200, 3); //splitUpdate.Function = delegate(List<JHSemesterScoreRecord> part) //{ // JHSemesterScore.Update(part); // return null; //}; //splitUpdate.Execute(new List<JHSemesterScoreRecord>(uList.Values)); JHSemesterScore.Insert(iList.Values); JHSemesterScore.Update(uList.Values); FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入學期科目成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆學期科目成績。"); #endregion }; wizard.ImportComplete += delegate { MsgBox.Show("匯入完成"); }; }
/// <summary> /// 將學生編號轉換成 SCStudent 物件。 /// </summary> /// <remarks>使用指定的學生編號,向 DAL 取得 VO 後轉換成 SCStudent 物件。</remarks> public static List <ReportStudent> ToReportStudent(this IEnumerable <string> studentIDs) { List <string> StudentIDList = new List <string>(); List <ReportStudent> students = new List <ReportStudent>(); foreach (JHStudentRecord each in JHStudent.SelectByIDs(studentIDs)) { StudentIDList.Add(each.ID); students.Add(new ReportStudent(each)); } // 取得學生類別List List <StudentTagRecord> StudTagRecList = StudentTag.SelectByStudentIDs(StudentIDList); // 取得特種身分學生,加分比 Dictionary <string, decimal> StudAddWeightDict = DAL.DALTransfer.GetStudentAddWeightFormUDTByStudentTag(StudTagRecList, DAL.DALTransfer.SchoolType.高中); // 取得特種身分學生名稱 Dictionary <string, string> StudSpecTypeDict = DAL.DALTransfer.GetStudentSpcTypeFormUDTByStudentTag(StudTagRecList, JointAdmissionModule.DAL.DALTransfer.SchoolType.高中); Dictionary <string, K12.Data.UpdateRecordRecord> studUpdateRec = DAL.DALTransfer.GetStudentUpdareDate3ByStudentID(StudentIDList); foreach (ReportStudent rs in students) { // 加分比 if (StudAddWeightDict.ContainsKey(rs.StudentID)) { rs.AddWeight = StudAddWeightDict[rs.StudentID]; } // 學生身分 if (StudSpecTypeDict.ContainsKey(rs.StudentID)) { rs.SpcStudTypeName = StudSpecTypeDict[rs.StudentID]; } // 轉入學生異動 if (studUpdateRec.ContainsKey(rs.StudentID)) { if (studUpdateRec[rs.StudentID] != null) { DateTime dt; if (DateTime.TryParse(studUpdateRec[rs.StudentID].UpdateDate, out dt)) { rs.TransUpdateDateStr = (dt.Year - 1911).ToString() + "/" + dt.Month + "/" + dt.Day; } else { rs.TransUpdateDateStr = ""; } rs.LastEnterSchoolyear = studUpdateRec[rs.StudentID].SchoolYear; rs.LastEnterSemester = studUpdateRec[rs.StudentID].Semester; int gr; if (int.TryParse(studUpdateRec[rs.StudentID].GradeYear, out gr)) { rs.LastEnterGradeYear = gr; } } } } return(students); }
public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { wizard.ExportableFields.AddRange("姓名", "學號", "班級", "座號"); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { //課程資訊 List <JHCourseRecord> courses = JHCourse.SelectByIDs(e.List); //學生修課資訊 Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSCAttendRecord> >(); //課程修課學生 Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); #region 取得修課記錄 foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(new string[] { }, e.List)) { if (!scattends.ContainsKey(record.RefCourseID)) { scattends.Add(record.RefCourseID, new List <JHSchool.Data.JHSCAttendRecord>()); } scattends[record.RefCourseID].Add(record); if (!students.ContainsKey(record.RefStudentID)) { students.Add(record.RefStudentID, null); } } #endregion #region 取得學生資訊 JHSchool.Data.JHStudent.RemoveAll(); foreach (JHStudentRecord record in JHStudent.SelectByIDs(new List <string>(students.Keys))) { if (students.ContainsKey(record.ID)) { students[record.ID] = record; } } #endregion #region 產生 Row Data foreach (JHCourseRecord course in courses) { //Debug if (!scattends.ContainsKey(course.ID)) { continue; } foreach (JHSCAttendRecord record in scattends[course.ID]) { RowData row = new RowData(); row.ID = course.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "姓名": row.Add(field, students[record.RefStudentID].Name); break; case "學號": row.Add(field, students[record.RefStudentID].StudentNumber); break; case "班級": row.Add(field, (students[record.RefStudentID].Class != null ? students[record.RefStudentID].Class.Name : "")); break; case "座號": row.Add(field, "" + students[record.RefStudentID].SeatNo); break; } } } e.Items.Add(row); } } #endregion if (Item != "社團") { FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出課程修課學生", "總共匯出" + e.Items.Count + "筆課程修課學生。"); } }; }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { //學生資訊 key: studentID Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); //學生修課資訊 studentID -> List:SCAttendRecord Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSCAttendRecord> >(); //學生修習的課程 courseID -> CourseRecord Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHCourseRecord>(); //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord) Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHSchool.Data.JHCourseRecord> >(); //學生修習的課程對應的評量設定細節 Dictionary <string, List <JHAEIncludeRecord> > courseAe = new Dictionary <string, List <JHSchool.Data.JHAEIncludeRecord> >(); //學生的評量成績記錄 Dictionary <string, List <JHSCETakeRecord> > existSces = new Dictionary <string, List <JHSchool.Data.JHSCETakeRecord> >(); //所有試別 Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>(); // 取得努力程度對照 K12.Data.Configuration.ConfigData cd = K12.Data.School.Configuration["努力程度對照表"]; if (!string.IsNullOrEmpty(cd["xml"])) { XmlElement element = XmlHelper.LoadXml(cd["xml"]); foreach (XmlElement each in element.SelectNodes("Effort")) { int code = int.Parse(each.GetAttribute("Code")); decimal score; if (!decimal.TryParse(each.GetAttribute("Score"), out score)) { score = 0; } if (!_EffortDict.ContainsKey(score)) { _EffortDict.Add(score, code); } } _ScoreList.AddRange(_EffortDict.Keys); _ScoreList.Reverse(); } wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange("學年度", "學期", "課程名稱", "評量名稱", "分數評量", "努力程度", "文字描述"); wizard.RequiredFields.AddRange("學年度", "學期", "課程名稱", "評量名稱"); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { #region 取得學生資訊 foreach (JHStudentRecord stu in JHStudent.SelectByIDs(e.List)) { if (!students.ContainsKey(stu.ID)) { students.Add(stu.ID, stu); } } #endregion #region 取得修課記錄 MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>(); loader1.MaxThreads = 3; loader1.PackageSize = 250; loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1) { foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e1.List, new string[] { })) { if (!scattends.ContainsKey(record.RefStudentID)) { scattends.Add(record.RefStudentID, new List <JHSchool.Data.JHSCAttendRecord>()); } scattends[record.RefStudentID].Add(record); if (!courses.ContainsKey(record.RefCourseID)) { courses.Add(record.RefCourseID, null); } } }; loader1.Run(e.List); #endregion #region 取得課程資訊 MultiThreadWorker <string> loader2 = new MultiThreadWorker <string>(); loader2.MaxThreads = 3; loader2.PackageSize = 250; loader2.PackageWorker += delegate(object sender2, PackageWorkEventArgs <string> e2) { foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(e2.List))) { if (courses.ContainsKey(record.ID)) { courses[record.ID] = record; } } }; loader2.Run(courses.Keys); foreach (JHCourseRecord course in JHCourse.SelectAll()) { string key = course.SchoolYear + "_" + course.Semester; if (!allcourses.ContainsKey(key)) { allcourses.Add(key, new Dictionary <string, JHSchool.Data.JHCourseRecord>()); } if (!allcourses[key].ContainsKey(course.Name)) { allcourses[key].Add(course.Name, course); } } #endregion #region 取得目前評量成績記錄 MultiThreadWorker <string> loader3 = new MultiThreadWorker <string>(); loader3.MaxThreads = 3; loader3.PackageSize = 250; loader3.PackageWorker += delegate(object sender3, PackageWorkEventArgs <string> e3) { foreach (JHSCETakeRecord sce in JHSCETake.SelectByStudentIDs(e3.List)) { if (!existSces.ContainsKey(sce.RefSCAttendID)) { existSces.Add(sce.RefSCAttendID, new List <JHSchool.Data.JHSCETakeRecord>()); } existSces[sce.RefSCAttendID].Add(sce); } }; loader3.Run(e.List); #endregion #region 取得評量設定 foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll()) { if (!courseAe.ContainsKey(ae.RefAssessmentSetupID)) { courseAe.Add(ae.RefAssessmentSetupID, new List <JHSchool.Data.JHAEIncludeRecord>()); } courseAe[ae.RefAssessmentSetupID].Add(ae); } #endregion #region 取得試別 foreach (JHExamRecord exam in JHExam.SelectAll()) { if (!exams.ContainsKey(exam.ID)) { exams.Add(exam.ID, exam); } } #endregion }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i; decimal d; #region 檢查學生是否存在 JHStudentRecord student = null; if (students.ContainsKey(e.Data.ID)) { student = students[e.Data.ID]; } else { e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID; return; } #endregion #region 驗證各個欄位格式 bool inputFormatPass = true; foreach (string field in e.SelectFields) { string value = e.Data[field]; switch (field) { default: break; case "學年度": case "學期": if (value == "" || !int.TryParse(value, out i)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } break; case "課程名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入課程名稱"); } break; case "評量名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入評量名稱"); } break; case "分數評量": if (value != "" && !decimal.TryParse(value, out d)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或數值"); } break; case "努力程度": if (value != "" && !int.TryParse(value, out i)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或整數"); } break; case "文字描述": break; } } #endregion //輸入格式正確才會針對情節做檢驗 #region 驗證各種情節 if (inputFormatPass) { string errorMessage = ""; string sy = e.Data["學年度"]; string se = e.Data["學期"]; string key = e.Data.ID + "_" + sy + "_" + se; string courseName = e.Data["課程名稱"]; string semsKey = sy + "_" + se; string examName = e.Data["評量名稱"]; //int schoolyear = Framework.Int.ParseInt(sy); //int semester = Framework.Int.ParseInt(se); #region 檢查課程是否存在系統中 bool noCourse = false; if (!allcourses.ContainsKey(semsKey)) { noCourse = true; errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else if (!allcourses[semsKey].ContainsKey(courseName)) { noCourse = true; errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else { } #endregion #region 檢查學生是否有修此課程 & 評量是否存在 bool attended = false; JHCourseRecord attendCourse = null; if (scattends.ContainsKey(e.Data.ID)) { foreach (JHSCAttendRecord record in scattends[e.Data.ID]) { bool HasRec = false; // 當有學年度學期課程名稱相同 if (courses[record.RefCourseID].Name == courseName && courses[record.RefCourseID].SchoolYear.HasValue && courses[record.RefCourseID].Semester.HasValue) { if ((courses[record.RefCourseID].SchoolYear.Value.ToString().Trim() == sy.Trim()) && courses[record.RefCourseID].Semester.Value.ToString().Trim() == se.Trim()) { HasRec = true; } } if (HasRec && courses.ContainsKey(record.RefCourseID)) { attendCourse = courses[record.RefCourseID]; } } } else //學生沒修半堂課 { } if (attendCourse == null && !noCourse) { if (!e.ErrorFields.ContainsKey("無修課記錄")) { e.ErrorFields.Add("無修課記錄", "學生在此學期並無修習此課程"); } } else if (attendCourse != null) { #region 驗證評量是否存在 if (string.IsNullOrEmpty(attendCourse.RefAssessmentSetupID)) { if (!e.ErrorFields.ContainsKey("無評量設定")) { e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定"); } } else { if (!courseAe.ContainsKey(attendCourse.RefAssessmentSetupID)) { if (!e.ErrorFields.ContainsKey("無評量設定")) { e.ErrorFields.Add("無評量設定", "課程(" + attendCourse.Name + ")無評量設定"); } } else { bool examValid = false; foreach (JHAEIncludeRecord ae in courseAe[attendCourse.RefAssessmentSetupID]) { if (!exams.ContainsKey(ae.RefExamID)) { continue; } // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",因此必須要在原本的Exam.Name驗證 // 加上 ||examName =="平時評量" ,避免平時評量的欄位被擋掉 if (exams[ae.RefExamID].Name == examName || examName == "平時評量") { examValid = true; } } if (!examValid) { if (!e.ErrorFields.ContainsKey("評量名稱無效")) { e.ErrorFields.Add("評量名稱無效", "評量名稱(" + examName + ")不存在系統中"); } } } } #endregion } #endregion e.ErrorMessage = errorMessage; } #endregion }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); #region 分包裝 foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } #endregion List <KH.JHSCETakeRecord> insertList = new List <KH.JHSCETakeRecord>(); List <KH.JHSCETakeRecord> updateList = new List <KH.JHSCETakeRecord>(); //交叉比對各學生資料 #region 交叉比對各學生資料 foreach (string id in id_Rows.Keys) { JHStudentRecord studentRec = students[id]; foreach (RowData data in id_Rows[id]) { string examName = data["評量名稱"]; string courseName = data["課程名稱"]; string SchoolYear = data["學年度"]; string Semester = data["學期"]; // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式 bool isOrdinarilyScore = false; if (!scattends.ContainsKey(id)) { continue; } foreach (JHSCAttendRecord record in scattends[id]) { if (!courses.ContainsKey(record.RefCourseID)) { continue; } JHCourseRecord course = courses[record.RefCourseID]; //if (course.Name != courseName) continue; string sy = "", ss = ""; if (course.SchoolYear.HasValue) { sy = course.SchoolYear.Value.ToString(); } if (course.Semester.HasValue) { ss = course.Semester.Value.ToString(); } if (SchoolYear != sy || Semester != ss || course.Name != courseName) { continue; } KH.JHSCETakeRecord currentSCE = null; if (SchoolYear == sy && Semester == ss && course.Name == courseName) { // 2016/7/26,穎驊新增,由於高雄國中希望可以加入匯出匯入"平時評量的功能",在原本的Code努力尋找見縫插針的位子, //因為"平時評量"與一般的"評量成績"處理邏輯要分開 //後來決定這邊是最佳位子,邏輯為,當程序在一條一條讀取Excel Row時,讀到欄位"評量名稱"值為 "平時評量" //則進入我們處理平時評量的程序,如果欄位"評量名稱"值非為 "平時評量" 則使用它原本的邏輯處理 // 上面的CODE會幫忙進行學年、學期、課程的驗證,確保是同一門課程成績資料, //而 JHSCAttendRecord record內意外發現剛好有 平時評量OrdinarilyScore的欄位 //因此只要指定欄位為新的Excel 內的值,最後 使用JHSCAttend.Update(record) 更新即可 if (data["評量名稱"] == "平時評量") { if (data["分數評量"] != null && data["分數評量"] != "") { decimal d; // 使用TryParse 的轉換,是因為可能會有Row 的分數評量欄位是空的(EX: 社團成績) ,直接Parse會爆 if (decimal.TryParse(data["分數評量"], out d)) { record.OrdinarilyScore = d; } } if (data["努力程度"] != null) { int i; if (int.TryParse(data["努力程度"], out i)) { record.OrdinarilyEffort = i; } } if (data["文字描述"] != null) { record.Text = data["文字描述"].ToString(); } JHSCAttend.Update(record); isOrdinarilyScore = true; currentSCE = null; } else { if (existSces.ContainsKey(record.ID)) { foreach (KH.JHSCETakeRecord sce in existSces[record.ID].AsKHJHSCETakeRecords()) { if (!exams.ContainsKey(sce.RefExamID)) { continue; } if (exams[sce.RefExamID].Name == examName) { currentSCE = sce; } } } } } // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式 if (currentSCE != null && isOrdinarilyScore == false) { bool changed = false; #region 填入資料 foreach (string field in e.ImportFields) { string value = data[field]; switch (field) { case "分數評量": if ("" + currentSCE.Score != value) { decimal d; if (decimal.TryParse(value, out d)) { currentSCE.Score = d; } else { currentSCE.Score = null; } changed = true; } break; case "努力程度": if ("" + currentSCE.Effort != value) { int i; if (int.TryParse(value, out i)) { currentSCE.Effort = i; } else { currentSCE.Effort = null; } changed = true; } break; case "文字描述": if (currentSCE.Text != value) { currentSCE.Text = value; changed = true; } break; } } #endregion if (changed) { updateList.Add(currentSCE); } } // 2016/7/26,穎驊新增bool值避免 在有"平時評量"的評量名稱Row 進入算評量成績的判斷式 if (currentSCE == null && isOrdinarilyScore == false) { KH.JHSCETakeRecord newSCE = new KH.JHSCETakeRecord(new JHSCETakeRecord()); newSCE.RefStudentID = id; newSCE.RefSCAttendID = record.ID; newSCE.RefCourseID = record.RefCourseID; foreach (JHExamRecord exam in exams.Values) { if (exam.Name == examName) { newSCE.RefExamID = exam.ID; break; } } #region 填入資料 foreach (string field in e.ImportFields) { string value = data[field]; switch (field) { case "分數評量": if (value != "") { decimal d; if (decimal.TryParse(value, out d)) { newSCE.Score = d; } else { newSCE.Score = null; } } else { newSCE.Score = null; } break; case "努力程度": if (value != "") { int i; if (int.TryParse(value, out i)) { newSCE.Effort = i; } else { newSCE.Effort = null; } } else { newSCE.Effort = null; } break; case "文字描述": newSCE.Text = value; break; } } #endregion if (newSCE.RefExamID != "") { insertList.Add(newSCE); } } } } } try { // 解析並填入轉換空白的努力程度 foreach (KH.JHSCETakeRecord rec in updateList) { // 當努力程度沒有值卻有成績。 if ((rec.Effort.HasValue == false) && rec.Score.HasValue) { rec.Effort = ConvertEffort(rec.Score.Value); } } foreach (KH.JHSCETakeRecord rec in insertList) { // 當努力程度沒有值卻有成績。 if ((rec.Effort.HasValue == false) && rec.Score.HasValue) { rec.Effort = ConvertEffort(rec.Score.Value); } } if (updateList.Count > 0) { #region 分批次兩路上傳 List <List <KH.JHSCETakeRecord> > updatePackages = new List <List <KH.JHSCETakeRecord> >(); List <List <KH.JHSCETakeRecord> > updatePackages2 = new List <List <KH.JHSCETakeRecord> >(); { List <KH.JHSCETakeRecord> package = null; int count = 0; foreach (KH.JHSCETakeRecord var in updateList) { if (count == 0) { package = new List <KH.JHSCETakeRecord>(30); count = 30; if ((updatePackages.Count & 1) == 0) { updatePackages.Add(package); } else { updatePackages2.Add(package); } } package.Add(var); count--; } } Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore.IsBackground = true; threadUpdateSemesterSubjectScore.Start(updatePackages); Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore2.IsBackground = true; threadUpdateSemesterSubjectScore2.Start(updatePackages2); threadUpdateSemesterSubjectScore.Join(); threadUpdateSemesterSubjectScore2.Join(); #endregion } } catch (Exception ex) { } if (insertList.Count > 0) { #region 分批次兩路上傳 List <List <KH.JHSCETakeRecord> > insertPackages = new List <List <KH.JHSCETakeRecord> >(); List <List <KH.JHSCETakeRecord> > insertPackages2 = new List <List <KH.JHSCETakeRecord> >(); { List <KH.JHSCETakeRecord> package = null; int count = 0; foreach (KH.JHSCETakeRecord var in insertList) { if (count == 0) { package = new List <KH.JHSCETakeRecord>(30); count = 30; if ((insertPackages.Count & 1) == 0) { insertPackages.Add(package); } else { insertPackages2.Add(package); } } package.Add(var); count--; } } Thread threadInsertSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore.IsBackground = true; threadInsertSemesterSubjectScore.Start(insertPackages); Thread threadInsertSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore2.IsBackground = true; threadInsertSemesterSubjectScore2.Start(insertPackages2); threadInsertSemesterSubjectScore.Join(); threadInsertSemesterSubjectScore2.Join(); #endregion } FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入評量成績", "總共匯入" + (insertList.Count + updateList.Count) + "筆評量成績。"); #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 == "8") { 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 (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 (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["異動年級"]; } JHUpdateRecordRecord updateRec = null; foreach (JHUpdateRecordRecord urr in UpdateRecs[id]) { if (urr.SchoolYear == schoolYear && urr.Semester == Semester) { 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; } bool checkData = false; foreach (string field in e.ImportFields) { string value = data[field].Trim(); switch (field) { case "異動類別": if (value == "續讀") { updateRec.UpdateCode = "8"; 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 "備註": 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.OriginAddress = 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; } } 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) { } }; }
void wizard_ImportPackage(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { // 尋找主要Key來判斷,如果有學生系統編號先用系統編號,沒有使用學號, Dictionary <string, RowData> RowDataDict = new Dictionary <string, RowData>(); Dictionary <string, int> chkSidDict = new Dictionary <string, int>(); Dictionary <string, string> chkSnumDict = new Dictionary <string, string>(); List <JHStudentRecord> InsertStudentRecList = new List <JHStudentRecord>(); List <JHStudentRecord> StudentRecAllList = JHStudent.SelectAll(); foreach (JHStudentRecord rec in StudentRecAllList) { chkSidDict.Add(rec.ID, 0); string key = rec.StudentNumber + rec.StatusStr; if (!chkSnumDict.ContainsKey(key)) { chkSnumDict.Add(key, rec.ID); } } // 先處理學生基本資料 foreach (RowData Row in e.Items) { string StudentID = ""; if (Row.ContainsKey("學生系統編號")) { string id = Row["學生系統編號"].ToString(); if (chkSidDict.ContainsKey(id)) { StudentID = id; } } if (StudentID == "") { string ssNum = "", snum = ""; if (Row.ContainsKey("學號")) { snum = Row["學號"].ToString(); string status = "一般"; if (Row.ContainsKey("狀態")) { if (Row["狀態"].ToString() != "") { status = Row["狀態"].ToString(); } } ssNum = snum + status; } if (chkSnumDict.ContainsKey(ssNum)) { StudentID = chkSnumDict[ssNum]; } else { // 新增 if (chkSnumDict.ContainsKey(snum + "一般")) { // 有重複 } else { // 批次新增 JHStudentRecord newRec = new JHStudentRecord(); newRec.StudentNumber = snum; newRec.Status = StudentRecord.StudentStatus.一般; if (Row.ContainsKey("姓名")) { newRec.Name = Row["姓名"].ToString(); } InsertStudentRecList.Add(newRec); } } } } // 如有新學生處理新增學生 if (InsertStudentRecList.Count > 0) { JHStudent.Insert(InsertStudentRecList); } // 再次建立索引 Dictionary <string, JHStudentRecord> StudRecAllDict = new Dictionary <string, JHStudentRecord>(); StudentRecAllList = JHStudent.SelectAll(); chkSidDict.Clear(); chkSnumDict.Clear(); foreach (JHStudentRecord rec in StudentRecAllList) { chkSidDict.Add(rec.ID, 0); string key = rec.StudentNumber + rec.StatusStr; if (!chkSnumDict.ContainsKey(key)) { chkSnumDict.Add(key, rec.ID); } StudRecAllDict.Add(rec.ID, rec); } List <string> StudentIDList = new List <string>(); //比對 foreach (RowData Row in e.Items) { string StudentID = ""; if (Row.ContainsKey("學生系統編號")) { string id = Row["學生系統編號"].ToString(); if (chkSidDict.ContainsKey(id)) { StudentID = id; } } if (StudentID == "") { string ssNum = "", snum = ""; if (Row.ContainsKey("學號")) { snum = Row["學號"].ToString(); string status = "一般"; if (Row.ContainsKey("狀態")) { if (Row["狀態"].ToString() != "") { status = Row["狀態"].ToString(); } } ssNum = snum + status; } if (chkSnumDict.ContainsKey(ssNum)) { StudentID = chkSnumDict[ssNum]; } } if (!string.IsNullOrEmpty(StudentID)) { if (!RowDataDict.ContainsKey(StudentID)) { RowDataDict.Add(StudentID, Row); } StudentIDList.Add(StudentID); } } // 取得學生基本、父母監護人、電話、地址、UDT List <JHStudentRecord> StudentRecordList = JHStudent.SelectByIDs(StudentIDList); Dictionary <string, JHStudentRecord> StudentRecordDict = new Dictionary <string, JHStudentRecord>(); foreach (JHStudentRecord rec in StudentRecordList) { if (!StudentRecordDict.ContainsKey(rec.ID)) { StudentRecordDict.Add(rec.ID, rec); } } List <JHParentRecord> ParentRecordList = JHParent.SelectByStudentIDs(StudentIDList); Dictionary <string, JHParentRecord> ParentRecordDict = new Dictionary <string, JHParentRecord>(); foreach (JHParentRecord rec in ParentRecordList) { if (!ParentRecordDict.ContainsKey(rec.RefStudentID)) { ParentRecordDict.Add(rec.RefStudentID, rec); } } List <JHPhoneRecord> PhoneRecordList = JHPhone.SelectByStudentIDs(StudentIDList); Dictionary <string, JHPhoneRecord> PhoneRecordDict = new Dictionary <string, JHPhoneRecord>(); foreach (JHPhoneRecord rec in PhoneRecordList) { if (!PhoneRecordDict.ContainsKey(rec.RefStudentID)) { PhoneRecordDict.Add(rec.RefStudentID, rec); } } List <JHAddressRecord> AddressRecordList = JHAddress.SelectByStudentIDs(StudentIDList); Dictionary <string, JHAddressRecord> AddressRecordDict = new Dictionary <string, JHAddressRecord>(); foreach (JHAddressRecord rec in AddressRecordList) { if (!AddressRecordDict.ContainsKey(rec.RefStudentID)) { AddressRecordDict.Add(rec.RefStudentID, rec); } } AccessHelper accHepler = new AccessHelper(); string qry = "ref_student_id in('" + string.Join("','", StudentIDList.ToArray()) + "')"; List <StudentRecord_Ext> StudentRecord_ExtList = accHepler.Select <StudentRecord_Ext>(qry); Dictionary <string, StudentRecord_Ext> StudentRecord_ExtDict = new Dictionary <string, StudentRecord_Ext> (); foreach (StudentRecord_Ext rec in StudentRecord_ExtList) { if (!StudentRecord_ExtDict.ContainsKey(rec.RefStudentID)) { StudentRecord_ExtDict.Add(rec.RefStudentID, rec); } } // 開始處理 List <JHStudentRecord> updateStudentRecList = new List <JHStudentRecord>(); List <JHParentRecord> updateParentRecList = new List <JHParentRecord>(); List <JHPhoneRecord> updatePhoneList = new List <JHPhoneRecord>(); List <JHAddressRecord> updateAddressList = new List <JHAddressRecord>(); List <StudentRecord_Ext> insertStudentRecord_ExtList = new List <StudentRecord_Ext>(); List <StudentRecord_Ext> updateStudentRecord_ExtList = new List <StudentRecord_Ext>(); List <JHClassRecord> classRecAllList = JHClass.SelectAll(); Dictionary <string, string> classNameIDDict = new Dictionary <string, string>(); foreach (JHClassRecord rec in classRecAllList) { classNameIDDict.Add(rec.Name, rec.ID); } StringBuilder sbLog = new StringBuilder(); foreach (string StudentID in RowDataDict.Keys) { RowData rd = RowDataDict[StudentID]; if (StudentRecordDict.ContainsKey(StudentID)) { string tt = "學生系統編號:" + StudentID + ",學號:" + StudentRecordDict[StudentID].StudentNumber; if (StudentRecordDict[StudentID].Class != null) { tt += "班級:" + StudentRecordDict[StudentID].Class.Name; } if (StudentRecordDict[StudentID].SeatNo.HasValue) { tt += "座號:" + StudentRecordDict[StudentID].SeatNo.Value; } sbLog.AppendLine(tt); if (rd.ContainsKey("學號")) { string value = rd["學號"].ToString(); if (StudentRecordDict[StudentID].StudentNumber != value) { sbLog.AppendLine(string.Format("學號由「{0}」改為「{1}」", StudentRecordDict[StudentID].StudentNumber, value)); } StudentRecordDict[StudentID].StudentNumber = value; } if (rd.ContainsKey("班級")) { string value = rd["班級"].ToString(); string oldValue = ""; if (StudentRecordDict[StudentID].Class != null) { oldValue = StudentRecordDict[StudentID].Class.Name; } if (oldValue != value) { sbLog.AppendLine(string.Format("班級由「{0}」改為「{1}」", oldValue, value)); } if (classNameIDDict.ContainsKey(value)) { StudentRecordDict[StudentID].RefClassID = classNameIDDict[value]; } } if (rd.ContainsKey("座號")) { string value = rd["座號"].ToString(); string oldValue = ""; if (StudentRecordDict[StudentID].SeatNo.HasValue) { oldValue = StudentRecordDict[StudentID].SeatNo.Value.ToString(); } if (oldValue != value) { sbLog.AppendLine(string.Format("座號由「{0}」改為「{1}」", oldValue, value)); } StudentRecordDict[StudentID].SeatNo = null; int i; if (int.TryParse(value, out i)) { StudentRecordDict[StudentID].SeatNo = i; } } if (rd.ContainsKey("姓名")) { string value = rd["姓名"].ToString(); if (StudentRecordDict[StudentID].Name != value) { sbLog.AppendLine(string.Format("姓名由「{0}」改為「{1}」", StudentRecordDict[StudentID].Name, value)); } StudentRecordDict[StudentID].Name = value; } if (rd.ContainsKey("身分證號")) { string value = rd["身分證號"].ToString(); if (StudentRecordDict[StudentID].IDNumber != value) { sbLog.AppendLine(string.Format("身分證號由「{0}」改為「{1}」", StudentRecordDict[StudentID].IDNumber, value)); } StudentRecordDict[StudentID].IDNumber = value; } if (rd.ContainsKey("國籍")) { string value = rd["國籍"].ToString(); if (StudentRecordDict[StudentID].Nationality != value) { sbLog.AppendLine(string.Format("國籍由「{0}」改為「{1}」", StudentRecordDict[StudentID].Nationality, value)); } StudentRecordDict[StudentID].Nationality = value; } if (rd.ContainsKey("出生地")) { string value = rd["出生地"].ToString(); if (StudentRecordDict[StudentID].BirthPlace != value) { sbLog.AppendLine(string.Format("出生地由「{0}」改為「{1}」", StudentRecordDict[StudentID].BirthPlace, value)); } StudentRecordDict[StudentID].BirthPlace = value; } if (rd.ContainsKey("生日")) { string value = rd["生日"].ToString(); string oldValue = ""; if (StudentRecordDict[StudentID].Birthday.HasValue) { oldValue = StudentRecordDict[StudentID].Birthday.Value.ToShortDateString(); } if (oldValue != value) { sbLog.AppendLine(string.Format("生日由「{0}」改為「{1}」", oldValue, value)); } StudentRecordDict[StudentID].Birthday = null; DateTime dt; if (DateTime.TryParse(value, out dt)) { StudentRecordDict[StudentID].Birthday = dt; } } if (rd.ContainsKey("性別")) { string value = rd["性別"].ToString(); if (StudentRecordDict[StudentID].Gender != value) { sbLog.AppendLine(string.Format("性別由「{0}」改為「{1}」", StudentRecordDict[StudentID].Gender, value)); } StudentRecordDict[StudentID].Gender = value; } if (rd.ContainsKey("英文姓名")) { string value = rd["英文姓名"].ToString(); if (StudentRecordDict[StudentID].EnglishName != value) { sbLog.AppendLine(string.Format("英文姓名由「{0}」改為「{1}」", StudentRecordDict[StudentID].EnglishName, value)); } StudentRecordDict[StudentID].EnglishName = value; } if (rd.ContainsKey("登入帳號")) { string value = rd["登入帳號"].ToString(); if (StudentRecordDict[StudentID].SALoginName != value) { sbLog.AppendLine(string.Format("登入帳號由「{0}」改為「{1}」", StudentRecordDict[StudentID].SALoginName, value)); } StudentRecordDict[StudentID].SALoginName = value; } if (rd.ContainsKey("狀態")) { string value = rd["狀態"].ToString(); string oldValue = StudentRecordDict[StudentID].StatusStr; if (oldValue != value) { sbLog.AppendLine(string.Format("狀態由「{0}」改為「{1}」", oldValue, value)); } switch (value) { case "": case "一般": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.一般; break; case "畢業或離校": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.畢業或離校; break; case "休學": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.休學; break; case "輟學": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.輟學; break; case "刪除": StudentRecordDict[StudentID].Status = StudentRecord.StudentStatus.刪除; break; } } } // 和班級走 //if (rd.ContainsKey("年級") && StudentRecordDict.ContainsKey(StudentID)) { string value = rd["年級"].ToString(); } StudentRecord_Ext exRec = null; bool isNewExRec = false; if (StudentRecord_ExtDict.ContainsKey(StudentID)) { exRec = StudentRecord_ExtDict[StudentID]; } else { exRec = new StudentRecord_Ext(); exRec.RefStudentID = StudentID; isNewExRec = true; } if (rd.ContainsKey("英文別名")) { string value = rd["英文別名"].ToString(); if (exRec.Nickname != value) { sbLog.AppendLine(string.Format("英文別名由「{0}」改為「{1}」", exRec.Nickname, value)); } exRec.Nickname = value; } if (rd.ContainsKey("居留證號")) { string value = rd["居留證號"].ToString(); if (exRec.PassportNumber != value) { sbLog.AppendLine(string.Format("居留證號由「{0}」改為「{1}」", exRec.PassportNumber, value)); } exRec.PassportNumber = value; } if (rd.ContainsKey("GivenName")) { string value = rd["GivenName"].ToString(); if (exRec.GivenName != value) { sbLog.AppendLine(string.Format("GivenName由「{0}」改為「{1}」", exRec.GivenName, value)); } exRec.GivenName = value; } if (rd.ContainsKey("MiddleName")) { string value = rd["MiddleName"].ToString(); if (exRec.MiddleName != value) { sbLog.AppendLine(string.Format("MiddleName由「{0}」改為「{1}」", exRec.MiddleName, value)); } exRec.MiddleName = value; } if (rd.ContainsKey("FamilyName")) { string value = rd["FamilyName"].ToString(); if (exRec.FamilyName != value) { sbLog.AppendLine(string.Format("FamilyName由「{0}」改為「{1}」", exRec.FamilyName, value)); } exRec.FamilyName = value; } if (rd.ContainsKey("入學日期")) { string value = rd["入學日期"].ToString(); string oldValue = ""; if (exRec.EntranceDate.HasValue) { oldValue = exRec.EntranceDate.Value.ToShortDateString(); } exRec.EntranceDate = null; if (oldValue != value) { sbLog.AppendLine(string.Format("入學日期由「{0}」改為「{1}」", oldValue, value)); } DateTime dt1; if (DateTime.TryParse(value, out dt1)) { exRec.EntranceDate = dt1; } } if (rd.ContainsKey("畢業日期")) { string value = rd["畢業日期"].ToString(); string oldValue = ""; if (exRec.LeavingDate.HasValue) { oldValue = exRec.LeavingDate.Value.ToShortDateString(); } if (oldValue != value) { sbLog.AppendLine(string.Format("畢業日期由「{0}」改為「{1}」", oldValue, value)); } exRec.LeavingDate = null; DateTime dt2; if (DateTime.TryParse(value, out dt2)) { exRec.LeavingDate = dt2; } } if (isNewExRec) { insertStudentRecord_ExtList.Add(exRec); } else { updateStudentRecord_ExtList.Add(exRec); } if (ParentRecordDict.ContainsKey(StudentID)) { if (rd.ContainsKey("父親姓名")) { string value = rd["父親姓名"].ToString(); string oldValue = ParentRecordDict[StudentID].Father.Name; if (oldValue != value) { sbLog.AppendLine(string.Format("父親姓名由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Father.Name = value; } if (rd.ContainsKey("父親學歷")) { string value = rd["父親學歷"].ToString(); string oldValue = ParentRecordDict[StudentID].Father.EducationDegree; if (oldValue != value) { sbLog.AppendLine(string.Format("父親學歷由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Father.EducationDegree = value; } if (rd.ContainsKey("父親職業")) { string value = rd["父親職業"].ToString(); string oldValue = ParentRecordDict[StudentID].Father.Job; if (oldValue != value) { sbLog.AppendLine(string.Format("父親職業由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Father.Job = value; } if (rd.ContainsKey("父親電話")) { string value = rd["父親電話"].ToString(); string oldValue = ParentRecordDict[StudentID].Father.Phone; if (oldValue != value) { sbLog.AppendLine(string.Format("父親電話由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Father.Phone = value; } if (rd.ContainsKey("父親電子郵件")) { string value = rd["父親電子郵件"].ToString(); string oldValue = ParentRecordDict[StudentID].Father.EMail; if (oldValue != value) { sbLog.AppendLine(string.Format("父親電子郵件由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Father.EMail = value; } if (rd.ContainsKey("母親姓名")) { string value = rd["母親姓名"].ToString(); string oldValue = ParentRecordDict[StudentID].Mother.Name; if (oldValue != value) { sbLog.AppendLine(string.Format("母親姓名由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Mother.Name = value; } if (rd.ContainsKey("母親學歷")) { string value = rd["母親學歷"].ToString(); string oldValue = ParentRecordDict[StudentID].Mother.EducationDegree; if (oldValue != value) { sbLog.AppendLine(string.Format("母親學歷由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Mother.EducationDegree = value; } if (rd.ContainsKey("母親職業")) { string value = rd["母親職業"].ToString(); string oldValue = ParentRecordDict[StudentID].Mother.Job; if (oldValue != value) { sbLog.AppendLine(string.Format("母親職業由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Mother.Job = value; } if (rd.ContainsKey("母親電話")) { string value = rd["母親電話"].ToString(); string oldValue = ParentRecordDict[StudentID].Mother.Phone; if (oldValue != value) { sbLog.AppendLine(string.Format("母親電話由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Mother.Phone = value; } if (rd.ContainsKey("母親電子郵件")) { string value = rd["母親電子郵件"].ToString(); string oldValue = ParentRecordDict[StudentID].Mother.EMail; if (oldValue != value) { sbLog.AppendLine(string.Format("母親電子郵件由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Mother.EMail = value; } if (rd.ContainsKey("監護人姓名")) { string value = rd["監護人姓名"].ToString(); string oldValue = ParentRecordDict[StudentID].Custodian.Name; if (oldValue != value) { sbLog.AppendLine(string.Format("監護人姓名由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Custodian.Name = value; } if (rd.ContainsKey("監護人電話")) { string value = rd["監護人電話"].ToString(); string oldValue = ParentRecordDict[StudentID].Custodian.Phone; if (oldValue != value) { sbLog.AppendLine(string.Format("監護人電話由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Custodian.Phone = value; } if (rd.ContainsKey("監護人電子郵件")) { string value = rd["監護人電子郵件"].ToString(); string oldValue = ParentRecordDict[StudentID].Custodian.EMail; if (oldValue != value) { sbLog.AppendLine(string.Format("監護人電子郵件由「{0}」改為「{1}」", oldValue, value)); } ParentRecordDict[StudentID].Custodian.EMail = value; } updateParentRecList.Add(ParentRecordDict[StudentID]); } if (PhoneRecordDict.ContainsKey(StudentID)) { if (rd.ContainsKey("戶籍電話")) { string value = rd["戶籍電話"].ToString(); string oldValue = PhoneRecordDict[StudentID].Permanent; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍電話由「{0}」改為「{1}」", oldValue, value)); } PhoneRecordDict[StudentID].Permanent = value; } if (rd.ContainsKey("聯絡電話")) { string value = rd["聯絡電話"].ToString(); string oldValue = PhoneRecordDict[StudentID].Contact; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡電話由「{0}」改為「{1}」", oldValue, value)); } PhoneRecordDict[StudentID].Contact = value; } if (rd.ContainsKey("行動電話")) { string value = rd["行動電話"].ToString(); string oldValue = PhoneRecordDict[StudentID].Cell; if (oldValue != value) { sbLog.AppendLine(string.Format("行動電話由「{0}」改為「{1}」", oldValue, value)); } PhoneRecordDict[StudentID].Cell = value; } if (rd.ContainsKey("其它電話1")) { string value = rd["其它電話1"].ToString(); string oldValue = PhoneRecordDict[StudentID].Phone1; if (oldValue != value) { sbLog.AppendLine(string.Format("其它電話1由「{0}」改為「{1}」", oldValue, value)); } PhoneRecordDict[StudentID].Phone1 = value; } updatePhoneList.Add(PhoneRecordDict[StudentID]); } if (AddressRecordDict.ContainsKey(StudentID)) { if (rd.ContainsKey("戶籍:郵遞區號")) { string value = rd["戶籍:郵遞區號"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.ZipCode; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:郵遞區號由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.ZipCode = value; } if (rd.ContainsKey("戶籍:縣市")) { string value = rd["戶籍:縣市"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.County; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:縣市由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.County = value; } if (rd.ContainsKey("戶籍:鄉鎮市區")) { string value = rd["戶籍:鄉鎮市區"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.Town; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:鄉鎮市區由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.Town = value; } if (rd.ContainsKey("戶籍:村里")) { string value = rd["戶籍:村里"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.District; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:村里由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.District = value; } if (rd.ContainsKey("戶籍:鄰")) { string value = rd["戶籍:鄰"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.Area; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:鄰由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.Area = value; } if (rd.ContainsKey("戶籍:其他")) { string value = rd["戶籍:其他"].ToString(); string oldValue = AddressRecordDict[StudentID].Permanent.Detail; if (oldValue != value) { sbLog.AppendLine(string.Format("戶籍:其他由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Permanent.Detail = value; } if (rd.ContainsKey("聯絡:郵遞區號")) { string value = rd["聯絡:郵遞區號"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.ZipCode; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:郵遞區號由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.ZipCode = value; } if (rd.ContainsKey("聯絡:縣市")) { string value = rd["聯絡:縣市"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.County; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:縣市由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.County = value; } if (rd.ContainsKey("聯絡:鄉鎮市區")) { string value = rd["聯絡:鄉鎮市區"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.Town; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:鄉鎮市區由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.Town = value; } if (rd.ContainsKey("聯絡:村里")) { string value = rd["聯絡:村里"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.District; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:村里由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.District = value; } if (rd.ContainsKey("聯絡:鄰")) { string value = rd["聯絡:鄰"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.Area; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:鄰由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.Area = value; } if (rd.ContainsKey("聯絡:其他")) { string value = rd["聯絡:其他"].ToString(); string oldValue = AddressRecordDict[StudentID].Mailing.Detail; if (oldValue != value) { sbLog.AppendLine(string.Format("聯絡:其他由「{0}」改為「{1}」", oldValue, value)); } AddressRecordDict[StudentID].Mailing.Detail = value; } sbLog.AppendLine(); updateAddressList.Add(AddressRecordDict[StudentID]); } } // 處理學生資料 foreach (string key in StudentRecordDict.Keys) { updateStudentRecList.Add(StudentRecordDict[key]); } if (updateStudentRecList.Count > 0) { JHStudent.Update(updateStudentRecList); } if (updateParentRecList.Count > 0) { JHParent.Update(updateParentRecList); } if (updatePhoneList.Count > 0) { JHPhone.Update(updatePhoneList); } if (updateAddressList.Count > 0) { JHAddress.Update(updateAddressList); } if (insertStudentRecord_ExtList.Count > 0) { insertStudentRecord_ExtList.SaveAll(); } if (updateStudentRecord_ExtList.Count > 0) { updateStudentRecord_ExtList.SaveAll(); } FISCA.LogAgent.ApplicationLog.Log("匯入學生基本資料(New)", "匯入", sbLog.ToString()); // 同步 JHSchool.Student.Instance.SyncAllBackground(); JHSchool.Data.JHStudent.RemoveAll(); JHSchool.Data.JHStudent.SelectAll(); }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { //學生資訊 Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); //學生修課資訊 studentID -> List:SCAttendRecord Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSCAttendRecord> >(); //學生修習的課程 courseID -> CourseRecord Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHCourseRecord>(); //所有課程(依學年度學期分開) schoolYear_semester -> (courseName -> CourseRecord) Dictionary <string, Dictionary <string, JHCourseRecord> > allcourses = new Dictionary <string, Dictionary <string, JHCourseRecord> >(); //studentID_schoolYear_semester -> List:courseName Dictionary <string, List <string> > semesterCourseName = new Dictionary <string, List <string> >(); //準備加入修課的資料 studentID -> (schoolYear_semester_courseName -> RowData) Dictionary <string, Dictionary <string, RowData> > prepareAttends = new Dictionary <string, Dictionary <string, RowData> >(); wizard.PackageLimit = 3000; if (Item != "社團") { wizard.ImportableFields.Add("課程系統編號"); } wizard.ImportableFields.AddRange("學年度", "學期"); if (Item != "社團") { wizard.ImportableFields.Add("課程名稱"); } else { wizard.ImportableFields.Add("社團名稱"); } wizard.ImportableFields.AddRange("班級", "座號"); wizard.RequiredFields.AddRange("學年度", "學期"); if (Item != "社團") { wizard.RequiredFields.Add("課程名稱"); } else { wizard.RequiredFields.Add("社團名稱"); } wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { #region 取得學生資訊 foreach (JHStudentRecord stu in JHStudent.SelectByIDs(e.List)) { if (!students.ContainsKey(stu.ID)) { students.Add(stu.ID, stu); } } #endregion #region 取得修課記錄 MultiThreadWorker <string> loader1 = new MultiThreadWorker <string>(); loader1.MaxThreads = 3; loader1.PackageSize = 250; loader1.PackageWorker += delegate(object sender1, PackageWorkEventArgs <string> e1) { foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e1.List, new string[] { })) { if (!scattends.ContainsKey(record.RefStudentID)) { scattends.Add(record.RefStudentID, new List <JHSCAttendRecord>()); } scattends[record.RefStudentID].Add(record); if (!courses.ContainsKey(record.RefCourseID)) { courses.Add(record.RefCourseID, null); } } }; loader1.Run(e.List); #endregion #region 取得課程資訊 MultiThreadWorker <string> loader2 = new MultiThreadWorker <string>(); loader2.MaxThreads = 3; loader2.PackageSize = 250; loader2.PackageWorker += delegate(object sender2, PackageWorkEventArgs <string> e2) { foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(e2.List))) { if (courses.ContainsKey(record.ID)) { courses[record.ID] = record; } } }; loader2.Run(courses.Keys); foreach (JHCourseRecord course in JHCourse.SelectAll()) { string key = course.SchoolYear + "_" + course.Semester; if (!allcourses.ContainsKey(key)) { allcourses.Add(key, new Dictionary <string, JHCourseRecord>()); } if (!allcourses[key].ContainsKey(course.Name)) { allcourses[key].Add(course.Name, course); } } #endregion }; wizard.ValidateRow += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateRowEventArgs e) { int i; #region 檢查學生是否存在 JHStudentRecord student = null; if (students.ContainsKey(e.Data.ID)) { student = students[e.Data.ID]; } else { e.ErrorMessage = "壓根就沒有這個學生" + e.Data.ID; return; } #endregion #region 驗證各個欄位格式 bool inputFormatPass = true; foreach (string field in e.SelectFields) { string value = e.Data[field]; switch (field) { default: break; case "學年度": case "學期": if (value == "" || !int.TryParse(value, out i)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入整數"); } break; case "課程名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入課程名稱"); } break; case "社團名稱": if (value == "") { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入社團名稱"); } break; case "班級": if (value == "") { } break; case "座號": if (value != "" && !int.TryParse(value, out i)) { inputFormatPass &= false; e.ErrorFields.Add(field, "必須填入空白或整數"); } break; } } #endregion //輸入格式正確才會針對情節做檢驗 #region 驗證各種情節 if (inputFormatPass) { string errorMessage = ""; string sy = e.Data["學年度"]; string se = e.Data["學期"]; string courseName = (Item != "社團") ? e.Data["課程名稱"] : e.Data["社團名稱"]; string key = e.Data.ID + "_" + sy + "_" + se; string semsKey = sy + "_" + se; //int schoolyear = Framework.Int.ParseInt(sy); //int semester = Framework.Int.ParseInt(se); #region 一個學年度學期不能有重覆的課程名稱 if (!semesterCourseName.ContainsKey(key)) { semesterCourseName.Add(key, new List <string>()); } if (semesterCourseName[key].Contains(courseName)) { if (Item != "社團") { errorMessage += (errorMessage == "" ? "" : "\n") + " 同一學年度學期不允許修習多筆相同名稱的課程"; } else { errorMessage += (errorMessage == "" ? "" : "\n") + " 同一學年度學期不允許參與多個相同名稱的社團"; } } else { semesterCourseName[key].Add(courseName); } #endregion #region 檢查課程是否存在系統中 bool noCourse = false; if (!allcourses.ContainsKey(semsKey)) { noCourse = true; if (Item != "社團") { errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else { errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該社團"; } } else if (!allcourses[semsKey].ContainsKey(courseName)) { noCourse = true; if (Item != "社團") { errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該課程"; } else { errorMessage += (errorMessage == "" ? "" : "\n") + " 系統中找不到該社團"; } } else { } #endregion #region 檢查學生是否有修此課程 bool attended = false; if (scattends.ContainsKey(e.Data.ID)) { foreach (JHSCAttendRecord record in scattends[e.Data.ID]) { if (courses[record.RefCourseID].Name == courseName && "" + courses[record.RefCourseID].SchoolYear == sy && "" + courses[record.RefCourseID].Semester == se) { attended = true; } } } else //學生沒修半堂課 { } if (!attended && !noCourse) { if (Item != "社團") { if (!e.WarningFields.ContainsKey("無修課記錄")) { e.WarningFields.Add("無修課記錄", "學生在此學期並無修習此課程,將會新增修課記錄"); } } else { if (!e.WarningFields.ContainsKey("無參與記錄")) { e.WarningFields.Add("無參與記錄", "學生在此學期並無參與此社團,將會新增參與記錄"); } } if (!prepareAttends.ContainsKey(e.Data.ID)) { prepareAttends.Add(e.Data.ID, new Dictionary <string, RowData>()); } if (!prepareAttends[e.Data.ID].ContainsKey(semsKey + "_" + courseName)) { prepareAttends[e.Data.ID].Add(semsKey + "_" + courseName, e.Data); } } #endregion e.ErrorMessage = errorMessage; } #endregion }; wizard.ImportPackage += delegate(object sender, SmartSchool.API.PlugIn.Import.ImportPackageEventArgs e) { Dictionary <string, List <RowData> > id_Rows = new Dictionary <string, List <RowData> >(); #region 分包裝 foreach (RowData data in e.Items) { if (!id_Rows.ContainsKey(data.ID)) { id_Rows.Add(data.ID, new List <RowData>()); } id_Rows[data.ID].Add(data); } #endregion List <JHSCAttendRecord> insertList = new List <JHSCAttendRecord>(); List <JHSCAttendRecord> updateList = new List <JHSCAttendRecord>(); //交叉比對各學生資料 #region 交叉比對各學生資料 foreach (string id in id_Rows.Keys) { JHStudentRecord studentRec = students[id]; #region 處理要新增的修課記錄 if (prepareAttends.ContainsKey(id)) { foreach (RowData data in prepareAttends[id].Values) { string sy = data["學年度"]; string se = data["學期"]; string semsKey = sy + "_" + se; string courseName = (Item != "社團") ? data["課程名稱"] : data["社團名稱"]; if (allcourses.ContainsKey(semsKey) && allcourses[semsKey].ContainsKey(courseName)) { JHSCAttendRecord record = new JHSCAttendRecord(); record.RefStudentID = id; record.RefCourseID = allcourses[semsKey][courseName].ID; insertList.Add(record); } } } #endregion } try { if (updateList.Count > 0) { #region 分批次兩路上傳 List <List <JHSCAttendRecord> > updatePackages = new List <List <JHSCAttendRecord> >(); List <List <JHSCAttendRecord> > updatePackages2 = new List <List <JHSCAttendRecord> >(); { List <JHSCAttendRecord> package = null; int count = 0; foreach (JHSCAttendRecord var in updateList) { if (count == 0) { package = new List <JHSCAttendRecord>(30); count = 30; if ((updatePackages.Count & 1) == 0) { updatePackages.Add(package); } else { updatePackages2.Add(package); } } package.Add(var); count--; } } Thread threadUpdateSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore.IsBackground = true; threadUpdateSemesterSubjectScore.Start(updatePackages); Thread threadUpdateSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Update)); threadUpdateSemesterSubjectScore2.IsBackground = true; threadUpdateSemesterSubjectScore2.Start(updatePackages2); threadUpdateSemesterSubjectScore.Join(); threadUpdateSemesterSubjectScore2.Join(); #endregion } } catch (Exception ex) { } if (insertList.Count > 0) { #region 分批次兩路上傳 List <List <JHSCAttendRecord> > insertPackages = new List <List <JHSCAttendRecord> >(); List <List <JHSCAttendRecord> > insertPackages2 = new List <List <JHSCAttendRecord> >(); { List <JHSCAttendRecord> package = null; int count = 0; foreach (JHSCAttendRecord var in insertList) { if (count == 0) { package = new List <JHSCAttendRecord>(30); count = 30; if ((insertPackages.Count & 1) == 0) { insertPackages.Add(package); } else { insertPackages2.Add(package); } } package.Add(var); count--; } } Thread threadInsertSemesterSubjectScore = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore.IsBackground = true; threadInsertSemesterSubjectScore.Start(insertPackages); Thread threadInsertSemesterSubjectScore2 = new Thread(new ParameterizedThreadStart(Insert)); threadInsertSemesterSubjectScore2.IsBackground = true; threadInsertSemesterSubjectScore2.Start(insertPackages2); threadInsertSemesterSubjectScore.Join(); threadInsertSemesterSubjectScore2.Join(); #endregion } if (Item != "社團") { FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯入課程修課學生", "總共匯入" + (insertList.Count + updateList.Count) + "筆課程修課學生。"); } #endregion }; }
public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { //SmartSchool.API.PlugIn.VirtualCheckBox filterRepeat = new SmartSchool.API.PlugIn.VirtualCheckBox("自動略過重讀成績", true); //wizard.Options.Add(filterRepeat); wizard.ExportableFields.AddRange("領域", "分數評量"); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { #region ExportPackage List <JHStudentRecord> students = JHStudent.SelectByIDs(e.List); GradScore.Instance.SyncDataBackground(e.List); foreach (JHStudentRecord stu in students) { GradScoreRecord record = GradScore.Instance.Items[stu.ID]; if (record == null) { continue; } foreach (GradDomainScore domain in record.Domains.Values) { RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "領域": row.Add(field, "" + domain.Domain); break; case "分數評量": row.Add(field, "" + domain.Score); break; } } } e.Items.Add(row); } foreach (string item in new string[] { "學習領域", "課程學習" }) { RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "領域": row.Add(field, item); break; case "分數評量": if (item == "學習領域") { row.Add("分數評量", "" + record.LearnDomainScore); } else if (item == "課程學習") { row.Add("分數評量", "" + record.CourseLearnScore); } break; } } } e.Items.Add(row); } } #endregion FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出畢業成績", "總共匯出" + e.Items.Count + "筆畢業成績。"); }; }
// 載入修課學生與成績到畫面 private void LoadSCAttendScoreToDGV() { // 取得修課成績 foreach (JHSCAttendRecord rec in JHSCAttend.SelectByCourseIDs(CIDs)) { if (!_SCAttendListDic.ContainsKey(rec.RefStudentID)) { _SCAttendListDic.Add(rec.RefStudentID, rec); } } // 組成學生課程成績 foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(_SCAttendListDic.Keys)) { // 過濾非一般生 if (studRec.Status != K12.Data.StudentRecord.StudentStatus.一般) { continue; } StudentSCAtendScore sscas = new StudentSCAtendScore(); sscas.StudentID = studRec.ID; if (studRec.Class != null) { sscas.ClassName = studRec.Class.Name; // 小郭, 2012/12/27 sscas.ClassId = studRec.Class.ID; } if (studRec.SeatNo.HasValue) { sscas.SeatNo = studRec.SeatNo.Value; } sscas.Name = studRec.Name; sscas.StudentNumber = studRec.StudentNumber; if (_SCAttendListDic.ContainsKey(studRec.ID)) { sscas.SCAtendRec = _SCAttendListDic[studRec.ID]; } _StudentSCAtendScoreList.Add(sscas); } // 排序 _StudentSCAtendScoreList.Sort(new Comparison <StudentSCAtendScore>(SortStudSeatNo)); // 載入值 dgv.SuspendLayout(); dgv.Rows.Clear(); int dgRowIdx = 0; foreach (StudentSCAtendScore sscas in _StudentSCAtendScoreList) { dgv.Rows.Add(); dgv.Rows[dgRowIdx].Cells[colClassName.Index].Value = sscas.ClassName; dgv.Rows[dgRowIdx].Cells[colSeatNo.Index].Value = sscas.SeatNo; dgv.Rows[dgRowIdx].Cells[colName.Index].Value = sscas.Name; dgv.Rows[dgRowIdx].Cells[colStudentNumber.Index].Value = sscas.StudentNumber; dgv.Rows[dgRowIdx].Cells[colInputScore.Index].Value = sscas.GetOrdinarilyScore(); dgv.Rows[dgRowIdx].Cells[colInputEffort.Index].Value = sscas.GetOrdinarilyEffort(); dgv.Rows[dgRowIdx].Tag = sscas.StudentID; dgRowIdx++; } dgv.ResumeLayout(); }
public void Execute() { SmartSchool.Customization.PlugIn.Global.SetStatusBarMessage("處理中,請稍候...", 0); this._book.Worksheets[0].Cells.Clear(); int row = 0; int page = 1; // 將所選取的班級,資料取出 foreach (CourseRecord cr in this._CourseList) { #region 標題 { this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 0, row); this._book.Worksheets[0].Cells[row++, 0].PutValue(cr.SchoolYear + "學年度第" + cr.Semester + "學期 課程學生修課清單"); } #endregion #region 第二行 { this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 1, row); // 課程名稱 this._book.Worksheets[0].Cells[row, 1].PutValue(cr.Name); // 節次/權數 this._book.Worksheets[0].Cells[row, 6].PutValue(cr.Period); #region 授課教師 { if (cr.GetFirstTeacher() != null) { this._book.Worksheets[0].Cells[row, 8].PutValue(cr.GetFirstTeacher().Name); } if (cr.GetSecondTeacher() != null) { this._book.Worksheets[0].Cells[row, 8].PutValue(this._book.Worksheets[0].Cells[row, 6].StringValue + "," + cr.GetSecondTeacher().Name); } if (cr.GetThirdTeacher() != null) { this._book.Worksheets[0].Cells[row, 8].PutValue(this._book.Worksheets[0].Cells[row, 6].StringValue + "," + cr.GetThirdTeacher().Name); } //欄位重新定位 this._book.Worksheets[0].AutoFitColumn(8, row, row); } #endregion row++; } #endregion IEnumerable <JHSchool.Data.JHSCAttendRecord> scr = JHSchool.Data.JHSCAttend.SelectByCourseIDs(new string[] { cr.ID }); IEnumerable <string> studentids = from screc in scr select screc.RefStudentID; // 取得一般生 List <JHSchool.Data.JHStudentRecord> students = JHStudent.SelectByIDs(studentids).Where(x => x.Status == K12.Data.StudentRecord.StudentStatus.一般).ToList(); students.Sort(ParseStudent); #region 第三行 { this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 2, row); // 所屬科目 this._book.Worksheets[0].Cells[row, 1].PutValue(cr.Subject); #region 修課人數 { if (cr.Class == null) { this._book.Worksheets[0].Cells[row, 8].PutValue(null); } else { // 修課學生人數 this._book.Worksheets[0].Cells[row, 8].PutValue(students.Count); } } #endregion row++; } #endregion this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 3, row++); #region 填入課程的修課學生資料 { int n = 0; foreach (JHStudentRecord student in students) { n++; if (students.Count == n) { this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 6, row); } else { this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 5, row); } #region 學生班級 { if (student.Class != null) { this._book.Worksheets[0].Cells[row, 0].PutValue(student.Class.Name); } else { this._book.Worksheets[0].Cells[row, 0].PutValue(""); } } #endregion this._book.Worksheets[0].Cells[row, 1].PutValue(student.SeatNo); // 座號 this._book.Worksheets[0].Cells[row, 2].PutValue(student.StudentNumber); // 學號 this._book.Worksheets[0].Cells[row, 3].PutValue(student.EnglishName); // 英文姓名 this._book.Worksheets[0].Cells[row, 5].PutValue(student.Name); // 姓名 this._book.Worksheets[0].Cells[row, 7].PutValue(student.Gender); // 性別 row++; } } #endregion this._book.Worksheets[0].Cells.CopyRow(this._template.Worksheets[0].Cells, 7, row); this._book.Worksheets[0].Cells[row, 7].PutValue("第" + page + "頁/共" + _CourseList.Count + "頁"); row++; page++; this._book.Worksheets[0].HorizontalPageBreaks.Add(row, 0); } Save(); }
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; ErrorViewer viewer = new 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 override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { // 2018.09.06 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 項目,增加 "領域", "科目", "節數(權重)", "學分" 項目資料。 // 2018.09.07 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 新需求更動項目排序。 wizard.ExportableFields.AddRange("學年度", "學期", "課程名稱", "領域", "科目", "節數(權重)", "學分", "評量名稱", "定期分數", "平時分數", "文字描述"); wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e) { //學生資訊 List <JHStudentRecord> students = JHStudent.SelectByIDs(e.List); //學生修課資訊 Dictionary <string, List <JHSCAttendRecord> > scattends = new Dictionary <string, List <JHSchool.Data.JHSCAttendRecord> >(); //學生修習的課程 Dictionary <string, JHCourseRecord> courses = new Dictionary <string, JHSchool.Data.JHCourseRecord>(); //評量成績 key: SCAttendID Dictionary <string, List <HC.JHSCETakeRecord> > sces = new Dictionary <string, List <HC.JHSCETakeRecord> >(); //試別資訊 Dictionary <string, JHExamRecord> exams = new Dictionary <string, JHSchool.Data.JHExamRecord>(); #region 取得修課記錄 foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(e.List, new string[] { })) { if (!scattends.ContainsKey(record.RefStudentID)) { scattends.Add(record.RefStudentID, new List <JHSchool.Data.JHSCAttendRecord>()); } scattends[record.RefStudentID].Add(record); if (!courses.ContainsKey(record.RefCourseID)) { courses.Add(record.RefCourseID, null); } } #endregion #region 取得課程資訊 foreach (JHCourseRecord record in JHCourse.SelectByIDs(new List <string>(courses.Keys))) { if (courses.ContainsKey(record.ID)) { courses[record.ID] = record; } } #endregion #region 取得試別資訊 foreach (JHExamRecord exam in JHExam.SelectAll()) { if (!exams.ContainsKey(exam.ID)) { exams.Add(exam.ID, exam); } } #endregion #region 取得評量成績 foreach (HC.JHSCETakeRecord record in JHSCETake.SelectByStudentAndCourse(new List <string>(scattends.Keys), new List <string>(courses.Keys)).AsHCJHSCETakeRecords()) { if (!sces.ContainsKey(record.RefSCAttendID)) { sces.Add(record.RefSCAttendID, new List <HC.JHSCETakeRecord>()); } sces[record.RefSCAttendID].Add(record); } #endregion #region 取得評量成績缺考暨免試設定 PluginMain.ScoreTextMap.Clear(); PluginMain.ScoreValueMap.Clear(); Framework.ConfigData cd = JHSchool.School.Configuration["評量成績缺考暨免試設定"]; if (!string.IsNullOrEmpty(cd["評量成績缺考暨免試設定"])) { XmlElement element = Framework.XmlHelper.LoadXml(cd["評量成績缺考暨免試設定"]); foreach (XmlElement each in element.SelectNodes("Setting")) { var UseText = each.SelectSingleNode("UseText").InnerText; var AllowCalculation = bool.Parse(each.SelectSingleNode("AllowCalculation").InnerText); decimal Score; decimal.TryParse(each.SelectSingleNode("Score").InnerText, out Score); var Active = bool.Parse(each.SelectSingleNode("Active").InnerText); var UseValue = decimal.Parse(each.SelectSingleNode("UseValue").InnerText); if (Active) { if (!PluginMain.ScoreTextMap.ContainsKey(UseText)) { PluginMain.ScoreTextMap.Add(UseText, new ScoreMap { UseText = UseText, AllowCalculation = AllowCalculation, Score = Score, Active = Active, UseValue = UseValue, }); } if (!PluginMain.ScoreValueMap.ContainsKey(UseValue)) { PluginMain.ScoreValueMap.Add(UseValue, new ScoreMap { UseText = UseText, AllowCalculation = AllowCalculation, Score = Score, Active = Active, UseValue = UseValue, }); } } } } #endregion #region 產生 Row Data try { foreach (JHStudentRecord stu in students) { if (!scattends.ContainsKey(stu.ID)) { continue; } foreach (JHSCAttendRecord record in scattends[stu.ID]) { if (!sces.ContainsKey(record.ID)) { continue; } sces[record.ID].Sort(delegate(HC.JHSCETakeRecord x, HC.JHSCETakeRecord y) { return(x.RefExamID.CompareTo(y.RefExamID)); }); foreach (HC.JHSCETakeRecord sce in sces[record.ID]) { string examName = sce.RefExamID; if (exams.ContainsKey(sce.RefExamID)) { examName = exams[sce.RefExamID].Name; } RowData row = new RowData(); row.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "學年度": row.Add(field, "" + courses[record.RefCourseID].SchoolYear); break; case "學期": row.Add(field, "" + courses[record.RefCourseID].Semester); break; case "課程名稱": row.Add(field, courses[record.RefCourseID].Name); break; // 2018.09.06 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 項目,增加 "領域", "科目", "節數(權重)", "學分" 項目資料。 case "領域": row.Add(field, courses[record.RefCourseID].Domain); break; case "科目": row.Add(field, courses[record.RefCourseID].Subject); break; case "節數(權重)": row.Add(field, "" + courses[record.RefCourseID].Period); break; case "學分": row.Add(field, "" + courses[record.RefCourseID].Credit); break; case "評量名稱": row.Add(field, examName); break; case "定期分數": if (sce.Score.HasValue) { if (PluginMain.ScoreValueMap.ContainsKey(sce.Score.Value)) { row.Add(field, PluginMain.ScoreValueMap[sce.Score.Value].UseText); } else { row.Add(field, sce.Score.Value + ""); } } else { row.Add(field, ""); } break; case "平時分數": if (sce.AssignmentScore.HasValue) { if (PluginMain.ScoreValueMap.ContainsKey(sce.AssignmentScore.Value)) { row.Add(field, PluginMain.ScoreValueMap[sce.AssignmentScore.Value].UseText); } else { row.Add(field, sce.AssignmentScore.Value + ""); } } else { row.Add(field, ""); } break; case "文字描述": row.Add(field, sce.Text); break; } } } e.Items.Add(row); } } } } catch (Exception ex) { ; // MessageBox.Show(ex.Message); } #endregion FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出評量成績", "總共匯出" + e.Items.Count + "筆評量成績。"); }; }
public override void InitializeImport(SmartSchool.API.PlugIn.Import.ImportWizard wizard) { Dictionary <string, JHStudentRecord> students = new Dictionary <string, JHStudentRecord>(); Dictionary <string, List <JHStudentTagRecord> > StudTagRecDic = new Dictionary <string, List <JHStudentTagRecord> > (); Dictionary <string, Dictionary <string, string> > StudTagNameDic = DAL.DALTransfer.GetStudentTagNameDic(); // 取得可加入學生 TagName wizard.PackageLimit = 3000; wizard.ImportableFields.AddRange(ImportItemList); wizard.ValidateStart += delegate(object sender, SmartSchool.API.PlugIn.Import.ValidateStartEventArgs e) { // 取得學生資料 foreach (JHStudentRecord studRec in JHStudent.SelectByIDs(e.List)) { if (!students.ContainsKey(studRec.ID)) { students.Add(studRec.ID, studRec); StudTagRecDic.Add(studRec.ID, new List <JHStudentTagRecord>()); } } // 取得學生類別 foreach (JHStudentTagRecord studTag in JHStudentTag.SelectByStudentIDs(students.Keys)) { //if (!StudTagRecDic.ContainsKey(studTag.RefStudentID)) //{ // List<JHStudentTagRecord> rec = new List<JHStudentTagRecord> (); // rec.Add(studTag ); // StudTagRecDic.Add(studTag.RefStudentID,rec); //} //else if (StudTagRecDic.ContainsKey(studTag.RefStudentID)) { StudTagRecDic[studTag.RefStudentID].Add(studTag); } } }; 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; } // 驗證資料 foreach (string field in e.SelectFields) { string value = e.Data[field].Trim(); // 驗證$無法匯入 if (value.IndexOf('$') > -1) { e.ErrorFields.Add(field, "儲存格有$無法匯入."); break; } if (field == "類別名稱") { if (string.IsNullOrEmpty(value)) { e.ErrorFields.Add(field, "不允許空白"); } } } }; 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 <JHStudentTagRecord> InsertList = new List <JHStudentTagRecord>(); // List<JHStudentTagRecord> UpdateList = new List<JHStudentTagRecord>(); // 放需要新增的學生類別 Dictionary <string, List <string> > NeedAddPrefixName = new Dictionary <string, List <string> >(); // 檢查用 List List <string> CheckStudTagName = new List <string>(); foreach (KeyValuePair <string, Dictionary <string, string> > data in StudTagNameDic) { foreach (KeyValuePair <string, string> data1 in data.Value) { CheckStudTagName.Add(data.Key + data1.Key); } } // 檢查類別是否已經存在 foreach (string id in id_Rows.Keys) { if (!StudTagRecDic.ContainsKey(id)) { continue; } foreach (RowData data in id_Rows[id]) { string strPrefix = string.Empty, strName = string.Empty; if (data.ContainsKey("群組")) { strPrefix = data["群組"]; } if (data.ContainsKey("類別名稱")) { strName = data["類別名稱"]; } string FullName = strPrefix + strName; // 需要新增的, if (!CheckStudTagName.Contains(FullName)) { CheckStudTagName.Add(FullName); if ((NeedAddPrefixName.ContainsKey(strPrefix))) { NeedAddPrefixName[strPrefix].Add(strName); } else { List <string> Names = new List <string>(); Names.Add(strName); NeedAddPrefixName.Add(strPrefix, Names); } } } } // 新增至學生類別管理 List <JHTagConfigRecord> Recs = new List <JHTagConfigRecord>(); foreach (KeyValuePair <string, List <string> > data in NeedAddPrefixName) { foreach (string data1 in data.Value) { JHTagConfigRecord rec = new JHTagConfigRecord(); rec.Category = "Student"; rec.Prefix = data.Key; rec.Name = data1; rec.Color = System.Drawing.Color.White; Recs.Add(rec); } } JHTagConfig.Insert(Recs); StudTagNameDic.Clear(); // 重新取得 StudTagNameDic = DAL.DALTransfer.GetStudentTagNameDic(); foreach (string id in id_Rows.Keys) { if (!StudTagRecDic.ContainsKey(id)) { continue; } foreach (RowData data in id_Rows[id]) { string strPrefix = string.Empty, strName = string.Empty; if (data.ContainsKey("群組")) { strPrefix = data["群組"]; } if (data.ContainsKey("類別名稱")) { strName = data["類別名稱"]; } // 欄位有在 Tag Prefix 內 bool isInsert = true; foreach (JHStudentTagRecord rec in StudTagRecDic[id]) { if (rec.Prefix == strPrefix && rec.Name == strName) { isInsert = false; break; } } if (isInsert) { // 學生類別管理名稱對照 if (StudTagNameDic.ContainsKey(strPrefix)) { if (StudTagNameDic[strPrefix].ContainsKey(strName)) { JHStudentTagRecord StudTag = new JHStudentTagRecord(); StudTag.RefEntityID = id; StudTag.RefTagID = StudTagNameDic[strPrefix][strName]; InsertList.Add(StudTag); } } } } } try { if (InsertList.Count > 0) { Insert(InsertList); } //if (UpdateList.Count > 0) // Update(UpdateList); JHSchool.PermRecLogProcess prlp = new JHSchool.PermRecLogProcess(); prlp.SaveLog("學生.匯入類別", "匯入學生類別", "匯入學生類別:共新增" + InsertList.Count + "筆資料"); JHSchool.Student.Instance.SyncAllBackground(); JHSchool.StudentTag.Instance.SyncAllBackground(); JHSchool.Data.JHStudent.RemoveAll(); JHSchool.Data.JHStudent.SelectAll(); } catch (Exception ex) {} }; }
public ImportStartupForm() { InitializeComponent(); InitializeSemesters(); _effortMapper = new EffortMapper(); // 載入預設儲存值 LoadConfigData(); _worker = new BackgroundWorker(); _worker.WorkerReportsProgress = true; _worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) { lblMessage.Text = "" + e.UserState; }; _worker.DoWork += delegate(object sender, DoWorkEventArgs e) { #region Worker DoWork _worker.ReportProgress(0, "檢查讀卡文字格式…"); #region 檢查文字檔 ValidateTextFiles vtf = new ValidateTextFiles(intStudentNumberLenght.Value); ValidateTextResult vtResult = vtf.CheckFormat(_files); if (vtResult.Error) { e.Result = vtResult; return; } #endregion //文字檔轉 RawData RawDataCollection rdCollection = new RawDataCollection(); rdCollection.ConvertFromFiles(_files); //RawData 轉 DataRecord DataRecordCollection drCollection = new DataRecordCollection(); drCollection.ConvertFromRawData(rdCollection); _rawDataValidator = new DataValidator <RawData>(); _dataRecordValidator = new DataValidator <DataRecord>(); #region 取得驗證需要的資料 JHCourse.RemoveAll(); _worker.ReportProgress(0, "取得學生資料…"); List <JHStudentRecord> studentList = GetInSchoolStudents(); List <string> s_ids = new List <string>(); Dictionary <string, List <string> > studentNumberToStudentIDs = new Dictionary <string, List <string> >(); foreach (JHStudentRecord student in studentList) { string sn = SCValidatorCreator.GetStudentNumberFormat(student.StudentNumber); if (!studentNumberToStudentIDs.ContainsKey(sn)) { studentNumberToStudentIDs.Add(sn, new List <string>()); } studentNumberToStudentIDs[sn].Add(student.ID); } foreach (var dr in drCollection) { if (studentNumberToStudentIDs.ContainsKey(dr.StudentNumber)) { s_ids.AddRange(studentNumberToStudentIDs[dr.StudentNumber]); } } studentList.Clear(); _worker.ReportProgress(0, "取得課程資料…"); List <JHCourseRecord> courseList = JHCourse.SelectBySchoolYearAndSemester(SchoolYear, Semester); List <JHAEIncludeRecord> aeList = JHAEInclude.SelectAll(); //List<JHSCAttendRecord> scaList = JHSCAttend.SelectAll(); var c_ids = from course in courseList select course.ID; _worker.ReportProgress(0, "取得修課資料…"); //List<JHSCAttendRecord> scaList2 = JHSCAttend.SelectByStudentIDAndCourseID(s_ids, c_ids.ToList<string>()); List <JHSCAttendRecord> scaList = new List <JHSCAttendRecord>(); FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, 3); spliter.Function = delegate(List <string> part) { return(JHSCAttend.Select(part, c_ids.ToList <string>(), null, SchoolYear.ToString(), Semester.ToString())); }; scaList = spliter.Execute(s_ids); _worker.ReportProgress(0, "取得試別資料…"); List <JHExamRecord> examList = JHExam.SelectAll(); #endregion #region 註冊驗證 _worker.ReportProgress(0, "載入驗證規則…"); _rawDataValidator.Register(new SubjectCodeValidator()); _rawDataValidator.Register(new ClassCodeValidator()); _rawDataValidator.Register(new ExamCodeValidator()); SCValidatorCreator scCreator = new SCValidatorCreator(JHStudent.SelectByIDs(s_ids), courseList, scaList); _dataRecordValidator.Register(scCreator.CreateStudentValidator()); _dataRecordValidator.Register(new ExamValidator(examList)); _dataRecordValidator.Register(scCreator.CreateSCAttendValidator()); _dataRecordValidator.Register(new CourseExamValidator(scCreator.StudentCourseInfo, aeList, examList)); #endregion #region 進行驗證 _worker.ReportProgress(0, "進行驗證中…"); List <string> msgList = new List <string>(); foreach (RawData rawData in rdCollection) { List <string> msgs = _rawDataValidator.Validate(rawData); msgList.AddRange(msgs); } if (msgList.Count > 0) { e.Result = msgList; return; } foreach (DataRecord dataRecord in drCollection) { List <string> msgs = _dataRecordValidator.Validate(dataRecord); msgList.AddRange(msgs); } if (msgList.Count > 0) { e.Result = msgList; return; } #endregion #region 取得學生的評量成績 _deleteScoreList.Clear(); _addScoreList.Clear(); //var student_ids = from student in scCreator.StudentNumberDictionary.Values select student.ID; //List<string> course_ids = scCreator.AttendCourseIDs; var scaIDs = from sca in scaList select sca.ID; Dictionary <string, JHSCETakeRecord> sceList = new Dictionary <string, JHSCETakeRecord>(); FunctionSpliter <string, JHSCETakeRecord> spliterSCE = new FunctionSpliter <string, JHSCETakeRecord>(300, 3); spliterSCE.Function = delegate(List <string> part) { return(JHSCETake.Select(null, null, null, null, part)); }; foreach (JHSCETakeRecord sce in spliterSCE.Execute(scaIDs.ToList())) { string key = GetCombineKey(sce.RefStudentID, sce.RefCourseID, sce.RefExamID); if (!sceList.ContainsKey(key)) { sceList.Add(key, sce); } } Dictionary <string, JHExamRecord> examTable = new Dictionary <string, JHExamRecord>(); Dictionary <string, JHSCAttendRecord> scaTable = new Dictionary <string, JHSCAttendRecord>(); foreach (JHExamRecord exam in examList) { if (!examTable.ContainsKey(exam.Name)) { examTable.Add(exam.Name, exam); } } foreach (JHSCAttendRecord sca in scaList) { string key = GetCombineKey(sca.RefStudentID, sca.RefCourseID); if (!scaTable.ContainsKey(key)) { scaTable.Add(key, sca); } } foreach (DataRecord dr in drCollection) { JHStudentRecord student = student = scCreator.StudentNumberDictionary[dr.StudentNumber]; JHExamRecord exam = examTable[dr.Exam]; List <JHCourseRecord> courses = new List <JHCourseRecord>(); foreach (JHCourseRecord course in scCreator.StudentCourseInfo.GetCourses(dr.StudentNumber)) { if (dr.Subjects.Contains(course.Subject)) { courses.Add(course); } } foreach (JHCourseRecord course in courses) { string key = GetCombineKey(student.ID, course.ID, exam.ID); if (sceList.ContainsKey(key)) { _deleteScoreList.Add(sceList[key]); } JHSCETakeRecord jh = new JHSCETakeRecord(); KH.JHSCETakeRecord sceNew = new KH.JHSCETakeRecord(jh); sceNew.RefCourseID = course.ID; sceNew.RefExamID = exam.ID; sceNew.RefSCAttendID = scaTable[GetCombineKey(student.ID, course.ID)].ID; sceNew.RefStudentID = student.ID; sceNew.Score = dr.Score; sceNew.Effort = _effortMapper.GetCodeByScore(dr.Score); _addScoreList.Add(sceNew.AsJHSCETakeRecord()); } } #endregion e.Result = null; #endregion }; _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { #region Worker Completed if (e.Error == null && e.Result == null) { if (!_upload.IsBusy) { //如果學生身上已有成績,則提醒使用者 if (_deleteScoreList.Count > 0) { _warn.RunWorkerAsync(); } else { lblMessage.Text = "成績上傳中…"; FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0); counter = 0; _upload.RunWorkerAsync(); } } } else { ControlEnable = true; if (e.Error != null) { MsgBox.Show("匯入失敗。" + e.Error.Message); SmartSchool.ErrorReporting.ReportingService.ReportException(e.Error); } else if (e.Result != null && e.Result is ValidateTextResult) { ValidateTextResult result = e.Result as ValidateTextResult; ValidationErrorViewer viewer = new ValidationErrorViewer(); viewer.SetTextFileError(result.LineIndexes, result.ErrorFormatLineIndexes, result.DuplicateLineIndexes); viewer.ShowDialog(); } else if (e.Result != null && e.Result is List <string> ) { ValidationErrorViewer viewer = new ValidationErrorViewer(); viewer.SetErrorLines(e.Result as List <string>); viewer.ShowDialog(); } } #endregion }; _upload = new BackgroundWorker(); _upload.WorkerReportsProgress = true; _upload.ProgressChanged += new ProgressChangedEventHandler(_upload_ProgressChanged); //_upload.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) //{ // counter += double.Parse("" + e.ProgressPercentage); // FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", (int)(counter * 100f / (double)_addScoreList.Count)); //}; _upload.DoWork += new DoWorkEventHandler(_upload_DoWork); //_upload.DoWork += delegate //{ //#region Upload DoWork //Framework.MultiThreadWorker<JHSCETakeRecord> multi = new Framework.MultiThreadWorker<JHSCETakeRecord>(); //multi.MaxThreads = 3; //multi.PackageSize = 500; //multi.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e) //{ // JHSCETake.Delete(e.List); //}; //multi.Run(_deleteScoreList); //Framework.MultiThreadWorker<JHSCETakeRecord> multi2 = new Framework.MultiThreadWorker<JHSCETakeRecord>(); //multi2.MaxThreads = 3; //multi2.PackageSize = 500; //multi2.PackageWorker += delegate(object sender, Framework.PackageWorkEventArgs<JHSCETakeRecord> e) //{ // JHSCETake.Insert(e.List); // lock (_upload) // { // _upload.ReportProgress(e.List.Count); // } //}; //multi2.Run(_addScoreList); //#endregion //}; _upload.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_upload_RunWorkerCompleted); _warn = new BackgroundWorker(); _warn.WorkerReportsProgress = true; _warn.DoWork += delegate(object sender, DoWorkEventArgs e) { _warn.ReportProgress(0, "產生警告訊息..."); Dictionary <string, string> examDict = new Dictionary <string, string>(); foreach (JHExamRecord exam in JHExam.SelectAll()) { if (!examDict.ContainsKey(exam.ID)) { examDict.Add(exam.ID, exam.Name); } } WarningForm form = new WarningForm(); int count = 0; foreach (JHSCETakeRecord sce in _deleteScoreList) { // 當成績資料是空值跳過 if (sce.Score.HasValue == false && sce.Effort.HasValue == false && string.IsNullOrEmpty(sce.Text)) { continue; } count++; JHStudentRecord student = JHStudent.SelectByID(sce.RefStudentID); JHCourseRecord course = JHCourse.SelectByID(sce.RefCourseID); string exam = (examDict.ContainsKey(sce.RefExamID) ? examDict[sce.RefExamID] : "<未知的試別>"); string s = ""; if (student.Class != null) { s += student.Class.Name; } if (!string.IsNullOrEmpty("" + student.SeatNo)) { s += " " + student.SeatNo + "號"; } if (!string.IsNullOrEmpty(student.StudentNumber)) { s += " (" + student.StudentNumber + ")"; } s += " " + student.Name; form.Add(student.ID, s, string.Format("學生在「{0}」課程「{1}」中已有成績。", course.Name, exam)); _warn.ReportProgress((int)(count * 100 / _deleteScoreList.Count), "產生警告訊息..."); } e.Result = form; }; _warn.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { WarningForm form = e.Result as WarningForm; if (form.ShowDialog() == DialogResult.OK) { lblMessage.Text = "成績上傳中…"; FISCA.Presentation.MotherForm.SetStatusBarMessage("成績上傳中…", 0); counter = 0; _upload.RunWorkerAsync(); } else { this.DialogResult = DialogResult.Cancel; } }; _warn.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e) { FISCA.Presentation.MotherForm.SetStatusBarMessage("" + e.UserState, e.ProgressPercentage); }; _files = new List <FileInfo>(); _addScoreList = new List <JHSCETakeRecord>(); _deleteScoreList = new List <JHSCETakeRecord>(); }
private void _worker_DoWork(object sender, DoWorkEventArgs e) { double total = AllStudentID.Count; double count = 0; //學期歷程 Dictionary <string, HistoryUtil> utilCache = GetStudentHistories(); //學期成績 Dictionary <string, StudentScores> scoreCache = GetStudentScores(utilCache); //聯絡資訊 Dictionary <string, ContactInfo> contactCache = GetStudentContactInfos(); //等第對照表 DegreeMapper degreeMapper = new DegreeMapper(); Workbook book = new Workbook(); book.Open(new MemoryStream(Properties.Resources.五專集體報名成績匯入檔)); Worksheet ws = book.Worksheets[0]; int rowIndex = 2; foreach (JHStudentRecord stu in JHStudent.SelectByIDs(AllStudentID)) { count++; int colIndex = 3; //前面三個欄位不用管,直接跳過。 #region 基本資料 ws.Cells[rowIndex, colIndex++].PutValue((stu.Class != null) ? stu.Class.Name : ""); ws.Cells[rowIndex, colIndex++].PutValue(stu.StudentNumber); ws.Cells[rowIndex, colIndex++].PutValue(stu.Name); ws.Cells[rowIndex, colIndex++].PutValue(stu.IDNumber); ws.Cells[rowIndex, colIndex++].PutValue((stu.Gender == "男") ? "1" : "2"); ws.Cells[rowIndex, colIndex++].PutValue(Global.GetFormatedBirthday(stu.Birthday)); #endregion #region 聯絡資訊 if (contactCache.ContainsKey(stu.ID)) { ContactInfo contact = contactCache[stu.ID]; ws.Cells[rowIndex, colIndex++].PutValue(contact.PhoneNumber); ws.Cells[rowIndex, colIndex++].PutValue(contact.ZipCode); ws.Cells[rowIndex, colIndex++].PutValue(contact.Address); } else { colIndex += 3; //沒有聯絡資訊直接跳過三個欄位 } #endregion #region 學期成績 //有學期歷程及學期成績才會印 if (utilCache.ContainsKey(stu.ID) && scoreCache.ContainsKey(stu.ID)) { #region 領域成績 int scoreStartColIndex = 12; HistoryUtil util = utilCache[stu.ID]; StudentScores studentScore = scoreCache[stu.ID]; SemesterData indexSem = new SemesterData(0, 0, 2); for (int i = 0; i < FiveSemester; i++) { colIndex = scoreStartColIndex + i * Global.GetDomains().Count; indexSem = indexSem.NextSemester(); if (util.ExistByGradeYear(indexSem.GradeYear, indexSem.Semester) == false) { continue; } foreach (decimal?score in studentScore.GetScoreList(util.SemesterData)) { string value = score.HasValue ? degreeMapper.GetDegreeByScore(score.Value) : ""; if (ScoreMode) //如果是 ScoreMode,則印出分數 { ws.Cells[rowIndex, colIndex++].PutValue("" + score); } else { ws.Cells[rowIndex, colIndex++].PutValue(value); } } } #endregion #region 總平均 colIndex = scoreStartColIndex + FiveSemester * Global.GetDomains().Count; decimal?averageScore = studentScore.GetAverage(util.AllSemesterData); string averageValue = averageScore.HasValue ? degreeMapper.GetDegreeByScore(averageScore.Value) : ""; if (ScoreMode) //如果是 ScoreMode,則印出分數 { ws.Cells[rowIndex, colIndex++].PutValue("" + averageScore); } else { ws.Cells[rowIndex, colIndex++].PutValue(averageValue); } #endregion } #endregion _worker.ReportProgress((int)(count * 100 / total)); rowIndex++; } e.Result = book; }