Compras.ComparaCotizacion.java Source code

Java tutorial

Introduction

Here is the source code for Compras.ComparaCotizacion.java

Source

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

 import Hibernate.Util.HibernateUtil;
 import Hibernate.entidades.Ejemplar;
 import Hibernate.entidades.Orden;
 import Hibernate.entidades.Partida;
 import Hibernate.entidades.Pedido;
 import Hibernate.entidades.Proveedor;
 import Hibernate.entidades.Usuario;
 import Proveedor.buscaProveedor;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Toolkit;
 import java.io.File;
 import java.io.FileInputStream;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 import javax.swing.ImageIcon;
 import javax.swing.JOptionPane;
 import javax.swing.SwingConstants;
 import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.JTableHeader;
 import javax.swing.table.TableColumn;
 import javax.swing.table.TableColumnModel;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
 import Integral.ExtensionFileFilter;
 import Integral.FormatoEditor;
 import Integral.FormatoTabla;
 import Integral.Herramientas;
 import Integral.HorizontalBarUI;
 import Integral.Render1;
 import Integral.VerticalBarUI;
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.util.Properties;
 import javax.mail.BodyPart;
 import javax.mail.Message;
 import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;

 /**
  *
  * @author salvador
  */
 public class ComparaCotizacion extends javax.swing.JPanel {

     Herramientas h;
     private Usuario user;
     private String orden;
     private Session session;
     Orden ord = null;
     String sessionPrograma = "";
     List columnas = new ArrayList();
     List tipos = new ArrayList();
     List NoProveedor = new ArrayList();
     List id_pedido;
     FormatoTabla formato;
     MyModel model;
     DefaultTableModel modeloPedidos;
     Formatos f1;
     Workbook libro1 = null;
     Workbook libro2 = null;
     Workbook libro3 = null;
     private Usuario usrAut;
     String[] colPedidos = new String[] { "No", "Proveedor", "Fecha", };
     String edo = "";

     /**
      * Creates new form ComparaCotizacion
      */
     public ComparaCotizacion(String orde, Usuario us, String ses, Orden a, String estado) {
         initComponents();
         scroll.getVerticalScrollBar().setUI(new VerticalBarUI());
         scroll.getHorizontalScrollBar().setUI(new HorizontalBarUI());
         ord = a;
         sessionPrograma = ses;
         orden = orde;
         user = us;
         formato = new FormatoTabla();
         edo = estado;
         if (edo.compareTo("") != 0) {
             h = new Herramientas(user, 0);
             if (h.isCerrada(orden) == true)
                 visualiza(false, 1);
             else
                 visualiza(false, 0);
         } else {
             h = new Herramientas(user, 0);
             if (h.isCerrada(orden) == true)
                 visualiza(false, 1);
             else
                 visualiza(true, 0);
         }
     }

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

     jLabel9 = new javax.swing.JLabel();
     t_proveedor6 = new javax.swing.JTextField();
     listaPedidos = new javax.swing.JDialog();
     jPanel6 = new javax.swing.JPanel();
     jLabel7 = new javax.swing.JLabel();
     jScrollPane3 = new javax.swing.JScrollPane();
     t_pedidos = new javax.swing.JTable();
     jPanel7 = new javax.swing.JPanel();
     jButton6 = new javax.swing.JButton();
     jButton7 = new javax.swing.JButton();
     autorizarCosto = new javax.swing.JDialog();
     jPanel9 = new javax.swing.JPanel();
     jLabel11 = new javax.swing.JLabel();
     t_user = new javax.swing.JTextField();
     jLabel12 = new javax.swing.JLabel();
     t_clave = new javax.swing.JPasswordField();
     b_aceptar = new javax.swing.JButton();
     jLabel14 = new javax.swing.JLabel();
     jTabbedPane1 = new javax.swing.JTabbedPane();
     jPanel1 = new javax.swing.JPanel();
     jLabel1 = new javax.swing.JLabel();
     jLabel2 = new javax.swing.JLabel();
     jLabel3 = new javax.swing.JLabel();
     jLabel4 = new javax.swing.JLabel();
     t_proveedor1 = new javax.swing.JTextField();
     t_proveedor2 = new javax.swing.JTextField();
     t_proveedor3 = new javax.swing.JTextField();
     jButton1 = new javax.swing.JButton();
     jButton2 = new javax.swing.JButton();
     jButton3 = new javax.swing.JButton();
     t_np1 = new javax.swing.JTextField();
     t_np2 = new javax.swing.JTextField();
     t_np3 = new javax.swing.JTextField();
     r_automatico = new javax.swing.JRadioButton();
     jPanel2 = new javax.swing.JPanel();
     jPanel4 = new javax.swing.JPanel();
     l_p1 = new javax.swing.JLabel();
     l_proveedor1 = new javax.swing.JLabel();
     l_proveedor2 = new javax.swing.JLabel();
     l_p2 = new javax.swing.JLabel();
     l_proveedor3 = new javax.swing.JLabel();
     l_p3 = new javax.swing.JLabel();
     scroll = new javax.swing.JScrollPane();
     t_datos = new javax.swing.JTable();
     jPanel5 = new javax.swing.JPanel();
     jButton4 = new javax.swing.JButton();
     jLabel5 = new javax.swing.JLabel();
     t_empresa = new javax.swing.JTextField();
     b_busca = new javax.swing.JButton();

     jLabel9.setBackground(new java.awt.Color(21, 0, 255));
     jLabel9.setForeground(new java.awt.Color(254, 254, 254));
     jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
     jLabel9.setText("Proveedor 3");
     jLabel9.setOpaque(true);

     t_proveedor6.setEnabled(false);

     listaPedidos.setModalExclusionType(null);
     listaPedidos.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);

     jPanel6.setBackground(new java.awt.Color(0, 153, 153));

     jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
     jLabel7.setForeground(new java.awt.Color(255, 255, 255));
     jLabel7.setText("Relacin de pedidos generados");
     jPanel6.add(jLabel7);

     listaPedidos.getContentPane().add(jPanel6, java.awt.BorderLayout.PAGE_START);

     t_pedidos.setModel(new javax.swing.table.DefaultTableModel(
         new Object [][] {

         },
         new String [] {
             "No", "Proveedor", "Fecha"
         }
     ));
     t_pedidos.getTableHeader().setReorderingAllowed(false);
     jScrollPane3.setViewportView(t_pedidos);

     listaPedidos.getContentPane().add(jScrollPane3, java.awt.BorderLayout.CENTER);

     jPanel7.setBackground(new java.awt.Color(214, 217, 223));

     jButton6.setBackground(new java.awt.Color(90, 66, 126));
     jButton6.setForeground(new java.awt.Color(255, 255, 255));
     jButton6.setIcon(new ImageIcon("imagenes/nuevo.png"));
     jButton6.setText("Pedido");
     jButton6.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton6ActionPerformed(evt);
         }
     });
     jPanel7.add(jButton6);

     jButton7.setBackground(new java.awt.Color(90, 66, 126));
     jButton7.setForeground(new java.awt.Color(255, 255, 255));
     jButton7.setIcon(new ImageIcon("imagenes/nuevo.png"));
     jButton7.setText("Ord. de Compra");
     jButton7.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton7ActionPerformed(evt);
         }
     });
     jPanel7.add(jButton7);

     listaPedidos.getContentPane().add(jPanel7, java.awt.BorderLayout.PAGE_END);

     autorizarCosto.setModalExclusionType(null);
     autorizarCosto.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);

     jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Autorizacin de costos mayores", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

     jLabel11.setText("Usuario:");

     t_user.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             t_userActionPerformed(evt);
         }
     });

     jLabel12.setText("contrasea:");

     t_clave.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             t_claveActionPerformed(evt);
         }
     });

     b_aceptar.setText("Autorizar");
     b_aceptar.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             b_aceptarActionPerformed(evt);
         }
     });

     jLabel14.setText("Autorizar un costo mayor al autorizado");

     javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
     jPanel9.setLayout(jPanel9Layout);
     jPanel9Layout.setHorizontalGroup(
         jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel9Layout.createSequentialGroup()
             .addContainerGap()
             .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addComponent(b_aceptar)
                     .addGroup(jPanel9Layout.createSequentialGroup()
                         .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                             .addComponent(jLabel12)
                             .addComponent(jLabel11))
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                             .addComponent(t_user)
                             .addComponent(t_clave, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE))))
                 .addComponent(jLabel14))
             .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
     );
     jPanel9Layout.setVerticalGroup(
         jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
             .addContainerGap()
             .addComponent(jLabel14)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
             .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jLabel11)
                 .addComponent(t_user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jLabel12)
                 .addComponent(t_clave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addComponent(b_aceptar)
             .addContainerGap())
     );

     autorizarCosto.getContentPane().add(jPanel9, java.awt.BorderLayout.CENTER);

     setBackground(new java.awt.Color(254, 254, 254));
     setLayout(new java.awt.BorderLayout());

     jTabbedPane1.setBackground(new java.awt.Color(254, 254, 254));
     jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.RIGHT);
     jTabbedPane1.setAlignmentX(0.0F);
     jTabbedPane1.setAlignmentY(0.0F);
     jTabbedPane1.setOpaque(true);
     jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
         public void stateChanged(javax.swing.event.ChangeEvent evt) {
             jTabbedPane1StateChanged(evt);
         }
     });

     jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
     jLabel1.setText("Selecciona los archivos de cotizaciones:");

     jLabel2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
     jLabel2.setText("Proveedor1:");

     jLabel3.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
     jLabel3.setText("Proveedor2:");

     jLabel4.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
     jLabel4.setText("Proveedor3:");

     t_proveedor1.setEnabled(false);

     t_proveedor2.setEnabled(false);

     t_proveedor3.setEnabled(false);

     jButton1.setBackground(new java.awt.Color(2, 135, 242));
     jButton1.setForeground(new java.awt.Color(254, 254, 254));
     jButton1.setText("Buscar");
     jButton1.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton1ActionPerformed(evt);
         }
     });

     jButton2.setBackground(new java.awt.Color(2, 135, 242));
     jButton2.setForeground(new java.awt.Color(254, 254, 254));
     jButton2.setText("Buscar");
     jButton2.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton2ActionPerformed(evt);
         }
     });

     jButton3.setBackground(new java.awt.Color(2, 135, 242));
     jButton3.setForeground(new java.awt.Color(254, 254, 254));
     jButton3.setText("Buscar");
     jButton3.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton3ActionPerformed(evt);
         }
     });

     t_np1.setEnabled(false);

     t_np2.setEnabled(false);

     t_np3.setEnabled(false);

     r_automatico.setText("almacenar automaticamente el costo mayor para cotizacin");

     javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
     jPanel1.setLayout(jPanel1Layout);
     jPanel1Layout.setHorizontalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel1Layout.createSequentialGroup()
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addGroup(jPanel1Layout.createSequentialGroup()
                     .addGap(268, 268, 268)
                     .addComponent(jLabel1))
                 .addGroup(jPanel1Layout.createSequentialGroup()
                     .addContainerGap()
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addComponent(jLabel4)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                             .addComponent(t_np3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                             .addComponent(jLabel3)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                             .addComponent(t_np2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                             .addComponent(jLabel2)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                             .addComponent(t_np1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addComponent(t_proveedor3, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                             .addComponent(jButton2))
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addComponent(t_proveedor2, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                             .addComponent(jButton3))
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addComponent(t_proveedor1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                             .addComponent(jButton1))))
                 .addGroup(jPanel1Layout.createSequentialGroup()
                     .addContainerGap()
                     .addComponent(r_automatico)))
             .addContainerGap(461, Short.MAX_VALUE))
     );
     jPanel1Layout.setVerticalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel1Layout.createSequentialGroup()
             .addContainerGap()
             .addComponent(jLabel1)
             .addGap(18, 18, 18)
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jLabel2)
                 .addComponent(t_proveedor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addComponent(jButton1)
                 .addComponent(t_np1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jLabel3)
                 .addComponent(t_proveedor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addComponent(jButton3)
                 .addComponent(t_np2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jLabel4)
                 .addComponent(t_proveedor3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addComponent(jButton2)
                 .addComponent(t_np3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
             .addComponent(r_automatico)
             .addContainerGap(105, Short.MAX_VALUE))
     );

     jTabbedPane1.addTab("", new ImageIcon("imagenes/file.png"), jPanel1);

     jPanel2.setBackground(new java.awt.Color(254, 254, 254));
     jPanel2.setLayout(new java.awt.BorderLayout());

     l_p1.setBackground(new java.awt.Color(90, 66, 0));
     l_p1.setText(" ");
     l_p1.setOpaque(true);

     l_proveedor1.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
     l_proveedor1.setText("Proveedor 1");

     l_proveedor2.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
     l_proveedor2.setText("Proveedor 2");

     l_p2.setBackground(new java.awt.Color(161, 169, 29));
     l_p2.setText(" ");
     l_p2.setOpaque(true);

     l_proveedor3.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
     l_proveedor3.setText("Proveedor 3");

     l_p3.setBackground(new java.awt.Color(26, 23, 52));
     l_p3.setText(" ");
     l_p3.setOpaque(true);

     javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
     jPanel4.setLayout(jPanel4Layout);
     jPanel4Layout.setHorizontalGroup(
         jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel4Layout.createSequentialGroup()
             .addContainerGap()
             .addComponent(l_p1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addComponent(l_proveedor1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
             .addComponent(l_p2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addComponent(l_proveedor2, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
             .addComponent(l_p3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addComponent(l_proveedor3, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addGap(68, 68, 68))
     );
     jPanel4Layout.setVerticalGroup(
         jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel4Layout.createSequentialGroup()
             .addGap(0, 0, Short.MAX_VALUE)
             .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(l_p1)
                 .addComponent(l_proveedor1)
                 .addComponent(l_p2)
                 .addComponent(l_proveedor2)
                 .addComponent(l_p3)
                 .addComponent(l_proveedor3)))
     );

     jPanel2.add(jPanel4, java.awt.BorderLayout.PAGE_START);

     scroll.setBackground(new java.awt.Color(254, 254, 254));
     scroll.setBorder(null);
     scroll.setPreferredSize(new java.awt.Dimension(453, 150));

     t_datos.setForeground(new java.awt.Color(102, 102, 102));
     t_datos.setModel(new javax.swing.table.DefaultTableModel(
         new Object [][] {
             {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
         },
         new String [] {
             "N", "#", "Cant", "Med", "Descripcin", "Autorizado", "Codigo", "Precio c/u ", "Plazo", "ok", "Cot", "Codigo", "Precio c/u", "Plazo", "ok", "Cot", "Codigo", "Precio c/u", "Plazo", "ok", "Cot"
         }
     ) {
         Class[] types = new Class [] {
             java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class
         };

     public Class getColumnClass(int columnIndex) {
             return types [columnIndex];
         }
     });
     t_datos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
     t_datos.setGridColor(new java.awt.Color(102, 102, 102));
     t_datos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
     t_datos.getTableHeader().setResizingAllowed(false);
     t_datos.getTableHeader().setReorderingAllowed(false);
     t_datos.addMouseListener(new java.awt.event.MouseAdapter() {
         public void mouseClicked(java.awt.event.MouseEvent evt) {
             t_datosMouseClicked(evt);
         }
     });
     t_datos.addFocusListener(new java.awt.event.FocusAdapter() {
         public void focusGained(java.awt.event.FocusEvent evt) {
             t_datosFocusGained(evt);
         }
     });
     scroll.setViewportView(t_datos);

     jPanel2.add(scroll, java.awt.BorderLayout.CENTER);

     jButton4.setBackground(new java.awt.Color(2, 135, 242));
     jButton4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
     jButton4.setForeground(new java.awt.Color(254, 254, 254));
     jButton4.setText("Generar");
     jButton4.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton4ActionPerformed(evt);
         }
     });

     jLabel5.setFont(new java.awt.Font("Arial", 1, 9)); // NOI18N
     jLabel5.setForeground(new java.awt.Color(90, 66, 126));
     jLabel5.setText("Facturar a:");

     t_empresa.setFont(new java.awt.Font("Arial", 0, 9)); // NOI18N
     t_empresa.setBorder(javax.swing.BorderFactory.createEtchedBorder());
     t_empresa.setEnabled(false);

     b_busca.setBackground(new java.awt.Color(2, 135, 242));
     b_busca.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
     b_busca.setIcon(new ImageIcon("imagenes/buscar.png"));
     b_busca.setToolTipText("Busca una partida");
     b_busca.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             b_buscaActionPerformed(evt);
         }
     });

     javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
     jPanel5.setLayout(jPanel5Layout);
     jPanel5Layout.setHorizontalGroup(
         jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel5Layout.createSequentialGroup()
             .addComponent(jLabel5)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addComponent(t_empresa, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addGap(2, 2, 2)
             .addComponent(b_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 849, Short.MAX_VALUE)
             .addComponent(jButton4)
             .addContainerGap())
     );
     jPanel5Layout.setVerticalGroup(
         jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jButton4)
         .addGroup(jPanel5Layout.createSequentialGroup()
             .addGap(10, 10, 10)
             .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(t_empresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)))
         .addGroup(jPanel5Layout.createSequentialGroup()
             .addGap(8, 8, 8)
             .addComponent(b_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
     );

     jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_END);

     jTabbedPane1.addTab("", new ImageIcon("imagenes/grafica.png"), jPanel2);

     add(jTabbedPane1, java.awt.BorderLayout.LINE_END);
 }// </editor-fold>//GEN-END:initComponents

     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         // TODO add your handling code here:
         h = new Herramientas(this.user, 0);
         h.session(sessionPrograma);
         javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
         jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));

         String ruta = null;
         if (jF1.showOpenDialog(this) == jF1.APPROVE_OPTION) {
             ruta = jF1.getSelectedFile().getAbsolutePath();
             if (ruta != null) {
                 File archivo1XLS = new File(ruta);
                 try {
                     FileInputStream archivo = new FileInputStream(archivo1XLS);
                     POIFSFileSystem fsFileSystem = new POIFSFileSystem(archivo);
                     libro1 = new HSSFWorkbook(fsFileSystem);
                     Sheet hoja = libro1.getSheetAt(0);
                     if (hoja.getRow(1).getCell(7).getStringCellValue().compareTo(orden) == 0) {
                         t_np1.setText(hoja.getRow(4).getCell(1).getStringCellValue());
                         t_proveedor1.setText(hoja.getRow(4).getCell(3).getStringCellValue());
                     } else {
                         t_np1.setText("");
                         t_proveedor1.setText("");
                         JOptionPane.showMessageDialog(this, "La cotizacin pertenece a la orden NO: '"
                                 + hoja.getRow(1).getCell(7).getStringCellValue() + "'");
                         libro1 = null;
                     }
                 } catch (Exception e) {
                     System.out.println(e);
                     e.printStackTrace();
                     t_proveedor1.setText("");
                     libro1 = null;
                     JOptionPane.showMessageDialog(this, "No se pudo abrir el archivo");
                 }
             }
         } else {
             t_proveedor1.setText("");
             libro1 = null;
         }
     }//GEN-LAST:event_jButton1ActionPerformed

     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
         // TODO add your handling code here:
         h = new Herramientas(this.user, 0);
         h.session(sessionPrograma);
         javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
         jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));

         String ruta = null;
         if (jF1.showOpenDialog(this) == jF1.APPROVE_OPTION) {
             ruta = jF1.getSelectedFile().getAbsolutePath();
             if (ruta != null) {
                 File archivo2XLS = new File(ruta);
                 try {
                     FileInputStream archivo2 = new FileInputStream(archivo2XLS);
                     POIFSFileSystem fsFileSystem2 = new POIFSFileSystem(archivo2);
                     libro2 = new HSSFWorkbook(fsFileSystem2);
                     Sheet hoja2 = libro2.getSheetAt(0);
                     if (hoja2.getRow(1).getCell(7).getStringCellValue().compareTo(orden) == 0) {
                         t_np2.setText(hoja2.getRow(4).getCell(1).getStringCellValue());
                         t_proveedor2.setText(hoja2.getRow(4).getCell(3).getStringCellValue());
                     } else {
                         t_np2.setText("");
                         t_proveedor2.setText("");
                         JOptionPane.showMessageDialog(this, "La cotizacin pertenece a la orden NO: '"
                                 + hoja2.getRow(1).getCell(7).getStringCellValue() + "'");
                         libro2 = null;
                     }
                 } catch (Exception e) {
                     System.out.println(e);
                     e.printStackTrace();
                     t_proveedor2.setText("");
                     libro2 = null;
                     JOptionPane.showMessageDialog(this, "No se pudo abrir el archivo");
                 }
             }
         } else {
             t_proveedor2.setText("");
             libro2 = null;
         }
     }//GEN-LAST:event_jButton3ActionPerformed

     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
         // TODO add your handling code here:
         h = new Herramientas(this.user, 0);
         h.session(sessionPrograma);
         javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
         jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));

         String ruta = null;
         if (jF1.showOpenDialog(this) == jF1.APPROVE_OPTION) {
             ruta = jF1.getSelectedFile().getAbsolutePath();
             if (ruta != null) {
                 File archivo3XLS = new File(ruta);
                 try {
                     FileInputStream archivo3 = new FileInputStream(archivo3XLS);
                     POIFSFileSystem fsFileSystem3 = new POIFSFileSystem(archivo3);
                     libro3 = new HSSFWorkbook(fsFileSystem3);
                     Sheet hoja3 = libro3.getSheetAt(0);
                     if (hoja3.getRow(1).getCell(7).getStringCellValue().compareTo(orden) == 0) {
                         t_np3.setText(hoja3.getRow(4).getCell(1).getStringCellValue());
                         t_proveedor3.setText(hoja3.getRow(4).getCell(3).getStringCellValue());
                     } else {
                         t_np3.setText("");
                         t_proveedor3.setText("");
                         JOptionPane.showMessageDialog(this, "La cotizacin pertenece a la orden NO: '"
                                 + hoja3.getRow(1).getCell(7).getStringCellValue() + "'");
                         libro3 = null;
                     }
                 } catch (Exception e) {
                     System.out.println(e);
                     e.printStackTrace();
                     t_proveedor3.setText("");
                     libro3 = null;
                     JOptionPane.showMessageDialog(this, "No se pudo abrir el archivo");
                 }
             }
         } else {
             t_proveedor3.setText("");
             libro3 = null;
         }
     }//GEN-LAST:event_jButton2ActionPerformed

     private void t_datosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_t_datosMouseClicked
         // TODO add your handling code here:
     }//GEN-LAST:event_t_datosMouseClicked

     private void t_datosFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_t_datosFocusGained
         // TODO add your handling code here:
     }//GEN-LAST:event_t_datosFocusGained

     private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
         if (jTabbedPane1.getSelectedIndex() == 1) {
             if (this.libro1 != null && this.libro2 != null || this.libro1 != null && this.libro3 != null
                     || this.libro2 != null && this.libro3 != null) {
                 CargaTabla();
                 if (this.r_automatico.isSelected() == true)
                     cotizacionAutomatico();
                 usrAut = null;
                 this.t_user.setText("");
                 this.t_clave.setText("");
             } else {
                 jTabbedPane1.setSelectedIndex(0);
                 JOptionPane.showMessageDialog(this, "Ingrese almenos 2 cotizaciones");
             }
         }
     }//GEN-LAST:event_jTabbedPane1StateChanged

     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
         boolean edo = true;
         int col = 9;
         if (t_empresa.getText().compareTo("") != 0) {
             if (consultaLista() == true) {
                 if (session.isOpen())
                     session.close();
                 session = HibernateUtil.getSessionFactory().openSession();
                 session.beginTransaction().begin();
                 id_pedido = new ArrayList();
                 for (int p = 0; p < this.NoProveedor.size(); p++) {
                     edo = generaPedido(Integer.parseInt(NoProveedor.get(p).toString()), col);
                     col += 5;
                     if (edo == false) {
                         p = this.NoProveedor.size();
                         session.beginTransaction().rollback();
                         JOptionPane.showMessageDialog(this, "Error al generar los pedidos");
                     }
                 }
                 if (edo == true) {
                     session.beginTransaction().commit();
                     if (id_pedido.size() > 0) {
                         envia();
                         t_pedidos.setModel(ModeloTablaPedidos(id_pedido.size(), colPedidos));
                         for (int i = 0; i < id_pedido.size(); i++) {
                             List Part = (List) id_pedido.get(i);
                             modeloPedidos.setValueAt((Integer) Part.get(0), i, 0);
                             modeloPedidos.setValueAt((String) Part.get(1), i, 1);
                             modeloPedidos.setValueAt(Part.get(2), i, 2);
                         }
                         CargaTabla();
                         usrAut = null;
                         this.t_user.setText("");
                         this.t_clave.setText("");
                         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                         listaPedidos.setSize(400, 276);
                         listaPedidos.setLocation((d.width / 2) - (listaPedidos.getWidth() / 2),
                                 (d.height / 2) - (listaPedidos.getHeight() / 2));
                         listaPedidos.setVisible(true);
                     } else
                         JOptionPane.showMessageDialog(this, "No se genero ningun pedido!");

                 }
                 if (session.isOpen())
                     session.close();
             } else
                 JOptionPane.showMessageDialog(null,
                         "No se puede almacenar ya que una partida contiene 0 unudades a pedir");
         } else {
             JOptionPane.showMessageDialog(this, "Falta ingresar a quien se va a facturar!");
             b_busca.requestFocus();
         }
     }//GEN-LAST:event_jButton4ActionPerformed

     private void b_buscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_buscaActionPerformed
         // TODO add your handling code here:
         h = new Herramientas(user, 0);
         h.session(sessionPrograma);
         if (user.getGeneraPedidos() == true) {
             buscaProveedor obj = new buscaProveedor(new javax.swing.JFrame(), true, this.user,
                     this.sessionPrograma);
             obj.t_busca.requestFocus();
             Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
             obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
             obj.setVisible(true);

             Proveedor prov = obj.getReturnStatus();
             if (prov != null) {
                 t_empresa.setText("" + prov.getIdProveedor());
             } else {
                 t_empresa.setText("");
             }
         } else {
             JOptionPane.showMessageDialog(null, "Acceso denegado!");
         }
     }//GEN-LAST:event_b_buscaActionPerformed

     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
         // TODO add your handling code here:
         if (t_pedidos.getSelectedRow() > -1) {
             f1 = new Formatos(this.user, this.sessionPrograma, this.ord,
                     t_pedidos.getValueAt(t_pedidos.getSelectedRow(), 0).toString());
             f1.pedidos();
         } else {
             JOptionPane.showMessageDialog(this, "Seleccione primero un pedido de la lista!");
         }
     }//GEN-LAST:event_jButton6ActionPerformed

     private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
         // TODO add your handling code here:
         if (t_pedidos.getSelectedRow() > -1) {
             f1 = new Formatos(this.user, this.sessionPrograma, this.ord,
                     t_pedidos.getValueAt(t_pedidos.getSelectedRow(), 0).toString());
             f1.ordenCompra();
         } else {
             JOptionPane.showMessageDialog(this, "Seleccione primero un pedido de la lista!");
         }
     }//GEN-LAST:event_jButton7ActionPerformed

     private void t_userActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_userActionPerformed
         // TODO add your handling code here:
         t_clave.requestFocus();
     }//GEN-LAST:event_t_userActionPerformed

     private void b_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_aceptarActionPerformed
         if (t_user.getText().compareTo("") != 0) {
             if (t_clave.getPassword().toString().compareTo("") != 0) {
                 session = HibernateUtil.getSessionFactory().openSession();
                 try {
                     session.beginTransaction().begin();
                     Usuario autoriza = (Usuario) session.createCriteria(Usuario.class)
                             .add(Restrictions.eq("idUsuario", t_user.getText()))
                             .add(Restrictions.eq("clave", t_clave.getText())).setMaxResults(1).uniqueResult();
                     if (autoriza != null) {
                         if (autoriza.getAutorizarSobrecosto() == true) {
                             usrAut = autoriza;
                             autorizarCosto.dispose();
                         } else
                             JOptionPane.showMessageDialog(this, "el usuario no tiene permiso de autorizar!");
                     } else {
                         session.beginTransaction().rollback();
                         JOptionPane.showMessageDialog(this, "Datos incorrectos!");
                     }
                 } catch (Exception e) {
                     session.beginTransaction().rollback();
                     JOptionPane.showMessageDialog(this, "Error al consultar los datos!");
                     e.printStackTrace();
                 } finally {
                     if (session.isOpen() == true)
                         session.close();
                 }
             } else
                 JOptionPane.showMessageDialog(this, "Ingrese la contrasea!");
         } else
             JOptionPane.showMessageDialog(this, "Ingrese el Usiario!");
     }//GEN-LAST:event_b_aceptarActionPerformed

     private void t_claveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_claveActionPerformed
         b_aceptar.requestFocus();
     }//GEN-LAST:event_t_claveActionPerformed

     boolean generaPedido(int np, int col) {
         if (marcado(col) == true) {
             try {
                 Date fechaCotizacion = new Date();
                 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
                 String valor = dateFormat.format(fechaCotizacion);
                 String[] fecha = valor.split("-");
                 String[] hora = fecha[2].split(":");
                 String[] aux = hora[0].split(" ");
                 fecha[2] = aux[0];
                 hora[0] = aux[1];
                 Calendar calendario = Calendar.getInstance();
                 calendario.set(Integer.parseInt(fecha[2]), Integer.parseInt(fecha[1]) - 1,
                         Integer.parseInt(fecha[0]), Integer.parseInt(hora[0]), Integer.parseInt(hora[1]),
                         Integer.parseInt(hora[2]));

                 //session = HibernateUtil.getSessionFactory().openSession();
                 //session.beginTransaction().begin();
                 Pedido registroNuevo = new Pedido();
                 Proveedor prov = (Proveedor) session.get(Proveedor.class, np);
                 Proveedor emp = (Proveedor) session.get(Proveedor.class, Integer.parseInt(t_empresa.getText()));
                 registroNuevo.setProveedorByIdProveedor(prov);
                 registroNuevo.setProveedorByIdEmpresa(emp);
                 registroNuevo.setUsuarioByIdUsuario(user);
                 registroNuevo.setFechaPedido(calendario.getTime());
                 registroNuevo.setTipoPedido("Interno");

                 List vec = new ArrayList();
                 vec.add((int) session.save(registroNuevo));
                 vec.add(prov.getNombre());
                 vec.add(calendario.getTime());
                 id_pedido.add(vec);

                 for (int r = 0; r < t_datos.getRowCount(); r++) {
                     if ((boolean) t_datos.getValueAt(r, col) == true) {
                         Partida part = (Partida) session.createCriteria(Partida.class)
                                 .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                                 .add(Restrictions.eq("idEvaluacion",
                                         Integer.parseInt(t_datos.getValueAt(r, 0).toString())))
                                 .add(Restrictions.eq("subPartida",
                                         Integer.parseInt(t_datos.getValueAt(r, 1).toString())))
                                 .setMaxResults(1).uniqueResult();
                         part.setPedido(registroNuevo);
                         part.setPcp((double) t_datos.getValueAt(r, col - 2));
                         if (part.getPcp() > part.getPrecioAutCU()) {
                             usrAut = (Usuario) session.get(Usuario.class, usrAut.getIdUsuario());
                             part.setUsuario(usrAut);
                         }
                         part.setCantPcp((Double) t_datos.getValueAt(r, 2));
                         if (t_datos.getValueAt(r, col - 3).toString().compareTo("") != 0) {
                             if (part.getEjemplar() != null) {
                                 if (part.getEjemplar().getIdParte()
                                         .compareTo(t_datos.getValueAt(r, col - 3).toString()) != 0) {
                                     Ejemplar ej = (Ejemplar) session.get(Ejemplar.class,
                                             t_datos.getValueAt(r, col - 3).toString());
                                     if (ej == null) {
                                         ord = (Orden) session.get(Orden.class, ord.getIdOrden());
                                         ej = new Ejemplar();
                                         ej.setIdParte(t_datos.getValueAt(r, col - 3).toString());
                                         ej.setMarca(ord.getMarca());
                                         ej.setTipo(ord.getTipo());
                                         ej.setModelo(ord.getModelo());
                                         ej.setCatalogo(part.getCatalogo().getNombre());
                                         //ej.addPartida(part);
                                         session.save(part);
                                         part.setEjemplar(ej);
                                     } else
                                         part.setEjemplar(ej);
                                 }
                             } else {
                                 Ejemplar ej = (Ejemplar) session.get(Ejemplar.class,
                                         t_datos.getValueAt(r, col - 3).toString());
                                 if (ej == null) {
                                     ord = (Orden) session.get(Orden.class, ord.getIdOrden());
                                     ej = new Ejemplar();
                                     ej.setIdParte(t_datos.getValueAt(r, col - 3).toString());
                                     ej.setMarca(ord.getMarca());
                                     ej.setTipo(ord.getTipo());
                                     ej.setModelo(ord.getModelo());
                                     ej.setCatalogo(part.getCatalogo().getNombre());
                                     //ej.addPartida(part);
                                     session.save(part);
                                     part.setEjemplar(ej);
                                 } else
                                     part.setEjemplar(ej);
                             }
                         }
                         session.update(part);
                     }
                 }
             } catch (Exception e) {
                 e.printStackTrace();
                 //System.out.println(e);
                 return false;
             }
         }
         return true;
     }

     boolean marcado(int col) {
         try {
             for (int r = 0; r < t_datos.getRowCount(); r++) {
                 if ((boolean) t_datos.getValueAt(r, col) == true)
                     return true;
             }
             return false;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
         }
     }

     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JDialog autorizarCosto;
     private javax.swing.JButton b_aceptar;
     private javax.swing.JButton b_busca;
     private javax.swing.JButton jButton1;
     private javax.swing.JButton jButton2;
     private javax.swing.JButton jButton3;
     private javax.swing.JButton jButton4;
     private javax.swing.JButton jButton6;
     private javax.swing.JButton jButton7;
     private javax.swing.JLabel jLabel1;
     private javax.swing.JLabel jLabel11;
     private javax.swing.JLabel jLabel12;
     private javax.swing.JLabel jLabel14;
     private javax.swing.JLabel jLabel2;
     private javax.swing.JLabel jLabel3;
     private javax.swing.JLabel jLabel4;
     private javax.swing.JLabel jLabel5;
     private javax.swing.JLabel jLabel7;
     private javax.swing.JLabel jLabel9;
     private javax.swing.JPanel jPanel1;
     private javax.swing.JPanel jPanel2;
     private javax.swing.JPanel jPanel4;
     private javax.swing.JPanel jPanel5;
     private javax.swing.JPanel jPanel6;
     private javax.swing.JPanel jPanel7;
     private javax.swing.JPanel jPanel9;
     private javax.swing.JScrollPane jScrollPane3;
     private javax.swing.JTabbedPane jTabbedPane1;
     private javax.swing.JLabel l_p1;
     private javax.swing.JLabel l_p2;
     private javax.swing.JLabel l_p3;
     private javax.swing.JLabel l_proveedor1;
     private javax.swing.JLabel l_proveedor2;
     private javax.swing.JLabel l_proveedor3;
     private javax.swing.JDialog listaPedidos;
     private javax.swing.JRadioButton r_automatico;
     private javax.swing.JScrollPane scroll;
     private javax.swing.JPasswordField t_clave;
     private javax.swing.JTable t_datos;
     private javax.swing.JTextField t_empresa;
     private javax.swing.JTextField t_np1;
     private javax.swing.JTextField t_np2;
     private javax.swing.JTextField t_np3;
     private javax.swing.JTable t_pedidos;
     private javax.swing.JTextField t_proveedor1;
     private javax.swing.JTextField t_proveedor2;
     private javax.swing.JTextField t_proveedor3;
     private javax.swing.JTextField t_proveedor6;
     private javax.swing.JTextField t_user;
     // End of variables declaration//GEN-END:variables

 public void tabla_tamaos()
{
     TableColumnModel col_model = t_datos.getColumnModel();
     DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
     tcr.setHorizontalAlignment(SwingConstants.RIGHT);

     for (int i=0; i<t_datos.getColumnCount(); i++)
     {
        TableColumn column = col_model.getColumn(i);
           switch(i)
           {
               case 0://N
                   column.setPreferredWidth(45);
                   //column.setCellRenderer(tcr);
                   break;
               case 1://#
                   column.setPreferredWidth(35);
                   //column.setCellRenderer(tcr);
                   break;
               case 2://Cant
                   column.setPreferredWidth(40);
                   break;
               case 3://Medida
                   column.setPreferredWidth(50);
                   break;
               case 4://Descripcion
                   column.setPreferredWidth(250);
                   break;
               case 5://Autorizado
                   column.setPreferredWidth(70);
                   break;
               case 6://Codigo   P1
                   column.setPreferredWidth(70);
                   break;
               case 7://c/u      P1
                   column.setPreferredWidth(70);
                   break;
               case 8://Plazo    P1
                   column.setPreferredWidth(35);
                   break;
               case 9://Ok       P1
                   column.setPreferredWidth(10);
                   break;
               case 10://Cot     P1
                   column.setPreferredWidth(10);
                   break;
               case 11://Codigo   P2
                   column.setPreferredWidth(70);
                   break;
               case 12://c/u     P2
                   column.setPreferredWidth(70);
                   break;
               case 13://Plazo   P2
                   column.setPreferredWidth(35);
                   break;
               case 14://ok      P2
                   column.setPreferredWidth(10);
                   break;
               case 15://Cot     P3
                   column.setPreferredWidth(10);
                   break;
               case 16://Codigo  P3
                   column.setPreferredWidth(70);
                   break;
               case 17://c/u     P3
                   column.setPreferredWidth(70);
                   break;
               case 18://Plazo   P3
                   column.setPreferredWidth(35);
                   break;
               case 19://Ok      P3
                   column.setPreferredWidth(10);
                   break;
               case 20://Ok      P3
                   column.setPreferredWidth(10);
                   break;
               default:
                   column.setPreferredWidth(21);
                   break;
           }
     }
     JTableHeader header = t_datos.getTableHeader();
     header.setForeground(Color.white);
}

 public void formatoTabla(List colores)
 {
     Color c1 = new java.awt.Color(2, 135, 242);
     for(int x=0; x<t_datos.getColumnModel().getColumnCount(); x++)
     {
         if( x>-1 && x<=5)
             t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1(c1));
         if( x>=6 && x<=10)
             t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1((Color)colores.get(0)));
         if( x>=11 && x<=15)
             t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1((Color)colores.get(1)));
         if(x>=16 && x<=20)
             t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1((Color)colores.get(2)));
     }
     tabla_tamaos();
     t_datos.setShowVerticalLines(true);
     t_datos.setShowHorizontalLines(true);
        
     FormatoEditor fe=new FormatoEditor();
     t_datos.setDefaultEditor(Double.class, fe);
        
     t_datos.setDefaultRenderer(Double.class, formato); 
     t_datos.setDefaultRenderer(Integer.class, formato);
     t_datos.setDefaultRenderer(String.class, formato);
     t_datos.setDefaultRenderer(Boolean.class, formato);
 }

     public class MyModel extends DefaultTableModel {
         Class[] types;
         int ren = 0;
         int col = 0;
         private boolean[][] celdaEditable;

         public MyModel(int renglones, String columnas[], Class[] tipos) {
             types = tipos;
             ren = renglones;
             col = columnas.length;
             celdaEditable = new boolean[types.length][renglones];
             for (int x = 0; x < types.length; x++) {
                 for (int y = 0; y < renglones; y++) {
                     celdaEditable[x][y] = false;
                 }
             }
             this.setDataVector(new Object[renglones][columnas.length], columnas);
         }

         @Override
         public int getRowCount() {
             return ren;
         }

         @Override
         public int getColumnCount() {
             return col;
         }

         @Override
         public void setValueAt(Object value, int row, int col) {
             Vector vector = (Vector) this.dataVector.elementAt(row);
             Object celda = ((Vector) this.dataVector.elementAt(row)).elementAt(col);
             switch (col) {
             case 2:
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     session = HibernateUtil.getSessionFactory().openSession();
                     session.beginTransaction().begin();
                     Partida part = (Partida) session.createCriteria(Partida.class)
                             .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                             .add(Restrictions.eq("idEvaluacion",
                                     Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString())))
                             .add(Restrictions.eq("subPartida",
                                     Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString())))
                             .setMaxResults(1).uniqueResult();
                     double cant = part.getCantidadAut();
                     session.beginTransaction().rollback();
                     session.close();
                     if (cant >= (double) value) {
                         vector.setElementAt(value, col);
                         this.dataVector.setElementAt(vector, row);
                         fireTableCellUpdated(row, col);
                     } else
                         JOptionPane.showMessageDialog(null, "La Cantidad mayor autorizada es de: " + cant);
                 }
                 break;

             case 9:
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         if ((double) t_datos.getValueAt(row, 5) < (double) t_datos.getValueAt(row, 7)
                                 && usrAut == null) {
                             Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                             autorizarCosto.setSize(284, 177);
                             autorizarCosto.setLocation((d.width / 2) - (autorizarCosto.getWidth() / 2),
                                     (d.height / 2) - (autorizarCosto.getHeight() / 2));
                             t_user.setText("");
                             t_clave.setText("");
                             autorizarCosto.setVisible(true);
                             if (usrAut != null) {
                                 vector.setElementAt(value, col);
                                 t_datos.setValueAt(false, row, 14);
                                 if (t_datos.getColumnCount() == 21)
                                     t_datos.setValueAt(false, row, 19);
                             }
                         } else {
                             vector.setElementAt(value, col);
                             t_datos.setValueAt(false, row, 14);
                             if (t_datos.getColumnCount() == 21)
                                 t_datos.setValueAt(false, row, 19);
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             case 10://importar el precio de cotizacion proveedor 1
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         h = new Herramientas(user, 0);
                         h.session(sessionPrograma);
                         session = HibernateUtil.getSessionFactory().openSession();
                         try {
                             session.flush();
                             session.beginTransaction().begin();
                             user = (Usuario) session.get(Usuario.class, user.getIdUsuario());
                             if (user.getEditaPrecioCu() == true) {
                                 Partida part = (Partida) session.createCriteria(Partida.class)
                                         .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                                         .add(Restrictions.eq("idEvaluacion",
                                                 Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0)
                                                         .toString())))
                                         .add(Restrictions.eq("subPartida", Integer.parseInt(
                                                 t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString())))
                                         .setMaxResults(1).uniqueResult();
                                 part.setCU((double) t_datos.getValueAt(row, 7));
                                 double aut = 0.0 + Math.round(part.getCU() / (1 - (part.getPorcentaje() * 0.01)));
                                 part.setPrecioAutCU(aut);
                                 part.setPrecioCiaSegurosCU(part.getPrecioAutCU());
                                 part.setPrecioFactura(part.getPrecioAutCU());
                                 session.update(part);
                                 session.beginTransaction().commit();
                                 vector.setElementAt(value, col);
                                 t_datos.setValueAt(aut, row, 5);
                                 t_datos.setValueAt(false, row, 15);
                                 if (t_datos.getColumnCount() == 21)
                                     t_datos.setValueAt(false, row, 20);
                             }
                         } catch (HibernateException | NumberFormatException e) {
                             JOptionPane.showMessageDialog(null, "Error al actualizar precio cotizacin:=" + e);
                         } finally {
                             if (session.isOpen())
                                 session.close();
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             case 14:
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         if ((double) t_datos.getValueAt(row, 5) < (double) t_datos.getValueAt(row, 12)
                                 && usrAut == null) {
                             Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                             autorizarCosto.setSize(284, 177);
                             autorizarCosto.setLocation((d.width / 2) - (autorizarCosto.getWidth() / 2),
                                     (d.height / 2) - (autorizarCosto.getHeight() / 2));
                             t_user.setText("");
                             t_clave.setText("");
                             autorizarCosto.setVisible(true);
                             if (usrAut != null) {
                                 t_datos.setValueAt(false, row, 9);
                                 vector.setElementAt(value, col);
                                 if (t_datos.getColumnCount() == 21)
                                     t_datos.setValueAt(false, row, 19);
                             }
                         } else {
                             t_datos.setValueAt(false, row, 9);
                             vector.setElementAt(value, col);
                             if (t_datos.getColumnCount() == 21)
                                 t_datos.setValueAt(false, row, 19);
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             case 15://importar el precio de cotizacion proveedor 2
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         h = new Herramientas(user, 0);
                         h.session(sessionPrograma);
                         session = HibernateUtil.getSessionFactory().openSession();
                         try {
                             session.beginTransaction().begin();
                             user = (Usuario) session.get(Usuario.class, user.getIdUsuario());
                             if (user.getEditaPrecioCu() == true) {
                                 Partida part = (Partida) session.createCriteria(Partida.class)
                                         .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                                         .add(Restrictions.eq("idEvaluacion",
                                                 Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0)
                                                         .toString())))
                                         .add(Restrictions.eq("subPartida", Integer.parseInt(
                                                 t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString())))
                                         .setMaxResults(1).uniqueResult();
                                 part.setCU((double) t_datos.getValueAt(row, 12));
                                 double aut = 0.0 + Math.round(part.getCU() / (1 - (part.getPorcentaje() * 0.01)));
                                 part.setPrecioAutCU(aut);
                                 part.setPrecioCiaSegurosCU(part.getPrecioAutCU());
                                 part.setPrecioFactura(part.getPrecioAutCU());
                                 session.update(part);
                                 session.beginTransaction().commit();
                                 vector.setElementAt(value, col);
                                 t_datos.setValueAt(aut, row, 5);
                                 t_datos.setValueAt(false, row, 10);
                                 if (t_datos.getColumnCount() == 21)
                                     t_datos.setValueAt(false, row, 20);
                             }
                         } catch (HibernateException | NumberFormatException e) {
                             JOptionPane.showMessageDialog(null, "Error al actualizar precio cotizacin:=" + e);
                         } finally {
                             if (session.isOpen())
                                 session.close();
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             case 19:
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         if ((double) t_datos.getValueAt(row, 5) < (double) t_datos.getValueAt(row, 17)
                                 && usrAut == null) {
                             Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                             autorizarCosto.setSize(284, 177);
                             autorizarCosto.setLocation((d.width / 2) - (autorizarCosto.getWidth() / 2),
                                     (d.height / 2) - (autorizarCosto.getHeight() / 2));
                             t_user.setText("");
                             t_clave.setText("");
                             autorizarCosto.setVisible(true);
                             if (usrAut != null) {
                                 t_datos.setValueAt(false, row, 9);
                                 t_datos.setValueAt(false, row, 14);
                                 vector.setElementAt(value, col);
                             }
                         } else {
                             t_datos.setValueAt(false, row, 9);
                             t_datos.setValueAt(false, row, 14);
                             vector.setElementAt(value, col);
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             case 20://importar el precio de cotizacion proveedor 3
                 if (vector.get(col) == null) {
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 } else {
                     if ((boolean) value == true) {
                         h = new Herramientas(user, 0);
                         h.session(sessionPrograma);
                         session = HibernateUtil.getSessionFactory().openSession();
                         try {
                             session.beginTransaction().begin();
                             user = (Usuario) session.get(Usuario.class, user.getIdUsuario());
                             if (user.getEditaPrecioCu() == true) {
                                 Partida part = (Partida) session.createCriteria(Partida.class)
                                         .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                                         .add(Restrictions.eq("idEvaluacion",
                                                 Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0)
                                                         .toString())))
                                         .add(Restrictions.eq("subPartida", Integer.parseInt(
                                                 t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString())))
                                         .setMaxResults(1).uniqueResult();
                                 part.setCU((double) t_datos.getValueAt(row, 17));
                                 double aut = 0.0 + Math.round(part.getCU() / (1 - (part.getPorcentaje() * 0.01)));
                                 part.setPrecioAutCU(aut);
                                 part.setPrecioCiaSegurosCU(part.getPrecioAutCU());
                                 part.setPrecioFactura(part.getPrecioAutCU());
                                 session.update(part);
                                 session.beginTransaction().commit();
                                 vector.setElementAt(value, col);
                                 t_datos.setValueAt(aut, row, 5);
                                 t_datos.setValueAt(false, row, 10);
                                 t_datos.setValueAt(false, row, 15);
                             }
                         } catch (HibernateException | NumberFormatException e) {
                             JOptionPane.showMessageDialog(null, "Error al actualizar precio cotizacin:=" + e);
                         } finally {
                             if (session.isOpen())
                                 session.close();
                         }
                     } else
                         vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                 }
                 break;

             default:
                 vector.setElementAt(value, col);
                 this.dataVector.setElementAt(vector, row);
                 fireTableCellUpdated(row, col);
                 break;
             }
         }

         public Class getColumnClass(int columnIndex) {
             return types[columnIndex];
         }

         public boolean isCellEditable(int rowIndex, int columnIndex) {
             return this.celdaEditable[columnIndex][rowIndex];
         }

         public void setCeldaEditable(int fila, int columna, boolean editable) {
             this.celdaEditable[columna][fila] = editable;
         }

         public void setColumnaEditable(int columna, boolean editable) {
             int i = 0;
             int cantidadFilas = this.getRowCount();
             for (i = 0; i < celdaEditable[columna].length; i++)
                 this.celdaEditable[columna][i] = editable;
         }

     }

     void buscaPartidas() {
         if (ord != null) {
             session = HibernateUtil.getSessionFactory().openSession();
             try {
                 session.beginTransaction().begin();
                 ord = (Orden) session.get(Orden.class, ord.getIdOrden());
                 Partida[] cuentas = (Partida[]) session.createCriteria(Partida.class)
                         .add(Restrictions.eq("ordenByIdOrden.idOrden", Integer.parseInt(orden)))
                         .add(Restrictions.eq("autorizadoValuacion", true)).add(Restrictions.eq("refComp", true))
                         .add(Restrictions.isNull("pedido")).addOrder(Order.asc("idEvaluacion"))
                         .addOrder(Order.asc("subPartida")).list().toArray(new Partida[0]);
                 if (cuentas.length > 0) {
                     model = new MyModel(cuentas.length, (String[]) columnas.toArray(new String[0]),
                             (Class[]) tipos.toArray(new Class[0]));
                     t_datos.setModel(model);

                     for (int i = 0; i < cuentas.length; i++) {
                         model.setValueAt(cuentas[i].getIdEvaluacion(), i, 0);
                         model.setValueAt(cuentas[i].getSubPartida(), i, 1);
                         model.setValueAt(cuentas[i].getCantidadAut(), i, 2);
                         model.setCeldaEditable(i, 2, true);
                         model.setValueAt(cuentas[i].getMed(), i, 3);
                         model.setValueAt(cuentas[i].getCatalogo().getNombre(), i, 4);
                         model.setValueAt(cuentas[i].getPrecioAutCU(), i, 5);

                         model.setValueAt(false, i, 9);
                         model.setValueAt(false, i, 10);
                         model.setValueAt(false, i, 14);
                         model.setValueAt(false, i, 15);
                         if (model.getColumnCount() == 21) {
                             model.setValueAt(false, i, 19);
                             model.setValueAt(false, i, 20);
                         }
                     }
                 } else {
                     model = new MyModel(0, (String[]) columnas.toArray(new String[0]),
                             (Class[]) tipos.toArray(new Class[0]));
                     t_datos.setModel(model);
                 }
             } catch (Exception e) {
                 e.printStackTrace();
             } finally {
                 if (session.isOpen())
                     session.close();
             }
         }
     }

     void importaDatos(Workbook wb, int col) {
         Sheet hoja = wb.getSheetAt(0);
         Iterator rowIterator = hoja.rowIterator();
         List renglones = new ArrayList();
         while (rowIterator.hasNext()) {
             HSSFRow hssfRow = (HSSFRow) rowIterator.next();
             List celdas = new ArrayList();
             Iterator iterator = hssfRow.cellIterator();
             while (iterator.hasNext()) {
                 HSSFCell hssfCell = (HSSFCell) iterator.next();
                 celdas.add(hssfCell);
             }
             renglones.add(celdas);
         }
         for (int r = 8; r < renglones.size(); r++) {
             List aux = (List) renglones.get(r);
             HSSFCell auxCell = (HSSFCell) aux.get(0);
             HSSFCell auxCell1 = (HSSFCell) aux.get(1);
             int res = busca(auxCell.getNumericCellValue(), auxCell1.getNumericCellValue());
             if (res != -1) {
                 for (int c = 0; c < aux.size(); c++) {
                     HSSFCell valor = (HSSFCell) aux.get(c);

                     switch (valor.getColumnIndex()) {
                     case 4:
                         switch (valor.getCellType()) {
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
                             t_datos.setValueAt((int) valor.getNumericCellValue(), res, col);
                             break;
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
                             t_datos.setValueAt(valor.getStringCellValue(), res, col);
                             break;
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK:
                             t_datos.setValueAt("", res, col);
                             break;
                         default:
                             t_datos.setValueAt("", res, col);
                             break;
                         }
                         break;

                     case 7:
                         switch (valor.getCellType()) {
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
                             t_datos.setValueAt(valor.getNumericCellValue(), res, col + 1);
                             break;
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
                             t_datos.setValueAt(valor.getStringCellValue(), res, col + 1);
                             break;
                         default:
                             t_datos.setValueAt("", res, col + 1);
                             break;
                         }
                         if (t_datos.getValueAt(res, col + 1).toString().compareTo("") != 0) {
                             model.setCeldaEditable(res, col + 3, true);
                             model.setCeldaEditable(res, col + 4, true);
                         }
                         break;

                     case 10:
                         switch (valor.getCellType()) {
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
                             t_datos.setValueAt((int) valor.getNumericCellValue(), res, col + 2);
                             break;
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
                             t_datos.setValueAt(valor.getStringCellValue(), res, col + 2);
                             break;
                         default:
                             t_datos.setValueAt("", res, col + 2);
                             break;
                         }
                         break;
                     }
                     t_datos.setValueAt(false, res, col + 3);
                     t_datos.setValueAt(false, res, col + 4);
                 }
             }
         }
     }

     int busca(double part, double sub) {
         for (int r = 0; r < t_datos.getRowCount(); r++) {
             if (Double.parseDouble(t_datos.getValueAt(r, 0).toString()) == part
                     && Double.parseDouble(t_datos.getValueAt(r, 1).toString()) == sub) {
                 return r;
             }
         }
         return -1;
     }

     DefaultTableModel ModeloTablaPedidos(int renglones, String columnas[]) {
         modeloPedidos = new DefaultTableModel(new Object[renglones][2], columnas) {
             Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                     java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                     java.lang.String.class };
             boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, };

             public void setValueAt(Object value, int row, int col) {
                 Vector vector = (Vector) this.dataVector.elementAt(row);
                 Object celda = ((Vector) this.dataVector.elementAt(row)).elementAt(col);
                 switch (col) {
                 case 0:
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                     break;

                 default:
                     vector.setElementAt(value, col);
                     this.dataVector.setElementAt(vector, row);
                     fireTableCellUpdated(row, col);
                     break;
                 }
             }

             public Class getColumnClass(int columnIndex) {
                 return types[columnIndex];
             }

             public boolean isCellEditable(int rowIndex, int columnIndex) {
                 return canEdit[columnIndex];
             }
         };
         return modeloPedidos;
     }

     void CargaTabla() {
         NoProveedor = new ArrayList();
         if (t_np1.getText().compareTo("") != 0)
             NoProveedor.add(t_np1.getText());
         if (t_np2.getText().compareTo("") != 0)
             NoProveedor.add(t_np2.getText());
         if (t_np3.getText().compareTo("") != 0)
             NoProveedor.add(t_np3.getText());
         columnas = new ArrayList();
         columnas.add("N");
         columnas.add("#");
         columnas.add("Cant");
         columnas.add("Med");
         columnas.add("Descripcin");
         columnas.add("Autorizado");

         tipos = new ArrayList();
         tipos.add(java.lang.String.class);
         tipos.add(java.lang.String.class);
         tipos.add(java.lang.Double.class);
         tipos.add(java.lang.String.class);
         tipos.add(java.lang.String.class);
         tipos.add(java.lang.Double.class);
         List colores = new ArrayList();
         if (this.libro1 != null) {
             l_p1.setVisible(true);
             l_proveedor1.setVisible(true);
             l_proveedor1.setText(t_proveedor1.getText());
             columnas.add("Codigo");
             columnas.add("Precio c/u");
             columnas.add("Plazo");
             columnas.add("ok");
             columnas.add("Cot");
             colores.add(new java.awt.Color(90, 66, 0));

             tipos.add(java.lang.String.class);
             tipos.add(java.lang.Double.class);
             tipos.add(java.lang.Integer.class);
             tipos.add(java.lang.Boolean.class);
             tipos.add(java.lang.Boolean.class);
         } else {
             l_p1.setVisible(false);
             l_proveedor1.setVisible(false);
         }

         if (this.libro2 != null) {
             l_p2.setVisible(true);
             l_proveedor2.setVisible(true);
             l_proveedor2.setText(t_proveedor2.getText());
             columnas.add("Codigo");
             columnas.add("Precio c/u");
             columnas.add("Plazo");
             columnas.add("ok");
             columnas.add("Cot");
             colores.add(new java.awt.Color(161, 169, 29));

             tipos.add(java.lang.String.class);
             tipos.add(java.lang.Double.class);
             tipos.add(java.lang.Integer.class);
             tipos.add(java.lang.Boolean.class);
             tipos.add(java.lang.Boolean.class);
         } else {
             l_p2.setVisible(false);
             l_proveedor2.setVisible(false);
         }

         if (this.libro3 != null) {
             l_p3.setVisible(true);
             l_proveedor3.setVisible(true);
             l_proveedor3.setText(t_proveedor3.getText());
             columnas.add("Codigo");
             columnas.add("Precio c/u");
             columnas.add("Plazo");
             columnas.add("ok");
             columnas.add("Cot");
             colores.add(new java.awt.Color(26, 23, 52));

             tipos.add(java.lang.String.class);
             tipos.add(java.lang.Double.class);
             tipos.add(java.lang.Integer.class);
             tipos.add(java.lang.Boolean.class);
             tipos.add(java.lang.Boolean.class);
         } else {
             l_p3.setVisible(false);
             l_proveedor3.setVisible(false);
         }
         buscaPartidas();
         int var = 6;
         if (this.libro1 != null) {
             importaDatos(libro1, var);
             var += 5;
         }
         if (this.libro2 != null) {
             importaDatos(libro2, var);
             var += 5;
         }
         if (this.libro3 != null) {
             importaDatos(libro3, var);
         }
         formatoTabla(colores);
     }

     public void cotizacionAutomatico() {
         for (int r = 0; r < t_datos.getRowCount(); r++) {
             double p1 = 0.0d, p2 = 0.0d, p3 = 0.0d, mayor = 0.0d;
             if (t_datos.getValueAt(r, 7) != null)
                 p1 = (double) t_datos.getValueAt(r, 7);
             if (t_datos.getValueAt(r, 12) != null)
                 p2 = (double) t_datos.getValueAt(r, 12);
             if (t_datos.getColumnCount() == 21)
                 if (t_datos.getValueAt(r, 17) != null)
                     p3 = (double) t_datos.getValueAt(r, 17);
             if ((p1 > p2 && p1 > p3) || (p1 == p2 && p1 > p3) || (p1 > p2 && p1 == p3)) {
                 t_datos.setRowSelectionInterval(r, r);
                 t_datos.setValueAt(true, r, 10);
             }
             if ((p2 > p1 && p2 > p3) || (p2 == p1 && p2 > p3) || (p2 > p1 && p2 == p3)) {
                 t_datos.setRowSelectionInterval(r, r);
                 t_datos.setValueAt(true, r, 15);
             }
             if ((p3 > p2 && p3 > p1) || (p3 == p2 && p3 > p1) || (p3 > p2 && p3 == p1)) {
                 t_datos.setRowSelectionInterval(r, r);
                 t_datos.setValueAt(true, r, 20);
             }
             if (p1 == p2 && p1 == p3) {
                 if (p1 > 0) {
                     t_datos.setRowSelectionInterval(r, r);
                     t_datos.setValueAt(true, r, 10);
                 }
             }
         }
     }

     public void visualiza(boolean ver, int op) {
         session = HibernateUtil.getSessionFactory().openSession();
         try {
             session.beginTransaction().begin();
             ord = (Orden) session.get(Orden.class, Integer.parseInt(orden));
             if (ord.getCierreRefacciones() != null && op == 0) {
                 this.jButton1.setEnabled(false);
                 this.jButton2.setEnabled(false);
                 this.jButton3.setEnabled(false);
                 this.r_automatico.setEnabled(false);
             } else {
                 this.jButton1.setEnabled(ver);
                 this.jButton2.setEnabled(ver);
                 this.jButton3.setEnabled(ver);
                 if (user.getEditaPrecioCu() == true)
                     this.r_automatico.setEnabled(ver);
                 else
                     this.r_automatico.setEnabled(false);
             }
             session.beginTransaction().rollback();
         } catch (Exception e) {
             e.printStackTrace();
             session.getTransaction().rollback();
         } finally {
             if (session.isOpen())
                 session.close();
         }
     }

     private boolean consultaLista() {
         if (t_datos.getColumnCount() > 16) {
             for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                 //9 14 19
                 if ((boolean) t_datos.getValueAt(ren, 9) == true || (boolean) t_datos.getValueAt(ren, 14) == true
                         || (boolean) t_datos.getValueAt(ren, 19) == true) {
                     if ((double) t_datos.getValueAt(ren, 2) == 0.00)
                         return false;
                 }
             }
         } else {
             for (int ren = 0; ren < t_datos.getRowCount(); ren++) {
                 //9 14
                 if ((boolean) t_datos.getValueAt(ren, 9) == true || (boolean) t_datos.getValueAt(ren, 14) == true) {
                     if ((double) t_datos.getValueAt(ren, 2) == 0.00)
                         return false;
                 }
             }
         }
         return true;
     }

     void envia() {
         session = HibernateUtil.getSessionFactory().openSession();
         try {
             session.beginTransaction().begin();
             Usuario[] autoriza = (Usuario[]) session.createCriteria(Usuario.class)
                     .add(Restrictions.eq("autorizarPedidos", true)).list().toArray(new Usuario[0]);
             if (autoriza != null) {
                 String correos = "";
                 for (int y = 0; y < autoriza.length; y++) {
                     correos += autoriza[y].getEmpleado().getEmail() + ";";
                 }
                 for (int x = 0; x < id_pedido.size(); x++) {
                     List vec = (ArrayList) id_pedido.get(x);
                     enviaCorreo("Nuevo Pedido (" + vec.get(0).toString() + ")",
                             "Hola buen dia, se te comunica que se genero el pedido No:" + vec.get(0).toString()
                                     + " para que sea revisado y autorizado saludos.",
                             correos);
                 }
             }
             session.beginTransaction().rollback();
         } catch (Exception e) {
             e.printStackTrace();
             session.getTransaction().rollback();
         } finally {
             if (session.isOpen())
                 session.close();
         }
     }

     public void enviaCorreo(String asunto, String mensaje, String from) {
         String smtp = "";
         boolean ttl = false;
         String puerto = "";
         String envia = "";
         String clave = "";
         //String from="";
         String cc = "";
         String texto = null;

         try {
             FileReader f = new FileReader("correo.ml");
             BufferedReader b = new BufferedReader(f);
             int renglon = 0;
             while ((texto = b.readLine()) != null) {
                 switch (renglon) {
                 case 1://smtp
                     smtp = texto.trim();
                     break;
                 case 2://ttl
                     if (texto.compareToIgnoreCase("true") == 0)
                         ttl = true;
                     else
                         ttl = false;
                     break;
                 case 3://puerto
                     puerto = texto.trim();
                     break;
                 case 4://cuenta
                     envia = texto.trim();
                     break;
                 case 5://contrasea
                     clave = texto.trim();
                     break;
                 }
                 renglon += 1;
             }
             b.close();
         } catch (Exception e) {
             e.printStackTrace();
         }

         try {
             // se obtiene el objeto Session.
             Properties props = new Properties();
             props.put("mail.smtp.host", smtp);
             props.setProperty("mail.smtp.starttls.enable", "" + ttl);
             props.setProperty("mail.smtp.port", puerto);
             props.setProperty("mail.smtp.user", envia);
             props.setProperty("mail.smtp.auth", "true");

             javax.mail.Session session = javax.mail.Session.getDefaultInstance(props, null);
             // session.setDebug(true);

             // Se compone la parte del texto
             BodyPart texto_mensaje = new MimeBodyPart();
             texto_mensaje.setText(mensaje);

             // Una MultiParte para agrupar texto e imagen.
             MimeMultipart multiParte = new MimeMultipart();
             multiParte.addBodyPart(texto_mensaje);

             // Se compone el correo, dando to, from, subject y el contenido.
             MimeMessage message = new MimeMessage(session);
             message.setFrom(new InternetAddress(envia));

             String[] direcciones = from.split(";");
             for (int x = 0; x < direcciones.length; x++) {
                 if (direcciones[x].compareTo("") != 0)
                     message.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(direcciones[x].replace(" ", "")));
             }

             String[] dirCC = cc.split(";");
             for (int y = 0; y < dirCC.length; y++) {
                 if (dirCC[y].compareTo("") != 0)
                     message.addRecipient(Message.RecipientType.CC, new InternetAddress(dirCC[y].replace(" ", "")));
             }

             message.setSubject(asunto);
             message.setContent(multiParte);

             Transport t = session.getTransport("smtp");
             t.connect(envia, clave);
             t.sendMessage(message, message.getAllRecipients());
             t.close();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 }