private void Insert(object item) { List <List <JHSCAttendRecord> > insertPackages = (List <List <JHSCAttendRecord> >)item; foreach (List <JHSCAttendRecord> package in insertPackages) { JHSCAttend.Insert(package); } }
private void btnAdd_Click(object sender, EventArgs e) { JHStudentRecord student = JHStudent.SelectByID(PrimaryKey); CreateForm form = new CreateForm(student); if (form.ShowDialog() == DialogResult.OK) { if (form.Course == null) { return; } try { JHSCAttendRecord scattend = new JHSCAttendRecord(); scattend.RefCourseID = form.Course.ID; scattend.RefStudentID = PrimaryKey; JHSCAttend.Insert(scattend); StringBuilder builder = new StringBuilder(""); builder.Append(StudentInfoConvertor.GetInfoWithClass(student)); builder.Append(" 加入修課:" + form.Course.Name); FISCA.LogAgent.ApplicationLog.Log("成績系統.修課及評量成績", "新增修課", "student", PrimaryKey, builder.ToString()); } catch (Exception ex) { MsgBox.Show("新增修課記錄失敗。" + ex.Message); } ScoreInputForm inputform = new ScoreInputForm(student, form.Course); inputform.ShowDialog(); if (!_worker.IsBusy) { _RunningID = PrimaryKey; _worker.RunWorkerAsync(); } } }
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 }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { #region DoWork object[] objs = (object[])e.Argument; int schoolyear = Framework.Int.Parse(objs[0] as string); int semester = Framework.Int.Parse(objs[1] as string); string domain = objs[2] as string; string subject = objs[3] as string; string periodcredit = objs[4] as string; string required = objs[5] as string; PeriodCredit pc = new PeriodCredit(); pc.Parse(periodcredit); double total = _classes.Count; double counter = 0; if (total == 0) { total = 1; } else { total *= 2; } _worker.ReportProgress(1, "正在檢查班級課程…"); _classes.Sort(SortClassesByClassName); #region 檢查重複開課 List <string> errors = new List <string>(); List <string> classIDs = new List <string>(); foreach (JHClassRecord cla in _classes) { classIDs.Add(cla.ID); } Dictionary <string, List <JHCourseRecord> > classExistCourses = new Dictionary <string, List <JHCourseRecord> >(); List <JHCourseRecord> orphanCourse = new List <JHCourseRecord>(); foreach (JHCourseRecord course in JHCourse.SelectBySchoolYearAndSemester(schoolyear, semester)) { if (!classIDs.Contains(course.RefClassID)) { orphanCourse.Add(course); continue; } if (!classExistCourses.ContainsKey(course.RefClassID)) { classExistCourses.Add(course.RefClassID, new List <JHCourseRecord>()); } classExistCourses[course.RefClassID].Add(course); } foreach (JHClassRecord cla in _classes) { if (!classExistCourses.ContainsKey(cla.ID)) { continue; } foreach (JHCourseRecord course in classExistCourses[cla.ID]) { if (course.Subject == subject) { errors.Add(cla.Name + ":已有相同科目(" + subject + ")的課程。"); } } foreach (JHCourseRecord course in orphanCourse) { if (course.Name == cla.Name + " " + subject) { errors.Add(cla.Name + ":已有相同課程名稱(" + course.Name + ")的課程。"); } } } if (errors.Count > 0) { e.Result = errors; return; } #endregion #region 開課 Dictionary <string, string> classNewCourse = new Dictionary <string, string>(); DSXmlHelper req = new DSXmlHelper("UpdateRequest"); foreach (JHClassRecord cla in _classes) { JHCourseRecord newCourse = new JHCourseRecord(); newCourse.CalculationFlag = "1"; newCourse.Period = pc.Period; newCourse.Credit = pc.Credit; newCourse.Domain = domain; newCourse.Subject = subject; newCourse.Name = cla.Name + " " + subject; newCourse.SchoolYear = schoolyear; newCourse.Semester = semester; newCourse.RefClassID = cla.ID; //建立Course時也將CourseExtendRecord建立 string course_id = JHCourse.Insert(newCourse); CourseExtendRecord courseEx = new CourseExtendRecord(); courseEx.Ref_course_id = int.Parse(course_id); courseEx.GradeYear = cla.GradeYear == null ? -1 : int.Parse(cla.GradeYear + ""); courseEx.Save(); classNewCourse.Add(cla.ID, course_id); req.AddElement("Course"); req.AddElement("Course", "Field"); req.AddElement("Course/Field", "IsRequired", required.Replace("修", "")); req.AddElement("Course", "Condition"); req.AddElement("Course/Condition", "ID", classNewCourse[cla.ID]); counter++; _worker.ReportProgress((int)(counter * 100d / total), "正在進行開課…"); } //更新必選修 if (classNewCourse.Count > 0) { JHSchool.Feature.Legacy.EditCourse.UpdateCourse(new DSRequest(req)); } #endregion #region 加入學生修課 foreach (JHClassRecord cla in _classes) { List <JHSCAttendRecord> scattends = new List <JHSchool.Data.JHSCAttendRecord>(); foreach (JHStudentRecord stu in cla.Students) { JHSCAttendRecord scattend = new JHSchool.Data.JHSCAttendRecord(); scattend.RefCourseID = classNewCourse[cla.ID]; scattend.RefStudentID = stu.ID; scattends.Add(scattend); } if (scattends.Count > 0) { JHSCAttend.Insert(scattends); } counter++; _worker.ReportProgress((int)(counter * 100d / total), "正在加入學生修課…"); } #endregion // 加這主要是重新整理 Course.Instance.SyncDataBackground(classNewCourse.Values); e.Result = string.Empty; #endregion }