Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.com.imobiliaria.view;
- import br.com.imobiliaria.controller.Imobiliaria;
- import br.com.imobiliaria.controller.Imovel;
- import br.com.imobiliaria.model.ModuloConexao;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLClientInfoException;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Arrays;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author alexandre
- */
- public class TelaLogin extends javax.swing.JFrame {
- Connection c = null;
- //Prepared Statement e ResultSet são frameworks do pacote java.sql e servem para preparar e executar as instruções SQL
- PreparedStatement pst = null;
- ResultSet rs = null;
- Imobiliaria i = new Imobiliaria();
- /**
- * Creates new form TelaLogin
- */
- public TelaLogin() {
- initComponents();
- try {
- c = ModuloConexao.conector();
- if (c == null) {
- lblStatus.setText("OFFLINE");
- txtSenha.setEnabled(false);
- txtUsuario.setEnabled(false);
- btnLogar.setEnabled(false);
- btnCadastrar.setEnabled(false);
- //System.exit(0);
- } else {
- lblStatus.setText("ONLINE");
- try {
- c.close();
- } catch (SQLException ex) {
- Logger.getLogger(TelaLogin.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- } catch (SQLClientInfoException ex) {
- JOptionPane.showMessageDialog(null, "SISTEMA OFFLINE\nErro: " + ex.getMessage(), "STATUS", JOptionPane.ERROR_MESSAGE);
- //Logger.getLogger(TelaLogin.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- buttonGroupTipoLogin = new javax.swing.ButtonGroup();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- txtUsuario = new javax.swing.JTextField();
- txtSenha = new javax.swing.JPasswordField();
- btnLogar = new javax.swing.JButton();
- btnCadastrar = new javax.swing.JButton();
- lblStatus = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("TELA DE LOGIN");
- setResizable(false);
- jLabel1.setText("Usuário .:");
- jLabel2.setText("Senha .:");
- btnLogar.setText("Logar");
- btnLogar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnLogarActionPerformed(evt);
- }
- });
- btnCadastrar.setText("Cadastre-se");
- btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnCadastrarActionPerformed(evt);
- }
- });
- lblStatus.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel2)
- .addComponent(jLabel1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(btnLogar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnCadastrar)
- .addGap(18, 18, 18)
- .addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
- .addComponent(txtUsuario)
- .addComponent(txtSenha))
- .addGap(26, 26, 26))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnLogar)
- .addComponent(btnCadastrar)
- .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- public void buscarImobiliaria() {
- String sql = "SELECT cod_imob, cnpj, nm_imob, email, tel, login, senha, ult_acesso FROM imobiliaria where login = ?";
- try {
- c = ModuloConexao.conector();
- pst = c.prepareStatement(sql);
- pst.setString(1, txtUsuario.getText().trim());
- rs = pst.executeQuery();
- if (rs.next()) {
- i.setCodigo(rs.getInt("cod_imob"));
- i.setCnpj(rs.getString("cnpj"));
- i.setNome(rs.getString("nm_imob"));
- i.setEmail(rs.getString("email"));
- i.setTelefone(rs.getString("tel"));
- i.setLogin(rs.getString("login"));
- i.setSenha(rs.getString("senha"));
- i.setUlt_acesso(rs.getTimestamp("ult_acesso"));
- }
- } catch (SQLException ex) {
- Logger.getLogger(TelaLogin.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- //Metodo com problema
- public void atualizaUltAcesso() {
- String sql = "UPDATE imobiliaria SET ult_acesso = SYSDATE-interval'3'hour WHERE cod_imob=?";
- try {
- c = ModuloConexao.conector();
- pst = c.prepareStatement(sql);
- pst.setInt(1, (i.getCodigo())); //i refere-se a variável do tipo imobiliaria
- pst.executeUpdate();
- c.commit();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- //Fonte usada pra solução do problema de select:
- //https://www.javac.com.br/jc/posts/list/3793-faultstringora03115tipo-de-dados-ou-representacao-de-rede-nao-aceitaofaultstringresolvido.page
- private void btnLogarActionPerformed(java.awt.event.ActionEvent evt) {
- if (txtUsuario.getText().length() == 0) {
- JOptionPane.showMessageDialog(null, "Campo Vazio, Digite usuário", "ATENÇÃO !", JOptionPane.INFORMATION_MESSAGE);
- } else {
- buscarImobiliaria();
- //Verifica se usuário e senha correspondem
- System.out.println(i.getLogin() + "---" + i.getSenha());
- if (txtUsuario.getText().trim().equals(i.getLogin()) && txtSenha.getText().equals(i.getSenha())) {
- atualizaUltAcesso();
- //buscarImobiliaria();
- //Envia os dados da imobiliaria para o proximo form
- //TelaPrincipal.imob = i;
- //new TelaPrincipal().setVisible(true);
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "Usuário Inválido", "ATENÇÃO !", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
- CadastroDeImobiliaria ci = new CadastroDeImobiliaria();
- ci.setVisible(true);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(TelaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(TelaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(TelaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(TelaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new TelaLogin().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnCadastrar;
- private javax.swing.JButton btnLogar;
- private javax.swing.ButtonGroup buttonGroupTipoLogin;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel lblStatus;
- private javax.swing.JPasswordField txtSenha;
- private javax.swing.JTextField txtUsuario;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement