-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSales_bill.java
More file actions
332 lines (273 loc) · 9.51 KB
/
Sales_bill.java
File metadata and controls
332 lines (273 loc) · 9.51 KB
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
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
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 javax.swing.JTable;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.Font;
import java.awt.FlowLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
public class Sales_bill {
public JFrame frmAmElectronics;
private JTextField chno;
private JTextField c1;
private JTextField c2;
private final ButtonGroup buttonGroup = new ButtonGroup();
/**
* @wbp.nonvisual location=134,101
*/
private final JTable table = new JTable();
/**
* @wbp.nonvisual location=63,71
*/
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
int i=0;
Sales_bill window = new Sales_bill(i);
window.frmAmElectronics.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
* @param i
*/
public Sales_bill(int i)
{
JOptionPane.showMessageDialog(null, i);
initialize(i);
}
/**
* Initialize the contents of the frame.
*/
private void initialize(int i) {
table.setRowHeight(40);
table.setFont(new Font("Tahoma", Font.BOLD, 15));
table.setBorder(new LineBorder(new Color(0, 0, 0)));
frmAmElectronics = new JFrame();
frmAmElectronics.setTitle("AM ELECTRONICS");
frmAmElectronics.setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\stuff\\img1.jpg"));
frmAmElectronics.setBounds(100, 100, 642, 463);
frmAmElectronics.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmAmElectronics.getContentPane().setLayout(null);
frmAmElectronics.setContentPane(new JLabel(new ImageIcon("D:\\xyz.jpg")));
JRadioButton p1 = new JRadioButton("Cash");
buttonGroup.add(p1);
p1.setBounds(65, 219, 109, 23);
frmAmElectronics.getContentPane().add(p1);
JRadioButton p2 = new JRadioButton("Cheque");
buttonGroup.add(p2);
p2.setBounds(65, 245, 109, 23);
frmAmElectronics.getContentPane().add(p2);
chno = new JTextField();
chno.setBounds(242, 246, 137, 20);
frmAmElectronics.getContentPane().add(chno);
chno.setColumns(10);
JRadioButton p3 = new JRadioButton("Card Payment");
buttonGroup.add(p3);
p3.setBounds(68, 271, 109, 23);
frmAmElectronics.getContentPane().add(p3);
c1 = new JTextField();
c1.setColumns(10);
c1.setBounds(164, 301, 137, 20);
frmAmElectronics.getContentPane().add(c1);
c2 = new JTextField();
c2.setColumns(10);
c2.setBounds(164, 326, 137, 20);
frmAmElectronics.getContentPane().add(c2);
JComboBox<String> c3 = new JComboBox<String>();
c3.setModel(new DefaultComboBoxModel<String>(new String[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}));
c3.setBounds(164, 351, 57, 22);
frmAmElectronics.getContentPane().add(c3);
JComboBox<String> c4 = new JComboBox<String>();
c4.setModel(new DefaultComboBoxModel<String>(new String[] {"2018", "2019", "2020", "2021", "2022", "2023"}));
c4.setBounds(230, 351, 57, 22);
frmAmElectronics.getContentPane().add(c4);
JButton btnNewButton = new JButton("Good Delivered");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String query = "Select sales_id,sdate,customername,total_amount,pname,qty,price from sales where sales_id=?";
PreparedStatement stmt = conObject.prepareStatement(query);
stmt.setInt(1,i);
ResultSet rs = stmt.executeQuery();
int totalamount=0;
String sdate="";
while(rs.next())
{
totalamount = totalamount + rs.getInt(4);
sdate=rs.getString(2);
}
String query1 = "insert into sales_payment(sales_id,sales_date,amt,paymentmode,chno,cardno,cardname,validmonth,validyear) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement stmt1 = conObject.prepareStatement(query1);
stmt1.setInt(1,i);
stmt1.setString(2,sdate);
stmt1.setInt(3,totalamount);
if(p1.isSelected() == true)
{
stmt1.setString(4,"cash");
stmt1.setString(5,"");
stmt1.setString(6,"");
stmt1.setString(7,"");
stmt1.setInt(8,0);
stmt1.setInt(9,0);
}
if(p2.isSelected() == true)
{
stmt1.setString(4,"cheque");
stmt1.setString(5,chno.getText());
stmt1.setString(6,"");
stmt1.setString(7,"");
stmt1.setInt(8,0);
stmt1.setInt(9,0);
}
if(p3.isSelected() == true)
{
stmt1.setString(4,"card");
stmt1.setString(5,"");
stmt1.setString(6,c1.getText());
stmt1.setString(7,c1.getText());
stmt1.setInt(8,(int) (c3.getSelectedItem()));
stmt1.setInt(9,(int) (c4.getSelectedItem()));
}
int result = stmt1.executeUpdate();
if(result == 1)
{
JOptionPane.showMessageDialog(null, "inserted in sales table");
String str2;
int pqty;
query = "Select sales_id,sdate,customername,total_amount,pname,qty,price from sales where sales_id=?";
stmt = conObject.prepareStatement(query);
stmt.setInt(1,i);
rs = stmt.executeQuery();
while(rs.next())
{
str2=rs.getString(5); pqty = rs.getInt(6);
String query2="select qty,cprice from actual_product where modelname=?";
PreparedStatement stmt3 = conObject.prepareStatement(query2);
stmt3.setString(1, str2);
ResultSet rs3 = stmt3.executeQuery();
int qty=0;
while(rs3.next())
{
qty = rs3.getInt(1);
int final_qty= qty - pqty;
query = "update actual_product set qty=? where modelname=?";
stmt1 = conObject.prepareStatement(query);
stmt1.setInt(1,final_qty);
stmt1.setString(2,str2);
result = stmt1.executeUpdate();
if(result == 1)
JOptionPane.showMessageDialog(null, "Items Delivered! Stock Updated.");
}
}
}
else
JOptionPane.showMessageDialog(null,"Items not delivered...error!");
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
}
});
btnNewButton.setBounds(67, 402, 144, 23);
frmAmElectronics.getContentPane().add(btnNewButton);
JButton btnGenerateBill = new JButton("Generate Bill");
btnGenerateBill.setBounds(270, 402, 144, 23);
frmAmElectronics.getContentPane().add(btnGenerateBill);
JLabel lblNewLabel = new JLabel("Payment Details");
lblNewLabel.setBounds(42, 198, 46, 14);
frmAmElectronics.getContentPane().add(lblNewLabel);
try {
Connection conObject=DriverManager.getConnection("jdbc:ucanaccess://d:/electronics1.accdb");
String query = "Select sales_id,invoice_no,sdate,customername,pname,qty,price,gst,total_amount from sales where sales_id=?";
PreparedStatement stmt = conObject.prepareStatement(query);
stmt.setInt(1,i);
ResultSet rs = stmt.executeQuery();
int j=0;
while(rs.next())
{
table.setValueAt(rs.getInt(1), j, 0);
table.setValueAt(rs.getString(2), j, 1);
table.setValueAt(rs.getString(3), j, 2);
table.setValueAt(rs.getString(4), j, 3);
table.setValueAt(rs.getString(5), j, 4);
table.setValueAt(rs.getInt(6), j, 5);
table.setValueAt(rs.getDouble(7), j, 6);
table.setValueAt(rs.getDouble(8), j, 7);
table.setValueAt(rs.getDouble(9), j, 8);
j++;
}
frmAmElectronics.getContentPane().add(new JScrollPane());
frmAmElectronics.getContentPane().validate();
frmAmElectronics.getContentPane().repaint();
stmt.close();
conObject.close();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
}
c1.setVisible(false);
c2.setVisible(false);
c3.setVisible(false);
c4.setVisible(false);
chno.setVisible(false);
p1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
c1.setVisible(false);
c2.setVisible(false);
c3.setVisible(false);
c4.setVisible(false);
chno.setVisible(false);
}
});
p2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chno.setVisible(true);
c1.setVisible(false);
c2.setVisible(false);
c3.setVisible(false);
c4.setVisible(false);
}
});
p3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
c1.setVisible(true);
c2.setVisible(true);
c3.setVisible(true);
c4.setVisible(true);
chno.setVisible(false);
}
});
}
}