/// <summary> /// 根据编号查找方法编辑对象 /// </summary> /// <param name="code">方法编号</param> public FunctionEditModel GetFunctionByCode(string functionCode) { try { FunctionEditModel roleEditModel = new FunctionEditModel(); Repository<SysFunction> sysFunctionDal = _unitOfWork.GetRepository<SysFunction>(); SysFunction sysFunction = sysFunctionDal.GetObjectByKey(functionCode).Entity; if (sysFunction != null) { roleEditModel.InitEditModel(sysFunction); } return roleEditModel; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
private void moduleCode_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.moduleCode.SelectedItems.Count == 0) { return; } this._sysFunction = (FunctionEditModel)this.moduleCode.SelectedItem; }
/// <summary> /// 根据 /// </summary> /// <param name="functionID"></param> /// <returns></returns> public static SelectResult <FunctionEditModel> GetFunctionByID(int functionID) { List <SqlParameter> paras = new List <SqlParameter>() { new SqlParameter("@ID", SqlDbType.Int), }; paras[0].Value = functionID; string sql = @"SELECT fun.ID , fun.FunctionName , fun.ActionID , fun.ParentID , fun.Description, fun.IsBackground, fun.OrderIndex, act.ControllerID , c.AreaID, fun.IsAppFeatures, fun.FeaturesCode,fun.IsAppHomeModule,fun.IsAppShortcutMenu FROM dbo.Functions fun LEFT JOIN dbo.Actions act ON fun.ActionID = act.ID LEFT JOIN dbo.Controllers c ON act.ControllerID = c.ID WHERE fun.ID = @ID"; List <FunctionEditModel> list = ConvertToList <FunctionEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras.ToArray())); FunctionEditModel data = null; string msg = string.Empty; if (list == null) { msg = PromptInformation.DBError; } else if (list.Count == 0) { msg = PromptInformation.NotExists; } else { data = list[0]; } return(new SelectResult <FunctionEditModel>() { DataResult = data, Message = msg }); }
public ActionResult EditFunctionInfo(FunctionEditModel model) { if (ModelState.IsValid) { var result = FunctionBLL.EditFunction(model, base.UserIDForLog); base.DoLog(OperationTypeEnum.Edit, result, "FunctionID:" + model.ID); return(Json(result)); } else { if (model.FunctionIsMenu) { var aList = AreaBLL.GetAreas(); model.AreasSelectList = new SelectList(aList, "ID", "AreaName"); var cList = ControllerBLL.GetControllersByAreaID(aList.First().ID); model.ControllersSelectList = new SelectList(cList, "ID", "ControllerName"); var actionList = ActionBLL.GetActionsByControllerID(cList.First().ID); model.ActionsSelectList = actionList.ToSelectList(m => GetSelectListItem(m.ID, m.ActionName)); var parentFuncList = FunctionBLL.GetFunctions(); model.ParentFunctionsSelectList = new SelectList(FunctionBLL.GetFunctions(model.ID), "ID", "FunctionName"); return(PartialView("_EditFunctionInfo", model)); } else { int areaID = model.AreaID.Value; int controllerID = model.ControllerID.Value; int?parentID = model.ParentID; int actionID = model.ActionID.Value; model.IsTopFunction = model.ParentID == null; model.AreasSelectList = new SelectList(AreaBLL.GetAreas(), "ID", "AreaName", areaID); model.ControllersSelectList = new SelectList(ControllerBLL.GetControllersByAreaID(areaID), "ID", "ControllerName", controllerID); model.ActionsSelectList = ActionBLL.GetActionsByControllerID(controllerID).ToSelectList(m => GetSelectListItem(m.ID, m.ActionName)); model.ParentFunctionsSelectList = new SelectList(FunctionBLL.GetFunctions(model.ID), "ID", "FunctionName"); return(PartialView("_EditFunctionInfo", model)); } } }
/// <summary> /// 添加方法 /// </summary> /// <param name="newFunction">需要添加的方法</param> public FunctionEditModel Add(FunctionEditModel newFunction) { try { if (CheckCodeExists(newFunction.FunctionCode)) { throw new FaultException<LCFault>(new LCFault("方法添加失败"), "该方法编号已存在,不能重复添加"); } Repository<SysFunction> sysFunctionEiditModelDal = _unitOfWork.GetRepository<SysFunction>(); SysFunction sysFunction = new SysFunction(); sysFunction.FunctionCode = newFunction.FunctionCode; sysFunction.Name = newFunction.Name; sysFunction.Remark = newFunction.Remark; sysFunction.Type = newFunction.Type; sysFunction.Assembly = newFunction.Assembly; sysFunction.ClassName = newFunction.ClassName; sysFunction.OperationCode = newFunction.OperationCode; sysFunction.OperationName = newFunction.OperationName; sysFunction.Params = newFunction.Params; sysFunction.ModuleCode = newFunction.ModuleCode; _unitOfWork.AddAction(sysFunction, DataActions.Add); _unitOfWork.Save(); return newFunction; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
/// <summary> /// 更新方法 /// </summary> /// <param name="newFunction">需要更新的方法</param> public FunctionEditModel Update(FunctionEditModel newFunction) { try { Repository<SysFunction> sysFunctionDal = _unitOfWork.GetRepository<SysFunction>(); SysFunction sysFunction = sysFunctionDal.GetObjectByKey(newFunction.FunctionCode).Entity; if (sysFunction != null) { sysFunction.FunctionCode = newFunction.FunctionCode; sysFunction.Name = newFunction.Name; sysFunction.Remark = newFunction.Remark; sysFunction.Type = newFunction.Type; sysFunction.Assembly = newFunction.Assembly; sysFunction.ClassName = newFunction.ClassName; sysFunction.OperationCode = newFunction.OperationCode; sysFunction.OperationName = newFunction.OperationName; sysFunction.Params = newFunction.Params; sysFunction.ModuleCode = newFunction.ModuleCode; //sysFunction.ParentModule = newFunction.Function.ParentModule; //sysFunction.SysMenus = newFunction.Function.SysMenus; } _unitOfWork.AddAction(sysFunction, DataActions.Update); _unitOfWork.Save(); return newFunction; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
/// <summary> /// 删除方法 /// </summary> /// <param name="deleteFunction">需要删除的方法对象</param> public bool Delete(FunctionEditModel deleteFunction) { try { return DeleteByCode(deleteFunction.FunctionCode); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
private async void DeleFun_Click(object sender, RoutedEventArgs e) { if (this.moduleList.SelectedItems.Count == 0) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "没有选择模块请选择!", MessageDialogStyle.Affirmative, null); return; } if (this.moduleList.SelectedItems.Count > 1) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "不能选择多个模块,请重新选择!", MessageDialogStyle.Affirmative, null); return; } if (this._sysFunction == null || this.moduleCode.SelectedItems.Count == 0) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "没有选择方法请选择!", MessageDialogStyle.Affirmative, null); return; } if (this.moduleCode.SelectedItems.Count > 1) { await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "不能选择多个方法,请重新选择!", MessageDialogStyle.Affirmative, null); return; } MessageDialogResult result = await DialogManager.ShowMessageAsync(this.GetMainWindow(), UIResources.MsgInfo, "确认删除所选的方法吗!", MessageDialogStyle.AffirmativeAndNegative, null); if (result == MessageDialogResult.Affirmative) { IAsyncProxy <IFunctionModelService> _functionAyncProxy = await Task.Run(() => ServiceHelper.GetFunctionService()); await _functionAyncProxy.CallAsync(c => c.DeleteByCode(_sysFunction.FunctionCode)); this._sysFunction = null; await bindModuleCode(); } }
private async void btnOK_Click(object sender, RoutedEventArgs e) { string strErrorMsg = string.Empty; try { FunctionEditModel sysFunction = new FunctionEditModel(); sysFunction.ModuleCode = this._moduleDisplayModel.Code; sysFunction.OperationCode = this.txtOperationCode.Text; sysFunction.OperationName = this.txtOperationName.Text; sysFunction.Assembly = this.txtAssembly.Text; sysFunction.ClassName = this.txtClassName.Text; sysFunction.FunctionCode = this.txtFunctionCode.Text; sysFunction.Name = this.txtFunctionName.Text; sysFunction.Params = this.txtParams.Text; sysFunction.Remark = this.txtRemark.Text; FunctionType functionType = (FunctionType)Enum.Parse(typeof(FunctionType), this.cmbFunctionType.Text); sysFunction.Type = functionType; _functionAyncProxy = await Task.Run(() => ServiceHelper.GetFunctionService()); if (Om == OperationMode.AddMode) { await _functionAyncProxy.CallAsync(c => c.Add(sysFunction)); this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "新增方法成功!"); //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "新增方法成功!", MessageDialogStyle.Affirmative, null); ; this.DialogResult = true; } if (Om == OperationMode.EditMode) { await _functionAyncProxy.CallAsync(c => c.Update(sysFunction)); this.ShowAutoCloseDialogOwter(UIResources.MsgInfo, "修改方法成功!"); //MessageDialogResult result = await DialogManager.ShowMessageAsync(this, UIResources.MsgInfo, "修改方法成功!", MessageDialogStyle.Affirmative, null); this.DialogResult = true; } } catch (TimeoutException timeProblem) { strErrorMsg = timeProblem.Message + UIResources.TimeOut + timeProblem.Message; } catch (FaultException <LCFault> af) { strErrorMsg = af.Detail.Message; } catch (FaultException unknownFault) { strErrorMsg = UIResources.UnKnowFault + unknownFault.Message; } catch (CommunicationException commProblem) { strErrorMsg = UIResources.ConProblem + commProblem.Message + commProblem.StackTrace; } catch (Exception ex) { strErrorMsg = ex.Message; } if (strErrorMsg != string.Empty) { AisinoMessageBox.Show(strErrorMsg); } }
/// <summary> /// 编辑功能信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static OperationResult EditFunction(FunctionEditModel model, int EditUserID) { List <SqlParameter> paras = new List <SqlParameter>() { new SqlParameter("@FunctionName", SqlDbType.NVarChar, 20), new SqlParameter("@ActionID", SqlDbType.Int), new SqlParameter("@IsBackground", SqlDbType.Bit), new SqlParameter("@ID", SqlDbType.Int), new SqlParameter("@ParentID", SqlDbType.Int), new SqlParameter("@Description", SqlDbType.NVarChar, 50), new SqlParameter("@OrderIndex", SqlDbType.Int), new SqlParameter("EditUserID", SqlDbType.Int), new SqlParameter("EditTime", SqlDbType.DateTime), new SqlParameter("IsAppFeatures", SqlDbType.Bit), new SqlParameter("FeaturesCode", SqlDbType.VarChar), new SqlParameter("IsAppHomeModule", SqlDbType.Bit), new SqlParameter("IsAppShortcutMenu", SqlDbType.Bit), }; paras[0].Value = model.FunctionName.Trim(); if (model.FunctionIsMenu) { paras[1].Value = DBNull.Value; } else { paras[1].Value = model.ActionID; } paras[2].Value = model.IsBackground; paras[3].Value = model.ID; if (model.IsTopFunction) { paras[4].Value = DBNull.Value; } else { paras[4].Value = model.ParentID; } if (string.IsNullOrWhiteSpace(model.Description)) { paras[5].Value = DBNull.Value; } else { paras[5].Value = model.Description; } paras[6].Value = model.OrderIndex; paras[7].Value = EditUserID; paras[8].Value = DateTime.Now; paras[9].Value = model.IsAppFeatures; if (string.IsNullOrWhiteSpace(model.FeaturesCode)) { paras[10].Value = DBNull.Value; } else { paras[10].Value = model.FeaturesCode.Trim(); } paras[11].Value = model.IsAppHomeModule; paras[12].Value = model.IsAppShortcutMenu; string sql = @"UPDATE dbo.Functions SET FunctionName = @FunctionName, ActionID = @ActionID, ParentID =@ParentID, IsBackground=@IsBackground, [Description] = @Description, IsAppFeatures = @IsAppFeatures,FeaturesCode = @FeaturesCode,IsAppHomeModule = @IsAppHomeModule, IsAppShortcutMenu = @IsAppShortcutMenu, OrderIndex=@OrderIndex,EditTime=@EditTime,EditUserID=@EditUserID WHERE ID =@ID"; int result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, sql, paras.ToArray()); string msg = string.Empty; switch (result) { case 1: msg = PromptInformation.OperationSuccess; break; case 0: msg = PromptInformation.NotExists; break; case -1: msg = PromptInformation.DBError; break; } return(new OperationResult() { Success = result > 0, Message = msg }); }