void _BGWork_DoWork(object sender, DoWorkEventArgs e) { _AllTeacherNameDic.Clear(); _AllLogIDDic.Clear(); _AllIDNumberDict.Clear(); foreach (JHTeacherRecord TR in JHTeacher.SelectAll()) { _AllTeacherNameDic.Add(TR.Name + TR.Nickname, TR.ID); if (!string.IsNullOrEmpty(TR.TALoginName)) { _AllLogIDDic.Add(TR.TALoginName, TR.ID); } // 身分證號檢查 if (!string.IsNullOrWhiteSpace(TR.IDNumber)) { if (!_AllIDNumberDict.ContainsKey(TR.IDNumber)) { _AllIDNumberDict.Add(TR.IDNumber, TR.ID); } } } UpdateUDTData(); // 讀取教師資料 _TeacherRec = JHTeacher.SelectByID(PrimaryKey); }
// 載入資料到畫面 private void DataBindToForm() { if (_TeacherRec == null) { _TeacherRec = new JHTeacherRecord(); } _DataListener.SuspendListen(); txtName.Text = _TeacherRec.Name; txtIDNumber.Text = _TeacherRec.IDNumber; cboGender.Text = _TeacherRec.Gender; txtNickname.Text = _TeacherRec.Nickname; txtPhone.Text = _TeacherRec.ContactPhone; txtEmail.Text = _TeacherRec.Email; txtCategory.Text = _TeacherRec.Category; txtSTLoginAccount.Text = _TeacherRec.TALoginName; txtSTLoginPwd.Text = _TeacherRec.TAPassword; cboAccountType.Text = _TeacherRec.AccountType; txtTeacherNumber.Text = _TeacherRec.TeacherNumber; try { pic1.Image = Photo.ConvertFromBase64Encoding(_TeacherRec.Photo, pic1.Width, pic1.Height); } catch (Exception) { pic1.Image = pic1.InitialImage; } // Log prlp.SetBeforeSaveText("姓名", txtName.Text); prlp.SetBeforeSaveText("身分證號", txtIDNumber.Text); prlp.SetBeforeSaveText("性別", cboGender.Text); prlp.SetBeforeSaveText("暱稱", txtNickname.Text); prlp.SetBeforeSaveText("聯絡電話", txtPhone.Text); prlp.SetBeforeSaveText("電子信箱", txtEmail.Text); prlp.SetBeforeSaveText("教師類別", txtCategory.Text); prlp.SetBeforeSaveText("登入帳號", txtSTLoginAccount.Text); prlp.SetBeforeSaveText("登入密碼", txtSTLoginPwd.Text); prlp.SetBeforeSaveText("帳號類型", cboAccountType.Text); prlp.SetBeforeSaveText("教師編號", txtTeacherNumber.Text); this.Loading = false; SaveButtonVisible = false; CancelButtonVisible = false; _DataListener.Reset(); _DataListener.ResumeListen(); }
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 }