123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using EMIS.Entities;
- using System.Text;
- namespace EMIS.Web
- {
- public partial class TS : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnAddControlButton_Click(object sender, EventArgs e)
- {
- var dic = new Dictionary<string, Sys_ContextMenu>();
- dic.Add("Refresh", new Sys_ContextMenu { FormClass = "List", Title = "刷新", IsNeedPrivilege = true, IconName = "icon-reload", SeqNo = -1, RecordStatus = 1 });
- dic.Add("Ensure", new Sys_ContextMenu { FormClass = "Refresh", Title = "确定", IsNeedPrivilege = false, IconName = "icon-ok", SeqNo = 1, RecordStatus = 1 });
- dic.Add("Add", new Sys_ContextMenu { FormClass = "List", Title = "新增", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 1, RecordStatus = 1 });
- dic.Add("Delete", new Sys_ContextMenu { FormClass = "List", Title = "删除", IsNeedPrivilege = true, IconName = "icon-remove", SeqNo = 2, RecordStatus = 1 });
- dic.Add("Update", new Sys_ContextMenu { FormClass = "List", Title = "修改", IsNeedPrivilege = true, IconName = "icon-edit", SeqNo = 3, RecordStatus = 1 });
- dic.Add("BatchUpdate", new Sys_ContextMenu { FormClass = "List", Title = "批量修改", IsNeedPrivilege = true, IconName = "icon-edit", SeqNo = 3, RecordStatus = 1 });
- dic.Add("EditImport", new Sys_ContextMenu { FormClass = "Import", Title = "导入", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 4, RecordStatus = 1 });
- dic.Add("Save", new Sys_ContextMenu { FormClass = "Edit", Title = "保存", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 4, RecordStatus = 1 });
- dic.Add("Approved", new Sys_ContextMenu { FormClass = "Edit", Title = "通过", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 5, RecordStatus = 1 });
- dic.Add("Rejected", new Sys_ContextMenu { FormClass = "Edit", Title = "驳回", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 6, RecordStatus = 1 });
- dic.Add("Submit", new Sys_ContextMenu { FormClass = "List", Title = "提交", IsNeedPrivilege = true, IconName = "icon-ok", SeqNo = 5, RecordStatus = 1 });
- dic.Add("AddApply", new Sys_ContextMenu { FormClass = "List", Title = "添加申请", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 6, RecordStatus = 1 });
- dic.Add("SubmitApply", new Sys_ContextMenu { FormClass = "List", Title = "提交申请", IsNeedPrivilege = true, IconName = "icon-ok", SeqNo = 7, RecordStatus = 1 });
- dic.Add("CancelApply", new Sys_ContextMenu { FormClass = "List", Title = "取消申请", IsNeedPrivilege = true, IconName = "icon-remove", SeqNo = 8, RecordStatus = 1 });
- dic.Add("Approve", new Sys_ContextMenu { FormClass = "List", Title = "审核", IsNeedPrivilege = true, IconName = "icon-add", SeqNo = 9, RecordStatus = 1 });
- dic.Add("Edit_Submit", new Sys_ContextMenu { FormClass = "Edit", Title = "提交", IsNeedPrivilege = false, IconName = "icon-save", SeqNo = 10, RecordStatus = 1 });
- dic.Add("Import", new Sys_ContextMenu { FormClass = "List", Title = "Excel导入", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1001, RecordStatus = 1 });
- dic.Add("PicImport", new Sys_ContextMenu { FormClass = "List", Title = "照片导入", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1001, RecordStatus = 1 });
- dic.Add("Export", new Sys_ContextMenu { FormClass = "List", Title = "Excel导出", IsNeedPrivilege = true, IconName = "icon-print", SeqNo = 1002, RecordStatus = 1 });
- dic.Add("ImportSave", new Sys_ContextMenu { FormClass = "Import", Title = "保存", IsNeedPrivilege = true, IconName = "icon-save", SeqNo = 1003, RecordStatus = 1 });
- var menuNo = txtMenuNo.Text;
- if (string.IsNullOrWhiteSpace(menuNo))
- {
- txtResult.Text = "MenuNo 不能为空!";
- return;
- }
- var db = new EMISNewContext();
- var menu = db.Sys_Menu.FirstOrDefault(w => w.MenuNo == menuNo);
- if (menu == null)
- {
- txtResult.Text = "MenuNo[" + menuNo + "]没找到记录!";
- return;
- }
- var code = menu.FunctionCode.Substring(menu.FunctionCode.LastIndexOf('_') + 1);
- //var code = menu.FunctionCode;
- foreach (var key in dic.Keys)
- {
- var chk = FindControl("chk" + key) as CheckBox;
- if (chk != null && chk.Checked)
- {
- var entity = dic[key];
- var postfix = key;
- switch (key)
- {
- case "BatchUpdate":
- AutoCompleteData(menuNo, menu, code, entity, postfix, db, "SystemBatchModifyControl.showBatchModifydiv()");
- break;
- default:
- AutoCompleteData(menuNo, menu, code, entity, postfix, db);
- break;
- }
- }
- }
- db.SaveChanges();
- txtResult.Text = "添加成功";
- }
- private static void AutoCompleteData(string menuNo, Sys_Menu menu, string code, Sys_ContextMenu entity, string postfix, EMISNewContext db, string scripts = null)
- {
- entity.ContextMnuNo = menuNo + "_" + postfix;
- entity.MenuNo = menuNo;
- if (string.IsNullOrEmpty(scripts))
- {
- entity.Scripts = code + "_" + postfix + "()";
- }
- else
- {
- entity.Scripts = scripts;
- }
- entity.FunctionCode = menu.FunctionCode + "_" + postfix;
- var function = db.Sys_FunctionCode.FirstOrDefault(w => w.FunctionCode == entity.FunctionCode);
- if (function == null)
- {
- function = new Sys_FunctionCode
- {
- FunctionCode = entity.FunctionCode,
- OrderNo = (short)entity.SeqNo,
- FunctionName = entity.Title,
- ParentFunctionCode = menu.FunctionCode
- };
- var systemRole = db.Sys_Role.Single(w => w.RoleName == "超级用户");
- function.Sys_Role = new HashSet<Sys_Role> { systemRole };
- }
- entity.Sys_FunctionCode = function;
- db.Sys_ContextMenu.Add(entity);
- }
- protected void btnAddMenu_Click(object sender, EventArgs e)
- {
- var functionCode = txtMenuFunctionCode.Text;
- if (string.IsNullOrWhiteSpace(functionCode))
- {
- txtResult.Text = "functionCode 不能为空!";
- return;
- }
- var menuNo = txtAddMenuNo.Text;
- if (string.IsNullOrWhiteSpace(menuNo))
- {
- txtResult.Text = "menuNo 不能为空!";
- return;
- }
- var menuName = txtAddMenuName.Text;
- if (string.IsNullOrWhiteSpace(menuName))
- {
- txtResult.Text = "menuName 不能为空!";
- return;
- }
- functionCode = functionCode.Trim();
- menuNo = menuNo.Trim();
- menuName = menuName.Trim();
- var db = new EMISNewContext();
- var menu = new Sys_Menu();
- var function = new Sys_FunctionCode();
- var parentMenuNo = txtParentMenuNo.Text;
- Sys_Menu parentMenu = null;
- if (!string.IsNullOrWhiteSpace(parentMenuNo))
- {
- parentMenuNo = parentMenuNo.Trim();
- parentMenu = db.Sys_Menu.FirstOrDefault(w => w.MenuNo == parentMenuNo);
- if (parentMenu == null)
- {
- txtResult.Text = parentMenuNo + " 找不到对应的菜单!";
- return;
- }
- var count = db.Sys_Menu.Count(w => w.ParentMenuNo == parentMenuNo);
- function.ParentFunctionCode = parentMenu.FunctionCode;
- function.OrderNo = (short)(count + 1);
- menu.ParentMenuNo = parentMenuNo;
- menu.OrderNo = (short)(count + 1);
- }
- menu.MenuNo = menuNo;
- menu.MenuName = menuName;
- menu.Description = menuName;
- menu.FunctionCode = functionCode;
- menu.IsTopMenu = false;
- menu.IsVisible = true;
- var url = txtAddMenuUrl.Text.Trim();
- if (string.IsNullOrEmpty(url))
- {
- menu.IsLeaf = false;
- }
- else
- {
- menu.IsLeaf = true;
- menu.Url = url;
- }
- menu.RecordStatus = 1;
- db.Sys_Menu.Add(menu);
- function.FunctionCode = functionCode;
- function.FunctionName = menuName;
- var systemRole = db.Sys_Role.Single(w => w.RoleName == "系统超级管理员");
- function.Sys_Role = new HashSet<Sys_Role> { systemRole };
- db.Sys_FunctionCode.Add(function);
- db.SaveChanges();
- txtResult.Text = "添加菜单成功";
- }
- }
- }
|