From b9e8cd2e6043d3917371d53a850645b8f4629e9d Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Tue, 27 Mar 2018 23:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ButcherFactory.BO/Base/WpfUser.cs | 16 ++-------------- ButcherFactory.BO/Utils/AppContext.cs | 15 ++++++++++++--- ButcherFactory.BO/Utils/LoginUtil.cs | 17 +++++++---------- ButcherFactory.Login/Login.cs | 10 ++++++++-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/ButcherFactory.BO/Base/WpfUser.cs b/ButcherFactory.BO/Base/WpfUser.cs index 54a4d20..20b9003 100644 --- a/ButcherFactory.BO/Base/WpfUser.cs +++ b/ButcherFactory.BO/Base/WpfUser.cs @@ -19,21 +19,9 @@ namespace ButcherFactory.BO public byte[] Password { get; set; } public string Role { get; set; } - List _roleList; + List _roleList = new List(); [NonDmoProperty] - public List RoleList - { - get - { - if (_roleList == null) - { - _roleList = new List(); - if (!string.IsNullOrEmpty(Role)) - _roleList.AddRange(Role.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); - } - return _roleList; - } - } + public List RoleList { get { return _roleList; } } [NonDmoProperty] public bool Login { get; set; } diff --git a/ButcherFactory.BO/Utils/AppContext.cs b/ButcherFactory.BO/Utils/AppContext.cs index d6ed6be..8e7f8d0 100644 --- a/ButcherFactory.BO/Utils/AppContext.cs +++ b/ButcherFactory.BO/Utils/AppContext.cs @@ -12,8 +12,17 @@ namespace ButcherFactory.BO.Utils static ServerUrlConfig _connectInfo = ServerUrlConfig.Init(); public static ServerUrlConfig ConnectInfo { get { return _connectInfo; } } - static WpfUser _user = LoginUtil.InitUserFromLocal(); - public static WpfUser User { get { return _user; } } + static WpfUser _user = null; + public static WpfUser User + { + get + { + if (_user == null) + _user = LoginUtil.InitUserFromLocal(); + return _user; + } + set { _user = value; } + } } public class ServerUrlConfig @@ -22,7 +31,7 @@ namespace ButcherFactory.BO.Utils { return XmlUtil.DeserializeFromFile(); } - + public string ServerUrl { get; set; } public string SqlConnection { get; set; } diff --git a/ButcherFactory.BO/Utils/LoginUtil.cs b/ButcherFactory.BO/Utils/LoginUtil.cs index 528e169..859f992 100644 --- a/ButcherFactory.BO/Utils/LoginUtil.cs +++ b/ButcherFactory.BO/Utils/LoginUtil.cs @@ -23,7 +23,12 @@ namespace ButcherFactory.BO.Utils var query = new DmoQuery(typeof(WpfUser)); var obj = session.ExecuteScalar(query); if (obj != null) - return (WpfUser)obj; + { + var user = (WpfUser)obj; + if (!string.IsNullOrEmpty(user.Role)) + user.RoleList.AddRange(user.Role.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); + return user; + } } return new WpfUser(); } @@ -76,6 +81,7 @@ namespace ButcherFactory.BO.Utils public static void Login(string userName, string pwd) { RpcFacade.Login(userName, pwd); + AppContext.User = new WpfUser(); AppContext.User.Login = true; AppContext.User.Name = userName; FillUserEmpInfo(userName); @@ -119,15 +125,6 @@ namespace ButcherFactory.BO.Utils } } - public static void AddUserRole(string role) - { - - if (AppContext.User.RoleList.Contains(role)) - return; - AppContext.User.RoleList.Add(role); - UpdateUserRole(); - } - public static bool TestConnection(int? millisecondsTimeout = null) { var url = AppContext.ConnectInfo.ServerUrl; diff --git a/ButcherFactory.Login/Login.cs b/ButcherFactory.Login/Login.cs index 461b659..0a36365 100644 --- a/ButcherFactory.Login/Login.cs +++ b/ButcherFactory.Login/Login.cs @@ -52,8 +52,8 @@ namespace ButcherFactory.Login } else { - if (AppContext.User.Name != username && LoginUtil.EncodePwd(pwd) != AppContext.User.Password) - throw new Exception("请输入用户名"); + if (AppContext.User.Name != username || string.Join("", LoginUtil.EncodePwd(pwd)) != string.Join("", AppContext.User.Password)) + throw new Exception("离线时只能使用上次登录信息登录"); } @@ -98,6 +98,12 @@ namespace ButcherFactory.Login var keyBoard = new NumberPad(); if (keyBoard.ShowDialog() == true) { + if (!LoginUtil.TestConnection(1000)) + { + if (string.IsNullOrEmpty(AppContext.User.Name)) + throw new Exception("请检查网络"); + throw new Exception("离线时无法切换用户"); + } string errorInfo; userNameBox.Text = LoginUtil.GetUserNameByCode(keyBoard.Result, out errorInfo); if (string.IsNullOrEmpty(userNameBox.Text))