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.

67 lines
2.7 KiB
C#

1 year ago
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Mesnac.Action.Base;
using Mesnac.Basic;
using Mesnac.Codd.Session;
using Mesnac.Controls.Base;
namespace Mesnac.Action.Default.Purview
{
/// <summary>
/// 窗体控件的用户权限处理类
/// 创建人:郑立兵
/// 创建时间2013-7-24
/// 说明:根据登录用户的权限处理窗体内的控件是否可用
/// </summary>
public class CheckPurviewControl : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);//必须调用
ICSharpCode.Core.LoggingService<CheckPurviewControl>.Debug("通用方法——窗体中权限控件的处理");
if (runtime.Sender == null || !runtime.Sender.GetType().IsSubclassOf(typeof(Form)))
{
return;//sender不是功能Form
}
if (!(runtime.Sender as IPurviewControl).MCPurview)
{
return;//窗体不验证权限
}
if (UserInfo.Instance.RoleGUID == "-99")
{
return;//超级用户
}
DbHelper dbHelper = NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
return;
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
string strSql = "SELECT TA.GUID, TA.PermissionItemGUID, TA.PermissionType,tb.formname,formtext,tc.functionname FROM BasRolePermission TA INNER JOIN BasFormFunction TC ON TA.PermissionItemGUID=TC.GUID AND TA.PermissionType=TC.FunctionType left join BasForm TB on tc.FormGUID=tb.GUID WHERE TC.DeleteFlag='0' AND TC.DeleteFlag='0' AND TA.RoleGUID=@RoleGUID;";
dbHelper.AddParameter("@RoleGUID", UserInfo.Instance.RoleGUID);
dbHelper.CommandText = strSql;
DataTable dt = dbHelper.ToDataTable();
string Formname = string.Empty;
if (base.GetThisOwer() is Form)
{
Formname = (base.GetThisOwer() as Form).Name;
}
List<IPurviewControl> listPC = GetAllMCPurviewControls();
foreach (IPurviewControl control in listPC)
{
if (control.MCPurview && !control.GetType().IsSubclassOf(typeof(Form)))
{
control.MCEnabled = false;
if (dt.Select(string.Format("formname='{0}' AND functionname='{1}'", Formname, (control as Control).Name)).Length > 0)
{
control.MCEnabled = true;
}
}
}
}
}
}