/*
 * 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 interfacePharmacie;

//import static interfacePharmacie.InterfaceLoginUser0.levelProfil;
//import static interfacePharmacie.InterfaceLoginUser0.nom;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;


/**
 *
 * @author awn27
 */
public class InterfaceLoginUser extends javax.swing.JFrame {

    /**
     * Creates new form InterfaceLogin
     */
    public InterfaceLoginUser() {
        initComponents();
         //conn=db.java_db();
        Toolkit toolkit = getToolkit();
        Dimension size = toolkit.getScreenSize();
        setLocation(size.width/2 - getWidth()/2, 
        size.height/2 - getHeight()/2);
        this.setLocationRelativeTo(this);
        this.setResizable(false);
        CurrentDate();
       lblPharmacie.setText(String.valueOf(InterfaceLogin.nomPharmacie).toString());

    }
public void CurrentDate(){
    Calendar cal = new GregorianCalendar();
    int mois = cal.get(Calendar.MONTH);
    int annee = cal.get(Calendar.YEAR);
    int jour = cal.get(Calendar.DAY_OF_MONTH);
    lblDate.setText(" "+jour+"/"+mois+1+"/"+annee); 
    
   // int seconde = cal.get(Calendar.SECOND);
    int minute = cal.get(Calendar.MINUTE);
    int heure = cal.get(Calendar.HOUR);
    lblHeure.setText(heure+":"+minute);
   
}
   
    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblDate = new javax.swing.JLabel();
        lblHeure = new javax.swing.JLabel();
        txtLoginUser = new javax.swing.JTextField();
        btnConnectionUser = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtPasswordUser = new javax.swing.JPasswordField();
        jLabel4 = new javax.swing.JLabel();
        lblPharmacie = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblDate.setText("Date");
        getContentPane().add(lblDate, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 90, -1));

        lblHeure.setText("Heure");
        getContentPane().add(lblHeure, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, 130, -1));

        txtLoginUser.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N
        getContentPane().add(txtLoginUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 380, 190, 30));

        btnConnectionUser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/iconCon.png"))); // NOI18N
        btnConnectionUser.setText("Connection");
        btnConnectionUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnectionUserActionPerformed(evt);
            }
        });
        getContentPane().add(btnConnectionUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 470, 190, 60));

        jLabel2.setFont(new java.awt.Font("Arial Black", 0, 16)); // NOI18N
        jLabel2.setText("Identifiant :");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 380, -1, -1));

        jLabel3.setFont(new java.awt.Font("Arial Black", 0, 16)); // NOI18N
        jLabel3.setText("Mot de passe :");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 430, 150, 20));

        txtPasswordUser.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N
        getContentPane().add(txtPasswordUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 430, 190, 30));

        jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Connexion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Vivaldi", 1, 24))); // NOI18N
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 340, 420, 210));

        lblPharmacie.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18)); // NOI18N
        lblPharmacie.setText("jLabel6");
        getContentPane().add(lblPharmacie, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 100, 190, 50));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public static String nom;
    public static int idUser;
    public static String levelProfil;
    
    
    
    private void btnConnectionUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectionUserActionPerformed
        // TODO add your handling code here:
        String loginUser = txtLoginUser.getText().toString();
        String passwordUser = txtPasswordUser.getText().toString();

 if (loginUser.isEmpty() || passwordUser.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Veuillez renseigner les champs");
        }
        else {
          BDPharmacie db = new BDPharmacie();
          String resultLogin = db.checkUser(loginUser, passwordUser);
          String resultNomUser = db.checkNomUser(loginUser);
          String resultProfil = db.checkProfil(loginUser);
          
          if (resultLogin == null) {
              JOptionPane.showMessageDialog(this, "Paramètres incorrects");
          }
          else {
              idUser = Integer.parseInt(resultLogin);
              nom = String.valueOf(resultNomUser);
              levelProfil = String.valueOf(resultProfil);
          }
          
           switch (levelProfil)
       {
           case "Vendeur":
                new AccueilVendeur().setVisible(true);
                dispose();
           break;
           case "Pharmacien":
               new AccueilPharmacie().setVisible(true);
               dispose();
           break;
           case "Comptable":
               new AccueilComptable().setVisible(true);
               dispose();
           break;
          default:
              JOptionPane.showMessageDialog(this, "Vous ne pouvez pas utiliser ce programme");               
               
       }           
          
     }
        
    }//GEN-LAST:event_btnConnectionUserActionPerformed

    /**
     * @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(InterfaceLoginUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InterfaceLoginUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InterfaceLoginUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InterfaceLoginUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfaceLoginUser().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConnectionUser;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblDate;
    private javax.swing.JLabel lblHeure;
    private javax.swing.JLabel lblPharmacie;
    private javax.swing.JTextField txtLoginUser;
    private javax.swing.JPasswordField txtPasswordUser;
    // End of variables declaration//GEN-END:variables
}
