'====>ปุ่มบันทึก
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sb As StringBuilder
If TextBox16.Text.Trim() = "" Then
MessageBox.Show("กรุณากดปุ่มเพิ่มใบรับสินค้าก่อน", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = .ConnectionString
.Open()
End With
If ListView2.Items.Count = 0 Then
Exit Sub
End If
'====> บันทึกตาราง Receive
Dim i As Integer = 0
Dim sqlsave As String = ""
sb = New StringBuilder
sb.Remove(0, sb.Length)
sb.Append("insert into RECEIVE(Receive_ID,Order_Id,Receive_Date,Vat,Net_Total)")
sb.Append("Values(@Receive_ID,@Order_ID,@Receive_Date ,@Vat,@Net_Total)")
sqlsave = sb.ToString()
Dim cm As New SqlCommand
With cm
.Parameters.Clear()
.CommandText = sqlsave
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@Receive_ID", SqlDbType.NVarChar, 5).Value = TextBox16.Text
.Parameters.Add("@Order_ID", SqlDbType.NVarChar, 5).Value = TextBox2.Text
.Parameters.Add("@Receive_Date", SqlDbType.DateTime).Value = Label4.Text
.Parameters.Add("@Vat", SqlDbType.Int).Value = totVat
.Parameters.Add("@Net_Total", SqlDbType.Int).Value = netTotal
.ExecuteNonQuery()
End With
'====> บันทึกตาราง re_detail
Dim sqlsave1 As String = ""
Dim a As Integer = 0
For a = 0 To ListView2.Items.Count - 1
sb = New StringBuilder
sb.Remove(0, sb.Length)
sb.Append("insert into RE_DETAIL(Med_ID,Receive_ID,Amount)")
sb.Append(" Values(@Med_ID,@Receive_ID,@Amount)")
sqlsave1 = sb.ToString()
Next
With cm
.Parameters.Clear()
.CommandText = sqlsave1
.Connection = cn
.Parameters.Clear()
.Parameters.Add("@Med_ID", SqlDbType.NVarChar, 5).Value = TextBox14.Text
.Parameters.Add("@Receive_ID", SqlDbType.NVarChar, 5).Value = TextBox16.Text
.Parameters.Add("@Amount", SqlDbType.Int).Value = TextBox13.Text
.ExecuteNonQuery()
End With