/*
 * 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.
 */

/* Ver referencias aqui http://bitingenieria.com.ar/doc/ifu/IFUniversal_TLB/IDriver.html*/

package feafip.demo;

import javax.swing.JOptionPane;

/**
 *
 * @author amiranda
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

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

        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton2.setText("Transaccion Medicamento");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(46, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(59, Short.MAX_VALUE))
        );

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

    private void msgBox(String text){
        JOptionPane.showMessageDialog(this,
                    text,
                    "FEAFIP Demo",
                    JOptionPane.PLAIN_MESSAGE);
        
    }
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Realiza el registro de una transacción de medicamento.
        // El usuario (laboratorio/droguería/operador logístico/farmacia) informa el evento ocurrido para cada uno de los medicamentos.

        bi.trazamedlib.ITrazaMed trazamedObj = bi.trazamedlib.ClassFactory.createTrazaMed();
        bi.trazamedlib.ImedicamentosDTO med = bi.trazamedlib.ClassFactory.createmedicamentosDTO();

        trazamedObj.modo_produccion(false);
        trazamedObj.logTransaction("Request.xml", "Response.xml"); //Deja un log de cada transaccion en los archivos.

        trazamedObj.usuario("pruebasws");
        trazamedObj.password("Clave1234");

        med.f_evento("24/04/2012");
        med.h_evento("04:24");
        med.gln_origen("GLNWS");
        med.gln_destino("9999999999918");
        med.n_remito("R000100000001");
        med.n_factura("F000100000001");
        med.vencimiento("30/12/2011");
        med.gtin("GTIN2");
        med.lote("11113");
        med.numero_serial("8623344444223468698");  // Cambiar este valor si recibe error que ya fue informado el medicamento.
        med.id_obra_social("600309");
        med.id_evento(156);
        med.cuit_origen("20939802593");
        med.cuit_destino("20929007862");
        med.apellido("Abel");
        med.nombres("Miranda");
        med.tipo_documento(96);
        med.n_documento("93980259");
        med.sexo("M");
        med.direccion("Blanco Encalada");
        med.numero("1234");
        med.piso("");
        med.dpto("");
        med.localidad("Capital Federal");
        med.provincia("Buenos Aires");
        med.n_postal("1428");
        med.fecha_nacimiento("01/01/2000");
        med.telefono("5555-5555");

        trazamedObj.agregaMedicamento(med);
        if (!trazamedObj.sendMedicamentos()) {
          msgBox(trazamedObj.errores());
        } else {
          msgBox("Transacción exitosa! Id de transacción: " + trazamedObj.id_transaccion());
        }   
    }//GEN-LAST:event_jButton2ActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    // End of variables declaration//GEN-END:variables
}
