TS.aspx.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using EMIS.Entities;
  8. using System.Text;
  9. namespace EMIS.Web
  10. {
  11. public partial class TS : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. }
  16. protected void btnAddControlButton_Click(object sender, EventArgs e)
  17. {
  18. var dic = new Dictionary<string, Sys_ContextMenu>();
  19. dic.Add("Refresh", new Sys_ContextMenu { FormClass = "List", Title = "刷新", IsNeedPrivilege = true, IconName = "icon-reload", SeqNo = -1, RecordStatus = 1 });
  20. dic.Add("Ensure", new Sys_ContextMenu { FormClass = "Refresh", Title = "确定", IsNeedPrivilege = false, IconName = "icon-ok", SeqNo = 1, RecordStatus = 1 });
  21. dic.Add("Add", new Sys_ContextMenu { FormClass = "List", Title = "新增", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 1, RecordStatus = 1 });
  22. dic.Add("Delete", new Sys_ContextMenu { FormClass = "List", Title = "删除", IsNeedPrivilege = true, IconName = "icon-remove", SeqNo = 2, RecordStatus = 1 });
  23. dic.Add("Update", new Sys_ContextMenu { FormClass = "List", Title = "修改", IsNeedPrivilege = true, IconName = "icon-edit", SeqNo = 3, RecordStatus = 1 });
  24. dic.Add("BatchUpdate", new Sys_ContextMenu { FormClass = "List", Title = "批量修改", IsNeedPrivilege = true, IconName = "icon-edit", SeqNo = 3, RecordStatus = 1 });
  25. dic.Add("EditImport", new Sys_ContextMenu { FormClass = "Import", Title = "导入", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 4, RecordStatus = 1 });
  26. dic.Add("Save", new Sys_ContextMenu { FormClass = "Edit", Title = "保存", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 4, RecordStatus = 1 });
  27. dic.Add("Approved", new Sys_ContextMenu { FormClass = "Edit", Title = "通过", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 5, RecordStatus = 1 });
  28. dic.Add("Rejected", new Sys_ContextMenu { FormClass = "Edit", Title = "驳回", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 6, RecordStatus = 1 });
  29. dic.Add("Submit", new Sys_ContextMenu { FormClass = "List", Title = "提交", IsNeedPrivilege = true, IconName = "icon-ok", SeqNo = 5, RecordStatus = 1 });
  30. dic.Add("AddApply", new Sys_ContextMenu { FormClass = "List", Title = "添加申请", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 6, RecordStatus = 1 });
  31. dic.Add("SubmitApply", new Sys_ContextMenu { FormClass = "List", Title = "提交申请", IsNeedPrivilege = true, IconName = "icon-ok", SeqNo = 7, RecordStatus = 1 });
  32. dic.Add("CancelApply", new Sys_ContextMenu { FormClass = "List", Title = "取消申请", IsNeedPrivilege = true, IconName = "icon-remove", SeqNo = 8, RecordStatus = 1 });
  33. dic.Add("Approve", new Sys_ContextMenu { FormClass = "List", Title = "审核", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 9, RecordStatus = 1 });
  34. dic.Add("Edit_Submit", new Sys_ContextMenu { FormClass = "Edit", Title = "提交", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 10, RecordStatus = 1 });
  35. dic.Add("Import", new Sys_ContextMenu { FormClass = "List", Title = "Excel导入", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1001, RecordStatus = 1 });
  36. dic.Add("PicImport", new Sys_ContextMenu { FormClass = "List", Title = "照片导入", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1001, RecordStatus = 1 });
  37. dic.Add("Export", new Sys_ContextMenu { FormClass = "List", Title = "Excel导出", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1002, RecordStatus = 1 });
  38. dic.Add("ImportSave", new Sys_ContextMenu { FormClass = "Import", Title = "保存", IsNeedPrivilege = true, IconName = "icon-save", SeqNo = 1003, RecordStatus = 1 });
  39. var menuNo = txtMenuNo.Text;
  40. if (string.IsNullOrWhiteSpace(menuNo))
  41. {
  42. txtResult.Text = "MenuNo 不能为空!";
  43. return;
  44. }
  45. var db = new EMISNewContext();
  46. var menu = db.Sys_Menu.FirstOrDefault(w => w.MenuNo == menuNo);
  47. if (menu == null)
  48. {
  49. txtResult.Text = "MenuNo[" + menuNo + "]没找到记录!";
  50. return;
  51. }
  52. var code = menu.FunctionCode.Substring(menu.FunctionCode.LastIndexOf('_') + 1);
  53. //var code = menu.FunctionCode;
  54. foreach (var key in dic.Keys)
  55. {
  56. var chk = FindControl("chk" + key) as CheckBox;
  57. if (chk != null && chk.Checked)
  58. {
  59. var entity = dic[key];
  60. var postfix = key;
  61. switch (key)
  62. {
  63. case "BatchUpdate":
  64. AutoCompleteData(menuNo, menu, code, entity, postfix, db, "SystemBatchModifyControl.showBatchModifydiv()");
  65. break;
  66. default:
  67. AutoCompleteData(menuNo, menu, code, entity, postfix, db);
  68. break;
  69. }
  70. }
  71. }
  72. db.SaveChanges();
  73. txtResult.Text = "添加成功";
  74. }
  75. private static void AutoCompleteData(string menuNo, Sys_Menu menu, string code, Sys_ContextMenu entity, string postfix, EMISNewContext db, string scripts = null)
  76. {
  77. entity.ContextMnuNo = menuNo + "_" + postfix;
  78. entity.MenuNo = menuNo;
  79. if (string.IsNullOrEmpty(scripts))
  80. {
  81. entity.Scripts = code + "_" + postfix + "()";
  82. }
  83. else
  84. {
  85. entity.Scripts = scripts;
  86. }
  87. entity.FunctionCode = menu.FunctionCode + "_" + postfix;
  88. var function = db.Sys_FunctionCode.FirstOrDefault(w => w.FunctionCode == entity.FunctionCode);
  89. if (function == null)
  90. {
  91. function = new Sys_FunctionCode
  92. {
  93. FunctionCode = entity.FunctionCode,
  94. OrderNo = (short)entity.SeqNo,
  95. FunctionName = entity.Title,
  96. ParentFunctionCode = menu.FunctionCode
  97. };
  98. var systemRole = db.Sys_Role.Single(w => w.RoleName == "超级用户");
  99. function.Sys_Role = new HashSet<Sys_Role> { systemRole };
  100. }
  101. entity.Sys_FunctionCode = function;
  102. db.Sys_ContextMenu.Add(entity);
  103. }
  104. protected void btnAddMenu_Click(object sender, EventArgs e)
  105. {
  106. var functionCode = txtMenuFunctionCode.Text;
  107. if (string.IsNullOrWhiteSpace(functionCode))
  108. {
  109. txtResult.Text = "functionCode 不能为空!";
  110. return;
  111. }
  112. var menuNo = txtAddMenuNo.Text;
  113. if (string.IsNullOrWhiteSpace(menuNo))
  114. {
  115. txtResult.Text = "menuNo 不能为空!";
  116. return;
  117. }
  118. var menuName = txtAddMenuName.Text;
  119. if (string.IsNullOrWhiteSpace(menuName))
  120. {
  121. txtResult.Text = "menuName 不能为空!";
  122. return;
  123. }
  124. functionCode = functionCode.Trim();
  125. menuNo = menuNo.Trim();
  126. menuName = menuName.Trim();
  127. var db = new EMISNewContext();
  128. var menu = new Sys_Menu();
  129. var function = new Sys_FunctionCode();
  130. var parentMenuNo = txtParentMenuNo.Text;
  131. Sys_Menu parentMenu = null;
  132. if (!string.IsNullOrWhiteSpace(parentMenuNo))
  133. {
  134. parentMenuNo = parentMenuNo.Trim();
  135. parentMenu = db.Sys_Menu.FirstOrDefault(w => w.MenuNo == parentMenuNo);
  136. if (parentMenu == null)
  137. {
  138. txtResult.Text = parentMenuNo + " 找不到对应的菜单!";
  139. return;
  140. }
  141. var count = db.Sys_Menu.Count(w => w.ParentMenuNo == parentMenuNo);
  142. function.ParentFunctionCode = parentMenu.FunctionCode;
  143. function.OrderNo = (short)(count + 1);
  144. menu.ParentMenuNo = parentMenuNo;
  145. menu.OrderNo = (short)(count + 1);
  146. }
  147. menu.MenuNo = menuNo;
  148. menu.MenuName = menuName;
  149. menu.Description = menuName;
  150. menu.FunctionCode = functionCode;
  151. menu.IsTopMenu = false;
  152. menu.IsVisible = true;
  153. var url = txtAddMenuUrl.Text.Trim();
  154. if (string.IsNullOrEmpty(url))
  155. {
  156. menu.IsLeaf = false;
  157. }
  158. else
  159. {
  160. menu.IsLeaf = true;
  161. menu.Url = url;
  162. }
  163. menu.RecordStatus = 1;
  164. db.Sys_Menu.Add(menu);
  165. function.FunctionCode = functionCode;
  166. function.FunctionName = menuName;
  167. var systemRole = db.Sys_Role.Single(w => w.RoleName == "系统超级管理员");
  168. function.Sys_Role = new HashSet<Sys_Role> { systemRole };
  169. db.Sys_FunctionCode.Add(function);
  170. db.SaveChanges();
  171. txtResult.Text = "添加菜单成功";
  172. }
  173. }
  174. }