Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
If lsvProductlist.Items.Count > 0 Then
If MessageBox.Show("คุณต้องการบัน กรายการสั่งซื้อสินค้า ใช่หรือไม่ ?", "คำยืนยัน",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
tr = conn.BeginTransaction()
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO Order (ORDERID,ORDERDATE)")
sb.Append("VALUES (" & txtproductid.Text.Trim().Replace("", "") & ",")
sb.Append("" & DateTime.Today & ")")
Dim sqlSave As String = sb.ToString()
Dim Com = conn.CreateCommand()
With Com
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = conn
.Transaction = tr
.ExecuteNonQuery()
End With
sb.Remove(0, sb.Length)
sb.Append("SELECT TOP 1 ORDERID FROM Order")
sb.Append("Order BY ORDERID DESC")
sqlSave = sb.ToString()
Dim LastOrderID As Integer
With Com
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = conn
dr = .ExecuteReader
If dr.HasRows Then
dr.Read()
LastOrderID = dr.GetInt32(dr.GetOrdinal("ORDERID"))
Else
LastOrderID = 10000
End If
End With
dr.Close()
Dim i As Integer
For i = 0 To lsvProductlist.Items.Count - 1
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO [Orderdetail] (OrderID,ProductID,")
sb.Append("ProductName,UnitPrice,Quantity,Total)")
sb.Append("VALUES (" & LastOrderID & ",")
sb.Append("" & lsvProductlist.Items(i).SubItems(0).Text & ",")
sb.Append(lsvProductlist.Items(i).SubItems(2).Text & ",")
sb.Append(lsvProductlist.Items(i).SubItems(3).Text & ",0)")
sqlSave = sb.ToString()
With Com
.CommandText = sqlSave
.ExecuteNonQuery()
End With
Next
tr.Commit()
MessageBox.Show("บันทึกรายการสั่งซื้อสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
lsvProductlist.Clear()
lblTotal.Text = "0"
txtproductid.Focus()
End If
End If
End Sub
str = "INSERT INTO inputdata (users,password) VALUES('" & user.Text & "' , '" & password.Text & "')"
Dim myCommand As SqlCommand = New SqlCommand(str, connetionString)
' Dim REDER As SqlDataReader
Try
If user.Text = Nothing Then
MsgBox("You Must Enter The Username!", MsgBoxStyle.Exclamation, "Error!")
MsgBox("ท่านใส่ข้อมูลที่ชื่อว่า user ไม่ครบถ้วน") : Exit Sub
user.Clear()
End If
If password.Text = Nothing Then
MsgBox("You Must Enter The Passworld !", MsgBoxStyle.Exclamation, "Error!")
MsgBox("ท่านใส่ข้อมูล password ไม่ครบถ้วน") : Exit Sub
password.Clear()
End If
connetionString.Open()
' Dim cm As New SqlCommand(str, connetionString)
Dim result = myCommand.ExecuteScalar()
If result Is Nothing Then
MessageBox.Show("คุณต้องการเพิ่มรายชื่อใหม่ใช่หรือไม่?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
MessageBox.Show("เพิ่มรายชื่อพนักงานแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
user.Clear()
password.Clear()
ElseIf result IsNot Nothing Then
'MessageBox.Show("เพิ่มรายชื่อพนักงานแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
MessageBox.Show("คุณ'ได้เพิ่มข้อมูล ซ้ำกันแล้ว ?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'MessageBox.Show("ยืนยันต้องการยกเลิก", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If (connetionString.State = ConnectionState.Open) Then
connetionString.Close()
End If
End Try
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Try
If lsvProductlist.Items.Count > 0 Then
End If
If MessageBox.Show("คุณต้องการบัน กรายการสั่งซื้อสินค้า ใช่หรือไม่ ?", "คำยืนยัน",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
End If
conn.Open()
tr = conn.BeginTransaction()
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO Order (ORDERID,ORDERDATE)")
sb.Append("VALUES (" & txtproductid.Text.Trim().Replace("", "") & ",")
sb.Append("" & DateTime.Today & ")")
Dim sqlSave As String = sb.ToString()
Dim Com = conn.CreateCommand()
With Com
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = conn
.Transaction = tr
.ExecuteNonQuery()
End With
sb.Remove(0, sb.Length)
sb.Append("SELECT TOP 1 ORDERID FROM Order")
sb.Append("Order BY ORDERID DESC")
sqlSave = sb.ToString()
Dim LastOrderID As Integer
With Com
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = conn
dr = .ExecuteReader
If dr.HasRows Then
dr.Read()
LastOrderID = dr.GetInt32(dr.GetOrdinal("ORDERID"))
Else
LastOrderID = 10000
End If
'----------------------------'
End With
Dim i As Integer
For i = 0 To lsvProductlist.Items.Count - 1
Next
sb.Remove(0, sb.Length)
sb.Append("INSERT INTO [Orderdetail] (OrderID,ProductID,")
sb.Append("ProductName,UnitPrice,Quantity,Total)")
sb.Append("VALUES (" & LastOrderID & ",")
sb.Append("" & lsvProductlist.Items(i).SubItems(0).Text & ",")
sb.Append(lsvProductlist.Items(i).SubItems(2).Text & ",")
sb.Append(lsvProductlist.Items(i).SubItems(3).Text & ",0)")
sqlSave = sb.ToString()
With Com
.CommandText = sqlSave
.ExecuteNonQuery()
End With
Catch ex As Exception
tr.Commit()
MessageBox.Show("บันทึกรายการสั่งซื้อสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
lsvProductlist.Clear()
lblTotal.Text = "0"
txtproductid.Focus()
conn.Close()
End Try
End Sub