-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
266 lines (260 loc) · 9.56 KB
/
User.java
File metadata and controls
266 lines (260 loc) · 9.56 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
import java.util.Scanner;
public class User extends DataBase
{
Scanner in =new Scanner(System.in);
Scanner in1 =new Scanner(System.in);
User (){
super();
}
String username,password,acno=null,acno1=null;
public void login(){
System.out.println("*********************************");
System.out.println("*--------- USER LOGIN ---------*");
System.out.println("*********************************");
System.out.print("Enter Username : ");
username=in1.nextLine();
System.out.print("Enter Password : ");
password=in1.nextLine();
this.check();
}
private void check(){
try{
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `users` WHERE username='"+username+"'AND password='"+password+"'");
if(re.next()){
acno=re.getString("acno");
this.clearScreen();
this.umenu();
}
else{
this.clearScreen();
System.out.println("*********************************");
System.out.println("* Username Or Password is Wrong *");
System.out.println("* TryAgain Or Contact Admin *");
System.out.println("*********************************");
Login l=new Login();
}
}catch(Exception e){
System.out.println(e);
}
}
public void umenu(){
if((username!=null&&password!=null)||acno!=null){
int a=0;
System.out.println("\n********Welcome ************");
System.out.println("* Menu *");
System.out.println("* 1.Display Detials *");
System.out.println("* 2.Balance Enquary *");
System.out.println("* 3.Transaction History *");
System.out.println("* 4.Money Transfer *");
if(username==null&&password==null)
{
System.out.println("* 5.Back *");
}
else{
System.out.println("* 5.Change Password *");
System.out.println("* 6.Logout *");
}
System.out.println("****************************");
System.out.print("Enter Your Choise : ");
a=in.nextInt();
switch(a){
case 1:
this.display();
break;
case 2:
this.balanceEnquary();
break;
case 3:
this.accountHistory();
break;
case 4:
this.moneyTransfer();
break;
case 5 : if(username==null&&password==null)
{
this.clearScreen();
Admin a1=new Admin();
a1.amenu();
}
else{
this.changePassword();
}
break;
case 6:
if(username==null&&password==null)
{
System.out.println("*****************");
System.out.println("* Wrong Choise *");
System.out.println("*****************");
this.umenu();
}
else{
this.clearScreen();
username=null;
password=null;
acno=null;
Login l=new Login();
}
break;
default:System.out.println("*****************");
System.out.println("* Wrong Choise *");
System.out.println("*****************");
this.umenu();
break;
}
}
}
private void display(){
try{
this.clearScreen();
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `users` WHERE acno='"+acno+"'");
if(re.next()){
System.out.println("***********************************************************");
System.out.println("* Account Holder NAME \t: "+re.getString("name"));
System.out.println("* Account Number\t: "+re.getString("acno"));
System.out.println("* Email \t\t: "+re.getString("email"));
System.out.println("* Phone Number \t\t: "+re.getString("phone"));
System.out.println("* Adderss \t\t: "+re.getString("address"));
System.out.println("* Account Type \t\t: "+re.getString("actype"));
System.out.println("* Branch \t\t: "+re.getString("branch"));
System.out.println("* Balance \t\t: "+re.getString("balance"));
System.out.println("**********************************************************");
this.umenu();
}
}catch(Exception e){
System.out.println(e);
}
}
private void balanceEnquary(){
try {
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `users` WHERE acno='"+acno+"'");
if(re.next()){
this.clearScreen();
System.out.println("*********************************************");
System.out.println("* Balance In Account : "+re.getString("balance"));
System.out.println("*********************************************");
}
this.umenu();
} catch (Exception e) {
System.out.println(e);
}
}
private void accountHistory(){
try {
this.clearScreen();
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `"+acno+"`");
System.out.println("*****************************************************************************************");
System.out.println("Credited/Debited \t Reason \t\t Amount \t Balance");
while(re.next()){
System.out.println(re.getString("cd")+"\t \t "+re.getString("reason")+"\t\t" +re.getString("amount")+" \t\t"+re.getString("balance"));
}
System.out.println("****************************************************************************************");
this.umenu();
} catch (Exception e) {
System.out.println(e);
}
}
private void moneyTransfer(){
int balance=0,bal=0,balance1=0;
System.out.print("Enter Account Number : ");
acno1=in1.nextLine();
try{
if(acno.equals(acno1)){
this.clearScreen();
System.out.println("*****************************************");
System.out.println("* Same Account Transaction Not Possible *");
System.out.println("*****************************************");
this.umenu();
}
else{
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `users` WHERE acno='"+acno+"'");
if(re.next()){
balance=re.getInt("balance");
}
re=stm.executeQuery("SELECT * FROM `users` WHERE acno='"+acno1+"'");
if(re.next()){
balance1=re.getInt("balance");
System.out.print("Enter Amount to be Transfered : ");
bal=in.nextInt();
}
else{
this.clearScreen();
System.out.println("****************************");
System.out.println("* Account Number Not Found *");
System.out.println("****************************");
this.umenu();
}
if(balance<bal)
{
this.clearScreen();
System.out.println("+++++++++++++++++++++++");
System.out.println("+ Insufficent Balance +");
System.out.println("+++++++++++++++++++++++");
this.umenu();
}
else{
balance=balance-bal;
balance1=balance1+bal;
stm.executeUpdate("UPDATE `users` SET `balance`='"+balance+"' WHERE acno='"+acno+"'");
stm.executeUpdate("UPDATE `users` SET `balance`='"+balance1+"' WHERE acno='"+acno1+"'");
st=con.prepareStatement("INSERT INTO `"+acno+"`( `cd`,`amount`,`reason`, `balance`) VALUES ('Debited.','"+bal+"','Transfer','"+balance+"')");
st.executeUpdate();
st=con.prepareStatement("INSERT INTO `"+acno1+"`( `cd`,`amount`,`reason`, `balance`) VALUES ('Credited','"+bal+"','Transfer','"+balance1+"')");
st.executeUpdate();
this.clearScreen();
System.out.println("+++++++++++++++++++++++");
System.out.println("+ Transaction Success +");
System.out.println("+++++++++++++++++++++++");
this.umenu();
}
}
}catch(Exception e){
System.out.println(e);
}
}
private void changePassword(){
System.out.print("Enter Current Password : ");
String password0=in1.nextLine();
System.out.print("Enter New Password : ");
String password1=in1.nextLine();
System.out.print("Confirm Password : ");
String password2=in1.nextLine();
try{ if(password1.equals(password2))
{
stm=con.createStatement();
re=stm.executeQuery("SELECT * FROM `users` WHERE username='"+username+"'AND password='"+password0+"'");
if(re.next()){
this.clearScreen();
stm.executeUpdate("UPDATE `users` SET `password`='"+password1+"'WHERE username='"+username+"'AND password='"+password0+"'");
System.out.println("********************************");
System.out.println("* Passwords Reset Successfully *");
System.out.println("********************************");
password=password1;
this.umenu();
}
else{
this.clearScreen();
System.out.println("********************************");
System.out.println("* CURRENT PASSWORD IS WRONG *");
System.out.println("********************************");
username=null;password=null;
Login l=new Login();
}
}
else{
this.clearScreen();
System.out.println("*********************************");
System.out.println("* Two Passwords are not Matched *");
System.out.println("*********************************");
this.umenu();
}
}catch(Exception ex){
System.out.println(ex);
}
}
}