Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Data.SqlClient
Public Class test1
Private textboxes As ArrayList
Private labels As ArrayList
'Private Tboxes As Integer = 10
Private _floor As Integer
Private _blank As Integer
Private chk_park As Integer
Private chk_amount As Integer
Private Sub test1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim conn As New SqlConnection
Dim cmd As New SqlCommand()
conn.ConnectionString = _conStr
cmd.CommandText = _
"SELECT count(park_floor)FROM park"
cmd.Connection = conn
conn.Open()
_floor = cmd.ExecuteScalar
Catch ex As Exception
MsgBox("[Error: " & ex.Message.ToUpper & "]", MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton1, "เกิดข้อผิดพลาด")
End Try
Method2()
End Sub
Private Sub Method2()
Dim conn1 As New SqlConnection
Dim cmd1 As New SqlCommand()
'----
Dim conn As New SqlConnection
Dim cmd As New SqlCommand()
'----
'----
Dim conn2 As New SqlConnection
Dim cmd2 As New SqlCommand()
Dim _amount As Integer
Dim Tboxes As Integer = _floor
Dim i As Integer = 0
Dim t As Integer = (480 / Tboxes) / 2
Dim f As New Font("Microsoft Sans Serif", t, FontStyle.Regular)
Dim test_null As Boolean
Dim show_blank As String
conn.ConnectionString = _conStr
conn.Open()
conn1.ConnectionString = _conStr
conn1.Open()
conn2.ConnectionString = _conStr
conn2.Open()
Me.textboxes = New ArrayList()
Me.labels = New ArrayList
For i = 0 To Tboxes - 1
_amount = i + 1
cmd2.CommandText = _
"SELECT park_amount FROM park WHERE park_floor='" & _amount.ToString & "' "
cmd2.Connection = conn2
chk_amount = cmd2.ExecuteScalar
cmd1.CommandText = _
"select count(times .park_in) " & _
"from times left join park on times .park_ip =park .park_ip " & _
"WHERE times.park_out is null AND park.park_floor='" & _amount.ToString & "' " & _
"GROUP BY times.park_ip ,park .park_amount"
cmd1.Connection = conn1
chk_park = cmd1.ExecuteScalar
If chk_park = 0 Then
show_blank = chk_amount
Else
cmd.CommandText = _
"select park .park_amount-count(times .park_in) " & _
"from times left join park on times .park_ip =park .park_ip " & _
"WHERE times.park_out is null AND park.park_floor='" & _amount.ToString & "' " & _
"GROUP BY times.park_ip ,park .park_amount"
cmd.Connection = conn
_blank = cmd.ExecuteScalar
test_null = cmd.ExecuteScalar
If _blank > 0 Then
show_blank = _blank
Else
show_blank = "เต็ม"
End If
End If
Me.textboxes.Add(New TextBox())
Me.labels.Add(New Label())
DirectCast(Me.labels(i), Label).Location = New System.Drawing.Point(50, 20 + i * (480 / Tboxes))
DirectCast(Me.labels(i), Label).Font = f
DirectCast(Me.labels(i), Label).TextAlign = HorizontalAlignment.Right
DirectCast(Me.labels(i), Label).AutoSize = True
DirectCast(Me.labels(i), Label).Size = New System.Drawing.Size(100, 480 / Tboxes)
DirectCast(Me.labels(i), Label).TabIndex = i + 2
DirectCast(Me.labels(i), Label).Text = "ชั้น " & i + 1.ToString()
Me.Controls.Add(DirectCast(Me.labels(i), Label))
DirectCast(Me.textboxes(i), TextBox).Location = New System.Drawing.Point(200, 20 + i * (480 / Tboxes))
DirectCast(Me.textboxes(i), TextBox).Name = "TextBoxName" & i.ToString()
DirectCast(Me.textboxes(i), TextBox).Font = f
DirectCast(Me.textboxes(i), TextBox).ReadOnly = True
DirectCast(Me.textboxes(i), TextBox).Multiline = True
DirectCast(Me.textboxes(i), TextBox).TextAlign = HorizontalAlignment.Center
DirectCast(Me.textboxes(i), TextBox).Size = New System.Drawing.Size(100, 480 / Tboxes)
DirectCast(Me.textboxes(i), TextBox).TabIndex = i + 2
DirectCast(Me.textboxes(i), TextBox).Text = show_blank.ToString()
'[String].Empty
Me.Controls.Add(DirectCast(Me.textboxes(i), TextBox))
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Method2()
End Sub
End Class