Package com.vgo.movie.ecran

Source Code of com.vgo.movie.ecran.Login

package com.vgo.movie.ecran;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.SQLException;
import java.util.HashMap;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import com.vgo.movie.data.DatabaseDAO;
import com.vgo.movie.domain.Generique;
import com.vgo.movie.domain.Utilisateurs;
import com.vgo.movie.util.Libelle;
import com.vgo.movie.util.Version;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Login extends javax.swing.JFrame {

  private static final long serialVersionUID = 1L;
  private JLabel jLabelLogin;
  private JLabel jLabelMotDePasse;
  private JButton jButtonLogin;
  private JPasswordField jPasswordField;
  private JTextField jTextFieldLogin;

  /**
  * Auto-generated main method to display this JDialog
  */
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    Login inst = new Login(frame);
    inst.setTitle(Libelle.getLibelle("titreFenetre") + " " + Version.currentVersion);
    inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
 
  public Login(JFrame frame) {
    super();
    verificationBaseDeDonnees();
    if(!connexionSSO()){
      this.setVisible(true);
      initGUI();
      initLibelle();
    }
  }
 
  private boolean connexionSSO() {
    Utilisateurs tmpUtil = new Utilisateurs();
    tmpUtil.setLoginNT(System.getenv("COMPUTERNAME") + "\\" +System.getenv().get("USERNAME"));
   
    try {
      tmpUtil = (Utilisateurs)DatabaseDAO.selectDetailUtilisateur(tmpUtil);
    } catch (Exception e) {
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurVerifUser"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.ERROR_MESSAGE,
          null,
          null,
          null);   
      System.exit(-1);
    }


    if(tmpUtil != null){
      Main inst = new Main(tmpUtil);
      inst.setVisible(true);
      inst.setTitle(Libelle.getLibelle("titreFenetre") + " " + Version.currentVersion);
      inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      return true;
   
    else{
      return false;
    }
   
  }

  private void initGUI() {
    try {
      {
        getContentPane().setLayout(null);
      }
      {
        jLabelLogin = new JLabel();
        getContentPane().add(jLabelLogin);
        jLabelLogin.setBounds(7, 28, 154, 28);
      }
      {
        jTextFieldLogin = new JTextField();
        getContentPane().add(jTextFieldLogin);
        jTextFieldLogin.setBounds(168, 28, 210, 28);
      }
      {
        jLabelMotDePasse = new JLabel();
        getContentPane().add(jLabelMotDePasse);
        jLabelMotDePasse.setBounds(7, 70, 161, 28);
      }
      {
        jPasswordField = new JPasswordField();
        getContentPane().add(jPasswordField);
        jPasswordField.setBounds(168, 70, 210, 28);
     
      }
      {
        jButtonLogin = new JButton();
        getContentPane().add(jButtonLogin);
        jButtonLogin.setBounds(126, 126, 112, 28);
        jButtonLogin.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            jButtonLoginActionPerformed(evt);
          }
        });
      }
      this.setSize(400, 202);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  private void initLibelle() {
    jLabelLogin.setText(Libelle.getLibelle("login"));       
    jLabelMotDePasse.setText(Libelle.getLibelle("password"))
    jButtonLogin.setText(Libelle.getLibelle("ok"));         
   
  }
 
 
  private void jButtonLoginActionPerformed(ActionEvent evt) {
    //Faire l'authentification sur la base
    Utilisateurs tmpUtilisateur = new Utilisateurs();
   
    tmpUtilisateur.setLogin(jTextFieldLogin.getText());
    tmpUtilisateur.setMotDePasse(new String(jPasswordField.getPassword()));
   
    try {
      tmpUtilisateur = (Utilisateurs)DatabaseDAO.selectDetailUtilisateur(tmpUtilisateur);
      if(tmpUtilisateur == null){
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(this),
            Libelle.getLibelle("echecLogin"),
            Libelle.getLibelle("erreur"),
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            null,
            null);       
      }
      else{
        Main inst = new Main(tmpUtilisateur);
        inst.setVisible(true);
        inst.setTitle(Libelle.getLibelle("titreFenetre") + " " + Version.currentVersion);
        inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
        this.setVisible(false);
      }
    } catch (SQLException e) {
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurVerifUser"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.ERROR_MESSAGE,
          null,
          null,
          null);   
      System.exit(-1);
    }
  }

  private void verificationBaseDeDonnees(){
    File f = new File("movie.db");
    if(!f.exists()){
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("initialisationBdd"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.WARNING_MESSAGE,
          null,
          null,
          null)

      try {
        DatabaseDAO.creationBDD();
      } catch (SQLException e) {
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(this),
            Libelle.getLibelle("erreurInitialisationBdd"),
            Libelle.getLibelle("erreur"),
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.WARNING_MESSAGE,
            null,
            null,
            null)
        e.printStackTrace();
        //System.exit(-1);
      }
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("initialisationBddOk"),
          Libelle.getLibelle("information"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.INFORMATION_MESSAGE,
          null,
          null,
          null)
    }
    try {
      if(DatabaseDAO.selectLastVersion() != null){
        Generique tmpVersion = (Generique)DatabaseDAO.selectLastVersion();
        Float lastVersionFloat = new Float(tmpVersion.getCode());
        if(!tmpVersion.getCode().equals(Version.currentVersion)){
          Version.getHistoriqueVersion();
          for (HashMap<String,String> temp : Version.getHistoriqueVersion()) {
            Float versionHistoIte = new Float(temp.get("Code"));
            if(versionHistoIte > lastVersionFloat){
              //Version diff�rente entre la BDD et le programme
              DatabaseDAO.migration(temp.get("Script"));
            }
          }

        }
      }

    } catch (SQLException e) {
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurInitialisationBdd"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.WARNING_MESSAGE,
          null,
          null,
          null)
      System.exit(-1);
    }   

  } 
 
}
TOP

Related Classes of com.vgo.movie.ecran.Login

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.