-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminPage.java
616 lines (537 loc) · 20 KB
/
AdminPage.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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
package OnlineShopping;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.awt.Color;
import javax.swing.JLayeredPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class AdminPage extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable BestSellerTable;
private JTextField prodNum;
private JTextField textField;
private JTextField textField_1;
private JTextField StartDatetext;
private JTextField EndDateField;
private JTable allProdTable;
private JTextField startDateField;
private JTextField endDateField;
private JTable prodwiseRevTable;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AdminPage frame = new AdminPage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public AdminPage() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0, 0, 1301, 704);
contentPane = new JPanel();
contentPane.setBackground(new Color(113, 29, 176));
contentPane.setForeground(new Color(113, 29, 176));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.setBounds(354, 21, 893, 623);
contentPane.add(layeredPane);
layeredPane.setLayout(null);
JPanel productwiseRevenuePanel = new JPanel();
productwiseRevenuePanel.setForeground(new Color(225, 210, 63));
productwiseRevenuePanel.setLayout(null);
productwiseRevenuePanel.setBackground(new Color(59, 52, 132));
productwiseRevenuePanel.setBounds(0, 0, 893, 623);
layeredPane.add(productwiseRevenuePanel);
JPanel TotalItemsPanel = new JPanel();
TotalItemsPanel.setLayout(null);
TotalItemsPanel.setBackground(new Color(59, 52, 132));
TotalItemsPanel.setBounds(0, 0, 893, 623);
layeredPane.add(TotalItemsPanel);
JPanel highestSalePanel = new JPanel();
highestSalePanel.setBounds(0, 0, 893, 623);
layeredPane.add(highestSalePanel);
highestSalePanel.setBackground(new Color(59, 52, 132));
highestSalePanel.setLayout(null);
JPanel Revenuepanel = new JPanel();
Revenuepanel.setBounds(74, 0, 893, 623);
layeredPane.add(Revenuepanel);
Revenuepanel.setLayout(null);
Revenuepanel.setBackground(new Color(59, 52, 132));
layeredPane.removeAll();
JLabel lblNumProd = new JLabel("Enter Number of top products: \r\n");
lblNumProd.setForeground(new Color(255, 210, 63));
lblNumProd.setFont(new Font("Segoe UI", Font.BOLD, 20));
lblNumProd.setBounds(54, 63, 299, 52);
highestSalePanel.add(lblNumProd);
prodNum = new JTextField();
prodNum.setBounds(64, 126, 265, 40);
highestSalePanel.add(prodNum);
prodNum.setColumns(10);
JButton btnRevenue = new JButton("Show Revenue");
btnRevenue.setForeground(new Color(255, 210, 63));
btnRevenue.setBackground(new Color(94, 22, 117));
btnRevenue.setFont(new Font("Segoe UI", Font.BOLD, 15));
btnRevenue.setBounds(63, 35, 191, 79);
contentPane.add(btnRevenue);
btnRevenue.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
layeredPane.removeAll();
layeredPane.add(Revenuepanel);
layeredPane.repaint();
layeredPane.revalidate();
// TODO Auto-generated method stub
}});
JButton btnHighestSelling = new JButton("Best Sellers ");
btnHighestSelling.setForeground(new Color(255, 210, 63));
btnHighestSelling.setFont(new Font("Segoe UI", Font.BOLD, 15));
btnHighestSelling.setBackground(new Color(94, 22, 117));
btnHighestSelling.setBounds(63, 155, 191, 79);
contentPane.add(btnHighestSelling);
btnHighestSelling.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
layeredPane.removeAll();
layeredPane.add(highestSalePanel);
layeredPane.repaint();
layeredPane.revalidate();
// TODO Auto-generated method stub
}
});
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(54, 220, 496, 359);
highestSalePanel.add(scrollPane);
JButton btnProdNum = new JButton("Enter");
btnProdNum.setForeground(new Color(64, 0, 128));
btnProdNum.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnProdNum.setBackground(new Color(255, 210, 63));
btnProdNum.setBounds(373, 114, 118, 52);
btnProdNum.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
String prod=prodNum.getText();
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="Call highest_selling_products("+prod+");";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
ResultSetMetaData rsmdt=rs1.getMetaData();
DefaultTableModel m=(DefaultTableModel) BestSellerTable.getModel();
m.setRowCount(0);
int c=rsmdt.getColumnCount();
String [] colnames=new String[c];
for (int i=0; i<c; i++)
{
colnames[i]=rsmdt.getColumnName(i+1);
}
m.setColumnIdentifiers(colnames);
while(rs1.next())
{
String [] row= new String[c];
for(int i=1; i<=c; i++)
{
row[i-1]=rs1.getString(i);
}
m.addRow(row);
}
conn.close();
pstmt.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
highestSalePanel.add(btnProdNum);
BestSellerTable = new JTable();
BestSellerTable.setBackground(new Color(59, 52, 132));
BestSellerTable.setForeground(new Color(225, 210, 63));
scrollPane.setViewportView(BestSellerTable);
textField = new JTextField();
textField.setColumns(10);
textField.setBounds(197, 83, 185, 36);
Revenuepanel.add(textField);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(197, 135, 185, 36);
Revenuepanel.add(textField_1);
JLabel lblAmt = new JLabel("");
lblAmt.setForeground(new Color(255, 210, 63));
lblAmt.setFont(new Font("Segoe UI", Font.BOLD, 20));
lblAmt.setBackground(new Color(59, 52, 132));
lblAmt.setBounds(449, 393, 289, 95);
Revenuepanel.add(lblAmt);
JLabel lblStartDate = new JLabel("Enter Start Date: ");
lblStartDate.setForeground(new Color(255, 210, 63));
lblStartDate.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblStartDate.setBackground(new Color(59, 52, 132));
lblStartDate.setBounds(68, 105, 119, 14);
Revenuepanel.add(lblStartDate);
JLabel lblEndDate = new JLabel("Enter End Date: ");
lblEndDate.setForeground(new Color(255, 210, 63));
lblEndDate.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblEndDate.setBackground(new Color(59, 52, 132));
lblEndDate.setBounds(68, 145, 119, 14);
Revenuepanel.add(lblEndDate);
JButton btnNodate = new JButton("Display All time Revenue");
btnNodate.setForeground(new Color(64, 0, 128));
btnNodate.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnNodate.setBackground(new Color(255, 210, 63));
btnNodate.setBounds(498, 65, 240, 54);
btnNodate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="call total_revenue();";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
while(rs1.next())
{
lblAmt.setText(rs1.getString(1));;
}
conn.close();
pstmt.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Revenuepanel.add(btnNodate);
JButton btnDate = new JButton("Display Revenue with dates");
btnDate.setForeground(new Color(64, 0, 128));
btnDate.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnDate.setBackground(new Color(255, 210, 63));
btnDate.setBounds(498, 147, 240, 54);
btnDate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String start=textField.getText();
String end=textField_1.getText();
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="call total_revenue_bydate('"+start+"', '"+end+"');";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
while(rs1.next())
{
lblAmt.setText(rs1.getString(1));;
}
conn.close();
pstmt.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Revenuepanel.add(btnDate);
JLabel lblTheRevenueGenerated = new JLabel("The revenue generated is Rs. ");
lblTheRevenueGenerated.setForeground(new Color(255, 210, 63));
lblTheRevenueGenerated.setFont(new Font("Segoe UI", Font.BOLD, 20));
lblTheRevenueGenerated.setBackground(new Color(59, 52, 132));
lblTheRevenueGenerated.setBounds(157, 393, 289, 95);
Revenuepanel.add(lblTheRevenueGenerated);
JButton btnTotalSales = new JButton("Total Items Sold");
btnTotalSales.setForeground(new Color(255, 210, 63));
btnTotalSales.setFont(new Font("Segoe UI", Font.BOLD, 15));
btnTotalSales.setBackground(new Color(94, 22, 117));
btnTotalSales.setBounds(63, 274, 191, 79);
contentPane.add(btnTotalSales);
btnTotalSales.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
layeredPane.removeAll();
layeredPane.add(TotalItemsPanel);
layeredPane.repaint();
layeredPane.revalidate();
// TODO Auto-generated method stub
}
});
StartDatetext = new JTextField();
StartDatetext.setColumns(10);
StartDatetext.setBounds(197, 83, 185, 36);
TotalItemsPanel.add(StartDatetext);
EndDateField = new JTextField();
EndDateField.setColumns(10);
EndDateField.setBounds(197, 135, 185, 36);
TotalItemsPanel.add(EndDateField);
JLabel lblStartDate_1 = new JLabel("Enter Start Date: ");
lblStartDate_1.setForeground(new Color(255, 210, 63));
lblStartDate_1.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblStartDate_1.setBackground(new Color(59, 52, 132));
lblStartDate_1.setBounds(68, 105, 119, 14);
TotalItemsPanel.add(lblStartDate_1);
JLabel lblEndDate_1 = new JLabel("Enter End Date: ");
lblEndDate_1.setForeground(new Color(255, 210, 63));
lblEndDate_1.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblEndDate_1.setBackground(new Color(59, 52, 132));
lblEndDate_1.setBounds(68, 145, 119, 14);
TotalItemsPanel.add(lblEndDate_1);
JButton btnDisplayAllProducts = new JButton("Display All Products Sold");
btnDisplayAllProducts.setForeground(new Color(64, 0, 128));
btnDisplayAllProducts.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnDisplayAllProducts.setBackground(new Color(255, 210, 63));
btnDisplayAllProducts.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String start=StartDatetext.getText();
String end=EndDateField.getText();
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="call total_sales_bydate('"+start+"', '"+end+"');";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
ResultSetMetaData rsmdt=rs1.getMetaData();
DefaultTableModel m=(DefaultTableModel) allProdTable.getModel();
m.setRowCount(0);
int c=rsmdt.getColumnCount();
String [] colnames=new String[c];
for (int i=0; i<c; i++)
{
colnames[i]=rsmdt.getColumnName(i+1);
}
m.setColumnIdentifiers(colnames);
while(rs1.next())
{
String [] row= new String[c];
for(int i=1; i<=c; i++)
{
row[i-1]=rs1.getString(i);
}
m.addRow(row);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
btnDisplayAllProducts.setBounds(498, 105, 240, 54);
TotalItemsPanel.add(btnDisplayAllProducts);
JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setBounds(87, 209, 651, 355);
TotalItemsPanel.add(scrollPane_1);
allProdTable = new JTable();
allProdTable.setBackground(new Color(59, 52, 132));
allProdTable.setForeground(new Color(225, 210, 63));
scrollPane_1.setViewportView(allProdTable);
JButton btnProductwiseSales = new JButton("Productwise Sales");
btnProductwiseSales.setForeground(new Color(255, 210, 63));
btnProductwiseSales.setFont(new Font("Segoe UI", Font.BOLD, 15));
btnProductwiseSales.setBackground(new Color(94, 22, 117));
btnProductwiseSales.setBounds(63, 407, 191, 79);
btnProductwiseSales.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
layeredPane.removeAll();
layeredPane.add(productwiseRevenuePanel);
layeredPane.repaint();
layeredPane.revalidate();
// TODO Auto-generated method stub
}
});
contentPane.add(btnProductwiseSales);
startDateField = new JTextField();
startDateField.setColumns(10);
startDateField.setBounds(197, 83, 185, 36);
productwiseRevenuePanel.add(startDateField);
endDateField = new JTextField();
endDateField.setColumns(10);
endDateField.setBounds(197, 135, 185, 36);
productwiseRevenuePanel.add(endDateField);
JLabel lblStartDate_1_1 = new JLabel("Enter Start Date: ");
lblStartDate_1_1.setForeground(new Color(255, 210, 63));
lblStartDate_1_1.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblStartDate_1_1.setBackground(new Color(59, 52, 132));
lblStartDate_1_1.setBounds(68, 105, 119, 14);
productwiseRevenuePanel.add(lblStartDate_1_1);
JLabel lblEndDate_1_1 = new JLabel("Enter End Date: ");
lblEndDate_1_1.setForeground(new Color(255, 210, 63));
lblEndDate_1_1.setFont(new Font("Segoe UI", Font.BOLD, 13));
lblEndDate_1_1.setBackground(new Color(59, 52, 132));
lblEndDate_1_1.setBounds(68, 145, 119, 14);
productwiseRevenuePanel.add(lblEndDate_1_1);
JButton btnproductsWithDate = new JButton("Display Productwise Revenue ");
btnproductsWithDate.setForeground(new Color(64, 0, 128));
btnproductsWithDate.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnproductsWithDate.setBackground(new Color(255, 210, 63));
btnproductsWithDate.setBounds(478, 52, 295, 54);
productwiseRevenuePanel.add(btnproductsWithDate);
btnproductsWithDate.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="call product_wise_revenue();";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
ResultSetMetaData rsmdt=rs1.getMetaData();
DefaultTableModel m=(DefaultTableModel) prodwiseRevTable.getModel();
m.setRowCount(0);
int c=rsmdt.getColumnCount();
String [] colnames=new String[c];
for (int i=0; i<c; i++)
{
colnames[i]=rsmdt.getColumnName(i+1);
}
m.setColumnIdentifiers(colnames);
while(rs1.next())
{
String [] row= new String[c];
for(int i=1; i<=c; i++)
{
row[i-1]=rs1.getString(i);
}
m.addRow(row);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton btnDisplayProductwiseRevenue = new JButton("Display Productwise Revenue with date");
btnDisplayProductwiseRevenue.setForeground(new Color(64, 0, 128));
btnDisplayProductwiseRevenue.setFont(new Font("Segoe UI", Font.BOLD, 13));
btnDisplayProductwiseRevenue.setBackground(new Color(255, 210, 63));
btnDisplayProductwiseRevenue.setBounds(478, 125, 295, 54);
btnDisplayProductwiseRevenue.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String start=startDateField.getText();
String end=endDateField.getText();
ResultSet rs1=null;
String DB_URL = "jdbc:mysql://127.0.0.1:3306/miniproj?autoReconnect=true&useSSL=false";
String USER = "root";
String PASS = "root";
Connection conn=null;
try {
PreparedStatement pstmt=null;
String query="call product_wise_revenue_bydate('"+start+"', '"+end+"');";
conn=DriverManager.getConnection(DB_URL, USER, PASS);
pstmt=conn.prepareStatement(query);
rs1=pstmt.executeQuery(query);
ResultSetMetaData rsmdt=rs1.getMetaData();
DefaultTableModel m=(DefaultTableModel) prodwiseRevTable.getModel();
m.setRowCount(0);
int c=rsmdt.getColumnCount();
String [] colnames=new String[c];
for (int i=0; i<c; i++)
{
colnames[i]=rsmdt.getColumnName(i+1);
}
m.setColumnIdentifiers(colnames);
while(rs1.next())
{
String [] row= new String[c];
for(int i=1; i<=c; i++)
{
row[i-1]=rs1.getString(i);
}
m.addRow(row);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
productwiseRevenuePanel.add(btnDisplayProductwiseRevenue);
JScrollPane scrollPane_2 = new JScrollPane();
scrollPane_2.setBounds(68, 237, 762, 335);
productwiseRevenuePanel.add(scrollPane_2);
prodwiseRevTable = new JTable();
prodwiseRevTable.setForeground(new Color(225, 210, 63));
prodwiseRevTable.setBackground(new Color(59, 52, 132));
scrollPane_2.setViewportView(prodwiseRevTable);
JButton BackButton = new JButton("<= BACK");
BackButton.setForeground(new Color(255, 210, 63));
BackButton.setFont(new Font("Segoe UI", Font.BOLD, 15));
BackButton.setBackground(new Color(128, 0, 0));
BackButton.setBounds(37, 591, 133, 53);
BackButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
new AdminLoginPage().setVisible(true);
}
});
contentPane.add(BackButton);
}
}