Guest User

Untitled

a guest
Jan 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public void nuevoUsuario(Usuario usuario) throws SQLException {
  2. try {
  3. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empresa", "root", "ticowrc2017");
  4. String sentencia = "INSERT INTO usuario (Cedula_Usuario,Nombre, Usuario, Contrasena, Rol) "
  5. + "VALUES (?,?,?,?,?)";
  6. ps = con.prepareStatement(sentencia);
  7. ps.setString(1, usuario.getCedulaUsuario());
  8. ps.setString(2, usuario.getNombre());
  9. ps.setString(3, usuario.getUsuario());
  10. ps.setString(4, usuario.getContrasena());
  11. ps.setInt(5, usuario.getRol());
  12. ps.executeUpdate();
  13. } catch (SQLException ex) {
  14. JOptionPane.showMessageDialog(null, "El usuario ya está registrado o uno de los campon"
  15. + "que ha llenado han sido ingresados en otro usuario");
  16. } finally {
  17. try {
  18. ps.close();
  19. con.close();
  20. } catch (SQLException ex) {
  21. Logger.getLogger(DATUsuario.class.getName()).log(Level.SEVERE, null, ex);
  22. }
  23. }
  24.  
  25. }
  26.  
  27. public void nuevoUsuario() {
  28. int rolUs = 0;
  29. int digitosCedula = txtCedulaUser.getText().length();
  30. if (txtConf.getText().isEmpty() || txtNombre.getText().isEmpty()
  31. || txtPass.getText().isEmpty() || txtUsuario.getText().isEmpty()) {
  32. JOptionPane.showMessageDialog(null, "Todos los campos son obligatorios");
  33. } else if (digitosCedula != 10) {
  34. JOptionPane.showMessageDialog(null, "Número de cédula incorrecto");
  35. } else {
  36. String cedula = txtCedulaUser.getText();
  37. String nom = txtNombre.getText();
  38. String usu = txtUsuario.getText();
  39. String pass = txtPass.getText();
  40. String rol = (String) jComboBox1.getSelectedItem();
  41. if (rol.equals("Vendedor")) {
  42. rolUs = 0;
  43. }
  44. if (txtPass.getText().equals(txtConf.getText())) {
  45. String newPass = pass;
  46. pass = getMD5(newPass);
  47. objUs = new Usuario(cedula, nom, usu, pass, rolUs);
  48. try {
  49. usuario.nuevoUsuario(objUs);
  50. } catch (SQLException ex) {
  51. JOptionPane.showMessageDialog(null, "Error");
  52. }
  53. this.dispose();
  54. } else {
  55. JOptionPane.showMessageDialog(null, "Las contraseñas no coinciden");
  56. }
  57. }
  58. }
  59.  
  60. private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
  61. nuevoUsuarioVendedor();
  62. JOptionPane.showMessageDialog(
  63. null, "El usuario se creó correctamente, "
  64. + "a continuación deberá nvolver a ingresar "
  65. + "su usuario y contraseña");
  66. Validacion objV = new Validacion();
  67. objV.setVisible(true);
  68. this.dispose();
  69. }
Add Comment
Please, Sign In to add comment