private void deleteC_Click(object sender, EventArgs e) { try { if (bunifuCustomDataGrid1.SelectedCells.Count > 0) { SqlDataAdapter adapt = new SqlDataAdapter("select class_id from classrooms where class_name= '" + className + "' AND facilitator_id='" + Program.user_id + "' ", con); DataTable dt = new DataTable(); adapt.Fill(dt); int ID = int.Parse(dt.Rows[0][0].ToString());//Getting the ID of The Classroom DialogResult result = Dialogue1.Show("Are You Sure?", "", "Ok", "Cancel"); if (result == DialogResult.Yes) { con.Open(); String qer = "DELETE FROM classlist WHERE class_id= '" + ID + "' "; String qe = "DELETE FROM grouplist WHERE group_id=(Select group_id from groups where class_id= '" + ID + "') "; String que = "DELETE FROM groups WHERE class_id= '" + ID + "' "; String query = "DELETE FROM classrooms WHERE class_name= '" + className + "' AND facilitator_id = '" + Program.user_id + "' "; SqlDataAdapter sad = new SqlDataAdapter(qer, con); SqlDataAdapter s = new SqlDataAdapter(qe, con); SqlDataAdapter d = new SqlDataAdapter(que, con); SqlDataAdapter sda = new SqlDataAdapter(query, con); int n = sad.SelectCommand.ExecuteNonQuery(); int o = s.SelectCommand.ExecuteNonQuery(); int p = d.SelectCommand.ExecuteNonQuery(); int m = sda.SelectCommand.ExecuteNonQuery(); con.Close(); if (n >= 0 && m > 0) { Load_Class(); Load_Participant(); bunifuCustomDataGrid1.ClearSelection(); bunifuCustomDataGrid2.ClearSelection(); Dialogue.Show("Successfully Deleted!", "", "Ok", "Cancel"); } else { Dialogue.Show("Fail to Delete!", "", "Ok", "Cancel"); Load_Class(); Load_Participant(); bunifuCustomDataGrid1.ClearSelection(); bunifuCustomDataGrid2.ClearSelection(); } }//end if result } else { Dialogue.Show("Nothing Selected", "", "Ok", "Cancel"); } }//try catch (Exception ex) { Dialogue.Show(" ' " + ex.Message.ToString() + "' ", "", "Ok", "Cancel"); } }
private void createP_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem == null || comboBox1.SelectedItem.ToString() == "") { Dialogue.Show("Invalid Input or Empty", "", "Ok", "Cancel"); } else { string selected = comboBox1.SelectedItem.ToString();//Getting the Value From COMBO BOX SqlDataAdapter adapt = new SqlDataAdapter("Select class_id from classrooms WHERE class_name = '" + className + "' AND facilitator_id='" + Program.user_id + "' ", con); DataTable dt = new DataTable(); adapt.Fill(dt); int ID = int.Parse(dt.Rows[0][0].ToString()); //Getting the ID of The Classroom SqlDataAdapter add = new SqlDataAdapter("Select participant_id from participant WHERE fullname = '" + selected + "' ", con); DataTable data = new DataTable(); add.Fill(data); int id = int.Parse(data.Rows[0][0].ToString());//Getting the ID of The Participant try { con.Open(); String query = "INSERT INTO classlist (participant_id,class_id,facilitator_id) VALUES ('" + id + "','" + ID + "','" + Program.user_id + "')"; SqlDataAdapter sda = new SqlDataAdapter(query, con); int n = sda.SelectCommand.ExecuteNonQuery(); con.Close(); if (n > 0) { Dialogue.Show("Participant Added!", "", "Ok", "Cancel"); comboBox1.Items.Clear(); try { SqlCommand cmd = new SqlCommand("Select DISTINCT fullname from participant p left join classlist cl on p.participant_id =cl.participant_id where cl.class_id != '" + ID + "' OR cl.class_id IS NULL", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { comboBox1.Items.Add(dr["fullname"]); } dr.Close(); con.Close(); } catch (Exception ex) { Dialogue.Show(" ' " + ex.Message.ToString() + "' ", "", "Ok", "Cancel"); } } else { Dialogue.Show("Fail to Add!", "", "Ok", "Cancel"); } Load_Participant(); bunifuCustomDataGrid2.ClearSelection(); } catch (Exception ex) { Dialogue.Show(" ' " + ex.Message.ToString() + "' ", "", "Ok", "Cancel"); } } }