private void Create_Click(object sender, EventArgs e) { this.Hide(); CreateAdvisor st = new CreateAdvisor(); st.ShowDialog(); this.Close(); }
private void AdvisorData_CellContentClick(object sender, DataGridViewCellEventArgs e) { AdvisorData.Rows[e.RowIndex].ReadOnly = true; int noOfRows = AdvisorData.RowCount; if (e.ColumnIndex == 9 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on del button { DialogResult dialogResult = MessageBox.Show("Are you sure that you want to delete it?", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlConnection con = new SqlConnection(conURL); // connection opens con.Open(); try { string cmdText = "DELETE FROM Advisor WHERE Id = @Id"; SqlCommand c = new SqlCommand(cmdText, con); int Idy = Convert.ToInt32(AdvisorData.Rows[e.RowIndex].Cells[0].Value); c.Parameters.Add(new SqlParameter("@Id", Idy)); //execute it int result = c.ExecuteNonQuery(); if (result < 0) { MessageBox.Show("Error"); } string cmdText2 = "DELETE FROM Person WHERE Id = @Id"; SqlCommand c2 = new SqlCommand(cmdText2, con); c2.Parameters.Add(new SqlParameter("@Id", Idy)); c2.ExecuteNonQuery(); // connection closed con.Close(); AdvisorData.DataSource = null; AdvisorData.Rows.Clear(); AdvisorData.Columns.Clear(); update(); // show dialog box if del MessageBox.Show("Successfully Deleted"); } catch (Exception) { MessageBox.Show("This advisor might be assign to the project. So first delete that record, then delete it here."); } } else if (dialogResult == DialogResult.No) { //do something else } } if (e.ColumnIndex == 10 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on update button { adId = Convert.ToInt32(AdvisorData.Rows[e.RowIndex].Cells[0].Value); this.Hide(); CreateAdvisor create = new CreateAdvisor(); create.ShowDialog(); this.Close(); } else { } }