protected void btnSave_ServerClick(object sender, EventArgs e) { string strModuleName = txt_Name.Value.Trim(); string strKey = txt_Key.Value.Trim(); string strController = txt_Controller.Value.Trim(); string strDescription = txt_Description.Text.Trim(); if ("" == strModuleName || "" == strKey || "" == strController) return; if (nId <= 0 && SystemModule.Exist(strKey)) { PageUtil.PageAlert(this.Page, "该模块Key已存在!"); return; } SystemModule addItem = SystemModule.Get(nId); if (null == addItem) { addItem = new SystemModule(); addItem.Key = strKey; } addItem.Name = strModuleName; addItem.Controller = strController; addItem.Description = strDescription; int nNewId = SystemModule.Save(addItem); if (nNewId <= 0) return; PageUtil.PageAlert(this.Page, "保存成功!"); }
private void _BindData() { SystemModule oModule = new SystemModule(); PagerNavication.RecordsCount = EntityAccess<SystemModule>.Access.Count(); SystemModule[] al = SystemModule.List("", "", PagerNavication.PageIndex, PagerNavication.PageSize); rptItems.DataSource = al; rptItems.DataBind(); }
public static int Save(SystemModule _Entity) { int result; if (null == _Entity) { result = -1; } else { int nModuleId = EntityAccess<SystemModule>.Access.Save(_Entity); if (nModuleId <= 0) { result = -1; } else { SystemFunction rootFn = SystemFunction.Get(_Entity.Key); if (null == rootFn) { rootFn = new SystemFunction(); rootFn.Key = _Entity.Key; rootFn.ModuleId = nModuleId; rootFn.Level = 1; rootFn.ParentId = -1; } rootFn.Name = _Entity.Name; rootFn.IconName = _Entity.IconName; rootFn.Description = _Entity.Description; rootFn.OrderId = _Entity.OrderId; SystemFunction.Save(rootFn); result = nModuleId; } } return result; }
protected void btn_UpdateModule_Click(object sender, EventArgs e) { txt_UpdateResult.Value = ""; string strConfigFullName = file_ModuleConfig.Value; if (string.IsNullOrEmpty(strConfigFullName)) { _setMessage("请先选择模块配置文件!", true); return; } string strFileName = System.IO.Path.GetFileName(strConfigFullName); string strFileEx = strFileName.Substring(strFileName.IndexOf(".")); if (strFileEx != ".cfg.xml") { _setMessage("请上传文件后缀名称为“.cfg.xml”的配置文件!", true); return; } string strUploadPath = string.Format("{0}\\{1}", Server.MapPath(SystemUtil.GetVirtualSysUploadPath()), strFileName); try { file_ModuleConfig.PostedFile.SaveAs(strUploadPath); _setMessage("上传配置文件成功!", true); } catch (Exception ee) { _setMessage("上传配置文件失败!", true); _setMessage("程序终止!", true); return; } XmlDocument xmlModuleConfig = new XmlDocument(); try { xmlModuleConfig.Load(strUploadPath); _setMessage("读取配置文件成功!", true); } catch (Exception ee) { _setMessage("读取配置文件失败!", true); _setMessage("程序终止!", true); return; } //模块配置文件有效性验证 if (!_vModuleConfig(xmlModuleConfig)) return; XmlNode moduleNode = xmlModuleConfig.SelectSingleNode("Module"); //if (!_vModuleNode(moduleNode)) // return; Hashtable htFns = new Hashtable(); //该模块下的所有功能 //配置模块基本信息 string strModuleKey = _GetChildNodeText(moduleNode, "Key"); SystemModule oModuleExist = SystemModule.Get(strModuleKey); bool bModuleAdd = null == oModuleExist; if (bModuleAdd) { oModuleExist = new SystemModule(); oModuleExist.Key = strModuleKey; } oModuleExist.Name = _GetChildNodeText(moduleNode, "Name"); oModuleExist.Description = _GetChildNodeText(moduleNode, "Description"); oModuleExist.Controller = _GetChildNodeText(moduleNode, "Controller"); oModuleExist.IconName = _GetChildNodeText(moduleNode, "IconName"); oModuleExist.OrderId = TypeUtil.ParseInt(_GetChildNodeText(moduleNode, "OrderId"), 1); int nModuleId = SystemModule.Save(oModuleExist); _setMessage("模块信息保存" + (nModuleId <= 0 ? "失败!" : "成功!"), true); if(nModuleId <= 0) return; //检测模块功能根节点是否自动新增 SystemFunction rootFn = SystemFunction.Get(strModuleKey); if (null == rootFn) { _setMessage(string.Format("模块根节点不存在!"), true); return; } //配置模块功能信息 XmlNodeList nlFnsRoot = moduleNode.SelectNodes("Functions/Function"); foreach (XmlNode nodeRootFn in nlFnsRoot) { //if (!_vFnNode(nodeRootFn)) // return; string strFnKey = _GetChildNodeText(nodeRootFn, "Key"); SystemFunction oFnExist = SystemFunction.Get(strFnKey); bool bFnAdd = null == oFnExist; if (bFnAdd) { oFnExist = new SystemFunction(); oFnExist.Key = strFnKey; oFnExist.Level = 2; } oFnExist.ParentId = rootFn.Id; oFnExist.ModuleId = nModuleId; oFnExist.Name = _GetChildNodeText(nodeRootFn, "Name"); oFnExist.Description = _GetChildNodeText(nodeRootFn, "Description"); oFnExist.IconName = _GetChildNodeText(nodeRootFn, "IconName"); oFnExist.OrderId = TypeUtil.ParseInt(_GetChildNodeText(nodeRootFn, "OrderId"), 1); int nFnId = SystemFunction.Save(oFnExist); if (nFnId <= 0) { _setMessage(string.Format("功能“{0}”信息保存失败!", oFnExist.Name), true); continue; } _setMessage(string.Format("功能“{0}”信息保存成功!", oFnExist.Name), true); if (!bModuleAdd) { htFns[strFnKey] = 1; } //功能Action信息保存 Hashtable htActions = new Hashtable(); XmlNodeList nlActions = nodeRootFn.SelectNodes("Actions/Action"); foreach (XmlNode nodeAction in nlActions) { //if (!_vActionNode(nodeAction)) // return; string strActionKey = _GetChildNodeText(nodeAction, "Key"); SystemAction oActionExist = SystemAction.Get(strActionKey); bool bActionAdd = null == oActionExist; if (bActionAdd) { oActionExist = new SystemAction(); oActionExist.Key = strActionKey; } oActionExist.FunctionId = nFnId; oActionExist.Name = _GetChildNodeText(nodeAction, "Name"); oActionExist.Description = _GetChildNodeText(nodeAction, "Description"); oActionExist.ActionType = _GetChildNodeText(nodeAction, "ActionType"); oActionExist.ActionValue = _GetChildNodeText(nodeAction, "ActionValue"); oActionExist.IsDefault = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsDefault"), 2); oActionExist.ControlName = _GetChildNodeText(nodeAction, "ControlName"); oActionExist.Tip = _GetChildNodeText(nodeAction, "Tip"); oActionExist.IconName = _GetChildNodeText(nodeAction, "IconName"); oActionExist.Target = _GetChildNodeText(nodeAction, "Target"); oActionExist.EntityCount = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "EntityCount"), 0); oActionExist.IsPopup = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsPopup"), 2); oActionExist.Width = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "Width"), 0); oActionExist.Height = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "Height"), 0); oActionExist.IsResize = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsResize"), 2); oActionExist.IsMove = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsMove"), 2); oActionExist.IsIncludeMinBox = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsIncludeMinBox"), 2); oActionExist.IsIncludeMaxBox = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsIncludeMaxBox"), 2); oActionExist.IsShowInTaskBar = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "IsShowInTaskBar"), 2); oActionExist.OrderId = TypeUtil.ParseInt(_GetChildNodeText(nodeAction, "OrderId"), 1); int nActionId = SystemAction.Save(oActionExist); if (nActionId <= 0) { _setMessage(string.Format("功能“{0}”的动作“{1}”信息保存失败!", oFnExist.Name, oActionExist.Name), true); continue; } if (!bFnAdd) { htActions[strActionKey] = 1; } } //删除该功能下的冗余操作(Action) if (!bFnAdd) { SystemAction[] alAtions = SystemAction.GetFunctionAction(nFnId); foreach (SystemAction action in alAtions) { if (!htActions.ContainsKey(action.Key)) SystemAction.Delete(action.Id); } _setMessage(string.Format("删除功能【{0}】冗余操作(Action)完成!", oFnExist.Name), true); } } ////删除该模块下的冗余功能(Function) if (!bModuleAdd) { SystemFunction moduleRootFn = SystemFunction.Get(strModuleKey); if(null == moduleRootFn) { _setMessage("删除模块冗余功能(Function)失败!", true); return; } SystemFunction[] alFns = SystemFunction.GetFunctions(moduleRootFn.Id, false); foreach (SystemFunction function in alFns) { if (!htFns.ContainsKey(function.Key)) SystemFunction.Delete(function.Id); } _setMessage("删除模块冗余功能(Function)成功!", true); } _setMessage("模块配置完成,请刷新浏览器!", true); }