private void metroButtonGet_Click(object sender, EventArgs e) { // Check if records exists, if yes load them for edit and if not create a record for each student and load for edit AttendanceREcordsTBLTableAdapter ada = new AttendanceREcordsTBLTableAdapter(); DataTable dt = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); if (dt.Rows.Count > 0) { //we have records, so we can edit DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); dataGridView1.DataSource = dt_new; } else { //create a record for each student //Get the class students list StudentsTBLTableAdapter students_adapter = new StudentsTBLTableAdapter(); DataTable dt_Students = students_adapter.GetDataByCLassID((int)metroComboBox1.SelectedValue); foreach (DataRow row in dt_Students.Rows) { //INsert a new record for this student ada.InsertQuery((int)row[0], (int)metroComboBox1.SelectedValue, dateTimePicker1.Text, "", row[1].ToString(), metroComboBox1.Text); } DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); dataGridView1.DataSource = dt_new; } }
private void metroButton2_Click(object sender, EventArgs e) { AttendanceREcordsTBLTableAdapter ada = new AttendanceREcordsTBLTableAdapter(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value != null) { ada.UpdateQuery("", row.Cells[0].Value.ToString(), (int)metroComboBox1.SelectedValue, dateTimePicker1.Text); } } DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); dataGridView1.DataSource = dt_new; }