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 { /// /// 设置默认权限项 /// 创建人:郑立兵 /// 创建时间:2014-6-07 /// 说明:实现勾选不受权限控制的有节点项 /// public class SetDefaultPurviewAction : DatabaseAction, IAction { public void Run(RuntimeParameter runtime) { base.RunIni(runtime); ICSharpCode.Core.LoggingService.Debug("设置默认权限"); DbMCControl basRolePurviewControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "BasRolePermission").FirstOrDefault(); if (basRolePurviewControl == null || !basRolePurviewControl.BaseControl.GetType().IsSubclassOf(typeof(TreeView))) { ICSharpCode.Core.LoggingService.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.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.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; } } } } } }