01.
Object[] data =
new
Object[
0
];
02.
DefaultTableModel std =
new
DefaultTableModel();
03.
std = (DefaultTableModel) table2.getModel();
04.
std.addRow(data);
05.
int
row = table.getSelectedRow();
06.
int
row1 = table2.getRowCount() -
1
;
07.
08.
if
(row == -
1
) {
09.
JOptionPane.showMessageDialog(
null
,
"กรูณาค้นสินค้าและเลือกสินค้าก่อน"
,
"เลือกสินค้าก่อน"
, JOptionPane.ERROR_MESSAGE);
10.
std.removeRow(row1);
11.
count();
12.
return
;
13.
}
else
{
14.
String id = table.getValueAt(row,
0
).toString();
15.
String name = table.getValueAt(row,
1
).toString();
16.
String unit = table.getValueAt(row,
2
).toString();
17.
String price = table.getValueAt(row,
3
).toString();
18.
String amount = table.getValueAt(row,
4
).toString();
19.
table2.setValueAt(bill.getText(), row1,
0
);
20.
table2.setValueAt(count++, row1,
1
);
21.
table2.setValueAt(id, row1,
2
);
22.
table2.setValueAt(name, row1,
3
);
23.
table2.setValueAt(unit, row1,
4
);
24.
25.
String unitbuy2 = JOptionPane.showInputDialog(
this
,
"ใส่จำนวนที่ต้องการซื้อ"
,
"กรอกจำนวนที่ต้องการซื้อ"
, JOptionPane.INFORMATION_MESSAGE);
26.
if
(unitbuy2 ==
null
) {
27.
JOptionPane.showMessageDialog(
null
,
"กรุณากรอกจำนวน"
);
28.
std.removeRow(row1);
29.
count =
1
;
30.
return
;
31.
}
32.
if
(unitbuy2.matches(
"[0-9]+$"
)) {
33.
}
else
{
34.
JOptionPane.showMessageDialog(
null
,
"กรุณากรอกเป็นตัวเลขเท่านั้น"
);
35.
std.removeRow(row1);
36.
count =
1
;
37.
return
;
38.
}
39.
40.
unitbuy1 = Integer.parseInt(unitbuy2);
41.
int
amount1 = Integer.parseInt(amount);
42.
if
(unitbuy1 > amount1) {
43.
JOptionPane.showMessageDialog(
null
,
"สินค้าไม่พอขาย"
);
44.
std.removeRow(row1);
45.
count--;
46.
return
;
47.
}
48.
int
pricebuy = Integer.parseInt(price);
49.
int
sum = unitbuy1 * pricebuy;
50.
table2.setValueAt(unitbuy1, row1,
5
);
51.
table2.setValueAt(sum, row1,
6
);
52.
String showtotal2 = table2.getValueAt(row1,
6
).toString();
53.
int
sum1;
54.
sum1 = Integer.parseInt(showtotal2);
55.
total = total + sum1;
56.
String show = String.valueOf(total);
57.
showtotal1.setText(show);
58.
tax =
0.07
;
59.
tax = total * tax;
60.
DecimalFormat df =
new
DecimalFormat(
"0.00"
);
61.
String taxshow = String.valueOf(df.format(tax));
62.
showtax.setText(taxshow);
63.
saletotal = total + tax;
64.
String saletotalshow = String.valueOf(df.format(saletotal));
65.
showtotalsale.setText(saletotalshow);
66.
for
(
int
row11 = -
1
; row11 < row1; ++row11) {
67.
String check1 = table.getValueAt(row,
4
).toString();
68.
int
check2 = Integer.parseInt(check1);
69.
int
sumcheck = check2 - unitbuy1;
70.
int
checkstore[] = {sumcheck};
71.
for
(
int
a =
0
; a < checkstore.length; a++) {
72.
System.out.println(checkstore[a]);
73.
}
74.
System.out.println(row11);
75.
System.out.println(row1);