Пример #1
0
        private static void TestAddTableFindMethod()
        {
            AddTableFindMethodDialog dialog = new AddTableFindMethodDialog();

            AddTableFindMethodParms parms = new AddTableFindMethodParms();

            //parms.MethodName = "find3";
            parms.IsTestMode = true;
            parms.TableName  = "MyTable";
            parms.Fields     = new List <AxTableFieldParm> {
                new AxTableFieldParm {
                    FieldName = "Field1", FieldType = "Type1", IsMandatory = true
                },
                new AxTableFieldParm {
                    FieldName = "Field2Big", FieldType = "Type2Big", IsMandatory = true
                },
                new AxTableFieldParm {
                    FieldName = "F3", FieldType = "T3", IsMandatory = false
                }
            };

            dialog.SetParameters(parms);

            Application.Run(dialog);
        }
Пример #2
0
        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}; ");
                }
            }
        }