/// <summary> /// function creates a new object of viewassessmentcomponent form and close the current form /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void button2_Click(object sender, EventArgs e) { ViewAssessmentComponent a = new ViewAssessmentComponent(); this.Hide(); a.Show(); }
/// <summary> /// function Edit the Component or Delete the Component /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { ///checks if e.ColumnIndex is equal to edit index if (e.ColumnIndex == dataGridView1.Columns["Edit"].Index) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); string fname = (dataGridView1.Rows[e.RowIndex].Cells["Name"].Value).ToString(); int marks = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["TotalMarks"].Value); EditAssessmentComponent frm = new EditAssessmentComponent(ID, fname, marks); this.Hide(); frm.Show(); } } ///checks id e.column index is equal to delete index if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); string query = "DELETE FROM dbo.AssessmentComponent WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); int x = cmd.ExecuteNonQuery(); ViewAssessmentComponent frm = new ViewAssessmentComponent(); this.Hide(); frm.Show(); } } }
/// <summary> /// function updates the assessment component /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void button6_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { string query = "UPDATE dbo.AssessmentComponent SET Name = '" + textBox1.Text + "', RubricId = '" + comboBox2.SelectedValue + "', TotalMarks = '" + textBox4.Text + "', DateUpdated = '" + DateTime.Now + "', AssessmentId = '" + comboBox1.SelectedValue + "' WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); MessageBox.Show("Updated"); ViewAssessmentComponent vs = new ViewAssessmentComponent(); this.Hide(); vs.Show(); } }