-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaySalary.java
489 lines (376 loc) · 12.8 KB
/
PaySalary.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
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class PaySalary extends JFrame implements MouseListener{
public static void main(String args[])
{
PaySalary obj = new PaySalary(1001);
obj.setVisible(true);
}
private JLabel LabelTitle,WelcomeLabel, LabelInstructorID, LabelBill,LabelBackGroundImage;
private JLabel LabelPaidDate, LabelPDD, LabelPMM, LabelPYYYY;
private JTextField InstructorIDTF, InstructorBillTF;
private JSpinner spinnerPDD, spinnerPMM, spinnerPYYYY;
private SpinnerModel valuePDD, valuePMM, valuePYYYY;
private JButton buttonReciveBill, buttonBack;
private JPanel panel;
private String PaidDate, Status, queryTransaction;
private int PMonth, PYear, transactionNo=100;
private double Salary, Fee;
private int AdminId, InstructorId, count;
private boolean flagTransactionDate=true, flagDB,flagCount;
public PaySalary(int AdminId)
{
super("Pay Salary");
Color lightButton = new Color(71, 92, 150);
Color lightBlue = new Color(172, 166, 255);
this.setSize(600, 650);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(null);
panel.setBackground(Color.WHITE);
ImageIcon img = new ImageIcon("icon.jpg");
this.setIconImage(img.getImage());
LabelBackGroundImage = new JLabel();
LabelBackGroundImage.setBounds(0,0, 600,180);
ImageIcon imgThisImg = new ImageIcon("logInBackground.JPG");
LabelBackGroundImage.setIcon(imgThisImg);
panel.add(LabelBackGroundImage);
this.AdminId=AdminId;
Status="Instructor";
LabelTitle = new JLabel("Pay Instructor Salary");
LabelTitle.setFont(new Font("Tahoma", Font.PLAIN, 19));
LabelTitle.setForeground(Color.BLACK);
LabelTitle.setBounds(212,190,250,30);
panel.add(LabelTitle);
LabelInstructorID = new JLabel("Enter Instructor Id :");
LabelInstructorID.setBounds(120, 250, 150, 25);
LabelInstructorID.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelInstructorID.setForeground(Color.BLACK);
panel.add(LabelInstructorID);
InstructorIDTF = new JTextField();
InstructorIDTF.setBounds(300, 250, 135, 25);
panel.add(InstructorIDTF);
LabelInstructorID = new JLabel("Enter Amount :");
LabelInstructorID.setBounds(120, 290, 150, 25);
LabelInstructorID.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelInstructorID.setForeground(Color.BLACK);
panel.add(LabelInstructorID);
InstructorBillTF = new JTextField();
InstructorBillTF.setBounds(300, 290, 135, 25);
panel.add(InstructorBillTF);
LabelPaidDate = new JLabel("Payment Date : ");
LabelPaidDate.setBounds(120, 330, 125, 25);
LabelPaidDate.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelPaidDate.setForeground(Color.BLACK);
panel.add(LabelPaidDate);
LabelPDD = new JLabel("DD");
LabelPDD.setFont(new Font("Tahoma", Font.PLAIN, 12));
//LabelPDD.setForeground(Color.GRAY);
LabelPDD.setBounds(230, 333, 20, 20);
panel.add(LabelPDD);
LabelPMM = new JLabel("MM");
LabelPMM.setFont(new Font("Tahoma", Font.PLAIN, 12));
//LabelPMM.setForeground(Color.GRAY);
LabelPMM.setBounds(300, 333, 20, 20);
panel.add(LabelPMM);
LabelPYYYY = new JLabel("YYYY");
LabelPYYYY.setFont(new Font("Tahoma", Font.PLAIN, 12));
//LabelPYYYY.setForeground(Color.GRAY);
LabelPYYYY.setBounds(370, 333, 40, 20);
panel.add(LabelPYYYY);
valuePDD = new SpinnerNumberModel(1, //initial value
1, //minimum value
31, //maximum value
1); //step
valuePMM = new SpinnerNumberModel(1, //initial value
1, //minimum value
12, //maximum value
1); //step
valuePYYYY = new SpinnerNumberModel(2017, //initial value
2017, //minimum value
3000, //maximum value
1); //step
spinnerPDD = new JSpinner(valuePDD);
spinnerPDD.setBounds(250,333,35,20);
spinnerPDD.addMouseListener(this);
JFormattedTextField tfpd = ((JSpinner.DefaultEditor)spinnerPDD.getEditor()).getTextField();
tfpd.setEditable(false);
panel.add(spinnerPDD);
spinnerPMM = new JSpinner(valuePMM);
spinnerPMM.setBounds(323,333,35,20);
spinnerPMM.addMouseListener(this);
JFormattedTextField tfpm = ((JSpinner.DefaultEditor)spinnerPMM.getEditor()).getTextField();
tfpm.setEditable(false);
panel.add(spinnerPMM);
spinnerPYYYY = new JSpinner(valuePYYYY);
spinnerPYYYY.setBounds(413,333,50,20);
spinnerPYYYY.addMouseListener(this);
JFormattedTextField tfpy = ((JSpinner.DefaultEditor)spinnerPYYYY.getEditor()).getTextField();
tfpy.setEditable(false);
panel.add(spinnerPYYYY);
buttonReciveBill = new JButton("Pay Salary");
buttonReciveBill.setBounds(150,400,120,30);
buttonReciveBill.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonReciveBill.setForeground(Color.BLACK);
buttonReciveBill.setBackground(lightButton);
buttonReciveBill.addMouseListener(this);
panel.add(buttonReciveBill);
buttonBack = new JButton("BACK");
buttonBack.setBounds(300,400,120,30);
buttonBack.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonBack.setForeground(Color.BLACK);
buttonBack.setBackground(lightButton);
buttonBack.addMouseListener(this);
panel.add(buttonBack);
WelcomeLabel = new JLabel(" Logged in as : Admin");
WelcomeLabel.setBounds(215, 520, 200, 20);
WelcomeLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
WelcomeLabel.setForeground(Color.BLACK);
panel.add(WelcomeLabel);
WelcomeLabel = new JLabel(" ID : "+AdminId);
WelcomeLabel.setBounds(255, 550, 200, 20);
WelcomeLabel.setFont(new Font("Tahoma", Font.PLAIN, 15));
WelcomeLabel.setForeground(Color.BLACK);
panel.add(WelcomeLabel);
this.add(panel);
}//end of constructor
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
JButton b = (JButton) me.getComponent();
if(b==buttonReciveBill)
{
if(InstructorBillTF.getText().isEmpty())
{
JOptionPane.showMessageDialog(this, "Please Enter Amount");
}
System.out.println("buttonReciveBill");
try{
InstructorId=Integer.parseInt(InstructorIDTF.getText());
Salary=Double.parseDouble(InstructorBillTF.getText());
}catch(Exception ex){}
getPaidDate();
CheckInstructorId();
if(flagCount)
{
CheckTransaction();
CheckTransactionNo();
if(flagTransactionDate)
{System.out.println("call into db");
insertIntoDB();
Back();}
}
else
{
JOptionPane.showMessageDialog(this, "Instructor Not Found");
}
}
else if(b==buttonBack)
{
System.out.println("buttonBack");
AdminFinancialManage fin = new AdminFinancialManage(1001);
try{
this.setVisible(false);
fin.setVisible(true);
}catch(Exception ex){}
}
}
public void getPaidDate()
{
Integer PDD = (Integer)spinnerPDD.getValue();
String ConvertPDD = Integer.toString(PDD);
Integer PMM = (Integer)spinnerPMM.getValue();
String ConvertPMM = Integer.toString(PMM);
PMonth=PMM;
Integer PYYYY = (Integer)spinnerPYYYY.getValue();
String ConvertPYYYY = Integer.toString(PYYYY);
PYear=PYYYY;
PaidDate = ConvertPDD+"/"+ConvertPMM+"/"+ConvertPYYYY ;
}
public void insertIntoDB()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/group8f", "root", "");
Statement stm = con.createStatement();
stm.execute(queryTransaction);
flagDB=true;
stm.close();
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, "Exception : " +ex.getMessage());
System.out.println("Exception : " +ex.getMessage());
flagDB=false;
}
}
public void CheckInstructorId()
{
String queryInstructorId ="SELECT `UserId` FROM `instructoracc` WHERE UserId ="+ InstructorId+";";
Connection con=null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
rs = st.executeQuery(queryInstructorId);
System.out.println("results received");
while(rs.next())
{
int mID = rs.getInt("UserId");
if(InstructorId==mID){
flagCount=true;
}
}
System.out.println("Instructor count "+flagCount);
}
catch(Exception ex)
{
System.out.println("Exception : " +ex.getMessage());
}
finally
{
try
{
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(con!=null)
con.close();
}
catch(Exception ex){}
}
}
public void Back()
{
if(flagDB)
{
JOptionPane.showMessageDialog(this,"Payment Success");
UpdateAccount();
System.out.println("buttonBack");
AdminHome admin = new AdminHome(AdminId);
try{
this.setVisible(false);
admin.setVisible(true);
}catch(Exception ex){}
}
}
public void CheckTransaction()
{
String queryTransactionDate ="SELECT `AccountId`, `Status` ,`Month` , `Year` FROM `transaction` WHERE AccountId ="+ InstructorId+";";
Connection con=null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
rs = st.executeQuery(queryTransactionDate);
System.out.println("results received");
while(rs.next())
{
System.out.println("loop");
int m = rs.getInt("Month");
int y = rs.getInt("Year");
int id = rs.getInt("AccountId");
if(InstructorId==id && PMonth==m && PYear==y)
{ System.out.println("SAME id "+id +"Pmonth"+PMonth+" m "+m+"Pyear" +PYear+" yy"+y);
JOptionPane.showMessageDialog(this," Already DOne");
flagTransactionDate=false;
AdminFinancialManage fin = new AdminFinancialManage(AdminId);
try{
this.setVisible(false);
fin.setVisible(true);
}catch(Exception ex){}
}
}
}
catch(Exception ex)
{
System.out.println("Exception : " +ex.getMessage());
flagTransactionDate=false;
}
finally
{
try
{
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(con!=null)
con.close();
}
catch(Exception ex){}
}
}
public void CheckTransactionNo()
{
String queryTransactionNo = "SELECT `TransactionNo` FROM transaction ORDER BY `TransactionNo` DESC LIMIT 1;";
Connection con=null;
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
rs = st.executeQuery(queryTransactionNo);
System.out.println("results received");
if(rs.next()){
int t = rs.getInt("TransactionNo");
transactionNo=t+1;
}
System.out.println("TransactionNo: "+ transactionNo);
queryTransaction = "INSERT INTO transaction VALUES ("+transactionNo+","+InstructorId+",'"+Status+"',"+Fee+","+Salary+","+PMonth+","+PYear+",'"+PaidDate+"',"+AdminId+");";
}
catch(Exception ex)
{
System.out.println("Error:xxx "+ ex.getMessage());
queryTransaction = "INSERT INTO transaction VALUES ("+transactionNo+","+InstructorId+",'"+Status+"',"+Fee+","+Salary+","+PMonth+","+PYear+",'"+PaidDate+"',"+AdminId+");";
System.out.println("TransactionNo:xxx "+ transactionNo);
}
}
public void UpdateAccount()
{
Connection con =null;
Statement st = null;
String queryForUpdate = "UPDATE accounts SET Validity= 'Valid' where UserId="+InstructorId;
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
st.executeUpdate(queryForUpdate);
JOptionPane.showMessageDialog(this, "Account Now Valid");
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
}