Imports System.Data.SqlClient
Public Class frmCapacity
    Dim chair As Integer = 0
    Private Sub frmCapacity_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtCapacity.MaxLength = 3
        capacity()
    End Sub

    Private Sub txtCapacity_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCapacity.KeyPress
        If Not Char.IsNumber(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then e.KeyChar = ""
    End Sub

    Public Sub capacity()
        Try
            cm = New SqlCommand("select * from tblCapacity", cn)
            dr = cm.ExecuteReader
            While dr.Read
                lblCapacity.Text = dr.Item(0).ToString
            End While
            dr.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub txtCapacity_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCapacity.KeyDown
        If e.KeyCode = Keys.Enter Then
            If is_empty(txtCapacity) = True Then Exit Sub
            chair = recordCount("select count(seatNo) from tblSeat")
            ' capacity()

            If Convert.ToInt32(txtCapacity.Text) < chair Then
                MessageBox.Show("Sorry you have enough number of passengers already.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            End If

            Try
                cm = New SqlCommand("update tblCapacity set capacity = '" & Convert.ToInt32(txtCapacity.Text) & "'", cn)
                cm.ExecuteNonQuery()
                MessageBox.Show("Successfully updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtCapacity.Clear()
                frmCenter.auditTrail(uID, "Capacity update to " & txtCapacity.Text & "")
                frmCenter.dawat(uID, loginDate)
                capacity()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub
End Class