private void ShowData_Click(object sender, EventArgs e) { this.Hide(); Advisor f4 = new Advisor(); f4.ShowDialog(); this.Close(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { con1.Open(); int UP_Row = int.Parse(e.RowIndex.ToString()); int UP_RowIndex = int.Parse(e.ColumnIndex.ToString()); ID1 = Convert.ToInt32(dataGridView1.Rows[UP_Row].Cells[0].Value.ToString()); int dd = (int)dataGridView1.CurrentRow.Cells[0].Value; if (UP_RowIndex == 10) { if (UP_RowIndex == 1) { if (UP_RowIndex == 0) { MessageBox.Show("lala"); } } if (UP_RowIndex != 0) { var askfirst1 = MessageBox.Show("Are you sure you want to Update this?", "Update", MessageBoxButtons.YesNo); if (askfirst1 == DialogResult.Yes) { Add_Advisor s = new Add_Advisor(dd); ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()); s.textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); s.textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); s.textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); s.textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); s.dateTimePicker1.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); s.textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); if (dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString() == "") { s.comboBox1.Text = ""; } else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value) == 1) { s.comboBox1.Text = "Male"; } else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value) == 2) { s.comboBox1.Text = "Female"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 6) { s.comboBox2.Text = "Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 7) { s.comboBox2.Text = "Associate Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 8) { s.comboBox2.Text = "Assisstant Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 9) { s.comboBox2.Text = "Lecturer"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 10) { s.comboBox2.Text = "Industry Professional"; } s.ShowDialog(); con1.Close(); } else { con1.Close(); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); DisplayAdvisor(); } } } else if (UP_RowIndex == 9) { int URow = int.Parse(e.RowIndex.ToString()); int URowIndex = int.Parse(e.ColumnIndex.ToString()); ID = Convert.ToInt32(dataGridView1.Rows[URow].Cells[0].Value.ToString()); if (URowIndex == 0) { MessageBox.Show("Click on Delete Again"); } if (URowIndex != 0) { var askfirst = MessageBox.Show("Are you sure you want to delete this?", "Delete", MessageBoxButtons.YesNo); if (askfirst == DialogResult.Yes) { cmd1 = new SqlCommand("DELETE FROM Person where ID = @Id", con1); cmd2 = new SqlCommand("DELETE FROM Advisor where ID = @Id", con1); cmd2.Parameters.AddWithValue("@Id", ID); cmd1.Parameters.AddWithValue("@Id", ID); cmd2.ExecuteNonQuery(); cmd1.ExecuteNonQuery(); con1.Close(); MessageBox.Show("Deleted Succesfully"); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); this.Close(); } else { con1.Close(); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); DisplayAdvisor(); } } } else { con1.Close(); } }