void DoTableUpdate() { AxTable newTable = _axHelper.MetadataProvider.Tables.Read(TableName); if (newTable != null) { AxTableFieldGroup axTableFieldGroup; bool isTableModified = false; switch (TemplateType) { case FormTemplateType.SimpleList: if (!string.IsNullOrWhiteSpace(GroupNameGrid) && !newTable.FieldGroups.Contains(GroupNameGrid)) { axTableFieldGroup = new AxTableFieldGroup { Name = GroupNameGrid, Label = "Overview" }; newTable.AddFieldGroup(axTableFieldGroup); isTableModified = true; AddLog($"Group added: {GroupNameGrid}; "); } break; case FormTemplateType.SimpleListDetails: if (!string.IsNullOrWhiteSpace(GroupNameGrid) && !newTable.FieldGroups.Contains(GroupNameGrid)) { axTableFieldGroup = new AxTableFieldGroup { Name = GroupNameGrid, Label = "Overview" }; newTable.AddFieldGroup(axTableFieldGroup); isTableModified = true; AddLog($"Group added: {GroupNameGrid}; "); } if (!string.IsNullOrWhiteSpace(GroupNameHeader) && !newTable.FieldGroups.Contains(GroupNameHeader)) { axTableFieldGroup = new AxTableFieldGroup { Name = GroupNameHeader, Label = "Details header" }; newTable.AddFieldGroup(axTableFieldGroup); isTableModified = true; AddLog($"Group added: {GroupNameHeader}; "); } break; } if (isTableModified) { _axHelper.MetaModelService.UpdateTable(newTable, _axHelper.ModelSaveInfo); _axHelper.AppendToActiveProject(newTable); //AddLog($"Table modified: {newTable.Name}; "); } } }
protected void AddField(AxTableField field) { AxTableFieldGroup axTableFieldGroup; AxTableFieldGroupField axTableFieldGroupField = new AxTableFieldGroupField(); axTableFieldGroupField.Name = field.Name; axTableFieldGroupField.DataField = field.Name; if (TableName.Contains(".") == false) { AxTable axTable = _axHelper.MetadataProvider.Tables.Read(TableName); if (IsDisplayMethod) { AxMethod axMethod = new AxMethod(); axMethod.Name = field.Name; axMethod.Source = $"public display {field.ExtendedDataType} {field.Name}() " + Environment.NewLine + "{" + Environment.NewLine + " return '';" + Environment.NewLine + "}"; axTable.AddMethod(axMethod); } else { axTable.Fields.Add(field); } if (GroupName != String.Empty) { if (axTable.FieldGroups.Contains(GroupName)) { axTableFieldGroup = axTable.FieldGroups.getObject(GroupName); axTableFieldGroup.AddField(axTableFieldGroupField); } else { axTableFieldGroup = new AxTableFieldGroup { Name = GroupName }; axTableFieldGroup.AddField(axTableFieldGroupField); axTable.AddFieldGroup(axTableFieldGroup); } } if (!IsDisplayMethod) { AxTableRelationForeignKey axTableRelationForeignKey = AddTableRelation(field, axTable.Relations); if (axTableRelationForeignKey != null) { axTable.AddRelation(axTableRelationForeignKey); } } _axHelper.MetadataProvider.Tables.Update(axTable, _axHelper.ModelSaveInfo); } else { AxTableExtension axTableExtension = _axHelper.MetadataProvider.TableExtensions.Read(TableName); if (!IsDisplayMethod) { axTableExtension.Fields.Add(field); } if (GroupName != String.Empty) { if (axTableExtension.FieldGroups.Contains(GroupName)) { axTableFieldGroup = axTableExtension.FieldGroups.getObject(GroupName); axTableFieldGroup.AddField(axTableFieldGroupField); } else { axTableFieldGroup = new AxTableFieldGroup { Name = GroupName }; axTableFieldGroup.AddField(axTableFieldGroupField); axTableExtension.FieldGroups.Add(axTableFieldGroup); } } if (!IsDisplayMethod) { AxTableRelationForeignKey axTableRelationForeignKey = AddTableRelation(field, axTableExtension.Relations); if (axTableRelationForeignKey != null) { axTableExtension.Relations.Add(axTableRelationForeignKey); } } _axHelper.MetadataProvider.TableExtensions.Update(axTableExtension, _axHelper.ModelSaveInfo); } }
void DoTableCreate() { AxTable newTable = _axHelper.MetadataProvider.Tables.Read(TableName); if (newTable == null) { newTable = new AxTable(); newTable.Name = TableName; newTable.Label = TableLabel; newTable.TitleField1 = KeyFieldName; newTable.CacheLookup = RecordCacheLevel.Found; newTable.ClusteredIndex = $"{KeyFieldName}Idx"; newTable.PrimaryIndex = newTable.ClusteredIndex; newTable.ReplacementKey = newTable.ClusteredIndex; newTable.TableGroup = TableGroup.Group; newTable.CreatedBy = NoYes.Yes; newTable.CreatedDateTime = NoYes.Yes; newTable.ModifiedBy = NoYes.Yes; newTable.ModifiedDateTime = NoYes.Yes; AxTableField primaryField = new AxTableFieldString(); primaryField.Name = KeyFieldName; primaryField.ExtendedDataType = PrimaryKeyEdtName; primaryField.IgnoreEDTRelation = NoYes.Yes; primaryField.AllowEdit = NoYes.No; primaryField.Mandatory = NoYes.Yes; newTable.AddField(primaryField); AxTableField descriptionField = new AxTableFieldString(); descriptionField.Name = "Description"; descriptionField.ExtendedDataType = "Description"; newTable.AddField(descriptionField); AxTableIndexField axTableIndexField = new AxTableIndexField(); axTableIndexField.DataField = KeyFieldName; axTableIndexField.Name = KeyFieldName; AxTableIndex axTableIndex = new AxTableIndex(); axTableIndex.Name = newTable.ClusteredIndex; axTableIndex.AlternateKey = NoYes.Yes; axTableIndex.AddField(axTableIndexField); newTable.AddIndex(axTableIndex); AxTableFieldGroup axTableFieldGroup; AxTableFieldGroupField axTableFieldGroupField; axTableFieldGroup = new AxTableFieldGroup { Name = "AutoReport", IsSystemGenerated = NoYes.Yes }; axTableFieldGroupField = new AxTableFieldGroupField { Name = KeyFieldName, DataField = KeyFieldName }; axTableFieldGroup.AddField(axTableFieldGroupField); newTable.AddFieldGroup(axTableFieldGroup); axTableFieldGroup = new AxTableFieldGroup { Name = "AutoLookup", IsSystemGenerated = NoYes.Yes }; newTable.AddFieldGroup(axTableFieldGroup); axTableFieldGroup = new AxTableFieldGroup { Name = "AutoIdentification", IsSystemGenerated = NoYes.Yes, AutoPopulate = NoYes.Yes }; newTable.AddFieldGroup(axTableFieldGroup); axTableFieldGroup = new AxTableFieldGroup { Name = "AutoSummary", IsSystemGenerated = NoYes.Yes }; newTable.AddFieldGroup(axTableFieldGroup); axTableFieldGroup = new AxTableFieldGroup { Name = "AutoBrowse", IsSystemGenerated = NoYes.Yes }; newTable.AddFieldGroup(axTableFieldGroup); axTableFieldGroup = new AxTableFieldGroup { Name = "Overview", Label = "Overview" }; axTableFieldGroupField = new AxTableFieldGroupField { Name = KeyFieldName, DataField = KeyFieldName }; axTableFieldGroup.AddField(axTableFieldGroupField); if (descriptionField != null) { axTableFieldGroupField = new AxTableFieldGroupField { Name = descriptionField.Name, DataField = descriptionField.Name }; axTableFieldGroup.AddField(axTableFieldGroupField); } newTable.AddFieldGroup(axTableFieldGroup); AddTableFindMethodParms findMethodParms = new AddTableFindMethodParms(); findMethodParms.IsCreateFind = true; findMethodParms.IsTestMode = true; findMethodParms.TableName = TableName; findMethodParms.VarName = TableVarName; findMethodParms.Fields = new List <AxTableFieldParm> { new AxTableFieldParm { FieldName = KeyFieldName, FieldType = PrimaryKeyEdtName, IsMandatory = true } }; AxMethod axMethod = new AxMethod(); axMethod.Name = "find"; axMethod.IsStatic = true; axMethod.Source = findMethodParms.GenerateResult(); newTable.AddMethod(axMethod); _axHelper.MetaModelService.CreateTable(newTable, _axHelper.ModelSaveInfo); _axHelper.AppendToActiveProject(newTable); AddLog($"Table: {newTable.Name}; "); AxEdt edtLocal = _axHelper.MetadataProvider.Edts.Read(PrimaryKeyEdtName); if (edtLocal != null) { if (String.IsNullOrEmpty(edtLocal.ReferenceTable)) //check for the existing EDT. Do not modify it { if (edtLocal.Relations == null || edtLocal.Relations.Count == 0) //no old style relations { edtLocal.ReferenceTable = TableName; edtLocal.AddTableReference(TableName, KeyFieldName); _axHelper.MetaModelService.UpdateExtendedDataType(edtLocal, _axHelper.ModelSaveInfo); _axHelper.AppendToActiveProject(edtLocal); } } //AddLog($"EDT: {edtLocal.Name}; "); } } }