MS: Chat und co
This commit is contained in:
@@ -4,7 +4,7 @@ Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class ChatControl
|
||||
Private ReadOnly IdColumn As String = "GUID"
|
||||
Private ReadOnly UsernameColumn As String = "USER_FROM"
|
||||
Private ReadOnly IdentificationColumn As String = "USER_FROM"
|
||||
Private ReadOnly MessageColumn As String = "MESSAGE_TEXT"
|
||||
Private ReadOnly DateColumn As String = "ADDED_WHEN"
|
||||
|
||||
@@ -21,45 +21,76 @@ Public Class ChatControl
|
||||
}
|
||||
|
||||
Public IDBObjectId As Long
|
||||
Public ConnectionString As String
|
||||
Public CurrentUser As String
|
||||
Public ConnStringIDB As String
|
||||
Public ConversationIdentification As String
|
||||
Public Username As String
|
||||
Public CurrentConversation As Long
|
||||
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
End Sub
|
||||
|
||||
Public Sub Init(LogConfig As LogConfig, ConnectionString As String, CurrentUser As String)
|
||||
Public Sub Init(LogConfig As LogConfig, ConnectionStringIDB As String, ConversationIdentification As String, Username As String)
|
||||
Me.LogConfig = LogConfig
|
||||
Me.Logger = LogConfig.GetLogger()
|
||||
Me.ConnectionString = ConnectionString
|
||||
Me.CurrentUser = CurrentUser
|
||||
Me.Db = New MSSQLServer(LogConfig, ConnectionString)
|
||||
Me.ConnStringIDB = ConnectionStringIDB
|
||||
Me.ConversationIdentification = ConversationIdentification
|
||||
Me.Username = Username
|
||||
|
||||
Me.Db = New MSSQLServer(LogConfig, ConnStringIDB)
|
||||
End Sub
|
||||
|
||||
Public Sub LoadConversations(IDBObjectId As Long)
|
||||
Dim oSQL As String = $"SELECT * FROM VWIDB_CONVERSATION WHERE IDB_OBJ_ID = {IDBObjectId}"
|
||||
Public Function GetConversations(IDBObjectId As Long)
|
||||
Dim oSQL As String = $"SELECT * FROM VWIDB_CONVERSATION WHERE IDB_OBJ_ID = {IDBObjectId} ORDER BY CONVERSATION_ID DESC"
|
||||
Dim oDatatable As DataTable = Db.GetDatatable(oSQL)
|
||||
Dim oConversations As New List(Of String)
|
||||
If Not IsNothing(oDatatable) Then
|
||||
If oDatatable.Rows.Count = 1 Then
|
||||
Dim oItem = oDatatable.Rows(0).Item("CONVERSATION_ID").ToString + "|" + oDatatable.Rows(0).Item("TITLE").ToString
|
||||
oConversations.Insert(0, oItem)
|
||||
CurrentConversation = oDatatable.Rows(0).Item("CONVERSATION_ID")
|
||||
LoadConversation(CurrentConversation)
|
||||
Else
|
||||
For Each oROW As DataRow In oDatatable.Rows
|
||||
Dim oItem = oROW.Item("CONVERSATION_ID").ToString + "|" + oROW.Item("TITLE").ToString
|
||||
oConversations.Insert(0, oItem)
|
||||
If oROW.Item("CONVERSATION_STATE") = "Started" Then
|
||||
CurrentConversation = oROW.Item("CONVERSATION_ID")
|
||||
LoadConversation(CurrentConversation)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
Return oConversations
|
||||
End Function
|
||||
|
||||
lookupConversations.DataSource = oDatatable
|
||||
Private Sub tsCBConversations_SelectedIndexChanged(sender As Object, e As EventArgs)
|
||||
'If tsCBConversations.SelectedIndex <> -1 Then
|
||||
' Dim oValues As List(Of String) = tsCBConversations.Text.Split("|").ToList()
|
||||
' CurrentConversation = oValues(0)
|
||||
' LoadConversation(CurrentConversation)
|
||||
|
||||
'End If
|
||||
End Sub
|
||||
|
||||
Public Sub LoadConversation(ConversationId As Long)
|
||||
Dim oSQL As String = $"SELECT * FROM VWIDB_CONV_MESSAGES WHERE CONV_ID = {ConversationId} ORDER BY GUID"
|
||||
Dim oDatatable As DataTable = Db.GetDatatable(oSQL)
|
||||
|
||||
BuildUsernameColorDict(oDatatable)
|
||||
|
||||
oSQL = $"SELECT * FROM VWIDB_CONVERSATION WHERE CONVERSATION_ID = {ConversationId}"
|
||||
Dim oDatatable2 As DataTable = Db.GetDatatable(oSQL)
|
||||
GridChat.DataSource = ChatSource
|
||||
ChatSource.DataSource = oDatatable
|
||||
lblTitle.Text = oDatatable2.Rows(0).Item("TITLE")
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub SendMessage(MessageText As String)
|
||||
Public Sub NewMessage(MessageText As String)
|
||||
Try
|
||||
Dim oSQL As String = $"EXEC [PRIDB_NEW_CONVERSATION_MESSAGE] {CurrentConversation},'{MessageText}', '{CurrentUser}'"
|
||||
Dim oSQL As String = $"EXEC [PRIDB_NEW_CONVERSATION_MESSAGE] {CurrentConversation},'{MessageText}', '{ConversationIdentification}'"
|
||||
Dim oResult = Db.GetScalarValue(oSQL)
|
||||
LoadConversation(CurrentConversation)
|
||||
txtMessage.Text = String.Empty
|
||||
ChatView.MoveLast()
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
@@ -71,7 +102,7 @@ Public Class ChatControl
|
||||
UsernameColorsDict.Clear()
|
||||
|
||||
Datatable.AsEnumerable().
|
||||
Select(Function(Row) Row.Item(UsernameColumn)).
|
||||
Select(Function(Row) Row.Item(IdentificationColumn)).
|
||||
Distinct().ToList().
|
||||
ForEach(Sub(Name)
|
||||
UsernameColorsDict.Add(Name, UsernameColors.Item(oIndex))
|
||||
@@ -81,9 +112,9 @@ Public Class ChatControl
|
||||
|
||||
Private Sub ChatView_CustomItemTemplate(sender As Object, e As TileViewCustomItemTemplateEventArgs) Handles ChatView.CustomItemTemplate
|
||||
Dim oRow As DataRow = ChatView.GetDataRow(e.RowHandle)
|
||||
Dim oUsername As String = oRow.Item(UsernameColumn)
|
||||
Dim oUsername As String = oRow.Item(IdentificationColumn)
|
||||
|
||||
If oUsername = CurrentUser Then
|
||||
If oUsername = ConversationIdentification Or oUsername = Username Then
|
||||
e.Template = e.Templates.Item("ChatRight")
|
||||
Else
|
||||
e.Template = e.Templates.Item("ChatLeft")
|
||||
@@ -93,33 +124,40 @@ Public Class ChatControl
|
||||
Private Sub ChatView_ItemCustomize(sender As Object, e As TileViewItemCustomizeEventArgs) Handles ChatView.ItemCustomize
|
||||
Dim oRow As DataRow = ChatView.GetDataRow(e.RowHandle)
|
||||
|
||||
Dim oUsername As String = oRow.Item(UsernameColumn)
|
||||
Dim oUsername As String = oRow.Item(IdentificationColumn)
|
||||
Dim oMessage As String = oRow.Item(MessageColumn)
|
||||
Dim oColor As Color = UsernameColorsDict.Item(oUsername)
|
||||
|
||||
If oUsername = CurrentUser Then
|
||||
If oUsername = ConversationIdentification Or oUsername = Username Then
|
||||
e.Item.AppearanceItem.Normal.BackColor = Color.PaleTurquoise
|
||||
End If
|
||||
e.Item.AppearanceItem.Focused.BackColor = Color.Turquoise
|
||||
e.Item.Item(UsernameColumn).Appearance.Normal.ForeColor = oColor
|
||||
e.Item.Item(IdentificationColumn).Appearance.Normal.ForeColor = oColor
|
||||
End Sub
|
||||
|
||||
Private Sub lookupConversations_SelectedValuesChanged(sender As Object, SelectedValues As List(Of String)) Handles lookupConversations.SelectedValuesChanged
|
||||
If SelectedValues.Count > 0 Then
|
||||
CurrentConversation = SelectedValues.First()
|
||||
LoadConversation(CurrentConversation)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub txtMessage_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMessage.KeyUp
|
||||
If e.Control And e.KeyCode = Keys.Enter And txtMessage.Text.Count > 0 Then
|
||||
SendMessage(txtMessage.Text)
|
||||
End If
|
||||
|
||||
Private Sub txtMessage_KeyUp(sender As Object, e As KeyEventArgs)
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles btnSendMessage.Click
|
||||
If txtMessage.Text.Count > 0 Then
|
||||
SendMessage(txtMessage.Text)
|
||||
NewMessage(txtMessage.Text)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMessage.KeyUp
|
||||
If e.Control And e.KeyCode = Keys.Enter And txtMessage.Text.Count > 0 Then
|
||||
NewMessage(txtMessage.Text)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub ChatControl_Click(sender As Object, e As EventArgs) Handles MyBase.Click
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub ChatControl_Leave(sender As Object, e As EventArgs) Handles Me.Leave
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user