Example #1
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            if (txt_name.Text != "" && txt_marks.Text != "" && cmb_clo.Text != "" && cmb_rubric.Text != "")
            {
                SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");
                if (update == 1)
                {
                    if (cmb_assessID.Text != "")
                    {
                        conn.Open();
                        string     RubricID       = (cmb_rubric.SelectedItem as ComboboxItem).Value.ToString();
                        string     Assess_id      = (cmb_assessID.SelectedItem as ComboboxItem).Value.ToString();
                        string     query2         = "Update AssessmentComponent set Name = '" + txt_name.Text + " ', RubricId = '" + RubricID + " ', TotalMarks = '" + txt_marks.Text + " ' , DateCreated = '" + this.date + " ' , DateUpdated = '" + DateTime.Today + " ', AssessmentId = '" + Assess_id + " '   where Id = '" + this.id + "'";
                        SqlCommand update_command = new SqlCommand(query2, conn);
                        int        j = update_command.ExecuteNonQuery();
                        if (j != 0)
                        {
                            MessageBox.Show("Component Record Updated Successfully");
                            assessment_comp ff = new assessment_comp();
                            ff.Close();
                            assess_comp_detail ss = new assess_comp_detail(assess_id);
                            ss.Show();
                            this.Hide();
                        }
                        conn.Close();
                    }
                    else
                    {
                        error_msg.Show();
                    }
                }
                else
                {
                    cmb_assessID.Hide();
                    conn.Open();
                    string RubricId = (cmb_rubric.SelectedItem as ComboboxItem).Value.ToString();

                    string     query   = "Insert into AssessmentComponent (Name,RubricId,TotalMarks,DateCreated,DateUpdated,AssessmentId) values('" + txt_name.Text + "','" + RubricId + "','" + txt_marks.Text + "', '" + DateTime.Today + "','" + DateTime.Today + "', '" + this.assess_id + "')";
                    SqlCommand command = new SqlCommand(query, conn);
                    int        i       = command.ExecuteNonQuery();
                    if (i != 0)
                    {
                        MessageBox.Show("Assessment Component Record Inserted Successfully");
                        assessment_comp f = new assessment_comp();
                        f.Close();
                        assess_comp_detail s = new assess_comp_detail(assess_id);
                        this.Hide();
                        s.Show();
                    }
                    conn.Close();
                }
            }
            else
            {
                error_msg.Show();
            }
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");

            conn.Open();
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0 && e.ColumnIndex == 0)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                string[]        values;
                values = new string[7];
                using (SqlConnection con = new SqlConnection("Data Source = DESKTOP - M9PBVHQ; Initial Catalog = ProjectB; Integrated Security = True"))
                {
                    string     oString = "Select * from Assessment where Id='" + a + "'";
                    SqlCommand oCmd    = new SqlCommand(oString, conn);
                    using (SqlDataReader oReader = oCmd.ExecuteReader())
                    {
                        while (oReader.Read())
                        {
                            values[0] = oReader["Id"].ToString();
                            values[1] = oReader["Title"].ToString();
                            values[2] = oReader["DateCreated"].ToString();
                            values[3] = oReader["TotalMarks"].ToString();
                            values[4] = oReader["TotalWeightage"].ToString();
                            break;
                        }

                        conn.Close();
                    }
                }
                assessment s = new assessment(values[0], values[1], values[2], values[3], values[4]);
                this.Hide();
                s.Show();
            }
            else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                     e.RowIndex >= 0 && e.ColumnIndex == 1)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                string          q2          = "DELETE FROM AssessmentComponent where AssessmentId = '" + a + "'";
                string          query       = "DELETE FROM Assessment WHERE Id = '" + a + "'";
                SqlCommand      command     = new SqlCommand(query, conn);
                SqlCommand      s           = new SqlCommand(q2, conn);
                s.ExecuteNonQuery();
                MessageBox.Show("Assessment deleted of this CLO");
                command.ExecuteNonQuery();
                MessageBox.Show("Row Deleted");
                conn.Close();

                SqlConnection cnn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");
                conn.Open();
                string query1 = "select * from Assessment";
                using (SqlDataAdapter am = new SqlDataAdapter(query1, cnn))
                {
                    DataTable t = new DataTable();
                    am.Fill(t);
                    dataGridView1.DataSource = t;
                }
            }
            else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                     e.RowIndex >= 0 && e.ColumnIndex == 2)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                assessment_comp r           = new assessment_comp(a);
                this.Hide();
                assess_comp_detail rr = new assess_comp_detail(a);
                rr.Show();
                assessment_details c = new assessment_details();
                c.Hide();
            }
        }