/// <summary> /// (Network Access)將目前學期的資料填入到 Courses、SCAttends 變數中。 /// </summary> private void FillCurrentSemesterData() { Courses = new Dictionary <string, JHCourseRecord>(); SCAttends = new Dictionary <string, JHSCAttendRecord>(); if (Students.Count <= 0) { return; //沒有學生當然就沒有任何資料了。 } //Network Access int t1 = Environment.TickCount; List <JHCourseRecord> listCourses = JHCourse.SelectBySchoolYearAndSemester(Sems.SelectedSchoolYear, Sems.SelectedSemester); Console.WriteLine(string.Format("JHCourse.SelectBySchoolYearAndSemester Time:{0}", Environment.TickCount - t1)); if (listCourses.Count <= 0) { return; //沒有任何課程也不會有成績資料了。 } #region 建立 Course Dictionary foreach (JHCourseRecord each in listCourses) { Courses.Add(each.ID, each); } #endregion //Network Access t1 = Environment.TickCount; List <JHSCAttendRecord> listSCAttends = JHSCAttend.SelectByStudentIDAndCourseID(Students.ToKeys(), Courses.Values.ToKeys()); Console.WriteLine(string.Format("JHSCAttend.SelectByStudentIDAndCourseID Time:{0}", Environment.TickCount - t1)); t1 = Environment.TickCount; #region 建立 SCAttend Dictionary int selSchoolYear = Sems.SelectedSchoolYear; int selSemester = Sems.SelectedSemester; foreach (JHSCAttendRecord each in listSCAttends) { JHCourseRecord course = Courses[each.RefCourseID]; if (course.SchoolYear != selSchoolYear || course.Semester != selSemester) { continue; } SCAttends.Add(each.ID, each); } #endregion Console.WriteLine(string.Format("建立 SCAttend Dictionary Time:{0}", Environment.TickCount - t1)); }
private void btnDelete_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count <= 0) { return; } ListViewItem item = listView.SelectedItems[0]; JHCourseRecord course = item.Tag as JHCourseRecord; if (MsgBox.Show(string.Format("您確定要刪除課程「{0}」的修課記錄及相關評量成績嗎?", course.Name), MessageBoxButtons.YesNo) == DialogResult.Yes) { JHStudentRecord student = JHStudent.SelectByID(PrimaryKey); List <JHSCETakeRecord> sces = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID); if (sces.Count > 0) { JHSCETake.Delete(sces); FISCA.LogAgent.LogSaver logSaver = FISCA.LogAgent.ApplicationLog.CreateLogSaverInstance(); string studentInfo = StudentInfoConvertor.GetInfoWithClass(student); foreach (var sce in sces) { string desc = studentInfo + " 刪除評量成績:" + sce.Course.Name + " " + sce.Exam.Name; logSaver.AddBatch("成績系統.修課及評量成績", "刪除評量成績", "student", PrimaryKey, desc); } logSaver.LogBatch(); } List <JHSCAttendRecord> scattends = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID }); if (scattends.Count > 0) { JHSCAttend.Delete(scattends); StringBuilder builder = new StringBuilder(""); builder.Append(StudentInfoConvertor.GetInfoWithClass(student)); builder.Append(" 刪除修課:" + course.Name); FISCA.LogAgent.ApplicationLog.Log("成績系統.修課及評量成績", "刪除修課", "student", PrimaryKey, builder.ToString()); } listView.Items.Remove(item); } }
private void btnSave_Click(object sender, EventArgs e) { if (cboCourseName.SelectedItem == null) { return; } _course = cboCourseName.SelectedItem as JHCourseRecord; foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(new string[] { _student.ID }, new string[] { })) { if (record.RefCourseID == _course.ID) { MsgBox.Show(string.Format("學生「{0}」已修習課程「{1}」", _student.Name, _course.Name)); return; } } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// (Network Access)將目前學期的資料填入到 Courses、SCAttends 變數中。 /// </summary> private void FillCurrentSemesterData() { Courses = new Dictionary <string, JHCourseRecord>(); SCAttends = new Dictionary <string, JHSCAttendRecord>(); if (Students.Count <= 0) { return; //沒有學生當然就沒有任何資料了。 } //Network Access List <JHCourseRecord> listCourses = JHCourse.SelectBySchoolYearAndSemester(Sems.SelectedSchoolYear, Sems.SelectedSemester); if (listCourses.Count <= 0) { return; //沒有任何課程也不會有成績資料了。 } #region 建立 Course Dictionary foreach (JHCourseRecord each in listCourses) { Courses.Add(each.ID, each); } #endregion //Network Access List <JHSCAttendRecord> listSCAttends = JHSCAttend.SelectByStudentIDAndCourseID(Students.ToKeys(), Courses.Values.ToKeys()); #region 建立 SCAttend Dictionary foreach (JHSCAttendRecord each in listSCAttends) { JHCourseRecord course = Courses[each.RefCourseID]; if (course.SchoolYear != Sems.SelectedSchoolYear || course.Semester != Sems.SelectedSemester) { continue; } SCAttends.Add(each.ID, each); } #endregion }
private void InitializeBackgroundWorker() { _worker = new BackgroundWorker(); _worker.DoWork += delegate(object sender, DoWorkEventArgs e) { JHStudentRecord student = JHStudent.SelectByID(PrimaryKey); List <string> courseIDs = new List <string>(); foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { })) { if (!courseIDs.Contains(record.RefCourseID)) { courseIDs.Add(record.RefCourseID); } } List <JHCourseRecord> courses = JHCourse.SelectByIDs(courseIDs); courses.Sort(delegate(JHCourseRecord x, JHCourseRecord y) { return(x.Name.CompareTo(y.Name)); }); e.Result = courses; }; _worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (_RunningID != PrimaryKey) { _RunningID = PrimaryKey; _worker.RunWorkerAsync(_RunningID); return; } ResetListView(); PrefillItems(e.Result as List <JHCourseRecord>); }; }
public ScoreInputForm(JHStudentRecord student, JHCourseRecord course) { InitializeComponent(); InitializeListener(); prlp = new PermRecLogProcess(); lblCourseName.Text = course.Name; lblStudent.Text = student.Name + " " + student.StudentNumber; _course = course; _student = student; List <JHSCAttendRecord> scattendList = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID }); if (scattendList.Count > 0) { _scattend = scattendList[0]; } #region 取得評量成績 _listener.SuspendListen(); // 取得所有試別 Dictionary <string, JHExamRecord> exams = JHExam.SelectAll().ToDictionary(x => x.ID); List <string> examIDs = new List <string>(exams.Keys); List <HC.JHAEIncludeRecord> aeList = new List <HC.JHAEIncludeRecord>(); if (course.RefAssessmentSetupID != null) { JHAssessmentSetupRecord assessment = JHAssessmentSetup.SelectByID(course.RefAssessmentSetupID); if (assessment != null) { foreach (JHAEIncludeRecord ae in JHAEInclude.SelectByAssessmentSetupID(assessment.ID)) { aeList.Add(new HC.JHAEIncludeRecord(ae)); } } //{ // foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll()) // { // if (ae.RefAssessmentSetupID == assessment.ID) // aeList.Add(new HC.JHAEIncludeRecord(ae)); // } //} } List <JHSCETakeRecord> jhSCEList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID); //aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y) //{ // return x.RefExamID.CompareTo(y.RefExamID); //}); aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y) { int ix = examIDs.IndexOf(x.RefExamID); int iy = examIDs.IndexOf(y.RefExamID); if (ix == -1) { ix = int.MaxValue; } if (iy == -1) { iy = int.MaxValue; } return(ix.CompareTo(iy)); }); List <HC.JHSCETakeRecord> sceList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID).AsHCJHSCETakeRecords(); Dictionary <string, DataGridViewRow> rows = new Dictionary <string, DataGridViewRow>(); foreach (HC.JHAEIncludeRecord ae in aeList) { DataGridViewRow row = new DataGridViewRow(); //JHExamRecord exam = JHExam.SelectByID(ae.RefExamID); JHExamRecord exam = null; if (exams.ContainsKey(ae.RefExamID)) { exam = exams[ae.RefExamID]; } row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + ae.RefExamID + ")", "", "", ""); dgv.Rows.Add(row); row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : ""; if (!ae.UseScore) { DisableCell(row, chScore); } if (!ae.UseAssignmentScore) { DisableCell(row, chAssignmentScore); } if (!ae.UseText) { DisableCell(row, chText); } if (!rows.ContainsKey(ae.RefExamID)) { rows.Add(ae.RefExamID, row); } } //List<HC.JHSCETakeRecord> sceList = jhSCEList.AsHCJHSCETakeRecords(); foreach (HC.JHSCETakeRecord sce in sceList) { if (rows.ContainsKey(sce.RefExamID)) { DataGridViewRow row = rows[sce.RefExamID]; row.Cells[chScore.Index].Value = sce.Score.HasValue ? "" + sce.Score.Value : ""; row.Cells[chAssignmentScore.Index].Value = sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : ""; row.Cells[chText.Index].Value = sce.Text; row.Tag = sce; } else { DataGridViewRow row = new DataGridViewRow(); JHExamRecord exam = JHExam.SelectByID(sce.RefExamID); row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + sce.RefExamID + ")", sce.Score.HasValue ? "" + sce.Score.Value : "", sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : "", sce.Text); row.Tag = sce; row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : ""; dgv.Rows.Add(row); DisableCell(row, chExamName); DisableCell(row, chScore); DisableCell(row, chAssignmentScore); DisableCell(row, chText); } } #region 填入修課總成績 if (_scattend != null) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgv, "課程總成績", "" + _scattend.Score, "", _scattend.Text); DisableCell(row, chAssignmentScore); row.Tag = "課程總成績"; dgv.Rows.Add(row); } #endregion foreach (DataGridViewRow dgv1 in dgv.Rows) { foreach (DataGridViewCell cell in dgv1.Cells) { cell.ErrorText = ""; if (cell.OwningColumn == chScore || cell.OwningColumn == chAssignmentScore) { cell.Style.ForeColor = Color.Black; if (!string.IsNullOrEmpty("" + cell.Value)) { decimal d; if (!decimal.TryParse("" + cell.Value, out d)) { cell.ErrorText = "分數必須為數字"; } else { if (d < 60) { cell.Style.ForeColor = Color.Red; } if (d > 100 || d < 0) { cell.Style.ForeColor = Color.Green; } } } } } } _listener.Reset(); _listener.ResumeListen(); #endregion SetLoadDataToLog(); }
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 <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 產生 Row Data 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; case "評量名稱": row.Add(field, examName); break; case "定期分數": row.Add(field, "" + sce.Score); break; case "平時分數": row.Add(field, "" + sce.AssignmentScore); break; case "文字描述": row.Add(field, sce.Text); break; } } } e.Items.Add(row); } } } #endregion 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, 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>(); 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 }; 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)) { 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 { currentSCE.Score = null; } changed = true; } break; case "平時分數": if ("" + currentSCE.AssignmentScore != value) { decimal d; if (decimal.TryParse(value, out d)) { currentSCE.AssignmentScore = d; } 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 { newSCE.Score = null; } } else { newSCE.Score = null; } break; case "平時分數": if (value != "") { decimal d; if (decimal.TryParse(value, out d)) { newSCE.AssignmentScore = d; } 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 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; // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 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 = -1; decimal d = -1; #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, "必須填入空白或整數"); } else { // 2020/10/15 加入檢查,當分數與努力轉換後努力程度不同,需要顯示警告 if (value != "") { int x = ConvertEffort(d); if (x != i) { e.WarningFields.Add(field, "努力程度與使用分數轉換後不一致"); } } } break; // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 //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>(); // 檢查是否有努力程度欄位 bool isHasEffortField = false; //交叉比對各學生資料 #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 (isHasEffortField == false) { if (data.ContainsKey("努力程度")) { // 有努力程度這欄位 isHasEffortField = true; } } // 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.ContainsKey("評量名稱")) { if (data["評量名稱"] == "平時評量") { if (data.ContainsKey("分數評量")) { if (data["分數評量"] != null && data["分數評量"] != "") { decimal d; // 使用TryParse 的轉換,是因為可能會有Row 的分數評量欄位是空的(EX: 社團成績) ,直接Parse會爆 if (decimal.TryParse(data["分數評量"], out d)) { record.OrdinarilyScore = d; } } // 當分數評量是空白 if (data["分數評量"] != null && data["分數評量"].Trim() == "") { record.OrdinarilyScore = null; } } if (data.ContainsKey("努力程度")) { if (data["努力程度"] != null && data["努力程度"] != "") { int i; if (int.TryParse(data["努力程度"], out i)) { record.OrdinarilyEffort = i; } } if (data["努力程度"] != null && data["努力程度"].Trim() == "") { record.OrdinarilyEffort = null; } } // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 //if (data["文字描述"] != null) //{ // record.Text = data["文字描述"].ToString(); //} // 2020/10/15 宏安與小組會議討論,當沒有努力程度欄位,會使用成績轉換努力程度 if (isHasEffortField == false) { if (record.OrdinarilyScore.HasValue) { record.OrdinarilyEffort = ConvertEffort(record.OrdinarilyScore.Value); } else { record.OrdinarilyEffort = null; } } 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; // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 //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; // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 //case "文字描述": // newSCE.Text = value; // break; } } #endregion if (newSCE.RefExamID != "") { insertList.Add(newSCE); } } } } } try { // 解析並填入轉換空白的努力程度 // 2020/10/15 透過宏安討論,當沒有努力程度欄位才會使用成績轉換,如果有努力程度欄位不會使用成績轉換。 foreach (KH.JHSCETakeRecord rec in updateList) { //// 當努力程度沒有值卻有成績。 //if ((rec.Effort.HasValue == false) && rec.Score.HasValue) //{ // rec.Effort = ConvertEffort(rec.Score.Value); //} if (isHasEffortField == false) { if (rec.Score.HasValue) { rec.Effort = ConvertEffort(rec.Score.Value); } else { rec.Effort = null; } } } foreach (KH.JHSCETakeRecord rec in insertList) { //// 當努力程度沒有值卻有成績。 //if ((rec.Effort.HasValue == false) && rec.Score.HasValue) //{ // rec.Effort = ConvertEffort(rec.Score.Value); //} if (isHasEffortField == false) { if (rec.Score.HasValue) { rec.Effort = ConvertEffort(rec.Score.Value); } else { rec.Effort = null; } } } 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 InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 // 2018.09.05 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 項目,增加 "領域", "科目", "節數(權重)", "學分" 。 // 2018.09.07 [ischoolKingdom] Vicky依據新需求調整項目位置。 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 <KH.JHSCETakeRecord> > sces = new Dictionary <string, List <KH.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 (KH.JHSCETakeRecord record in JHSCETake.SelectByStudentAndCourse(new List <string>(scattends.Keys), new List <string>(courses.Keys)).AsKHJHSCETakeRecords()) { if (!sces.ContainsKey(record.RefSCAttendID)) { sces.Add(record.RefSCAttendID, new List <KH.JHSCETakeRecord>()); } sces[record.RefSCAttendID].Add(record); } #endregion #region 產生 Row Data 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(KH.JHSCETakeRecord x, KH.JHSCETakeRecord y) { return(x.RefExamID.CompareTo(y.RefExamID)); }); foreach (KH.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.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 // 2018.09.05 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 項目,增加 "領域", "科目", "節數(權重)", "學分" 項目資料。 //case "文字描述": row.Add(field, sce.Text); break; 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 "分數評量": row.Add(field, "" + sce.Score); break; case "努力程度": row.Add(field, "" + sce.Effort); break; } } } e.Items.Add(row); } //2016/7/26 穎驊新增,因應高雄國中希望能加入匯出匯入"平時成績"的功能,因此在原本的匯出評量成績報表Excel中增加平時成績的項目, // 基本邏輯跟 SCEtake 的定期評量一樣,另外意外發現平時成績、努力程度、Text在 JHSCAttendRecord裏頭就有了,不必在另外下SQL 找UDT 在用XElement 去解析Xml 檔填成績 string examName2 = "平時評量"; RowData row2 = new RowData(); row2.ID = stu.ID; foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "學年度": row2.Add(field, "" + courses[record.RefCourseID].SchoolYear); break; case "學期": row2.Add(field, "" + courses[record.RefCourseID].Semester); break; case "課程名稱": row2.Add(field, courses[record.RefCourseID].Name); break; // 2018.09.05 [ischoolKingdom] Vicky依據 [02-01][03] 匯入評量成績 項目,移除文字描述。 // 2018.09.05 [ischoolKingdom] Vicky依據 [12-01][01] 多學期成績排名 項目,增加 "領域", "科目", "節數(權重)", "學分" 項目資料。 // case "文字描述": row2.Add(field, record.Text); break; case "領域": row2.Add(field, courses[record.RefCourseID].Domain); break; case "科目": row2.Add(field, courses[record.RefCourseID].Subject); break; case "節數(權重)": row2.Add(field, "" + courses[record.RefCourseID].Period); break; case "學分": row2.Add(field, "" + courses[record.RefCourseID].Credit); break; case "評量名稱": row2.Add(field, examName2); break; case "分數評量": row2.Add(field, "" + record.OrdinarilyScore); break; case "努力程度": row2.Add(field, "" + record.OrdinarilyEffort); break; } } } e.Items.Add(row2); } } #endregion FISCA.LogAgent.ApplicationLog.Log("成績系統.匯入匯出", "匯出評量成績", "總共匯出" + e.Items.Count + "筆評量成績。"); }; }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { double total = _config.Students.Count; double count = 0; _worker.ReportProgress(0); List <string> student_ids = new List <string>(); foreach (JHStudentRecord item in _config.Students) { student_ids.Add(item.ID); } #region 快取資料 //獎勵 Dictionary <string, List <JHMeritRecord> > meritCache = new Dictionary <string, List <JHMeritRecord> >(); foreach (JHMeritRecord record in JHMerit.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!meritCache.ContainsKey(record.RefStudentID)) { meritCache.Add(record.RefStudentID, new List <JHMeritRecord>()); } meritCache[record.RefStudentID].Add(record); } //懲戒 Dictionary <string, List <JHDemeritRecord> > demeritCache = new Dictionary <string, List <JHDemeritRecord> >(); foreach (JHDemeritRecord record in JHDemerit.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!demeritCache.ContainsKey(record.RefStudentID)) { demeritCache.Add(record.RefStudentID, new List <JHDemeritRecord>()); } demeritCache[record.RefStudentID].Add(record); } //缺曠 Dictionary <string, List <JHAttendanceRecord> > attendanceCache = new Dictionary <string, List <JHAttendanceRecord> >(); foreach (JHAttendanceRecord record in JHAttendance.SelectByStudentIDs(student_ids)) { if (record.OccurDate < _config.StartDate) { continue; } if (record.OccurDate > _config.EndDate) { continue; } if (!attendanceCache.ContainsKey(record.RefStudentID)) { attendanceCache.Add(record.RefStudentID, new List <JHAttendanceRecord>()); } attendanceCache[record.RefStudentID].Add(record); } List <string> course_ids = new List <string>(); foreach (JHSCAttendRecord record in JHSCAttend.SelectByStudentIDs(student_ids)) { if (!course_ids.Contains(record.RefCourseID)) { course_ids.Add(record.RefCourseID); } } //課程 JHCourse.RemoveAll(); int schoolYear = _config.SchoolYear; int semester = _config.Semester; Dictionary <string, JHCourseRecord> courseCache = new Dictionary <string, JHCourseRecord>(); foreach (JHCourseRecord record in JHCourse.SelectByIDs(course_ids)) { if ("" + record.SchoolYear != "" + schoolYear) { continue; } if ("" + record.Semester != "" + semester) { continue; } // 過濾使用者所選課程才放入 if (Global._selectCourseIDList.Contains(record.ID)) { if (!courseCache.ContainsKey(record.ID)) { courseCache.Add(record.ID, record); } } } //修課記錄 Dictionary <string, List <string> > scCache = new Dictionary <string, List <string> >(); //foreach (JHSCAttendRecord sc in JHSCAttend.Select(student_ids, course_ids, new string[] { }, "" + _config.SchoolYear, "" + _config.Semester)) foreach (JHSCAttendRecord sc in JHSCAttend.SelectByStudentIDAndCourseID(student_ids, course_ids)) { if (!courseCache.ContainsKey(sc.RefCourseID)) { continue; } if (!scCache.ContainsKey(sc.RefStudentID)) { scCache.Add(sc.RefStudentID, new List <string>()); } // 過濾使用者不選 if (Global._selectCourseIDList.Contains(sc.RefCourseID)) { scCache[sc.RefStudentID].Add(sc.RefCourseID); } } //評量成績 Dictionary <string, List <HC.JHSCETakeRecord> > sceScoreCache = new Dictionary <string, List <HC.JHSCETakeRecord> >(); foreach (JHSCETakeRecord record in JHSCETake.SelectByStudentAndCourse(student_ids, course_ids)) { if (record.RefExamID != _config.Exam.ID) { continue; } if (!sceScoreCache.ContainsKey(record.RefStudentID)) { sceScoreCache.Add(record.RefStudentID, new List <HC.JHSCETakeRecord>()); } sceScoreCache[record.RefStudentID].Add(new HC.JHSCETakeRecord(record)); } //學期歷程 Dictionary <string, K12.Data.SemesterHistoryItem> historyCache = new Dictionary <string, K12.Data.SemesterHistoryItem>(); foreach (JHSemesterHistoryRecord record in JHSemesterHistory.SelectByStudentIDs(student_ids)) { foreach (K12.Data.SemesterHistoryItem item in record.SemesterHistoryItems) { if ("" + item.SchoolYear != K12.Data.School.DefaultSchoolYear) { continue; } if ("" + item.Semester != K12.Data.School.DefaultSemester) { continue; } if (!historyCache.ContainsKey(record.RefStudentID)) { historyCache.Add(record.RefStudentID, item); } } } //取得所有教師,為了Cache下來 JHTeacher.SelectAll(); #endregion #region 建立節次對照及假別列表 Dictionary <string, string> periodMapping = new Dictionary <string, string>(); foreach (JHPeriodMappingInfo info in JHPeriodMapping.SelectAll()) { if (!periodMapping.ContainsKey(info.Name)) { periodMapping.Add(info.Name, info.Type); } } List <string> absenceList = new List <string>(); foreach (JHAbsenceMappingInfo info in JHAbsenceMapping.SelectAll()) { absenceList.Add(info.Name); } #endregion #region 判斷要列印的領域科目 Dictionary <string, bool> domains = new Dictionary <string, bool>(); Dictionary <string, List <string> > subjects = new Dictionary <string, List <string> >(); List <JHCourseRecord> courseList = new List <JHCourseRecord>(courseCache.Values); courseList.Sort(delegate(JHCourseRecord x, JHCourseRecord y) { return(JHSchool.Evaluation.Subject.CompareSubjectOrdinal(x.Subject, y.Subject)); //List<string> list = new List<string>(new string[] { "國語文", "國文", "英文", "英語", "數學", "歷史", "地理", "公民", "理化", "生物" }); //int ix = list.IndexOf(x.Subject); //int iy = list.IndexOf(y.Subject); //if (ix >= 0 && iy >= 0) // return ix.CompareTo(iy); //else if (ix >= 0) // return -1; //else if (iy >= 0) // return 1; //else // return x.Subject.CompareTo(y.Subject); }); string domainSubjectSetup = _rc.GetString("領域科目設定", "Domain"); _config.DomainSubjectSetup = domainSubjectSetup; if (domainSubjectSetup == "Domain") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, true); } //domains.Add("彈性課程", false); if (domains.ContainsKey("語文")) { domains["語文"] = false; } if (!domains.ContainsKey("")) { domains.Add("", false); } } else if (domainSubjectSetup == "Subject") { foreach (var domain in JHSchool.Evaluation.Subject.Domains) { domains.Add(domain, false); } //domains.Add("彈性課程", false); if (!domains.ContainsKey("")) { domains.Add("", false); } } else { throw new Exception("請重新儲存一次列印設定"); } foreach (var domain in JHSchool.Evaluation.Subject.Domains) { subjects.Add(domain, new List <string>()); } //subjects.Add("彈性課程", new List<string>()); subjects.Add("", new List <string>()); //foreach (JHCourseRecord course in courseList) //{ // if (!domains.ContainsKey(course.Domain)) continue; // if (!subjects.ContainsKey(course.Domain)) // subjects.Add(course.Domain, new List<string>()); // //很怪 // if (domains[course.Domain] == true) continue; // if (!subjects[course.Domain].Contains(course.Subject)) // subjects[course.Domain].Add(course.Subject); //} _config.SetPrintDomains(domains); _config.SetPrintSubjects(subjects); #endregion DocumentBuilder templateBuilder = new DocumentBuilder(_template); #region 判斷是否列印文字評語 templateBuilder.MoveToMergeField("文字評語"); if (_rc.GetBoolean("列印文字評語", true)) { templateBuilder.Write("文字評語"); } else { Cell first = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = first.CellFormat.Width; Table table = first.ParentRow.ParentTable; foreach (Row row in table.Rows) { if (row.ChildNodes.Count == 1) { break; } row.RemoveChild(row.LastCell); int lastIndex = row.ChildNodes.Count - 1; row.Cells[lastIndex--].CellFormat.Width += (width / 3f); row.Cells[lastIndex--].CellFormat.Width += (width / 3f); row.Cells[lastIndex].CellFormat.Width += (width / 3f); } } #endregion #region 依節權數設定,在畫面上顯示 string pcDisplay = string.Empty; bool p = _rc.GetBoolean("列印節數", false); bool c = _rc.GetBoolean("列印權數", false); if (p && c) { pcDisplay = "節/權數"; } else if (p) { pcDisplay = "節數"; } else if (c) { pcDisplay = "權數"; } while (templateBuilder.MoveToMergeField("節權數")) { templateBuilder.Write(pcDisplay); } #endregion #region 如果使用者不印定期評量,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("定期評量"); if (_rc.GetBoolean("列印定期評量", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 3]); lastIndex = eachRow.ChildNodes.Count - 3; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("定期評量"); } #endregion #region 如果使用者不印平時評量,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("平時評量"); if (_rc.GetBoolean("列印平時評量", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 2]); lastIndex = eachRow.ChildNodes.Count - 2; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("平時評量"); } #endregion #region 如果使用者不印定期學習評量總成績,從畫面上將欄位拿掉 templateBuilder.MoveToMergeField("定期學習評量總成績"); if (_rc.GetBoolean("列印定期學習評量總成績", false) == false) { Cell assignmentCell = templateBuilder.CurrentParagraph.ParentNode as Cell; double width = assignmentCell.CellFormat.Width; bool hasText = false; if (assignmentCell.NextSibling != null) { hasText = true; } Table scoreTable = assignmentCell.ParentRow.ParentTable; foreach (Row eachRow in scoreTable.Rows) { if (eachRow.Cells.Count == 1) { break; } int lastIndex = 0; if (hasText) { eachRow.RemoveChild(eachRow.Cells[eachRow.Count - 2]); lastIndex = eachRow.ChildNodes.Count - 2; } else { eachRow.RemoveChild(eachRow.LastCell); lastIndex = eachRow.ChildNodes.Count - 1; } eachRow.Cells[lastIndex--].CellFormat.Width += (width / 2f); eachRow.Cells[lastIndex].CellFormat.Width += (width / 2f); } } else { templateBuilder.Write("定期學習評量總成績"); } #endregion #region 取得學生成績計算規則 ScoreCalculator defaultScoreCalculator = new ScoreCalculator(null); //key: ScoreCalcRuleID Dictionary <string, ScoreCalculator> calcCache = new Dictionary <string, ScoreCalculator>(); //key: StudentID, val: ScoreCalcRuleID Dictionary <string, string> calcIDCache = new Dictionary <string, string>(); List <string> scoreCalcRuleIDList = new List <string>(); foreach (JHStudentRecord student in _config.Students) { //calcCache.Add(student.ID, new ScoreCalculator(student.ScoreCalcRule)); string calcID = string.Empty; if (!string.IsNullOrEmpty(student.OverrideScoreCalcRuleID)) { calcID = student.OverrideScoreCalcRuleID; } else if (student.Class != null && !string.IsNullOrEmpty(student.Class.RefScoreCalcRuleID)) { calcID = student.Class.RefScoreCalcRuleID; } if (!string.IsNullOrEmpty(calcID)) { calcIDCache.Add(student.ID, calcID); } } foreach (JHScoreCalcRuleRecord record in JHScoreCalcRule.SelectByIDs(calcIDCache.Values)) { if (!calcCache.ContainsKey(record.ID)) { calcCache.Add(record.ID, new ScoreCalculator(record)); } } //MsgBox.Show("" + (Environment.TickCount - t)); #endregion #region 檢查學生成績是否超出可列印行數 foreach (JHStudentRecord student in _config.Students) { if (scCache.ContainsKey(student.ID)) { int checkCount = 0; if (_config.DomainSubjectSetup == "Subject") { checkCount = scCache[student.ID].Count; } else { List <string> checkDomains = new List <string>(); foreach (string courseID in scCache[student.ID]) { JHCourseRecord course = courseCache[courseID]; if (string.IsNullOrEmpty(course.Domain)) { checkCount++; } else if (!checkDomains.Contains(course.Domain)) { checkDomains.Add(course.Domain); } } checkCount += checkDomains.Count; } if (checkCount > _rowCount) { _overStudentList.Add(student.ID); } } } //有學生資料超出範圍 if (_overStudentList.Count > 0) { //K12.Presentation.NLDPanels.Student.AddToTemp(overStudentList); System.Windows.Forms.DialogResult result = MsgBox.Show("有 " + _overStudentList.Count + " 位學生評量成績資料超出範本可列印範圍,已將學生加入待處理。\n是否繼續列印?", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { e.Result = "Cancel"; } } #endregion // 取得學生課程ID對照 Dictionary <string, List <string> > studCourseID = new Dictionary <string, List <string> >(); List <string> sid = (from stud in _config.Students select stud.ID).ToList(); foreach (JHSCAttendRecord attend in JHSCAttend.SelectByStudentIDs(sid)) { if (attend.Course.SchoolYear.HasValue && attend.Course.Semester.HasValue) { if (attend.Course.SchoolYear == _config.SchoolYear && attend.Course.Semester == _config.Semester) { if (studCourseID.ContainsKey(attend.RefStudentID)) { studCourseID[attend.RefStudentID].Add(attend.RefCourseID); } else { List <string> coid = new List <string>(); coid.Add(attend.RefCourseID); studCourseID.Add(attend.RefStudentID, coid); } } } } // 取得學期歷程 Config._StudSemesterHistoryItemDict.Clear(); List <JHSemesterHistoryRecord> semHisRec = JHSemesterHistory.SelectByStudents(_config.Students); // 當畫面學期歷程內的學年度學期與畫面上設定相同,加入 foreach (JHSemesterHistoryRecord rec in semHisRec) { foreach (K12.Data.SemesterHistoryItem shi in rec.SemesterHistoryItems) { if (shi.SchoolYear == _config.SchoolYear && shi.Semester == _config.Semester) { if (!Config._StudSemesterHistoryItemDict.ContainsKey(shi.RefStudentID)) { Config._StudSemesterHistoryItemDict.Add(shi.RefStudentID, shi); } } } } // 取得評量比例 Utility.ScorePercentageHSDict.Clear(); Utility.ScorePercentageHSDict = Utility.GetScorePercentageHS(); #region 產生 foreach (JHStudentRecord student in _config.Students) { count++; if (_overStudentList.Contains(student.ID)) { continue; } Document each = (Document)_template.Clone(true); DocumentBuilder builder = new DocumentBuilder(each); #region 學生基本資料 StudentBasicInfo basicInfo = new StudentBasicInfo(builder); basicInfo.SetStudent(student); #endregion #region 班導師 builder.MoveToMergeField("班導師"); if (historyCache.ContainsKey(student.ID)) { builder.Write(historyCache[student.ID].Teacher); } else { builder.Write(string.Empty); } #endregion #region 成績 List <HC.JHSCETakeRecord> sceScoreList = null; if (sceScoreCache.ContainsKey(student.ID)) { sceScoreList = sceScoreCache[student.ID]; } else { sceScoreList = new List <HC.JHSCETakeRecord>(); } ScoreCalculator studentCalculator = defaultScoreCalculator; if (calcIDCache.ContainsKey(student.ID) && calcCache.ContainsKey(calcIDCache[student.ID])) { studentCalculator = calcCache[calcIDCache[student.ID]]; } // 過濾 courseCache studid Dictionary <string, JHCourseRecord> courseCache1 = new Dictionary <string, JHCourseRecord>(); foreach (KeyValuePair <string, JHCourseRecord> val in courseCache) { // 從學生修課來對應到課程 if (studCourseID.ContainsKey(student.ID)) { if (studCourseID[student.ID].Contains(val.Value.ID)) { courseCache1.Add(val.Key, val.Value); } } } StudentExamScore examScore = new StudentExamScore(builder, _config, courseCache1); examScore.PrintPeriod = _rc.GetBoolean("列印節數", false); examScore.PrintCredit = _rc.GetBoolean("列印權數", false); examScore.PrintText = _rc.GetBoolean("列印文字評語", true); examScore.PrintScore = _rc.GetBoolean("列印定期評量", true); examScore.PrintAssScore = _rc.GetBoolean("列印平時評量", true); examScore.PrintTotalScore = _rc.GetBoolean("列印定期學習評量總成績", true); examScore.SetScoreCalculator(studentCalculator); if (scCache.ContainsKey(student.ID)) { examScore.SetSubjects(scCache[student.ID]); } examScore.SetData(sceScoreList); #endregion if (_config.DomainSubjectSetup == "Subject") { // 科目定期評量加權平均 if (builder.MoveToMergeField("加權平均") || builder.MoveToMergeField("定期評量加權平均")) { if (examScore.SubjAvgScore > 0) { builder.Write(examScore.SubjAvgScore.ToString()); } else { builder.Write(""); } } // 科目平時評量加權平均 if (builder.MoveToMergeField("平時評量加權平均")) { if (examScore.SubjAvgAssignmentScore > 0) { builder.Write(examScore.SubjAvgAssignmentScore.ToString()); } else { builder.Write(""); } } // 科目學習總分加權平均 if (builder.MoveToMergeField("定期學習評量總成績加權平均")) { if (examScore.SubjAvgFinalScore > 0) { builder.Write(examScore.SubjAvgFinalScore.ToString()); } else { builder.Write(""); } } } else { // 領域定期評量加權平均 if (builder.MoveToMergeField("加權平均") || builder.MoveToMergeField("定期評量加權平均")) { if (examScore.DomainAvgScore > 0) { builder.Write(examScore.DomainAvgScore.ToString()); } else { builder.Write(""); } } // 領域平時評量加權平均 if (builder.MoveToMergeField("平時評量加權平均")) { if (examScore.DomainAvgAssignmentScore > 0) { builder.Write(examScore.DomainAvgAssignmentScore.ToString()); } else { builder.Write(""); } } // 領域學習總分加權平均 if (builder.MoveToMergeField("定期學習評量總成績加權平均")) { if (examScore.DomainAvgFinalScore > 0) { builder.Write(examScore.DomainAvgFinalScore.ToString()); } else { builder.Write(""); } } } #region 日常表現 List <JHMeritRecord> meritList = null; List <JHDemeritRecord> demeritList = null; List <JHAttendanceRecord> attendanceList = null; meritList = (meritCache.ContainsKey(student.ID)) ? meritCache[student.ID] : new List <JHMeritRecord>(); demeritList = (demeritCache.ContainsKey(student.ID)) ? demeritCache[student.ID] : new List <JHDemeritRecord>(); attendanceList = (attendanceCache.ContainsKey(student.ID)) ? attendanceCache[student.ID] : new List <JHAttendanceRecord>(); StudentMoralScore moral = new StudentMoralScore(builder, _config, periodMapping, absenceList); moral.SetData(meritList, demeritList, attendanceList); #endregion foreach (Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } //回報進度 _worker.ReportProgress((int)(count * 100.0 / total)); } List <string> globalFieldName = new List <string>(); List <object> globalFieldValue = new List <object>(); globalFieldName.Add("學校名稱"); globalFieldValue.Add(K12.Data.School.ChineseName); globalFieldName.Add("學年度"); globalFieldValue.Add(_config.SchoolYear); globalFieldName.Add("學期"); globalFieldValue.Add(_config.Semester); globalFieldName.Add("評量名稱"); globalFieldValue.Add(_config.Exam.Name); globalFieldName.Add("統計期間"); globalFieldValue.Add(_config.StartDate.ToShortDateString() + " ~ " + _config.EndDate.ToShortDateString()); globalFieldName.Add("列印日期"); globalFieldValue.Add(DateConvert.CDate(DateTime.Now.ToString("yyyy/MM/dd")) + " " + DateTime.Now.ToString("HH:mm:ss")); string chancellor, eduDirector, stuDirector; chancellor = eduDirector = stuDirector = string.Empty; XmlElement schoolInfo = K12.Data.School.Configuration["學校資訊"].PreviousData; XmlElement chancellorElement = (XmlElement)schoolInfo.SelectSingleNode("ChancellorChineseName"); XmlElement eduDirectorElement = (XmlElement)schoolInfo.SelectSingleNode("EduDirectorName"); if (chancellorElement != null) { chancellor = chancellorElement.InnerText; } if (eduDirectorElement != null) { eduDirector = eduDirectorElement.InnerText; } globalFieldName.Add("教務主任"); globalFieldValue.Add(eduDirector); globalFieldName.Add("校長"); globalFieldValue.Add(chancellor); globalFieldName.Add("成績校正日期"); globalFieldValue.Add(_rc.GetString("成績校正日期", string.Empty)); if (_config.Students.Count > _overStudentList.Count) { _doc.MailMerge.Execute(globalFieldName.ToArray(), globalFieldValue.ToArray()); } #endregion }
public ScoreInputForm(JHStudentRecord student, JHCourseRecord course) { InitializeComponent(); InitializeListener(); prlp = new PermRecLogProcess(); lblCourseName.Text = course.Name; lblStudent.Text = student.Name + " " + student.StudentNumber; _course = course; _student = student; List <JHSCAttendRecord> scattendList = JHSCAttend.SelectByStudentIDAndCourseID(new string[] { student.ID }, new string[] { course.ID }); if (scattendList.Count > 0) { _scattend = scattendList[0]; } #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 取得評量成績 _listener.SuspendListen(); // 取得所有試別 Dictionary <string, JHExamRecord> exams = JHExam.SelectAll().ToDictionary(x => x.ID); List <string> examIDs = new List <string>(exams.Keys); List <HC.JHAEIncludeRecord> aeList = new List <HC.JHAEIncludeRecord>(); if (course.RefAssessmentSetupID != null) { JHAssessmentSetupRecord assessment = JHAssessmentSetup.SelectByID(course.RefAssessmentSetupID); if (assessment != null) { foreach (JHAEIncludeRecord ae in JHAEInclude.SelectByAssessmentSetupID(assessment.ID)) { aeList.Add(new HC.JHAEIncludeRecord(ae)); } } //{ // foreach (JHAEIncludeRecord ae in JHAEInclude.SelectAll()) // { // if (ae.RefAssessmentSetupID == assessment.ID) // aeList.Add(new HC.JHAEIncludeRecord(ae)); // } //} } List <JHSCETakeRecord> jhSCEList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID); //aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y) //{ // return x.RefExamID.CompareTo(y.RefExamID); //}); aeList.Sort(delegate(HC.JHAEIncludeRecord x, HC.JHAEIncludeRecord y) { int ix = examIDs.IndexOf(x.RefExamID); int iy = examIDs.IndexOf(y.RefExamID); if (ix == -1) { ix = int.MaxValue; } if (iy == -1) { iy = int.MaxValue; } return(ix.CompareTo(iy)); }); List <HC.JHSCETakeRecord> sceList = JHSCETake.SelectByStudentAndCourse(student.ID, course.ID).AsHCJHSCETakeRecords(); Dictionary <string, DataGridViewRow> rows = new Dictionary <string, DataGridViewRow>(); foreach (HC.JHAEIncludeRecord ae in aeList) { DataGridViewRow row = new DataGridViewRow(); //JHExamRecord exam = JHExam.SelectByID(ae.RefExamID); JHExamRecord exam = null; if (exams.ContainsKey(ae.RefExamID)) { exam = exams[ae.RefExamID]; } row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + ae.RefExamID + ")", "", "", ""); dgv.Rows.Add(row); row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : ""; if (!ae.UseScore) { DisableCell(row, chScore); } if (!ae.UseAssignmentScore) { DisableCell(row, chAssignmentScore); } if (!ae.UseText) { DisableCell(row, chText); } if (!rows.ContainsKey(ae.RefExamID)) { rows.Add(ae.RefExamID, row); } } //List<HC.JHSCETakeRecord> sceList = jhSCEList.AsHCJHSCETakeRecords(); foreach (HC.JHSCETakeRecord sce in sceList) { if (rows.ContainsKey(sce.RefExamID)) { DataGridViewRow row = rows[sce.RefExamID]; if (sce.Score.HasValue) { if (PluginMain.ScoreValueMap.ContainsKey(decimal.Parse(sce.Score.Value + ""))) { row.Cells[chScore.Index].Value = PluginMain.ScoreValueMap[decimal.Parse(sce.Score.Value + "")].UseText; } else { row.Cells[chScore.Index].Value = sce.Score.Value; } } else { row.Cells[chScore.Index].Value = ""; } if (sce.AssignmentScore.HasValue) { if (PluginMain.ScoreValueMap.ContainsKey(decimal.Parse(sce.AssignmentScore.Value + ""))) { row.Cells[chAssignmentScore.Index].Value = PluginMain.ScoreValueMap[decimal.Parse(sce.AssignmentScore.Value + "")].UseText; } else { row.Cells[chAssignmentScore.Index].Value = sce.AssignmentScore.Value; } } else { row.Cells[chAssignmentScore.Index].Value = ""; } row.Cells[chText.Index].Value = sce.Text; row.Tag = sce; } else { DataGridViewRow row = new DataGridViewRow(); JHExamRecord exam = JHExam.SelectByID(sce.RefExamID); row.CreateCells(dgv, (exam != null) ? exam.Name : "無此評量(" + sce.RefExamID + ")", sce.Score.HasValue ? "" + sce.Score.Value : "", sce.AssignmentScore.HasValue ? "" + sce.AssignmentScore.Value : "", sce.Text); row.Tag = sce; row.Cells[chExamName.Index].Tag = (exam != null) ? exam.ID : ""; dgv.Rows.Add(row); DisableCell(row, chExamName); DisableCell(row, chScore); DisableCell(row, chAssignmentScore); DisableCell(row, chText); } } #region 填入修課總成績 if (_scattend != null) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgv, "課程總成績", "" + _scattend.Score, "", _scattend.Text); DisableCell(row, chAssignmentScore); row.Tag = "課程總成績"; dgv.Rows.Add(row); } #endregion foreach (DataGridViewRow dgv1 in dgv.Rows) { foreach (DataGridViewCell cell in dgv1.Cells) { cell.ErrorText = ""; if (cell.OwningColumn == chScore || cell.OwningColumn == chAssignmentScore) { cell.Style.ForeColor = Color.Black; if (!string.IsNullOrEmpty("" + cell.Value)) { decimal d; if (!decimal.TryParse("" + cell.Value, out d)) { if (PluginMain.ScoreTextMap.Keys.Count > 0) { if (!PluginMain.ScoreTextMap.ContainsKey("" + cell.Value)) { cell.ErrorText = "分數必須為數字或「" + string.Join("、", PluginMain.ScoreTextMap.Keys) + "」"; } } else { cell.ErrorText = "分數必須為數字"; } } else { if (d < 60) { cell.Style.ForeColor = Color.Red; } if (d > 100 || d < 0) { cell.Style.ForeColor = Color.Green; } } } } } } _listener.Reset(); _listener.ResumeListen(); #endregion SetLoadDataToLog(); }
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>(); //學生修課資訊 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) { 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 + "筆課程修課學生。"); } }; }