}//End of Load public List <EnrolledStudents> CountStudInSection() { try { //prepare connection string using (MySqlConnection con = new MySqlConnection(GOCSystem2018.Config.GetConnectionString())) { //try to open connection con.Open(); //prepare sql query string sql = "SELECT * FROM enrolled_grade_11 WHERE section =@section;"; MySqlCommand cmd = new MySqlCommand(sql, con); cmd.Parameters.AddWithValue("section", section); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model EnrolledStudents enroll = new EnrolledStudents(); //prepare properties enroll.id = Convert.ToInt32(reader["id"].ToString()); enroll.regNo = reader["regno"].ToString(); enroll.theGOCNo = reader["gocno"].ToString(); enroll.fullName = reader["full_name"].ToString(); enroll.gradeLevel = reader["grade_level"].ToString(); enroll.strand = reader["strand"].ToString(); enroll.section = reader["section"].ToString(); enroll.semester = reader["semester"].ToString(); enroll.syEnroll = reader["sy_enrolled"].ToString(); // MessageBox.Show("sasa"); enrollees.Add(enroll); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.ToString(), "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(enrollees); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { string message = "Do you want to assign all " + lblCount.Text + " Student(s) to section " + cmbToAssign.Text + "?"; string title = "GOC_INFOSYS"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, title, buttons); if (result == DialogResult.Yes) { for (int i = 0; i < dgvSectionBefore.Rows.Count; i++) { studProfile.StudGOCNo = dgvSectionBefore.Rows[i].Cells[0].FormattedValue.ToString(); studProfile.Section = cmbToAssign.Text; studProfile.UpdateTheSectionWithGOCNO(); EnrolledStudents enroll = new EnrolledStudents(); enroll.RegNo = dgvSectionBefore.Rows[i].Cells[7].FormattedValue.ToString(); enroll.TheGOCNo = dgvSectionBefore.Rows[i].Cells[0].FormattedValue.ToString(); enroll.FullName = dgvSectionBefore.Rows[i].Cells[3].FormattedValue.ToString() + ", " + dgvSectionBefore.Rows[i].Cells[1].FormattedValue.ToString() + " " + dgvSectionBefore.Rows[i].Cells[2].FormattedValue.ToString(); enroll.GradeLevel = dgvSectionBefore.Rows[i].Cells[5].FormattedValue.ToString(); enroll.Strand = dgvSectionBefore.Rows[i].Cells[4].FormattedValue.ToString(); enroll.Section = cmbToAssign.Text; enroll.Semester = lblSemester.Text; enroll.SyEnroll = dgvSectionBefore.Rows[i].Cells[9].FormattedValue.ToString(); if (dgvSectionBefore.Rows[i].Cells[5].FormattedValue.ToString() == "11") { enroll.Save();//grade 11 } else { enroll.SaveGrade12();//grade 12 } } MessageBox.Show("Section Saved!", "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Information); a = 0; WithSectionStudents(); CountStudPerSection(); strand = cmbStrand.Text; CheckSectionInfo(); CheckRoomInfo(); } else { string input = Microsoft.VisualBasic.Interaction.InputBox("How many student do you want to assign to section " + cmbToAssign.Text + "?", "GOC_INFOSYS", "", -1, -1); int listSize; bool success = int.TryParse(input, out listSize); if (listSize > dgvSectionBefore.Rows.Count)//check if the current no is not greaterthan the input { MessageBox.Show("Sorry you cannot assign morethan " + dgvSectionBefore.Rows.Count + " students."); } else { for (int i = 0; i < listSize; i++) { studProfile.StudGOCNo = dgvSectionBefore.Rows[i].Cells[0].FormattedValue.ToString(); studProfile.Section = cmbToAssign.Text; studProfile.UpdateTheSectionWithGOCNO(); EnrolledStudents enroll = new EnrolledStudents(); enroll.RegNo = dgvSectionBefore.Rows[i].Cells[7].FormattedValue.ToString(); enroll.TheGOCNo = dgvSectionBefore.Rows[i].Cells[0].FormattedValue.ToString(); enroll.FullName = dgvSectionBefore.Rows[i].Cells[3].FormattedValue.ToString() + ", " + dgvSectionBefore.Rows[i].Cells[1].FormattedValue.ToString() + " " + dgvSectionBefore.Rows[i].Cells[2].FormattedValue.ToString(); enroll.GradeLevel = dgvSectionBefore.Rows[i].Cells[5].FormattedValue.ToString(); enroll.Strand = dgvSectionBefore.Rows[i].Cells[4].FormattedValue.ToString(); enroll.Section = cmbToAssign.Text; enroll.Semester = lblSemester.Text; enroll.SyEnroll = dgvSectionBefore.Rows[i].Cells[9].FormattedValue.ToString(); if (dgvSectionBefore.Rows[i].Cells[5].FormattedValue.ToString() == "11") { enroll.Save();//grade 11 MessageBox.Show("Section Saved!", "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { enroll.SaveGrade12();//grade 12 MessageBox.Show("Section Saved!", "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Information); } } a = 0; WithSectionStudents(); CountStudPerSection(); strand = cmbStrand.Text; CheckSectionInfo(); CheckRoomInfo(); } return; } }