You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Main/Mesnac.Basic/UserInfo.cs

289 lines
7.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Data;
using Mesnac.Codd;
using Mesnac.Codd.Session;
namespace Mesnac.Basic
{
/// <summary>
/// 登录用户信息类
/// 创建人:初风鸣
/// 创建时间2013-7-23
/// 说明:采用单例模式
/// </summary>
public class UserInfo
{
#region 事件定义
/// <summary>
/// 重新登录事件
/// </summary>
public event EventHandler OnReLogin;
#endregion
#region 字段定义
private string _userGUId;
private int _seqIndex;
private string _userName;
private string _realName;
private string _roleGUID;//未登录时为-1预留超级用户为-99
private int _classID; //所属班组
private DateTime _loginTime;
public const bool MustLogin=false;
private List<string> _purviewList = null; //当前用户的权限项列表
private List<string> _allFormPurview = null; //所有权限项
#endregion
#region 单例模式
private static UserInfo user=null;
public static UserInfo Instance
{
get
{
//lock(String.Empty)
{
if (user == null)
{
user = new UserInfo();
}
return user;
}
}
}
#endregion
#region 构造方法
public UserInfo()
: this( "-1" , 0, "--" , "--" , "-1", 1)
{
}
public UserInfo( string userGUId , string userName, string realName , string roleGUID )
{
this._userGUId = userGUId;
this._userName = userName;
this._realName = realName;
this._roleGUID = roleGUID;
this._loginTime = DateTime.Now;
}
public UserInfo(string userGUId, int seqIndex, string userName, string realName, string roleGUID)
{
this._userGUId = userGUId;
this._seqIndex = seqIndex;
this._userName = userName;
this._realName = realName;
this._roleGUID = roleGUID;
this._loginTime = DateTime.Now;
}
public UserInfo(string userGUId, int seqIndex, string userName, string realName, string roleGUID, int classID)
{
this._userGUId = userGUId;
this._seqIndex = seqIndex;
this._userName = userName;
this._realName = realName;
this._roleGUID = roleGUID;
this._classID = classID;
this._loginTime = DateTime.Now;
}
#endregion
#region 属性定义
public string UserGUID
{
get
{
return _userGUId;
}
set
{
_userGUId = value;
}
}
public int SeqIndex
{
get { return _seqIndex; }
set { _seqIndex = value; }
}
public string UserName
{
get
{
return _userName;
}
set
{
_userName = value;
}
}
public string RealName
{
get
{
return _realName;
}
set
{
_realName = value;
}
}
public string RoleGUID
{
get
{
return _roleGUID;
}
set
{
_roleGUID = value;
if ( _roleGUID.Equals( "-99" ) )
{
_userGUId = "mesnac";
_userName = "mesnac";
_realName = "超级用户";
}
}
}
public int ClassID
{
get { return _classID; }
set { _classID = value; }
}
public DateTime LoginTime
{
get
{
return _loginTime;
}
set
{
_loginTime = DateTime.Now;
}
}
/// <summary>
/// 当前登录窗体对象
/// </summary>
public System.Windows.Forms.Form FrmSysLogin { get; set; }
/// <summary>
/// 获取权限项列表
/// </summary>
public List<string> AllFormPurview
{
get
{
this.RefreshAllFormPurview();
return this._allFormPurview;
}
}
/// <summary>
/// 获取当前用户的权限项列表
/// </summary>
public List<string> PurviewList
{
get
{
this.RefreshPurview();
return this._purviewList;
}
}
#endregion
#region 方法定义
public DataTable GetPurview()
{
DataTable dt = new DataTable();
DbHelper dbhelper = DataSourceFactory.Instance.GetDbHelper( DataSourceFactory.MCDbType.Local);
if ( dbhelper != null )
{
dbhelper.ClearParameter();
dbhelper.CommandType = CommandType.Text;
dbhelper.CommandText = "SELECT DISTINCT TA.PermissionItemGUID,TB.FormName,TB.FormText,TB.FormType FROM BasRolePermission TA INNER JOIN BasForm TB ON TA.PermissionItemGUID=TB.GUID AND TA.PermissionType=TB.FormType WHERE '" + _roleGUID + "' IN('-99',TA.RoleGUID) AND TB.DeleteFlag='0'";
dt = dbhelper.ToDataTable();
}
return dt;
}
/// <summary>
/// 刷新权限项列表
/// </summary>
public void RefreshAllFormPurview()
{
if (this._allFormPurview == null)
{
this._allFormPurview = new List<string>();
}
this._allFormPurview.Clear();
DataTable dt = new DataTable();
DbHelper dbhelper = DataSourceFactory.Instance.GetDbHelper(DataSourceFactory.MCDbType.Local);
if (dbhelper != null)
{
dbhelper.ClearParameter();
dbhelper.CommandType = CommandType.Text;
dbhelper.CommandText = "SELECT [GUID],[FormName],[FormText],[FormType],[DeleteFlag] FROM [BasForm] where DeleteFlag = 0";
dt = dbhelper.ToDataTable();
}
if (dt != null)
{
foreach (DataRow row in dt.Rows)
{
this._allFormPurview.Add(row["FormName"] as string);
}
}
}
/// <summary>
/// 刷新当前用户权限项
/// </summary>
public void RefreshPurview()
{
if (this._purviewList == null)
{
this._purviewList = new List<string>();
}
this._purviewList.Clear();
DataTable table = this.GetPurview();
if (table != null)
{
foreach (DataRow row in table.Rows)
{
this._purviewList.Add(row["FormName"] as string);
}
}
}
/// <summary>
/// 触发重新登录事件
/// </summary>
public void TriggerReLoginEvent()
{
if (this.OnReLogin != null)
{
this.OnReLogin(this, System.EventArgs.Empty);
}
}
#endregion
}
}