Browse Source

修改。

master
yibo 7 years ago
parent
commit
b9e8cd2e60
4 changed files with 29 additions and 29 deletions
  1. +2
    -14
      ButcherFactory.BO/Base/WpfUser.cs
  2. +12
    -3
      ButcherFactory.BO/Utils/AppContext.cs
  3. +7
    -10
      ButcherFactory.BO/Utils/LoginUtil.cs
  4. +8
    -2
      ButcherFactory.Login/Login.cs

+ 2
- 14
ButcherFactory.BO/Base/WpfUser.cs View File

@ -19,21 +19,9 @@ namespace ButcherFactory.BO
public byte[] Password { get; set; }
public string Role { get; set; }
List<string> _roleList;
List<string> _roleList = new List<string>();
[NonDmoProperty]
public List<string> RoleList
{
get
{
if (_roleList == null)
{
_roleList = new List<string>();
if (!string.IsNullOrEmpty(Role))
_roleList.AddRange(Role.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
}
return _roleList;
}
}
public List<string> RoleList { get { return _roleList; } }
[NonDmoProperty]
public bool Login { get; set; }


+ 12
- 3
ButcherFactory.BO/Utils/AppContext.cs View File

@ -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<ServerUrlConfig>();
}
public string ServerUrl { get; set; }
public string SqlConnection { get; set; }


+ 7
- 10
ButcherFactory.BO/Utils/LoginUtil.cs View File

@ -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;


+ 8
- 2
ButcherFactory.Login/Login.cs View File

@ -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))


Loading…
Cancel
Save