-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnItem.java
More file actions
271 lines (233 loc) · 12.3 KB
/
ReturnItem.java
File metadata and controls
271 lines (233 loc) · 12.3 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package src.anearcan;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
/**
*
* @author anearcan
*/
public class ReturnItem extends javax.swing.JFrame {
private static Item returnedItems[] = new Item[Utility.numberOfTransactions];
private Employee employee;
private static MemberAccount member;
private static DefaultListModel listModel;
public static ItemControl control;
public static JFrame frame = new JFrame();
private static int count = 0;
/** Creates new form ReturnItem */
public ReturnItem() throws SQLException {
listModel = new DefaultListModel();
employee = null;
member = null;
control = new ItemControl();
initComponents();
}
ReturnItem(Employee employee) throws SQLException {
listModel = new DefaultListModel();
this.employee = employee;
member = null;
control = new ItemControl();
}
/** 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() {
jScrollPane1 = new javax.swing.JScrollPane();
unreturnedItems = new javax.swing.JList();
jLabel1 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
memberID = new javax.swing.JLabel();
Done = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
accBalance = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Return Item");
jScrollPane1.setToolTipText("");
unreturnedItems.setModel(listModel);
jScrollPane1.setViewportView(unreturnedItems);
jLabel1.setText("Items In Possession");
jLabel1.setToolTipText("");
jLabel7.setText("MemberID");
jLabel7.setToolTipText("");
memberID.setToolTipText("");
Done.setText("Done");
Done.setToolTipText("");
Done.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DoneActionPerformed(evt);
}
});
jLabel2.setText("Account Balance: $");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(18, 18, 18)
.addComponent(memberID, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(accBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(Done)))
.addContainerGap(60, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(accBalance, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(memberID, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
.addComponent(Done)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
//Scans item and add item to list of scanned items.
public static void addItemsToList(){
String id = null;
do{
id = (String)JOptionPane.showInputDialog(frame, "Scan Item(enter 0 to stop)","Return",JOptionPane.PLAIN_MESSAGE);
String queryGames = "SELECT * FROM games where id = "+ id;
String queryMovies = "SELECT * FROM movies where id = " + id;
try {
new Utility().connect();
PreparedStatement gameStmt = new Utility().con.prepareStatement(queryGames);
PreparedStatement movieStmt = new Utility().con.prepareStatement(queryMovies);
ResultSet rsGame = gameStmt.executeQuery();
while (rsGame.next()) {
listModel.addElement(rsGame.getString("title"));
returnedItems[count] = new Game(Integer.parseInt(id), rsGame.getString("title"), rsGame.getInt("rentalPrice"), rsGame.getInt("purchasePrice"));
//CHECK OVERDUE AND MANAGE FEES
//Select the new item and make it visible.
unreturnedItems.setSelectedIndex(count);
unreturnedItems.ensureIndexIsVisible(count);
}
ResultSet rsMovies = movieStmt.executeQuery();
while(rsMovies.next()){
listModel.addElement(rsMovies.getString("Title") + " $" + rsMovies.getInt("rentalPrice"));
returnedItems[count] = new Video(Integer.parseInt(id), rsGame.getString("title"), rsGame.getInt("rentalPrice"), rsGame.getInt("purchasePrice"));
//CHECK OVERDUE AND MANAGE
//Select the new item and make it visible.
unreturnedItems.setSelectedIndex(count);
unreturnedItems.ensureIndexIsVisible(count);
}
count++;
Utility.con.close();
} //end try
catch(ClassNotFoundException e) {
e.printStackTrace();
}
catch(SQLException e) {
e.printStackTrace();
}
}while(!id.equalsIgnoreCase("0"));
}
private void DoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DoneActionPerformed
// TODO add your handling code here:
for(int i= 0; i <count; i++){
if(returnedItems[i].getClass().equals(Game.class)){
control.returnGame((Game)returnedItems[i], member);
}else if(returnedItems[i].getClass().equals(Video.class)){
control.returnVideo((Video)returnedItems[i], member);
}else{
System.err.println("Returned Item entry is was not converted to either Video or Game class");
}
try {
new Utility().returnToMainMenu(employee);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ReturnItem.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(ReturnItem.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_DoneActionPerformed
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ReturnItem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ReturnItem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ReturnItem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ReturnItem.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new ReturnItem().setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(ReturnItem.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
String s = (String)JOptionPane.showInputDialog(frame,"Scan Membership Card\n","Confirm Membership",
JOptionPane.PLAIN_MESSAGE, null, null,null);
try {
memberID.setText(s);
ResultSet rs = new Utility().stmt.executeQuery("SELECT * FROM members WHERE MemberID = " + Integer.parseInt(s));
while(rs.next()){
member = new MemberAccount(Integer.parseInt(s), rs.getString("FirstName"), rs.getString("LastName"),
rs.getString("email"), (int)rs.getLong("PhoneNumber"));
member.setAddress(rs.getString("Address"));
member.setStatus(rs.getString("Status"));
member.setTotalCharge(rs.getFloat("accountBalance"));
accBalance.setText(Double.toString(member.getTotalCharge()));
}
} catch (SQLException ex) {
Logger.getLogger(AdminLoginSuccess.class.getName()).log(Level.SEVERE, null, ex);
}
addItemsToList();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Done;
private static javax.swing.JLabel accBalance;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel7;
private javax.swing.JScrollPane jScrollPane1;
private static javax.swing.JLabel memberID;
private static javax.swing.JList unreturnedItems;
// End of variables declaration//GEN-END:variables
}