-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSignUp.java
More file actions
348 lines (315 loc) · 13.7 KB
/
Copy pathSignUp.java
File metadata and controls
348 lines (315 loc) · 13.7 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import java.sql.*;
import java.util.*;
import java.sql.SQLException;
import java.text.ParseException;
import java.sql.Date;
public class SignUp {
static Scanner scan = new Scanner(System.in);
static int input = -1;
static ResultSet rs = null;
//Declaring and Instantiating all the attribute of a SignUp
static int storeID = 0;
static Date signUpDate = Date.valueOf("0001-01-01");
static int staffID = 0;
static int memberID = 0;
/**
* This method is called in the MainMenu file when the user wants to add/edit/delete/view members in the database.
* @throws ClassNotFoundException
* @throws SQLException
* @throws ParseException
*/
public static void signUpMenu() throws ClassNotFoundException, SQLException, ParseException{
do{
System.out.println("SignUp Menu");
System.out.println();
System.out.println("0. Return to Information Processing Menu");
System.out.println("1. View All SignUps");
System.out.println("2. View SignUp by ID");
System.out.println("3. Add SignUp");
System.out.println("4. Edit SignUp");
System.out.println("5. Delete SignUp");
System.out.println();
System.out.println("Please choose an option from the menu: ");
input = scan.nextInt();
switch(input){
case 0:
System.out.println("Going back to Information Processing Menu");
return;
case 1:
viewAllSignUps();
break;
case 2:
viewSignUp();
break;
case 3:
addSignUp();
break;
case 4:
editSignUp();
break;
case 5:
deleteSignUp();
break;
default:
System.out.println("Invalid input");
break;
}
input = -1;
} while(input != 0);
}
/**
* Method displays all SignUps in the database
*/
public static void viewAllSignUps() throws ClassNotFoundException, SQLException, ParseException{
try{
rs = SignUpSQL.viewAllSignUps();
printSignUp(rs);
}
catch(SQLException e){
System.out.println("SQL Exception");
e.getStackTrace();
}
}
/**
* Method displays information of a single member
*/
public static void viewSignUp() throws ClassNotFoundException, SQLException, ParseException {
do{
System.out.println("In order to go back to SignUp Menu, enter 0");
System.out.println("Please enter a member ID to view a SignUp");
System.out.println();
System.out.println("Member ID: ");
input = scan.nextInt();
scan.nextLine();
if(input > 0){
rs = SignUpSQL.viewSignUp(input);
printSignUp(rs);
rs.close();
} else if(input < 0){
System.out.println("Invalid input");
} else if(input == 0){
System.out.println("Going back to SignUp Menu");
break;
}
} while(input != 0);
}
/**
* Method adds a SignUp information to database by calling the addSignUp in the SignUpSQl file
*/
public static void addSignUp() throws ParseException, ClassNotFoundException, SQLException{
//All the current attributes on the first iteration will be empty, as the user begins to fill in attributes
//of the SignUp the display will be updated. Before the user selects 5, all the attributes must be filled
//so that the SignUp can be created in the database.
do{
System.out.println("0. Go back to Member Menu: ");
System.out.println("1. Store ID: " + memberID);
System.out.println("2. Sign Up Date: " + signUpDate);
System.out.println("3. Staff ID: " + staffID);
System.out.println("4. Member ID: " + memberID);
System.out.println("5. After all attributes have been entered, select 5 to add SignUp:");
System.out.println();
System.out.println("Select a number to add SignUp information: ");
input = scan.nextInt();
scan.nextLine();
updateAttributes(input, "a");
} while(input != 0);
rs.close();
}
/**
* Method edits a member's information to database by calling the editMember in the MemberSQl file
*/
public static void editSignUp() throws ParseException, ClassNotFoundException, SQLException{
int input = 0;
do{
System.out.println("In order to go back to SignUp Menu, enter 0");
System.out.println("Please enter a member ID to edit a SignUp");
input = scan.nextInt();
scan.nextLine();
System.out.println();
//MemberID must be a number greater than 0 so that the application can search for that member.
if(input > 0){
rs = SignUpSQL.viewSignUp(memberID);
//Checks if viewSignUp was able to find an existing SignUp
if(!rs.next()){
System.out.println("SignUp does not exist");
} else{
//The SignUp exist and all the attributes of that SignUp are being stored into variables so
//that they can be displayed to the user. In order for them to choose which attribute to edit.
storeID = rs.getInt("storeID");
signUpDate = rs.getDate("signUpDate");
staffID = rs.getInt("staffID");
memberID = rs.getInt("memberID");
do{
//Attributes are displayed to the user and they must choose which one to edit.
//User will be reprompted these options until they decide to go back to SignUp Menu
System.out.println("0. Go back to Member Menu: ");
System.out.println("1. Store ID: " + memberID);
System.out.println("2. Sign Up Date: " + signUpDate);
System.out.println("3. Staff ID: " + staffID);
System.out.println("4. Member ID: " + memberID);
System.out.println("5. After all attributes have been entered, select 5 to edit SignUp:");
System.out.println();
System.out.println("Select a number to edit SignUp information: ");
input = scan.nextInt();
scan.nextLine();
updateAttributes(input, "e");
} while(input != 0);
}
}
}while(input != 0);
}
/**
* Method deletes a member's information in the database by calling the deleteMember in the MemberSQl file
*/
public static void deleteSignUp(){
do {
System.out.println("In order to go back to SignUp Menu, enter 0");
System.out.println("Please enter a member ID to delete a SignUp");
System.out.println();
System.out.println("Member ID: ");
input = scan.nextInt();
if(input > 0){
SignUpSQL.deleteSignUp(input);
} else if(input < 0){
System.out.println("Invalid input");
} else if (input ==0){
System.out.println("Going back to SignUp Menu");
break;
}
} while(input != 0);
}
/**
* Method is used in all the methods above to print out the information of a SignUp. This method takes in
* a ResultSet and then prints out all the attributes each SignUp of the ResultSet.
* @param rs
* @throws SQLException
*/
public static void printSignUp(ResultSet rs) throws SQLException{
if(!rs.next()){
System.out.println("There is no SignUp with this memberID");
} else{
do{
storeID = rs.getInt("storeID");
signUpDate = rs.getDate("signUpDate");
staffID = rs.getInt("staffID");
memberID = rs.getInt("memberID");
System.out.println("Store ID: " + storeID + ", Sign Up Date: " + signUpDate + ", Staff ID: " + staffID + ", Member ID: "
+ memberID );
} while(rs.next());
}
}
/**
* This method is used to reset all the variables to "", 0, or false
*/
public static void resetAttributes(){
storeID = 0;
signUpDate = Date.valueOf("0001-01-01");
staffID = 0;
memberID = 0;
}
/**
* From option that the user selects, this switch statement will prompt the user for the new value for
* specific attribute.
* Case 5 will take all the updated attributes and update the SignUp in the query. Afterwards, it will
* reset all the variable fields to "" , 0, or false.
* @param input
* @param s
*/
public static void updateAttributes(int input, String s) throws ParseException, ClassNotFoundException, SQLException{
switch(input){
case 0:
System.out.println("Going back to SignUp Menu");
System.out.println();
resetAttributes();
break;
case 1:
System.out.println("Enter Store ID:");
memberID = scan.nextInt();
break;
case 2:
System.out.println("Enter Sign Up Date in the format YYYY-MM-DD:");
signUpDate = Date.valueOf(scan.nextLine());
break;
case 3:
System.out.println("Enter Staff ID:");
staffID = scan.nextInt();
break;
case 4:
System.out.println("Enter Member ID:");
memberID = scan.nextInt();
break;
case 5:
try{
if(s.equals("e")){
SignUpSQL.editSignUp(storeID, signUpDate, staffID, memberID);
}
else if(s.equals("a")){
SignUpSQL.addSignUp(storeID, signUpDate, staffID, memberID);
}
} catch(SQLException e){
System.out.println("SQL Exception");
e.getStackTrace();
break;
}
rs = SignUpSQL.viewSignUp(memberID);
printSignUp(rs);
resetAttributes();
break;
default:
System.out.println("Invalid input");
}
}
public static void memberGrowth() throws ClassNotFoundException, SQLException, ParseException
{
do {
String rangeStart = "0001-01-01";
String rangeEnd = "0001-01-01";
int storeID = -1;
boolean isStore = false; // Is this for a specific store?
System.out.println("Report: Customer Growth");
System.out.println();
System.out.println("0. Return to Reports Menu");
System.out.println("1. View customer growth by month");
System.out.println("2. View customer growth by year");
System.out.println();
System.out.print("Please choose an option from the menu: ");
input = scan.nextInt();
if (input != 0) {
System.out.println("Is this for a specific store? (y/n)");
isStore = scan.next().toLowerCase().equals("y");
}
if (isStore) {
System.out.println("Please enter the ID of the store: ");
storeID = scan.nextInt();
}
switch(input) {
case 0:
System.out.println("Going back to Reports Menu");
return;
case 1:
System.out.println("Please input Start year in the format YYYY");
rangeStart = String.valueOf(scan.nextInt()) + rangeStart.substring(4);
System.out.println("Please input Start month in the format MM");
rangeStart = rangeStart.toString().substring(0, 5) + String.valueOf(scan.nextInt()) + "-01";
System.out.println("Please input End year in the format YYYY");
rangeEnd = String.valueOf(scan.nextInt()) + rangeEnd.substring(4);
System.out.println("Please input End month in the format MM");
rangeEnd = rangeEnd.substring(0, 5) + String.valueOf(scan.nextInt()) + "-01";
break;
case 2:
System.out.println("Please input Start year in the format YYYY");
rangeStart = String.valueOf(scan.nextInt()) + "-01-01";
System.out.println("Please input End year in the format YYYY");
rangeEnd = String.valueOf(scan.nextInt()) + "-01-01";
break;
}
rs = SignUpSQL.growthReport(isStore, storeID, rangeStart, rangeEnd);
rs.next();
if (isStore) {
System.out.println("Total new member sign ups for Store " + storeID + " for period between " + rangeStart + " and " + rangeEnd + ": " + rs.getInt("COUNT(memberID)"));
} else {
System.out.println("Total new member sign ups for period between " + rangeStart + " and " + rangeEnd + ": " + rs.getInt("COUNT(memberID)"));
}
} while (input != 0);
}
}