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.

106 lines
3.6 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.Linq;
using System.Text;
using Mesnac.Action.Base;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using Mesnac.Basic;
using Mesnac.Codd.Session;
using System.Data;
namespace Mesnac.Action.Default.Purview
{
/// <summary>
/// 设置默认权限项
/// 创建人:郑立兵
/// 创建时间2014-6-07
/// 说明:实现勾选不受权限控制的有节点项
/// </summary>
public class SetDefaultPurviewAction : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
ICSharpCode.Core.LoggingService<SetDefaultPurviewAction>.Debug("设置默认权限");
DbMCControl basRolePurviewControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasRolePermission").FirstOrDefault();
if (basRolePurviewControl == null || !basRolePurviewControl.BaseControl.GetType().IsSubclassOf(typeof(TreeView)))
{
ICSharpCode.Core.LoggingService<SetDefaultPurviewAction>.Warn("权限树初始化勾选 缺少权限树形控件...");
return;
}
TreeView tv = basRolePurviewControl.BaseControl as TreeView;
if (tv != null)
{
try
{
DbHelper dbhelper = NewDbHelper(basRolePurviewControl.DesignSource);
if (dbhelper == null)
{
return;
}
dbhelper.ClearParameter();
dbhelper.CommandType = CommandType.Text;
dbhelper.CommandText = "SELECT * FROM BasDefaultPermission";
DataTable dt = dbhelper.ToDataTable();
if (dt == null)
{
ICSharpCode.Core.LoggingService<SetDefaultPurviewAction>.Warn("默认权限为null...");
return;
}
ClearTreeNodes(tv.Nodes);
foreach (DataRow dr in dt.Rows)
{
CheckTreeNode(tv.Nodes, dr["PermissionType"].ToString() + dr["PermissionItemGUID"].ToString());
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<SetDefaultPurviewAction>.Error("设置默认权限失败:" + ex.Message, ex);
runtime.IsReturn = true;
return;
}
}
}
private void ClearTreeNodes(TreeNodeCollection tnc)
{
foreach (TreeNode n in tnc)
{
n.Checked = false;
if (n.Nodes != null)
{
ClearTreeNodes(n.Nodes);
}
}
}
private void CheckTreeNode(TreeNodeCollection tnc, string NodeName)
{
foreach (TreeNode n in tnc)
{
if (n.Nodes != null && n.Nodes.Count > 0)
{
foreach (TreeNode childNode in n.Nodes)
{
if (childNode.Name == NodeName && childNode.Checked == false)
{
childNode.Checked = true;
}
}
}
else
{
if (n.Name == NodeName && n.Checked == false)
{
n.Checked = true;
}
}
}
}
}
}