Imports System.Data.SqlClient
Public Class frmCenter

    Public Sub auditTrail(ByVal ID As String, ByVal action As String)
        cm = New SqlCommand("insert into tblAuditTrail(uID,actionmade,datemade) values('" + ID + "','" + action + "','" + DateTime.Now + "')", cn)
        cm.ExecuteNonQuery()
    End Sub

    Public Sub dawat(ByVal ID As String, ByVal loginID As String)
        uID = ID
        loginDate = loginID
        cm = New SqlCommand("select * from tblLoginTrail where uID like '" + uID + "' and loginDate like '" + loginDate + "'", cn)
        dr = cm.ExecuteReader
        dr.Read()
        If dr.HasRows Then
            logID = dr.GetValue(0).ToString()
        End If
        dr.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        auditTrail(uID, "Display passengers list")
        dawat(uID, loginDate)
        frmList.ShowDialog()
    End Sub

    Private Sub frmCenter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        connection()
        Timer1.Start()
        auditTrail(uID, "Load main form")
        dawat(uID, loginDate)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        auditTrail(uID, "Display login trail form")
        dawat(uID, loginDate)
        frmLoginTrail.MdiParent = Me
        frmLoginTrail.WindowState = FormWindowState.Maximized
        frmLoginTrail.Show()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        auditTrail(uID, "Display audit trail form")
        dawat(uID, loginDate)
        frmAuditTrail.MdiParent = Me
        frmAuditTrail.WindowState = FormWindowState.Maximized
        frmAuditTrail.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        auditTrail(uID, "Display transaction form")
        dawat(uID, loginDate)
        frmTransaction.ShowDialog()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        auditTrail(uID, "Display capacity form under the maintenance")
        dawat(uID, loginDate)
        frmCapacity.ShowDialog()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        auditTrail(uID, "Display passenger seat form under the maintenance")
        dawat(uID, loginDate)
        frmSeat.ShowDialog()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        auditTrail(uID, "Display payment form under the maintenance")
        dawat(uID, loginDate)
        frmPayment.ShowDialog()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lblTime.Text = DateTime.Now.ToString("hh:mm:ss tt")
        lbldate.Text = DateTime.Now.ToString("MMMM  dd  yyyy")
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If MsgBox("Are you sure you want to logout?", vbYesNo + vbQuestion, "Message") = MsgBoxResult.Yes Then
            cm = New SqlCommand("update tblUser set status = 'offline' where username like '" & frmLogin.txtuser.Text & "' and password like '" & frmLogin.txtpass.Text & "'", cn)
            cm.ExecuteNonQuery()
            dr.Close()
            cm = New SqlCommand("update tblLoginTrail set logoutDate = '" + DateTime.Now + "' where logID like '" + logID + "'", cn)
            cm.ExecuteNonQuery()
            dr.Close()
            auditTrail(uID, "Logged out successfully")
            dawat(uID, loginDate)
            Me.Close()
            frmLogin.Panel1.Enabled = True
            frmLogin.ProgressBar1.Visible = False
            frmLogin.txtpass.Clear()
            frmLogin.txtuser.Clear()
            frmLogin.txtuser.Text = "username"
            frmLogin.txtpass.Text = "password"
            frmLogin.ProgressBar1.Value = 0
            frmLogin.Height = 237
            frmLogin.Show()
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        auditTrail(uID, "Display about us")
        dawat(uID, loginDate)
        frmAboutus.ShowDialog()
    End Sub
End Class