}//End of Load public List <Grading> ViewThisGrades() { try { //prepare connection string using (MySqlConnection con = new MySqlConnection(Grading_System.Config2.GetConnectionString())) { //try to open connection con.Open(); //prepare sql query string sql = "SELECT * FROM grading WHERE term=@term and grade_level=@gradeLevel and full_name=@fullName"; //IDNo = @studentId and MySqlCommand cmd = new MySqlCommand(sql, con); //cmd.Parameters.AddWithValue("studentId", studentId); //cmd.Parameters.AddWithValue("subjectCode", subjectCode); cmd.Parameters.AddWithValue("term", term); cmd.Parameters.AddWithValue("gradeLevel", gradeLevel); //cmd.Parameters.AddWithValue("section", section); //cmd.Parameters.AddWithValue("strand", strand); cmd.Parameters.AddWithValue("fullName", fullName); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model Grading grade = new Grading(); //prepare properties grade.id = Convert.ToInt32(reader["id"].ToString()); grade.studentId = reader["IDNo"].ToString(); grade.fullName = reader["full_name"].ToString(); grade.subjectCode = reader["subject_code"].ToString(); grade.subjectDesc = reader["subject_desc"].ToString(); grade.units = reader["units"].ToString(); grade.firstQ = Convert.ToDouble(reader["1stQ"].ToString()); grade.secondQ = Convert.ToDouble(reader["2ndQ"].ToString()); grade.average = Convert.ToDouble(reader["average"].ToString()); grade.remarks = reader["remarks"].ToString(); grade.term = reader["term"].ToString(); grade.gradeLevel = reader["grade_level"].ToString(); grade.section = reader["section"].ToString(); grade.strand = reader["strand"].ToString(); grades.Add(grade); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.ToString(), "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(grades); }//End of Load
public List <Grading> Load() { try { using (MySqlConnection con = new MySqlConnection(Grading_System.Config2.GetConnectionString())) { con.Open(); string sql = "SELECT * FROM grading"; MySqlCommand cmd = new MySqlCommand(sql, con); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model Grading grade = new Grading(); //prepare properties grade.id = Convert.ToInt32(reader["id"].ToString()); grade.studentId = reader["IDNo"].ToString(); grade.fullName = reader["full_name"].ToString(); grade.subjectCode = reader["subject_code"].ToString(); grade.subjectDesc = reader["subject_desc"].ToString(); grade.units = reader["units"].ToString(); grade.firstQ = Convert.ToDouble(reader["1stQ"].ToString()); grade.secondQ = Convert.ToDouble(reader["2ndQ"].ToString()); grade.average = Convert.ToDouble(reader["average"].ToString()); grade.remarks = reader["remarks"].ToString(); grade.term = reader["term"].ToString(); grade.gradeLevel = reader["grade_level"].ToString(); grade.section = reader["section"].ToString(); grade.strand = reader["strand"].ToString(); grades.Add(grade); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.ToString(), "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(grades); }//End of Load
private void BtnSaveGrades_Click(object sender, EventArgs e) { if (dgvGrades.Rows.Count > 0) { for (int i = 0; i < dgvGrades.Rows.Count; i++) { Grading g = new Grading(); g.StudentId = dgvGrades.Rows[i].Cells[1].Value.ToString(); g.SubjectCode = dgvGrades.Rows[i].Cells[3].Value.ToString(); g.FirstQ = Double.Parse(dgvGrades.Rows[i].Cells[5].Value.ToString()); g.SecondQ = Double.Parse(dgvGrades.Rows[i].Cells[6].Value.ToString()); g.Average = Double.Parse(dgvGrades.Rows[i].Cells[7].Value.ToString()); g.Remarks = dgvGrades.Rows[i].Cells[8].Value.ToString(); g.Update(); } MessageBox.Show("Grades already Submitted!", "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { return; } }