2016-03-01 80 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 –