/// <summary> /// 把某个自定义的聚合块保存到硬盘上。 /// </summary> /// <param name="blocksName"></param> /// <param name="blocks"></param> public void Save(string blocksName, AggtBlocks blocks) { var path = XmlConfigFileSystem.GetCompositeBlocksFilePath(blocksName); var xml = blocks.ToXmlString(); File.WriteAllText(path, xml); }
internal ClientAggtMeta ConvertToAggtMeta(AggtBlocks aggt, string childPropertyName = null) { var meta = new ClientAggtMeta(); ConvertToAggtMeta(aggt, meta, childPropertyName); return(meta); }
private void ConvertToAggtMeta(AggtBlocks aggt, ClientAggtMeta meta, string childPropertyName = null) { var mainBlock = aggt.MainBlock; meta.mainBlock = ConvertToClientMeta(mainBlock.ViewMeta.AsWebView(), mainBlock.BlockType == BlockType.Detail); if (mainBlock is ChildBlock) { meta.mainBlock.label = (mainBlock as ChildBlock).Label; } meta.childProperty = childPropertyName; meta.layoutClass = aggt.Layout.Class; //surrounders foreach (var surAggt in aggt.Surrounders) { var surBlock = surAggt.MainBlock as SurrounderBlock; var surroundMeta = new SurrounderMeta { surrounderType = surBlock.SurrounderType }; ConvertToAggtMeta(surAggt, surroundMeta); meta.surrounders.Add(surroundMeta); } //children foreach (var childAggt in aggt.Children) { var childBlock = childAggt.MainBlock as ChildBlock; var child = ConvertToAggtMeta(childAggt, childBlock.ChildrenPropertyName); meta.children.Add(child); } }
/// <summary> /// 生成条件查询和主体模块 /// </summary> /// <returns></returns> protected override AggtBlocks DefineBlocks() { var entityType = this.EntityType; AggtBlocks result = new AggtBlocks { MainBlock = new Block(entityType), Layout = new LayoutMeta(typeof(ConditionQueryLayout)) }; var conAttri = entityType.GetSingleAttribute <ConditionQueryTypeAttribute>(); if (conAttri != null) { result.Surrounders.Add(new AggtBlocks { MainBlock = new ConditionBlock() { EntityType = conAttri.QueryType, }, Layout = new LayoutMeta(typeof(HorizentalConditionLayout)) }); } return(result); }
protected override void OnBlocksDefined(AggtBlocks blocks) { //添加一个升级数据库的按钮。 blocks.MainBlock.ViewMeta.AsWPFView().UseCommands(typeof(MigrateDatabaseCommand)); base.OnBlocksDefined(blocks); }
public override void Initialize(IApp app) { WPFCommandNames.CustomizeUI = typeof(CustomizeUI); if (RafyEnvironment.IsDebuggingEnabled) { WPFCommandNames.SysCommands.Insert(0, typeof(CustomizeUI)); WPFCommandNames.SysQueryCommands.Insert(0, typeof(CustomizeUI)); } app.MetaCompiled += (o, e) => { UIModel.AggtBlocks.DefineBlocks("ViewConfigurationModel模块界面", m => { var blocks = new AggtBlocks { MainBlock = new Block(typeof(ViewConfigurationModel)) { BlockType = BlockType.Detail }, Children = { new ChildBlock("属性", ViewConfigurationModel.ViewConfigurationPropertyListProperty), new ChildBlock("命令", ViewConfigurationModel.ViewConfigurationCommandListProperty) } }; blocks.Layout.IsLayoutChildrenHorizonal = true; return(blocks); }); }; }
internal ControlResult CreateUI(AggtBlocks blocks) { var ui = this.CreateUICore(blocks); this.OnUIGenerated(ui); return(ui); }
public RegionContainer(AggtBlocks aggt) { if (aggt == null) { throw new ArgumentNullException("aggt"); } this._aggt = aggt; }
/// <summary> /// 递归获取某个聚合块中所有可用的操作列表 /// </summary> /// <param name="blocks"></param> /// <param name="list"></param> private void GetByBlocksRecur(AggtBlocks blocks, OperationACList list) { var mainBlock = blocks.MainBlock; //查看,编辑 list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = SystemOperationKeys.Read, Label = SystemOperationKeys.Read.Translate(), }); //list.Add(new OperationAC //{ // ScopeKeyLabel = mainBlock.KeyLabel.Translate(), // OperationKey = SystemOperationKeys.Edit, // Label = SystemOperationKeys.Edit.Translate(), //}); if (RafyEnvironment.Location.IsWebUI) { //功能按钮权限 foreach (var cmd in mainBlock.ViewMeta.AsWebView().Commands) { list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = cmd.Name, Label = cmd.Label.Translate(), }); } } else { //功能按钮权限 foreach (var cmd in mainBlock.ViewMeta.AsWPFView().Commands) { list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = cmd.Name, Label = cmd.Label.Translate(), }); } } foreach (var surrounder in blocks.Surrounders) { this.GetByBlocksRecur(surrounder, list); } foreach (var child in blocks.Children) { this.GetByBlocksRecur(child, list); } }
protected override void OnBlocksDefined(AggtBlocks blocks) { //TimeSpanCriteria 默认是横向排列的,需要修改此数据 blocks.MainBlock.ViewMeta.AsWPFView().UseDetailAsHorizontal(false); foreach (var sur in blocks.Surrounders) { ModuleBase.MakeBlockReadonly(sur); } base.OnBlocksDefined(blocks); }
/// <summary> /// 创建某个自定义的聚合块 /// </summary> /// <param name="blocksName"></param> /// <returns></returns> public AggtBlocks GetBlocks(string blocksName) { var path = XmlConfigFileSystem.GetCompositeBlocksFilePath(blocksName); if (File.Exists(path)) { var xml = File.ReadAllText(path); var blocks = AggtBlocks.FromXml(xml); return(blocks); } return(null); }
public ControlResult(FrameworkElement control, LogicalView view, AggtBlocks blocks) { if (control == null) { throw new ArgumentNullException("control"); } if (view == null) { throw new ArgumentNullException("control"); } this.Control = control; this.MainView = view; this.Blocks = blocks; }
public static void MakeBlockReadonly(AggtBlocks block) { var childMeta = block.MainBlock.ViewMeta; childMeta.DisableEditing(); var commands = childMeta.AsWPFView().Commands; for (int i = commands.Count - 1; i >= 0; i--) { var cmd = commands[i]; if (cmd.GroupType != CommandGroupType.View && cmd.GroupType != CommandGroupType.System) { commands.Remove(cmd); } } }
/// <summary> /// 根据聚合元数据,生成最终的聚合控件 /// </summary> /// <param name="aggt"> /// 集合中的第一个,是主区域对应的View</param> /// <param name="recurChildren"></param> /// <param name="recurSurrounders"></param> /// <param name="ownerView"></param> /// <param name="type"></param> /// <returns></returns> public ControlResult GenerateControl(AggtBlocks aggt) { var mainView = this._viewFactory.CreateView(aggt.MainBlock); this.CreateCommandsUI(mainView, aggt.MainBlock); var result = this.GenerateCompoundControl(aggt, mainView); Zoom.EnableZoom(result.Control); if (this.GesturesLocation == GesturesLocation.Whole) { this.CreateCommandBindingsOnWhole(result.Control, mainView); } return(result); }
protected override AggtBlocks DefineBlocks() { AggtBlocks blocks = new AggtBlocks { Layout = new LayoutMeta(typeof(FinanceInputLayout)), MainBlock = new Block(this.EntityType) { BlockType = BlockType.Detail, KeyLabel = "经费输入", ExtendView = typeof(FinanceLogInputDetailWPFViewConfig) }, Surrounders = { new SurrounderBlock(this.EntityType, "list") } }; return(blocks); }
/// <summary> /// 根据元数据创建一个布局的方案 /// </summary> /// <param name="meta"></param> /// <returns></returns> private static LayoutMethod CreateLayoutMethod(AggtBlocks meta) { if (meta.Layout.Class != null) { var type = Type.GetType(meta.Layout.Class); var instance = Activator.CreateInstance(type); if (instance is ILayoutControl) { return(new ControlLayoutMethod(instance as ILayoutControl)); } if (instance is LayoutMethod) { return(instance as LayoutMethod); } throw new InvalidProgramException(string.Format( "{0} 类型不能用于布局。原因:WPF 中用于布局类型必须实现 ILayoutControl 接口或者继承自 LayoutMethod 类!", type.FullName)); } var mainBlock = meta.MainBlock; var generateType = mainBlock.BlockType; if (generateType == BlockType.Detail) { return(new ControlLayoutMethod(new DetailLayout())); } //var entityViewInfo = mainBlock.EntityViewInfo; //if (entityViewInfo.EntityInfo.IsDefaultObject && // entityViewInfo.BusinessObjectAttribute.ModuleType != ModuleType.Query) //{ // return new TraditionalLayout<NaviListDetailLayoutControl>(); //} return(new ControlLayoutMethod(new ListDetailLayout())); //return new TraditionalLayout<ListDetailPopupChildrenLayoutControl>(); }
protected override AggtBlocks DefineBlocks() { var blocks = new AggtBlocks { Layout = new LayoutMeta(typeof(BillQueryLayout)), MainBlock = new ConditionBlock(this.EntityType), Surrounders = { new SurrounderBlock(typeof(PurchaseOrder), QueryLogicalView.ResultSurrounderType), new SurrounderBlock(typeof(OrderStorageInBill), QueryLogicalView.ResultSurrounderType), new SurrounderBlock(typeof(OrderStorageInBill), QueryLogicalView.ResultSurrounderType) { KeyLabel = "采购入库单 - 报表", BlockType = BlockType.Report, }, new SurrounderBlock(typeof(OtherStorageInBill), QueryLogicalView.ResultSurrounderType), new SurrounderBlock(typeof(OtherStorageOutBill), QueryLogicalView.ResultSurrounderType), new SurrounderBlock(typeof(StorageMove), QueryLogicalView.ResultSurrounderType), } }; return(blocks); }
public override void Initialize(IApp app) { var customeUICmd = "Rafy.customization.cmd.CustomizeUI"; WebCommandNames.CustomizeUI = customeUICmd; WebCommandNames.SysCommands.Add(customeUICmd); WebCommandNames.SysQueryCommands.Add(customeUICmd); if (RafyEnvironment.IsDebuggingEnabled) { WebCommandNames.TreeCommands.Insert(0, customeUICmd); WebCommandNames.CommonCommands.Insert(0, customeUICmd); } app.MetaCreating += (o, e) => { UIModel.AggtBlocks.DefineBlocks("ViewConfigurationModel模块界面", m => { var blocks = new AggtBlocks { MainBlock = new Block(typeof(ViewConfigurationModel)) { BlockType = BlockType.Detail }, Children = { new ChildBlock("属性", ViewConfigurationModel.ViewConfigurationPropertyListProperty), new ChildBlock("命令", ViewConfigurationModel.ViewConfigurationCommandListProperty) } }; blocks.Layout.Class = "Rafy.autoUI.layouts.RightChildren"; return(blocks); }); }; }
/// <summary> /// 为聚合对象生成组合控件。 /// </summary> /// <param name="aggt"> /// 需要生成聚合控件的聚合对象元数据 /// </param> /// <param name="mainView"> /// 已经生成好的聚合对象 aggt 中的“根”对象所对应的 LogicalView。 /// </param> /// <returns></returns> private ControlResult GenerateCompoundControl(AggtBlocks aggt, LogicalView mainView) { var regions = new RegionContainer(aggt); //如果不要查询面板,则需要生成主区域 var viewInfo = aggt.MainBlock.ViewMeta; regions.Add(TraditionalRegions.Main, AutoUIHelper.CreateBusyControlResult(mainView)); if (mainView.CommandsContainer != null) { regions.Add(TraditionalRegions.CommandsContainer, new ControlResult(mainView.CommandsContainer, mainView)); } //Surrounders this.SurroundersToRegions(aggt.Surrounders, mainView, regions); //Children this.ChildrenToRegions(aggt.Children, mainView, regions); //Layout var layout = CreateLayoutMethod(aggt); var result = layout.Arrange(regions); //在 View 中保存最终布局完成的控件。 mainView.LayoutControl = result; //返回布局后的整个控件。 var ui = new ControlResult(result, mainView, aggt); if (this.GesturesLocation == GesturesLocation.Layout) { this.CreateCommandBindings(ui.Control, ui.MainView); } return(ui); }
/// <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> /// 创建一个实体控件。 /// /// 本方法提供了生成期扩展性。 /// /// ( /// 重写时注意,可以不使用 AutoUI,但是这样的话, /// 界面可能与模板的结构定义并不一致,这会产生一些影响,例如权限系统无法控制。 /// ) /// </summary> /// <returns></returns> protected virtual ControlResult CreateUICore(AggtBlocks blocks) { return(AutoUI.AggtUIFactory.GenerateControl(blocks)); }
protected override string ResponseScript(HttpContext context) { var request = context.Request; var converter = new ClientMetaFactory(); var op = converter.Option; op.ignoreCommands = request.GetQueryStringOrDefault("ignoreCommands", 0) == 1; op.isDetail = request.GetQueryStringOrDefault("isDetail", 0) == 1; op.isLookup = request.GetQueryStringOrDefault("isLookup", 0) == 1; op.isReadonly = request.GetQueryStringOrDefault("isReadonly", 0) == 1; op.viewName = request.GetQueryStringOrDefault("viewName", string.Empty); var moduleName = request.GetQueryStringOrDefault("module", string.Empty); var typeName = request.GetQueryStringOrDefault("type", string.Empty); var templateType = request.GetQueryStringOrDefault("templateType", string.Empty); var isAggt = request.GetQueryStringOrDefault("isAggt", 0) == 1; JsonModel jsonResult = null; //如果指定了 module,则直接返回模块的格式。 if (!string.IsNullOrEmpty(moduleName)) { var module = CommonModel.Modules[moduleName]; var aggt = UIModel.AggtBlocks.GetModuleBlocks(module); jsonResult = converter.ConvertToAggtMeta(aggt); } else { var type = ClientEntities.Find(typeName); //需要聚合块 if (isAggt) { AggtBlocks aggt = null; //通过定义的模板类来返回模块格式 if (!string.IsNullOrEmpty(templateType)) { var uiTemplateType = Type.GetType(templateType); var template = Activator.CreateInstance(uiTemplateType) as BlocksTemplate; template.EntityType = type.EntityType; aggt = template.GetBlocks(); } else { //通过定义的聚合块名称来获取聚合块 if (!string.IsNullOrEmpty(op.viewName)) { aggt = UIModel.AggtBlocks.GetDefinedBlocks(op.viewName); } else { //通过默认的聚合块名称来获取聚合块 aggt = UIModel.AggtBlocks.GetDefaultBlocks(type.EntityType); } } jsonResult = converter.ConvertToAggtMeta(aggt); } else { //获取单块 UI 的元数据 var evm = UIModel.Views.Create(type.EntityType, op.viewName) as WebEntityViewMeta; jsonResult = converter.ConvertToClientMeta(evm); } } var json = jsonResult.ToJsonString(); return(json); }