Beispiel #1
0
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Add_display_rubrics obj = new Add_display_rubrics();

            this.Hide();
            obj.Show();
        }
Beispiel #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)//rubrics
            {
                if (e.RowIndex != -1)
                {
                    DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                    publicCloId = rows.Cells[3].Value.ToString();//column3 is containing id
                    if (publicCloId == "")
                    {
                        MessageBox.Show("First enter Clo");
                    }
                    else
                    {
                        Add_display_rubrics form_rub = new Add_display_rubrics();
                        this.Hide();
                        form_rub.Show();
                    }
                }
            }//end of rubric

            else if (e.ColumnIndex == 1)//edit
            {
                if (e.RowIndex != -1)
                {
                    DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                    globalid      = rows.Cells[3].Value.ToString();
                    textBox1.Text = rows.Cells[4].Value.ToString();
                }
            }//end of edit

            else if (e.ColumnIndex == 2)// delete
            {
                if (e.RowIndex != -1)
                {
                    DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                    globalid = rows.Cells[3].Value.ToString();

                    try
                    {
                        SqlConnection conn = new SqlConnection(constr);
                        //Open the connection to db
                        conn.Open();
                        string     q1    = "Select count(Id) from Rubric where CloId='" + globalid + "' GROUP BY CloId having count(Id)>1";
                        SqlCommand cmd1  = new SqlCommand(q1, conn);//no of same id
                        int        jj    = Convert.ToInt32(cmd1.ExecuteScalar());
                        string     q2    = "Select * from Rubric where CloId='" + globalid + "'";
                        SqlCommand cmd11 = new SqlCommand(q2, conn);//id of first rubric having sme cloId
                        int        ii    = Convert.ToInt32(cmd11.ExecuteScalar());
                        int        k;
                        for (int j = 0; j < jj; j++)
                        {
                            k = j + ii;
                            for (int i = 0; i < dataGridView1.RowCount; i++)
                            {
                                string        delete_rubric_level = "DELETE RubricLevel WHERE EXISTS ( SELECT * FROM Rubric WHERE Rubric.Id= RubricLevel.RubricId and Rubric.Id ='" + k + "')";
                                SqlCommand    cmd2    = new SqlCommand(delete_rubric_level, conn);
                                SqlDataReader reader1 = cmd2.ExecuteReader();
                            }
                        }
                        for (int i = 0; i < dataGridView1.RowCount; i++)
                        {
                            string        delete_rubric = "DELETE Rubric WHERE EXISTS ( SELECT * FROM Clo WHERE Rubric.CloId= Clo.Id and Clo.Id ='" + globalid + "')";
                            SqlCommand    cmd3          = new SqlCommand(delete_rubric, conn);
                            SqlDataReader reader2       = cmd3.ExecuteReader();
                        }

                        string        delete_clo = "DELETE from Clo WHERE Clo.Id ='" + globalid + "'";
                        SqlCommand    cmd4       = new SqlCommand(delete_clo, conn);
                        SqlDataReader reader3    = cmd4.ExecuteReader();

                        MessageBox.Show("Deleted");


                        show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            else
            {
                MessageBox.Show("Click rightly box");
            }
        }