/// <summary> /// 直接打开某个模块。 /// </summary> /// <param name="module"></param> /// <returns></returns> public WorkspaceWindow OpenModule(WPFModuleMeta module) { var view = this.FindOrCreateWindow(module); this.Workspace.TryActive(view); return(view); }
/// <summary> /// 使用元数据中定义的模块来构造一个新的模块视图模型。 /// /// 子类可重写此方法来生成新的视图对象。 /// </summary> /// <param name="meta"></param> /// <returns></returns> private ModuleViewModel CreateViewModel(WPFModuleMeta meta) { var vm = this.CreateViewModelCore(meta); vm._ownerCollection = this; vm.Label = meta.Label; vm.ModuleMeta = meta; return(vm); }
/// <summary> /// 打开某个模块。 /// /// 如果没有权限打开该模块,则弹出提示框。 /// </summary> /// <param name="module"></param> /// <returns></returns> public WorkspaceWindow OpenModuleOrAlert(WPFModuleMeta module) { if (!PermissionMgr.CanShowModule(module)) { App.MessageBox.Show(string.Format( "对不起,此功能需要 [ {0} ] 模块权限,您不具备此权限,如有需要,请与系统管理员联系!".Translate(), module.Label.Translate() )); return(null); } return(this.OpenModule(module)); }
/// <summary> /// 创建/找到具体的视图控件。 /// </summary> /// <param name="module"></param> /// <returns></returns> private WorkspaceWindow FindOrCreateWindow(WPFModuleMeta module) { var workSpace = this.Workspace; var view = workSpace.GetWindow(module.Label); //如果已经打开则激活模块,否则新增模块窗体 if (view == null) { view = this.CreateModule(module); workSpace.Add(view); } return(view); }
/// <summary> /// 构造模块的窗口 /// </summary> /// <param name="moduleMeta"></param> public WorkspaceWindow CreateModule(WPFModuleMeta moduleMeta) { if (moduleMeta == null) { throw new ArgumentNullException("moduleMeta"); } //创建 WorkspaceWindow var window = new ModuleWorkspaceWindow { ModuleMeta = moduleMeta, Title = moduleMeta.Label }; var args = new ModuleEventArgs(window); if (!moduleMeta.IsCustomUI) { try { AutoUI.AggtUIFactory.PermissionModule = moduleMeta; ControlResult ui = null; //在 WPF 中,TemplateType 属性应该是继承自 UITemplate 的类,表示使用的自定义实体模块类型 if (moduleMeta.BlocksTemplate != null) { var module = Activator.CreateInstance(moduleMeta.BlocksTemplate) as UITemplate; if (module == null) { throw new InvalidProgramException("WPF 中模板类需要从 UITemplate 类继承。"); } window.Template = module; window.Template.EntityType = moduleMeta.EntityType; this.OnModuleTemplateCreated(args); window.Blocks = module.GetBlocks(); this.OnModuleBlocksCreated(args); ui = module.CreateUI(window.Blocks); } else { AggtBlocks blocks = UIModel.AggtBlocks.GetModuleBlocks(moduleMeta); window.Blocks = blocks; this.OnModuleBlocksCreated(args); ui = AutoUI.AggtUIFactory.GenerateControl(blocks); } window.WindowControl = ui.Control; window.MainView = ui.MainView; Focus(ui); //刚创建的窗体,尝试加载数据。 if (moduleMeta.TryAutoLoadData) { this.AsyncLoadListData(ui); } } finally { AutoUI.AggtUIFactory.PermissionModule = null; } } else { window.WindowControl = Activator.CreateInstance(moduleMeta.CustomUI) as FrameworkElement; if (window.WindowControl == null) { throw new InvalidProgramException(moduleMeta.CustomUI + " 类型必须是一个 FrameworkElement。"); } } AutomationProperties.SetName(window.WindowControl, moduleMeta.Label); this.OnModuleCreated(args); return(window); }
/// <summary> /// 创建/找到具体的视图控件。 /// </summary> /// <param name="module"></param> /// <returns></returns> private WorkspaceWindow FindOrCreateWindow(WPFModuleMeta module) { var workSpace = this.Workspace; var view = workSpace.GetWindow(module.Label); //如果已经打开则激活模块,否则新增模块窗体 if (view == null) { view = this.CreateModule(module); workSpace.Add(view); } return view; }
/// <summary> /// 打开某个模块。 /// /// 如果没有权限打开该模块,则弹出提示框。 /// </summary> /// <param name="module"></param> /// <returns></returns> public WorkspaceWindow OpenModuleOrAlert(WPFModuleMeta module) { if (!PermissionMgr.CanShowModule(module)) { App.MessageBox.Show(string.Format( "对不起,此功能需要 [ {0} ] 模块权限,您不具备此权限,如有需要,请与系统管理员联系!".Translate(), module.Label.Translate() )); return null; } return this.OpenModule(module); }
/// <summary> /// 直接打开某个模块。 /// </summary> /// <param name="module"></param> /// <returns></returns> public WorkspaceWindow OpenModule(WPFModuleMeta module) { var view = this.FindOrCreateWindow(module); this.Workspace.TryActive(view); return view; }
/// <summary> /// 构造模块的窗口 /// </summary> /// <param name="moduleMeta"></param> public WorkspaceWindow CreateModule(WPFModuleMeta moduleMeta) { if (moduleMeta == null) throw new ArgumentNullException("moduleMeta"); //创建 WorkspaceWindow var window = new ModuleWorkspaceWindow { ModuleMeta = moduleMeta, Title = moduleMeta.Label }; var args = new ModuleEventArgs(window); if (!moduleMeta.IsCustomUI) { try { AutoUI.AggtUIFactory.PermissionModule = moduleMeta; ControlResult ui = null; //在 WPF 中,TemplateType 属性应该是继承自 UITemplate 的类,表示使用的自定义实体模块类型 if (moduleMeta.BlocksTemplate != null) { var module = Activator.CreateInstance(moduleMeta.BlocksTemplate) as UITemplate; if (module == null) throw new InvalidProgramException("WPF 中模板类需要从 UITemplate 类继承。"); window.Template = module; window.Template.EntityType = moduleMeta.EntityType; this.OnModuleTemplateCreated(args); window.Blocks = module.GetBlocks(); this.OnModuleBlocksCreated(args); ui = module.CreateUI(window.Blocks); } else { AggtBlocks blocks = UIModel.AggtBlocks.GetModuleBlocks(moduleMeta); window.Blocks = blocks; this.OnModuleBlocksCreated(args); ui = AutoUI.AggtUIFactory.GenerateControl(blocks); } window.WindowControl = ui.Control; window.MainView = ui.MainView; Focus(ui); //刚创建的窗体,尝试加载数据。 if (moduleMeta.TryAutoLoadData) { this.AsyncLoadListData(ui); } } finally { AutoUI.AggtUIFactory.PermissionModule = null; } } else { window.WindowControl = Activator.CreateInstance(moduleMeta.CustomUI) as FrameworkElement; if (window.WindowControl == null) throw new InvalidProgramException(moduleMeta.CustomUI + " 类型必须是一个 FrameworkElement。"); } AutomationProperties.SetName(window.WindowControl, moduleMeta.Label); this.OnModuleCreated(args); return window; }
/// <summary> /// 使用元数据中定义的模块来构造一个新的模块视图模型。 /// /// 子类可重写此方法来生成新的视图对象。 /// </summary> /// <param name="meta"></param> /// <returns></returns> protected virtual ModuleViewModel CreateViewModelCore(WPFModuleMeta meta) { return(new ModuleViewModel()); }