-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbill.java
1640 lines (1301 loc) · 64.5 KB
/
bill.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.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import com.mysql.jdbc.DatabaseMetaData;
//import com.mxrck.autocompleter.TextAutoCompleter;
import com.mysql.jdbc.Statement;
import javaGUI.sqlconnection;
import net.proteanit.sql.DbUtils;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileOutputStream;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.SoftBevelBorder;
import javax.swing.table.DefaultTableModel;
//import org.controlsfx.control.textfield.TextFields;
import javafx.scene.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JSlider;
import javax.swing.JFormattedTextField;
public class bill extends JFrame {
static GraphicsEnvironment ge ;
static GraphicsDevice gs ;
static GraphicsConfiguration gc ;
AutocompletePayment objPayment=new AutocompletePayment();
Autocomplete cmpltObj=new Autocomplete();
InsertBills insert=new InsertBills();
private JPanel contentPane;
public JTextField textFieldName;
public JTextField textFieldQuantity;
public ArrayList billNamesArray,quantArry,purchaseList;
static ArrayList purchase=new ArrayList();
public JTextField textFieldLeft;
//private java.sql.Date sqlDate;
private JComboBox<String> comboBoxName ;
public java.sql.Connection connection=null;
private JTable table;
private JTable table2;
private static double width,currentResolutionWidth;
private static double height,referenceResolutionHeight,currentResolutionHeight ,referenceResolutionWidth;
private String s;
home hm;
static bill frame;
private JPanel panelBill ;
private JLabel lblTotal;
private JScrollPane scrollPane,scrollPane2 ;
private static JButton btnAdd;
private JLabel lblBillno;
/**
* Launch the application.
*/
//stock stk=new stock();
private String query,query2,query3,query4;
PreparedStatement pst1,pst2,pst3,pst4;
ResultSet rs1,rs2,rs3,rs4;
public JTextField textFieldId;
public JTextField textFieldPrice;
public JTextField textFieldTotal;
public JTextField textFieldcName;
public JTextField textFieldPaid;
public JTextField textFieldRemaining;
public JTextField textFieldcMobile ;
public JTextField textFieldPRemaining;
public JTextField textFieldTRemaining;
float saleProfitFinder,purchaseProfitFinder,stockpurchase,clsStk,opnStk,total;
public JTextField textFieldCity;
//bill frame ;
public JTextField textFieldDate;
float sale_price,purchase_price,abnormal,stockpurchase1,opening_stk,closing_stk,new_closing_stk,newStockPurchase,previous_closing_stk,new_purchase_price;
float tax,taxProfitFinder;
//==============================================================
public static synchronized int getWidthForCurrentResolution(int width1) {
return (int)((currentResolutionWidth / referenceResolutionWidth) * width1);
}
public static synchronized int getHeightForCurrentResolution(int height1) {
return (int)((currentResolutionHeight/ referenceResolutionHeight) * height1);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
purchase.clear();
int n=1;
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gs = ge.getDefaultScreenDevice();
gc = gs.getDefaultConfiguration();
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
referenceResolutionWidth=1920;
referenceResolutionHeight=1080;
currentResolutionWidth=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth();
currentResolutionHeight=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight();
width = screenSize.getWidth();
height = screenSize.getHeight();
double width1=getWidthForCurrentResolution((int)width);
double height1=getHeightForCurrentResolution((int)height);
frame = new bill(n,gc);
frame.setSize((int)width,(int)height);
frame.setResizable(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
//frame.setUndecorated(true);
frame.getRootPane().setDefaultButton(btnAdd);
//frame.setLocation((int)(dimension.getWidth()/ 2 - width / 2));
frame.showCart();
frame.setLocationRelativeTo(null); // Explicit JFrame if outside JFrame constructor.
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
//##########################################################################################################
public void getProfitFinderComponents(Date date1)
{
try{
String query="select * from profitfinder where date='"+date1+"';";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
sale_price=rs.getFloat("sale_price");
purchase_price=rs.getFloat("purchase_price");
stockpurchase=rs.getFloat("stockpurchase");
opening_stk=rs.getFloat("opening_stk");
closing_stk=rs.getFloat("closing_stk");
abnormal=rs.getFloat("abnormal");;
}
pst.close();
rs.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "ERROR IN CHRCKDATE :"+ e);
e.printStackTrace();
}
}
//###############################################CALCULATE CLOSING STK FUNCTION###################################################################
public void calculateClosingStk(Date date)
{
getProfitFinderComponents(cmpltObj.sqlDate);
new_closing_stk=opening_stk+stockpurchase-new_purchase_price;
}
//#################################SELECT PREVIOUS CLOSING STK FUNCTION #################################################
public void selectPreviousClosingStk()
{
try{
String query="select * from profitfinder where id= ( select max(ID) from profitfinder);";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
previous_closing_stk=rs.getFloat("closing_stk");
}
pst.close();
rs.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "ERROR IN CHRCKDATE :"+ e);
e.printStackTrace();
}
}
//############################################################################################################
public void getTotalPurchasePrice()
{
int count=table2.getRowCount();
billNamesArray=new ArrayList();
billNamesArray.clear();
billNamesArray=cmpltObj.ItemlistArray("bill");
billQuantity();
purchaseList=new ArrayList();
purchaseList.clear();
try{
if(billNamesArray.size()!=0)
{
for(int i=0;i<billNamesArray.size();i++)
{
String query="select purchase_price from stock where name='"+billNamesArray.get(i)+"'";
PreparedStatement pst2=connection.prepareStatement(query);
if(!billNamesArray.isEmpty())
{
ResultSet rs2=pst2.executeQuery();
while(rs2.next())
{
String qua=rs2.getString(1);
purchaseList.add(Integer.parseInt(qua));
}
rs2.close();
}
pst2.close();
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "error in billQuantity :"+e);
e.printStackTrace();
}
System.out.println(billNamesArray);
System.out.println(purchaseList);
System.out.println(quantArry);
// System.out.println(name);
}
public void billQuantity()
{
quantArry=new ArrayList();
quantArry.clear();
try{
String query="select Quantity from bill";
PreparedStatement pst2=connection.prepareStatement(query);
ResultSet rs2=pst2.executeQuery();
String qua;
while(rs2.next())
{
qua=rs2.getString(1);
quantArry.add(Integer.parseInt(qua));
}
pst2.close();
rs2.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "error in billQuantity :"+e);
e.printStackTrace();
}
}
public int checkDate()
{
int ch=0;
try{
cmpltObj.date();
String query="select date from profitfinder where date='"+cmpltObj.sqlDate+"';";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
ch=1;
}
pst.close();
rs.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "ERROR IN CHRCKDATE :"+ e);
e.printStackTrace();
}
return ch;
}
public void getDateProfitFinder(Date date2)
{
try{
String query="select * from profitfinder where date='"+date2+"' ;";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
purchaseProfitFinder=rs.getInt("purchase_price");
saleProfitFinder=rs.getFloat("sale_price");
stockpurchase=rs.getFloat("stockpurchase");
taxProfitFinder=rs.getFloat("tax");
}
pst.close();
rs.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST EXIST INSERT =="+e);
}
}
public void updateProfitFinder()
{
try
{
cmpltObj.date();
getDateProfitFinder(cmpltObj.sqlDate);
calculateClosingStk(cmpltObj.sqlDate);
String query="Update profitfinder set purchase_price='"+(purchaseProfitFinder+total)+"',sale_price='"+(saleProfitFinder+Integer.parseInt(textFieldTotal.getText()))+"' where date='"+cmpltObj.sqlDate+"';";
PreparedStatement pst=connection.prepareStatement(query);
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "update profit finder =="+e);
}
}
//#########################################################################################################################
public void profitFinderInsert()
{
getTotalPurchasePrice();
int size=billNamesArray.size();
total=0;
int ch;
for(int i=0;i<size;i++)
{
float p=Integer.parseInt(quantArry.get(i).toString())*Integer.parseInt(purchaseList.get(i).toString());
total+=p;
}
try{
cmpltObj.date();
ch=checkDate();
selectPreviousClosingStk();
new_purchase_price=total;
calculateClosingStk(cmpltObj.sqlDate);
String query1="select * from profitfinder where date='"+cmpltObj.sqlDate+"';";
PreparedStatement pst1=connection.prepareStatement(query1);
ResultSet rs=pst1.executeQuery();
while(rs.next())
{
taxProfitFinder=Float.parseFloat(rs.getString("tax"));
}
String query="Insert into profitfinder (date,sale_price,purchase_price,opening_stk,tax) values (?,?,?,?,?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,cmpltObj.sqlDate.toString());
pst.setString(2,textFieldTotal.getText());
pst.setString(3,Float.toString(total));
pst.setString(4,Float.toString(previous_closing_stk));
pst.setString(5,Float.toString(taxProfitFinder+tax));
if(ch!=1)
{
pst.execute();
pst.close();
}
else
{
pst.close();
updateProfitFinder();
}
objPayment.updateClosingStk();
}
catch(Exception e)
{
}
System.out.println(total);
}
//################################ OLD CUSTOMER INSERT IN PROFIT#############################################
public void existUpdate()
{
try{
String query="Update profit set Paid='"+(cmpltObj.pp+cmpltObj.pt)+"',Total='"+(cmpltObj.tp+Integer.parseInt(textFieldTotal.getText()))+ "',Remaining='"+textFieldTRemaining.getText()+"' where Name='"+textFieldcName.getText()+"'";
PreparedStatement pst=connection.prepareStatement(query);
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST EXIST INSERT =="+e);
}
}
//################################NEW CUSTOMER INSERT IN PROFIT#############################################
public void newInsert()
{
try{
String query="Insert into profit (Name,city,mobile,Date,Paid,Remaining,Total) values (?,?,?,?,?,?,?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,textFieldcName.getText().toLowerCase());
pst.setString(2,textFieldCity.getText().toLowerCase());
pst.setString(3,textFieldcMobile.getText());
pst.setString(4,cmpltObj.sqlDate.toString());
pst.setString(5,textFieldPaid.getText());
pst.setString(6,textFieldRemaining.getText());
pst.setString(7,textFieldTotal.getText());
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST NEW INSERT =="+e);
}
}
//#########################################INSERT IN RECORD FOR ALL USERS##################################
public void commonInsert()
{
try{
String query="Insert into record (Name,city,mobile,Date,Paid,Remaining,Total,tax) values (?,?,?,?,?,?,?,?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,textFieldcName.getText().toLowerCase());
pst.setString(2,textFieldCity.getText().toLowerCase());
pst.setString(3,textFieldcMobile.getText());
pst.setString(4,cmpltObj.sqlDate.toString());
pst.setString(5,textFieldPaid.getText());
pst.setString(6,textFieldRemaining.getText());
pst.setString(7,textFieldTotal.getText());
pst.setString(8,Float.toString(tax));
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST COMMON INSERT =="+e);
}
}
//#########################################INSERT FUNCTION FOR CUSTOMERS DETAILS#######################################
public void custinsfun()
{
try{
if((textFieldName.getText().toLowerCase()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Name is Missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldcMobile.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Please Enter Mobile number...!", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldCity.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Please Enter city...!", "Failure", JOptionPane.ERROR_MESSAGE);
}
else
{
if((textFieldPaid.getText()).isEmpty())
{
textFieldPaid.setText(Integer.toString(0));
}
int ch=cmpltObj.checkCustomer(textFieldcName);
if(ch==1)
{
commonInsert();
existUpdate();
//showfun();
profitFinderInsert();
}
else
{
commonInsert();
newInsert();
profitFinderInsert();
}
}
//JOptionPane.showMessageDialog(null,"Data Saved..........!");
}
catch(Exception R2){
JOptionPane.showMessageDialog(null,
R2.getMessage(), "Failure", JOptionPane.ERROR_MESSAGE);
R2.printStackTrace();
}
clearBill();
showCart();
}
//################################################UPDATE STOCK FUNCTION######################################################
public void stkupdatefun(int q)
{
String total;
total=Integer.toString(q);
try{
//String query="Update stock set ID= '"+textFieldId.getText()+"' , Name= '"+textFieldName.getText()+"' ,Quantity='"+textFieldQuantity.getText()+"', Price='"+textFieldPrice+"' where ID='"+textFieldIDS.getText()+"'";
String query="Update stock set Quantity='"+total+"' where Name='"+textFieldName.getText()+"'";
PreparedStatement pst=connection.prepareStatement(query);
if(Integer.parseInt(textFieldQuantity.getText())<0)
{
JOptionPane.showMessageDialog(null,
"Quantity must be more than 0", "Failure", JOptionPane.ERROR_MESSAGE);
pst.close();
}
else{
pst.execute();
pst.close();
showStock();
//JOptionPane.showMessageDialog(null,"Data Updated Successfully..........!");
}
}
catch(Exception R1){
JOptionPane.showMessageDialog(null,
R1, "Failure", JOptionPane.ERROR_MESSAGE);
R1.printStackTrace();
}
}
//########################################DELETE BILL FUNCTION##############################################################
public void deletefun()
{
try{
String query="delete from bill where lower(`name`)='"+textFieldName.getText().toLowerCase()+"'";
PreparedStatement pst=connection.prepareStatement(query);
if((textFieldName.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Name is missing \n"+"Please enter Item name to be deleted", "Failure", JOptionPane.ERROR_MESSAGE);
}
else
{
cmpltObj.quantity();
if(cmpltObj.ic==cmpltObj.cartSize)
{
JOptionPane.showMessageDialog(null,
"Item not found", "Failure", JOptionPane.ERROR_MESSAGE);
}
else{
pst.execute();
pst.close();
if(textFieldQuantity.getText().isEmpty())
{
textFieldQuantity.setText(Integer.toString(0));
cmpltObj.qt=1;
}
stkupdatefun(cmpltObj.qc+cmpltObj.qs);
showCart();
}
}
}
catch(Exception R){
JOptionPane.showMessageDialog(null,
"Duplicate Entry Or ID may be wrong", "Failure", JOptionPane.ERROR_MESSAGE);
R.printStackTrace();
}
}
//################################################UPDATE BILL FUNCTION######################################################
public void billupdatefun()
{
try{
//String query="Update stock set ID= '"+textFieldId.getText()+"' , Name= '"+textFieldName.getText()+"' ,Quantity='"+textFieldQuantity.getText()+"', Price='"+textFieldPrice+"' where ID='"+textFieldIDS.getText()+"'";
String query="Update bill set Name='"+textFieldName.getText()+"',Quantity='"+textFieldQuantity.getText()+"',Price='"+textFieldPrice.getText()+"' where name='"+textFieldName.getText()+"'";
PreparedStatement pst=connection.prepareStatement(query);
cmpltObj.quantity();
if(cmpltObj.ic==cmpltObj.cartSize)
{
JOptionPane.showMessageDialog(null,
"Item not found", "Failure", JOptionPane.ERROR_MESSAGE);
}
else
{
if(Integer.parseInt(textFieldQuantity.getText())<0)
{
JOptionPane.showMessageDialog(null,
"Quantity must be more than 0", "Failure", JOptionPane.ERROR_MESSAGE);
}
else{
if(cmpltObj.qs+cmpltObj.qc-cmpltObj.qt >0)
{
pst.execute();
stkupdatefun(cmpltObj.qs+cmpltObj.qc-cmpltObj.qt);
showCart();
}
else
JOptionPane.showMessageDialog(null,
"Stock not available", "Failure", JOptionPane.ERROR_MESSAGE);
}
}
pst.close();
}
catch(Exception R1){
JOptionPane.showMessageDialog(null,
R1, "Failure", JOptionPane.ERROR_MESSAGE);
R1.printStackTrace();
}
}
//###############################################Insert Update Function#######################################################
public void insbillupdatefun()
{
try{
int totalint;
totalint=cmpltObj.qt+cmpltObj.qc;
if(cmpltObj.qt>cmpltObj.qs)
JOptionPane.showMessageDialog(null, "Out of Stock");
else
{
String totalstr=Integer.toString(totalint);
String query="Update bill set Name='"+textFieldName.getText()+"',Quantity='"+totalstr+"',Price='"+textFieldPrice.getText()+"' where name='"+textFieldName.getText()+"'";
PreparedStatement pst=connection.prepareStatement(query);
pst.execute();
pst.close();
stkupdatefun(cmpltObj.qs-cmpltObj.qt);
showCart();
}
}
catch(Exception R1){
JOptionPane.showMessageDialog(null,
R1, "Failure", JOptionPane.ERROR_MESSAGE);
R1.printStackTrace();
}
}
//#########################################################################################################
public void fieldSet()
{
PreparedStatement pst3;
String query3;
ResultSet rs3;
try{
query3="select * from stock where name= ?";
pst3=connection.prepareStatement(query3);
pst3.setString(1,textFieldName.getText());
rs3=pst3.executeQuery();
while(rs3.next())
{
textFieldName.setText(rs3.getString("Name"));
textFieldId.setText(rs3.getString("ID"));
textFieldLeft.setText(rs3.getString("Quantity"));
textFieldPrice.setText(rs3.getString("Price"));
textFieldPrice.setEditable(false);
}
pst3.close(); //JOptionPane.showMessageDialog(null,"Data Saved..........!");
rs3.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//#########################################################################################################
public void insfun()
{ try{
fieldSet();
cmpltObj.quantity();
if(cmpltObj.is==cmpltObj.stockSize)
{
JOptionPane.showMessageDialog(null,
"Item not found", "Failure", JOptionPane.ERROR_MESSAGE);
}
else
{
if(cmpltObj.qt > cmpltObj.qs )
JOptionPane.showMessageDialog(null," Out of Stock");
else
{
String query="insert into bill (name,Quantity,Price) values (?,?,?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,textFieldName.getText());
pst.setString(2,textFieldQuantity.getText());
pst.setString(3,textFieldPrice.getText());
if((textFieldId.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"ID is missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldName.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Name is Missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldQuantity.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Quantity is Missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldPrice.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Price is Missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if(Integer.parseInt(textFieldQuantity.getText())<=0)
{
JOptionPane.showMessageDialog(null,
"Quantity must be more than 0", "Failure", JOptionPane.ERROR_MESSAGE);
}
else
{
if(cmpltObj.ic==cmpltObj.cartSize)
{
pst.execute();
pst.close();
stkupdatefun(cmpltObj.qs-cmpltObj.qt);
fieldSet();
showStock();
showCart();
}
else
{
pst.close();
insbillupdatefun();
showStock();
showCart();
}
}
}
}
}
catch(Exception R2){
JOptionPane.showMessageDialog(null,"Failed..=="+R2);
showStock();
showCart();
}
}
//####################################SHOW STOCK####################################################
//#######################################DISPLAY FUNCTION##########################################################
public void showStock()
{
try{
String query="select ID,name,Quantity,Price,Quantity*Price as TOTAL from stock order by name asc";
//String query="select * from stock";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
pst.close();
rs.close();
}
catch(Exception e){
e.printStackTrace();
}
}
public int getSum(){
int rowsCount = table2.getRowCount();
int sum = 0;
for(int i = 0; i < rowsCount; i++){
sum = sum+Integer.parseInt(table2.getValueAt(i, 4).toString());
}
getTotalPurchasePrice();
int size=billNamesArray.size();
total=0;
int ch;
if(size!=0)
{
for(int i=0;i<size;i++)
{
float p=Integer.parseInt(quantArry.get(i).toString())*Integer.parseInt(purchaseList.get(i).toString());
total+=p;
}
if(textFieldTotal.getText().isEmpty())
textFieldTotal.setText("0");
tax=(Float.parseFloat(textFieldTotal.getText())-total)*28/100;
}
return sum;
}
public void showCart()
{
try{
Dimension d = table2.getPreferredSize();
scrollPane2.setBounds((int)(32*(currentResolutionWidth/referenceResolutionWidth)*(8/5)), (int)(159*(currentResolutionHeight/referenceResolutionHeight)*(8/5)), (int)(450*(currentResolutionWidth/referenceResolutionWidth)*(8/5)), table2.getRowHeight()*(table2.getRowCount()+1));
textFieldTotal.setBounds((int)(380*(currentResolutionWidth/referenceResolutionWidth)*(8/5)),(int)((100+ table2.getRowHeight()*(table2.getRowCount()+1)+60)*(currentResolutionHeight/referenceResolutionHeight)*(8/5)),(int)( 86*(currentResolutionWidth/referenceResolutionWidth)*(8/5)), (int)(22*(currentResolutionHeight/referenceResolutionHeight)*(8/5)));
lblTotal.setBounds((int)(298*(currentResolutionWidth/referenceResolutionWidth)*(8/5)), (int)((100+table2.getRowHeight()*(table2.getRowCount()+1)+60)*(currentResolutionHeight/referenceResolutionHeight)*(8/5)), (int)(86*(currentResolutionHeight/referenceResolutionHeight)*(8/5)), (int)(20*(currentResolutionHeight/referenceResolutionHeight)*(8/5)));
String query="select ID,name,Quantity,Price,Quantity*Price as TOTAL from bill";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
table2.setModel(DbUtils.resultSetToTableModel(rs));
int t=getSum();
textFieldTotal.setText(Integer.toString(t));
pst.close();
rs.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Total =="+e);
e.printStackTrace();
}
}
public void clearBill()
{
String query="DELETE FROM bill";
try
{
PreparedStatement pst=connection.prepareStatement(query);
pst.executeUpdate();
pst.close();
showCart();
}
catch(Exception e2)