PageRenderTime 15ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/ZXFramework_2/source/Tool/HF.Permission.UI/SetPowerFm.cs

#
C# | 288 lines | 244 code | 28 blank | 16 comment | 24 complexity | 0d12c019226e40bb422cc8ae1a96fc3a MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, Apache-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Data.SqlClient;
  8. using System.Windows.Forms;
  9. using HF.Framework;
  10. using HF.Framework.UI.BaseForms;
  11. using HF.Permission.Data;
  12. using HF.WorkFlow.Const;
  13. using HF.WorkFlow.DataContract;
  14. using HF.Framework.Windows;
  15. using HF.User.Data;
  16. namespace HF.Permission
  17. {
  18. public partial class fmSetPower : BaseForm_Single
  19. {
  20. string GroupId = "";
  21. string UserId = "";
  22. public fmSetPower(string iKey,string userId)
  23. {
  24. InitializeComponent();
  25. GroupId = iKey;
  26. UserId = userId;
  27. initPowerTree();
  28. }
  29. private void initPowerTree()
  30. {
  31. //列出所有权限
  32. HFTreeNode tmpBootNode = new HFTreeNode();
  33. tmpBootNode.NodeId = "#00";
  34. tmpBootNode.ImageIndex = 0;
  35. tmpBootNode.SelectedImageIndex = 0;
  36. tmpBootNode.NodeType = "#ALL";//表示模块
  37. tmpBootNode.Text = "已有权限";
  38. tmpBootNode.Description = "已有权限";
  39. tvPower.Nodes.Add(tmpBootNode);
  40. List<ModuleEntity> entitys = ModuleData.GetInstance().GetAllModuleEntitys();
  41. foreach (ModuleEntity entity in entitys)
  42. {
  43. HFTreeNode tmpNode = new HFTreeNode();
  44. tmpNode.NodeId = entity.ModuleId;
  45. tmpNode.ImageIndex = 2;
  46. tmpNode.SelectedImageIndex = 3;
  47. tmpNode.NodeType = "#MDL";//表示模块
  48. tmpNode.Text =entity.ModuleName;
  49. tmpNode.Description = entity.ModuleDes;
  50. tmpBootNode.Nodes.Add(tmpNode);
  51. }
  52. tvPower.ExpandAll();
  53. showSelModule();//列出拥有的权限
  54. tvSelectPower.ExpandAll();
  55. }
  56. /// <summary>
  57. /// 装载模块下的功能
  58. /// </summary>
  59. public void showFunction()
  60. {
  61. HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
  62. List<FunctionEntity> entitys = FunctionData.GetInstance().GetFunctionEntitysByModule(tmpNowNode.NodeId);
  63. tmpNowNode.Nodes.Clear();
  64. foreach (FunctionEntity entity in entitys)
  65. {
  66. HFTreeNode tmpNode = new HFTreeNode();
  67. tmpNode.NodeId =entity.FunctionId;
  68. tmpNode.ImageIndex = 2;
  69. tmpNode.SelectedImageIndex = 3;
  70. tmpNode.NodeType = "#FUN";//表示功能
  71. tmpNode.Text = entity.FunctionName;
  72. tmpNowNode.Nodes.Add(tmpNode);
  73. }
  74. }
  75. /// <summary>
  76. /// 装载功能下的操作
  77. /// </summary>
  78. public void showOperation()
  79. {
  80. HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
  81. List<OperationEntity> entitys = OperationData.GetInstance().GetOperationEntitysByFunction(tmpNowNode.NodeId);
  82. tmpNowNode.Nodes.Clear();
  83. foreach (OperationEntity entity in entitys)
  84. {
  85. HFTreeNode tmpNode = new HFTreeNode();
  86. tmpNode.NodeId =entity.OperationId;
  87. tmpNode.ImageIndex = 4;
  88. tmpNode.SelectedImageIndex = 5;
  89. tmpNode.NodeType = "#OPER";//表示操作
  90. tmpNode.Text =entity.OperationName;
  91. tmpNowNode.Nodes.Add(tmpNode);
  92. }
  93. }
  94. public void showSelModule()
  95. {
  96. //列出拥有的权限
  97. tvSelectPower.Nodes.Clear();
  98. List<ModuleEntity> mdlEntitys = ModuleData.GetInstance().GetPowerModuleEntitys(GroupId);
  99. HFTreeNode tmpselBootNode = new HFTreeNode();
  100. tmpselBootNode.NodeId = "#00";
  101. tmpselBootNode.ImageIndex = 0;
  102. tmpselBootNode.SelectedImageIndex = 0;
  103. tmpselBootNode.NodeType = "#ALL";//表示模块
  104. tmpselBootNode.Text = "已有权限";
  105. tmpselBootNode.Description = "已有权限";
  106. tvSelectPower.Nodes.Add(tmpselBootNode);
  107. foreach (ModuleEntity entity in mdlEntitys)
  108. {
  109. HFTreeNode tmpNode = new HFTreeNode();
  110. tmpNode.NodeId =entity.ModuleId;
  111. tmpNode.ImageIndex = 2;
  112. tmpNode.SelectedImageIndex = 3;
  113. tmpNode.NodeType = "#MDL";//表示模块
  114. tmpNode.Text =entity.ModuleName;
  115. tmpNode.Description =entity.ModuleDes;
  116. tmpselBootNode.Nodes.Add(tmpNode);
  117. }
  118. }
  119. /// <summary>
  120. /// 装载已分配权限模块下的功能
  121. /// </summary>
  122. public void showSelFun()
  123. {
  124. HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
  125. List<FunctionEntity> funEntitys = FunctionData.GetInstance().GetPowerFunctionEntitys(tmpNowNode.NodeId, GroupId);
  126. tmpNowNode.Nodes.Clear();
  127. foreach (FunctionEntity entity in funEntitys)
  128. {
  129. HFTreeNode tmpNode = new HFTreeNode();
  130. tmpNode.NodeId = entity.FunctionId;
  131. tmpNode.ImageIndex = 2;
  132. tmpNode.SelectedImageIndex = 3;
  133. tmpNode.NodeType = "#FUN";//表示功能
  134. tmpNode.Text = entity.FunctionName;
  135. tmpNode.Description = entity.FunctionDes;
  136. tmpNowNode.Nodes.Add(tmpNode);
  137. }
  138. }
  139. /// <summary>
  140. /// 装载已分配权限功能下的操作
  141. /// </summary>
  142. public void showSelOper()
  143. {
  144. HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
  145. List<OperationEntity> oprEntitys = OperationData.GetInstance().GetPowerOperationEntitys(tmpNowNode.NodeId, GroupId);
  146. tmpNowNode.Nodes.Clear();
  147. foreach (OperationEntity entity in oprEntitys)
  148. {
  149. HFTreeNode tmpNode = new HFTreeNode();
  150. tmpNode.NodeId = entity.OperationId;
  151. tmpNode.ImageIndex = 4;
  152. tmpNode.SelectedImageIndex = 5;
  153. tmpNode.NodeType = "#OPER";//表示操作
  154. tmpNode.Text = entity.OperationName;
  155. tmpNode.Description = entity.OperationDes;
  156. tmpNowNode.Nodes.Add(tmpNode);
  157. }
  158. }
  159. private void btnSave_Click(object sender, EventArgs e)
  160. {
  161. this.Close();
  162. }
  163. private void tvPower_AfterSelect(object sender, TreeViewEventArgs e)
  164. {
  165. if (tvPower.SelectedNode == null) return;
  166. HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
  167. lbPowerDes.Text = tmpNowNode.Description;
  168. if (tmpNowNode.NodeType == "#MDL")
  169. {
  170. showFunction();
  171. }
  172. else
  173. if (tmpNowNode.NodeType == "#FUN")
  174. {
  175. showOperation();
  176. }
  177. }
  178. private void tvSelectPower_AfterSelect(object sender, TreeViewEventArgs e)
  179. {
  180. if (tvSelectPower.SelectedNode == null) return;
  181. HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
  182. if (tmpNowNode.NodeType == "#00")
  183. {
  184. showSelModule();
  185. }
  186. else
  187. if (tmpNowNode.NodeType == "#MDL")
  188. {
  189. showSelFun();
  190. }
  191. else
  192. if (tmpNowNode.NodeType == "#FUN")
  193. {
  194. showSelOper();
  195. }
  196. }
  197. private bool PowerExists()
  198. {
  199. if (tvPower.SelectedNode == null) return false;
  200. HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
  201. return PurviewData.GetInstance().IsPowerExistInGroup(tmpNowNode.NodeId, GroupId);
  202. }
  203. private void btnAddPower_Click(object sender, EventArgs e)
  204. {
  205. if (tvPower.SelectedNode == null) return;
  206. HFTreeNode tmpNowNode = (HFTreeNode)tvPower.SelectedNode;
  207. if (PowerExists())
  208. {
  209. WorkDialog.WarningDlg("该权限已经存在,不能再添加,请分别添加下级权限!","提示");
  210. return;
  211. }
  212. if (tvSelectPower.Nodes.Count < 1)
  213. {
  214. HFTreeNode tmpselBootNode = new HFTreeNode();
  215. tmpselBootNode.NodeId = "#00";
  216. tmpselBootNode.ImageIndex = 0;
  217. tmpselBootNode.SelectedImageIndex =0;
  218. tmpselBootNode.NodeType = "#ALL";//表示模块
  219. tmpselBootNode.Text = "已有权限";
  220. tmpselBootNode.Description = "已有权限";
  221. tvSelectPower.Nodes.Add(tmpselBootNode);
  222. }
  223. PurviewData.GetInstance().SetPowerToGroup(tmpNowNode.NodeId, GroupId);
  224. showSelModule();
  225. tvSelectPower.ExpandAll();
  226. }
  227. private void btnDelete_Click(object sender, EventArgs e)
  228. {
  229. if (tvSelectPower.SelectedNode == null) return;
  230. HFTreeNode tmpNowNode = (HFTreeNode)tvSelectPower.SelectedNode;
  231. if (WorkDialog.QuestionDlg("是否删除权限 " + tmpNowNode.Text + " ,删除后不能恢复?", "询问") == DialogResult.Yes)
  232. {
  233. PurviewData.GetInstance().RemovePowerFromGroup(tmpNowNode.NodeId, GroupId);
  234. tvSelectPower.Nodes.Remove(tmpNowNode);
  235. }
  236. }
  237. private void initImage()
  238. {
  239. //imgListSmall
  240. this.imgListSmall.Images.Clear();
  241. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_UserS);
  242. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_GroupS);
  243. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_FolderCloseS);
  244. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_FolderOpenS);
  245. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_OperationS);
  246. this.imgListSmall.Images.Add(HF.Resources.Properties.Resources.HF_SelOperationS);
  247. //formicon
  248. this.Icon = HF.Resources.Properties.Resources.HF_AppMainIcon;
  249. }
  250. private void fmSetPower_Load(object sender, EventArgs e)
  251. {
  252. WinFormFun.ControlEnable(this, UserId);
  253. initImage();
  254. }
  255. private void btnClose_Click(object sender, EventArgs e)
  256. {
  257. Close();
  258. }
  259. }
  260. }