/// <summary> /// function creates a new object of viewAssessment 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) { ViewAssessment v = new ViewAssessment(); this.Hide(); v.Show(); }
/// <summary> /// function update the Assessment /// </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.Assessment SET Title = '" + textBox1.Text + "', TotalMarks = '" + textBox2.Text + "',TotalWeightage = '" + textBox3.Text + "' WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); MessageBox.Show("Updated"); ViewAssessment vs = new ViewAssessment(); this.Hide(); vs.Show(); } }
/// <summary> /// function Edit and Delete the Assessment /// </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) { //Edit form will be Open if user clicks the edit column 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 title = (dataGridView1.Rows[e.RowIndex].Cells["Title"].Value).ToString(); int marks = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["TotalMarks"].Value); int w = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["TotalWeightage"].Value); EsitAssessment frm = new EsitAssessment(ID, title, marks, w); this.Hide(); frm.Show(); } } ///Delete the current Assessment and Assessment Component against the Assessment if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { if (MessageBox.Show("Deleting this item will cause other items to delete. Are You Sure you Want to Delete?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); string query1 = "DELETE FROM dbo.AssessmentComponent WHERE AssessmentId = '" + ID + "'"; SqlCommand cmd1 = new SqlCommand(query1, con); cmd1.ExecuteNonQuery(); string query = "DELETE FROM dbo.Assessment WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); ViewAssessment frm = new ViewAssessment(); this.Hide(); frm.Show(); } } } }