using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json.Linq; namespace CommonLibrary { /// /// 本系統的用账户类,包含了一些常用的数据信息,如果你想添加额外属性,请继承此类 /// public class UserAccount { #region Public Members /// /// 用户名称,该名称唯一 /// public string UserName { get; set; } = ""; /// /// 用户名称的别名,也不可以不使用 /// public string NameAlias { get; set; } = ""; /// /// 用户登录的密码 /// public string Password { get; set; } = ""; /// /// 账户所属的工厂名称或类别名称 /// public string Factory { get; set; } = ""; /// /// 用户的权限等级,目前配置了4个等级 /// public int Grade { get; set; } = 0; /// /// 用户的手机号 /// public string Phone { get; set; } /// /// 用户的电子邮件 /// public string EMail { get; set; } /// /// 该用户的注册日期,一旦注册,应该固定 /// public DateTime RegisterTime { get; set; } = DateTime.Now; /// /// 该用户是否允许登录 /// public bool LoginEnable { get; set; } = false; /// /// 该用户不允许被登录的原因 /// public string ForbidMessage { get; set; } = "该账户被管理员禁止登录!"; /// /// 该用户自注册以来登录的次数 /// public int LoginFrequency { get; set; } = 0; /// /// 该用户上次登录的时间 /// public DateTime LastLoginTime { get; set; } = DateTime.Now; /// /// 该用户上次登录的IP地址 /// public string LastLoginIpAddress { get; set; } = ""; /// /// 该用户连续登录失败的计数,可以用来连续五次失败禁止账户登录 /// public int LoginFailedCount { get; set; } = 0; /// /// 上次登录系统的方式,有winform版,wpf版,web版,Android版 /// public string LastLoginWay { get; set; } = string.Empty; /// /// 小尺寸头像的MD5码 /// public string SmallPortraitMD5 { get; set; } = string.Empty; /// /// 大尺寸头像的MD5码 /// public string LargePortraitMD5 { get; set; } = string.Empty; #endregion #region Static Members /// /// 用于存储和传送的名称 /// public static string UserNameText { get { return "UserName"; } } /// /// 用于存储和传送的名称 /// public static string PasswordText { get { return "Password"; } } /// /// 用于存储和传送的名称 /// public static string LoginWayText { get { return "LoginWay"; } } /// /// 登录系统的唯一设备ID /// public static string DeviceUniqueID { get { return "DeviceUniqueID"; } } /// /// 小尺寸头像的MD5传送名称 /// public static string SmallPortraitText { get { return "SmallPortrait"; } } /// /// 大尺寸头像的MD5传送名称 /// public static string LargePortraitText { get { return "LargePortrait"; } } /// /// 系统的框架版本,框架版本不一致,由服务器决定是否允许客户端登录 /// public static string FrameworkVersion { get { return "FrameworkVersion"; } } #endregion #region Public Method /// /// 获取本账号的JSON字符串,用于在网络中数据传输 /// /// public string ToJsonString() { return JObject.FromObject(this).ToString(); } /// /// 深度拷贝当前的账户信息 /// /// 返回的类型,应该为继承后的类型 /// 新的对象 public T DeepCopy() where T : UserAccount { return JObject.FromObject(this).ToObject(); } #endregion #region Override Method /// /// 获取账号的用户名 /// /// public override string ToString() { return UserName; } #endregion } /// /// 账户的等级 /// public class AccountGrade { /// /// 超级管理员 /// public static int SuperAdministrator { get; private set; } = 10000; /// /// 管理员 /// public static int Admin { get; private set; } = 1000; /// /// 技术员 /// public static int Technology { get; private set; } = 100; /// /// 一般 /// public static int General { get; private set; } = 10; /// /// 获取对应等级的文本描述 /// /// 等级数据 /// 等级描述 public static string GetDescription(int grade) { if (grade >= SuperAdministrator) { return "超级管理员"; } else if (grade >= Admin) { return "管理员"; } else if (grade >= Technology) { return "技术员"; } else { return "普通"; } } /// /// 获取权限的数组 /// /// public static string[] GetDescription() { return new string[] { GetDescription(SuperAdministrator), GetDescription(Admin), GetDescription(Technology), GetDescription(General), }; } } }