Exemplo n.º 1
0
        protected void addSpecificPropertiesToEdt(Metadata.MetaModel.AxEdt edt)
        {
            FieldType fieldType;

            if (!edtExist)
            {
                Enum.TryParse <FieldType>(this.controller.comboBoxFieldType.SelectedValue.ToString(), out fieldType);

                switch (fieldType)
                {
                case FieldType.String:
                    Metadata.MetaModel.AxEdtString edtString = edt as Metadata.MetaModel.AxEdtString;
                    edtString.StringSize = (int)this.controller.numericUpDownStringSize.Value;
                    break;

                case FieldType.Enum:
                    Metadata.MetaModel.AxEdtEnum edtEnum = edt as Metadata.MetaModel.AxEdtEnum;
                    edtEnum.EnumType = this.controller.comboBoxFieldType.Text;
                    break;

                case FieldType.Memo:
                    edt.Extends = "FreTxt";
                    break;

                default:
                    break;
                }
            }
        }
        protected void CreateEDT(IBaseField baseField)
        {
            if (String.IsNullOrEmpty(baseField.ExtendedDataType) == false)
            {
                // There is already a EDT defined for this field
                return;
            }

            //  The Name of the edt to create should have the prefix as per the Settings
            //  If the Prefix already exists on the
            var modelSettings = Settings.FetchSettings.FindOrCreateSettings();
            var edtName       = baseField.Name;

            if (String.IsNullOrEmpty(modelSettings.Prefix) == false &&
                edtName.StartsWith(modelSettings.Prefix, StringComparison.InvariantCultureIgnoreCase) == false)
            {
                edtName = modelSettings.Prefix + edtName;
            }
            Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdt edtToCreate = null;

            if (baseField is IFieldContainer)
            {
                //var currentField = baseField as IFieldContainer;
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtContainer();
            }
            else if (baseField is IFieldDate)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtDate();
            }
            else if (baseField is IFieldEnum)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtEnum();
            }
            else if (baseField is IFieldGuid)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtGuid();
            }
            else if (baseField is IFieldInt)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtInt();
            }
            else if (baseField is IFieldReal)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtReal();
            }
            else if (baseField is IFieldString)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtString();
            }
            else if (baseField is IFieldTime)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtTime();
            }
            else if (baseField is IFieldUtcDateTime)
            {
                edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtUtcDateTime();
            }

            this.copyProperties(baseField, edtToCreate);
            edtToCreate.Name = edtName;

            if (edtToCreate != null)
            {
                // Find current model
                var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo();

                //Create menu item in the right model
                var metaModelProviders = ServiceLocator.GetService <IMetaModelProviders>() as IMetaModelProviders;
                var metaModelService   = metaModelProviders.CurrentMetaModelService;

                metaModelService.CreateExtendedDataType(edtToCreate, modelSaveInfo);

                //Update the table field with the EDT, also remove any labels from the field
                baseField.ExtendedDataType = edtToCreate.Name;
                baseField.Label            = String.Empty;
                baseField.HelpText         = String.Empty;

                // Add to the current active project
                Common.CommonUtil.AddElementToProject(edtToCreate);
            }
        }
Exemplo n.º 3
0
        public Metadata.MetaModel.AxEdt buildEdt()
        {
            Metadata.MetaModel.AxEdt edt;
            FieldType fieldType;

            edt = this.MetadataProvider.Edts.Read(this.controller.textBoxEDTName.Text);

            if (edt != null)
            {
                edtExist = true;
            }
            else
            {
                Enum.TryParse <FieldType>(this.controller.comboBoxFieldType.SelectedValue.ToString(), out fieldType);

                switch (fieldType)
                {
                case FieldType.String:
                    edt = new Metadata.MetaModel.AxEdtString();
                    break;

                case FieldType.Integer:
                    edt = new Metadata.MetaModel.AxEdtInt();
                    break;

                case FieldType.Real:
                    edt = new Metadata.MetaModel.AxEdtReal();
                    break;

                case FieldType.DateTime:
                    edt = new Metadata.MetaModel.AxEdtUtcDateTime();
                    break;

                case FieldType.Guid:
                    edt = new Metadata.MetaModel.AxEdtGuid();
                    break;

                case FieldType.Int64:
                    edt = new Metadata.MetaModel.AxEdtInt64();
                    break;

                case FieldType.Enum:
                    edt = new Metadata.MetaModel.AxEdtEnum();
                    break;

                case FieldType.Time:
                    edt = new Metadata.MetaModel.AxEdtTime();
                    break;

                case FieldType.Container:
                    edt = new Metadata.MetaModel.AxEdtContainer();
                    break;

                case FieldType.Memo:
                    edt = new Metadata.MetaModel.AxEdtString();
                    break;

                case FieldType.Date:
                    edt = new Metadata.MetaModel.AxEdtDate();
                    break;

                default:
                    throw new NotImplementedException($"Field type {this.controller.comboBoxFieldType.ToString()} is not supported");
                }
            }

            return(edt);
        }