-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
124 lines (82 loc) · 2.13 KB
/
Menu.java
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
package menu;
import java.util.Scanner;
import context.UnitOfWork;
import model.User;
import services.ManagerRepository;
import sha.GFG;
import show.CustomerShow;
import show.EmployeeShow;
import show.ManagerShow;
import show.UserShow;
public class Menu {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
Menu menu = new Menu();
menu.menuBar();
}
private void menuBar() {
int selected = -1;
while (selected != 0) {
System.out.println("------------***------------");
System.out.println("1.Login\n"
// + "2.\n"
+ "0.exit");
String check = scanner.nextLine();
selected = check_int(check);
switch (selected) {
case 1:
login();
break;
}
}
}
private void login() {
System.out.println("------------Login------------");
System.out.print("User name : ");
String username = scanner.nextLine();
User user = null;
try(UnitOfWork db = new UnitOfWork()) {
ManagerRepository manager = db.ManagerRepository();
user = (User) manager.GetAllByUsername(username);
}
if(user != null) {
System.out.print("password : ");
String password = scanner.nextLine();
password = GFG.convert(password);
if(password.equals(user.getPassword())) {
UserShow userShow;
switch (user.getTypeId()) {
case 1:
userShow = new ManagerShow();
userShow.show(user);
break;
case 2:
userShow = new EmployeeShow();
userShow.show(user);
break;
case 3:
userShow = new CustomerShow();
userShow.show(user);
break;
}
}
else {
PrintWarning("Wrong Password");
}
}
else {
PrintWarning("Wrong User Name");
}
}
protected int check_int(String check) {
try {
return Integer.parseInt(check);
} catch (Exception e) {
PrintWarning("Please Enter Numbers in the Menu");
return -1;
}
}
protected void PrintWarning(String warning) {
System.out.println("\n*** " + warning + " ***\n");
}
}