~ubuntu-branches/debian/sid/bgfinancas/sid

« back to all changes in this revision

Viewing changes to src/Movimentacoes/TransferenciasPesquisar.java

  • Committer: Package Import Robot
  • Author(s): Jose Robson Mariano Alves
  • Date: 2014-09-24 15:01:45 UTC
  • Revision ID: package-import@ubuntu.com-20140924150145-le88tcphc5vmc8sh
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2010, 2012, 2014 Jose Robson Mariano Alves
 
3
 
 
4
This file is part of bgfinancas.
 
5
 
 
6
This program is free software: you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation, either version 3 of the License, or
 
9
(at your option) any later version.
 
10
 
 
11
This package is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
*/
 
20
 
 
21
package Movimentacoes;
 
22
 
 
23
import Biblioteca.Botoes;
 
24
import Biblioteca.Calendario;
 
25
import Biblioteca.Datas;
 
26
import Biblioteca.Janela;
 
27
import Biblioteca.Janelinha;
 
28
import Biblioteca.Visual;
 
29
import Principal.TelaPrincipal;
 
30
import java.sql.SQLException;
 
31
import javax.swing.table.DefaultTableModel;
 
32
 
 
33
public class TransferenciasPesquisar extends Janela {
 
34
 
 
35
    private final String Acao;
 
36
    private final Transferencias Transferencias;
 
37
    private final TelaPrincipal Principal;
 
38
 
 
39
    public TransferenciasPesquisar(TelaPrincipal principal, Transferencias transferencias, String acao) {
 
40
        initComponents();
 
41
        Visual.Janela(this.getJanela());
 
42
        BarraDeFerramentas.add(Botoes.Sair(this));
 
43
        Transferencias = transferencias;
 
44
        Acao = acao;
 
45
        Principal = principal;
 
46
        resultado_pesquisa.setFont(FonteFinancas);
 
47
        resultado_pesquisa.getTableHeader().setFont(FonteFinancas);
 
48
    }
 
49
    
 
50
    public void Filtrar()
 
51
    {
 
52
        if(data.getSelectedItem()==null)
 
53
        {
 
54
            Banco.executeQuery("SELECT transferencias.*, TO_CHAR(transferencias.data,'DD/MM/YYYY') AS data_exibir, transferencias_itens.nome AS item_nome, transferencias_categorias.nome AS categoria_nome FROM transferencias, transferencias_itens, transferencias_categorias WHERE transferencias_itens.nome LIKE '%"+item.getText()+"%' AND transferencias.id_item=transferencias_itens.id_item AND transferencias_itens.id_categoria=transferencias_categorias.id_categoria ORDER BY transferencias.data DESC, transferencias.hora DESC");
 
55
        }else{
 
56
            Banco.executeQuery("SELECT transferencias.*, TO_CHAR(transferencias.data,'DD/MM/YYYY') AS data_exibir, transferencias_itens.nome AS item_nome, transferencias_categorias.nome AS categoria_nome FROM transferencias, transferencias_itens, transferencias_categorias WHERE transferencias_itens.nome LIKE '%"+item.getText()+"%' AND transferencias.data LIKE '%"+Datas.ConverterData(data.getSelectedItem().toString())+"%' AND transferencias.id_item=transferencias_itens.id_item AND transferencias_itens.id_categoria=transferencias_categorias.id_categoria ORDER BY transferencias.data DESC, transferencias.hora DESC");
 
57
        }
 
58
 
 
59
        try
 
60
        {
 
61
            DefaultTableModel modelo = (DefaultTableModel)resultado_pesquisa.getModel();
 
62
            modelo.setNumRows(0);
 
63
            while(Banco.getResultSet().next())
 
64
            {
 
65
                modelo.addRow(new Object[]{Banco.getResultSet().getString("id_transferencia"),Banco.getResultSet().getString("item_nome"),Banco.getResultSet().getString("categoria_nome"),Lingua.getMensagem("moeda")+" "+Banco.getResultSet().getString("valor"),Banco.getResultSet().getString("data_exibir")+" "+Banco.getResultSet().getString("hora")});
 
66
            }
 
67
        }catch(SQLException e)
 
68
        {
 
69
            Janelinha.Aviso(Lingua.getMensagem("atencao"),Lingua.getMensagem("excecao")+" "+e.getMessage());
 
70
        }
 
71
    }
 
72
    
 
73
    @Override
 
74
    public void Botoes(String acao)
 
75
    {
 
76
        if(acao.equals(Lingua.getMensagem("sair"))){
 
77
            TransferenciasPesquisar.this.dispose();
 
78
        }
 
79
    }
 
80
    
 
81
 
 
82
    /** This method is called from within the constructor to
 
83
     * initialize the form.
 
84
     * WARNING: Do NOT modify this code. The content of this method is
 
85
     * always regenerated by the Form Editor.
 
86
     */
 
87
    @SuppressWarnings("unchecked")
 
88
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 
89
    private void initComponents() {
 
90
 
 
91
        jScrollPane1 = new javax.swing.JScrollPane();
 
92
        jTable1 = new javax.swing.JTable();
 
93
        BarraDeFerramentas = new javax.swing.JToolBar();
 
94
        pesquisar_venda = new javax.swing.JPanel();
 
95
        scroll_pesquisa = new javax.swing.JScrollPane();
 
96
        resultado_pesquisa = new javax.swing.JTable();
 
97
        CLIENTE_NOME = new javax.swing.JLabel();
 
98
        item = new javax.swing.JTextField();
 
99
        ESTADO = new javax.swing.JLabel();
 
100
        BFiltrar = new javax.swing.JButton();
 
101
        data = new Calendario(false);
 
102
 
 
103
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
 
104
            new Object [][] {
 
105
                {null, null, null, null},
 
106
                {null, null, null, null},
 
107
                {null, null, null, null},
 
108
                {null, null, null, null}
 
109
            },
 
110
            new String [] {
 
111
                "Title 1", "Title 2", "Title 3", "Title 4"
 
112
            }
 
113
        ));
 
114
        jScrollPane1.setViewportView(jTable1);
 
115
 
 
116
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
117
        setTitle(Lingua.getMensagem("pesquisar"));
 
118
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
 
119
        getContentPane().setLayout(null);
 
120
 
 
121
        BarraDeFerramentas.setFloatable(false);
 
122
        BarraDeFerramentas.setRollover(true);
 
123
        getContentPane().add(BarraDeFerramentas);
 
124
        BarraDeFerramentas.setBounds(0, 0, 710, 41);
 
125
 
 
126
        pesquisar_venda.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Lingua.getMensagem("transferencia"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, FonteFinancas, new java.awt.Color(0, 102, 204)));
 
127
        pesquisar_venda.setForeground(new java.awt.Color(51, 94, 168));
 
128
 
 
129
        resultado_pesquisa.setModel(new javax.swing.table.DefaultTableModel(
 
130
            new Object [][] {
 
131
 
 
132
            },
 
133
            new String [] {
 
134
                "ID", "", "", "", ""
 
135
            }
 
136
        ) {
 
137
            boolean[] canEdit = new boolean [] {
 
138
                false, false, false, false, false
 
139
            };
 
140
 
 
141
            public boolean isCellEditable(int rowIndex, int columnIndex) {
 
142
                return canEdit [columnIndex];
 
143
            }
 
144
        });
 
145
        resultado_pesquisa.getTableHeader().setReorderingAllowed(false);
 
146
        resultado_pesquisa.addMouseListener(new java.awt.event.MouseAdapter() {
 
147
            public void mouseClicked(java.awt.event.MouseEvent evt) {
 
148
                resultado_pesquisaMouseClicked(evt);
 
149
            }
 
150
        });
 
151
        scroll_pesquisa.setViewportView(resultado_pesquisa);
 
152
        if (resultado_pesquisa.getColumnModel().getColumnCount() > 0) {
 
153
            resultado_pesquisa.getColumnModel().getColumn(0).setMaxWidth(40);
 
154
            resultado_pesquisa.getColumnModel().getColumn(1).setHeaderValue(Lingua.getMensagem("nome"));
 
155
            resultado_pesquisa.getColumnModel().getColumn(2).setHeaderValue(Lingua.getMensagem("categoria"));
 
156
            resultado_pesquisa.getColumnModel().getColumn(3).setHeaderValue(Lingua.getMensagem("valor"));
 
157
            resultado_pesquisa.getColumnModel().getColumn(4).setHeaderValue(Lingua.getMensagem("data"));
 
158
        }
 
159
 
 
160
        CLIENTE_NOME.setFont(FonteFinancas);
 
161
        CLIENTE_NOME.setText(Lingua.getMensagem("item")+":");
 
162
 
 
163
        item.setFont(FonteFinancas);
 
164
        item.addActionListener(new java.awt.event.ActionListener() {
 
165
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
166
                itemActionPerformed(evt);
 
167
            }
 
168
        });
 
169
 
 
170
        ESTADO.setFont(FonteFinancas);
 
171
        ESTADO.setText(Lingua.getMensagem("data")+":");
 
172
 
 
173
        BFiltrar.setFont(FonteFinancas);
 
174
        BFiltrar.setText(Lingua.getMensagem("pesquisar"));
 
175
        BFiltrar.setPreferredSize(null);
 
176
        BFiltrar.addActionListener(new java.awt.event.ActionListener() {
 
177
            public void actionPerformed(java.awt.event.ActionEvent evt) {
 
178
                BFiltrarActionPerformed(evt);
 
179
            }
 
180
        });
 
181
 
 
182
        data.setFont(FonteFinancas);
 
183
 
 
184
        javax.swing.GroupLayout pesquisar_vendaLayout = new javax.swing.GroupLayout(pesquisar_venda);
 
185
        pesquisar_venda.setLayout(pesquisar_vendaLayout);
 
186
        pesquisar_vendaLayout.setHorizontalGroup(
 
187
            pesquisar_vendaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
188
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pesquisar_vendaLayout.createSequentialGroup()
 
189
                .addContainerGap()
 
190
                .addGroup(pesquisar_vendaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
191
                    .addComponent(scroll_pesquisa)
 
192
                    .addGroup(pesquisar_vendaLayout.createSequentialGroup()
 
193
                        .addComponent(CLIENTE_NOME)
 
194
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
195
                        .addComponent(item)
 
196
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
197
                        .addComponent(ESTADO)
 
198
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
199
                        .addComponent(data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
200
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
201
                        .addComponent(BFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
 
202
                .addContainerGap())
 
203
        );
 
204
        pesquisar_vendaLayout.setVerticalGroup(
 
205
            pesquisar_vendaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
206
            .addGroup(pesquisar_vendaLayout.createSequentialGroup()
 
207
                .addContainerGap()
 
208
                .addGroup(pesquisar_vendaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
209
                    .addComponent(CLIENTE_NOME)
 
210
                    .addComponent(BFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
 
211
                    .addComponent(item, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
 
212
                    .addComponent(ESTADO)
 
213
                    .addComponent(data, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
 
214
                .addGap(18, 18, 18)
 
215
                .addComponent(scroll_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
 
216
                .addContainerGap())
 
217
        );
 
218
 
 
219
        getContentPane().add(pesquisar_venda);
 
220
        pesquisar_venda.setBounds(10, 60, 560, 389);
 
221
 
 
222
        setSize(new java.awt.Dimension(590, 489));
 
223
        setLocationRelativeTo(null);
 
224
    }// </editor-fold>//GEN-END:initComponents
 
225
 
 
226
private void itemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemActionPerformed
 
227
    Filtrar();
 
228
}//GEN-LAST:event_itemActionPerformed
 
229
 
 
230
private void BFiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BFiltrarActionPerformed
 
231
    Filtrar();
 
232
}//GEN-LAST:event_BFiltrarActionPerformed
 
233
 
 
234
private void resultado_pesquisaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resultado_pesquisaMouseClicked
 
235
    String codSelecionado0;
 
236
    String codSelecionado1;
 
237
    String codSelecionado3;
 
238
    codSelecionado0 = (String)resultado_pesquisa.getValueAt(resultado_pesquisa.getSelectedRow(), 0);
 
239
    codSelecionado1 = (String)resultado_pesquisa.getValueAt(resultado_pesquisa.getSelectedRow(), 1);
 
240
    codSelecionado3 = (String)resultado_pesquisa.getValueAt(resultado_pesquisa.getSelectedRow(), 3);
 
241
    if(Janelinha.Pergunta(codSelecionado1, Lingua.getMensagem("tem_certeza"))){
 
242
        Transferencias.PreencherFormulario(Acao, codSelecionado0);
 
243
        TransferenciasPesquisar.this.dispose();
 
244
    }
 
245
}//GEN-LAST:event_resultado_pesquisaMouseClicked
 
246
 
 
247
 
 
248
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
249
    private javax.swing.JButton BFiltrar;
 
250
    private javax.swing.JToolBar BarraDeFerramentas;
 
251
    private javax.swing.JLabel CLIENTE_NOME;
 
252
    private javax.swing.JLabel ESTADO;
 
253
    private javax.swing.JComboBox data;
 
254
    private javax.swing.JTextField item;
 
255
    private javax.swing.JScrollPane jScrollPane1;
 
256
    private javax.swing.JTable jTable1;
 
257
    private javax.swing.JPanel pesquisar_venda;
 
258
    private javax.swing.JTable resultado_pesquisa;
 
259
    private javax.swing.JScrollPane scroll_pesquisa;
 
260
    // End of variables declaration//GEN-END:variables
 
261
 
 
262
}