private void btnRegistrar_Pac_Click(object sender, EventArgs e) { try { AccionesTerminal at = new AccionesTerminal(); PACIENTE pac = new PACIENTE(); //capturando datos if (txtContrasena_Pac.Text == null || txtContrasena_Pac.Text == "") { throw new Exception(); } pac.NOMBRES_PACIENTE = txtNombres_Pac.Text; pac.APELLIDOS_PACIENTE = txtApellidos_Pac.Text; pac.EMAIL_PACIENTE = txtEmail_Pac.Text; pac.HASHED_PASS = Util.hashMD5(txtContrasena_Pac.Text); pac.RUT = int.Parse(txtRutCargado_Pac.Text); pac.DIGITO_VERIFICADOR = txtVerificadorCargado_Pac.Text; pac.FEC_NAC = DateTime.Parse(dtpFechaNac_Pac.Text); pac.ACTIVO = true; if (((ComboboxItem)cbSexo_Pac.SelectedItem).Value == 0) { pac.SEXO = "M"; } else if (((ComboboxItem)cbSexo_Pac.SelectedItem).Value == 1) { pac.SEXO = "F"; } if (!Util.isEmailValido(pac.EMAIL_PACIENTE)) { throw new Exception(); } if (!Util.rutValido(pac.RUT, pac.DIGITO_VERIFICADOR)) { throw new Exception(); } if (pac.HASHED_PASS == null || pac.HASHED_PASS == "") { throw new Exception(); } if (at.nuevoPaciente(pac)) { MessageBox.Show("¡Paciente creado exitosamente!", "Personal", MessageBoxButtons.OK, MessageBoxIcon.None); limpiarDatos(); } else { throw new Exception(); } } catch (Exception ex) { MessageBox.Show("Error al crear paciente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCrear_Click(object sender, EventArgs e) { string mensajeCorrecto = "Paciente creado correctamente"; string mensajeError = string.Empty; try { if (dtFechaNacimiento.Value.Date > DateTime.Today.Date) { mensajeError = "Fecha de nacimiento inválida"; } else if (!Util.rutValido(int.Parse(txtRut.Text), txtDv.Text)) { mensajeError = "RUT no válido"; } else if (!Util.isEmailValido(txtCorreo.Text)) { mensajeError = "Correo no válido"; } else if (!Util.isObjetoNulo(at.buscarPaciente(int.Parse(txtRut.Text), txtDv.Text))) { mensajeError = "Paciente ya ingresado"; } else { lblError.Visible = true; lblError.Text = "Creando paciente..."; lblError.ForeColor = System.Drawing.Color.Violet; btnCrear.Enabled = false; PACIENTE paciente = new PACIENTE(); paciente.NOMBRES_PACIENTE = txtNombres.Text; paciente.APELLIDOS_PACIENTE = txtApellidos.Text; paciente.RUT = int.Parse(txtRut.Text); paciente.DIGITO_VERIFICADOR = txtDv.Text; paciente.EMAIL_PACIENTE = txtCorreo.Text; paciente.SEXO = ((ComboboxItem)cmbSexo.SelectedItem).Value; paciente.FEC_NAC = dtFechaNacimiento.Value; if (!at.nuevoPaciente(paciente)) { mensajeError = "Error al crear paciente"; } } } catch (Exception ex) { mensajeError = "Error al crear paciente"; } if (mensajeError == string.Empty) { MessageBox.Show(mensajeCorrecto, "Creada", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(mensajeError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } btnCrear.Enabled = true; lblError.Visible = false; }