/ZXFramework_2/source/Tool/HF.Permission.UI/SetPowerFm.cs
# · C# · 288 lines · 244 code · 28 blank · 16 comment · 24 complexity · 0d12c019226e40bb422cc8ae1a96fc3a MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Data.SqlClient;
- using System.Windows.Forms;
- using HF.Framework;
- using HF.Framework.UI.BaseForms;
- using HF.Permission.Data;
- using HF.WorkFlow.Const;
- using HF.WorkFlow.DataContract;
- using HF.Framework.Windows;
- using HF.User.Data;
-
- namespace HF.Permission
- {
- public partial class fmSetPower : BaseForm_Single
- {
- string GroupId = "";
- string UserId = "";
- public fmSetPower(string iKey,string userId)
- {
- InitializeComponent();
- GroupId = iKey;
- UserId = userId;
- initPowerTree();
- }
- private void initPowerTree()
- {
- //列出所有权限
-
- HFTreeNode tmpBootNode = new HFTreeNode();
- tmpBootNode.NodeId = "#00";
- tmpBootNode.ImageIndex = 0;
- tmpBootNode.SelectedImageIndex = 0;
- tmpBootNode.NodeType = "#ALL";//表示模块
- tmpBootNode.Text = "已有权限";
- tmpBootNode.Description = "已有权限";
- tvPower.Nodes.Add(tmpBootNode);
-
- List<ModuleEntity> entitys = ModuleData.GetInstance().GetAllModuleEntitys();
- foreach (ModuleEntity entity in entitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId = entity.ModuleId;
- tmpNode.ImageIndex = 2;
- tmpNode.SelectedImageIndex = 3;
- tmpNode.NodeType = "#MDL";//表示模块
- tmpNode.Text =entity.ModuleName;
- tmpNode.Description = entity.ModuleDes;
- tmpBootNode.Nodes.Add(tmpNode);
- }
- tvPower.ExpandAll();
- showSelModule();//列出拥有的权限
- tvSelectPower.ExpandAll();
-
-
- }
- /// <summary>
- /// 装载模块下的功能
- /// </summary>
- public void showFunction()
- {
- HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
- List<FunctionEntity> entitys = FunctionData.GetInstance().GetFunctionEntitysByModule(tmpNowNode.NodeId);
- tmpNowNode.Nodes.Clear();
- foreach (FunctionEntity entity in entitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId =entity.FunctionId;
- tmpNode.ImageIndex = 2;
- tmpNode.SelectedImageIndex = 3;
- tmpNode.NodeType = "#FUN";//表示功能
- tmpNode.Text = entity.FunctionName;
- tmpNowNode.Nodes.Add(tmpNode);
-
-
- }
- }
- /// <summary>
- /// 装载功能下的操作
- /// </summary>
- public void showOperation()
- {
- HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
- List<OperationEntity> entitys = OperationData.GetInstance().GetOperationEntitysByFunction(tmpNowNode.NodeId);
- tmpNowNode.Nodes.Clear();
- foreach (OperationEntity entity in entitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId =entity.OperationId;
- tmpNode.ImageIndex = 4;
- tmpNode.SelectedImageIndex = 5;
- tmpNode.NodeType = "#OPER";//表示操作
- tmpNode.Text =entity.OperationName;
- tmpNowNode.Nodes.Add(tmpNode);
-
-
- }
-
- }
- public void showSelModule()
- {
- //列出拥有的权限
- tvSelectPower.Nodes.Clear();
- List<ModuleEntity> mdlEntitys = ModuleData.GetInstance().GetPowerModuleEntitys(GroupId);
- HFTreeNode tmpselBootNode = new HFTreeNode();
- tmpselBootNode.NodeId = "#00";
- tmpselBootNode.ImageIndex = 0;
- tmpselBootNode.SelectedImageIndex = 0;
- tmpselBootNode.NodeType = "#ALL";//表示模块
- tmpselBootNode.Text = "已有权限";
- tmpselBootNode.Description = "已有权限";
- tvSelectPower.Nodes.Add(tmpselBootNode);
- foreach (ModuleEntity entity in mdlEntitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId =entity.ModuleId;
- tmpNode.ImageIndex = 2;
- tmpNode.SelectedImageIndex = 3;
- tmpNode.NodeType = "#MDL";//表示模块
- tmpNode.Text =entity.ModuleName;
- tmpNode.Description =entity.ModuleDes;
- tmpselBootNode.Nodes.Add(tmpNode);
- }
- }
- /// <summary>
- /// 装载已分配权限模块下的功能
- /// </summary>
- public void showSelFun()
- {
- HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
- List<FunctionEntity> funEntitys = FunctionData.GetInstance().GetPowerFunctionEntitys(tmpNowNode.NodeId, GroupId);
- tmpNowNode.Nodes.Clear();
- foreach (FunctionEntity entity in funEntitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId = entity.FunctionId;
- tmpNode.ImageIndex = 2;
- tmpNode.SelectedImageIndex = 3;
- tmpNode.NodeType = "#FUN";//表示功能
- tmpNode.Text = entity.FunctionName;
- tmpNode.Description = entity.FunctionDes;
- tmpNowNode.Nodes.Add(tmpNode);
- }
-
-
- }
- /// <summary>
- /// 装载已分配权限功能下的操作
- /// </summary>
- public void showSelOper()
- {
- HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
- List<OperationEntity> oprEntitys = OperationData.GetInstance().GetPowerOperationEntitys(tmpNowNode.NodeId, GroupId);
- tmpNowNode.Nodes.Clear();
- foreach (OperationEntity entity in oprEntitys)
- {
- HFTreeNode tmpNode = new HFTreeNode();
- tmpNode.NodeId = entity.OperationId;
- tmpNode.ImageIndex = 4;
- tmpNode.SelectedImageIndex = 5;
- tmpNode.NodeType = "#OPER";//表示操作
- tmpNode.Text = entity.OperationName;
- tmpNode.Description = entity.OperationDes;
- tmpNowNode.Nodes.Add(tmpNode);
-
-
- }
-
- }
-
- private void btnSave_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void tvPower_AfterSelect(object sender, TreeViewEventArgs e)
- {
- if (tvPower.SelectedNode == null) return;
- HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
- lbPowerDes.Text = tmpNowNode.Description;
- if (tmpNowNode.NodeType == "#MDL")
- {
- showFunction();
- }
- else
- if (tmpNowNode.NodeType == "#FUN")
- {
- showOperation();
- }
-
- }
-
- private void tvSelectPower_AfterSelect(object sender, TreeViewEventArgs e)
- {
- if (tvSelectPower.SelectedNode == null) return;
- HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
- if (tmpNowNode.NodeType == "#00")
- {
- showSelModule();
- }
- else
- if (tmpNowNode.NodeType == "#MDL")
- {
- showSelFun();
- }
- else
- if (tmpNowNode.NodeType == "#FUN")
- {
- showSelOper();
- }
- }
- private bool PowerExists()
- {
- if (tvPower.SelectedNode == null) return false;
- HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
- return PurviewData.GetInstance().IsPowerExistInGroup(tmpNowNode.NodeId, GroupId);
-
-
- }
- private void btnAddPower_Click(object sender, EventArgs e)
- {
- if (tvPower.SelectedNode == null) return;
- HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
- if (PowerExists())
- {
- WorkDialog.WarningDlg("该权限已经存在,不能再添加,请分别添加下级权限!","提示");
- return;
- }
- if (tvSelectPower.Nodes.Count < 1)
- {
- HFTreeNode tmpselBootNode = new HFTreeNode();
- tmpselBootNode.NodeId = "#00";
- tmpselBootNode.ImageIndex = 0;
- tmpselBootNode.SelectedImageIndex =0;
- tmpselBootNode.NodeType = "#ALL";//表示模块
- tmpselBootNode.Text = "已有权限";
- tmpselBootNode.Description = "已有权限";
- tvSelectPower.Nodes.Add(tmpselBootNode);
- }
- PurviewData.GetInstance().SetPowerToGroup(tmpNowNode.NodeId, GroupId);
- showSelModule();
- tvSelectPower.ExpandAll();
-
- }
-
- private void btnDelete_Click(object sender, EventArgs e)
- {
- if (tvSelectPower.SelectedNode == null) return;
- HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
- if (WorkDialog.QuestionDlg("是否删除权限 " + tmpNowNode.Text + " ,删除后不能恢复?", "询问") == DialogResult.Yes)
- {
- PurviewData.GetInstance().RemovePowerFromGroup(tmpNowNode.NodeId, GroupId);
- tvSelectPower.Nodes.Remove(tmpNowNode);
- }
-
-
- }
- private void initImage()
- {
- //imgListSmall
- this.imgListSmall.Images.Clear();
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_UserS);
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_GroupS);
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_FolderCloseS);
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_FolderOpenS);
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_OperationS);
- this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_SelOperationS);
-
- //formicon
- this.Icon = HF.Resources.Properties.Resources.HF_AppMainIcon;
- }
- private void fmSetPower_Load(object sender, EventArgs e)
- {
- WinFormFun.ControlEnable(this, UserId);
- initImage();
- }
-
- private void btnClose_Click(object sender, EventArgs e)
- {
- Close();
- }
- }
- }