/*
 * 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 java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

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

    /**
     * Creates new form AccueilPharmacie
     */
    public AccueilVendeur() {
        initComponents();
        Toolkit toolkit = getToolkit();
        Dimension size = toolkit.getScreenSize();
        setLocation(size.width/2 - getWidth()/2, 
        size.height/2 - getHeight()/2);
        this.setLocationRelativeTo(this);
        this.setResizable(false);
        lblNomPharmacie.setText(String.valueOf(InterfaceLogin.nomPharmacie).toString());
        lblNomUser.setText(String.valueOf(InterfaceLoginUser.nom).toString());
        expiration();
    }

    /**
     * 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() {

        btnGestionClient = new javax.swing.JButton();
        btnAchatMedicament = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lblNomPharmacie = new javax.swing.JLabel();
        btnDeconnection = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        btnManuelUtilisation = new javax.swing.JButton();
        btnPharmacieEnligne = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        btnDetailsAchat = new javax.swing.JButton();
        btnGestionExpiration = new javax.swing.JButton();
        lblNomUser = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

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

        btnGestionClient.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnGestionClient.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/client.png"))); // NOI18N
        btnGestionClient.setText("Gestion Client");
        btnGestionClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGestionClientActionPerformed(evt);
            }
        });
        getContentPane().add(btnGestionClient, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 500, 190, 60));

        btnAchatMedicament.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnAchatMedicament.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/iconeAch.png"))); // NOI18N
        btnAchatMedicament.setText("Vente");
        btnAchatMedicament.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAchatMedicamentActionPerformed(evt);
            }
        });
        getContentPane().add(btnAchatMedicament, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 590, -1, 50));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("dans votre pharmacie ");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 0, 180, 30));

        lblNomPharmacie.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lblNomPharmacie.setText("jLabel2");
        getContentPane().add(lblNomPharmacie, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 0, 270, -1));

        btnDeconnection.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logout.png"))); // NOI18N
        btnDeconnection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeconnectionActionPerformed(evt);
            }
        });
        getContentPane().add(btnDeconnection, new org.netbeans.lib.awtextra.AbsoluteConstraints(920, 10, 50, 30));

        jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Vente & Gestion clientelle", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 18))); // NOI18N
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 470, 410, 220));

        btnManuelUtilisation.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnManuelUtilisation.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/manuel.png"))); // NOI18N
        btnManuelUtilisation.setText("Manuel d'aide");
        btnManuelUtilisation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManuelUtilisationActionPerformed(evt);
            }
        });
        getContentPane().add(btnManuelUtilisation, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 350, 190, 70));

        btnPharmacieEnligne.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnPharmacieEnligne.setText("Pharmacie en ligne");
        btnPharmacieEnligne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPharmacieEnligneActionPerformed(evt);
            }
        });
        getContentPane().add(btnPharmacieEnligne, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 350, 180, 70));

        jLabel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Aide", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 410, 150));

        btnDetailsAchat.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnDetailsAchat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/iconeFacture.png"))); // NOI18N
        btnDetailsAchat.setText("Détails Achat");
        btnDetailsAchat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetailsAchatActionPerformed(evt);
            }
        });
        getContentPane().add(btnDetailsAchat, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 590, 180, 50));

        btnGestionExpiration.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnGestionExpiration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/temps.png"))); // NOI18N
        btnGestionExpiration.setText("Péremption");
        btnGestionExpiration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGestionExpirationActionPerformed(evt);
            }
        });
        getContentPane().add(btnGestionExpiration, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 570, 180, 70));

        lblNomUser.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblNomUser.setText("jLabel6");
        getContentPane().add(lblNomUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 10, 90, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 2, 18)); // NOI18N
        jLabel6.setText("Bienvenue ");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 0, 90, 30));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDeconnectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeconnectionActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnDeconnectionActionPerformed

    private void btnGestionClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGestionClientActionPerformed
        // TODO add your handling code here:
        new Client ().setVisible(true);
    }//GEN-LAST:event_btnGestionClientActionPerformed

    private void btnAchatMedicamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAchatMedicamentActionPerformed
        
        new Vente().setVisible(true);
    }//GEN-LAST:event_btnAchatMedicamentActionPerformed

    private void btnManuelUtilisationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManuelUtilisationActionPerformed
        
        try {
            Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + "C:\\Users\\awn27\\Documents\\NetBeansProjects\\Pharmacie\\src\\Manuel\\ManuelUtilisation.pdf");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }//GEN-LAST:event_btnManuelUtilisationActionPerformed

    public void expiration () {
        try {
             BDPharmacie bd=new BDPharmacie();
             Connection connex = bd.connectToBD();
             String sql="SELECT id_medicament, nom_medicament, code, stock, date_expiration, MIN(datediff (date_expiration, CURRENT_DATE)) As expiration FROM medicament WHERE id_pharmacie = '"+InterfaceLogin.idPharmacie+"' ";
             PreparedStatement stm = connex.prepareStatement(sql);
             ResultSet rs=stm.executeQuery();
                         
             
             while(rs.next())
             { 
                String id=rs.getString("id_medicament");
                 String nom=rs.getString("nom_medicament");
                 String code=rs.getString("code");
                 String stock=rs.getString("stock");
                 String date=rs.getString("date_expiration");
                 String expiration=rs.getString("expiration");
                 
                 int a = Integer.parseInt(expiration);
                                 
                 
                 if (a < 11) {
                     JOptionPane.showMessageDialog(this,"Médicament ayant comme nom:"+nom+" et code:"+code +" va expirer dans: "+a+" jours");
             }
                 
             }
             
        } catch (Exception e) {
            e.printStackTrace();
        }
    }    
    
    private void btnPharmacieEnligneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPharmacieEnligneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnPharmacieEnligneActionPerformed

    private void btnDetailsAchatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetailsAchatActionPerformed
        new DetailsAchat().setVisible(true);
    }//GEN-LAST:event_btnDetailsAchatActionPerformed

    private void btnGestionExpirationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGestionExpirationActionPerformed
new GestionExpiration().setVisible(true);
    }//GEN-LAST:event_btnGestionExpirationActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAchatMedicament;
    private javax.swing.JButton btnDeconnection;
    private javax.swing.JButton btnDetailsAchat;
    private javax.swing.JButton btnGestionClient;
    private javax.swing.JButton btnGestionExpiration;
    private javax.swing.JButton btnManuelUtilisation;
    private javax.swing.JButton btnPharmacieEnligne;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel lblNomPharmacie;
    private javax.swing.JLabel lblNomUser;
    // End of variables declaration//GEN-END:variables
}
