private string createForm(ITable table) { AxForm axForm = new AxForm() { Name = table.Name, Design = new AxFormDesign() { Caption = table.Label } }; axForm.DataSources.Add(new AxFormDataSourceRoot() { Table = table.Name, Name = table.Name }); // Find current model var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo(); //Create menu item in the right model var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders; var metaModelService = metaModelProviders.CurrentMetaModelService; metaModelService.CreateForm(axForm, modelSaveInfo); // Add the menu item display to the active project Common.CommonUtil.AddElementToProject(axForm); // Common.CommonUtil.ShowLog($"Security privilege: {axSecurityPrivMaint} created"); return(axForm.Name); }
protected override void Create() { var element = new AxForm { Name = ElementName }; MetaService.CreateForm(element, Model); }
protected void CheckPattern(AxForm axForm) { Microsoft.Dynamics.AX.Metadata.Patterns.PatternFactory pf = new Microsoft.Dynamics.AX.Metadata.Patterns.PatternFactory(); var formDesignPattern = pf.AllPatterns.Where(p => p.Name.Equals(axForm.Design.Pattern)).FirstOrDefault(); if (formDesignPattern != null) { Microsoft.Dynamics.AX.Metadata.Patterns.PatternAnalyzer pa = new Microsoft.Dynamics.AX.Metadata.Patterns.PatternAnalyzer(); var patternResult = pa.TestPattern(axForm.Design, formDesignPattern); } }
/// <summary> /// Called when user clicks on the add-in menu /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { try { var selectedMenuItem = e.SelectedElement as Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.Forms.IForm; if (selectedMenuItem != null) { //var metadataType = selectedMenuItem.GetMetadataType(); var metaModelService = Common.CommonUtil.GetModelSaveService(); AxForm axForm = metaModelService.GetForm(selectedMenuItem.Name); this.CheckPattern(axForm); } } catch (Exception ex) { CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public static void Create(UtilElementType type, string name) { if (Project == null) { throw new InvalidOperationException("No project selected."); } _name = name; switch (type) { case UtilElementType.DisplayTool: var existsDisplayTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name); if (!existsDisplayTool) { var displayMenu = new AxMenuItemDisplay { Name = name }; LocalUtils.MetaService.CreateMenuItemDisplay(displayMenu, Model); AddAotElement <AxMenuItemDisplay>(); } break; case UtilElementType.OutputTool: var existsOutputTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name); if (!existsOutputTool) { var outputMenu = new AxMenuItemOutput { Name = name }; LocalUtils.MetaService.CreateMenuItemOutput(outputMenu, Model); AddAotElement <AxMenuItemOutput>(); } break; case UtilElementType.ActionTool: var existsActionTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name); if (!existsActionTool) { var actionMenu = new AxMenuItemAction { Name = name }; LocalUtils.MetaService.CreateMenuItemAction(actionMenu, Model); AddAotElement <AxMenuItemAction>(); } break; case UtilElementType.Query: var existsQuery = LocalUtils.MetaService.GetQueryNames().Contains(name); if (!existsQuery) { var query = new AxQuerySimple { Name = name }; LocalUtils.MetaService.CreateQuery(query, Model); AddAotElement <AxQuerySimple>(); } break; case UtilElementType.Enum: var Enum = LocalUtils.MetaService.GetEnumNames().Contains(name); if (!Enum) { var edtEnum = new AxEnum { Name = name }; LocalUtils.MetaService.CreateEnum(edtEnum, Model); AddAotElement <AxEnum>(); } break; case UtilElementType.ExtendedType: break; case UtilElementType.Table: var existsTable = LocalUtils.MetaService.GetTableNames().Contains(name); if (!existsTable) { var table = new AxTable { Name = name }; LocalUtils.MetaService.CreateTable(table, Model); AddAotElement <AxTable>(); } break; case UtilElementType.Class: var existsClass = LocalUtils.MetaService.GetClassNames().Contains(name); if (!existsClass) { var axClass = new AxClass { Name = name }; LocalUtils.MetaService.CreateClass(axClass, Model); AddAotElement <AxClass>(); } break; case UtilElementType.SSRSReport: var existsSsrsReport = LocalUtils.MetaService.GetReportNames().Contains(name); if (!existsSsrsReport) { var srsReport = new AxReport { Name = name }; LocalUtils.MetaService.CreateReport(srsReport, Model); AddAotElement <AxReport>(); } break; case UtilElementType.Form: var existsForm = LocalUtils.MetaService.GetFormNames().Contains(name); if (!existsForm) { var axForm = new AxForm { Name = name }; LocalUtils.MetaService.CreateForm(axForm, Model); AddAotElement <AxForm>(); } break; case UtilElementType.Menu: var existsMenu = LocalUtils.MetaService.GetMenuNames().Contains(name); if (!existsMenu) { var axMenu = new AxMenu { Name = name }; LocalUtils.MetaService.CreateMenu(axMenu, Model); AddAotElement <AxMenu>(); } break; case UtilElementType.SecDuty: var existsSecDuty = LocalUtils.MetaService.GetSecurityDutyNames().Contains(name); if (!existsSecDuty) { var axDuty = new AxSecurityDuty { Name = name }; LocalUtils.MetaService.CreateSecurityDuty(axDuty, Model); AddAotElement <AxSecurityDuty>(); } break; case UtilElementType.SecPolicy: var existsSecPolicy = LocalUtils.MetaService.GetSecurityPolicyNames().Contains(name); if (!existsSecPolicy) { var axPolicy = new AxSecurityPolicy { Name = name }; LocalUtils.MetaService.CreateSecurityPolicy(axPolicy, Model); AddAotElement <AxSecurityPolicy>(); } break; case UtilElementType.SecPrivilege: var existsSecPrivilege = LocalUtils.MetaService.GetSecurityPrivilegeNames().Contains(name); if (!existsSecPrivilege) { var privilege = new AxSecurityPrivilege { Name = name }; LocalUtils.MetaService.CreateSecurityPrivilege(privilege, Model); AddAotElement <AxSecurityPrivilege>(); } break; case UtilElementType.SecRole: var existsSecRole = LocalUtils.MetaService.GetSecurityRoleNames().Contains(name); if (!existsSecRole) { var role = new AxSecurityRole { Name = name }; LocalUtils.MetaService.CreateSecurityRole(role, Model); AddAotElement <AxSecurityRole>(); } break; default: throw new Exception("Element not supported"); } }
void DoFormCreate() { AxForm newForm = _axHelper.MetadataProvider.Forms.Read(FormName); if (newForm != null) { return; } newForm = new AxForm { Name = FormName }; AxMethod axMethod = new AxMethod(); axMethod.Name = "classDeclaration"; axMethod.Source = $"[Form]{Environment.NewLine}public class {newForm.Name} extends FormRun " + Environment.NewLine + "{" + Environment.NewLine + "}"; newForm.AddMethod(axMethod); string dsName = TableName; AxFormDataSourceRoot axFormDataSource = new AxFormDataSourceRoot(); axFormDataSource.Name = dsName; axFormDataSource.Table = TableName; axFormDataSource.InsertIfEmpty = NoYes.No; newForm.AddDataSource(axFormDataSource); //newForm.Design.Pattern = "SimpleList"; add apply pattern //newForm.Design.PatternVersion = "1.1"; newForm.Design.Caption = FormLabel; newForm.Design.TitleDataSource = dsName; newForm.Design.DataSource = dsName; newForm.Design.AddControl(new AxFormActionPaneControl { Name = "MainActionPane" }); var filterGrp = new AxFormGroupControl { Name = "FilterGroup", Pattern = "CustomAndQuickFilters", PatternVersion = "1.1" }; AxFormControlExtension quickFilterControl = new AxFormControlExtension { Name = "QuickFilterControl" }; AxFormControlExtensionProperty formControlExtensionProperty = new AxFormControlExtensionProperty(); formControlExtensionProperty.Name = "targetControlName"; formControlExtensionProperty.Type = CompilerBaseType.String; formControlExtensionProperty.Value = "MainGrid"; quickFilterControl.ExtensionProperties.Add(formControlExtensionProperty); filterGrp.AddControl(new AxFormControl { Name = "QuickFilter", FormControlExtension = quickFilterControl }); newForm.Design.AddControl(filterGrp); AxFormGridControl axFormGridControl = new AxFormGridControl { Name = "MainGrid", DataSource = dsName }; AxFormGroupControl overviewGroupControl = new AxFormGroupControl { Name = "Overview", DataGroup = "Overview", DataSource = dsName }; axFormGridControl.AddControl(overviewGroupControl); newForm.Design.AddControl(axFormGridControl); _axHelper.MetaModelService.CreateForm(newForm, _axHelper.ModelSaveInfo); _axHelper.AppendToActiveProject(newForm); AddLog($"Form: {newForm.Name}; "); }
void DoFormCreate() { AxForm newForm = _axHelper.MetadataProvider.Forms.Read(FormName); if (newForm != null) { throw new Exception($"Form {FormName} already exists"); } newForm = new AxForm { Name = FormName }; AxMethod axMethod = new AxMethod(); axMethod.Name = "classDeclaration"; axMethod.Source = $"[Form]{Environment.NewLine}public class {newForm.Name} extends FormRun " + Environment.NewLine + "{" + Environment.NewLine + "}"; newForm.AddMethod(axMethod); string dsName = TableName; AxFormDataSourceRoot axFormDataSource = new AxFormDataSourceRoot(); axFormDataSource.Name = dsName; axFormDataSource.Table = TableName; axFormDataSource.InsertIfEmpty = NoYes.No; newForm.AddDataSource(axFormDataSource); newForm.Design.Caption = FormLabel; newForm.Design.TitleDataSource = dsName; newForm.Design.DataSource = dsName; AxFormGroupControl filterGrp, detailsHeaderGroup; AxFormGridControl axFormGridControl; AxFormControlExtension quickFilterControl; AxFormControlExtensionProperty formControlExtensionProperty; AxFormGroupControl overviewGroupControl; AxFormTabControl formTabControl; switch (TemplateType) { case FormTemplateType.SimpleList: newForm.Design.AddControl(new AxFormActionPaneControl { Name = "MainActionPane" }); filterGrp = new AxFormGroupControl { Name = "FilterGroup", Pattern = "CustomAndQuickFilters", PatternVersion = "1.1" }; quickFilterControl = new AxFormControlExtension { Name = "QuickFilterControl" }; formControlExtensionProperty = new AxFormControlExtensionProperty(); formControlExtensionProperty.Name = "targetControlName"; formControlExtensionProperty.Type = CompilerBaseType.String; formControlExtensionProperty.Value = "MainGrid"; quickFilterControl.ExtensionProperties.Add(formControlExtensionProperty); filterGrp.AddControl(new AxFormControl { Name = "QuickFilter", FormControlExtension = quickFilterControl }); newForm.Design.AddControl(filterGrp); axFormGridControl = new AxFormGridControl { Name = "MainGrid", DataSource = dsName }; overviewGroupControl = new AxFormGroupControl { Name = GroupNameGrid, DataGroup = GroupNameGrid, DataSource = dsName }; axFormGridControl.AddControl(overviewGroupControl); newForm.Design.AddControl(axFormGridControl); break; case FormTemplateType.SimpleListDetails: newForm.Design.AddControl(new AxFormActionPaneControl { Name = "MainActionPane" }); filterGrp = new AxFormGroupControl { Name = "NavigationListGroup" }; quickFilterControl = new AxFormControlExtension { Name = "QuickFilterControl" }; formControlExtensionProperty = new AxFormControlExtensionProperty(); formControlExtensionProperty.Name = "targetControlName"; formControlExtensionProperty.Type = CompilerBaseType.String; formControlExtensionProperty.Value = "MainGrid"; quickFilterControl.ExtensionProperties.Add(formControlExtensionProperty); filterGrp.AddControl(new AxFormControl { Name = "NavListQuickFilter", FormControlExtension = quickFilterControl }); axFormGridControl = new AxFormGridControl { Name = "MainGrid", DataSource = dsName }; if (!string.IsNullOrWhiteSpace(GroupNameGrid)) { overviewGroupControl = new AxFormGroupControl { Name = GroupNameGrid, DataGroup = GroupNameGrid, DataSource = dsName }; axFormGridControl.AddControl(overviewGroupControl); } filterGrp.AddControl(axFormGridControl); newForm.Design.AddControl(filterGrp); detailsHeaderGroup = new AxFormGroupControl { Name = "DetailsHeaderGroup" }; detailsHeaderGroup.DataSource = dsName; detailsHeaderGroup.DataGroup = GroupNameHeader; newForm.Design.AddControl(detailsHeaderGroup); formTabControl = new AxFormTabControl { Name = "DetailsTab" }; List <string> listImp = new List <string>( TabLabels.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); foreach (string lineImp in listImp) { string tabName = AxHelper.GetTypeNameFromLabel(lineImp) + "TabPage"; formTabControl.AddControl(new AxFormTabPageControl { Name = tabName, Caption = lineImp, DataSource = dsName }); } newForm.Design.AddControl(formTabControl); break; } _axHelper.MetaModelService.CreateForm(newForm, _axHelper.ModelSaveInfo); _axHelper.AppendToActiveProject(newForm); AddLog($"Form: {newForm.Name} - Restore it before use;"); }