001.
Private
Sub
btnSaveList_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnSaveList.Click
002.
003.
If
txtID_E.Text =
""
Then
004.
MessageBox.Show(
"กรุณาระบุรหัสพนักงานก่อน !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
005.
txtID_E.Focus()
006.
Exit
Sub
007.
End
If
008.
009.
If
lsvProductsList.Items.Count = 0
Then
010.
MessageBox.Show(
"กรุณาป้อนรายการสั่งซื้ออุปกรณ์ !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
011.
txtID_P.Focus()
012.
Exit
Sub
013.
End
If
014.
015.
Dim
sqlOrder
As
String
=
""
016.
Dim
comOrder
As
OleDbCommand =
New
OleDbCommand
017.
018.
With
Conn
019.
If
.State = ConnectionState.Open
Then
.Close()
020.
.ConnectionString = strConn
021.
.Open()
022.
End
With
023.
024.
Try
025.
If
MessageBox.Show(
"คุณต้องการบันทึกรายการการสั่งซื้ออุปกรณ์ ใช่หรือไม่?"
,
"คำยืนยัน"
, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes
Then
026.
027.
AutoGenerateNo_O()
028.
029.
030.
031.
032.
With
comOrder
033.
.CommandType = CommandType.Text
034.
.CommandText = sqlOrder
035.
.Connection = Conn
036.
.ExecuteNonQuery()
037.
End
With
038.
039.
Dim
i
As
Integer
= 0
040.
041.
Dim
tmpID_P
As
String
=
""
042.
Dim
tmpNumber_O
As
Integer
= 0
043.
044.
Dim
sqlProducts
As
String
=
""
045.
046.
047.
048.
Dim
tmpDateOrder
As
Date
049.
tmpDateOrder =
Date
.Now
050.
051.
For
i = 0
To
lsvProductsList.Items.Count - 1
052.
sqlOrder =
"INSERT INTO t_Order (Order_id,Order_Date,Order_PriceTotal,Employee_id,Product_id,Order_Quantity) "
053.
sqlOrder &=
" VALUES('"
& LastID_O &
"',"
054.
sqlOrder &=
"'"
& dtpDateOrder.Value &
"',"
055.
sqlOrder &=
"'"
& lblTotal.Text &
"',"
056.
sqlOrder &=
"'"
& txtID_E.Text &
"')"
057.
sqlOrder &=
"'"
& tmpID_P &
"',"
058.
sqlOrder &= tmpNumber_O &
")"
059.
tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
060.
sqlOrder =
"INSERT INTO t_Order(Product_id,Order_Quantity)"
061.
062.
tmpNumber_O =
CInt
(lsvProductsList.Items(i).SubItems(3).Text)
063.
064.
065.
066.
With
comOrder
067.
.CommandText = sqlOrder
068.
.ExecuteNonQuery()
069.
End
With
070.
071.
Next
072.
073.
frmMain.tslStatus.Text =
"กำลังบันทึกข้อมูล..."
074.
MessageBox.Show(
"บันทึกรายการการสั่งซื้ออุปกรณ์เรียบร้อยแล้ว !!!"
,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
075.
frmMain.tslStatus.Text =
""
076.
077.
If
IsInstallPrinter() =
True
Then
078.
If
prDlg.ShowDialog = Windows.Forms.DialogResult.OK
Then
079.
prDoc.Print()
080.
End
If
081.
Else
082.
MessageBox.Show(
"กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
083.
084.
End
If
085.
086.
ClearAllEmployeesData()
087.
ClearAllProductsData()
088.
089.
lsvProductsList.Items.Clear()
090.
091.
txtID_E.Enabled =
True
092.
txtID_E.Focus()
093.
End
If
094.
Catch
ErrProcess
As
Exception
095.
MessageBox.Show(
"ไม่สามารถบันทึกรายการการสั่งซื้อได้ เนื่องจาก "
& ErrProcess.Message,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Warning)
096.
Exit
Sub
097.
End
Try
098.
End
Sub
099.
100.
มันเกี่ยวกับตรงนี้ด้วยไหมค่ะ
101.
Private
Sub
AutoGenerateNo_O()
102.
Dim
sqlTmp
As
String
=
""
103.
Dim
comTmp
As
OleDbCommand =
New
OleDbCommand
104.
Dim
drTmp
As
OleDbDataReader
105.
Dim
tmpID_O
As
Integer
= 0
106.
107.
sqlTmp =
"SELECT TOP 1 Order_id FROM t_Order ORDER BY Order_id DESC"
108.
109.
With
Conn
110.
If
.State = ConnectionState.Open
Then
.Close()
111.
.ConnectionString = strConn
112.
.Open()
113.
End
With
114.
115.
Try
116.
With
comTmp
117.
.CommandType = CommandType.Text
118.
.CommandText = sqlTmp
119.
.Connection = Conn
120.
drTmp = .ExecuteReader()
121.
122.
drTmp.Read()
123.
124.
tmpID_O =
CInt
(
CStr
((drTmp.Item(
"Order_id"
))))
125.
tmpID_O = tmpID_O + 1
126.
LastID_O = tmpID_O.ToString(
"00000"
)
127.
End
With
128.
Catch
129.
LastID_O =
"00001"
130.
End
Try
131.
End
Sub