头像处理提炼类,客户端界面调整
This commit is contained in:
@@ -75,6 +75,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="UserClient.cs" />
|
<Compile Include="UserClient.cs" />
|
||||||
|
<Compile Include="UserPortrait.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="FormDownloading.resx">
|
<EmbeddedResource Include="FormDownloading.resx">
|
||||||
|
|||||||
142
ClientsLibrary/UserPortrait.cs
Normal file
142
ClientsLibrary/UserPortrait.cs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
using CommonLibrary;
|
||||||
|
using HslCommunication;
|
||||||
|
using HslCommunication.BasicFramework;
|
||||||
|
using HslCommunication.Enthernet;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ClientsLibrary
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 头像管理类
|
||||||
|
/// </summary>
|
||||||
|
public class UserPortrait
|
||||||
|
{
|
||||||
|
public UserPortrait(string filePath,Action<string> loadPic)
|
||||||
|
{
|
||||||
|
if (!System.IO.Directory.Exists(filePath))
|
||||||
|
{
|
||||||
|
System.IO.Directory.CreateDirectory(filePath);
|
||||||
|
}
|
||||||
|
FileSavePath = filePath;
|
||||||
|
LoadPic = loadPic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FileSavePath { get; set; }
|
||||||
|
|
||||||
|
private Action<string> LoadPic = null;
|
||||||
|
|
||||||
|
public void ChangePortrait()
|
||||||
|
{
|
||||||
|
using (FormPortraitSelect fps = new FormPortraitSelect())
|
||||||
|
{
|
||||||
|
if (fps.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait;
|
||||||
|
string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
|
||||||
|
Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300);
|
||||||
|
bitmap300.Save(path300);
|
||||||
|
Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32);
|
||||||
|
bitmap32.Save(path32);
|
||||||
|
//传送服务器
|
||||||
|
bitmap300.Dispose();
|
||||||
|
bitmap32.Dispose();
|
||||||
|
|
||||||
|
using (FormFileOperate ffo = new FormFileOperate(CommonHeadCode.KeyToken, new System.Net.IPEndPoint(
|
||||||
|
System.Net.IPAddress.Parse(UserClient.ServerIp), CommonLibrary.CommonLibrary.Port_Portrait_Server),
|
||||||
|
new string[]
|
||||||
|
{
|
||||||
|
path300,
|
||||||
|
path32
|
||||||
|
}, "Files", "Portrait", UserClient.UserAccount.UserName))
|
||||||
|
{
|
||||||
|
ffo.ShowDialog();
|
||||||
|
}
|
||||||
|
DownloadUserPortraint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void DownloadUserPortraint()
|
||||||
|
{
|
||||||
|
string path = FileSavePath;
|
||||||
|
//获取服务器文件名称
|
||||||
|
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.请求小头, UserClient.UserAccount.UserName);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
if (result.Content[0] == 'Y')
|
||||||
|
{
|
||||||
|
//服务器存在头像
|
||||||
|
string fileName = path + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
string FileMd5 = result.Content.Substring(1);
|
||||||
|
if (System.IO.File.Exists(fileName))
|
||||||
|
{
|
||||||
|
//文件文件
|
||||||
|
string currentMd5 = SoftBasic.CalculateFileMD5(fileName);
|
||||||
|
if (currentMd5 == FileMd5)
|
||||||
|
{
|
||||||
|
//加载本地头像
|
||||||
|
LoadPic?.Invoke(fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//头像已经换了
|
||||||
|
DownloadUserPortraint(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//客户端不存在头像
|
||||||
|
DownloadUserPortraint(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//服务器不存在头像,本次加载结束
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DownloadUserPortraint(string path)
|
||||||
|
{
|
||||||
|
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.下载小头, UserClient.UserAccount.UserName);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
if (result.Content[0] == 'Y')
|
||||||
|
{
|
||||||
|
byte[] data = Convert.FromBase64String(result.Content.Substring(1));
|
||||||
|
string path32 = path + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
System.IO.File.WriteAllBytes(path32, data);
|
||||||
|
LoadPic?.Invoke(path32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadPoolDownloadSizeLarge()
|
||||||
|
{
|
||||||
|
string path = FileSavePath;
|
||||||
|
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.下载大头, UserClient.UserAccount.UserName);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
if (result.Content[0] == 'Y')
|
||||||
|
{
|
||||||
|
byte[] data = Convert.FromBase64String(result.Content.Substring(1));
|
||||||
|
string path32 = path + @"\" + PortraitSupport.LargePortrait;
|
||||||
|
System.IO.File.WriteAllBytes(path32, data);
|
||||||
|
System.Diagnostics.Process.Start(path32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:软件系统客户端Wpf"
|
xmlns:local="clr-namespace:软件系统客户端Wpf"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="350" Width="525" WindowState="Maximized">
|
Title="MainWindow" Height="350" Width="525" WindowState="Maximized" Activated="Window_Activated" Closing="Window_Closing" ContentRendered="Window_ContentRendered" Initialized="Window_Initialized"
|
||||||
|
Loaded="Window_Loaded">
|
||||||
|
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<Grid>
|
<Grid>
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
|
<!--菜单项目-->
|
||||||
<Menu IsMainMenu="True" DockPanel.Dock="Top">
|
<Menu IsMainMenu="True" DockPanel.Dock="Top">
|
||||||
<MenuItem Header="_管理员">
|
<MenuItem Header="_管理员">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
@@ -116,6 +118,52 @@
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
<!--底部状态栏以及公告-->
|
||||||
|
<Grid DockPanel.Dock="Bottom" Background="WhiteSmoke">
|
||||||
|
<Grid Margin="2">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
|
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock x:Name="TextBlock_CopyRight" Foreground="Gray">本软件著作权归某某所有</TextBlock>
|
||||||
|
<TextBlock Margin="20,0,0,0">版本号:</TextBlock>
|
||||||
|
<TextBlock x:Name="TextBlock_Version">1.0.0</TextBlock>
|
||||||
|
<TextBlock Margin="20,0,0,0">客户端状态:</TextBlock>
|
||||||
|
<TextBlock x:Name="TextBlock_ClientStatus">正在连接服务器...</TextBlock>
|
||||||
|
<TextBlock Margin="20,0,0,0" Foreground="Blue">温馨提示:</TextBlock>
|
||||||
|
<TextBlock x:Name="TextBlock_Information" Foreground="Blue"></TextBlock>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||||
|
<TextBlock>时间:</TextBlock>
|
||||||
|
<TextBlock x:Name="TextBlock_ServerTime">0000-00-00 00:00:00</TextBlock>
|
||||||
|
<TextBlock Margin="20,0,0,0">延迟:</TextBlock>
|
||||||
|
<TextBlock x:Name="TextBlock_ServerDelay">0</TextBlock>
|
||||||
|
<TextBlock>ms</TextBlock>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid Width="100" DockPanel.Dock="Left">
|
||||||
|
<Border BorderThickness="0,1,1,1" BorderBrush="LightGray">
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid DockPanel.Dock="Right">
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
<materialDesign:Snackbar MessageQueue="{materialDesign:MessageQueue}"
|
||||||
|
x:Name="SoftSnackbar" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using System.Windows.Media.Imaging;
|
|||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using ClientsLibrary;
|
using ClientsLibrary;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace 软件系统客户端Wpf
|
namespace 软件系统客户端Wpf
|
||||||
{
|
{
|
||||||
@@ -61,6 +62,113 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region 窗口相关方法
|
||||||
|
/// <summary>
|
||||||
|
/// 指示窗口是否显示的标志
|
||||||
|
/// </summary>
|
||||||
|
private bool IsWindowShow { get; set; } = false;
|
||||||
|
|
||||||
|
private void Window_Activated(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//窗口激活就触发,不应把初始代码放这里
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
{
|
||||||
|
IsWindowShow = false;
|
||||||
|
|
||||||
|
//通知服务器退出网络服务
|
||||||
|
net_socket_client.ClientClose();
|
||||||
|
|
||||||
|
//等待一秒退出
|
||||||
|
using (FormWaitInfomation fwm = new FormWaitInfomation("正在退出程序...", 1000))
|
||||||
|
{
|
||||||
|
fwm.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_ContentRendered(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//窗口呈现完成触发,已经显示了
|
||||||
|
//窗口显示
|
||||||
|
IsWindowShow = true;
|
||||||
|
|
||||||
|
//udp测试
|
||||||
|
//SendServerUdpData(0, "显示了窗体");
|
||||||
|
|
||||||
|
//是否显示更新日志,显示前进行判断该版本是否已经显示过了
|
||||||
|
if (UserClient.JsonSettings.IsNewVersionRunning)
|
||||||
|
{
|
||||||
|
UserClient.JsonSettings.IsNewVersionRunning = false;
|
||||||
|
UserClient.JsonSettings.SaveToFile();
|
||||||
|
MenuItem更新日志_Click(null, new RoutedEventArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据权限使能菜单
|
||||||
|
if (UserClient.UserAccount.Grade < AccountGrade.SuperAdministrator)
|
||||||
|
{
|
||||||
|
MenuItem日志查看.IsEnabled = false;
|
||||||
|
MenuItem账户管理.IsEnabled = false;
|
||||||
|
MenuItem远程更新.IsEnabled = false;
|
||||||
|
MenuItem注册账户.IsEnabled = false;
|
||||||
|
MenuItem消息发送.IsEnabled = false;
|
||||||
|
MenuItem开发中心.IsEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//启动网络服务
|
||||||
|
Net_Socket_Client_Initialization();
|
||||||
|
//启动定时器
|
||||||
|
TimeTickInitilization();
|
||||||
|
//显示头像
|
||||||
|
//DownloadUserPortraint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Initialized(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//在窗口实例化之后触发
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
//在窗体加载时触发,窗体还不显示任何东西
|
||||||
|
//窗口载入
|
||||||
|
//label_userName.Text = UserClient.UserAccount.UserName;
|
||||||
|
//label_grade.Text = AccountGrade.GetDescription(UserClient.UserAccount.Grade);
|
||||||
|
//label_factory.Text = UserClient.UserAccount.Factory;
|
||||||
|
//label_register.Text = UserClient.UserAccount.RegisterTime.ToString();
|
||||||
|
//label_last.Text = UserClient.UserAccount.LastLoginTime.ToString();
|
||||||
|
//label_times.Text = UserClient.UserAccount.LoginFrequency.ToString();
|
||||||
|
//label_address.Text = UserClient.UserAccount.LastLoginIpAddress;
|
||||||
|
|
||||||
|
//状态栏设置
|
||||||
|
TextBlock_CopyRight.Text = $"本软件著作权归{Resource.StringResouce.SoftCopyRight}所有";
|
||||||
|
|
||||||
|
//绑定事件,仅执行一次,不能放到show方法里
|
||||||
|
net_socket_client.MessageAlerts += Net_socket_client_MessageAlerts;
|
||||||
|
net_socket_client.LoginFailed += Net_socket_client_LoginFailed;
|
||||||
|
net_socket_client.LoginSuccess += Net_socket_client_LoginSuccess;
|
||||||
|
net_socket_client.AcceptByte += Net_socket_client_AcceptByte;
|
||||||
|
net_socket_client.AcceptString += Net_socket_client_AcceptString;
|
||||||
|
|
||||||
|
//label_Announcement.Text = UserClient.Announcement;
|
||||||
|
|
||||||
|
TextBlock_Version.Text = UserClient.CurrentVersion.ToString();
|
||||||
|
|
||||||
|
//初始化窗口
|
||||||
|
//MainRenderInitialization();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddStringRenderShow(string str)
|
||||||
|
{
|
||||||
|
var messageQueue = SoftSnackbar.MessageQueue;
|
||||||
|
//the message queue can be called from any thread
|
||||||
|
Task.Factory.StartNew(() => SoftSnackbar.MessageQueue.Enqueue(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 菜单逻辑块
|
#region 菜单逻辑块
|
||||||
|
|
||||||
|
|
||||||
@@ -87,25 +195,28 @@ namespace 软件系统客户端Wpf
|
|||||||
|
|
||||||
private void MenuItem注册账户_Click(object sender, RoutedEventArgs e)
|
private void MenuItem注册账户_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
//using (FormRegisterAccount fra = new FormRegisterAccount())
|
using (FormRegisterAccount fra = new FormRegisterAccount())
|
||||||
//{
|
{
|
||||||
// fra.ShowDialog();
|
fra.ShowDialog();
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuItem日志查看_Click(object sender, RoutedEventArgs e)
|
private void MenuItem日志查看_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
using (FormLog flg = new FormLog())
|
||||||
|
{
|
||||||
|
flg.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuItem远程更新_Click(object sender, RoutedEventArgs e)
|
private void MenuItem远程更新_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (UserClient.UserAccount.UserName == "admin")
|
if (UserClient.UserAccount.UserName == "admin")
|
||||||
{
|
{
|
||||||
//using (FormUpdateRemote fur = new FormUpdateRemote())
|
using (FormUpdateRemote fur = new FormUpdateRemote())
|
||||||
//{
|
{
|
||||||
// fur.ShowDialog();
|
fur.ShowDialog();
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -165,9 +276,14 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int index = 1;
|
||||||
private void MenuItem聊天信息_Click(object sender, RoutedEventArgs e)
|
private void MenuItem聊天信息_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
var messageQueue = SoftSnackbar.MessageQueue;
|
||||||
|
var message = "这是一条测试数据这是一条测试数据这是一条测试数据这是一条测试数据这是一条测试数据" + index++;
|
||||||
|
|
||||||
|
//the message queue can be called from any thread
|
||||||
|
Task.Factory.StartNew(() => messageQueue.Enqueue(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuItem头像更改_Click(object sender, RoutedEventArgs e)
|
private void MenuItem头像更改_Click(object sender, RoutedEventArgs e)
|
||||||
@@ -186,12 +302,24 @@ namespace 软件系统客户端Wpf
|
|||||||
|
|
||||||
private void MenuItem更新日志_Click(object sender, RoutedEventArgs e)
|
private void MenuItem更新日志_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
//更新情况复位
|
||||||
|
if (UserClient.JsonSettings.IsNewVersionRunning)
|
||||||
|
{
|
||||||
|
UserClient.JsonSettings.IsNewVersionRunning = false;
|
||||||
|
UserClient.JsonSettings.SaveToFile();
|
||||||
|
}
|
||||||
|
using (FormUpdateLog ful = new FormUpdateLog(UserClient.HistoryVersions))
|
||||||
|
{
|
||||||
|
ful.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuItem版本号说明_Click(object sender, RoutedEventArgs e)
|
private void MenuItem版本号说明_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
using (FormAboutVersion fav = new FormAboutVersion(UserClient.CurrentVersion))
|
||||||
|
{
|
||||||
|
fav.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuItem意见反馈_Click(object sender, RoutedEventArgs e)
|
private void MenuItem意见反馈_Click(object sender, RoutedEventArgs e)
|
||||||
@@ -237,7 +365,7 @@ namespace 软件系统客户端Wpf
|
|||||||
{
|
{
|
||||||
if (customer == CommonHeadCode.MultiNetHeadCode.弹窗新消息)
|
if (customer == CommonHeadCode.MultiNetHeadCode.弹窗新消息)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if(IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
FormPopup fpp = new FormPopup(data, System.Drawing.Color.DodgerBlue, 10000);
|
FormPopup fpp = new FormPopup(data, System.Drawing.Color.DodgerBlue, 10000);
|
||||||
fpp.Show();
|
fpp.Show();
|
||||||
@@ -245,14 +373,14 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.MultiNetHeadCode.总在线信息)
|
else if (customer == CommonHeadCode.MultiNetHeadCode.总在线信息)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//listBox1.DataSource = data.Split('#');
|
//listBox1.DataSource = data.Split('#');
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.MultiNetHeadCode.关闭客户端)
|
else if (customer == CommonHeadCode.MultiNetHeadCode.关闭客户端)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}));
|
}));
|
||||||
@@ -260,7 +388,7 @@ namespace 软件系统客户端Wpf
|
|||||||
else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告)
|
else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告)
|
||||||
{
|
{
|
||||||
//此处应用到了同步类的指令头
|
//此处应用到了同步类的指令头
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
UserClient.Announcement = data;
|
UserClient.Announcement = data;
|
||||||
//label_Announcement.Text = data;
|
//label_Announcement.Text = data;
|
||||||
@@ -276,23 +404,23 @@ namespace 软件系统客户端Wpf
|
|||||||
List<string> chats = JArray.Parse(json["chats"].ToString()).ToObject<List<string>>();
|
List<string> chats = JArray.Parse(json["chats"].ToString()).ToObject<List<string>>();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
chats.ForEach(m => { sb.Append(m + Environment.NewLine); });
|
chats.ForEach(m => { sb.Append(m + Environment.NewLine); });
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm");
|
TextBlock_ServerTime.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
//label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
|
//label_file_count.Text = json["FileCount"].ToObject<int>().ToString();
|
||||||
//UIControls_Chat.AddChatsHistory(sb.ToString());
|
//UIControls_Chat.AddChatsHistory(sb.ToString());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量)
|
else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//label_file_count.Text = data;
|
//label_file_count.Text = data;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
else if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息)
|
else if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//UIControls_Chat?.DealwithReceive(data);
|
//UIControls_Chat?.DealwithReceive(data);
|
||||||
}));
|
}));
|
||||||
@@ -302,7 +430,7 @@ namespace 软件系统客户端Wpf
|
|||||||
private void Net_socket_client_AcceptByte(AsyncStateOne object1, int customer, byte[] object2)
|
private void Net_socket_client_AcceptByte(AsyncStateOne object1, int customer, byte[] object2)
|
||||||
{
|
{
|
||||||
//接收到服务器发来的字节数据
|
//接收到服务器发来的字节数据
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
MessageBox.Show(customer.ToString());
|
MessageBox.Show(customer.ToString());
|
||||||
}));
|
}));
|
||||||
@@ -311,9 +439,9 @@ namespace 软件系统客户端Wpf
|
|||||||
private void Net_socket_client_LoginSuccess()
|
private void Net_socket_client_LoginSuccess()
|
||||||
{
|
{
|
||||||
//登录成功,或重新登录成功的事件,有些数据的初始化可以放在此处
|
//登录成功,或重新登录成功的事件,有些数据的初始化可以放在此处
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//toolStripStatusLabel_status.Text = "客户端启动成功";
|
TextBlock_ClientStatus.Text = "客户端启动成功";
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +450,7 @@ namespace 软件系统客户端Wpf
|
|||||||
//登录失败的情况,如果连续三次连接失败,请考虑退出系统
|
//登录失败的情况,如果连续三次连接失败,请考虑退出系统
|
||||||
if (object1 > 3)
|
if (object1 > 3)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}));
|
}));
|
||||||
@@ -332,9 +460,9 @@ namespace 软件系统客户端Wpf
|
|||||||
private void Net_socket_client_MessageAlerts(string object1)
|
private void Net_socket_client_MessageAlerts(string object1)
|
||||||
{
|
{
|
||||||
//信息提示
|
//信息提示
|
||||||
Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
//toolStripStatusLabel_status.Text = object1;
|
TextBlock_ClientStatus.Text = object1;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,8 +475,96 @@ namespace 软件系统客户端Wpf
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region 后台计数线程
|
||||||
|
|
||||||
|
/*********************************************************************************************
|
||||||
|
*
|
||||||
|
* 说明 一个后台线程,用来执行一些周期执行的东西
|
||||||
|
* 注意 它不仅执行每秒触发的代码,也支持每分钟,每天,每月,每年等等
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化后台的计数线程
|
||||||
|
/// </summary>
|
||||||
|
public void TimeTickInitilization()
|
||||||
|
{
|
||||||
|
|
||||||
|
Thread thread = new Thread(new ThreadStart(ThreadTimeTick));
|
||||||
|
thread.IsBackground = true;
|
||||||
|
thread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadTimeTick()
|
||||||
|
{
|
||||||
|
Thread.Sleep(300);//加一个微小的延时
|
||||||
|
int second = DateTime.Now.Second - 1;
|
||||||
|
int minute = -1;
|
||||||
|
int hour = -1;
|
||||||
|
int day = -1;
|
||||||
|
Action DTimeShow = delegate
|
||||||
|
{
|
||||||
|
//显示服务器的时间和当前网络的延时时间,通常为毫秒
|
||||||
|
TextBlock_ServerTime.Text = net_socket_client.ServerTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
TextBlock_ServerDelay.Text = net_socket_client.DelayTime.ToString();
|
||||||
|
};
|
||||||
|
|
||||||
|
while (IsWindowShow)
|
||||||
|
{
|
||||||
|
while (DateTime.Now.Second == second)
|
||||||
|
{
|
||||||
|
Thread.Sleep(20);
|
||||||
|
}
|
||||||
|
second = DateTime.Now.Second;
|
||||||
|
if (IsWindowShow) Dispatcher.Invoke(DTimeShow);
|
||||||
|
//每秒钟执行的代码
|
||||||
|
UserClient.DateTimeServer = net_socket_client.ServerTime;
|
||||||
|
|
||||||
|
if (second == 0)
|
||||||
|
{
|
||||||
|
//每个0秒执行的代码
|
||||||
|
}
|
||||||
|
if (minute != DateTime.Now.Minute)
|
||||||
|
{
|
||||||
|
minute = DateTime.Now.Minute;
|
||||||
|
//每分钟执行的代码
|
||||||
|
}
|
||||||
|
if (hour != DateTime.Now.Hour)
|
||||||
|
{
|
||||||
|
hour = DateTime.Now.Hour;
|
||||||
|
//每小时执行的代码
|
||||||
|
}
|
||||||
|
if (day != DateTime.Now.Day)
|
||||||
|
{
|
||||||
|
day = DateTime.Now.Day;
|
||||||
|
//每天执行的代码
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Udp发送示例
|
||||||
|
/// <summary>
|
||||||
|
/// 调用该方法并指定参数即可,最长字符串不得
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
private void SendServerUdpData(int customer, string data)
|
||||||
|
{
|
||||||
|
//测试发送udp消息
|
||||||
|
UserClient.Net_Udp_Client.SendMessage(customer, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user