2016-03-01 79 views
0

我正在爲我的工作制作一個聊天系統,並且無法找到顯示用戶及其狀態的方法。聊天聯繫人列表VB.NET和MSSQL

所以我有一個所謂的聊天客戶端窗體

在那裏,我已經Panel1(Left)Panel2(Right)

Panel1我必須讓每一個用戶在我的數據庫中列出

Select [first_name] + ' ' + [Name] As 'Contact', [Status] From dbo.TableUsers 

這給了以下內容:

[green image] [contact name] (if someone is logged in (status online)) 
[Orange image] [contact name] (If someone is logged in (status away)) 
[Red image] [contact name] (If someone is not logged in (Status offline)) 

如何創建一個下標,使表名中顯示其狀態的所有用戶在表中列出圖像?

+0

我會研究服務代理。您可以在應用程序中創建依賴項。隨時更改表格,例如刷新您的數據...在此處查找更多信息https://www.google.com/search?site=&source=hp&ei=KZnVVt2qDOOnjgS3sbjgAQ&q=service+broker+example&oq=service+broker+e&gs_l=mobile-gws -hp.1.1.0l5.1590.8026.0.10646.19.18.0.8.8.0.939.4446.0j6j5j3j1j0j1.16.0 .... 0 ... 1c.1j4.64.mobile-GWS-hp..2.17.2950.3.1mMoFrCMNVo#q構成= service + broker + vb.net + example – Codexer

+0

??這不是我的問題的答案。 我需要一些可以用statusimage和名稱創建列表的東西。 (Green.img)斯密約瑟 (Orande.img)凱蒂·約翰遜 (red.img)鮑勃·紐蘭 (red.img)埃德溫·庫珀 等等...我有有2列的表。第一個是[Name]和第二個[Status](它返回Online,Away或Offline) –

+0

'VB.NET中的這個下標將每分鐘運行一次,以刷新我怎麼做這個'聽起來像你需要幫助如何獲得它我...其他信息是你已經有的。也許你需要解釋更多***你沒有的東西***你也是對的這不是一個答案,因此它是一個評論。你的問題不夠清楚,無法幫助你。您可以創建一個用戶控件,該控件將爲圖像的名稱和圖片框設置標籤。創建這個新的控制永遠用戶從您的查詢回來,並顯示他們在一個flowlayoutnelnel ... – Codexer

回答

0

,我發現自己的答案:)

我用的電子TableLayoutPanel中的2列,我這個裝滿起來:

While UserData.Read 
      If UserData("Status").ToString = "Online" Then 
       Dim newPictureBox As New PictureBox 
       newPictureBox.Image = My.Resources.greenchat 
       newPictureBox.Visible = True 
       newPictureBox.Width = 30 
       newPictureBox.Height = 30 
       newPictureBox.SizeMode = PictureBoxSizeMode.Zoom 
       newPictureBox.Name = UserData("Username").ToString & "Pic" 
       ChatContactList.Controls.Add(newPictureBox) 

       Dim newLabel As New Label 
       newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString 
       newLabel.Name = UserData("Username").ToString & "Lab" 
       newLabel.Font = New Font("Microsoft sans serif", 12) 
       newLabel.Height = 30 
       newLabel.AutoSize = True 
       newLabel.TextAlign = ContentAlignment.MiddleLeft 
       newLabel.Visible = True 
       ChatContactList.Controls.Add(newLabel) 

      ElseIf UserData("Status").ToString = "Afwezig" Then 
       Dim newPictureBox As New PictureBox 
       newPictureBox.Image = My.Resources.orangechat 
       newPictureBox.Visible = True 
       newPictureBox.Width = 30 
       newPictureBox.Height = 30 
       newPictureBox.SizeMode = PictureBoxSizeMode.Zoom 
       newPictureBox.Name = UserData("Username").ToString & "Pic" 
       ChatContactList.Controls.Add(newPictureBox) 

       Dim newLabel As New Label 
       newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString 
       newLabel.Name = UserData("Username").ToString & "Lab" 
       newLabel.Font = New Font("Microsoft sans serif", 12) 
       newLabel.Height = 30 
       newLabel.AutoSize = True 
       newLabel.TextAlign = ContentAlignment.MiddleLeft 
       newLabel.Visible = True 
       ChatContactList.Controls.Add(newLabel) 

      ElseIf UserData("Status").ToString = "Offline" Then 
       Dim newPictureBox As New PictureBox 
       newPictureBox.Image = My.Resources.ResourceManager.GetObject("redchat") 
       newPictureBox.Visible = True 
       newPictureBox.Width = 30 
       newPictureBox.Height = 30 
       newPictureBox.SizeMode = PictureBoxSizeMode.Zoom 
       newPictureBox.Name = UserData("Username").ToString & "Pic" 
       ChatContactList.Controls.Add(newPictureBox) 

       Dim newLabel As New Label 
       newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString 
       newLabel.Name = UserData("Username").ToString & "Lab" 
       newLabel.Font = New Font("Microsoft sans serif", 12) 
       newLabel.Height = 30 
       newLabel.AutoSize = True 
       newLabel.TextAlign = ContentAlignment.MiddleLeft 
       newLabel.Visible = True 
       ChatContactList.Controls.Add(newLabel) 

      End If 
     End While 
-1

我看到你的決議,我錯誤地理解。反正它很好,你會得到這個任務的解決方案。

+0

我新與vb.net所以我有這個問題:爲什麼與(nolock)?我和web/WCF有什麼關係? –

+1

這是一個推薦,而不是OP問題的解決方案。 – Codexer

+0

在狀態「varbinary」(在MS SQL中)和下面的鏈接中添加字段可能有助於更多 http://stackoverflow.com/questions/16842065/how-to-save-and-retrive-picturebox-image-to -SQL-服務器數據庫varbinarymax-C –