private void btnBuscar_Click(object sender, EventArgs e) { try { string tipo = cboTipo.SelectedItem.ToString(); string valor = txtValor.Text; ServicioPaciente servicio = new ServicioPaciente(); listaDePacientes = servicio.BuscarPacientes(tipo,valor); dataPacientes.Rows.Clear(); foreach (Paciente paciente in listaDePacientes) { Object[] fila = { paciente.Nombre, paciente.ApellidoPaterno, paciente.ApellidoMaterno, paciente.Dni}; dataPacientes.Rows.Add(fila); } } catch (Exception err) { MessageBox.Show(this, "Ocurrio un problema al LISTAR los pacientes disponibles. \n\nIntente de nuevo o verifique con el Administrador.", "PRODENT: Error", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Console.WriteLine("ERROR -> presentacion -> FRM-CRUDPACIENTE -> CARGAR LISTADO DE PACIENTES " + err); } }
/* private int obtenerIdPacienteSeleccionado() { //int fila = int.Parse(dataPacientes.CurrentRow.Index.ToString()); //txtNombre.Text = dataPacientes.CurrentRow.Index.ToString(); objPacienteSeleccionado = listaDePacientes[int.Parse(dataPacientes.CurrentRow.Index.ToString())]; return objPacienteSeleccionado.Id; } */ private void btnActualizar_Click(object sender, EventArgs e) { int registros_afectados; Paciente objPaciente = new Paciente(); objPaciente.Id = objPacienteSeleccionado.Id; llenarObjetoPaciente(objPaciente); if (objPaciente.Nombre.Length == 0 || objPaciente.Dni.Length == 0) { MessageBox.Show(this, "Debe ingresar al menos el nombre y el dni", "PRODENT: Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error); txtNombre.Focus(); return; } try { ServicioPaciente crud = new ServicioPaciente(); registros_afectados = crud.modificarPaciente(objPaciente); if (registros_afectados == 1){ MessageBox.Show("El paciente fue actualizado.", "PRODENT: ConfirmaciĆ³n", MessageBoxButtons.OK, MessageBoxIcon.Information); CargarListadoDePacientes(); limpiarCajas(); activarCajas(false); activaBotones(true,false,false); } else MessageBox.Show("El paciente no pudo ser actualizado, verifique.", "PRODENT: Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception err) { System.Console.WriteLine("ERROR -> CAPA PRESENTACION -> FRM-CRUDPACIENTE -> BTN ACTUALIZAR " + err); MessageBox.Show(this, "Ocurrio un problema al actualizado el paciente. \n\nIntente de nuevo o verifique con el Administrador.", "PRODENT: Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CargarListadoDePacientes() { try { ServicioPaciente crud = new ServicioPaciente(); listaDePacientes = crud.listarPacientes(); dataPacientes.Rows.Clear(); foreach (Paciente paciente in listaDePacientes) { Object[] fila = { paciente.Nombre, paciente.ApellidoPaterno, paciente.ApellidoMaterno, paciente.Dni}; dataPacientes.Rows.Add(fila); } } catch (Exception err) { MessageBox.Show(this, "Ocurrio un problema al LISTAR los pacientes disponibles. \n\nIntente de nuevo o verifique con el Administrador.", "PRODENT: Error", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Console.WriteLine("ERROR -> presentacion -> FRM-CRUDPACIENTE -> CARGAR LISTADO DE PACIENTES " + err); //Console.WriteLine(err.ToString()); } }
private void btnEliminar_Click(object sender, EventArgs e) { int registros_afectados; DialogResult resultado; resultado = MessageBox.Show("Estas seguro que deseas eliminar el registro de: " + objPacienteSeleccionado.Nombre, "PRODENT: Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if(resultado == DialogResult.Yes){ try { ServicioPaciente crud = new ServicioPaciente(); registros_afectados = crud.eliminarPaciente(objPacienteSeleccionado); if (registros_afectados == 1) { MessageBox.Show("El paciente fue eliminado", "PRODENT: ConfirmaciĆ³n", MessageBoxButtons.OK, MessageBoxIcon.Information); CargarListadoDePacientes(); limpiarCajas(); activarCajas(false); activaBotones(true, false, false); } else MessageBox.Show("El paciente no pudo ser eliminado, verifique.", "PRODENT: Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception err) { System.Console.WriteLine("ERROR -> CAPA PRESENTACION -> FRM-CRUDPACIENTE -> BTN ELIMINAR " + err); MessageBox.Show(this, "Ocurrio un problema al actualizado el paciente. \n\nIntente de nuevo o verifique con el Administrador.", "PRODENT: Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { limpiarCajas(); activarCajas(false); activaBotones(true,false,false); } }