You are on page 1of 4

Acciones.

java
package mixtli; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Acciones { iniciarBD con; public Acciones (){ con = new iniciarBD(); } public void GuardaPermisosPerfil(int idPerfil){ try { String sql="select a.opcion from opciones as a, opcionesperfil as c where c.idPerfil="+idPerfil+" and c.idOpcion=a.idOpcion order by a.opcion"; PreparedStatement pstm = con.getConnection().prepareStatement(sql); ResultSet res = pstm.executeQuery(); principal.permisosPerfil=new String[20]; int auxDatos=0; while(res.next()){ principal.permisosPerfil[auxDatos]=res.getString("opcion"); auxDatos++; } res.close(); }catch(SQLException e){ System.out.println(e); } } public void ValidaUsuario(String alias, String clave){ try { String sql="select idPerfil from usuarios where alias='"+alias+"' and clave='"+clave+"'"; PreparedStatement pstm = con.getConnection().prepareStatement(sql); ResultSet res = pstm.executeQuery(); while(res.next()){ principal.perfilActivo=res.getInt("idPerfil"); GuardaPermisosPerfil(res.getInt("idPerfil")); } res.close(); }catch(SQLException e){ System.out.println(e); } } } package mixtli;

import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class principal extends javax.swing.JFrame{ public principal() { initComponents(); this.setIconImage(new ImageIcon(getClass().getResource("../imagenes/images.png")).getImage()); this.add(new imagenFondo()); logueo.setSize(350, 220); logueo.setLocationRelativeTo(this); logueo.setTitle("Inicio de Sesin"); logueo.setVisible(false); } private void botonSalirActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } private void botonLoginActionPerformed(java.awt.event.ActionEvent evt) { String valias=calias.getText(); String vclave=new String(cclave.getPassword()); perfilActivo=0; if((valias.isEmpty())||(vclave.isEmpty())) { JOptionPane.showMessageDialog(null, "Ingrese su alias y clave de usuario"); }else{ comandosSQL.ValidaUsuario(valias, vclave); if(perfilActivo>0){ JOptionPane.showMessageDialog(null, "Usuario aceptado habilitar botones"); logueo.setVisible(false); calias.setText(""); cclave.setText(""); barraPermisos.remove(opcionInicioSesion); int permiso1 = mandaExiste(permisosPerfil,"Usuarios"); if(permiso1!=-1){ menu1 = new javax.swing.JMenuItem(); menu1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/usuarios.png"))); menu1.setText("Usuarios"); menu1.setEnabled(true); menu1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { menu1ActionPerformed(evt); } }); barraPermisos.add(menu1); } int permiso2 = mandaExiste(permisosPerfil,"Perfiles"); if(permiso2!=-1){ menu2 = new javax.swing.JMenuItem();

menu2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/perfiles.png"))); menu2.setText("Perfiles"); menu2.setEnabled(true); menu2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { menu2ActionPerformed(evt); } }); barraPermisos.add(menu2); } cerrarSesion = new javax.swing.JMenuItem(); cerrarSesion.setText("Cerrar sesin"); cerrarSesion.setEnabled(true); cerrarSesion.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cerrarSesionActionPerformed(evt); } }); barraPermisos.add(cerrarSesion); }else{ JOptionPane.showMessageDialog(null, "Usuario no aceptado volver a intentar"); } } } private void menu1ActionPerformed(java.awt.event.ActionEvent evt){ JOptionPane.showMessageDialog(null, "menu1"); } private void menu2ActionPerformed(java.awt.event.ActionEvent evt){ JOptionPane.showMessageDialog(null, "menu2"); } private void cerrarSesionActionPerformed(java.awt.event.ActionEvent evt){ this.dispose(); new principal().setVisible(true); } private void opcionInicioSesionActionPerformed(java.awt.event.ActionEvent evt) { logueo.setVisible(true); } private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) { logueo.setVisible(false); calias.setText(""); cclave.setText(""); } public int mandaExiste(String[] arr, String cad) { int index=-1; for(int i=0;i<arr.length;i++)

} } }

if(arr[i] == null ? cad == null : arr[i].equals(cad)){ index=i; break; return index;

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new principal().setVisible(true); } });

} Acciones comandosSQL = new Acciones(); public static int perfilActivo=0; public static String permisosPerfil[]; public static javax.swing.JMenuItem menu1; public static javax.swing.JMenuItem menu2; public static javax.swing.JMenuItem cerrarSesion; // Variables declaration - do not modify private javax.swing.JButton botonCancelar; private javax.swing.JButton botonLogin; private javax.swing.JTextField calias; private javax.swing.JPasswordField cclave; private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JDesktopPane jDesktopPane2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JMenu jMenu1; private javax.swing.JMenu barraPermisos; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem botonLogin; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem botonSalir; private javax.swing.JDialog logueo; private javax.swing.JMenuItem opcionInicioSesion;

You might also like