|
|
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
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 重新登录事件
|
|
|
/// </summary>
|
|
|
public event EventHandler OnReLogin;
|
|
|
private string _userId;
|
|
|
private string _userName;
|
|
|
private string _realName;
|
|
|
private string _roleId;//未登录时为-1,预留超级用户为-99
|
|
|
private DateTime _loginTime;
|
|
|
public const bool MustLogin=false;
|
|
|
private List<string> _purviewList = null; //当前用户的权限项列表
|
|
|
private List<string> _allFormPurview = null; //所有权限项
|
|
|
|
|
|
#region 单例模式
|
|
|
private static UserInfo user=null;
|
|
|
public static UserInfo Instance
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if ( user == null )
|
|
|
{
|
|
|
user = new UserInfo();
|
|
|
}
|
|
|
return user;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
public UserInfo()
|
|
|
: this( "-1" , "--" , "--" , "-1" )
|
|
|
{
|
|
|
}
|
|
|
public UserInfo( string userId , string userName, string realName , string roleId )
|
|
|
{
|
|
|
this._userId = userId;
|
|
|
this._userName = userName;
|
|
|
this._realName = realName;
|
|
|
this._roleId = roleId;
|
|
|
this._loginTime = DateTime.Now;
|
|
|
}
|
|
|
|
|
|
public string UserID
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _userId;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_userId = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string UserName
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _userName;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_userName = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string RealName
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _realName;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_realName = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string RoleID
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _roleId;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_roleId = value;
|
|
|
if ( _roleId.Equals( "-99" ) )
|
|
|
{
|
|
|
_userName = "mesnac";
|
|
|
_realName = "超级用户";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public DateTime LoginTime
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _loginTime;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_loginTime = DateTime.Now;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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.PurviewID,TB.FormName,TB.FormText,TB.FormType FROM BasRolePurview TA INNER JOIN BasForm TB ON TA.PurviewID=TB.ObjID AND TA.PurviewType=TB.FormType WHERE "+_roleId+" IN(-99,TA.RoleID) AND TB.DeleteFlag='0'";
|
|
|
|
|
|
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 '" + _roleId + "' IN('-99',TA.RoleGUID) AND TB.DeleteFlag='0'";
|
|
|
|
|
|
dt = dbhelper.ToDataTable();
|
|
|
}
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取权限项列表
|
|
|
/// </summary>
|
|
|
public List<string> AllFormPurview
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
this.RefreshAllFormPurview();
|
|
|
return this._allFormPurview;
|
|
|
}
|
|
|
}
|
|
|
/// <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 [ObjID],[FormName],[FormText],[FormType],[DeleteFlag] FROM [BasForm] where DeleteFlag = 0";
|
|
|
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 List<string> PurviewList
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
this.RefreshPurview();
|
|
|
return this._purviewList;
|
|
|
}
|
|
|
}
|
|
|
/// <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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|