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/Actions/Default/Mesnac.Action.Default/Purview/RefreshSystemPurview.cs

79 lines
3.0 KiB
C#

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;
using Mesnac.Gui.Workbench;
using Mesnac.Gui.Run.Global;
using Mesnac.PlugIn.View;
using System.Reflection;
namespace Mesnac.Action.Default.Purview
{
public class RefreshSystemPurview : DatabaseAction, IAction
{
private static bool _isFirstRun = true;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);//必须调用
if (_isFirstRun)
{
Mesnac.Basic.UserInfo.Instance.OnReLogin += Instance_OnReLogin;
_isFirstRun = false;
}
DoRefresh();
}
void Instance_OnReLogin(object sender, System.EventArgs e)
{
DoRefresh();
}
private static void DoRefresh()
{
//WorkbenchSingleton.Workbench.CloseAllViews(); //关闭所有视图面板
IViewContent[] vcs = WorkbenchSingleton.Workbench.ViewContentCollection.ToArray();
for (int i = 0; i < vcs.Length; i++)
{
if (vcs[i] != null)
{
vcs[i].IsRealClose = false;
WorkbenchSingleton.Workbench.CloseView(vcs[i]);
}
}
//foreach (IViewContent vc in WorkbenchSingleton.Workbench.ViewContentCollection)
//{
// vc.IsRealClose = false;
// WorkbenchSingleton.Workbench.CloseView(vc);
//}
List<string> purviewList = Mesnac.Basic.UserInfo.Instance.PurviewList; //当前用户的权限列表
string[] keys = new string[WorkbenchSingleton.Workbench.ViewContentDic.Keys.Count];
WorkbenchSingleton.Workbench.ViewContentDic.Keys.CopyTo(keys, 0);
foreach (string key in keys)
{
IViewContent vc = WorkbenchSingleton.Workbench.ViewContentDic[key];
PropertyInfo p = vc.GetType().GetProperty("MCPurview");
bool isControlPruview = false;
if (bool.TryParse(p.GetValue(vc, null).ToString(), out isControlPruview))
{
if (isControlPruview == true) //需要权限控制
{
//if (!purviewList.Contains(key))
//{
//}
WorkbenchSingleton.Workbench.CloseViewByKey(key, true); //因为需要重新设定画面上按钮的权限,因此正真关闭
}
}
}
//WorkbenchSingleton.Workbench.CloseAllViews(false); //隐藏所有视图面板
//Mesnac.Gui.Common.RunEngine.Instance.CloseAllForms();
AppConfigHandler.Instance.InitCustomerMenuAndToolStrip(WorkbenchSingleton.Workbench.TopMenu, WorkbenchSingleton.Workbench.ToolStrip); //初始化自定义系统菜单和工具栏
}
}
}