private void ProcessDomain(Dictionary <string, DomainScoreCalculator> domainscores, JHSCETakeRecord take, JHCourseRecord course, RatingStudent student, ScoreItem subject, ScoreItem domain) { if (!course.Credit.HasValue) { return; //如果課程沒有權重就不處理。 } decimal weight = course.Credit.Value; if (!SelectedItems.Contains(domain)) { return; //不在處理的領域清單中。 } if (!domainscores.ContainsKey(student.Id)) { domainscores.Add(student.Id, new DomainScoreCalculator()); } if (domainscores[student.Id].Contains(subject.Name)) { throw new ArgumentException(string.Format("學生「{0}」在同一學期修習「{1}」科目一次以上。", student.Name, subject.Name)); } domainscores[student.Id].Add(domain.Name, subject.Name, take.Score.Value, weight); }
protected override void OnSaveButtonClick(EventArgs e) { if (!IsValid()) { return; } JHCourseRecord record = JHCourse.SelectByID(PrimaryKey); //CourseRecordEditor editor = record.GetEditor(); if (rdoCalcTrue.Checked) { record.CalculationFlag = "1"; } else { record.CalculationFlag = "2"; } record.RefAssessmentSetupID = string.Empty; if (cboAssessmentSetup.SelectedItem != null) { ComboBoxItem item = (cboAssessmentSetup.SelectedItem as ComboBoxItem); if (item.Tag != null && (item.Tag + "") != string.Empty) { record.RefAssessmentSetupID = (item.Tag as JHAssessmentSetupRecord).ID; } } JHCourse.Update(record); }
internal void Add(HC.JHSCETakeRecord sce) { if (!_courseDict.ContainsKey(sce.RefCourseID)) { return; } JHCourseRecord course = _courseDict[sce.RefCourseID]; if (!Domains.ContainsKey(course.Domain)) { Domains.Add(course.Domain, new DomainRow(course.Domain)); } DomainRow row = Domains[course.Domain]; if (!row.Subjects.ContainsKey(course.Subject)) { row.AddSubject(course.Subject); } SubjectRow subjectRow = row.Subjects[course.Subject]; subjectRow.RefAssessmentSetupID = course.RefAssessmentSetupID; subjectRow.SetPeriodCredit(course.Period, course.Credit); subjectRow.Score = sce.Score; subjectRow.AssignmentScore = sce.AssignmentScore; subjectRow.Text = sce.Text; subjectRow.Display = true; }
private void DisplayRecord(JHCourseRecord record) { Enabled = (record != null); if (!Enabled) { return; } Errors.Clear(); if (record != null) { if (record.CalculationFlag == "1") { rdoCalcTrue.Checked = true; } //else if (record.CalculationFlag == "2") else if (record.CalculationFlag == "2" || record.CalculationFlag == "") { rdoCalcFalse.Checked = true; } } JHAssessmentSetupRecord ass = JHAssessmentSetup.SelectByID(record.RefAssessmentSetupID); if (ass != null) { cboAssessmentSetup.Text = ass.Name; } else { cboAssessmentSetup.SelectedItem = NoScoreItem; } }
internal void AddCourse(string student_id, JHCourseRecord course) { if (!courseTable.ContainsKey(student_id)) { return; } courseTable[student_id].Add(course); }
private void FillSubjectOptions() { if (!Sems.ValidateControlContent()) { return; } #region 讀取修課記錄,並群組出科目項目。 string examid = ExamId; List <string> studentIDs = Students.ToKeys(); Dictionary <string, int> subjectCount = new Dictionary <string, int>(); Dictionary <string, decimal> subjectWeight = new Dictionary <string, decimal>(); foreach (JHSCAttendRecord record in SCAttends.Values) { JHCourseRecord course = Courses[record.RefCourseID]; if (!IncludeQuery.Contains(course.RefAssessmentSetupID, examid)) { continue; } string subject = course.Subject.Trim(); //course.RefAssessmentSetupID //JHAssessmentSetup.SelectByID("").ID //JHAEInclude.SelectByAssessmentSetupID("")[0].ExamName //隨機取得一個課程的 Credit 當作是 Subject 的比重。 if (!subjectWeight.ContainsKey(subject)) { subjectWeight.Add(subject, 0); subjectWeight[subject] = course.Credit.HasValue ? course.Credit.Value : 0; } //計算科目的修習人數。 if (!subjectCount.ContainsKey(subject)) { subjectCount.Add(subject, 0); } subjectCount[subject]++; } List <string> subjects = new List <string>(subjectCount.Keys); subjects.Sort(new Comparison <string>(SubjectSorter.Sort)); dgv.SuspendLayout(); dgv.Rows.Clear(); foreach (string eachSubj in subjects) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgv, false, subjectWeight[eachSubj], eachSubj, subjectCount[eachSubj]); dgv.Rows.Add(row); } dgv.ResumeLayout(); #endregion }
private bool IsValidSubject(JHCourseRecord each) { if (FilterSubject.Count > 0) //大於零才過慮。 { return(FilterSubject.Contains(each.Subject.Trim())); } else //不然就通通都要算。 { return(true); } }
public List <JHStudentRecord> GetAttendStudents(JHCourseRecord course) { List <JHStudentRecord> list = new List <JHStudentRecord>(); if (ContainsKey(course.ID)) { foreach (JHSCAttendRecord sca in this[course.ID]) { list.Add(JHStudent.SelectByID(sca.RefStudentID)); } } return(list); }
private void OpenScoreInputForm() { if (listView.SelectedItems.Count <= 0) { return; } ListViewItem item = listView.SelectedItems[0]; JHCourseRecord course = item.Tag as JHCourseRecord; ScoreInputForm form = new ScoreInputForm(JHStudent.SelectByID(PrimaryKey), course); form.ShowDialog(); }
private void FillData() { lvSubject.Items.Clear(); lvDomain.Items.Clear(); lvSubject.SuspendLayout(); lvDomain.SuspendLayout(); Dictionary <string, ListViewItem> subjectItems = new Dictionary <string, ListViewItem>(); Dictionary <string, ListViewItem> domainItems = new Dictionary <string, ListViewItem>(); //string id = (cb.SelectedItem as JHExamRecord).ID; foreach (string courseID in _courseList) { JHCourseRecord course = _courseDict[courseID]; ListViewItem subject_item; if (!subjectItems.ContainsKey(course.Subject)) { subject_item = new ListViewItem(course.Subject); List <string> ids = new List <string>(); subject_item.Tag = ids; subjectItems.Add(course.Subject, subject_item); } subject_item = subjectItems[course.Subject]; (subject_item.Tag as List <string>).Add(course.ID); if (!domainItems.ContainsKey(course.Domain)) { ListViewItem domain_item = new ListViewItem(course.Domain); domainItems.Add(course.Domain, domain_item); } } List <ListViewItem> itemList = new List <ListViewItem>(subjectItems.Values); itemList.Sort(ItemSort); foreach (ListViewItem item in itemList) { (item.Tag as List <string>).Sort(); lvSubject.Items.Add(item); } List <ListViewItem> itemList2 = new List <ListViewItem>(domainItems.Values); itemList2.Sort(ItemSortDomain); foreach (ListViewItem item in itemList2) { lvDomain.Items.Add(item); } lvSubject.ResumeLayout(); lvDomain.ResumeLayout(); }
/// <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)); }
public JHTeacherRecord GetTeacher(JHCourseRecord course, int sequence) { if (!ContainsKey(course.ID)) { return(null); } foreach (JHTCInstructRecord record in this[course.ID]) { if (record.Sequence == sequence) { return(JHTeacher.SelectByID(record.RefTeacherID)); } } return(null); }
public JHTCInstructRecord GetInstruct(JHCourseRecord course, int sequence) { if (!ContainsKey(course.ID)) { return(null); } foreach (JHTCInstructRecord record in this[course.ID]) { if (record.Sequence == sequence) { return(record); } } return(null); }
/// <summary> /// 加入課程 /// </summary> /// <param name="studentID"></param> /// <param name="course"></param> public void Add(string studentID, JHCourseRecord course) { if (!_attend.ContainsKey(studentID)) { _attend.Add(studentID, new SubjectCoursesCollection()); } SubjectCoursesCollection collection = _attend[studentID]; if (!collection.ContainsKey(course.Subject)) { collection.Add(course.Subject, new List <string>()); } collection[course.Subject].Add(course.ID); }
internal bool HasExam(JHCourseRecord course) { bool retVal = false; // 取得考試 if (aeExamName.ContainsKey(course.RefAssessmentSetupID)) { if (aeExamName[course.RefAssessmentSetupID].Contains(Exam.Name)) { retVal = true; } } return(retVal); //if (string.IsNullOrEmpty(course.RefAssessmentSetupID)) return false; //if (_asWithExam.Contains(course.RefAssessmentSetupID)) return true; //else return false; }
public MainFormScoreInput(JHCourseRecord courseRec) { InitializeComponent(); _EffortMap = new EffortMap(); _CourseRec = courseRec; CIDs = new List <string>(); _StudOldScoreDic = new Dictionary <string, string>(); _StudOldEffortDic = new Dictionary <string, string>(); CIDs.Add(courseRec.ID); _SCAttendListDic = new Dictionary <string, JHSCAttendRecord>(); lblCourseName.Text = courseRec.Name; _StudentSCAtendScoreList = new List <StudentSCAtendScore>(); // this.MinimumSize = this.MaximumSize = this.Size; // 取得課程評量 _AssessmentSetupRec = JHAssessmentSetup.SelectByID(courseRec.RefAssessmentSetupID); }
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 }
internal void Add(KH.JHSCETakeRecord sce) { if (!_courseDict.ContainsKey(sce.RefCourseID)) { return; } JHCourseRecord course = _courseDict[sce.RefCourseID]; if (!Domains.ContainsKey(course.Domain)) { Domains.Add(course.Domain, new DomainRow(course.Domain)); } DomainRow row = Domains[course.Domain]; if (_config.DomainSubjectSetup == DomainSubjectSetup.Subject) { row.Display = false; } else { row.Display = true; } row.AddExamID(sce.RefExamID); if (!row.Subjects.ContainsKey(course.Subject)) { row.Subjects.Add(course.Subject, new SubjectRow(course.Subject)); } SubjectRow subjectRow = row.Subjects[course.Subject]; subjectRow.SetPeriodCredit(course.Period, course.Credit); subjectRow.AddScore(sce.RefExamID, sce.Score, sce.Effort); if (_config.DomainSubjectSetup == DomainSubjectSetup.Subject) { subjectRow.Display = true; } }
internal void AddAssignment(JHSCAttendRecord assignment) { if (!_courseDict.ContainsKey(assignment.RefCourseID)) { return; } JHCourseRecord course = _courseDict[assignment.RefCourseID]; if (!Domains.ContainsKey(course.Domain)) { return; } DomainRow row = Domains[course.Domain]; if (!row.Subjects.ContainsKey(course.Subject)) { return; } SubjectRow subjectRow = row.Subjects[course.Subject]; subjectRow.AssignmentScore = assignment.OrdinarilyScore; }
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(); }
internal void Read() { Courses = ReadCourse(); AEIncludes = ReadAEInclude(); Attends = ReadCurrentSemesterAttend(); List <JHSCETakeRecord> SCETakes = ReadSCETake(); // 取得新竹評量樣版設定 Util.ScorePercentageHSDict.Clear(); Util.ScorePercentageHSDict = Util.GetScorePercentageHS(); //清除原有的資料。 foreach (StudentScore each in Students.Values) { each.AttendScore.Clear(); } Reporter.Feedback("計算成績...", 0); int t1 = Environment.TickCount; foreach (JHSCAttendRecord Attend in Attends.Values) { if (!Students.ContainsKey(Attend.RefStudentID)) { continue; } StudentScore Student = Students[Attend.RefStudentID]; if (!Courses.ContainsKey(Attend.RefCourseID)) { continue; } JHCourseRecord Course = Courses[Attend.RefCourseID]; bool toSems = (Course.CalculationFlag == "1") ? true : false; string subjName = Course.Subject.Trim(); // 如果科目名稱空白就不處理,因為無法計算到科目成績 if (string.IsNullOrWhiteSpace(subjName)) { continue; } //傳入學年度,判斷103以前的學年度5:5而以後6:4比例計算 if (!Student.AttendScore.Contains(subjName)) { Student.AttendScore.Add(subjName, new AttendScore(Attend, Course.Credit, Course.Period, toSems, Course.Domain, Course.SchoolYear)); } } try { foreach (JHSCETakeRecord take in SCETakes) { if (!Attends.ContainsKey(take.RefSCAttendID)) { continue; } JHSCAttendRecord Attend = Attends[take.RefSCAttendID]; if (!Students.ContainsKey(Attend.RefStudentID)) { continue; } StudentScore Student = Students[Attend.RefStudentID]; if (!Courses.ContainsKey(Attend.RefCourseID)) { continue; } JHCourseRecord Course = Courses[Attend.RefCourseID]; if (!AEIncludes.ContainsKey(Course.RefAssessmentSetupID)) { continue; } Dictionary <string, AEIncludeData> Include = AEIncludes[Course.RefAssessmentSetupID]; //沒有該次考試就不處理。 if (!Include.ContainsKey(take.RefExamID)) { continue; } string subjName = Course.Subject.Trim(); // 如果科目名稱空白就不處理,因為無法計算到科目成績 if (string.IsNullOrWhiteSpace(subjName)) { continue; } try { Student.AttendScore[subjName].Subscores.Add(take.RefExamID, new TakeScore(take, Include[take.RefExamID])); } catch (Exception ex) { Console.Write(ex.Message); } } } catch (Exception ex) { Console.Write(ex.Message); } Reporter.Feedback("時間:" + (Environment.TickCount - t1), 0); }
public static List <InternalExamScoreRecord> Select(IEnumerable <string> StudentIDs, UserOptions Options) { //key:CourseID Dictionary <string, JHCourseRecord> dictCourses = Utilities.GetCourseDict(Options.SchoolYear, Options.Semester); //key:AssessmentSetupID Dictionary <string, JHAEIncludeRecord> dictAEIncludes = Utilities.GetAEIncludeDict(dictCourses.Values.ToAssessmentSetupIDs(), Options.Exam); //類似學期成績的結構… Dictionary <string, InternalExamScoreRecord> dictStudentScores = new Dictionary <string, InternalExamScoreRecord>(); // 取得評量比例 Utilities.ScorePercentageHSDict = Utilities.GetScorePercentageHS(); #region 取得及轉換評量科目成績 int size = 200; int thread = 5; FunctionSpliter <string, JHSCETakeRecord> spliter = new FunctionSpliter <string, JHSCETakeRecord>(size, thread); spliter.Function = delegate(List <string> studentKeysPart) { return(JHSCETake.Select(null, studentKeysPart, new string[] { Options.Exam.ID }, null, null)); }; foreach (JHSCETakeRecord sce in spliter.Execute(StudentIDs.ToList())) { if (!dictCourses.ContainsKey(sce.RefCourseID)) { continue; //評量成績所屬課程非本學期,跳過 } if (Options.Exam.ID != sce.RefExamID) { continue; //評量成績的試別不符,跳過 } JHCourseRecord course = dictCourses[sce.RefCourseID]; if (!dictAEIncludes.ContainsKey(course.RefAssessmentSetupID)) { continue; //如果課程沒有評量設定,跳過 } JHAEIncludeRecord ae = dictAEIncludes[course.RefAssessmentSetupID]; //每個學生一個 InternalExamScoreRecord if (!dictStudentScores.ContainsKey(sce.RefStudentID)) { dictStudentScores.Add(sce.RefStudentID, new InternalExamScoreRecord(sce.RefStudentID)); } if (!dictStudentScores[sce.RefStudentID].Subjects.ContainsKey(course.Subject)) { SubjectScore subjectScore = new SubjectScore(); subjectScore.Domain = course.Domain; subjectScore.Subject = course.Subject; subjectScore.Period = course.Period; subjectScore.Credit = course.Credit; subjectScore.Score = Utilities.GetScore(new HC.JHSCETakeRecord(sce), new HC.JHAEIncludeRecord(ae), Options.ScoreSource); if (subjectScore.Score.HasValue) { dictStudentScores[sce.RefStudentID].Subjects.Add(course.Subject, subjectScore); } } } #endregion #region 計算評量領域成績 JHSchool.Evaluation.Calculation.ScoreCalculator defaultCalculator = new JHSchool.Evaluation.Calculation.ScoreCalculator(null); StudentScore.SetClassMapping(); List <StudentScore> Students = ToStudentScore(StudentIDs); Students.ReadCalculationRule(null); foreach (StudentScore student in Students) { student.SemestersScore.Add(SemesterData.Empty, new global::JHEvaluation.ScoreCalculation.ScoreStruct.SemesterScore(Options.SchoolYear, Options.Semester)); if (!dictStudentScores.ContainsKey(student.Id)) { continue; } global::JHEvaluation.ScoreCalculation.ScoreStruct.SemesterScore semesterScore = student.SemestersScore[SemesterData.Empty]; foreach (SubjectScore score in dictStudentScores[student.Id].Subjects.Values) { //科目成績偷偷進位 if (score.Score.HasValue) { if (student.CalculationRule != null) { score.Score = student.CalculationRule.ParseSubjectScore(score.Score.Value); } else { score.Score = defaultCalculator.ParseSubjectScore(score.Score.Value); } } if (!semesterScore.Subject.Contains(score.Subject)) { semesterScore.Subject.Add(score.Subject, new SemesterSubjectScore(score)); } } } Students.CalcuateDomainSemesterScore(new string[] { }); #endregion foreach (StudentScore student in Students) { if (!dictStudentScores.ContainsKey(student.Id)) { dictStudentScores.Add(student.Id, new InternalExamScoreRecord(student.Id)); } InternalExamScoreRecord examScore = dictStudentScores[student.Id]; examScore.Subjects = ToSubjects(student.SemestersScore[SemesterData.Empty].Subject); examScore.Domains = ToDomains(student.SemestersScore[SemesterData.Empty].Domain); } return(new List <InternalExamScoreRecord>(dictStudentScores.Values)); }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { #region DoWork SelectSemesterForm opt = e.Argument as SelectSemesterForm; Worker.ReportProgress(0, "正在進行開課..."); double totalClass = K12.Presentation.NLDPanels.Class.SelectedSource.Count; if (totalClass <= 0) { totalClass = 0; } double classCount = 0; Dictionary <string, JHCourseRecord> subjectCourseDict = new Dictionary <string, JHCourseRecord>(); foreach (JHClassRecord cla in JHClass.SelectByIDs(K12.Presentation.NLDPanels.Class.SelectedSource)) { #region 班級開課 classCount++; int gradeYear = 0; //取得班級年級 if (!cla.GradeYear.HasValue) { continue; } gradeYear = cla.GradeYear.Value; // TODO: 先寫著,之後再討論… if (gradeYear >= 7) { gradeYear -= 6; } #region 取得班級內每個學生的課程規劃表 List <JHProgramPlanRecord> programPlanList = new List <JHProgramPlanRecord>(); List <JHStudentRecord> studentsInSchool = GetInSchoolStudents(cla.Students); if (studentsInSchool.Count > 0) //班級有學生,抓學生課程規劃表 { foreach (JHStudentRecord stu in studentsInSchool) { //取得學生的課程規劃表 JHProgramPlanRecord record = PPCollection.GetProgramPlanRecord(stu); if (record != null) { if (!programPlanList.Contains(record)) { programPlanList.Add(record); } } } } else //班級沒有學生,也是要開課的! { JHProgramPlanRecord record = PPCollection.GetProgramPlanRecord(cla); if (record != null) { if (!programPlanList.Contains(record)) { programPlanList.Add(record); } } } #endregion #region 所有課程規劃表中要開的課程 Dictionary <string, K12.Data.ProgramSubject> courseDict = new Dictionary <string, K12.Data.ProgramSubject>(); foreach (JHProgramPlanRecord record in programPlanList) { foreach (K12.Data.ProgramSubject subject in record.Subjects) { if (subject.GradeYear == gradeYear && subject.Semester == opt.Semester && subject.Period.HasValue && subject.Credit.HasValue) { string key = subject.SubjectName.Trim(); if (!courseDict.ContainsKey(key)) { courseDict.Add(key, subject); } } } } #endregion //快取來源學期課程先放這 Dictionary <string, JHCourseRecord> copySourceCourses = new Dictionary <string, JHCourseRecord>(); #region 取得本學期已開的課程 Dictionary <string, JHCourseRecord> existSubjects = new Dictionary <string, JHCourseRecord>(); foreach (JHCourseRecord course in JHCourse.SelectAll()) { #region 取得複製來源學期的課程,智慧型開課需要 if (opt.CopyOptionEnabled && (opt.CopyTeacher || opt.CopyAssessmentSetup)) { if (course.SchoolYear == opt.CopySchoolYear && course.Semester == opt.CopySemester && course.RefClassID == cla.ID) { if (!copySourceCourses.ContainsKey(course.Subject)) { copySourceCourses.Add(course.Subject, course); } } } #endregion //取得本學期的課程 if (course.SchoolYear == opt.SchoolYear && course.Semester == opt.Semester && course.RefClassID == cla.ID) { if (!existSubjects.ContainsKey(course.Subject)) { existSubjects.Add(course.Subject, course); } } } #endregion #region 開課(加入新課程) List <JHCourseRecord> insertCourseList = new List <JHCourseRecord>(); foreach (string key in courseDict.Keys) { //是原來沒有的課程 if (!existSubjects.ContainsKey(key)) { K12.Data.ProgramSubject subject = courseDict[key]; JHCourseRecord newCourse = new JHCourseRecord(); newCourse.Credit = subject.Credit; newCourse.Period = subject.Period; newCourse.Domain = subject.Domain; newCourse.Name = cla.Name + " " + subject.SubjectName; newCourse.SchoolYear = opt.SchoolYear; newCourse.Semester = opt.Semester; newCourse.Subject = subject.SubjectName.Trim(); newCourse.RefClassID = cla.ID; newCourse.CalculationFlag = subject.CalcFlag ? "1" : "2"; insertCourseList.Add(newCourse); } } if (insertCourseList.Count > 0) { JHCourse.Insert(insertCourseList); } #endregion #region 重新取得本學期已開的課程(包含這次新開的課程) JHCourse.RemoveAll(); Dictionary <string, JHCourseRecord> reloadedExistSubjects = new Dictionary <string, JHCourseRecord>(); List <string> courseIDs = new List <string>(); foreach (JHCourseRecord course in JHCourse.SelectAll()) { if (course.SchoolYear == opt.SchoolYear && course.Semester == opt.Semester && course.RefClassID == cla.ID) { string key = course.Subject; if (!reloadedExistSubjects.ContainsKey(key)) { reloadedExistSubjects.Add(key, course); } courseIDs.Add(course.ID); } } #endregion #region 加入學生修課 CourseAttendCollection caCollection = new CourseAttendCollection(); foreach (JHSCAttendRecord sca in JHSCAttend.SelectByCourseIDs(courseIDs)) { if (!caCollection.ContainsKey(sca.RefCourseID)) { caCollection.Add(sca.RefCourseID, new List <JHSCAttendRecord>()); } caCollection[sca.RefCourseID].Add(sca); } List <JHSCAttendRecord> insertSCAttendList = new List <JHSCAttendRecord>(); foreach (JHStudentRecord student in GetInSchoolStudents(cla.Students)) { if (PPCollection.GetProgramPlanRecord(student) == null) { continue; } foreach (K12.Data.ProgramSubject subject in PPCollection.GetProgramPlanRecord(student).Subjects) { string key = subject.SubjectName.Trim(); if (subject.GradeYear == gradeYear && subject.Semester == opt.Semester && reloadedExistSubjects.ContainsKey(key)) { bool found = false; foreach (JHStudentRecord attendStudent in caCollection.GetAttendStudents(reloadedExistSubjects[key])) { if (attendStudent.ID == student.ID) { found = true; break; } } if (found == false) { JHSCAttendRecord newSCAttend = new JHSCAttendRecord(); newSCAttend.RefStudentID = student.ID; newSCAttend.RefCourseID = reloadedExistSubjects[key].ID; insertSCAttendList.Add(newSCAttend); } } } } if (insertSCAttendList.Count > 0) { int t1 = Environment.TickCount; JHSCAttend.Insert(insertSCAttendList); Trace.WriteLine("寫入修課記錄時間:" + (Environment.TickCount - t1).ToString()); } #endregion #region 判斷是否進行智慧型開課 if (opt.CopyOptionEnabled) { CourseInstructCollection ciCollection = new CourseInstructCollection(); CourseInstructCollection currentCICollection = new CourseInstructCollection(); List <string> copyCourseIDs = new List <string>(); foreach (JHCourseRecord course in copySourceCourses.Values) { copyCourseIDs.Add(course.ID); } foreach (JHTCInstructRecord tc in JHTCInstruct.SelectByTeacherIDAndCourseID(new string[] { }, copyCourseIDs)) { if (!ciCollection.ContainsKey(tc.RefCourseID)) { ciCollection.Add(tc.RefCourseID, new List <JHTCInstructRecord>()); } ciCollection[tc.RefCourseID].Add(tc); } foreach (JHTCInstructRecord tc in JHTCInstruct.SelectByTeacherIDAndCourseID(new string[] { }, courseIDs)) { if (!currentCICollection.ContainsKey(tc.RefCourseID)) { currentCICollection.Add(tc.RefCourseID, new List <JHTCInstructRecord>()); } currentCICollection[tc.RefCourseID].Add(tc); } List <JHTCInstructRecord> insertTCList = new List <JHTCInstructRecord>(); List <JHTCInstructRecord> updateTCList = new List <JHTCInstructRecord>(); List <JHCourseRecord> updateCourseList = new List <JHCourseRecord>(); //針對目前這個班級在開課學年度學期的所有課程 foreach (JHCourseRecord course in reloadedExistSubjects.Values) { //如果課程不存在課程規劃表中,則不處理 if (!courseDict.ContainsKey(course.Subject)) { continue; } //複製來源課程中,如果有相同科目名稱,則進行複製 if (copySourceCourses.ContainsKey(course.Subject)) { JHCourseRecord copyCourseRecord = copySourceCourses[course.Subject]; #region 自動加入授課教師 if (opt.CopyTeacher == true) { for (int i = 1; i <= 3; i++) { //取得來源課程的授課教師 JHTeacherRecord teacherRecord = ciCollection.GetTeacher(copyCourseRecord, i); if (teacherRecord != null) { //取得開課課程的授課記錄 JHTCInstructRecord tc = currentCICollection.GetInstruct(course, i); if (tc == null) { tc = new JHTCInstructRecord(); tc.RefCourseID = course.ID; tc.RefTeacherID = teacherRecord.ID; tc.Sequence = i; insertTCList.Add(tc); } else { tc.RefTeacherID = teacherRecord.ID; updateTCList.Add(tc); } } } } #endregion #region 自動加入評量設定 if (opt.CopyAssessmentSetup == true) { course.RefAssessmentSetupID = copyCourseRecord.RefAssessmentSetupID; updateCourseList.Add(course); } #endregion } } if (insertTCList.Count > 0) { JHTCInstruct.Insert(insertTCList); } if (updateTCList.Count > 0) { JHTCInstruct.Update(updateTCList); } if (updateCourseList.Count > 0) { JHCourse.Update(updateCourseList); } } #endregion #endregion //回報進度 Worker.ReportProgress((int)(classCount * 100d / totalClass), "正在進行開課..."); } #endregion }
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 }; }
private void FillItemOptions() { if (!Sems.ValidateControlContent()) { return; } dgv.SuspendLayout(); dgv.Rows.Clear(); #region 讀取修課記錄,並群組出科目項目。 string examid = ExamId; List <string> studentIDs = Students.ToKeys(); Dictionary <string, int> subjectCount = new Dictionary <string, int>(); Dictionary <string, decimal> subjectWeight = new Dictionary <string, decimal>(); foreach (JHSCAttendRecord record in SCAttends.Values) { JHCourseRecord course = Courses[record.RefCourseID]; if (!IncludeQuery.Contains(course.RefAssessmentSetupID, examid)) { continue; } string subject = course.Subject.Trim(); //隨機取得一個課程的 Credit 當作是 Subject 的比重。 if (!subjectWeight.ContainsKey(subject)) { subjectWeight.Add(subject, 0); subjectWeight[subject] = course.Credit.HasValue ? course.Credit.Value : 0; } //計算科目的修習人數。 if (!subjectCount.ContainsKey(subject)) { subjectCount.Add(subject, 0); } subjectCount[subject]++; } List <string> subjects = new List <string>(subjectCount.Keys); subjects.Sort(new Comparison <string>(SubjectSorter.Sort)); foreach (string eachSubj in subjects) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgv, false, subjectWeight[eachSubj], eachSubj, subjectCount[eachSubj]); row.Tag = new ScoreItem(eachSubj, ScoreType.Subject); dgv.Rows.Add(row); } #endregion #region 列出領域名稱。 foreach (string each in NameMapping.Keys) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgv, false, 1, each); row.Cells[chScoreItem.Index].Style.ForeColor = Color.Blue; row.Tag = new ScoreItem(each, ScoreType.Domain); dgv.Rows.Add(row); } #endregion dgv.ResumeLayout(); }
private Dictionary <string, JHSCAttendRecord> ReadCurrentSemesterAttend() { Reporter.Feedback("讀取修課資料...", 0); List <string> studKeys = Students.Values.ToKeys(); Dictionary <string, JHSCAttendRecord> currentAttends = new Dictionary <string, JHSCAttendRecord>(); //分批取得資料。 FunctionSpliter <string, JHSCAttendRecord> spliter = new FunctionSpliter <string, JHSCAttendRecord>(300, Util.MaxThread); spliter.Function = delegate(List <string> studKeysPart) { return(JHSCAttend.SelectByStudentIDs(studKeysPart)); }; spliter.ProgressChange = delegate(int progress) { Reporter.Feedback("讀取修課資料...", Util.CalculatePercentage(studKeys.Count, progress)); }; List <JHSCAttendRecord> allAttends = spliter.Execute(studKeys); //用於檢查重覆修習科目。 //Dictionary<string, Dictionary<string, string>> duplicate = new Dictionary<string, Dictionary<string, string>>(); //過濾修課記錄的學年度、學期,只要本學期的成績。 foreach (JHSCAttendRecord each in allAttends) { if (!Courses.ContainsKey(each.RefCourseID)) { continue; } JHCourseRecord course = Courses[each.RefCourseID]; if (!course.SchoolYear.HasValue) { continue; } if (!course.Semester.HasValue) { continue; } if (course.SchoolYear.Value != SchoolYear) { continue; } if (course.Semester.Value != Semester) { continue; } currentAttends.Add(each.ID, each); //// 2016/5/25 穎驊新增 ,只有在該科目需要列入計算才更進一步加到currentAttends,如此一來可以濾掉科目名稱為空的社團課(不列入計算的課) //if (each.Course.CalculationFlag == "1") //{ // #region 檢查重覆修習科目。 // if (!duplicate.ContainsKey(each.RefStudentID)) // duplicate.Add(each.RefStudentID, new Dictionary<string, string>()); // if (duplicate[each.RefStudentID].ContainsKey(course.Subject.Trim())) // { // if (!Students.ContainsKey(each.RefStudentID)) continue; // StudentScore student = Students[each.RefStudentID]; // // 2016/5/25 穎驊新增,針對如果同一學生同一學期有修習同一門科目名稱的課,會跳出視窗提醒。 // MessageBox.Show(string.Format("學生「{0}」在「{1}」學年「{2}」學期,重覆修習科目「{3}」,將使學期科目成績計算遺漏誤植,請確認並修正該科目。", student.Name, course.SchoolYear, course.Semester, course.Subject)); // break; // //throw new ArgumentException(string.Format("學生「{0}」重覆修習科目「{1}」。", student.Name, course.Subject)); // //continue; //先略過不管。 // } // duplicate[each.RefStudentID].Add(course.Subject.Trim(), null); // #endregion; // currentAttends.Add(each.ID, each); //} } return(currentAttends); }
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>(); }