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

            this.Hide();
            obj.Show();
        }
Beispiel #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);

            //Open the connection to db
            conn.Open();
            if (e.ColumnIndex == 0)   //assessment id
            {
                if (e.RowIndex != -1) //delete
                {
                    DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                    assessment_id = Convert.ToInt32(rows.Cells[3].Value);//column3 is containing id


                    string     q1    = "Select count(Id) from AssessmentComponent where AssessmentId='" + assessment_id + "' GROUP BY AssessmentId having count(Id)>=1";
                    SqlCommand cmd1  = new SqlCommand(q1, conn);//no of same id
                    int        jj    = Convert.ToInt32(cmd1.ExecuteScalar());
                    string     q2    = "Select * from AssessmentComponent where AssessmentId='" + assessment_id + "' ";
                    SqlCommand cmd11 = new SqlCommand(q2, conn);//id of first comp having sme assessment_id
                    int        ii    = Convert.ToInt32(cmd11.ExecuteScalar());
                    int        k;
                    for (int j = 0; j < jj; j++)
                    {
                        k = j + ii;
                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            string        delete_result = "DELETE  StudentResult WHERE EXISTS( SELECT * FROM AssessmentComponent WHERE AssessmentComponent.Id=StudentResult.AssessmentComponentId and AssessmentComponent.Id ='" + k + "')";
                            SqlCommand    cmd           = new SqlCommand(delete_result, conn);
                            SqlDataReader reader1       = cmd.ExecuteReader();
                        }
                    }

                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        string        delete_component = "DELETE AssessmentComponent WHERE EXISTS ( SELECT * FROM Assessment WHERE Assessment.Id= AssessmentComponent.AssessmentId and Assessment.Id ='" + assessment_id + "')";
                        SqlCommand    cmd3             = new SqlCommand(delete_component, conn);
                        SqlDataReader reader2          = cmd3.ExecuteReader();
                    }

                    string        delete = "DELETE from Assessment WHERE Id ='" + assessment_id + "'";
                    SqlCommand    cmd2   = new SqlCommand(delete, conn);
                    SqlDataReader reader = cmd2.ExecuteReader();
                    MessageBox.Show("Successfully deleted");
                    show();
                }
            }//end of delete

            if (e.ColumnIndex == 1)//edit
            {
                if (e.RowIndex != -1)
                {
                    DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                    assessment_id = Convert.ToInt32(rows.Cells[3].Value);

                    textBox1.Text = rows.Cells[4].Value.ToString();
                    textBox2.Text = rows.Cells[5].Value.ToString();
                    textBox3.Text = rows.Cells[6].Value.ToString();
                }
            }//end of edit
            if (e.ColumnIndex == 2)//manage component
            {
                DataGridViewRow rows = dataGridView1.Rows[e.RowIndex];
                assessment_id = Convert.ToInt32(rows.Cells[3].Value);
                Assess_component obj = new Assess_component();
                this.Hide();
                obj.Show();
            }
            else
            {
            }
        }