private void btnAceptar_Click(object sender, EventArgs e) { if (operacion == 1) // Buscar { this.btnBuscar.Enabled = false; this.btnAgregar.Enabled = false; this.btnModificar.Enabled = false; this.txbDni.Enabled = false; if (this.txbDni.Text.Trim().Count() != 0) { if (ValidarNumero(this.txbDni.Text.ToString(), "Documento")) {//busco por dni del paciente paciente = new Paciente(); PacienteNegocio pacientenegocio = new PacienteNegocio(); if (pacientenegocio.LeerDni(this.txbDni.Text.Trim(), ref paciente)) { CargarPantalla(paciente); CargarObraSocial(paciente); CargarPlan(paciente.dni); if (id == 2) { this.btnBuscar.Enabled = true; this.btnModificar.Enabled = true; this.btnAgregar.Enabled = true; this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; } } else { MessageBox.Show("No se encontró un Paciente con los datos ingresados"); this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; this.btnBuscar.Enabled = true; if (id == 2) { this.btnAgregar.Enabled = true; } this.txbDni.Text = " "; return; } } else { this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; this.btnBuscar.Enabled = true; if (id == 2) { this.btnAgregar.Enabled = true; } this.txbDni.Text = " "; return; } } else { if ((this.txbApellido.Text.Trim().Count() != 0) && (this.txbNombre.Text.Trim().Count() != 0)) { //busco por nombre y apellido del paciente paciente = new Paciente(); PacienteNegocio pacientenegocio = new PacienteNegocio(); if (pacientenegocio.LeerNomYAp(this.txbNombre.Text.ToUpper().Trim(), this.txbApellido.Text.ToUpper().Trim(), ref paciente)) { CargarPantalla(paciente); CargarObraSocial(paciente); CargarPlan(paciente.dni); } else { MessageBox.Show("No se encontró un Paciente con los datos ingresados"); return; } } else { MessageBox.Show("Debe ingresar Número de Documento del Paciente"); this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; this.btnBuscar.Enabled = true; if (id == 2) { this.btnAgregar.Enabled = true; } this.txbDni.Text = " "; return; } } } if (operacion == 2) //modificar { Deshabilitar_Campos(); if (ValidarCampos()) { this.LeerControles(); PacienteNegocio pacienteN = new PacienteNegocio(); if (pacienteN.Escribir(this.paciente) == false) { MessageBox.Show("Error al modificar"); CargarPantalla(paciente); CargarObraSocial(paciente); CargarPlan(txbDni.Text); } } else { CargarPantalla(paciente); CargarObraSocial(paciente); CargarPlan(txbDni.Text); } this.btnBuscar.Enabled = true; this.btnModificar.Enabled = true; this.btnAgregar.Enabled = true; this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; } if (operacion == 3) // agregar { paciente = new Paciente(); PacienteNegocio pacientenegocio = new PacienteNegocio(); if (pacientenegocio.LeerDni(this.txbDni.Text.Trim(), ref paciente)) { MessageBox.Show("Ya existe un Paciente con este Número de Documento"); return; } if (ValidarCampos()) { this.LeerControles(); PacienteNegocio pacienteN = new PacienteNegocio(); if (pacienteN.Agregar(this.paciente) == false) { MessageBox.Show("Error al Agregar"); return; } else { Deshabilitar_Campos(); this.btnBuscar.Enabled = true; this.btnModificar.Enabled = true; this.btnAgregar.Enabled = true; this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; } } return; } }