private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewButtonCell)
     {
         if (dgv.Columns[e.ColumnIndex].DefaultCellStyle.NullValue.ToString() == "Modify")
         {
             if (dgv.Columns[e.ColumnIndex].DefaultCellStyle.NullValue.ToString() == "Modify")
             {
                 using (ChoosingInfoModify cim = new ChoosingInfoModify()
                 {
                     connection = connection,
                     year = dgv.Rows[e.RowIndex].Cells["chosen_year"].Value.ToString(),
                     score = dgv.Rows[e.RowIndex].Cells["score"].Value.ToString(),
                     student = string.Format("{0}({1})", dgv.Rows[e.RowIndex].Cells["student_id"].Value, dgv.Rows[e.RowIndex].Cells["name"].Value),
                     teacher = string.Format("{0}({1})", current_teacher_id, current_teacher_name),
                     course = string.Format("{0}({1})", dgv.Rows[e.RowIndex].Cells["course_id"].Value, dgv.Rows[e.RowIndex].Cells["name1"].Value),
                     credit = dgv.Rows[e.RowIndex].Cells["credit"].Value.ToString(),
                     role = Common.UserType.TEACHER
                 })
                 {
                     cim.ShowDialog();
                     ClearDGV();
                     RefreshYearData();
                     RefreshDGV();
                 }
             }
         }
     }
 }
 private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewButtonCell)
     {
         if (dgv.Columns[e.ColumnIndex].DefaultCellStyle.NullValue.ToString() == "Modify")
         {
             using (ChoosingInfoModify cim = new ChoosingInfoModify()
             {
                 connection = connection,
                 year = dgv.Rows[e.RowIndex].Cells["Chosen Year"].Value.ToString(),
                 score = dgv.Rows[e.RowIndex].Cells["Score"].Value.ToString(),
                 student = string.Format("{0}({1})", dgv.Rows[e.RowIndex].Cells["Student ID"].Value, dgv.Rows[e.RowIndex].Cells["Student Name"].Value),
                 teacher = string.Format("{0}({1})", dgv.Rows[e.RowIndex].Cells["Teacher ID"].Value, dgv.Rows[e.RowIndex].Cells["Teacher Name"].Value),
                 course = string.Format("{0}({1})", dgv.Rows[e.RowIndex].Cells["Course ID"].Value, dgv.Rows[e.RowIndex].Cells["Course Name"].Value),
                 credit = dgv.Rows[e.RowIndex].Cells["Credit"].Value.ToString(),
                 role = Common.UserType.ADMIN
             })
             {
                 cim.ShowDialog();
                 choosing_clear_button.PerformClick();
                 choosing_query_button.PerformClick();
             }
         }
         else if (dgv.Columns[e.ColumnIndex].DefaultCellStyle.NullValue.ToString() == "Delete")
         {
             if (Common.ShowChoice("Delete Confirm", string.Format("Are you sure to delete the record ({0},{1},{2},{3})", dgv.Rows[e.RowIndex].Cells["Student Name"].Value, dgv.Rows[e.RowIndex].Cells["Course Name"].Value, dgv.Rows[e.RowIndex].Cells["Teacher Name"].Value, dgv.Rows[e.RowIndex].Cells["Chosen Year"].Value) + "?", MessageBoxIcon.Warning) == DialogResult.Yes)
             {
                 int delete_result = SQL_Help.ExecuteNonQuery("delete from course_choosing_info where (course_id=@course_id and teacher_id=@teacher_id and student_id=@student_id and chosen_year=@year);", connection, new MySqlParameter[]
                 {
                     new MySqlParameter("@course_id", MySqlDbType.VarChar)
                     {
                         Value = dgv.Rows[e.RowIndex].Cells["Course ID"].Value
                     },
                     new MySqlParameter("@teacher_id", MySqlDbType.VarChar)
                     {
                         Value = dgv.Rows[e.RowIndex].Cells["Teacher ID"].Value
                     },
                     new MySqlParameter("@student_id", MySqlDbType.VarChar)
                     {
                         Value = dgv.Rows[e.RowIndex].Cells["Student ID"].Value
                     },
                     new MySqlParameter("@year", MySqlDbType.Int32)
                     {
                         Value = dgv.Rows[e.RowIndex].Cells["Chosen Year"].Value
                     },
                 });
                 if (delete_result > 0)
                 {
                     Common.ShowInfo("Done", "Delete successfully!");
                     choosing_clear_button.PerformClick();
                     choosing_query_button.PerformClick();
                 }
             }
         }
     }
 }