/*
 * 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.InterfaceLoginUser.levelProfil;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

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

    /**
     * Creates new form InterfaceLogin
     */
    public InterfaceLogin() {
        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();
    }

    /**
     * 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();
        txtLoginPharmacie = new javax.swing.JTextField();
        btnConnection = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtPasswordPharmacie = new javax.swing.JPasswordField();
        jLabel4 = 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));

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

        btnConnection.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/iconCon.png"))); // NOI18N
        btnConnection.setText("Connection");
        btnConnection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnectionActionPerformed(evt);
            }
        });
        getContentPane().add(btnConnection, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 260, 150, 40));

        jLabel2.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N
        jLabel2.setText("Identifiant :");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 180, -1, -1));

        jLabel3.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 12)); // NOI18N
        jLabel3.setText("Mot de passe :");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 220, 90, 20));

        txtPasswordPharmacie.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N
        getContentPane().add(txtPasswordPharmacie, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 220, 190, -1));

        jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Connexion", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 1, 10))); // NOI18N
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 150, 350, 170));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public static int idPharmacie;
    public static String nomPharmacie;
    public static String soldePharmacie;
    
    
    
    private void btnConnectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectionActionPerformed
        // TODO add your handling code here:
        String login=txtLoginPharmacie.getText().toString();
        String password=txtPasswordPharmacie.getText().toString();

if(login.isEmpty() || password.isEmpty())
    {
JOptionPane.showMessageDialog(this, "Veuiller renseigner les champs");
    }
else{
       BDPharmacie bd=new BDPharmacie();
       String result=bd.checkPharmacie(login, password);
       String result1=bd.checkNomPharmacie(login);
       String resultProfil = bd.checkProfilPharma(login);
       String resultSolde = bd.checkSoldePharmacie(login);
       
       if(result==null){
JOptionPane.showMessageDialog(this, "Paramétres incorrects");
           
       }
       else{
           idPharmacie=Integer.parseInt(result);
           nomPharmacie=String.valueOf(result1);
           levelProfil = String.valueOf(resultProfil);
           soldePharmacie = String.valueOf(resultSolde);
           
          // new InterfaceLoginUser().setVisible(true);
           //dispose();
       }
       switch (levelProfil)
       {
           case "Administrateur":
                new Administrateur().setVisible(true);
                dispose();
           break;
           default:
              new InterfaceLoginUser().setVisible(true);              
               
       }  
    }
        
    }//GEN-LAST:event_btnConnectionActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConnection;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblDate;
    private javax.swing.JTextField txtLoginPharmacie;
    private javax.swing.JPasswordField txtPasswordPharmacie;
    // End of variables declaration//GEN-END:variables
}
