Private Sub CheckForNewMessages()
Try
'If the database connection is not open
If DBConn.State <> ConnectionState.Open Then
'Connect to the database
DBConn.Open()
End If
'Change the system tray icon to show that the client is checking for messages
niSysTrayIcon.Icon = My.Resources.Receiving
Dim i As Integer
Dim DisplayFlag As Boolean = True
For i = 0 To SQLQueries.Count - 1
'Run an SQL command
DBCmd = New OleDbCommand(SQLQueries.Item(i), DBConn)
DBReader = DBCmd.ExecuteReader
While DBReader.Read()
Dim j As Integer
DisplayFlag = True
For j = 0 To myStructs.ReceivedMessages.Count - 1
If DBReader("tblMessages.ID") = myStructs.ReceivedMessages.Item(j).ID Then
Dim tempDate1 As DateTime = DBReader("TimeSent")
Dim tempDate2 As DateTime = myStructs.ReceivedMessages.Item(j).DateTime
If tempDate1.Date = tempDate2.Date Then
If tempDate1.TimeOfDay = tempDate2.TimeOfDay Then
DisplayFlag = False
End If
End If
End If
Next
'If the message hasnt been received yet, display it, otherwise dont
If DisplayFlag = True Then
DisplayMessage(DBReader("FilterType"), DBReader("Filter"), DBReader("Forename") & " " & DBReader("Surname") & " (" & DBReader("Description") & ")", DBReader("TimeSent"), DBReader("Message"), DBReader("MsgBoxType"))
myStructs.AddNewMessage(DBReader("tblMessages.ID"), DBReader("TimeSent"))
End If
End While
Next
If DBConn.State <> ConnectionState.Closed Then
DBConn.Close()
End If
'Change the system tray icon to show that the client is has finished checking for messages
niSysTrayIcon.Icon = My.Resources.Online
'Start the next check timer
tmrNextCheck.Start()
Catch ex As Exception
'MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.ApplicationModal)
modErrorLogging.LogError(ex.Message, Me.Name, "CheckForNewMessages")
If DBConn.State <> ConnectionState.Closed Then
DBConn.Close()
End If
'Start the next check timer
tmrNextCheck.Start()
End Try
End Sub
|