protected override void OnLoad(EventArgs e) { base.OnLoad(e); List <Subject> subjects = new List <Subject>(); loader = new BackgroundWorker(); Class mainClass = new Class(); Teacher teacher = new Teacher(); loader.DoWork += (s, e) => { subjects = subjectController.LoadSubjects(); classController.LoadClass(classID, mainClass); if (mainClass.FormerTeacherID != null) { teacherController.LoadTeacher(mainClass.FormerTeacherID, teacher); } }; loader.RunWorkerCompleted += (s, e) => { lbClassID.Text = "Lớp: " + mainClass.ID; lbClassInfor.Text = string.Format("Phòng học: {0} - Sỉ số: {1}", mainClass.Room, mainClass.StudentNum); if (mainClass.FormerTeacherID != null) { txtRunnerTeacher.Text = mainClass.FormerTeacherID + " | " + teacher.GetName(); } int index = 0; foreach (Subject subject in subjects) { Add(index, subject); index++; } Dictionary <string, string> _teacherNameList = new Dictionary <string, string>(); Dictionary <string, string> _teacherNameList2 = new Dictionary <string, string>(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { teachingController.LoadTeaching(classID, 1, teacherList, editableList); foreach (KeyValuePair <string, string> id in teacherList) { if (string.IsNullOrEmpty(id.Value)) { continue; } Teacher _teacher = new Teacher(); teacherController.LoadTeacher(id.Value, _teacher); _teacherNameList.Add(id.Key, _teacher.GetName()); } teachingController.LoadTeaching(classID, 2, teacherList2, editableList2); foreach (KeyValuePair <string, string> id in teacherList2) { if (string.IsNullOrEmpty(id.Value)) { continue; } Teacher _teacher = new Teacher(); teacherController.LoadTeacher(id.Value, _teacher); _teacherNameList2.Add(id.Key, _teacher.GetName()); } }; worker.RunWorkerCompleted += (s, e) => { foreach (Control control in tbpgSem1.Controls) { try { if (control is MaterialTextBox && !string.IsNullOrEmpty(teacherList[control.Tag.ToString()])) { control.Text = teacherList[control.Tag.ToString()] + " | " + _teacherNameList[control.Tag.ToString()]; } if (control is MaterialCheckBox) { (control as MaterialCheckBox).Checked = !editableList[control.Tag.ToString()]; } } catch { } } foreach (Control control in tbpgSem2.Controls) { try { if (control is MaterialTextBox && !string.IsNullOrEmpty(teacherList2[control.Tag.ToString()])) { control.Text = teacherList2[control.Tag.ToString()] + " | " + _teacherNameList2[control.Tag.ToString()]; } if (control is MaterialCheckBox) { (control as MaterialCheckBox).Checked = !editableList2[control.Tag.ToString()]; } } catch { } } }; worker.RunWorkerAsync(); }; loader.RunWorkerAsync(); }