-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.java
3543 lines (2962 loc) · 156 KB
/
application.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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import com.toedter.calendar.JDateChooser;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class application {
private static String jdbcURL = "jdbc:mysql://localhost:3306/";
private static String dbName = "billing_system";
private static String dbUser = "root";
private static String dbPassword = "nabh1005";
private static Connection connection;
private static void createDatabase(Connection connection, String dbName) throws Exception {
Statement createDbStatement = connection.createStatement();
String createDbQuery = "CREATE DATABASE IF NOT EXISTS " + dbName;
createDbStatement.executeUpdate(createDbQuery);
}
private static void createLoginTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS login ( Company_Name VARCHAR(100) BINARY NOT NULL, User_Name VARCHAR(50) BINARY NOT NULL, Paswrd VARCHAR(50) BINARY NOT NULL )";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createCustomersTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS customers ( Customer_Id INT AUTO_INCREMENT PRIMARY KEY, Customer_Name VARCHAR(50) NOT NULL, Customer_Company VARCHAR(100), GSTIN VARCHAR(15), Phone_Number VARCHAR(13), Email VARCHAR(50), Address VARCHAR(200) )";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createItemStockTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS item_stock ( Item_Id INT AUTO_INCREMENT PRIMARY KEY, Item_Name VARCHAR(100) UNIQUE NOT NULL, Item_Stock INT DEFAULT 0)";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createOrdersTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS orders ( Order_Id INT AUTO_INCREMENT PRIMARY KEY, Order_Date DATE DEFAULT (CURDATE()), Customer_Id INT NOT NULL, Order_Status VARCHAR(20) NOT NULL, FOREIGN KEY (Customer_Id) REFERENCES customers(Customer_Id) )";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createBillsTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS bills ( Bill_Id INT PRIMARY KEY, Order_Id INT NOT NULL, Date DATE DEFAULT (CURDATE()), Time TIME DEFAULT (CURTIME()), Customer_Id INT NOT NULL, Shipping_Address VARCHAR(200) NOT NULL, tax_percentage INT, User_Name VARCHAR(50) NOT NULL, FOREIGN KEY (Order_Id) REFERENCES orders(Order_Id), FOREIGN KEY (Customer_Id) REFERENCES customers(Customer_Id) )";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createPaymentsTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS payments (Order_Id INT NOT NULL, Bill_Id INT, Payment_Method VARCHAR(25) NOT NULL, Payment_Status VARCHAR(30) NOT NULL, FOREIGN KEY (Order_Id) REFERENCES orders(Order_Id), FOREIGN KEY (Bill_Id) REFERENCES bills(Bill_Id) )";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createItemsTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS items (Order_Id INT NOT NULL, Bill_Id INT, Item_Id INT NOT NULL, Quantity INT NOT NULL, Rate INT NOT NULL, FOREIGN KEY (Order_Id) REFERENCES orders(Order_Id), FOREIGN KEY (Bill_Id) REFERENCES bills(Bill_Id), FOREIGN KEY (Item_Id) REFERENCES item_stock(Item_Id) );";
createTableStatement.executeUpdate(createTableQuery);
}
private static void createCompanyDetailsTable(Connection connection) throws Exception {
Statement createTableStatement = connection.createStatement();
String createTableQuery = "CREATE TABLE IF NOT EXISTS company_details (GSTIN VARCHAR(15) UNIQUE NOT NULL, Office_Address VARCHAR(300) NOT NULL, Email VARCHAR(100), Website VARCHAR(75), Phone_Number VARCHAR(20) NOT NULL);";
createTableStatement.executeUpdate(createTableQuery);
}
private static boolean isLoginTableEmpty(Connection connection) throws Exception {
String query = "SELECT COUNT(*) FROM login";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
resultSet.next();
int count = resultSet.getInt(1);
return count == 0;
}
private static void insertUserData(Connection connection, String companyName, String userName, String password) throws Exception {
createDatabase(connection, companyName);
String insertQuery = "INSERT INTO login (Company_Name, User_Name, Paswrd) VALUES (?, ?, ?)";
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, companyName);
preparedStatement.setString(2, userName);
preparedStatement.setString(3, password);
preparedStatement.executeUpdate();
connection.setCatalog(companyName);
createCustomersTable(connection);
createItemStockTable(connection);
createOrdersTable(connection);
createBillsTable(connection);
createPaymentsTable(connection);
createItemsTable(connection);
createCompanyDetailsTable(connection);
}
private static boolean checkCredentials(Connection connection, String companyName, String userName, String password) throws Exception {
String query = "SELECT * FROM login WHERE Company_Name = ? AND User_Name = ? AND Paswrd = ?";
PreparedStatement preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, companyName);
preparedStatement.setString(2, userName);
preparedStatement.setString(3, password);
ResultSet resultSet = preparedStatement.executeQuery();
return resultSet.next();
}
private static JFrame frame = new JFrame("Billing Software");
private static JMenuBar menuBar = new JMenuBar();
private static JMenu file = new JMenu("File");
private static JMenuItem exit = new JMenuItem("Exit");
private static JMenuItem logout = new JMenuItem("Logout");
private static JMenuItem addusermenu = new JMenuItem("Add New User");
private static JMenuItem homepage = new JMenuItem("Home Page");
private static JMenu view = new JMenu("View");
private static JMenuItem viewcustomer = new JMenuItem("View Customers");
private static JMenuItem viewbill = new JMenuItem("View Bills");
private static JMenuItem vieworder = new JMenuItem("View Orders");
private static JMenu add = new JMenu("Add");
private static JMenuItem addcustomer = new JMenuItem("Add Customer");
private static JMenuItem addorder = new JMenuItem("Add Order");
private static JMenuItem makebill = new JMenuItem("Make Bill");
private static JMenuItem additem = new JMenuItem("Add Item");
private static JMenu edit = new JMenu("Edit");
private static JMenuItem editpayment = new JMenuItem("Edit Payment");
private static JMenuItem editorder = new JMenuItem("Edit Order");
private static JMenuItem editbill = new JMenuItem("Edit Bill");
private static JMenuItem editstock = new JMenuItem("Edit Stock");
private static String username;
private static void edit_item(){
frame.getContentPane().removeAll();
frame.revalidate();
frame.repaint();
frame.setLayout(null);
JLabel itemname = new JLabel("Item Name:");
itemname.setForeground(new Color(0x293dff));
itemname.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
itemname.setVerticalAlignment(JLabel.CENTER);
itemname.setHorizontalAlignment(JLabel.LEFT);
itemname.setBounds(700, 70, 105, 35);
JTextField itemnametext = new JTextField();
itemnametext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
itemnametext.setBackground(new Color(0x99ccff));
itemnametext.setForeground(new Color(0x000099));
itemnametext.setCaretColor(new Color(0x000099));
itemnametext.setBounds(815, 70, 200, 35);
JLabel itemquantity = new JLabel("Item Quantity:");
itemquantity.setForeground(new Color(0x293dff));
itemquantity.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
itemquantity.setVerticalAlignment(JLabel.CENTER);
itemquantity.setHorizontalAlignment(JLabel.LEFT);
itemquantity.setBounds(732, 120, 135, 35);
JTextField itemquantitytext = new JTextField();
itemquantitytext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
itemquantitytext.setBackground(new Color(0x99ccff));
itemquantitytext.setForeground(new Color(0x000099));
itemquantitytext.setCaretColor(new Color(0x000099));
itemquantitytext.setBounds(877, 120, 100, 35);
JButton additembutton = new JButton("Edit Stock");
additembutton.setFocusable(false);
additembutton.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
additembutton.setBackground(new Color(0x4c73ff));
additembutton.setForeground(new Color(0x000099));
additembutton.setBounds(785, 210, 130, 35);
additembutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
Object itemnamevar = itemnametext.getText();
Object itemstockvar = itemquantitytext.getText();
if(itemnamevar!=null && itemstockvar!=null && itemnamevar!="" && itemstockvar!=""){
try{
String additemquery = "UPDATE item_stock SET Item_Stock = " + itemstockvar + " WHERE Item_Name = '" + itemnamevar + "'";
Statement statement = connection.createStatement();
statement.execute(additemquery);
JOptionPane.showMessageDialog(null, "Stock Edited", "Information", JOptionPane.INFORMATION_MESSAGE);
}catch(SQLException e1){
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Could not Edit Stock!!!", "Error", JOptionPane.ERROR_MESSAGE);
}catch(Exception e2){
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Could not Edit Stock!!!", "Error", JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null, "Enter Valid Data!!!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
frame.add(itemname);
frame.add(itemnametext);
frame.add(itemquantity);
frame.add(itemquantitytext);
frame.add(additembutton);
frame.setVisible(true);
frame.validate();
frame.repaint();
}
private static void edit_bills(){
frame.getContentPane().removeAll();
frame.revalidate();
frame.repaint();
frame.setLayout(null);
JLabel date = new JLabel("Date:");
date.setForeground(new Color(0x293dff));
date.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
date.setVerticalAlignment(JLabel.CENTER);
date.setHorizontalAlignment(JLabel.LEFT);
date.setBounds(471, 50, 50, 35);
JDateChooser dateentry = new JDateChooser();
dateentry.setDateFormatString("yyyy-MM-dd");
JTextField datetext = ((JTextField) dateentry.getDateEditor().getUiComponent());
datetext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
datetext.setBackground(new Color(0x99ccff));
datetext.setForeground(new Color(0x000099));
datetext.setCaretColor(new Color(0x000099));
dateentry.setBounds(531, 50, 150, 35);
JLabel time = new JLabel("Time:");
time.setForeground(new Color(0x293dff));
time.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
time.setVerticalAlignment(JLabel.CENTER);
time.setHorizontalAlignment(JLabel.LEFT);
time.setBounds(691, 50, 50, 35);
SpinnerDateModel timeModel = new SpinnerDateModel();
JSpinner timeSpinner = new JSpinner(timeModel);
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
timeSpinner.setEditor(timeEditor);
timeSpinner.setBackground(new Color(0x99ccff));
timeSpinner.setForeground(new Color(0x000099));
timeSpinner.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
timeSpinner.setBounds(751, 50, 150, 35);
JLabel company = new JLabel("Customer Company:");
company.setForeground(new Color(0x293dff));
company.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
company.setVerticalAlignment(JLabel.CENTER);
company.setHorizontalAlignment(JLabel.LEFT);
company.setBounds(50, 100, 185, 35);
JComboBox<String> companytext = new JComboBox<>();
JComboBox<String> nametext = new JComboBox<>();
java.util.List<String> companylist = new ArrayList<>();
java.util.List<String> namelist = new ArrayList<>();
JTextField billingAddtext = new JTextField();
JTextField shippingAddtext = new JTextField();
companytext.addItem("Select:");
nametext.addItem("Select:");
try{
String companyquery = "SELECT DISTINCT Customer_Company FROM customers";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(companyquery);
while(resultSet.next()){
companylist.add(resultSet.getString("Customer_Company"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : companylist){
companytext.addItem(i);
}
companytext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a){
nametext.removeAllItems();
nametext.addItem("Select:");
java.util.List<String> namelist2 = new ArrayList<>();
try{
String companyquery = "";
String addressquery = "";
String addressTemp = "";
if(companytext.getSelectedItem()=="" || companytext.getSelectedItem()==null){
companyquery = "SELECT DISTINCT Customer_Name FROM customers";
} else{
companyquery = "SELECT DISTINCT Customer_Name FROM customers WHERE Customer_Company = '" + companytext.getSelectedItem() + "'";
addressquery = "SELECT Address from customers WHERE Customer_Company = '" + companytext.getSelectedItem() + "'";
}
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(companyquery);
while(resultSet.next()){
namelist2.add(resultSet.getString("Customer_Name"));
}
ResultSet addressResult = statement.executeQuery(addressquery);
while (addressResult.next()) {
addressTemp = addressResult.getString("Address");
}
billingAddtext.setText(addressTemp);
shippingAddtext.setText(addressTemp);
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : namelist2){
nametext.addItem(i);
}
}
});
companytext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
companytext.setBackground(new Color(0x99ccff));
companytext.setForeground(new Color(0x000099));
JScrollPane companyscroll = new JScrollPane(companytext);
companyscroll.setPreferredSize(new Dimension(400, 45));
companyscroll.setBounds(245, 100, 400, 45);
JLabel name = new JLabel("Customer Name:");
name.setForeground(new Color(0x293dff));
name.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
name.setVerticalAlignment(JLabel.CENTER);
name.setHorizontalAlignment(JLabel.LEFT);
name.setBounds(50, 160, 155, 35);
try{
String namequery = "SELECT DISTINCT Customer_Name FROM customers";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(namequery);
while(resultSet.next()){
namelist.add(resultSet.getString("Customer_Name"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : namelist){
nametext.addItem(i);
}
nametext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
nametext.setBackground(new Color(0x99ccff));
nametext.setForeground(new Color(0x000099));
JScrollPane namescroll = new JScrollPane(nametext);
namescroll.setPreferredSize(new Dimension(400, 45));
namescroll.setBounds(215, 160, 400, 45);
JLabel billingAdd = new JLabel("Billing Address:");
billingAdd.setForeground(new Color(0x293dff));
billingAdd.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
billingAdd.setVerticalAlignment(JLabel.CENTER);
billingAdd.setHorizontalAlignment(JLabel.LEFT);
billingAdd.setBounds(50, 220, 145, 35);
billingAddtext.setBackground(new Color(0x99ccff));
billingAddtext.setForeground(new Color(0x000099));
billingAddtext.setCaretColor(new Color(0x000099));
billingAddtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
billingAddtext.setEditable(false);
billingAddtext.setBounds(205, 220, 500, 35);
JLabel shippingAdd = new JLabel("Shipping Address:");
shippingAdd.setForeground(new Color(0x293dff));
shippingAdd.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
shippingAdd.setVerticalAlignment(JLabel.CENTER);
shippingAdd.setHorizontalAlignment(JLabel.LEFT);
shippingAdd.setBounds(50, 270, 165, 35);
shippingAddtext.setBackground(new Color(0x99ccff));
shippingAddtext.setForeground(new Color(0x000099));
shippingAddtext.setCaretColor(new Color(0x000099));
shippingAddtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
shippingAddtext.setBounds(225, 270, 500, 35);
DefaultTableModel tableModel = new DefaultTableModel();
tableModel.addColumn("Item Name");
tableModel.addColumn("Quantity");
tableModel.addColumn("Rate");
tableModel.addColumn("Price");
tableModel.addColumn("Tax");
JTable orderTable = new JTable(tableModel);
orderTable.setBackground(new Color(0x99ccff));
JScrollPane tableScrollPane = new JScrollPane(orderTable);
tableScrollPane.setBounds(50, 365, 1000, 400);
JLabel paymentmethod = new JLabel("Payment Method:");
paymentmethod.setForeground(new Color(0x293dff));
paymentmethod.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentmethod.setVerticalAlignment(JLabel.CENTER);
paymentmethod.setHorizontalAlignment(JLabel.LEFT);
paymentmethod.setBounds(50, 785, 165, 35);
JTextField paymentmethodtext = new JTextField();
paymentmethodtext.setBackground(new Color(0x99ccff));
paymentmethodtext.setForeground(new Color(0x000099));
paymentmethodtext.setCaretColor(new Color(0x000099));
paymentmethodtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentmethodtext.setBounds(225, 785, 200, 35);
JLabel paymentstatus = new JLabel("Payment Status:");
paymentstatus.setForeground(new Color(0x293dff));
paymentstatus.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentstatus.setVerticalAlignment(JLabel.CENTER);
paymentstatus.setHorizontalAlignment(JLabel.LEFT);
paymentstatus.setBounds(460, 785, 155, 35);
JComboBox<String> paymentstatustext = new JComboBox<>();
paymentstatustext.addItem("Pending");
paymentstatustext.addItem("Partial Payment");
paymentstatustext.addItem("Complete Payment");
paymentstatustext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentstatustext.setBackground(new Color(0x99ccff));
paymentstatustext.setForeground(new Color(0x000099));
paymentstatustext.setBounds(625, 785, 200, 35);
JLabel tax = new JLabel("Tax Percentage:");
tax.setForeground(new Color(0x293dff));
tax.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
tax.setVerticalAlignment(JLabel.CENTER);
tax.setHorizontalAlignment(JLabel.LEFT);
tax.setBounds(50, 320, 152, 35);
JComboBox<Integer> taxtext = new JComboBox<>();
taxtext.addItem(5);
taxtext.addItem(12);
taxtext.addItem(18);
taxtext.addItem(28);
taxtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
taxtext.setBackground(new Color(0x99ccff));
taxtext.setForeground(new Color(0x000099));
taxtext.setBounds(212, 320, 70, 35);
taxtext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
for(int row = 0; row < tableModel.getRowCount(); row++){
float price = (float)tableModel.getValueAt(row, 3);
tableModel.setValueAt(price*(int)taxtext.getSelectedItem()/100, row, 4);
}
}
});
JLabel orderid = new JLabel("Order ID:");
orderid.setForeground(new Color(0x293dff));
orderid.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderid.setVerticalAlignment(JLabel.CENTER);
orderid.setHorizontalAlignment(JLabel.LEFT);
orderid.setBounds(251, 50, 85, 35);
JTextField orderidtext = new JTextField();
orderidtext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try{
String cutstomeridquery = "SELECT Customer_Id FROM orders WHERE Order_Id = " + orderidtext.getText();
Statement statement = connection.createStatement();
ResultSet customeridResultSet = statement.executeQuery(cutstomeridquery);
customeridResultSet.next();
int customerid = customeridResultSet.getInt("Customer_Id");
String customerquery = "SELECT Customer_Name, Customer_Company FROM customers WHERE Customer_Id = " + customerid;
ResultSet customerResultSet = statement.executeQuery(customerquery);
customerResultSet.next();
String customerName = customerResultSet.getString("Customer_Name");
String customerCompany = customerResultSet.getString("Customer_Company");
companytext.setSelectedItem(customerCompany);
nametext.setSelectedItem(customerName);
String paymentquery = "SELECT Payment_Method, Payment_Status FROM payments WHERE Order_Id = " + orderidtext.getText();
ResultSet paymentResultSet = statement.executeQuery(paymentquery);
paymentResultSet.next();
String payment_meth = paymentResultSet.getString("Payment_Method");
String payment_stat = paymentResultSet.getString("Payment_Status");
paymentmethodtext.setText(payment_meth);
paymentstatustext.setSelectedItem(payment_stat);
String items = "SELECT Item_Name, Quantity, Rate, Quantity*Rate AS Price FROM items WHERE Order_Id = " + orderidtext.getText();
ResultSet itemsResultSet = statement.executeQuery(items);
tableModel.setRowCount(0);
while(itemsResultSet.next()){
tableModel.addRow(new Object[]{itemsResultSet.getString("Item_Name"), itemsResultSet.getInt("Quantity"), itemsResultSet.getFloat("Rate"), itemsResultSet.getFloat("Price"), (float)itemsResultSet.getFloat("Price")*(int)taxtext.getSelectedItem()/100});
}
String addressTemp = "";
String addressquery = "SELECT Address from customers, orders WHERE orders.Order_Id = " + orderidtext.getText() + " AND orders.Customer_Id = customers.Customer_Id";
ResultSet addressResult = statement.executeQuery(addressquery);
while (addressResult.next()) {
addressTemp = addressResult.getString("Address");
}
billingAddtext.setText(addressTemp);
shippingAddtext.setText(addressTemp);
}catch(SQLException e1){
e1.printStackTrace();
}catch(Exception e2){
e2.printStackTrace();
}
}
});
orderidtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderidtext.setBackground(new Color(0x99ccff));
orderidtext.setForeground(new Color(0x000099));
orderidtext.setCaretColor(new Color(0x000099));
orderidtext.setBounds(346, 45, 100, 45);
JLabel billid = new JLabel("Bill ID:");
billid.setForeground(new Color(0x293dff));
billid.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
billid.setVerticalAlignment(JLabel.CENTER);
billid.setHorizontalAlignment(JLabel.LEFT);
billid.setBounds(50, 50, 83, 35);
JTextField billidtext = new JTextField();
billidtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
billidtext.setBackground(new Color(0x99ccff));
billidtext.setForeground(new Color(0x000099));
billidtext.setCaretColor(new Color(0x000099));
billidtext.setBounds(143, 50, 83, 35);
billidtext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try{
String billquery = "SELECT Order_Id, Date, Time FROM bills WHERE Bill_Id = " + billidtext.getText();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(billquery);
resultSet.next();
orderidtext.setText(resultSet.getString("Order_Id"));
orderidtext.setEditable(false);
datetext.setText(resultSet.getString("Date"));
timeSpinner.setValue(resultSet.getObject("Time"));
String cutstomeridquery = "SELECT Customer_Id FROM orders WHERE Order_Id = " + orderidtext.getText();
ResultSet customeridResultSet = statement.executeQuery(cutstomeridquery);
customeridResultSet.next();
int customerid = customeridResultSet.getInt("Customer_Id");
String customerquery = "SELECT Customer_Name, Customer_Company FROM customers WHERE Customer_Id = " + customerid;
ResultSet customerResultSet = statement.executeQuery(customerquery);
customerResultSet.next();
String customerName = customerResultSet.getString("Customer_Name");
String customerCompany = customerResultSet.getString("Customer_Company");
companytext.setSelectedItem(customerCompany);
nametext.setSelectedItem(customerName);
String paymentquery = "SELECT Payment_Method, Payment_Status FROM payments WHERE Order_Id = " + orderidtext.getText();
ResultSet paymentResultSet = statement.executeQuery(paymentquery);
paymentResultSet.next();
String payment_meth = paymentResultSet.getString("Payment_Method");
String payment_stat = paymentResultSet.getString("Payment_Status");
paymentmethodtext.setText(payment_meth);
paymentstatustext.setSelectedItem(payment_stat);
String items = "SELECT Item_Name, Quantity, Rate, Quantity*Rate AS Price FROM items, item_stock WHERE items.Item_Id = item_stock.Item_Id and Order_Id = " + orderidtext.getText();
ResultSet itemsResultSet = statement.executeQuery(items);
tableModel.setRowCount(0);
while(itemsResultSet.next()){
tableModel.addRow(new Object[]{itemsResultSet.getString("Item_Name"), itemsResultSet.getInt("Quantity"), itemsResultSet.getFloat("Rate"), itemsResultSet.getFloat("Price"), (float)itemsResultSet.getFloat("Price")*(int)taxtext.getSelectedItem()/100});
}
String addressTemp = "";
String addressquery = "SELECT Address from customers, bills WHERE bills.Bill_Id = " + billidtext.getText() + " AND bills.Customer_Id = customers.Customer_Id";
ResultSet addressResult = statement.executeQuery(addressquery);
while (addressResult.next()) {
addressTemp = addressResult.getString("Address");
}
billingAddtext.setText(addressTemp);
shippingAddtext.setText(addressTemp);
}catch(SQLException e1){
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Order ID not Found!!!", "Error", JOptionPane.INFORMATION_MESSAGE);
}catch(Exception e2){
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Order ID not Found!!!", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}
});
JButton addorderbutton = new JButton("Edit Bill");
addorderbutton.setFocusable(false);
addorderbutton.setFont(new Font("Haettenschweiler", Font.PLAIN, 25));
addorderbutton.setBackground(new Color(0x4c73ff));
addorderbutton.setForeground(new Color(0x000099));
addorderbutton.setBounds(1060, 780, 120, 35);
addorderbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
Object order_id = orderidtext.getText();
java.util.Date selecteddate = dateentry.getDate();
java.util.Date selectedTime = (Date) timeSpinner.getValue();
Object companyname = companytext.getSelectedItem();
Object customername = nametext.getSelectedItem();
String shippingAddress = shippingAddtext.getText();
String paymethod = paymentmethodtext.getText();
Object paystatus = paymentstatustext.getSelectedItem();
Object taxperc = taxtext.getSelectedItem();
if(billidtext.getText().length()!=0 && shippingAddress.length()!=0 && shippingAddress!=null && selecteddate!=null && selectedTime!=null && companyname!=null && customername!=null && paymethod!=null && paystatus!=null && taxperc!=null && companyname!="" && customername!="" && shippingAddress!="" && paymethod!="" && paystatus!="" && taxperc!="" && paymethod.length()!=0){
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = sdf.format(selecteddate);
SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss");
String formattedTime = stf.format(selectedTime);
Statement statement = connection.createStatement();
String insertOrderQuery = "UPDATE orders SET Order_Status = 'Complete' WHERE Order_Id = " + order_id;
statement.execute(insertOrderQuery);
int Temp = 0;
String customerIdQuery = "SELECT * from customers WHERE Customer_Name = '" + customername + "' AND Customer_Company = '" + companyname + "'";
ResultSet customerIdResult = statement.executeQuery(customerIdQuery);
Temp = 0;
while (customerIdResult.next()) {
Temp = customerIdResult.getInt("Customer_Id");
}
int customerId = Temp;
String insertBillQuery = "UPDATE bills SET Order_Id =" + order_id + ", Date ='" + java.sql.Date.valueOf(formattedDate) + "', Time = '" + java.sql.Time.valueOf(formattedTime) + "', Customer_Id = '" + customerId + "', Shipping_Address = '" + shippingAddress + "', tax_percentage = " + taxperc + " WHERE Bill_Id = " + billidtext.getText();
statement.execute(insertBillQuery);
String insertPaymentQuery = "UPDATE payments set Payment_Method = '" + paymethod + "', Payment_Status = '" + paystatus + "' WHERE Bill_Id = " + billidtext.getText();
statement.execute(insertPaymentQuery);
JOptionPane.showMessageDialog(null, "Bill Details Added", "Information", JOptionPane.INFORMATION_MESSAGE);
} catch(SQLException e1){
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Could not add Bill Details!!!", "Error", JOptionPane.ERROR_MESSAGE);
} catch(Exception e2){
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "Could not add Bill Details!!!", "Error", JOptionPane.ERROR_MESSAGE);
}
} else{
JOptionPane.showMessageDialog(null, "Enter Valid Details!!!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
frame.add(billid);
frame.add(billidtext);
frame.add(orderid);
frame.add(orderidtext);
frame.add(date);
frame.add(dateentry);
frame.add(time);
frame.add(timeSpinner);
frame.add(company);
frame.add(companyscroll);
frame.add(name);
frame.add(namescroll);
frame.add(billingAdd);
frame.add(billingAddtext);
frame.add(shippingAdd);
frame.add(shippingAddtext);
frame.add(tableScrollPane);
frame.add(paymentmethod);
frame.add(paymentmethodtext);
frame.add(paymentstatus);
frame.add(paymentstatustext);
frame.add(tax);
frame.add(taxtext);
frame.add(addorderbutton);
frame.setVisible(true);
frame.validate();
frame.repaint();
}
private static void edit_orders(){
frame.getContentPane().removeAll();
frame.revalidate();
frame.repaint();
frame.setLayout(null);
JLabel date = new JLabel("Date:");
date.setForeground(new Color(0x293dff));
date.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
date.setVerticalAlignment(JLabel.CENTER);
date.setHorizontalAlignment(JLabel.LEFT);
date.setBounds(250, 50, 50, 35);
JDateChooser dateentry = new JDateChooser();
dateentry.setDateFormatString("yyyy-MM-dd");
JTextField datetext = ((JTextField) dateentry.getDateEditor().getUiComponent());
datetext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
datetext.setBackground(new Color(0x99ccff));
datetext.setForeground(new Color(0x000099));
datetext.setCaretColor(new Color(0x000099));
dateentry.setBounds(310, 50, 150, 35);
JLabel company = new JLabel("Customer Company:");
company.setForeground(new Color(0x293dff));
company.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
company.setVerticalAlignment(JLabel.CENTER);
company.setHorizontalAlignment(JLabel.LEFT);
company.setBounds(50, 100, 185, 35);
JComboBox<String> companytext = new JComboBox<>();
JComboBox<String> nametext = new JComboBox<>();
java.util.List<String> companylist = new ArrayList<>();
java.util.List<String> namelist = new ArrayList<>();
companytext.addItem("Select:");
nametext.addItem("Select:");
try{
String companyquery = "SELECT DISTINCT Customer_Company FROM customers";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(companyquery);
while(resultSet.next()){
companylist.add(resultSet.getString("Customer_Company"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : companylist){
companytext.addItem(i);
}
companytext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a){
nametext.removeAllItems();
nametext.addItem("Select:");
java.util.List<String> namelist2 = new ArrayList<>();
try{
String companyquery = "";
if(companytext.getSelectedItem()=="" || companytext.getSelectedItem()==null){
companyquery = "SELECT DISTINCT Customer_Name FROM customers";
} else{
companyquery = "SELECT DISTINCT Customer_Name FROM customers WHERE Customer_Company = '" + companytext.getSelectedItem() + "'";
}
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(companyquery);
while(resultSet.next()){
namelist2.add(resultSet.getString("Customer_Name"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : namelist2){
nametext.addItem(i);
}
}
});
companytext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
companytext.setBackground(new Color(0x99ccff));
companytext.setForeground(new Color(0x000099));
JScrollPane companyscroll = new JScrollPane(companytext);
companyscroll.setPreferredSize(new Dimension(400, 45));
companyscroll.setBounds(245, 100, 400, 45);
JLabel name = new JLabel("Customer Name:");
name.setForeground(new Color(0x293dff));
name.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
name.setVerticalAlignment(JLabel.CENTER);
name.setHorizontalAlignment(JLabel.LEFT);
name.setBounds(50, 160, 155, 35);
try{
String namequery = "SELECT DISTINCT Customer_Name FROM customers";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(namequery);
while(resultSet.next()){
namelist.add(resultSet.getString("Customer_Name"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(Exception e1){
e1.printStackTrace();
}
for(String i : namelist){
nametext.addItem(i);
}
nametext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
nametext.setBackground(new Color(0x99ccff));
nametext.setForeground(new Color(0x000099));
JScrollPane namescroll = new JScrollPane(nametext);
namescroll.setPreferredSize(new Dimension(400, 45));
namescroll.setBounds(215, 160, 400, 45);
DefaultTableModel model1 = new DefaultTableModel();
model1.addColumn("Item Name");
model1.addColumn("Item Quantity");
model1.addColumn("Item Rate");
JTable orderTable = new JTable(model1);
orderTable.setBackground(new Color(0x99ccff));
orderTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(new JTextField()));
orderTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JTextField()));
orderTable.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(new JTextField()));
JScrollPane tableScrollPane = new JScrollPane(orderTable);
tableScrollPane.setBounds(50, 220, 1000, 400);
JButton addButton = new JButton("Add Row");
addButton.setFocusable(false);
addButton.setFont(new Font("Haettenschweiler", Font.PLAIN, 25));
addButton.setBackground(new Color(0x4c73ff));
addButton.setForeground(new Color(0x000099));
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
model1.addRow(new Object[]{"", "", ""});
}
});
addButton.setBounds(1060, 540, 110, 35);
JButton delButton = new JButton("Delete Row");
delButton.setFocusable(false);
delButton.setFont(new Font("Haettenschweiler", Font.PLAIN, 25));
delButton.setBackground(new Color(0x4c73ff));
delButton.setForeground(new Color(0x000099));
delButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rows = model1.getRowCount();
model1.setRowCount(rows-1);
}
});
delButton.setBounds(1060, 585, 130, 35);
JLabel paymentmethod = new JLabel("Payment Method:");
paymentmethod.setForeground(new Color(0x293dff));
paymentmethod.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentmethod.setVerticalAlignment(JLabel.CENTER);
paymentmethod.setHorizontalAlignment(JLabel.LEFT);
paymentmethod.setBounds(50, 640, 165, 35);
JTextField paymentmethodtext = new JTextField();
paymentmethodtext.setBackground(new Color(0x99ccff));
paymentmethodtext.setForeground(new Color(0x000099));
paymentmethodtext.setCaretColor(new Color(0x000099));
paymentmethodtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentmethodtext.setBounds(225, 640, 200, 35);
JLabel paymentstatus = new JLabel("Payment Status:");
paymentstatus.setForeground(new Color(0x293dff));
paymentstatus.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentstatus.setVerticalAlignment(JLabel.CENTER);
paymentstatus.setHorizontalAlignment(JLabel.LEFT);
paymentstatus.setBounds(460, 640, 155, 35);
JComboBox<String> paymentstatustext = new JComboBox<>();
paymentstatustext.addItem("Pending");
paymentstatustext.addItem("Partial Payment");
paymentstatustext.addItem("Complete Payment");
paymentstatustext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
paymentstatustext.setBackground(new Color(0x99ccff));
paymentstatustext.setForeground(new Color(0x000099));
paymentstatustext.setBounds(625, 640, 200, 35);
JLabel orderstatus = new JLabel("Order Status:");
orderstatus.setForeground(new Color(0x293dff));
orderstatus.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderstatus.setVerticalAlignment(JLabel.CENTER);
orderstatus.setHorizontalAlignment(JLabel.LEFT);
orderstatus.setBounds(50, 690, 130, 35);
JComboBox<String> orderstatustext = new JComboBox<>();
orderstatustext.addItem("Pending");
orderstatustext.addItem("Complete");
orderstatustext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderstatustext.setBackground(new Color(0x99ccff));
orderstatustext.setForeground(new Color(0x000099));
orderstatustext.setBounds(190, 690, 200, 35);
JLabel orderid = new JLabel("Order ID:");
orderid.setForeground(new Color(0x293dff));
orderid.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderid.setVerticalAlignment(JLabel.CENTER);
orderid.setHorizontalAlignment(JLabel.LEFT);
orderid.setBounds(50, 50, 83, 35);
JTextField orderidtext = new JTextField();
orderidtext.setFont(new Font("Haettenschweiler", Font.PLAIN, 30));
orderidtext.setBackground(new Color(0x99ccff));
orderidtext.setForeground(new Color(0x000099));
orderidtext.setCaretColor(new Color(0x000099));
orderidtext.setBounds(143, 50, 83, 35);
orderidtext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try{
String orderquery = "SELECT * FROM orders WHERE Order_Id = " + orderidtext.getText();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(orderquery);
resultSet.next();
Date orderdate = resultSet.getDate("Order_Date");
String customerid = resultSet.getString("Customer_Id");
String orderstatus = resultSet.getString("Order_Status");
dateentry.setDate(orderdate);
orderstatustext.setSelectedItem(orderstatus);
String customerdetails = "SELECT * FROM customers WHERE Customer_Id = " + customerid;
ResultSet customerResultSet = statement.executeQuery(customerdetails);
customerResultSet.next();
String customername = customerResultSet.getString("Customer_Name");
String companyname = customerResultSet.getString("Customer_Company");
companytext.setSelectedItem(companyname);
nametext.setSelectedItem(customername);
String paymentdetails = "SELECT * FROM payments WHERE Order_Id = " + orderidtext.getText();
ResultSet paymentResultSet = statement.executeQuery(paymentdetails);
paymentResultSet.next();
String paymethod = paymentResultSet.getString("Payment_Method");
String paystatus = paymentResultSet.getString("Payment_Status");
paymentmethodtext.setText(paymethod);
paymentstatustext.setSelectedItem(paystatus);
String searchquery1 = "select Order_Id, Item_Name, Quantity, Rate from items, item_stock WHERE items.Item_Id = item_stock.Item_Id and Order_Id = " + orderidtext.getText();
Statement statementselect = connection.createStatement();
ResultSet resultsetselect = statementselect.executeQuery(searchquery1);
while(resultsetselect.next()){
Object[] row = new Object[3];
row[0]=resultsetselect.getObject("Item_Name");
row[1]=resultsetselect.getObject("Quantity");
row[2]=resultsetselect.getObject("Rate");