Public Class Form1
Private NewServerMessage As New SampleInCommingMessageFromServer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
clientView.Width = 1000
Me.Width = clientView.Width + 40
AddListViewHeader()
End Sub
Private Sub AddListViewHeader()
Dim LVHeader() As ColumnHeader = {New ColumnHeader With {.Text = "#", .Width = 50, .TextAlign = HorizontalAlignment.Left},
New ColumnHeader With {.Text = "Name", .Width = 200, .TextAlign = HorizontalAlignment.Left},
New ColumnHeader With {.Text = "Time Started", .Width = 130, .TextAlign = HorizontalAlignment.Center},
New ColumnHeader With {.Text = "Time Consumed", .Width = 100, .TextAlign = HorizontalAlignment.Center},
New ColumnHeader With {.Text = "IP Address", .Width = 150, .TextAlign = HorizontalAlignment.Left},
New ColumnHeader With {.Text = "Location", .Width = 200, .TextAlign = HorizontalAlignment.Left},
New ColumnHeader With {.Text = "Card #", .Width = -2, .TextAlign = HorizontalAlignment.Left}}
clientView.Columns.Clear()
clientView.Columns.AddRange(LVHeader)
End Sub
'Private Sub OnIncomingMessage(ByVal Args As UNOLibs.Net.ServerClass.InMessEvArgs) Handles Server.IncomingMessage
Private Sub OnIncomingMessage(ByVal Args As SampleInCommingMessageFromServer)
'Assumed data structure from the incomming server message
'"Login.The_Kid.21/09/12 05:34:25.Baltimore.12345678910"
'clientView ListView Structure
'.text= "ListView Entry Number"
'.subItems(1).Text= "PC/User Name"
'.subItems(2).Text= "Time Started"
'.subItems(3).Text= "Time Consumed"
'.subItems(4).Text= "IP Address"
'.subItems(5).Text= "Location"
'.subItems(6).Text= "Card Number"
'LogInfo() Array Structure after the split command on DATA variable
'LogInfo(0)="Login"
'LogInfo(1)="Name of User"
'LogInfo(2)="Time Started"
'LogInfo(3)="Location"
'LogInfo(4)="Card Number"
'this variable keeps track of the number of NEW ENTRY messages being received from the server
Static NewMessageCount As Integer
Try
Dim SIP As String = Args.senderIP
Dim DATA As String = Args.message
Dim loginfo() As String = DATA.Split(".")
Dim itemFound As ListViewItem = clientView.FindItemWithText(SIP)
If (itemFound IsNot Nothing) Then
If DATA.ToLower.Contains("login") Then
With itemFound
.SubItems(1).Text = loginfo(1)
.SubItems(2).Text = loginfo(2)
.SubItems(3).Text = (DateTime.Parse(Now()) - DateTime.Parse(loginfo(2))).ToString
End With
End If
Else
NewMessageCount += 1
Dim NEWMessage As New ListViewItem
With NEWMessage
.Text = NewMessageCount.ToString
.SubItems.Add(loginfo(1))
.SubItems.Add(loginfo(2))
.SubItems.Add((DateTime.Parse(Now()) - DateTime.Parse(loginfo(2))).ToString)
.SubItems.Add(SIP)
.SubItems.Add(loginfo(3))
.SubItems.Add(loginfo(4))
End With
clientView.Items.Add(NEWMessage)
'Enable the timer now that at least one New Message has been received
If Not timeconsume.Enabled Then
With timeconsume
.Interval = 1000
.Enabled = True
End With
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub timeconsume_Tick(sender As System.Object, e As System.EventArgs) Handles timeconsume.Tick
For Each curLVI As ListViewItem In clientView.Items
With curLVI
.SubItems(3).Text = (DateTime.Parse(Now()) - DateTime.Parse(.SubItems(2).Text)).ToString
End With
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
NewServerMessage.senderIP = "192.168.0.1"
NewServerMessage.message = "Login.The_Kid.21/09/12 05:34:25.Baltimore.12345678910"
Call OnIncomingMessage(NewServerMessage)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
NewServerMessage.senderIP = "192.168.1.23"
NewServerMessage.message = "Login.IanPC.21/09/12 06:18:00.Healing.12345678910222"
Call OnIncomingMessage(NewServerMessage)
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
NewServerMessage.senderIP = "192.168.12.189"
NewServerMessage.message = "Login.Billy.21/09/12 06:19:00.Atlanta.99999999999999"
Call OnIncomingMessage(NewServerMessage)
End Sub
Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
NewServerMessage.senderIP = "192.168.12.189"
NewServerMessage.message = "Login.Jimmy.21/09/12 06:20:00.Atlanta.99999999999999"
Call OnIncomingMessage(NewServerMessage)
End Sub
Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
NewServerMessage.senderIP = "192.168.1.23"
NewServerMessage.message = "Login.JohnPC.21/09/12 06:21:30.Healing.12345678910222"
Call OnIncomingMessage(NewServerMessage)
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
NewServerMessage.senderIP = "192.168.0.1"
NewServerMessage.message = "Login.Helen.21/09/12 06:21:25.Baltimore.12345678910"
Call OnIncomingMessage(NewServerMessage)
End Sub
End Class
Friend Class SampleInCommingMessageFromServer
Public Property senderIP As String
Public Property message As String
End Class