Advertisement
LaCaraDeLaVerga

carrito con clientes

Nov 18th, 2020
1,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.97 KB | None | 0 0
  1. package presentacion.views.cajero;
  2.  
  3. import javax.swing.JButton;
  4. import javax.swing.JLabel;
  5. import javax.swing.JPanel;
  6. import javax.swing.JScrollPane;
  7. import java.awt.BorderLayout;
  8. import java.awt.Color;
  9. import java.awt.event.ActionListener;
  10. import java.util.List;
  11.  
  12. import javax.swing.JSplitPane;
  13. import javax.swing.JTable;
  14. import javax.swing.JTextField;
  15. import javax.swing.table.DefaultTableModel;
  16.  
  17. import com.jgoodies.forms.layout.FormLayout;
  18. import com.jgoodies.forms.layout.ColumnSpec;
  19. import com.jgoodies.forms.layout.FormSpecs;
  20. import com.jgoodies.forms.layout.RowSpec;
  21.  
  22. import dto.ClienteDTO;
  23. import dto.FichaTecnicaVehiculoDTO;
  24. import dto.OrdenDeTrabajoDTO;
  25. import dto.VehiculoConOrdenDeTrabajoDTO;
  26.  
  27. import javax.swing.BoxLayout;
  28. import javax.swing.border.TitledBorder;
  29. import javax.swing.event.ListSelectionListener;
  30. import javax.swing.border.SoftBevelBorder;
  31. import javax.swing.border.BevelBorder;
  32. import java.awt.FlowLayout;
  33. import javax.swing.JToolBar;
  34.  
  35. public class PanelCarritoRepuestoView extends JPanel {
  36.  
  37.     /**
  38.      *
  39.      */
  40.     private static final long serialVersionUID = -5623725856065117794L;
  41.     private JTextField txtDNI;
  42.  
  43.     private final String[] columnasTablaVehiculos = new String[] { "NRO. VEHICULO", "KM GARANTIA", "ASEGURADORA",
  44.             "NRO POLIZA SEGURO", "PATENTE" };
  45.     private DefaultTableModel tableModelVehiculos;
  46.  
  47.     private static PanelCarritoRepuestoView instance;
  48.     private JButton btnBuscar;
  49.     private JSplitPane splitPane;
  50.     private JPanel panel;
  51.     private JPanel panel_1;
  52.     private JPanel panel_2;
  53.     private JPanel panel_3;
  54.     private JTable table;
  55.  
  56.     private Integer idCliente;
  57.     private Integer idDatosPersonalesDelCliente;
  58.     private JTextField textDni;
  59.     private JTextField textNombre;
  60.     private JTextField textTelefono;
  61.     private JTextField textEmail;
  62.     private JTextField textCalle;
  63.     private JTextField textAltura;
  64.     private JTextField textPiso;
  65.     private JTextField textDpto;
  66.     private JTextField textLocalidad;
  67.  
  68.     private List<VehiculoConOrdenDeTrabajoDTO> vehiculos;
  69.     private JPanel panel_7;
  70.     private JToolBar toolBar;
  71.     private JButton btnRegistrarNuevoVehiculo;
  72.     private JButton btnRegistrarNuevoCliente;
  73.     private JPanel panel_6;
  74.     private JPanel panel_8;
  75.     private JToolBar toolBar_1;
  76.     private JButton btnRegistrarOrdenDeTrabajo;
  77.     private JButton btnEditarCliente;
  78.     private JLabel lblApellido;
  79.     private JTextField textApellido;
  80.  
  81. //-----------------------------------------------------------------------  
  82.    
  83.     private JScrollPane scrollPaneRepuestos;
  84.     private DefaultTableModel modelRepuestos;
  85.     private JTable tablaRepuestos;
  86.     private JScrollPane scrollPaneRepuestosInferior;
  87.     private DefaultTableModel modelRepuestosInferior;
  88.     private JTable tablaRepuestosInferior;
  89.  
  90.    
  91.     private static final String[] nombreColumnasSuperior = { "Codigo", "Descripcion", "Marca", "Fabricante", "Stock",
  92.     "Precio" };
  93.     private static final String[] nombreColumnasInferior = { "Codigo", "Descripcion", "Marca", "Fabricante","Cantidad" };
  94.     private JPanel panel_9;
  95. //------------------------------------------------------------------------
  96.        
  97.        
  98.        
  99.     public PanelCarritoRepuestoView() {
  100.         setLayout(new BorderLayout(0, 0));
  101.  
  102.         JPanel panel_4 = new JPanel();
  103.         panel_4.getLayout();
  104.         panel_4.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
  105.         add(panel_4, BorderLayout.NORTH);
  106.  
  107.         JLabel lblClienteDNI = new JLabel("Cliente DNI");
  108.         panel_4.add(lblClienteDNI);
  109.  
  110.         txtDNI = new JTextField("");
  111.         panel_4.add(txtDNI);
  112.         txtDNI.setColumns(10);
  113.  
  114.         btnBuscar = new JButton("Buscar");
  115.         panel_4.add(btnBuscar);
  116.  
  117.         splitPane = new JSplitPane();
  118.         add(splitPane, BorderLayout.CENTER);
  119.  
  120.         panel = new JPanel();
  121.         splitPane.setLeftComponent(panel);
  122.         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  123.  
  124.         panel_2 = new JPanel();
  125.         panel_2.setBorder(
  126.                 new TitledBorder(null, "Datos del cliente", TitledBorder.LEADING, TitledBorder.TOP, null, null));
  127.         panel.add(panel_2);
  128.         panel_2.setLayout(new FormLayout(
  129.                 new ColumnSpec[] { ColumnSpec.decode("14px"), ColumnSpec.decode("right:max(0dlu;default)"),
  130.                         FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(80dlu;default):grow"),
  131.                         FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("right:66px:grow"),
  132.                         FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(93dlu;default):grow"),
  133.                         FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, },
  134.                 new RowSpec[] { FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
  135.                         FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("26px"), FormSpecs.RELATED_GAP_ROWSPEC,
  136.                         FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
  137.                         FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
  138.                         FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
  139.  
  140.         JLabel lblNewLabel_1 = new JLabel("Nombre");
  141.         panel_2.add(lblNewLabel_1, "2, 4");
  142.  
  143.         textNombre = new JTextField();
  144.         panel_2.add(textNombre, "4, 4, fill, default");
  145.         textNombre.setColumns(10);
  146.  
  147.         lblApellido = new JLabel("Apellido");
  148.         panel_2.add(lblApellido, "6, 4, right, default");
  149.  
  150.         textApellido = new JTextField();
  151.         panel_2.add(textApellido, "8, 4, fill, default");
  152.         textApellido.setColumns(10);
  153.  
  154.         JLabel lblNewLabel = new JLabel("Dni");
  155.         panel_2.add(lblNewLabel, "2, 6");
  156.  
  157.         textDni = new JTextField();
  158.         panel_2.add(textDni, "4, 6, fill, default");
  159.         textDni.setColumns(10);
  160.  
  161.         JLabel lblNewLabel_2 = new JLabel("Telefono");
  162.         panel_2.add(lblNewLabel_2, "6, 6, right, default");
  163.  
  164.         textTelefono = new JTextField();
  165.         panel_2.add(textTelefono, "8, 6, fill, default");
  166.         textTelefono.setColumns(10);
  167.  
  168.         JLabel lblNewLabel_3 = new JLabel("Email");
  169.         panel_2.add(lblNewLabel_3, "2, 8");
  170.  
  171.         textEmail = new JTextField();
  172.         panel_2.add(textEmail, "4, 8, fill, default");
  173.         textEmail.setColumns(10);
  174.  
  175.         JLabel Calle = new JLabel("calle");
  176.         panel_2.add(Calle, "6, 8");
  177.  
  178.         textCalle = new JTextField();
  179.         panel_2.add(textCalle, "8, 8, fill, default");
  180.         textCalle.setColumns(10);
  181.  
  182.         JLabel lblNewLabel_4 = new JLabel("Altura");
  183.         panel_2.add(lblNewLabel_4, "2, 10");
  184.  
  185.         textAltura = new JTextField();
  186.         panel_2.add(textAltura, "4, 10, fill, default");
  187.         textAltura.setColumns(10);
  188.  
  189.         JLabel lblNewLabel_5 = new JLabel("Piso");
  190.         panel_2.add(lblNewLabel_5, "6, 10");
  191.  
  192.         textPiso = new JTextField();
  193.         panel_2.add(textPiso, "8, 10, fill, default");
  194.         textPiso.setColumns(10);
  195.  
  196.         JLabel lblNewLabel_6 = new JLabel("Dpto");
  197.         panel_2.add(lblNewLabel_6, "2, 12");
  198.  
  199.         textDpto = new JTextField();
  200.         panel_2.add(textDpto, "4, 12, fill, default");
  201.         textDpto.setColumns(10);
  202.  
  203.         JLabel lblNewLabel_7 = new JLabel("localidad");
  204.         panel_2.add(lblNewLabel_7, "6, 12, right, default");
  205.  
  206.         textLocalidad = new JTextField();
  207.         panel_2.add(textLocalidad, "8, 12, fill, default");
  208.         textLocalidad.setColumns(10);
  209.  
  210.         panel_3 = new JPanel();
  211.         panel_3.setBorder(new TitledBorder(null, "Listado de vehiculos del cliente", TitledBorder.LEADING,
  212.                 TitledBorder.TOP, null, null));
  213.         panel.add(panel_3);
  214.         panel_3.setLayout(new BorderLayout(0, 0));
  215.  
  216.         JScrollPane scrollPane = new JScrollPane();
  217.         panel_3.add(scrollPane);
  218.  
  219.         tableModelVehiculos = new DefaultTableModel(null, this.columnasTablaVehiculos) {
  220.             /**
  221.              *
  222.              */
  223.             private static final long serialVersionUID = -8904398996893892884L;
  224.  
  225.             public boolean isCellEditable(int row, int column) {
  226.                 return false;
  227.             }
  228.         };
  229.         table = new JTable(tableModelVehiculos);
  230.         scrollPane.setViewportView(table);
  231.  
  232.         panel_7 = new JPanel();
  233.         FlowLayout flowLayout_1 = (FlowLayout) panel_7.getLayout();
  234.         flowLayout_1.setAlignment(FlowLayout.LEFT);
  235.         panel_3.add(panel_7, BorderLayout.SOUTH);
  236.  
  237.         toolBar = new JToolBar();
  238.         toolBar.setFloatable(false);
  239.         panel_7.add(toolBar);
  240.  
  241.         btnRegistrarNuevoCliente = new JButton("Registrar nuevo cliente");
  242.         toolBar.add(btnRegistrarNuevoCliente);
  243.  
  244.         btnEditarCliente = new JButton("Editar cliente");
  245.         toolBar.add(btnEditarCliente);
  246.  
  247.         btnRegistrarNuevoVehiculo = new JButton("Registrar nuevo vehiculo");
  248.         toolBar.add(btnRegistrarNuevoVehiculo);
  249.  
  250.         panel_1 = new JPanel();
  251.         splitPane.setRightComponent(panel_1);
  252.         panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
  253.  
  254. //----------------------------------------------------------------------------------------------       
  255.        
  256.           modelRepuestos = new DefaultTableModel(null, nombreColumnasSuperior) {
  257.                 @Override
  258.                 public boolean isCellEditable(int row, int column) {
  259.                     return false;
  260.                 }
  261.             };
  262.        
  263.        
  264.         JPanel panel_5 = new JPanel();
  265.         panel_5.setBorder(new TitledBorder(null, "Repuestos disponibles", TitledBorder.LEADING, TitledBorder.TOP,
  266.                 null, null));
  267.         panel_1.add(panel_5);
  268.         panel_5.setLayout(new BorderLayout(0, 0));
  269.         tablaRepuestos = new JTable(modelRepuestos);
  270.         scrollPaneRepuestos = new JScrollPane(tablaRepuestos);
  271.         panel_5.add(scrollPaneRepuestos, BorderLayout.CENTER);
  272.        
  273.         panel_9 = new JPanel();
  274.         panel_5.add(panel_9, BorderLayout.NORTH);
  275. //-------------------------------------------------------------------------------------------------        
  276.  
  277.         panel_6 = new JPanel();
  278.         panel_6.setBorder(
  279.                 new TitledBorder(null, "Carrito", TitledBorder.LEADING, TitledBorder.TOP, null, null));
  280.         panel_1.add(panel_6);
  281.  
  282. //        panel_6.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Repuestos a confirmar",
  283. //                TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));
  284. //        panel_6.setBackground(SystemColor.menu);
  285. //        contentPanel.add(panel_6);
  286.         panel_6.setLayout(new BorderLayout(0, 0));
  287.  
  288.         scrollPaneRepuestosInferior = new JScrollPane();
  289.         panel_6.add(scrollPaneRepuestosInferior, BorderLayout.CENTER);
  290.  
  291.         modelRepuestosInferior = new DefaultTableModel(null, nombreColumnasInferior) {
  292.             @Override
  293.             public boolean isCellEditable(int row, int column) {
  294.                 return false;
  295.             }
  296.         };
  297.  
  298.         tablaRepuestosInferior = new JTable(modelRepuestosInferior);
  299.  
  300.         scrollPaneRepuestosInferior.setViewportView(tablaRepuestosInferior);
  301.  
  302.        
  303. //      panel_6.setLayout(new FormLayout(
  304. //              new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
  305. //                      FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
  306. //                      FormSpecs.DEFAULT_COLSPEC, },
  307. //              new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
  308. //                      FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
  309. //                      FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
  310. //                      FormSpecs.DEFAULT_ROWSPEC, }));
  311.  
  312.         panel_8 = new JPanel();
  313.         FlowLayout flowLayout = (FlowLayout) panel_8.getLayout();
  314.         flowLayout.setVgap(8);
  315.         panel_1.add(panel_8);
  316.  
  317.         toolBar_1 = new JToolBar();
  318.         toolBar_1.setFloatable(false);
  319.         panel_8.add(toolBar_1);
  320.  
  321.         btnRegistrarOrdenDeTrabajo = new JButton("Registrar orden de trabajo");
  322.         toolBar_1.add(btnRegistrarOrdenDeTrabajo);
  323.  
  324.         disableAllClienteInputs();
  325.         disableAllFichaTecnicaInputs();
  326.     }
  327.  
  328.     private void disableAllClienteInputs() {
  329.         this.textNombre.setEditable(false);
  330.         this.textApellido.setEditable(false);
  331.         this.textDni.setEditable(false);
  332.         this.textTelefono.setEditable(false);
  333.         this.textEmail.setEditable(false);
  334.         this.textCalle.setEditable(false);
  335.         this.textAltura.setEditable(false);
  336.         this.textPiso.setEditable(false);
  337.         this.textDpto.setEditable(false);
  338.         this.textLocalidad.setEditable(false);
  339.     }
  340.  
  341.     private void disableAllFichaTecnicaInputs() {
  342.     }
  343.  
  344.     public static PanelCarritoRepuestoView getInstance() {
  345.         if (instance == null) {
  346.             instance = new PanelCarritoRepuestoView();
  347.         }
  348.         return instance;
  349.     }
  350.  
  351.     public void clearDataCliente() {
  352.         this.idCliente = null;
  353.         this.idDatosPersonalesDelCliente = null;
  354.         this.textNombre.setText("");
  355.         this.textApellido.setText("");
  356.         this.textDni.setText("");
  357.         this.textTelefono.setText("");
  358.         this.textEmail.setText("");
  359.         this.textCalle.setText("");
  360.         this.textAltura.setText("");
  361.         this.textPiso.setText("");
  362.         this.textDpto.setText("");
  363.         this.textLocalidad.setText("");
  364.     }
  365.  
  366.     public void clearDataFichaTecnicaVehiculo() {
  367. //      this.textNroDeChasis.setText("");
  368. //      this.textNroMotor.setText("");
  369. //      this.textMarca.setText("");
  370. //      this.textColor.setText("");
  371. //      this.textCombustion.setText("");
  372. //      this.textModelo.setText("");
  373. //      this.textTipoDeOT.setText("");
  374.     }
  375.  
  376.     public void clearDataListadoVehiculosCliente() {
  377.         this.vehiculos = null;
  378.         this.tableModelVehiculos.setRowCount(0);
  379.         tableModelVehiculos.setColumnCount(0);
  380.         tableModelVehiculos.setColumnIdentifiers(columnasTablaVehiculos);
  381.     }
  382.  
  383.     public void clearDataOrdenDeTrabajo() {
  384. //      this.textFechaAltaOt.setText("");
  385. //      this.textFechaCierreOt.setText("");
  386. //      this.textTrabajoSugeridoOt.setText("");
  387. //      this.textTrabajoSolicitadoOt.setText("");
  388.     }
  389.  
  390.     public void setData(ClienteDTO cliente) {
  391.         this.idDatosPersonalesDelCliente = cliente.getDatosPersonalesDTO().getId();
  392.         this.idCliente = cliente.getIdCliente();
  393.         this.textNombre.setText(cliente.getDatosPersonalesDTO().getNombreCompleto());
  394.         this.textApellido.setText(cliente.getDatosPersonalesDTO().getApellido());
  395.         this.textDni.setText(cliente.getDatosPersonalesDTO().getDni().toString());
  396.         this.textTelefono.setText(cliente.getDatosPersonalesDTO().getTelefono());
  397.         this.textEmail.setText(cliente.getDatosPersonalesDTO().getEmail());
  398.         this.textCalle.setText(cliente.getDatosPersonalesDTO().getCalle());
  399.         this.textAltura.setText(cliente.getDatosPersonalesDTO().getAltura().toString());
  400.         this.textPiso.setText(cliente.getDatosPersonalesDTO().getPiso().toString());
  401.         this.textDpto.setText(cliente.getDatosPersonalesDTO().getDpto());
  402.         this.textLocalidad.setText(cliente.getDatosPersonalesDTO().getLocalidad());
  403.     }
  404.  
  405.     public void setData(FichaTecnicaVehiculoDTO fichaVehiculo) {
  406.         fichaVehiculo.getId();
  407. //      this.textNroDeChasis.setText(fichaVehiculo.getNroChasis().toString());
  408. //      this.textNroMotor.setText(fichaVehiculo.getNroMotor().toString());
  409. //      this.textMarca.setText(fichaVehiculo.getMarca());
  410. //      this.textColor.setText(fichaVehiculo.getColor());
  411. //      this.textCombustion.setText(fichaVehiculo.getCombustion());
  412. //      this.textModelo.setText(fichaVehiculo.getModelo().toString());
  413.     }
  414.  
  415.     public void setData(OrdenDeTrabajoDTO ordenDeTrabajo) {
  416. //      this.textFechaAltaOt.setText(ordenDeTrabajo.getFechaDeAlta().toString());
  417. //      this.textFechaCierreOt.setText(
  418. //              ordenDeTrabajo.getFechaEntregado() != null ? ordenDeTrabajo.getFechaEntregado().toString() : "");
  419. //      this.textTrabajoSugeridoOt.setText(ordenDeTrabajo.getTrabajoSujerido());
  420. //      this.textTrabajoSolicitadoOt.setText(ordenDeTrabajo.getTrabajoSolicitado());
  421. //      this.textTipoDeOT.setText(ordenDeTrabajo.getTipoOrdeTrabajo());
  422.     }
  423.  
  424.     public void setData(List<VehiculoConOrdenDeTrabajoDTO> vehiculos) {
  425.         this.vehiculos = vehiculos;
  426.         for (VehiculoConOrdenDeTrabajoDTO dto : vehiculos) {
  427.             Object[] row = { dto.getId().toString(), dto.getKilometrajeGarantia().toString(), dto.getAseguradora(),
  428.                     dto.getNroPolizaSeguro().toString(), dto.getPatente() };
  429.             this.tableModelVehiculos.addRow(row);
  430.         }
  431.     }
  432.  
  433.     public void setActionBuscar(ActionListener listener) {
  434.         this.btnBuscar.addActionListener(listener);
  435.     }
  436.  
  437.     public VehiculoConOrdenDeTrabajoDTO getidVehiculoSeleccionado() {
  438.         int rows = this.table.getSelectedRowCount();
  439.         if (rows == 1) {
  440.             int row = this.table.getSelectedRow();
  441.             VehiculoConOrdenDeTrabajoDTO dto = this.vehiculos.get(row);
  442.             return dto;
  443.         }
  444.         return null;
  445.     }
  446.  
  447.     public Integer getIdCliente() {
  448.         return this.idCliente;
  449.     }
  450.  
  451.     public Integer getIdDatosPersonalesCliente() {
  452.         return this.idDatosPersonalesDelCliente;
  453.     }
  454.  
  455.     public void setActionSelectVehiculoCliente(ListSelectionListener listener) {
  456.         this.table.getSelectionModel().addListSelectionListener(listener);
  457.     }
  458.  
  459.     public String getDniCliente() {
  460.         return txtDNI.getText();
  461.     }
  462.  
  463.     public void setActionRegistrarCliente(ActionListener listener) {
  464.         this.btnRegistrarNuevoCliente.addActionListener(listener);
  465.     }
  466.  
  467.     public void setActionRegistrarVehiculo(ActionListener listener) {
  468.         this.btnRegistrarNuevoVehiculo.addActionListener(listener);
  469.     }
  470.  
  471.     public void setActionRegistrarOrdenDeTrabajo(ActionListener listener) {
  472.         this.btnRegistrarOrdenDeTrabajo.addActionListener(listener);
  473.     }
  474.  
  475.     public void setActionOnEditarCliente(ActionListener listener) {
  476.         this.btnEditarCliente.addActionListener(listener);
  477.     }
  478.  
  479.     public void clearAll() {
  480.         this.clearDataCliente();
  481.         this.clearDataFichaTecnicaVehiculo();
  482.         this.clearDataListadoVehiculosCliente();
  483.         this.clearDataOrdenDeTrabajo();
  484.     }
  485.  
  486.     public void lockButtonRegistrarOrdenDeTrabajo() {
  487.         this.btnRegistrarOrdenDeTrabajo.setEnabled(false);
  488.     }
  489.  
  490.     public void unlockButtonRegistrarOrdenDeTrabajo() {
  491.         this.btnRegistrarOrdenDeTrabajo.setEnabled(true);
  492.     }
  493.    
  494.    
  495.    
  496.    
  497.    
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement