更新两种客户端的在线显示模型,v1.6.8

This commit is contained in:
dathlin
2017-10-09 22:18:51 +08:00
parent 8252e4d356
commit 1c4181363e
23 changed files with 966 additions and 40 deletions

View File

@@ -0,0 +1,77 @@
namespace ClientsLibrary.BasicSupport
{
partial class NetClientItem
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(4, 1);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(34, 34);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(45, 4);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// NetClientItem
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "NetClientItem";
this.Size = new System.Drawing.Size(185, 36);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.NetClientItem_Paint);
this.MouseEnter += new System.EventHandler(this.NetClientItem_MouseEnter);
this.MouseLeave += new System.EventHandler(this.NetClientItem_MouseLeave);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
}
}

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonLibrary;
using System.Threading;
namespace ClientsLibrary.BasicSupport
{
public partial class NetClientItem : UserControl
{
public NetClientItem()
{
InitializeComponent();
}
private void NetClientItem_Paint(object sender, PaintEventArgs e)
{
if (m_NetAccount != null)
{
// 绘制角色名称
if (m_NetAccount.Roles?.Length > 0)
{
int m_x = 45;
int m_y = 20;
for (int i = 0; i < m_NetAccount.Roles.Length; i++)
{
SizeF m_size = e.Graphics.MeasureString(m_NetAccount.Roles[i], Font);
e.Graphics.FillRectangle(Brushes.LightBlue, m_x, m_y - 2, m_size.Width, m_size.Height);
e.Graphics.DrawString(m_NetAccount.Roles[i], Font, Brushes.Blue, new Point(m_x, m_y));
m_x += (int)m_size.Width + 3;
}
}
}
}
public void SetNetAccount(NetAccount account)
{
m_NetAccount = account;
// 加载头像,显示信息
label1.Text = (string.IsNullOrEmpty(account.Alias) ? account.UserName : account.Alias) + $" ({account.Factory})";
ThreadPool.QueueUserWorkItem(ThreadPoolLoadPortrait, null);
}
private void ThreadPoolLoadPortrait(object obj)
{
// 向服务器请求小头像
if(m_NetAccount!=null)
{
try
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
HslCommunication.OperateResult result = UserClient.Net_File_Client.DownloadFile(
PortraitSupport.SmallPortrait,
"Files",
"Portrait",
m_NetAccount.UserName,
null,
ms
);
if (result.IsSuccess)
{
Bitmap bitmap = new Bitmap(ms);
pictureBox1.Image = bitmap;
}
else
{
MessageBox.Show(result.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private NetAccount m_NetAccount;
private void NetClientItem_MouseEnter(object sender, EventArgs e)
{
BackColor = Color.AliceBlue;
}
private void NetClientItem_MouseLeave(object sender, EventArgs e)
{
BackColor = SystemColors.Control;
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,81 @@
namespace ClientsLibrary.BasicSupport
{
partial class NetClientOnline
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(3, 4);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(92, 17);
this.label1.TabIndex = 0;
this.label1.Text = "在线客户端数:";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(101, 4);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(113, 18);
this.label2.TabIndex = 1;
this.label2.Text = "0";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// NetClientOnline
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "NetClientOnline";
this.Size = new System.Drawing.Size(217, 465);
this.Load += new System.EventHandler(this.NetClientOnline_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.NetClientOnline_Paint);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonLibrary;
namespace ClientsLibrary.BasicSupport
{
public partial class NetClientOnline : UserControl
{
public NetClientOnline()
{
InitializeComponent();
}
private void NetClientOnline_Load(object sender, EventArgs e)
{
}
private void ClearControls()
{
while (MyControls.Count > 0)
{
MyControls.Pop().Dispose();
}
}
public void SetOnlineRender(NetAccount[] accounts)
{
SuspendLayout();
//清楚缓存
ClearControls();
if (accounts != null)
{
label2.Text = accounts.Length.ToString();
if (accounts.Length > 0 && Width > 20)
{
int location_y = 25 - VerticalScroll.Value;
//添加子控件
foreach (var m in accounts)
{
NetClientItem item = new NetClientItem();
Controls.Add(item);
// 添加显示
item.SetNetAccount(m);
item.Location = new Point(2, location_y); // 控件的位置
int width = VerticalScroll.Visible ? Width - 4 - SystemInformation.VerticalScrollBarWidth : Width - 4; // 控件的宽度
item.Size = new Size(width, item.Size.Height); // 控件的大小
item.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; // 控件随窗口变化的样式
location_y += item.Height + 4; // 位置偏移
MyControls.Push(item); // 控件压入堆栈
}
}
}
ResumeLayout();
}
private Stack<IDisposable> MyControls = new Stack<IDisposable>();
private void NetClientOnline_Paint(object sender, PaintEventArgs e)
{
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -86,6 +86,18 @@
<Compile Include="BasicSupport\FormShowMachineId.Designer.cs">
<DependentUpon>FormShowMachineId.cs</DependentUpon>
</Compile>
<Compile Include="BasicSupport\NetClientItem.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BasicSupport\NetClientItem.Designer.cs">
<DependentUpon>NetClientItem.cs</DependentUpon>
</Compile>
<Compile Include="BasicSupport\NetClientOnline.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="BasicSupport\NetClientOnline.Designer.cs">
<DependentUpon>NetClientOnline.cs</DependentUpon>
</Compile>
<Compile Include="Configuration\ClientConfiguration.cs">
<SubType>UserControl</SubType>
</Compile>
@@ -187,6 +199,12 @@
<EmbeddedResource Include="BasicSupport\FormShowMachineId.resx">
<DependentUpon>FormShowMachineId.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BasicSupport\NetClientItem.resx">
<DependentUpon>NetClientItem.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BasicSupport\NetClientOnline.resx">
<DependentUpon>NetClientOnline.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Configuration\ClientConfiguration.resx">
<DependentUpon>ClientConfiguration.cs</DependentUpon>
</EmbeddedResource>

View File

@@ -43,7 +43,7 @@ namespace ClientsLibrary
/// 服务器的IP地址默认为127.0.0.1,可用于单机调试,
/// 云服务器端117.48.203.204,注意,云端为最新版,客户端版本比较旧会调试失败
/// </summary>
public static string ServerIp { get; } = "117.48.203.204";//用于测试的云服务器地址
public static string ServerIp { get; } = "117.48.203.204"; // 用于测试的云服务器地址
/// <summary>
@@ -63,7 +63,7 @@ namespace ClientsLibrary
new VersionInfo()
{
VersionNum = new SystemVersion("1.0.0"),
ReleaseDate = new DateTime(2017, 10, 1),//该版本发布的日期
ReleaseDate = new DateTime(2017, 10, 1), // 该版本发布的日期
UpdateDetails = new StringBuilder(
"1.本系统第一版本正式发布使用。"+Environment.NewLine+
"2.提供了多客户端用时在线的功能。"+Environment.NewLine+

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CommonLibrary
{
/// <summary>
/// 用于网络账户的在线情况监视
/// </summary>
public class NetAccount
{
/// <summary>
/// 唯一的用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 别名
/// </summary>
public string Alias { get; set; }
/// <summary>
/// ip地址
/// </summary>
public string IpAddress { get; set; }
/// <summary>
/// 工厂或是部分分类
/// </summary>
public string Factory { get; set; }
/// <summary>
/// 登陆时间
/// </summary>
public DateTime LoginTime { get; set; }
/// <summary>
/// 包含的角色名称
/// </summary>
public string[] Roles { get; set; }
}
}

View File

@@ -59,10 +59,16 @@ namespace CommonLibrary
}
#endregion
#region Public Method
public bool IsAllowAccountOperate(string roleCode,string name)
/// <summary>
/// 检测一个账户名是否有当前角色的权限
/// </summary>
/// <param name="roleCode">角色代号</param>
/// <param name="name">用户名</param>
/// <returns></returns>
public bool IsAllowAccountOperate(string roleCode, string name)
{
bool result = false;
hybirdLock.Enter();
@@ -85,6 +91,30 @@ namespace CommonLibrary
return result;
}
/// <summary>
/// 获取一个用户名的所有角色名称
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string[] GetRolesByUserName(string name)
{
List<string> list = new List<string>();
hybirdLock.Enter();
for (int i = 0; i < m_roles.Count; i++)
{
if (m_roles[i].Accounts.Contains(name))
{
list.Add(m_roles[i].RoleName);
}
}
hybirdLock.Leave();
return list.ToArray();
}
#endregion

View File

@@ -227,6 +227,7 @@ namespace CommonLibrary
return JObject.FromObject(result).ToString();
}
/// <summary>
/// 获取所有的账户的JSON字符串
/// </summary>
@@ -240,6 +241,50 @@ namespace CommonLibrary
return result;
}
/// <summary>
/// 获取账户的别名
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string GetAccountAlias(string name)
{
string result = string.Empty;
hybirdLock.Enter();
for (int i = 0; i < all_list_accounts.Count; i++)
{
if (name == all_list_accounts[i].UserName)
{
result = all_list_accounts[i].NameAlias;
}
}
hybirdLock.Leave();
return result;
}
/// <summary>
/// 获取账户的部门
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string GetAccountFactory(string name)
{
string result = string.Empty;
hybirdLock.Enter();
for (int i = 0; i < all_list_accounts.Count; i++)
{
if (name == all_list_accounts[i].UserName)
{
result = all_list_accounts[i].Factory;
}
}
hybirdLock.Leave();
return result;
}
/// <summary>
/// 获取所有的账户的用户名的JSON字符串
/// </summary>

View File

@@ -66,6 +66,7 @@
<Compile Include="AccountSupport\FormPasswordModify.designer.cs">
<DependentUpon>FormPasswordModify.cs</DependentUpon>
</Compile>
<Compile Include="AccountSupport\NetAccount.cs" />
<Compile Include="AccountSupport\RoleAssign.cs" />
<Compile Include="AccountSupport\ServerAccount.cs" />
<Compile Include="AccountSupport\UserAccount.cs" />

View File

@@ -45,7 +45,7 @@ namespace CommonLibrary
*
**************************************************************************/
SoftBasic.FrameworkVersion = new SystemVersion("1.6.7");
SoftBasic.FrameworkVersion = new SystemVersion("1.6.8");
}

Binary file not shown.

View File

@@ -277,7 +277,9 @@
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}">0</TextBlock>
</Border>
<TextBlock Grid.Row="1" Grid.Column="0">在线信息:</TextBlock>
<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="ListBox_Onlines" FontSize="10.5"></ListBox>
<!--<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="ListBox_Onlines" FontSize="10.5"></ListBox>-->
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Name="ClientsOnline" Orientation="Vertical"
Margin="0,4,0,0"></StackPanel>
</Grid>
</GroupBox>
</Grid>

View File

@@ -23,6 +23,7 @@ using System.Threading;
using Wpf.Views;
using System.Windows.Media.Animation;
using MaterialDesignThemes.Wpf;
using CommonLibrary;
namespace Wpf
{
@@ -441,7 +442,18 @@ namespace 软件系统客户端Wpf
{
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
{
ListBox_Onlines.ItemsSource = data.Split('#');
// ListBox_Onlines.ItemsSource = data.Split('#');
ClientsOnline.Children.Clear();
NetAccount[] accounts = JArray.Parse(data).ToObject<NetAccount[]>();
foreach(var m in accounts)
{
Views.Controls.UserClientRenderItem userClient = new Views.Controls.UserClientRenderItem();
userClient.SetClientRender(m);
ClientsOnline.Children.Add(userClient);
}
}));
}
else if (customer == CommonHeadCode.MultiNetHeadCode.)

View File

@@ -0,0 +1,33 @@
<UserControl x:Class="软件系统客户端Wpf.Views.Controls.UserClientRenderItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" HorizontalAlignment="Stretch"
d:DesignHeight="50" d:DesignWidth="300" Margin="0,3,0,0">
<Grid HorizontalAlignment="Stretch">
<materialDesign:Chip HorizontalAlignment="Stretch">
<materialDesign:Chip.Icon>
<Image Name="Image1" />
</materialDesign:Chip.Icon>
<materialDesign:Chip.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<TextBlock Margin="2,0,6,0" Name="UserName">admin</TextBlock>
<TextBlock Name="Factory">(总公司)</TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Name="Roles" Margin="2,0,0,0">
<TextBlock Background="LightBlue" Foreground="Blue">计划员</TextBlock>
</StackPanel>
</Grid>
</materialDesign:Chip.Content>
</materialDesign:Chip>
</Grid>
</UserControl>

View File

@@ -0,0 +1,107 @@
using ClientsLibrary;
using CommonLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Wpf.Views.Controls
{
/// <summary>
/// UserClientRenderItem.xaml 的交互逻辑
/// </summary>
public partial class UserClientRenderItem : UserControl
{
public UserClientRenderItem()
{
InitializeComponent();
}
public void SetClientRender(NetAccount account)
{
if (account != null)
{
UserName.Text = string.IsNullOrEmpty(account.Alias) ? account.UserName : account.Alias;
Factory.Text = $"({account.Factory})";
Roles.Children.Clear();
if(account.Roles?.Length>0)
{
foreach(var m in account.Roles)
{
TextBlock block = new TextBlock();
block.Background = Brushes.LightSkyBlue;
block.Foreground = Brushes.Blue;
block.Margin = new Thickness(0, 0, 4, 0);
block.Text = m;
Roles.Children.Add(block);
}
}
else
{
Roles.Children.Add(new TextBlock());
}
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ThreadPoolLoadPortrait), account);
}
}
private void ThreadPoolLoadPortrait(object obj)
{
// 向服务器请求小头像
if (obj is NetAccount m_NetAccount)
{
try
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
HslCommunication.OperateResult result = UserClient.Net_File_Client.DownloadFile(
PortraitSupport.SmallPortrait,
"Files",
"Portrait",
m_NetAccount.UserName,
null,
ms
);
if (result.IsSuccess)
{
Dispatcher.Invoke(new Action(() =>
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
Image1.Source = bi;
}));
}
else
{
MessageBox.Show(result.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}

View File

@@ -75,6 +75,9 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Views\AnotherCommandImplementation.cs" />
<Compile Include="Views\Controls\UserClientRenderItem.xaml.cs">
<DependentUpon>UserClientRenderItem.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Palette.xaml.cs">
<DependentUpon>Palette.xaml</DependentUpon>
</Compile>
@@ -113,6 +116,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\Controls\UserClientRenderItem.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Palette.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@@ -61,8 +61,6 @@
this.linkLabel_logout = new System.Windows.Forms.LinkLabel();
this.label_factory = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label_address = new System.Windows.Forms.Label();
this.label_last = new System.Windows.Forms.Label();
this.label_times = new System.Windows.Forms.Label();
@@ -80,6 +78,7 @@
this.label10 = new System.Windows.Forms.Label();
this.panel_main = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.netClientOnline1 = new ClientsLibrary.BasicSupport.NetClientOnline();
this.statusStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.panel_right.SuspendLayout();
@@ -309,13 +308,12 @@
// panel_right
//
this.panel_right.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel_right.Controls.Add(this.netClientOnline1);
this.panel_right.Controls.Add(this.label_file_count);
this.panel_right.Controls.Add(this.label8);
this.panel_right.Controls.Add(this.linkLabel_logout);
this.panel_right.Controls.Add(this.label_factory);
this.panel_right.Controls.Add(this.label9);
this.panel_right.Controls.Add(this.label7);
this.panel_right.Controls.Add(this.listBox1);
this.panel_right.Controls.Add(this.label_address);
this.panel_right.Controls.Add(this.label_last);
this.panel_right.Controls.Add(this.label_times);
@@ -341,7 +339,7 @@
this.label_file_count.Cursor = System.Windows.Forms.Cursors.Hand;
this.label_file_count.Location = new System.Drawing.Point(82, 143);
this.label_file_count.Name = "label_file_count";
this.label_file_count.Size = new System.Drawing.Size(129, 17);
this.label_file_count.Size = new System.Drawing.Size(137, 17);
this.label_file_count.TabIndex = 18;
this.label_file_count.Text = "0";
this.label_file_count.TextAlign = System.Drawing.ContentAlignment.TopRight;
@@ -385,29 +383,6 @@
this.label9.TabIndex = 14;
this.label9.Text = "所属分厂:";
//
// label7
//
this.label7.AutoSize = true;
this.label7.ForeColor = System.Drawing.Color.DimGray;
this.label7.Location = new System.Drawing.Point(8, 163);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(104, 17);
this.label7.TabIndex = 13;
this.label7.Text = "所有在线客户端:";
//
// listBox1
//
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 17;
this.listBox1.Location = new System.Drawing.Point(11, 183);
this.listBox1.Name = "listBox1";
this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.None;
this.listBox1.Size = new System.Drawing.Size(200, 242);
this.listBox1.TabIndex = 12;
//
// label_address
//
this.label_address.AutoSize = true;
@@ -566,6 +541,19 @@
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// netClientOnline1
//
this.netClientOnline1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.netClientOnline1.AutoScroll = true;
this.netClientOnline1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.netClientOnline1.Location = new System.Drawing.Point(5, 164);
this.netClientOnline1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.netClientOnline1.Name = "netClientOnline1";
this.netClientOnline1.Size = new System.Drawing.Size(214, 250);
this.netClientOnline1.TabIndex = 19;
//
// FormMainWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -621,8 +609,6 @@
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private System.Windows.Forms.Panel panel_right;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label_address;
private System.Windows.Forms.Label label_last;
private System.Windows.Forms.Label label_times;
@@ -653,6 +639,7 @@
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private ClientsLibrary.BasicSupport.NetClientOnline netClientOnline1;
}
}

View File

@@ -389,7 +389,11 @@ namespace 软件系统客户端模版
{
if (IsHandleCreated) Invoke(new Action(() =>
{
listBox1.DataSource = data.Split('#');
// listBox1.DataSource = data.Split('#');
NetAccount[] accounts = JArray.Parse(data).ToObject<NetAccount[]>();
netClientOnline1.SetOnlineRender(accounts);
}));
}
else if (customer == CommonHeadCode.MultiNetHeadCode.)

View File

@@ -12,6 +12,7 @@ using HslCommunication;
using CommonLibrary;
using ClientsLibrary;
using ClientsLibrary.FileSupport;
using System.Runtime.InteropServices;
namespace .UIControls
{
@@ -95,6 +96,12 @@ namespace 软件系统客户端模版.UIControls
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
}
private void SetFilesShow(List<GroupFileItem> files)
{
panel2.SuspendLayout();
@@ -128,6 +135,7 @@ namespace 软件系统客户端模版.UIControls
}
panel2.ResumeLayout();
}

View File

@@ -383,7 +383,7 @@ namespace 软件系统服务端模版
{
net_simplify_server.KeyToken = CommonProtocol.KeyToken;//设置身份令牌
net_simplify_server.LogNet = new LogNetSingle(LogSavePath + @"\simplify_log.txt");//日志路径
net_simplify_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储根据需要自行选择
net_simplify_server.LogNet.SetMessageDegree(HslMessageDegree.INFO);//默认debug及以上级别日志均进行存储根据需要自行选择
net_simplify_server.ReceiveStringEvent += Net_simplify_server_ReceiveStringEvent;//接收到字符串触发
net_simplify_server.ReceivedBytesEvent += Net_simplify_server_ReceivedBytesEvent;//接收到字节触发
net_simplify_server.ServerStart(CommonProtocol.Port_Second_Net);
@@ -971,11 +971,15 @@ namespace 软件系统服务端模版
private void Net_socket_server_ClientOffline(AsyncStateOne object1, string object2)
{
RemoveOnlineClient(object1.LoginAlias);
UserInterfaceMessageRender(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1._IpEnd_Point.Address.ToString() + "" + object1.LoginAlias + " " + object2);
}
private void Net_socket_server_ClientOnline(AsyncStateOne object1)
{
AddOnlineClient(object1.LoginAlias, object1._IpEnd_Point.Address.ToString());
// 上线后回发一条数据初始化信息
JObject json = new JObject
{
@@ -989,12 +993,67 @@ namespace 软件系统服务端模版
UserInterfaceMessageRender(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1._IpEnd_Point.Address.ToString() + "" + object1.LoginAlias + " 上线");
}
private List<NetAccount> OnlineClients = new List<NetAccount>();
private SimpleHybirdLock hybirdLock = new SimpleHybirdLock();
private void AddOnlineClient(string userName,string ip)
{
NetAccount account = new NetAccount();
account.UserName = userName;
account.Roles = UserServer.ServerRoles.GetRolesByUserName(userName);
account.IpAddress = ip;
account.Alias = UserServer.ServerAccounts.GetAccountAlias(userName);
account.Factory = UserServer.ServerAccounts.GetAccountFactory(userName);
account.LoginTime = DateTime.Now;
hybirdLock.Enter();
OnlineClients.Add(account);
hybirdLock.Leave();
}
private void RemoveOnlineClient(string userName)
{
hybirdLock.Enter();
int index = -1;
for (int i = 0; i < OnlineClients.Count; i++)
{
if (OnlineClients[i].UserName == userName)
{
index = i;
break;
}
}
if (index >= 0)
{
OnlineClients.RemoveAt(index);
}
hybirdLock.Leave();
}
private string GetOnlineClientsJson()
{
string result = string.Empty;
hybirdLock.Enter();
result = JArray.FromObject(OnlineClients).ToString();
hybirdLock.Leave();
return result;
}
private void Net_socket_server_AllClientsStatusChange(string data)
{
// 此处决定要不要将在线客户端的数据发送所有客户端
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.线, data);
// net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.总在线信息, data);
Net_Socket_All_Clients = data;
if (IsWindowShow && IsHandleCreated)
{
@@ -1004,6 +1063,8 @@ namespace 软件系统服务端模版
label4.Text = net_socket_server.ClientCount.ToString();
}));
}
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.线, GetOnlineClientsJson());
}
/// <summary>