01.
Private
Sub
BarCode20()
02.
Dim
Sql
As
String
=
""
03.
Dim
ReadId
As
String
=
""
04.
Dim
NewId
As
Integer
= 0
05.
06.
Try
07.
Com =
New
SqlCommand()
08.
With
Conn
09.
If
.State = ConnectionState.Open
Then
.Close()
10.
.ConnectionString = strConn
11.
.Open()
12.
End
With
13.
14.
Sql =
"DELETE FROM BarCode20"
15.
With
Com
16.
.CommandText = Sql
17.
.CommandType = CommandType.Text
18.
.Connection = Conn
19.
.ExecuteNonQuery()
20.
End
With
21.
22.
23.
Sql =
"SELECT TOP 1 ID_Barcode20 FROM BarCode20 ORDER BY ID_Barcode20 DESC"
24.
With
Com
25.
.CommandType = CommandType.Text
26.
.CommandText = Sql
27.
.Connection = Conn
28.
dr = .ExecuteReader()
29.
If
dr.HasRows
Then
30.
dr.Read()
31.
ReadId = dr.Item(
"ID_Barcode20"
).ToString()
32.
NewId =
CInt
(ReadId) + 1
33.
End
If
34.
End
With
35.
dr.Close()
36.
37.
For
j = 0
To
dgvFreshOrganicLongan.Rows.Count - 1
38.
If
CStr
(dgvFreshOrganicLongan.Rows(j).Cells(13).Value) <>
""
Or
CStr
(dgvFreshOrganicLongan.Rows(j).Cells(13).Value) <>
"0"
Then
39.
Dim
SizeLongan
As
String
=
""
40.
If
dgvFreshOrganicLongan.Rows(j).Cells(0).Value.ToString.Remove(0, 7).Remove(2, 4) =
"01"
Then
41.
SizeLongan =
"Cut"
42.
ElseIf
dgvFreshOrganicLongan.Rows(j).Cells(0).Value.ToString.Remove(0, 7).Remove(2, 4) =
"02"
Then
43.
SizeLongan =
"AA"
44.
ElseIf
dgvFreshOrganicLongan.Rows(j).Cells(0).Value.ToString.Remove(0, 7).Remove(2, 4) =
"03"
Then
45.
SizeLongan =
"A"
46.
End
If
47.
48.
Dim
NameProduct_Eng
As
String
=
""
49.
Sql =
"SELECT T.NameTypePruduct_Eng,M.Name_Eng"
50.
Sql &=
" FROM TypeProduct AS T,Member AS M"
51.
Sql &=
" WHERE T.ID_TypeProduct=@ID_TypeProduct AND M.Id_Member=@Id_Member"
52.
Dim
dtNameProduct =
New
DataTable()
53.
With
Com
54.
.Parameters.Clear()
55.
.CommandText = Sql
56.
.CommandType = CommandType.Text
57.
.Connection = Conn
58.
.Parameters.Add(
"@ID_TypeProduct"
, SqlDbType.NVarChar).Value = dtGanBarcode.Rows(j).Item(
"BarCode"
).ToString().Remove(0, 18)
59.
.Parameters.Add(
"@Id_Member"
, SqlDbType.NVarChar).Value = dtGanBarcode.Rows(j).Item(
"BarCode"
).ToString().Remove(3, 17)
60.
dr = .ExecuteReader
61.
If
dr.HasRows
Then
62.
dtNameProduct.Load(dr)
63.
NameProduct_Eng = dtNameProduct.Rows(0).Item(
"NameTypePruduct_Eng"
).ToString() &
" "
& SizeLongan &
" ("
& dtNameProduct.Rows(0).Item(
"Name_Eng"
).ToString() &
")"
64.
End
If
65.
End
With
66.
dr.Close()
67.
68.
For
i = 0
To
CInt
(dgvFreshOrganicLongan.Rows(j).Cells(13).Value) - 1
69.
Sql =
"INSERT INTO BarCode20(ID_Barcode20,BarCodeNumber20,NameProduct)"
70.
Sql &=
" VALUES(@ID_Barcode20,@BarCodeNumber20,@NameProduct)"
71.
With
Com
72.
.CommandText = Sql
73.
.Parameters.Clear()
74.
.Parameters.Add(
"@ID_Barcode20"
, SqlDbType.NVarChar).Value = NewId.ToString(
"0000"
)
75.
.Parameters.Add(
"@BarCodeNumber20"
, SqlDbType.NVarChar).Value = dtGanBarcode.Rows(j).Item(
"BarCode"
).ToString()
76.
.Parameters.Add(
"@NameProduct"
, SqlDbType.NVarChar).Value = NameProduct_Eng
77.
.ExecuteNonQuery()
78.
NewId = NewId + 1
79.
End
With
80.
dr.Close()
81.
Next
82.
End
If
83.
Next
84.
Conn.Close()
85.
ShellEx(
CInt
(
Me
.Handle),
"Open"
, Application.StartupPath() &
"\Barcode21.btw"
,
""
,
""
, 10)
86.
Catch
ErrProcess
As
Exception
87.
MessageBox.Show(
"ไม่สามารถเพิ่มสมาชิกใหม่ได้ เนื่องจาก"
& ErrProcess.Message,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Warning)
88.
Exit
Sub
89.
End
Try
90.
End
Sub