public List <TeacherAssignment> Load() { try { using (MySqlConnection con = new MySqlConnection(Grading_System.Config.GetConnectionString())) { con.Open(); string sql = "SELECT * FROM teacher_subjects"; MySqlCommand cmd = new MySqlCommand(sql, con); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model TeacherAssignment teacher = new TeacherAssignment(); //prepare properties teacher.id = Convert.ToInt32(reader["id"].ToString()); teacher.teacherId = reader["teacher_Id"].ToString(); teacher.fname = reader["fname"].ToString(); teacher.mname = reader["mname"].ToString(); teacher.lname = reader["lname"].ToString(); teacher.subjectCode = reader["subject_code"].ToString(); teacher.gradeLevel = reader["grade_level"].ToString(); teacher.section = reader["section"].ToString(); teacher.strand = reader["strand"].ToString(); teacher.semester = reader["semester"].ToString(); teachers.Add(teacher); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.ToString(), "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(teachers); }//End of Load
public List <TeacherAssignment> GetByTeacherNo2PARAM() { try { //prepare connection string using (MySqlConnection con = new MySqlConnection(Grading_System.Config.GetConnectionString())) { //try to open connection con.Open(); //prepare sql query string sql = "SELECT subject_code FROM teacher_subjects WHERE teacher_id =@teacherId and section = @section;"; MySqlCommand cmd = new MySqlCommand(sql, con); cmd.Parameters.AddWithValue("teacherId", teacherId); cmd.Parameters.AddWithValue("section", section); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model TeacherAssignment teacher = new TeacherAssignment(); //prepare properties //assesment.id = Convert.ToInt32(reader["id"].ToString()); teacher.subjectCode = reader["subject_code"].ToString(); teachers.Add(teacher); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.Message.ToString(), "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(teachers); }//OLD
private void dgvTeacher_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { //pass value to edit mode frmEditTeacher edit = new frmEditTeacher(); edit.id = this.dgvTeacher.Rows[e.RowIndex].Cells[2].Value.ToString();//for editing criteria edit.teacherId = this.dgvTeacher.Rows[e.RowIndex].Cells[3].Value.ToString(); edit.fname = this.dgvTeacher.Rows[e.RowIndex].Cells[4].Value.ToString(); edit.mname = this.dgvTeacher.Rows[e.RowIndex].Cells[5].Value.ToString(); edit.lname = this.dgvTeacher.Rows[e.RowIndex].Cells[6].Value.ToString(); edit.adviserOf = this.dgvTeacher.Rows[e.RowIndex].Cells[7].Value.ToString(); edit.course = this.dgvTeacher.Rows[e.RowIndex].Cells[8].Value.ToString(); edit.specializedSubj = this.dgvTeacher.Rows[e.RowIndex].Cells[9].Value.ToString(); edit.btnAdd.Text = "&Update";//set button to edit Users user = new Users(); List <Users> users = new List <Users>(); users.Clear(); user.Teacher_Id = this.dgvTeacher.Rows[e.RowIndex].Cells[3].Value.ToString(); users = user.GetByTeacherID(); //loop through load it to list view foreach (var item in users) { //MessageBox.Show("S"); edit.username = item.UserId; edit.pass = item.Password; edit.userType = item.UserType; }//End LoadSchedule() edit.Render();//call edit function edit.ShowDialog();// edit form } if (e.ColumnIndex == 1) { string message = "Do you want to delete this record?"; string title = "GOC_Grading_System"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, title, buttons, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { Teacher teacher = new Teacher(); teacher.Id = Convert.ToInt32(dgvTeacher.Rows[e.RowIndex].Cells[2].Value.ToString());//for editing criteria teacher.Delete(); MessageBox.Show(dgvTeacher.Rows[e.RowIndex].Cells[3].Value.ToString()); TeacherAssignment teacher2 = new TeacherAssignment(); teacher2.TeacherId = dgvTeacher.Rows[e.RowIndex].Cells[3].Value.ToString(); teacher2.Delete(); Load(); } else { return; } } }
private void btnAdd_Click(object sender, EventArgs e) { if (btnAdd.Text == "&Save")//to save new teacher { GenerateTeacherID(); Teacher addTeacher = new Teacher(); addTeacher.TeacherId = GOCNo; addTeacher.LName = txtLName.Text; addTeacher.MName = txtMName.Text; addTeacher.FName = txtFName.Text; addTeacher.AdviserOf = txtAdviserOf.Text; addTeacher.Course = txtCourse.Text; addTeacher.SpecializedSubj = txtSpeSub.Text; addTeacher.Save(); //Add User Users user = new Users(); user.UserId = txtUsername.Text; user.Password = txtPass.Text; user.UserType = cmbUserType.Text; user.FirstName = txtFName.Text; user.LastName = txtLName.Text; user.MiddleName = txtMName.Text; user.Teacher_Id = GOCNo; user.Save(); this.Close(); } else//to update teacher details { Teacher updateTeacher = new Teacher(); TeacherAssignment updateTeacherInfo = new TeacherAssignment(); updateTeacher.Id = Convert.ToInt32(txtId.Text); updateTeacher.TeacherId = txtIDNo.Text; updateTeacher.LName = txtLName.Text; updateTeacher.MName = txtMName.Text; updateTeacher.FName = txtFName.Text; updateTeacher.AdviserOf = txtAdviserOf.Text; updateTeacher.Course = txtCourse.Text; updateTeacher.SpecializedSubj = txtSpeSub.Text; updateTeacher.Update(); teach_subs.Clear(); updateTeacherInfo.TeacherId = txtIDNo.Text; teach_subs = updateTeacherInfo.Load(); //MessageBox.Show(teach_subs.Count.ToString()); for (int i = 0; i < teach_subs.Count; i++) { // MessageBox.Show(i.ToString()); //updateTeacherInfo.Id = Convert.ToInt32(txtId.Text); //updateTeacherInfo.TeacherId = txtIDNo.Text; updateTeacherInfo.Lname = txtLName.Text; updateTeacherInfo.Mname = txtMName.Text; updateTeacherInfo.Fname = txtFName.Text; updateTeacherInfo.Update(); } Users user = new Users(); user.Teacher_Id = txtIDNo.Text; user.UserId = txtUsername.Text; user.Password = txtPass.Text; user.UserType = cmbUserType.Text; user.Update(); this.Close(); } }