Example #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source = HAIER-PC; Initial Catalog = ProjectA; Integrated Security = True; MultipleActiveResultSets = True");



            if (e.ColumnIndex == 2)
            {
                ViewGroupStudents sdr = new ViewGroupStudents();
                sdr.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                sdr.Show();
            }
            if (e.ColumnIndex == 3)
            {
                GroupEvaluation grp = new GroupEvaluation();
                grp.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                grp.Show();
            }
            if (e.ColumnIndex == 4)
            {
                GroupProjects prg = new GroupProjects();
                prg.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                prg.Show();
            }
            //for deleting stuff
            if (e.ColumnIndex == 5)
            {
                var confirmResult = MessageBox.Show("Are you sure to delete this item ??",
                                                    "Confirm Delete!!",
                                                    MessageBoxButtons.YesNo);

                if (confirmResult == DialogResult.Yes)
                {
                    con.Open();

                    String cmd45 = string.Format("Delete FROM GroupEvaluation WHERE GroupId = {0};Delete FROM GroupStudent WHERE GroupId = {0};Delete FROM GroupProject WHERE GroupId = {0};Delete FROM [Group] WHERE Id = {0}",
                                                 Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()));
                    SqlCommand query45 = new SqlCommand(cmd45, con);
                    query45.ExecuteNonQuery();

                    con.Close();


                    MessageBox.Show("Deleted");

                    object    sende = null;
                    EventArgs er    = null;
                    dataGridView1.Rows.Clear();
                    this.Group_Load(sende, er);
                }
            }
        }
Example #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                ViewGroupStudents sdr = new ViewGroupStudents();
                sdr.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                sdr.Show();
            }
            if (e.ColumnIndex == 3)
            {
                GroupEvaluation grp = new GroupEvaluation();
                grp.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                grp.Show();
            }
            if (e.ColumnIndex == 4)
            {
                GroupProjects prg = new GroupProjects();
                prg.Id = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                prg.Show();
            }
            if (e.ColumnIndex == 5)
            {
                var confirmResult = MessageBox.Show("Are you sure to delete this item ??",
                                                    "Confirm Delete!!",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    //SqlConnection conn = new SqlConnection("Data Source=TALHAALI;Initial Catalog=ProjectA;User ID=sa;Password=talhaali");
                    conn.Open();

                    String     cm4   = string.Format("Delete from GroupEvaluation where GroupId={0};Delete from GroupStudent where GroupId={0};Delete from GroupProject where GroupId={0};Delete from [Group] where Id={0}", Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()));
                    SqlCommand comm4 = new SqlCommand(cm4, conn);
                    comm4.ExecuteNonQuery();
                    //SqlDataReader reader2 = comm4.ExecuteReader();
                    //int studentid = 0;
                    //while (reader2.Read())
                    //{
                    //    studentid = Convert.ToInt32(reader2["Id"]);
                    //}
                    conn.Close();


                    MessageBox.Show("Deleted");

                    object    sende = null;
                    EventArgs er    = null;
                    dataGridView1.Rows.Clear();
                    this.Groups_Load(sende, er);
                }
            }
        }