/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* FrmRegistrarEntrega.java
*
* Created on 22/06/2010, 01:06:56
*/
package boundary;
import control.ControladoraEntrega;
import control.ControladoraPagamento;
import control.ControladoraRelatorio;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import util.ConexaoException;
import util.MinhaException;
import util.Validador;
/**
*
* @author rodrigo
*/
public class FrmRegistrarEntrega extends javax.swing.JDialog {
private ControladoraEntrega controlEntrega = new ControladoraEntrega();
private ControladoraPagamento controlPagamento = new ControladoraPagamento();
private ControladoraRelatorio controlRelatorio = new ControladoraRelatorio();
int codLocacao = 0;
int codCarro = 0;
Vector usuarioTipo = new Vector();
Vector usuario = new Vector();
Double valorTotal;
String cpf, nomePlano;
DecimalFormat formato = new DecimalFormat("#.00");
String vFormat;
/** Creates new form FrmRegistrarEntrega */
public FrmRegistrarEntrega(Vector userTipo, Vector user) {
usuarioTipo = userTipo;
usuario = user;
initComponents();
this.setLocationRelativeTo(null);
this.setModal(true);
}
public void converteDataVetor(int[] dataInicio, int[] dataFim, Vector carro)
{
Date dataLocacao = null;
SimpleDateFormat formatBra = null;
Date dataEntrega = new Date();
formatBra = new SimpleDateFormat("dd/MM/yyyy");
try
{
String dataLoca = formatBra.format(carro.get(6));
String dataEntre = formatBra.format(carro.get(7));
DateFormat formatter = formatBra;
dataLocacao = formatter.parse(dataLoca);
dataEntrega = formatter.parse(dataEntre);
}
catch(ParseException e)
{
e.printStackTrace();
}
Calendar calendarI = Calendar.getInstance();
calendarI.setTime(dataLocacao);
dataInicio[0] = calendarI.get(Calendar.DAY_OF_MONTH);
dataInicio[1] = calendarI.get(Calendar.MONTH);
dataInicio[2] = calendarI.get(Calendar.YEAR);
Calendar calendarF = Calendar.getInstance();
calendarF.setTime(dataEntrega);
dataFim[0] = calendarF.get(Calendar.DAY_OF_MONTH);
dataFim[1] = calendarF.get(Calendar.MONTH);
dataFim[2] = calendarF.get(Calendar.YEAR);
}
public int calcularDatas(Vector carro)
{
int[] dataInicio = new int[3];
int[] dataFim = new int[3];
long diffMillis, diffDays = 0;
converteDataVetor(dataInicio, dataFim, carro);
Calendar dataI = new GregorianCalendar(dataInicio[2], dataInicio[1], dataInicio[0]);
Calendar dataF = new GregorianCalendar(dataFim[2], dataFim[1], dataFim[0]);
if(dataF.before(dataI)){
JOptionPane.showMessageDialog(null, " A data de Entrega não pode ser antes da data de Locação !", "Informação", JOptionPane.INFORMATION_MESSAGE);
}
else{
diffMillis = dataF.getTimeInMillis() - dataI.getTimeInMillis();
diffDays = diffMillis / (24*60*60*1000);
}
int dias = (int) diffDays;
return dias;
}
/** 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() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jTCPF = new java.awt.Label();
jLKMFinal = new javax.swing.JLabel();
jTFKMFinal = new javax.swing.JTextField();
jLValorPrevisto = new javax.swing.JLabel();
jTFValorTotal = new javax.swing.JTextField();
jTFValorPrevisto = new javax.swing.JTextField();
jLPagRealizado = new javax.swing.JLabel();
jRBSim = new javax.swing.JRadioButton();
jRBNao = new javax.swing.JRadioButton();
jBConfirmar = new javax.swing.JButton();
jBCancelar = new javax.swing.JButton();
jLKM = new javax.swing.JLabel();
jLCliente = new javax.swing.JLabel();
jTFCliente = new javax.swing.JTextField();
jLPlacaVeiculo = new javax.swing.JLabel();
jTFPlacaVeiculo = new javax.swing.JTextField();
jSeparator1 = new javax.swing.JSeparator();
jLGC = new javax.swing.JLabel();
jLCarro = new javax.swing.JLabel();
jLKMInicial = new javax.swing.JLabel();
jTFKMInicial = new javax.swing.JTextField();
jLKM2 = new javax.swing.JLabel();
jLDataEntrega = new javax.swing.JLabel();
jLHoraEntrega = new javax.swing.JLabel();
jDCDataEntrega = new com.toedter.calendar.JDateChooser();
jCBHoraEntrega = new javax.swing.JComboBox();
jSeparator2 = new javax.swing.JSeparator();
jLRS = new javax.swing.JLabel();
jLCobertura = new javax.swing.JLabel();
jTFCorbertura = new javax.swing.JTextField();
jLValorTotal = new javax.swing.JLabel();
jLRS2 = new javax.swing.JLabel();
jSeparator3 = new javax.swing.JSeparator();
jFTFCPF = new javax.swing.JFormattedTextField();
jTFGC = new javax.swing.JTextField();
jTFCarro = new javax.swing.JTextField();
jTFQntVezes = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("SCC - Entrega");
jTCPF.setFont(new java.awt.Font("Tahoma", 0, 11));
jTCPF.setText("CPF");
jLKMFinal.setText("Quilometragem Final");
jTFKMFinal.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTFKMFinalFocusLost(evt);
}
});
jLValorPrevisto.setText("Valor Previsto");
jTFValorTotal.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTFValorTotal.setEnabled(false);
jTFValorPrevisto.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTFValorPrevisto.setEnabled(false);
jLPagRealizado.setText("Pagamento A Vista:");
buttonGroup2.add(jRBSim);
jRBSim.setText("Sim");
buttonGroup2.add(jRBNao);
jRBNao.setText("Não");
jRBNao.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRBNaoMouseClicked(evt);
}
});
jBConfirmar.setText("Confirmar");
jBConfirmar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBConfirmarActionPerformed(evt);
}
});
jBCancelar.setText("Cancelar");
jBCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBCancelarActionPerformed(evt);
}
});
jLKM.setText("Km");
jLCliente.setText("Cliente");
jTFCliente.setEnabled(false);
jLPlacaVeiculo.setText("Placa Veiculo");
jTFPlacaVeiculo.setEnabled(false);
jLGC.setText("Grupo de Carro");
jLCarro.setText("Carro");
jLKMInicial.setText("Quilometragem Inicial");
jTFKMInicial.setEnabled(false);
jLKM2.setText("Km");
jLDataEntrega.setText("Data Entrega");
jLHoraEntrega.setText("Hora Entrega");
jCBHoraEntrega.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "HR", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00" }));
jCBHoraEntrega.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jCBHoraEntregaFocusLost(evt);
}
});
jLRS.setText("R$");
jLCobertura.setText("Cobertura");
jTFCorbertura.setEnabled(false);
jLValorTotal.setForeground(new java.awt.Color(255, 0, 51));
jLValorTotal.setText("VALOR TOTAL");
jLRS2.setText("R$");
try {
jFTFCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
jFTFCPF.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jFTFCPFFocusLost(evt);
}
});
jTFGC.setEnabled(false);
jTFCarro.setEnabled(false);
jTFQntVezes.setText("0");
jTFQntVezes.setEnabled(false);
jLabel1.setText("Quantidade de Vezes:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLDataEntrega)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jDCDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(85, 85, 85)
.addComponent(jLHoraEntrega)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCBHoraEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLPagRealizado)
.addGap(96, 96, 96)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(140, 140, 140)
.addComponent(jLValorTotal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLRS2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jRBSim)
.addGap(18, 18, 18)
.addComponent(jRBNao)
.addGap(37, 37, 37)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jTFQntVezes, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLGC)
.addGap(18, 18, 18)
.addComponent(jTFGC, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLKMInicial)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFKMInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLKM)))
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLCarro)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFCarro, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLKMFinal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFKMFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLKM2)))
.addGap(22, 22, 22)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLCliente)
.addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTFCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLPlacaVeiculo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFPlacaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jFTFCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLCobertura)
.addGap(145, 145, 145))
.addComponent(jTFCorbertura, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
.addGap(66, 66, 66)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLRS)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTFValorPrevisto, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLValorPrevisto))
.addGap(212, 212, 212)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(jBConfirmar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
.addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(403, 403, 403))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE)
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jFTFCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLCliente)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTFCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLPlacaVeiculo)
.addComponent(jTFPlacaVeiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLGC)
.addComponent(jLCarro)
.addComponent(jTFGC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTFCarro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLKMInicial)
.addComponent(jTFKMInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLKM)
.addComponent(jLKMFinal)
.addComponent(jTFKMFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLKM2))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLDataEntrega)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLHoraEntrega)
.addComponent(jCBHoraEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jDCDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLCobertura)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTFCorbertura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLValorPrevisto)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTFValorPrevisto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLRS))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLPagRealizado)
.addComponent(jRBSim)
.addComponent(jRBNao)
.addComponent(jLabel1)
.addComponent(jTFQntVezes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLRS2)
.addComponent(jLValorTotal)
.addComponent(jTFValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jBConfirmar)
.addComponent(jBCancelar))
.addGap(21, 21, 21))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jFTFCPFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFTFCPFFocusLost
// TODO add your handling code here:
cpf = this.jFTFCPF.getText();
Validador valida = new Validador();
cpf = valida.tiraPontosCPF(cpf);
if (!cpf.isEmpty())
{
try{
try {
Vector cliente = this.controlEntrega.obterCliente(cpf);
this.jTFCliente.setText(cliente.get(1).toString());
Vector carro = this.controlEntrega.obterCarro(cpf);
codLocacao = Integer.parseInt(carro.get(11).toString());
codCarro = Integer.parseInt(carro.get(10).toString());
nomePlano = carro.get(12).toString();
this.jTFPlacaVeiculo.setText(carro.get(0).toString());
this.jTFGC.setText(carro.get(1).toString());
this.jTFCarro.setText(carro.get(2).toString());
this.jTFKMInicial.setText(carro.get(3).toString());
if (carro.get(4).toString().equals("true"))
{
this.jTFCorbertura.setText("Sim");
}else{
this.jTFCorbertura.setText("Não");
}
String valorPrevisto = formato.format(Double.parseDouble(carro.get(5).toString()));
this.jTFValorPrevisto.setText(valorPrevisto);
Date data = new Date();
this.jDCDataEntrega.setDate(data);
this.jDCDataEntrega.setEnabled(false);
String qntVezes = "0";
this.jTFQntVezes.setText(qntVezes);
} catch (ConexaoException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}
}
catch(SQLException erro){
JOptionPane.showMessageDialog(null, erro.getMessage());
}
catch(MinhaException erro){
JOptionPane.showMessageDialog(null, erro.getMessage());
}
}else {
JOptionPane.showMessageDialog(null, "É necessário o CPF!", "Atenção", JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jFTFCPFFocusLost
private void jBConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBConfirmarActionPerformed
// TODO add your handling code here:
if (!this.jTCPF.getText().isEmpty())
{
if (!this.jTFKMFinal.getText().isEmpty())
{
if (!this.jDCDataEntrega.getDateFormatString().isEmpty())
{
if (!this.jCBHoraEntrega.getSelectedItem().equals("HR"))
{
if ((!this.jRBNao.isSelected()) || (!this.jRBSim.isSelected()))
{
int vTotal = (int) Double.parseDouble(this.jTFValorTotal.getText().replace(",", ""));
Vector novaEntrega = new Vector();
novaEntrega.addElement(codLocacao); //0
novaEntrega.addElement(this.jTFKMFinal.getText());
novaEntrega.addElement(this.jDCDataEntrega.getDate());
novaEntrega.addElement(this.jCBHoraEntrega.getSelectedItem());
novaEntrega.addElement(vTotal / 100);
novaEntrega.addElement(this.jTFQntVezes.getText());
novaEntrega.addElement(codCarro);
try {
try {
this.controlEntrega.inserirNovaEntrega(novaEntrega);
} catch (ConexaoException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}
this.jFTFCPF.setText("");
this.jTFCliente.setText("");
this.jTFPlacaVeiculo.setText("");
this.jTFGC.setText("");
this.jTFCarro.setText("");
this.jTFKMInicial.setText("");
this.jTFKMFinal.setText("");
this.jDCDataEntrega.setDate(null);
this.jCBHoraEntrega.setSelectedItem("HR");
this.jTFCorbertura.setText("");
this.jTFValorPrevisto.setText("");
this.jTFValorTotal.setText("");
this.jTFQntVezes.setText("");
this.dispose();
JOptionPane.showMessageDialog(null, "A Entrega foi registrada com sucesso!\n" +
"O Recibo para Pagamento será gerado em breve!",
"Atenção" , JOptionPane.INFORMATION_MESSAGE);
try {
controlPagamento.inserirNovoPagamento(novaEntrega);
controlRelatorio.geraPagamento(null, usuario, cpf);
} catch (ConexaoException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MinhaException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}catch (ParseException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}
}else
JOptionPane.showMessageDialog(null, "É necessário Selecionar o Pagamento!","Atenção" , JOptionPane.WARNING_MESSAGE);
}else
JOptionPane.showMessageDialog(null, "É necessário Selecionar a Hora de Entrega!","Atenção" , JOptionPane.WARNING_MESSAGE);
}else
JOptionPane.showMessageDialog(null, "É necessário a Data de Entrega!","Atenção" , JOptionPane.WARNING_MESSAGE);
}else
JOptionPane.showMessageDialog(null, "É necessário a Quilometragem Final!","Atenção" , JOptionPane.WARNING_MESSAGE);
}else
JOptionPane.showMessageDialog(null, "É necessário o CPF do Cliente!","Atenção" , JOptionPane.WARNING_MESSAGE);
}//GEN-LAST:event_jBConfirmarActionPerformed
private void jCBHoraEntregaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jCBHoraEntregaFocusLost
// TODO add your handling code here:
double kmFinal, kmInicial, kmResult;
Date dataEntrega = null;
Date dataAtual = new Date();
String cpf = this.jFTFCPF.getText();
Validador valida = new Validador();
cpf = valida.tiraPontosCPF(cpf);
try {
Vector carro = this.controlEntrega.obterCarro(cpf);
double diasSobrando = this.calcularDatas(carro);
dataEntrega = (Date) carro.get(7);
double valorDiario = Double.parseDouble(carro.get(8).toString());
double valorDiarioQuilometrado = Double.parseDouble(carro.get(13).toString());
double valorLitroKM = Double.parseDouble(carro.get(9).toString());
double valorCobertura = Double.parseDouble(carro.get(14).toString());
double valorTotal;
if (dataAtual.after(dataEntrega)) // se dataAtual for posterior a data de entrega
{
kmInicial = Integer.parseInt(this.jTFKMInicial.getText());
kmFinal = Integer.parseInt(this.jTFKMFinal.getText());
kmResult = +(kmFinal - kmInicial);
kmResult = (kmResult * valorLitroKM); // valor do desconto da KM
double result;
if (nomePlano.equals("Diaria Quilometrada")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult + valorCobertura ;
}else{
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
} else if(nomePlano.equals("Diaria Simples")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiario;
valorTotal = result + kmResult + valorCobertura;
}else{
result = diasSobrando * valorDiario;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
}
this.jTFValorTotal.setText(vFormat);
}
if (dataAtual.before(dataEntrega)) // se dataAtual é anterior a dataEntrega
{
kmInicial = Integer.parseInt(this.jTFKMInicial.getText());
kmFinal = Integer.parseInt(this.jTFKMFinal.getText());
kmResult = +(kmFinal - kmInicial);
kmResult = (kmResult * valorLitroKM); // valor do desconto da KM
double result;
if (nomePlano.equals("Diaria Quilometrada")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult + valorCobertura ;
}else{
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
} else if(nomePlano.equals("Diaria Simples")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiario;
valorTotal = result + kmResult + valorCobertura;
}else{
result = diasSobrando * valorDiario;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
}
this.jTFValorTotal.setText(vFormat);
}
if (dataAtual.equals(dataEntrega)){
kmInicial = Integer.parseInt(this.jTFKMInicial.getText());
kmFinal = Integer.parseInt(this.jTFKMFinal.getText());
kmResult = +(kmFinal - kmInicial);
kmResult = (kmResult * valorLitroKM); // valor do desconto da KM
double result;
if (nomePlano.equals("Diaria Quilometrada")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult + valorCobertura ;
}else{
result = diasSobrando * valorDiarioQuilometrado;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
} else if(nomePlano.equals("Diaria Simples")){
if (this.jTFCorbertura.getText().equals("Sim")){
result = diasSobrando * valorDiario;
valorTotal = result + kmResult + valorCobertura;
} else {
result = diasSobrando * valorDiario;
valorTotal = result + kmResult;
}
vFormat = formato.format(valorTotal);
}
this.jTFValorTotal.setText(String.valueOf(vFormat));
}
} catch (ConexaoException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
} catch (MinhaException ex) {
Logger.getLogger(FrmRegistrarEntrega.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jCBHoraEntregaFocusLost
private void jTFKMFinalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTFKMFinalFocusLost
// TODO add your handling code here:
if (!this.jTFKMFinal.getText().isEmpty()){
int kmFinal = Integer.parseInt(this.jTFKMFinal.getText());
int kmInicial = Integer.parseInt(this.jTFKMInicial.getText());
if ( kmFinal < kmInicial)
{
JOptionPane.showMessageDialog(null, "É necessário que a Quilometragem Final seja maior que a Inicial!","Atenção" , JOptionPane.WARNING_MESSAGE);
this.jTFKMFinal.setText("");
this.jTFKMFinal.grabFocus();
}
}else
JOptionPane.showMessageDialog(null, "É necessário digitar a Quilometragem Final!","Atenção" , JOptionPane.WARNING_MESSAGE);
}//GEN-LAST:event_jTFKMFinalFocusLost
private void jRBNaoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRBNaoMouseClicked
// TODO add your handling code here:
this.jTFQntVezes.setEnabled(true);
}//GEN-LAST:event_jRBNaoMouseClicked
private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_jBCancelarActionPerformed
/**
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmRegistrarEntrega().setVisible(true);
}
});
}*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JButton jBCancelar;
private javax.swing.JButton jBConfirmar;
private javax.swing.JComboBox jCBHoraEntrega;
private com.toedter.calendar.JDateChooser jDCDataEntrega;
private javax.swing.JFormattedTextField jFTFCPF;
private javax.swing.JLabel jLCarro;
private javax.swing.JLabel jLCliente;
private javax.swing.JLabel jLCobertura;
private javax.swing.JLabel jLDataEntrega;
private javax.swing.JLabel jLGC;
private javax.swing.JLabel jLHoraEntrega;
private javax.swing.JLabel jLKM;
private javax.swing.JLabel jLKM2;
private javax.swing.JLabel jLKMFinal;
private javax.swing.JLabel jLKMInicial;
private javax.swing.JLabel jLPagRealizado;
private javax.swing.JLabel jLPlacaVeiculo;
private javax.swing.JLabel jLRS;
private javax.swing.JLabel jLRS2;
private javax.swing.JLabel jLValorPrevisto;
private javax.swing.JLabel jLValorTotal;
private javax.swing.JLabel jLabel1;
private javax.swing.JRadioButton jRBNao;
private javax.swing.JRadioButton jRBSim;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private java.awt.Label jTCPF;
private javax.swing.JTextField jTFCarro;
private javax.swing.JTextField jTFCliente;
private javax.swing.JTextField jTFCorbertura;
private javax.swing.JTextField jTFGC;
private javax.swing.JTextField jTFKMFinal;
private javax.swing.JTextField jTFKMInicial;
private javax.swing.JTextField jTFPlacaVeiculo;
private javax.swing.JTextField jTFQntVezes;
private javax.swing.JTextField jTFValorPrevisto;
private javax.swing.JTextField jTFValorTotal;
// End of variables declaration//GEN-END:variables
}