-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertBills.java
208 lines (158 loc) · 6.28 KB
/
InsertBills.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
import java.sql.PreparedStatement;
import java.util.Calendar;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javaGUI.sqlconnection;
public class InsertBills {
private JTextField textFieldIdBill;
private JTextField textFieldPriceBill;
private JTextField textFieldTotalBill;
private JTextField textFieldcNameBill;
private JTextField textFieldNameBill;
private JTextField textFieldPaidBill;
private JTextField textFieldRemainingBill;
private JTextField textFieldcMobileBill ;
private JTextField textFieldPRemainingBill;
private JTextField textFieldTRemainingBill;
private JTextField textFieldCityBill;
private JTextField textFieldDateBill;
private JTextField textFieldQuantityBill;
//######################################################################################################
public java.sql.Date sqlDate;
Autocomplete cmpltObj=new Autocomplete();
private java.sql.Connection connection=null;
//bill bl=new bill();
public InsertBills()
{
connection=sqlconnection.dbConnector();
}
public void billcomponents(JTextField textFieldQuantity1,JTextField textFieldName1,JTextField textFieldId1,JTextField textFieldPrice1,JTextField textFieldTotal1,JTextField textFieldcName1,JTextField textFieldPaid1,JTextField textFieldRemaining1,JTextField textFieldcMobile1,JTextField textFieldPRemaining1,JTextField textFieldTRemaining1,JTextField textFieldCity1,JTextField textFieldDate1)
{
textFieldIdBill=textFieldId1;
textFieldPriceBill=textFieldPrice1;
textFieldTotalBill=textFieldTotal1;
textFieldcNameBill=textFieldcName1;
textFieldNameBill=textFieldName1;
textFieldPaidBill=textFieldPaid1;
textFieldRemainingBill=textFieldRemaining1;
textFieldcMobileBill=textFieldcMobile1 ;
textFieldPRemainingBill=textFieldPRemaining1;
textFieldTRemainingBill=textFieldTRemaining1;
textFieldCityBill=textFieldCity1;
textFieldDateBill=textFieldDate1;
textFieldQuantityBill=textFieldQuantity1;
}
//################################ OLD CUSTOMER INSERT IN PROFIT#############################################
public void existUpdateBill()
{
try{
String query="Update profit set Paid='"+(cmpltObj.pp+cmpltObj.pt)+"',Total='"+(cmpltObj.tp+Integer.parseInt(textFieldTotalBill.getText()))+ "',Remaining='"+textFieldTRemainingBill.getText()+"' where Name='"+textFieldcNameBill.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 newInsertBill()
{
try{
String query="Insert into profit (Name,city,mobile,Date,Paid,Remaining,Total) values (?,?,?,?,?,?,?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,textFieldcNameBill.getText().toLowerCase());
pst.setString(2,textFieldCityBill.getText().toLowerCase());
pst.setString(3,textFieldcMobileBill.getText());
pst.setString(4,cmpltObj.sqlDate.toString());
pst.setString(5,textFieldPaidBill.getText());
pst.setString(6,textFieldTRemainingBill.getText());
pst.setString(7,textFieldTotalBill.getText());
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST NEW INSERT =="+e);
}
}
//#########################################INSERT IN RECORD FOR ALL USERS##################################
public void commonInsertBill()
{
try{
String query="Insert into record (Name,city,mobile,Date,Paid,Remaining,Total,tax) values (?,?,?,?,?,?,?,?)";
float tax=(float) (Float.parseFloat(textFieldTotalBill.getText().toString())*28)/100;
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1,textFieldcNameBill.getText().toLowerCase());
pst.setString(2,textFieldCityBill.getText().toLowerCase());
pst.setString(3,textFieldcMobileBill.getText());
pst.setString(4,cmpltObj.sqlDate.toString());
pst.setString(5,textFieldPaidBill.getText());
pst.setString(6,textFieldTRemainingBill.getText());
pst.setString(7,textFieldTotalBill.getText());
JOptionPane.showMessageDialog(null, "TAX :"+tax);
pst.setString(7,Float.toString(tax));
pst.execute();
pst.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "EXIST COMMON INSERT =="+e);
}
}
//#########################################INSERT FUNCTION FOR CUSTOMERS DETAILS#######################################
public void custinsfunBill()
{
try{
if((textFieldNameBill.getText().toLowerCase()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Name is Missing \n"+"Enter valid Data", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldcMobileBill.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Please Enter Mobile number...!", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldCityBill.getText()).isEmpty())
{
JOptionPane.showMessageDialog(null,
"Please Enter city...!", "Failure", JOptionPane.ERROR_MESSAGE);
}
else if((textFieldPaidBill.getText()).isEmpty())
{
textFieldPaidBill.setText(Integer.toString(0));
}
else
{
int ch=cmpltObj.checkCustomer(textFieldNameBill);
if(ch==1)
{
commonInsertBill();
existUpdateBill();
//showfun();
}
else
{
commonInsertBill();
newInsertBill();
}
}
//JOptionPane.showMessageDialog(null,"Data Saved..........!");
}
catch(Exception R2){
JOptionPane.showMessageDialog(null,
R2.getMessage(), "Failure", JOptionPane.ERROR_MESSAGE);
R2.printStackTrace();
}
textFieldNameBill.setText(null);
textFieldcMobileBill.setText(null);
textFieldCityBill.setText(null);
textFieldPaidBill.setText(null);
textFieldRemainingBill.setText(null);
textFieldPRemainingBill.setText(null);
textFieldTRemainingBill.setText(null);
}
//=================================================================================================================================================
}