diff --git a/软件系统客户端Wpf/LoginWindow.xaml b/软件系统客户端Wpf/LoginWindow.xaml
index 3ad0e61..2251d46 100644
--- a/软件系统客户端Wpf/LoginWindow.xaml
+++ b/软件系统客户端Wpf/LoginWindow.xaml
@@ -32,7 +32,7 @@
[您的软件系统]
-
+
@@ -43,30 +43,32 @@
-
-
+
-
-
+
-
+
+
+ 是否记住密码?
+
-
-
- 是否记住密码?
-
+
- 正在连接服务器...
+ 正在连接服务器...
diff --git a/软件系统客户端Wpf/LoginWindow.xaml.cs b/软件系统客户端Wpf/LoginWindow.xaml.cs
index f1cef46..0f29fe1 100644
--- a/软件系统客户端Wpf/LoginWindow.xaml.cs
+++ b/软件系统客户端Wpf/LoginWindow.xaml.cs
@@ -11,6 +11,12 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Windows.Media.Animation;
+using System.Threading;
+using HslCommunication;
+using CommonLibrary;
+using HslCommunication.BasicFramework;
+using Newtonsoft.Json.Linq;
namespace 软件系统客户端Wpf
{
@@ -26,7 +32,257 @@ namespace 软件系统客户端Wpf
private void Button_Click(object sender, RoutedEventArgs e)
{
- this.DialogResult = true;
+ //启动线程登录
+ //验证输入
+ if (string.IsNullOrEmpty(NameTextBox.Text))
+ {
+ SetInformationString("请输入用户名");
+ NameTextBox.Focus();
+ return;
+ }
+
+ if (string.IsNullOrEmpty(PasswordBox.Password))
+ {
+ SetInformationString("请输入密码");
+ PasswordBox.Focus();
+ return;
+ }
+
+ SetInformationString("正在验证维护状态...");
+ UISettings(false);
+
+ UserName = NameTextBox.Text;
+ UserPassword = PasswordBox.Password;
+ IsChecked = (bool)Remember.IsChecked;
+
+ ThreadAccountLogin = new Thread(ThreadCheckAccount);
+ ThreadAccountLogin.IsBackground = true;
+ ThreadAccountLogin.Start();
+ }
+
+ #region 账户验证的逻辑块
+
+
+
+ private string UserName = string.Empty;
+ private string UserPassword = string.Empty;
+ private bool IsChecked = false;
+
+ ///
+ /// 用于验证的后台线程
+ ///
+ private Thread ThreadAccountLogin = null;
+ ///
+ /// 用户账户验证的后台端
+ ///
+ private void ThreadCheckAccount()
+ {
+ //定义委托
+ Action message_show = delegate (string message)
+ {
+ SetInformationString(message);
+ };
+ Action start_update = delegate
+ {
+ //需要该exe支持,否则将无法是实现自动版本控制
+ string update_file_name = AppDomain.CurrentDomain.BaseDirectory + @"\软件自动更新.exe";
+ try
+ {
+ System.Diagnostics.Process.Start(update_file_name);
+ Environment.Exit(0);//退出系统
+ }
+ catch
+ {
+ MessageBox.Show("更新程序启动失败,请检查文件是否丢失,联系管理员获取。");
+ }
+ };
+ Action thread_finish = delegate
+ {
+ UISettings(true);
+ };
+
+ //延时
+ Thread.Sleep(200);
+
+ //请求指令头数据,该数据需要更具实际情况更改
+ OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.维护检查);
+ if (result.IsSuccess)
+ {
+ byte[] temp = Encoding.Unicode.GetBytes(result.Content);
+ //例如返回结果为1说明允许登录,0则说明服务器处于维护中,并将信息显示
+ if (result.Content != "1")
+ {
+ Dispatcher.Invoke(message_show, result.Content.Substring(1));
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+ }
+ else
+ {
+ //访问失败
+ Dispatcher.Invoke(message_show, result.Message);
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+
+
+
+ //检查账户
+ Dispatcher.Invoke(message_show, "正在检查账户...");
+
+ //延时
+ Thread.Sleep(200);
+
+ //===================================================================================
+ // 根据实际情况校验,选择数据库校验或是将用户名密码发至服务器校验
+ // 以下展示了服务器校验的方法,如您需要数据库校验,请删除下面并改成SQL访问验证的方式
+
+ //包装数据
+ JObject json = new JObject
+ {
+ { UserAccount.UserNameText, new JValue(UserName) },
+ { UserAccount.PasswordText, new JValue(UserPassword) }
+ };
+ result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.账户检查, json.ToString());
+ if (result.IsSuccess)
+ {
+ //服务器应该返回账户的信息
+ UserAccount account = JObject.Parse(result.Content).ToObject();
+ if (!account.LoginEnable)
+ {
+ //不允许登录
+ Dispatcher.Invoke(message_show, account.ForbidMessage);
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+ UserClient.UserAccount = account;
+ }
+ else
+ {
+ //访问失败
+ Dispatcher.Invoke(message_show, result.Message);
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+
+ //登录成功,进行保存用户名称和密码
+ UserClient.JsonSettings.LoginName = UserName;
+ UserClient.JsonSettings.Password = IsChecked ? UserPassword : "";
+ UserClient.JsonSettings.LoginTime = DateTime.Now;
+ UserClient.JsonSettings.SaveToFile();
+
+
+ //版本验证
+ Dispatcher.Invoke(message_show, "正在验证版本...");
+
+ //延时
+ Thread.Sleep(200);
+
+ result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.更新检查);
+ if (result.IsSuccess)
+ {
+ //服务器应该返回服务器的版本号
+ SystemVersion sv = new SystemVersion(result.Content);
+ //系统账户跳过低版本检测
+ if (UserClient.UserAccount.UserName != "admin")
+ {
+ if (UserClient.CurrentVersion != sv)
+ {
+ //保存新版本信息
+ UserClient.JsonSettings.IsNewVersionRunning = true;
+ UserClient.JsonSettings.SaveToFile();
+ //和当前系统版本号不一致,启动更新
+ Dispatcher.Invoke(start_update);
+ return;
+ }
+ }
+ else
+ {
+ if (UserClient.CurrentVersion < sv)
+ {
+ //保存新版本信息
+ UserClient.JsonSettings.IsNewVersionRunning = true;
+ UserClient.JsonSettings.SaveToFile();
+ //和当前系统版本号不一致,启动更新
+ Dispatcher.Invoke(start_update);
+ return;
+ }
+ }
+ }
+ else
+ {
+ //访问失败
+ Dispatcher.Invoke(message_show, result.Message);
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+
+
+ //================================================================================
+ //验证结束后,根据需要是否下载服务器的数据,或是等到进入主窗口下载也可以
+ //如果有参数决定主窗口的显示方式,那么必要在下面向服务器请求数据
+ //以下展示了初始化参数的功能
+ Dispatcher.Invoke(message_show, "正在下载参数...");
+
+ //延时
+ Thread.Sleep(200);
+
+
+ result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.参数下载);
+ if (result.IsSuccess)
+ {
+ //服务器返回初始化的数据,此处进行数据的提取,有可能包含了多个数据
+ json = Newtonsoft.Json.Linq.JObject.Parse(result.Content);
+ //例如公告数据
+ UserClient.Announcement = SoftBasic.GetValueFromJsonObject(json, nameof(UserClient.Announcement), "");
+
+ }
+ else
+ {
+ //访问失败
+ Dispatcher.Invoke(message_show, result.Message);
+ Dispatcher.Invoke(thread_finish);
+ return;
+ }
+
+ //启动主窗口
+ Dispatcher.Invoke(new Action(() =>
+ {
+ DialogResult = true;
+ return;
+ }));
+ }
+
+
+ #endregion
+
+ private void UISettings(bool enable)
+ {
+ NameTextBox.IsEnabled = enable;
+ PasswordBox.IsEnabled = enable;
+ Remember.IsEnabled = enable;
+ LoginButton.IsEnabled = enable;
+ }
+
+ private void SetInformationString(string str)
+ {
+ if (WindowToolTip.Opacity == 1)
+ {
+ DoubleAnimation hidden = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(100));
+ hidden.Completed += delegate
+ {
+ DoubleAnimation show = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(100));
+ WindowToolTip.Text = str;
+ WindowToolTip.BeginAnimation(OpacityProperty, show);
+ };
+ WindowToolTip.BeginAnimation(OpacityProperty, hidden);
+ }
+ else
+ {
+ DoubleAnimation show = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(100));
+ WindowToolTip.Text = str;
+ WindowToolTip.BeginAnimation(OpacityProperty, show);
+ }
}
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
@@ -41,6 +297,7 @@ namespace 软件系统客户端Wpf
private void Window_Loaded(object sender, RoutedEventArgs e)
{
+ WindowToolTip.Opacity = 0;
TextBlockSoftName.Text = CommonLibrary.Resource.StringResouce.SoftName;
TextBlockSoftVersion.Text = UserClient.CurrentVersion.ToString();
TextBlockSoftCopyright.Text = $"本软件著作权归{CommonLibrary.Resource.StringResouce.SoftCopyRight}所有";
@@ -63,12 +320,12 @@ namespace 软件系统客户端Wpf
private void NameTextBox_KeyDown(object sender, KeyEventArgs e)
{
- PasswordBox.Focus();
+ if(e.Key==Key.Enter) PasswordBox.Focus();
}
private void PasswordBox_KeyDown(object sender, KeyEventArgs e)
{
- Button_Click(null, new RoutedEventArgs());
+ if (e.Key == Key.Enter) Button_Click(null, new RoutedEventArgs());
}
}
}
diff --git a/软件系统客户端Wpf/screenshots/client1.png b/软件系统客户端Wpf/screenshots/client1.png
new file mode 100644
index 0000000..76bcae3
Binary files /dev/null and b/软件系统客户端Wpf/screenshots/client1.png differ
diff --git a/软件系统服务端模版/FormServerWindow.cs b/软件系统服务端模版/FormServerWindow.cs
index e8ced80..47ed355 100644
--- a/软件系统服务端模版/FormServerWindow.cs
+++ b/软件系统服务端模版/FormServerWindow.cs
@@ -472,9 +472,9 @@ namespace 软件系统服务端模版
{
if (customer == CommonHeadCode.SimplifyHeadCode.维护检查)
{
- net_simplify_server.SendMessage(state, customer, "1");
- //UserServer.ServerSettings.Can_Account_Login ? "1" : "0" +
- //UserServer.ServerSettings.Account_Forbidden_Reason);
+ net_simplify_server.SendMessage(state, customer,
+ UserServer.ServerSettings.Can_Account_Login ? "1" : "0" +
+ UserServer.ServerSettings.Account_Forbidden_Reason);
}
else if (customer == CommonHeadCode.SimplifyHeadCode.更新检查)
{