-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionHistory_Panel.java
More file actions
221 lines (188 loc) · 9.09 KB
/
TransactionHistory_Panel.java
File metadata and controls
221 lines (188 loc) · 9.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* 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 banking_app;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import java.util.Arrays;
import javax.swing.JOptionPane;
import jdk.nashorn.internal.scripts.JO;
/**
*
* @author CLEMENT O. A-U
*/
public class TransactionHistory_Panel extends javax.swing.JPanel {
Connection conn;
PreparedStatement ps;
public final String url = "jdbc:mysql://localhost:3306/banking_app";
public final String user = "root";
public final String pwd = "";
/**
* Creates new form TransactionHistory_Panel
*/
public TransactionHistory_Panel() {
initComponents();
doConn();
}
public void doConn() {
try {
conn = DriverManager.getConnection(url, user, pwd);
} catch (SQLException se) {
se.printStackTrace();
}
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
accountNumber = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
transactionTable = new javax.swing.JTable();
goButton = new javax.swing.JButton();
beginDate = new javax.swing.JTextField();
endDate = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setBackground(new java.awt.Color(153, 153, 255));
jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Transaction History");
add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 45, -1, -1));
jLabel2.setText("Account Number");
add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 95, -1, -1));
add(accountNumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 91, 191, 23));
jLabel3.setText("Begin Date");
add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 150, 60, -1));
jLabel4.setText("End Date");
add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 190, 60, -1));
transactionTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Account Name", "Transaction Type", "Transaction Amount", "Current Balance", "Transaction Date"
}
));
jScrollPane1.setViewportView(transactionTable);
add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 213, 547, 194));
goButton.setBackground(new java.awt.Color(204, 153, 255));
goButton.setText("Go");
goButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
goButtonActionPerformed(evt);
}
});
add(goButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(403, 91, -1, -1));
beginDate.setText("YYYY-MM-DD");
beginDate.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
beginDateFocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
beginDateFocusLost(evt);
}
});
add(beginDate, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 150, 101, -1));
endDate.setText("YYYY-MM-DD");
endDate.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
endDateFocusGained(evt);
}
});
add(endDate, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 182, 101, -1));
jLabel5.setText("To check a transaction made today, use tomorrow's date.");
add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(289, 172, 282, 30));
jLabel6.setIcon(new javax.swing.ImageIcon("C:\\Users\\Patricia Osifo\\Pictures\\Photos\\From OsamaMagicFlix or my Photograghy Exploits\\20191222161248.jpg")); // NOI18N
add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 610, 420));
}// </editor-fold>//GEN-END:initComponents
private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goButtonActionPerformed
// TODO add your handling code here:
String search = "select * from account where acct_no = ? and trans_date between ? and ? order by trans_date asc ";
String search1 = "select * from account where acct_no = ? and trans_date >= ? order by trans_date asc";
String search2 = "select * from account where acct_no = ? and trans_date <= ? order by trans_date asc";
String search3 = "select * from account where acct_no = ? order by trans_date asc";
String acctNo = accountNumber.getText();
String begDate = "";
String enDate = "";
try {
//This program is still lacking an essential part: Validation of the Date inputs WHEN they are INDEED entered.
//I can't yet figure out where to place that though or how I might construct the contingent IF statement.
if (beginDate.getText().isEmpty() && endDate.getText().isEmpty()) {
ps = conn.prepareStatement(search3);
ps.setString(1, acctNo);
} else if (endDate.getText().length() > 0) {
ps = conn.prepareStatement(search2);
ps.setString(1, acctNo);
enDate = endDate.getText();
ps.setString(2, enDate);
} else if (beginDate.getText().length() > 0) {
ps = conn.prepareStatement(search1);
ps.setString(1, acctNo);
begDate = beginDate.getText();
ps.setString(2, begDate);
} else {
ps = conn.prepareStatement(search);
ps.setString(1, acctNo);
begDate = beginDate.getText();
enDate = endDate.getText();
ps.setString(2, begDate);
ps.setString(3, enDate);
}
ResultSet rs = ps.executeQuery();
DefaultTableModel model = (DefaultTableModel) transactionTable.getModel();
if (!rs.next()) {
model.setRowCount(0);
JOptionPane.showMessageDialog(null, "Account Not Found!");
} else {
rs.beforeFirst();
model.setRowCount(0);
while (rs.next()) {
String acctName = rs.getString("acct_name");
String transType = rs.getString("trans_type");
String transAmt = Double.toString(rs.getDouble("amount"));
String curBal = Double.toString(rs.getDouble("acct_balance"));
String transDate = rs.getDate("trans_date").toString();
String[] newRow = new String[]{acctName, transType, transAmt, curBal, transDate};
model.addRow(newRow);
}
}
} catch (SQLException sq) {
sq.printStackTrace();
}
}//GEN-LAST:event_goButtonActionPerformed
private void beginDateFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_beginDateFocusGained
// TODO add your handling code here:
beginDate.setText("");
}//GEN-LAST:event_beginDateFocusGained
private void endDateFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_endDateFocusGained
// TODO add your handling code here:
endDate.setText("");
}//GEN-LAST:event_endDateFocusGained
private void beginDateFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_beginDateFocusLost
// TODO add your handling code here:
}//GEN-LAST:event_beginDateFocusLost
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField accountNumber;
private javax.swing.JTextField beginDate;
private javax.swing.JTextField endDate;
private javax.swing.JButton goButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable transactionTable;
// End of variables declaration//GEN-END:variables
}