private void addbutton_Click(object sender, EventArgs e) { AddAdvisor advisor = new AddAdvisor(); advisor.Show(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { AddAdvisor change = new AddAdvisor(); if (e.ColumnIndex == 8) { DateTime?date; int? pay; if (String.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[5].Value as String)) // checking if it is null { date = null; } else //if not then continue as you would { date = Convert.ToDateTime(dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString()); } //will check the same for these string gender = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); string desig = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); if (String.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[7].Value as String)) { MessageBox.Show("no salary"); pay = null; } else //if salary is not empty { pay = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value); } //calling setpara change.setpara("Update", (int)e.RowIndex, dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(), date, gender, desig, pay); change.Show(); } if (e.ColumnIndex == 9) { var Result = MessageBox.Show("delete this item ??", "Confirm Delete!!", MessageBoxButtons.YesNo); if (Result == DialogResult.Yes) { SqlConnection con = new SqlConnection("Data Source = HAIER-PC; Initial Catalog = ProjectA; Integrated Security = True; MultipleActiveResultSets = True"); con.Open(); String cmD1 = string.Format("Delete FROM ProjectAdvisor WHERE AdvisorId = ANY(Select Id FROM Person WHERE Email='{0}');Delete From Advisor WHERE Id = ANY(Select Id FROM Person WHERE Email = '{0}');Delete From Person WHERE Id = ANY(Select Id FROM Person WHERE Email = '{0}')", dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); SqlCommand comm1 = new SqlCommand(cmD1, con); comm1.ExecuteNonQuery(); //String query = string.Format("Delete From Person where Id=ANY(Select Id from Person where Email='{0}')", dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); //SqlCommand comm = new SqlCommand(query, con); //var row = comm.ExecuteNonQuery(); con.Close(); MessageBox.Show("Deleted"); object sende = null; EventArgs er = null; dataGridView1.Rows.Clear(); this.Advisors_Load(sende, er); } else { MessageBox.Show("Not Deleted"); } } }
private void Advisorsview_CellContentClick(object sender, DataGridViewCellEventArgs e) { AddAdvisor adv = new AddAdvisor(); if (e.ColumnIndex == 8) { DateTime?date; int? pay; if (String.IsNullOrEmpty(Advisorsview.Rows[e.RowIndex].Cells[5].Value as String)) { //MessageBox.Show("Empty"); date = null; } else { date = Convert.ToDateTime(Advisorsview.Rows[e.RowIndex].Cells[5].Value.ToString()); } string gender = Advisorsview.Rows[e.RowIndex].Cells[4].Value.ToString(); string desig = Advisorsview.Rows[e.RowIndex].Cells[6].Value.ToString(); if (String.IsNullOrEmpty(Advisorsview.Rows[e.RowIndex].Cells[7].Value as String)) { MessageBox.Show("salary empty"); pay = null; } else { pay = Convert.ToInt32(Advisorsview.Rows[e.RowIndex].Cells[7].Value); } adv.Change("Update", (int)e.RowIndex, Advisorsview.Rows[e.RowIndex].Cells[0].Value.ToString() , Advisorsview.Rows[e.RowIndex].Cells[1].Value.ToString(), Advisorsview.Rows[e.RowIndex].Cells[2].Value.ToString(), Advisorsview.Rows[e.RowIndex].Cells[3].Value.ToString(), date, gender, desig, pay); adv.Show(); } if (e.ColumnIndex == 9) { var confirmResult = MessageBox.Show("Are you sure to delete this item ??", "Confirm Delete!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { //SqlConnection conn = new SqlConnection("Data Source=TALHAALI;Initial Catalog=ProjectA;User ID=sa;Password=talhaali"); conn.Open(); //String cm4 = string.Format("Select Id from Person where Email='{0}'", Advisorsview.Rows[e.RowIndex].Cells[3].Value.ToString()); //SqlCommand comm4 = new SqlCommand(cm4, conn); //SqlDataReader reader2 = comm4.ExecuteReader(); //int studentid = 0; //while (reader2.Read()) //{ // studentid = Convert.ToInt32(reader2["Id"]); //} //conn.Close(); //conn.Open(); String cm1 = string.Format("Delete From ProjectAdvisor where AdvisorId=ANY(Select Id from Person where Email='{0}');Delete From Advisor where Id=ANY(Select Id from Person where Email='{0}');Delete From Person where Id=ANY(Select Id from Person where Email='{0}')", Advisorsview.Rows[e.RowIndex].Cells[3].Value.ToString()); SqlCommand comm1 = new SqlCommand(cm1, conn); comm1.ExecuteNonQuery(); //String cm = string.Format("Delete From Person where Id=ANY(Select Id from Person where Email='{0}')", Advisorsview.Rows[e.RowIndex].Cells[3].Value.ToString()); //SqlCommand comm = new SqlCommand(cm, conn); //var row = comm.ExecuteNonQuery(); conn.Close(); MessageBox.Show("Deleted"); object sende = null; EventArgs er = null; Advisorsview.Rows.Clear(); this.Advisor_Load(sende, er); } else { MessageBox.Show("Not Deleted"); } } }