01.
Private
Sub
Button2_Click_1(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
02.
sql =
"insert into savegoods_production(save_pro_id,pro_id,goods_name,goods_unit,goods_amount,goods_price,emp_name,emp_tell,date_save) values "
03.
Dim
i
As
Integer
=
Me
.ListView1.Items.Count - 1
04.
For
j
As
Integer
= 0
To
i
05.
Dim
po_id
As
String
=
Me
.ListView1.Items(j).SubItems(1).Text
06.
Dim
goods_name
As
String
=
Me
.ListView1.Items(j).SubItems(2).Text
07.
Dim
goods_unit
As
String
=
Me
.ListView1.Items(j).SubItems(3).Text
08.
Dim
goods_amount
As
Double
=
Me
.ListView1.Items(j).SubItems(4).Text
09.
Dim
goods_price
As
Double
=
Me
.ListView1.Items(j).SubItems(5).Text
10.
Dim
em_name
As
String
=
Me
.em_name.Text
11.
Dim
em_tell
As
String
=
Me
.em_tell.Text
12.
Dim
save_date
As
Date
=
Me
.lbl_date_now.Text
13.
If
j = i
Then
14.
sql &=
String
.Format(
"('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')"
,
Me
.lbl_save_id.Text, po_id, goods_name, goods_unit, goods_amount, goods_price, em_name, em_tell, save_date)
15.
Else
16.
sql &=
String
.Format(
"('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}') ,"
,
Me
.lbl_save_id.Text, po_id, goods_name, goods_unit, goods_amount, goods_price, em_name, em_tell, save_date)
17.
End
If
18.
19.
Next
20.
21.
cmd =
New
SqlClient.SqlCommand(sql, cn)
22.
If
cmd.ExecuteNonQuery = 0
Then
23.
MsgBox(
"ไม่สามารถบันทึกได้"
)
24.
Else
25.
MsgBox(
"บันทึกสำเร็จ"
)
26.
27.
Dim
p
As
Integer
=
Me
.ListView1.Items.Count - 1
28.
For
j
As
Integer
= 0
To
p
29.
30.
31.
Dim
goods_name
As
String
=
Me
.ListView1.Items(j).SubItems(2).Text
32.
Dim
goods_unit
As
String
=
Me
.ListView1.Items(j).SubItems(3).Text
33.
Dim
goods_amount
As
Double
=
Me
.ListView1.Items(j).SubItems(4).Text
34.
Dim
goods_price
As
Double
=
Me
.ListView1.Items(j).SubItems(5).Text
35.
36.
37.
Dim
sql2
As
String
=
"select goods_name from stock_goods where goods_name ='"
& goods_name &
"'"
38.
Dim
cmd
As
New
SqlCommand(sql2, cn)
39.
Dim
dr
As
SqlDataReader
40.
dr = cmd.ExecuteReader
41.
If
dr.Read >= 0
Then
42.
sql =
"insert into stock_goods(goods_name,goods_unit,goods_amount,goods_price) values "
43.
If
j = p
Then
44.
sql &=
String
.Format(
"('{0}','{1}','{2}','{3}')"
, goods_name, goods_unit, goods_amount, goods_price)
45.
Else
46.
sql &=
String
.Format(
"('{0}','{1}','{2}','{3}') ,"
, goods_name, goods_unit, goods_amount, goods_price)
47.
End
If
48.
49.
Else
50.
sql =
"update stock_goods set goods_amount = goods_amount+ "
& goods_amount &
" where goods_name='"
& goods_name &
"'"
51.
End
If
52.
53.
54.
Next
55.
56.
cmd =
New
SqlClient.SqlCommand(sql, cn)
57.
If
cmd.ExecuteNonQuery = 0
Then
58.
MsgBox(
"ไม่สามารถบันทึกได้"
)
59.
Else
60.
MsgBox(
"บันทึกสำเร็จ"
)
61.
End
If
62.
End
If
63.
End
Sub