protected override void OnLoad(EventArgs e) { base.OnLoad(e); cbbConductSem2.SelectedIndex = cbbConductSem1.SelectedIndex = cbbYearConduct.SelectedIndex = 4; bool success = false; Student student = new Student(); StudentConduct studentConduct = new StudentConduct(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, ev) => { success = studentController.LoadStudentInformationById(studentID, student); if (success) { studentConduct = studentController.GetStudentConduct(studentID, grade); } }; worker.RunWorkerCompleted += (s, ev) => { if (!success || studentConduct == null) { MetroFramework.MetroMessageBox.Show(this, "Không tải được dữ liệu hạnh kiểm học sinh.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } cbbConductSem1.SelectedIndex = (int)studentConduct.Conducts[0].conductType; cbbConductSem2.SelectedIndex = (int)studentConduct.Conducts[1].conductType; cbbYearConduct.SelectedIndex = (int)studentConduct.Conducts[2].conductType; lbName.Text = string.Format("Học sinh: {1} - {0}", studentID, student.GetName()); lbSex.Text = string.Format("Giới tính: {0}", student.GetSex); }; worker.RunWorkerAsync(); }
private void UpdateConduct(object sender, EventArgs e) { bool success = false; StudentConduct studentConduct = new StudentConduct(); studentConduct.Conducts[0].conductType = (Conduct.ConductType)cbbConductSem1.SelectedIndex; studentConduct.Conducts[1].conductType = (Conduct.ConductType)cbbConductSem2.SelectedIndex; studentConduct.Conducts[2].conductType = (Conduct.ConductType)cbbYearConduct.SelectedIndex; lbInformation.Visible = mainProgressbar.Visible = true; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, ev) => { success = studentController.UpdateStudentConduct(studentID, grade, studentConduct); }; worker.RunWorkerCompleted += (s, ev) => { lbInformation.Visible = mainProgressbar.Visible = false; if (!success) { MetroFramework.MetroMessageBox.Show(this, "Có lỗi xảy ra trong quá trình cập nhật. Vui lòng thử lại sau!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MetroFramework.MetroMessageBox.Show(this, "Cập nhật hạnh kiểm thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); doneSet = true; this.Close(); }; worker.RunWorkerAsync(); }
public bool UpdateStudentConduct(string _studentID, int _grade, StudentConduct _studentConduct) { bool success = Connect(); if (!success) { return(false); } try { using (SqlCommand sqlCommand = connection.CreateCommand()) { sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "UPDATE LEARNRESULT SET ConductSE01 = @conductsem1, ConductSE02 = @conductsem2, YearConduct = @yearconduct " + "WHERE StudentID = @studentid AND Grade = @grade"; sqlCommand.Parameters.AddWithValue("@studentid", _studentID); sqlCommand.Parameters.AddWithValue("@grade", _grade); if (_studentConduct.Conducts[0].ToString() == string.Empty) { sqlCommand.Parameters.AddWithValue("@conductsem1", DBNull.Value); } else { sqlCommand.Parameters.AddWithValue("@conductsem1", _studentConduct.Conducts[0].ToString()); } if (_studentConduct.Conducts[1].ToString() == string.Empty) { sqlCommand.Parameters.AddWithValue("@conductsem2", DBNull.Value); } else { sqlCommand.Parameters.AddWithValue("@conductsem2", _studentConduct.Conducts[1].ToString()); } if (_studentConduct.Conducts[2].ToString() == string.Empty) { sqlCommand.Parameters.AddWithValue("@yearconduct", DBNull.Value); } else { sqlCommand.Parameters.AddWithValue("@yearconduct", _studentConduct.Conducts[2].ToString()); } sqlCommand.ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { Disconnect(); } return(true); }
public StudentConduct GetStudentConduct(string _studentID, int _grade) { StudentConduct studentConduct = new StudentConduct(); bool success = studentDA.GetStudentConduct(_studentID, _grade, studentConduct); if (!success) { return(null); } return(studentConduct); }
public Dictionary <string, StudentConduct> GetStudentsConduct(List <Student> students) { Dictionary <string, StudentConduct> studentConducts = new Dictionary <string, StudentConduct>(); foreach (Student student in students) { StudentConduct studentConduct = new StudentConduct(); studentDA.GetStudentConduct(student.ID, Int32.Parse(student.GetGrade), studentConduct); studentConducts.Add(student.ID, studentConduct); } return(studentConducts); }
public bool UpdateStudentConduct(string _studentID, int _grade, StudentConduct _studentConduct) { return(studentDA.UpdateStudentConduct(_studentID, _grade, _studentConduct)); }
public bool GetStudentConduct(string _studentID, int _grade, StudentConduct _studentConduct) { bool success = Connect(); if (!success) { return(false); } try { using (SqlCommand sqlCommand = connection.CreateCommand()) { sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "SELECT ConductSE01, ConductSE02, YearConduct FROM LEARNRESULT WHERE StudentID = @studentid AND Grade = @grade"; sqlCommand.Parameters.AddWithValue("@studentid", _studentID); sqlCommand.Parameters.AddWithValue("@grade", _grade); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { reader.Read(); for (int i = 0; i < _studentConduct.Conducts.Count; i++) { _studentConduct.Conducts[i].type = (Conduct.Type)i; if (reader.IsDBNull(i)) { _studentConduct.Conducts[i].conductType = Conduct.ConductType.ChuaXet; } else { switch (reader.GetString(i)) { case "Tot": _studentConduct.Conducts[i].conductType = Conduct.ConductType.Tot; break; case "Kha": _studentConduct.Conducts[i].conductType = Conduct.ConductType.Kha; break; case "TB": _studentConduct.Conducts[i].conductType = Conduct.ConductType.TrungBinh; break; case "Yeu": _studentConduct.Conducts[i].conductType = Conduct.ConductType.Yeu; break; default: break; } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { Disconnect(); } return(true); }