Exemplo n.º 1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].HeaderText == "Delete")
            {
                if (MessageBox.Show("Do you want to delete this " + type + " ?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    int dni      = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
                    int personId = servPerson.GetPersonByDni(dni).ID;
                    if (type == "Nurse")
                    {
                        nurse objNurse = new nurse();
                        objNurse = nurseService.GetNurseByPersonId(personId);
                        nurseService.DeleteNurse(objNurse.id);
                    }
                    else if (type == "Doctor")
                    {
                        doctor objDoctor = new doctor();
                        objDoctor = doctorService.GetDoctorByPersonId(personId);
                        doctorService.DeleteDoctor(objDoctor.id);
                    }
                    else if (type == "Patient")
                    {
                        patient objPatient = new patient();
                        objPatient = patientService.GetPatientByPersonId(personId);
                        patientService.DeletePatient(objPatient.id);
                    }

                    dataGridView1.DataBindings.Clear();
                    loadPersons();
                }
            }
        }