private void InsertEvaluation_Click_1(object sender, EventArgs e) { AddEvaluation form = new AddEvaluation("", 0, 0, "add"); this.Hide(); form.Show(); }
private void Evaluations_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == Evaluations.NewRowIndex || e.RowIndex < 0) { return; } if (e.ColumnIndex == Evaluations.Columns["EvaluationDeleteButton"].Index) { int i = e.RowIndex; string Name = Evaluations.Rows[i].Cells[0].Value.ToString(); string marks1 = Evaluations.Rows[i].Cells[1].Value.ToString(); int marks = int.Parse(marks1); string weightage1 = Evaluations.Rows[i].Cells[2].Value.ToString(); int weightage = int.Parse(weightage1); string dialog = string.Format("Delete Evaluation '{0}' and all its information?", Name); DialogResult dialogResult = MessageBox.Show(dialog, "Delete Evaluation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlConnection connection = new SqlConnection(connString); connection.Open(); string getid = string.Format("SELECT Id FROM Evaluation WHERE Name = '{0}'AND TotalMarks = '{1}' AND TotalWeightage = '{2}'", Name, marks, weightage); SqlCommand cmd = new SqlCommand(getid, connection); int id = (Int32)cmd.ExecuteScalar(); cmd.CommandText = string.Format("DELETE FROM GroupEvaluation WHERE EvaluationId = '{0}'", id); cmd.ExecuteNonQuery(); string display = String.Format("DELETE FROM Evaluation WHERE Name = '{0}'AND TotalMarks = '{1}' AND TotalWeightage = '{2}'", Name, marks, weightage); cmd.CommandText = display; cmd.ExecuteNonQuery(); Evaluations.Rows.RemoveAt(i); MessageBox.Show("Evaluation deleted successfully!"); connection.Close(); } else if (dialogResult == DialogResult.No) { MessageBox.Show("Evaluation not deleted!"); } } if (e.ColumnIndex == Evaluations.Columns["EvaluationEditButton"].Index) { int i = e.RowIndex; string Name = Evaluations.Rows[i].Cells[0].Value.ToString(); string marks1 = Evaluations.Rows[i].Cells[1].Value.ToString(); int marks = int.Parse(marks1); string weightage1 = Evaluations.Rows[i].Cells[2].Value.ToString(); int weightage = int.Parse(weightage1); AddEvaluation form = new AddEvaluation(Name, marks, weightage, "edit"); form.Show(); this.Hide(); } }