Exemple #1
0
        private void TableNameTextBox_Validated(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(TableVarNameTextBox.Text) &&
                !String.IsNullOrWhiteSpace(TableNameTextBox.Text))
            {
                TableVarNameTextBox.Text = AxHelper.GetVarNameFromType(TableNameTextBox.Text.Trim());
                _parms.TableVarName      = TableVarNameTextBox.Text;
            }

            if (!String.IsNullOrWhiteSpace(TableNameTextBox.Text))
            {
                FormNameTextBox.Text = TableNameTextBox.Text;
                _parms.FormName      = FormNameTextBox.Text;
            }
        }
        public void Run()
        {
            _logString = "";
            ValidateData();
            if (_axHelper == null)
            {
                _axHelper = new AxHelper();
            }
            DoTableUpdate();

            DoFormCreate();

            if (IsCreateMenuItem)
            {
                DoMenuItemCreate();
            }
        }
Exemple #3
0
        private void TableLabelTextBox_Validated(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(TableLabelTextBox.Text))
            {
                FormLabelTextBox.Text = TableLabelTextBox.Text;
                _parms.FormLabel      = FormLabelTextBox.Text;

                FormHelpTextBox.Text = $"Set up {AxHelper.PrettyName(TableLabelTextBox.Text)}";
                _parms.FormHelp      = FormHelpTextBox.Text;

                PrivilegeLabelViewTextBox.Text = $"{_parms.FormLabel} view";
                _parms.PrivilegeLabelView      = PrivilegeLabelViewTextBox.Text;

                PrivilegeLabelMaintainTextBox.Text = $"{_parms.FormLabel} maintain";
                _parms.PrivilegeLabelMaintain      = PrivilegeLabelMaintainTextBox.Text;
            }
        }
Exemple #4
0
        private void TableNameTextBox_Validated(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(TableNameTextBox.Text))
            {
                FormNameTextBox.Text = TableNameTextBox.Text;
                _parms.FormName      = FormNameTextBox.Text;

                TableVarNameTextBox.Text = AxHelper.GetVarNameFromType(TableNameTextBox.Text.Trim());
                _parms.TableVarName      = TableVarNameTextBox.Text;
                if (!_parms.IsExternalEDT)
                {
                    PrimaryKeyEDTTextBox.Text = $@"{TableNameTextBox.Text}Id";
                    _parms.PrimaryKeyEdtName  = PrimaryKeyEDTTextBox.Text;
                }

                FieldNameTextBox.Text = $@"{AxHelper.UppercaseWords(TableVarNameTextBox.Text)}Id";
                _parms.KeyFieldName   = FieldNameTextBox.Text;
            }
        }
Exemple #5
0
        void CreateClass()
        {
            AxHelper axHelper = new AxHelper();

            NewAxClass = axHelper.MetadataProvider.Classes.Read(ClassName);
            //newAxClass = axHelper.MetadataProvider.Classes.Read("Tutorial_RunbaseBatch");
            if (NewAxClass != null)
            {
                throw new Exception($"Class {ClassName} already exists");
            }

            if (IsCreateMenuItem)
            {
                if (axHelper.MetadataProvider.MenuItemActions.Read(ClassName) != null)
                {
                    throw new Exception($"Menu item action {ClassName} already exists");
                }
            }

            NewAxClass = new AxClass {
                Name = ClassName
            };
            CreateClassMethods();

            axHelper.MetaModelService.CreateClass(NewAxClass, axHelper.ModelSaveInfo);
            axHelper.AppendToActiveProject(NewAxClass);

            AddLog($"Class: {NewAxClass.Name}; ");

            if (IsCreateMenuItem)
            {
                AxMenuItemAction axMenuItem = new AxMenuItemAction
                {
                    Name = ClassName, Object = ClassName, ObjectType = MenuItemObjectType.Class
                };
                axMenuItem.Label    = ClassDescription;
                axMenuItem.HelpText = $"{axMenuItem.Label} operation";
                axHelper.MetaModelService.CreateMenuItemAction(axMenuItem, axHelper.ModelSaveInfo);
                axHelper.AppendToActiveProject(axMenuItem);

                AddLog($"MenuItem: {axMenuItem.Name}; ");
            }
        }
        public void CreateEnum()
        {
            _logString = "";
            AxHelper axHelper = new AxHelper();

            AxEnum newEnum = axHelper.MetadataProvider.Enums.Read(EnumName);

            if (newEnum == null)
            {
                newEnum = new AxEnum {
                    Name = EnumName, Label = EnumLabel, Help = EnumHelpText, UseEnumValue = NoYes.No
                };

                axHelper.MetaModelService.CreateEnum(newEnum, axHelper.ModelSaveInfo);
                axHelper.AppendToActiveProject(newEnum);

                AddLog($"Enum {newEnum.Name};");

                if (IsCreateEnumType)
                {
                    AxEdtEnum newAxEdtEnum = axHelper.MetadataProvider.Edts.Read(EnumTypeName) as AxEdtEnum;
                    if (newAxEdtEnum == null)
                    {
                        newAxEdtEnum = new AxEdtEnum {
                            Name = EnumTypeName, EnumType = newEnum.Name
                        };

                        axHelper.MetaModelService.CreateExtendedDataType(newAxEdtEnum, axHelper.ModelSaveInfo);
                        axHelper.AppendToActiveProject(newAxEdtEnum);

                        AddLog($"Enum type {newAxEdtEnum.Name};");
                    }
                }
                newEnum = axHelper.MetadataProvider.Enums.Read(EnumName);
            }

            foreach (var ea in GetAxEnumValues())
            {
                newEnum.AddEnumValue(ea);
            }
            axHelper.MetaModelService.UpdateEnum(newEnum, axHelper.ModelSaveInfo);
        }
        void CreateClass()
        {
            AxHelper axHelper = new AxHelper();

            NewAxClass = axHelper.MetadataProvider.Classes.Read(ClassName);

            if (NewAxClass != null)
            {
                throw new Exception($"Class {ClassName} already exists");
            }

            NewAxClass = new AxClass {
                Name = ClassName
            };
            CreateClassMethodsContract();

            axHelper.MetaModelService.CreateClass(NewAxClass, axHelper.ModelSaveInfo);
            axHelper.AppendToActiveProject(NewAxClass);

            AddLog($"Class: {NewAxClass.Name}; ");
        }
        public void CreateTable()
        {
            _logString = "";
            ValidateData();
            if (_axHelper == null)
            {
                _axHelper = new AxHelper();
            }

            if (IsCreateTable)
            {
                DoEdtCreate();
                DoTableCreate();
            }

            if (IsCreateForm)
            {
                DoFormCreate();
                DoMenuItemCreate();
            }
        }
Exemple #9
0
        public string GetClassName(Kernel.ExtensionClassType elementType, ExtensionClassModeType classType,
                                   string prefixValue, string mainElementValue,
                                   string subElementValue)
        {
            ExtensionNameTemplate nameTemplate = AxModelSettings.ExtensionNameTemplateList[elementType];

            string templateString = classType == ExtensionClassModeType.EventHandler
                ? nameTemplate.EventHandlerTemplate
                : nameTemplate.ExtensionTemplate;

            string resultName = templateString;

            //String
            resultName = resultName.Replace(PrefixTemplateName, prefixValue);
            resultName = resultName.Replace(MainElementTemplateName, mainElementValue);
            resultName = resultName.Replace(SubElementTemplateName, subElementValue);

            resultName = AxHelper.RemoveSpecialCharacters(resultName).Replace(" ", "");

            return(resultName);
        }
        void SrcParmMethod(DataContractBuilderVar parmVar)
        {
            string mName = $"parm{AxHelper.UppercaseWords(parmVar.Name)}";

            CodeGenerate.SetMethodName(mName);

            CodeGenerate.AppendLine("[");
            CodeGenerate.IndentIncrease();
            CodeGenerate.ProcessLastSym(",");
            CodeGenerate.Append($"DataMemberAttribute(identifierStr({AxHelper.UppercaseWords(parmVar.Name)}))");
            if (!String.IsNullOrEmpty(parmVar.Label))
            {
                CodeGenerate.ProcessLastSym(",");
                CodeGenerate.Append($"SysOperationLabelAttribute(literalstr(\"{parmVar.Label}\"))");
            }
            if (!String.IsNullOrEmpty(parmVar.LabelHelp))
            {
                CodeGenerate.ProcessLastSym(",");
                CodeGenerate.Append($"SysOperationHelpTextAttribute(literalstr(\"{parmVar.LabelHelp}\"))");
            }
            if (!String.IsNullOrEmpty(parmVar.GroupName))
            {
                CodeGenerate.ProcessLastSym(",");
                CodeGenerate.Append($"SysOperationGroupMemberAttribute('{parmVar.GroupName}')");
            }
            if (parmVar.PositionInGroup > 0)
            {
                CodeGenerate.ProcessLastSym(",");
                CodeGenerate.Append($"SysOperationDisplayOrderAttribute('{parmVar.PositionInGroup.ToString()}')");
            }

            CodeGenerate.AppendLine("").IndentDecrease();
            CodeGenerate.AppendLine("]");

            CodeGenerate.AppendLine($"public {parmVar.Type} {mName}({parmVar.Type} _{parmVar.Name} = {parmVar.Name})");
            CodeGenerate.BeginBlock();
            CodeGenerate.AppendLine($"{parmVar.Name} = _{parmVar.Name};");
            CodeGenerate.AppendLine($"return {parmVar.Name};");
            CodeGenerate.EndBlock();
        }
        public string GetPreviewString()
        {
            AxHelper axHelperLocal = new AxHelper();
            List <NewFieldEngine> fieldsValuesList = GetFieldsValues();

            CheckData(fieldsValuesList, axHelperLocal);

            StringBuilder stringBuilder = new StringBuilder();

            if (IsContainsHeader)
            {
                stringBuilder.AppendLine("");
            }

            foreach (NewFieldEngine newFieldEngine in GetFieldsValues())
            {
                string edtType;
                if (newFieldEngine.EdtText != String.Empty)
                {
                    var edt = axHelperLocal.MetadataProvider.Edts.Read(newFieldEngine.EdtText);

                    if (edt != null)
                    {
                        edtType = "Existing EDT";
                    }
                    else
                    {
                        edtType = "New EDT     ";
                    }
                }
                else
                {
                    edtType = "No EDT      ";
                }
                stringBuilder.AppendLine($"{edtType}.{newFieldEngine.EdtText} FieldName name:{newFieldEngine.FieldName}; FieldType type:{newFieldEngine.FieldType};");
            }

            return(stringBuilder.ToString());
        }
Exemple #12
0
        public void InitFromSelectedElement(AddinDesignerEventArgs e)
        {
            if (_axHelper == null)
            {
                _axHelper = new AxHelper();
            }

            BaseField baseField = e.SelectedElements.OfType <BaseField>().First();

            SelectedField = baseField.Name;

            TableName = baseField.Table != null?baseField.Table.GetMetadataType().Name : baseField.TableExtension?.GetMetadataType().Name;

            NewFieldEngine newFieldEngine = new NewFieldEngine();

            newFieldEngine.GetSetHelper = _axHelper;

            if (TableName.Contains(".") == false)
            {
                _axTable = _axHelper.MetadataProvider.Tables.Read(TableName);
                AxTableField axTableField = _axTable.Fields[baseField.Name];

                TableRelationForeignKey = newFieldEngine.AddTableRelation(axTableField, _axTable.Relations);
            }
            else
            {
                _axTableExtension = _axHelper.MetadataProvider.TableExtensions.Read(TableName);
                AxTableField axTableField = _axTableExtension.Fields[baseField.Name];

                TableRelationForeignKey = newFieldEngine.AddTableRelation(axTableField, _axTableExtension.Relations);
            }

            if (TableRelationForeignKey == null)
            {
                throw new System.Exception($"Field {baseField.Name} doesn't have an EDT relation");
            }

            RelationName = TableRelationForeignKey.Name;
        }
        public void Run()
        {
            AxEdt axEdt = null;

            if (_axHelper == null)
            {
                _axHelper = new AxHelper();
            }

            if (EdtText != String.Empty)
            {
                axEdt = BuildEdt();
                if (!IsEdtExist && axEdt != null)
                {
                    _axHelper.MetaModelService.CreateExtendedDataType(axEdt, _axHelper.ModelSaveInfo);
                    _axHelper.AppendToActiveProject(axEdt);
                }
            }

            AxTableField axTableField = BuildField(axEdt);

            AddField(axTableField);
        }
Exemple #14
0
        public void CalcResultName()
        {
            string res = "";

            res += ElementName;
            if (ElementType == ExtensionClassObject.Form ||
                ElementType == ExtensionClassObject.FormDataSource ||
                ElementType == ExtensionClassObject.FormDataField ||
                ElementType == ExtensionClassObject.FormControl)
            {
                res += "Form";
            }

            res += Prefix;

            if (ClassType == ExtensionClassType.Extension)
            {
                if (!string.IsNullOrWhiteSpace(SubElementName))
                {
                    res += "_" + AxHelper.GetTypeNameFromLabel(SubElementName);
                }
            }

            switch (ClassType)
            {
            case ExtensionClassType.Extension:
                res += "_Extension";
                break;

            case ExtensionClassType.EventHandler:
                res += "_EventHandler";
                break;
            }

            ResultClassName = res;
        }
        void CreateControllerClass()
        {
            AxHelper axHelper = new AxHelper();

            NewAxClass = axHelper.MetadataProvider.Classes.Read(ClassNameController);

            if (NewAxClass != null)
            {
                CoreUtility.DisplayInfo($"Class {NewAxClass.Name} already exists");
                axHelper.AppendToActiveProject(NewAxClass);
            }
            else
            {
                NewAxClass = new AxClass {
                    Name = ClassNameController
                };
                CreateControllerMethods();

                axHelper.MetaModelService.CreateClass(NewAxClass, axHelper.ModelSaveInfo);
                axHelper.AppendToActiveProject(NewAxClass);

                AddLog($"Class: {NewAxClass.Name}; ");
            }
        }
        public bool Run()
        {
            if (ResultClassName.Length > 80)
            {
                throw new Exception($"Class name can't be more than 80 symbols({ResultClassName.Length})");
            }

            AxHelper axHelper = new AxHelper();

            AxClass newClass = axHelper.MetadataProvider.Classes.Read(ResultClassName);
            bool    res      = false;

            if (newClass == null)
            {
                res = true;
                //throw new Exception($"Class {ResultClassName} already exists");

                newClass = new AxClass {
                    IsFinal = true, Name = ResultClassName
                };

                if (ClassModeType == ExtensionClassModeType.EventHandler)
                {
                    newClass.IsStatic = true;
                }

                string typeStr = "";
                switch (ElementType)
                {
                case Kernel.ExtensionClassType.Form:
                    typeStr = "formstr";
                    break;

                case Kernel.ExtensionClassType.Class:
                    typeStr = "classstr";
                    break;

                case Kernel.ExtensionClassType.Table:
                    typeStr = "tablestr";
                    break;

                case Kernel.ExtensionClassType.FormDataField:
                    typeStr = "formdatafieldstr";
                    break;

                case Kernel.ExtensionClassType.FormDataSource:
                    typeStr = "formdatasourcestr";
                    break;

                case Kernel.ExtensionClassType.FormControl:
                    typeStr = "formcontrolstr";
                    break;

                case Kernel.ExtensionClassType.DataEntityView:
                    typeStr = "dataentityviewstr";
                    break;

                case Kernel.ExtensionClassType.View:
                    typeStr = "viewstr";
                    break;

                case Kernel.ExtensionClassType.Map:
                    typeStr = "mapstr";
                    break;
                }

                StringBuilder declarationText = new StringBuilder();
                if (ClassModeType == ExtensionClassModeType.Extension)
                {
                    if (string.IsNullOrWhiteSpace(SubElementName))
                    {
                        declarationText.AppendLine($"[ExtensionOf({typeStr}({ElementName}))]");
                    }
                    else
                    {
                        declarationText.AppendLine($"[ExtensionOf({typeStr}({ElementName}, {SubElementName}))]");
                    }
                }

                declarationText.AppendLine($"final{(newClass.IsStatic ? " static " : " ")}class {newClass.Name}");
                declarationText.AppendLine("{");
                declarationText.AppendLine("}");

                newClass.SourceCode.Declaration = declarationText.ToString();
                axHelper.MetaModelService.CreateClass(newClass, axHelper.ModelSaveInfo);

                axHelper.AppendToActiveProject(newClass);
                AddLog($"Class: {newClass.Name}; ");
            }
            else
            {
                CoreUtility.DisplayInfo($"Class {newClass.Name} already exists");
                axHelper.AppendToActiveProject(newClass);
            }

            return(res);
        }
        public override void InitFromSnippetsParms(SnippetsParms snippetsParms)
        {
            ClassName = snippetsParms.GetParmStr(ClassNameParm);
            GenerateReportController = snippetsParms.GetParmBool(GenerateReportControllerParm);
            GenerateReportDP         = snippetsParms.GetParmBool(GenerateReportDPParm);
            ReportDPTableName        = snippetsParms.GetParmStr(ReportDPTableNameParm);
            if (String.IsNullOrWhiteSpace(ReportDPTableName))
            {
                ReportDPTableName = "TableTemDB";
            }
            ReportDPTableVarName = AxHelper.GetVarNameFromType(ReportDPTableName);
            string baseStr = ClassName;

            if (ClassName.ToLower().EndsWith("contract"))
            {
                baseStr = ClassName.Substring(0, ClassName.Length - "contract".Length);
            }
            ClassNameDP         = $"{baseStr}DP";
            ClassNameController = $"{baseStr}Controller";

            List <List <string> > parmList = snippetsParms.GetParmListSeparated(ParametersParmName);

            FieldsList = new List <DataContractBuilderVar>();
            GroupsList = new List <DataContractBuilderVar>();
            int groupNum = 0;

            IsAnyMandatory = false;

            Dictionary <string, int> groutPosDict = new Dictionary <string, int>();

            foreach (List <string> subList in parmList)
            {
                DataContractBuilderVar builderVar = new DataContractBuilderVar();

                string item = subList[0];
                if (item[item.Length - 1] == MandatoryPropertySym)//check mandatory
                {
                    builderVar.IsMandatory = true;
                    builderVar.Type        = item.Remove(item.Length - 1).Trim();
                }
                else
                {
                    builderVar.IsMandatory = false;
                    builderVar.Type        = item;
                }

                if (String.IsNullOrEmpty(builderVar.Type))
                {
                    throw new Exception("Type should be specified");
                }

                if (subList.Count > 1 && !String.IsNullOrWhiteSpace(subList[1]))  //check var name
                {
                    builderVar.Name = subList[1];
                }
                else
                {
                    builderVar.Name = AxHelper.GetVarNameFromType(builderVar.Type);
                }
                if (subList.Count > 2 && !String.IsNullOrWhiteSpace(subList[2]))
                {
                    builderVar.Label = subList[2];
                }
                if (subList.Count > 3 && !String.IsNullOrWhiteSpace(subList[3]))
                {
                    builderVar.LabelHelp = subList[3];
                }
                if (subList.Count > 4 && !String.IsNullOrWhiteSpace(subList[4]))
                {
                    builderVar.GroupName = subList[4];
                }
                if (subList.Count > 5 && !String.IsNullOrWhiteSpace(subList[5]))
                {
                    builderVar.GroupLabel = subList[5];
                }

                //calculate
                if (!groutPosDict.ContainsKey(builderVar.GroupName))
                {
                    groutPosDict.Add(builderVar.GroupName, 0);
                    if (!String.IsNullOrWhiteSpace(builderVar.GroupName))
                    {
                        groupNum++;
                        var varGr = new DataContractBuilderVar
                        {
                            GroupName       = builderVar.GroupName,
                            GroupLabel      = builderVar.GroupLabel,
                            PositionInGroup = groupNum
                        };
                        GroupsList.Add(varGr);
                    }
                }
                groutPosDict[builderVar.GroupName]++;
                if (builderVar.IsMandatory)
                {
                    IsAnyMandatory = true;
                }

                builderVar.PositionInGroup = groutPosDict[builderVar.GroupName];

                FieldsList.Add(builderVar);
            }
        }
Exemple #18
0
        public void Run()
        {
            AxHelper axHelper = new AxHelper();

            AxClass newClass = axHelper.MetadataProvider.Classes.Read(ResultClassName);

            if (newClass != null)
            {
                throw new Exception($"Class {ResultClassName} already exists");
            }

            newClass = new AxClass {
                IsFinal = true, Name = ResultClassName
            };

            if (ClassType == ExtensionClassType.EventHandler)
            {
                newClass.IsStatic = true;
            }

            string typeStr = "";

            switch (ElementType)
            {
            case ExtensionClassObject.Form:
                typeStr = "formstr";
                break;

            case ExtensionClassObject.Class:
                typeStr = "classstr";
                break;

            case ExtensionClassObject.Table:
                typeStr = "tablestr";
                break;

            case ExtensionClassObject.FormDataField:
                typeStr = "formdatafieldstr";
                break;

            case ExtensionClassObject.FormDataSource:
                typeStr = "formdatasourcestr";
                break;

            case ExtensionClassObject.FormControl:
                typeStr = "formcontrolstr";
                break;

            case ExtensionClassObject.DataEntityView:
                typeStr = "dataentityviewstr";
                break;
            }

            StringBuilder declarationText = new StringBuilder();

            if (ClassType == ExtensionClassType.Extension)
            {
                if (string.IsNullOrWhiteSpace(SubElementName))
                {
                    declarationText.AppendLine($"[ExtensionOf({typeStr}({ElementName}))]");
                }
                else
                {
                    declarationText.AppendLine($"[ExtensionOf({typeStr}({ElementName}, {SubElementName}))]");
                }
            }

            declarationText.AppendLine($"final{(newClass.IsStatic ? " static " : " ")}class {newClass.Name}");
            declarationText.AppendLine("{");
            declarationText.AppendLine("}");

            newClass.SourceCode.Declaration = declarationText.ToString();
            axHelper.MetaModelService.CreateClass(newClass, axHelper.ModelSaveInfo);
            axHelper.AppendToActiveProject(newClass);

            AddLog($"Class: {newClass.Name}; ");
        }
Exemple #19
0
        public override void InitFromSnippetsParms(SnippetsParms snippetsParms)
        {
            ClassName        = snippetsParms.GetParmStr(ClassNameParm);
            ClassDescription = snippetsParms.GetParmStr(DescriptionParmName);
            QueryTable       = snippetsParms.GetParmStr(QueryTableParmName);
            ExternalTable    = snippetsParms.GetParmStr(ExternalTableNameParmName);
            switch (snippetsParms.GetParmStr(AddFileUploadParmName).ToLower())
            {
            case "y":
                IsAddFileUpload = FileUploadType.Normal;
                break;

            case "excel":
                IsAddFileUpload = FileUploadType.Excel;
                break;

            case "csv":
                IsAddFileUpload = FileUploadType.CSV;
                break;
            }
            IsCreateMenuItem = snippetsParms.GetParmBool(CreateMenuItemParmName);
            if (ExternalTable != "")
            {
                ExternalTableVar      = new RunBaseBuilderVar();
                ExternalTableVar.Type = ExternalTable;
                ExternalTableVar.Name = $"caller{ExternalTable}";
            }
            List <List <string> > parmList = snippetsParms.GetParmListSeparated(ParametersParmName);

            FieldsList = new List <RunBaseBuilderVar>();

            foreach (List <string> subList in parmList)
            {
                RunBaseBuilderVar runBaseBuilderVars = new RunBaseBuilderVar();

                string item = subList[0];
                if (item[item.Length - 1] == MandatoryPropertySym)//check mandatory
                {
                    runBaseBuilderVars.IsMandatory = true;
                    runBaseBuilderVars.Type        = item.Remove(item.Length - 1).Trim();
                }
                else
                {
                    runBaseBuilderVars.IsMandatory = false;
                    runBaseBuilderVars.Type        = item;
                }

                if (String.IsNullOrEmpty(runBaseBuilderVars.Type))
                {
                    throw new Exception("Type should be specified");
                }

                if (subList.Count > 1 && !String.IsNullOrWhiteSpace(subList[1]))  //check var name
                {
                    runBaseBuilderVars.Name = subList[1];
                }
                else
                {
                    runBaseBuilderVars.Name = AxHelper.GetVarNameFromType(runBaseBuilderVars.Type);
                }
                if (subList.Count > 2 && !String.IsNullOrWhiteSpace(subList[2]))
                {
                    runBaseBuilderVars.Label = subList[2];
                }
                if (subList.Count > 3 && !String.IsNullOrWhiteSpace(subList[3]))
                {
                    runBaseBuilderVars.LabelHelp = subList[3];
                }

                runBaseBuilderVars.DlgName = $"dlg{AxHelper.UppercaseWords(runBaseBuilderVars.Name)}";
                FieldsList.Add(runBaseBuilderVars);
            }
        }
        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;");
        }
Exemple #21
0
        public string GenerateResult()
        {
            int longestNameLength = (from x in Fields select x.FieldName.Length).Max();
            int longestTypeLength = (from x in Fields select x.FieldType.Length).Max();

            longestTypeLength = Math.Max("boolean".Length, longestTypeLength);
            longestTypeLength++;
            longestNameLength++;

            CodeGenerateHelper generateHelper = new CodeGenerateHelper {
                IndentGlobalValue = 4
            };


            generateHelper.AddColumnAlignInt("Type", longestTypeLength);
            generateHelper.AddColumnAlignInt("FieldName", longestNameLength);

            if (VarName == "")
            {
                VarName = AxHelper.PrettyName(TableName);
            }

            string mandatoryFields;

            if (IsCreateFind)
            {
                generateHelper.IndentSetValue(0);
                generateHelper.Append($"public static {TableName} find(");
                generateHelper.IndentSetAsCurrentPos();

                // build args and mandatory fields list
                mandatoryFields = "";
                bool isFirst = true;
                foreach (AxTableFieldParm df in Fields.OrderBy(x => x.Position))
                {
                    if (df.IsMandatory || df.FieldName == "RecId")
                    {
                        if (mandatoryFields.Length > 0)
                        {
                            mandatoryFields += " && ";
                        }
                        mandatoryFields += "_" + AxHelper.PrettyName(df.FieldName);
                    }

                    if (!isFirst)
                    {
                        generateHelper.AppendLine(",");
                    }
                    generateHelper.Append(df.FieldType, "Type");
                    generateHelper.Append($" _{AxHelper.PrettyName(df.FieldName)}");
                    isFirst = false;
                }

                generateHelper.AppendLine(",");
                generateHelper.Append("boolean", "Type");
                generateHelper.AppendLine(" _forUpdate = false)");

                //build method header
                generateHelper.IndentSetValue(0);
                generateHelper.AppendLine("{");
                generateHelper.IndentIncrease();

                generateHelper.AppendLine(TableName + " " + VarName + ";");
                generateHelper.AppendLine(";");

                //check for mandatory fields
                if (mandatoryFields != "")
                {
                    generateHelper.AppendLine("if (" + mandatoryFields + ")");
                    generateHelper.AppendLine("{");
                    generateHelper.IndentIncrease();
                }

                //selectForUpdate
                generateHelper.AppendLine(VarName + ".selectForUpdate(_forUpdate);");
                generateHelper.AppendLine("");

                //build select query
                generateHelper.AppendLine("select firstonly " + VarName);
                generateHelper.Append("    where ");
                generateHelper.IndentSetAsCurrentPos();

                isFirst = true;
                foreach (AxTableFieldParm df in Fields.OrderBy(x => x.Position))
                {
                    if (!isFirst)
                    {
                        generateHelper.AppendLine(" && ");
                    }
                    generateHelper.Append(VarName + ".");
                    generateHelper.Append(df.FieldName, "FieldName");

                    generateHelper.Append(" == _" + AxHelper.PrettyName(df.FieldName));
                    isFirst = false;
                }

                generateHelper.IndentRestorePrev();
                generateHelper.AppendLine(";");

                //footer
                if (mandatoryFields != "")
                {
                    generateHelper.IndentDecrease();
                    generateHelper.AppendLine("}");
                }

                generateHelper.AppendLine("");
                generateHelper.AppendLine("return " + VarName + ";");
                generateHelper.IndentDecrease();

                generateHelper.AppendLine("}");
            }

            if (IsCreateFindRecId)
            {
                generateHelper.IndentSetValue(0);

                generateHelper.AppendLine("");
                generateHelper.AppendLine($"public static {TableName} findRecId(RefRecId _recId,  _forUpdate = false)");

                //build method header
                generateHelper.AppendLine("{");
                generateHelper.IndentIncrease();
                generateHelper.AppendLine(TableName + " " + VarName + ";");
                generateHelper.AppendLine(";");

                generateHelper.AppendLine("if (_recId)");
                generateHelper.AppendLine("{");
                generateHelper.IndentIncrease();

                //selectForUpdate
                generateHelper.AppendLine(VarName + ".selectForUpdate(_forUpdate);");
                generateHelper.AppendLine("");

                //build select query
                generateHelper.AppendLine("select firstonly " + VarName);
                generateHelper.AppendLine("    where " + VarName + ".RecId == _recId;");
                generateHelper.IndentDecrease();
                generateHelper.AppendLine("}");
                generateHelper.AppendLine("");
                generateHelper.AppendLine("return " + VarName + ";");
                generateHelper.IndentDecrease();

                generateHelper.AppendLine("}");
            }

            if (IsCreateExists)
            {
                generateHelper.IndentSetValue(0);
                generateHelper.AppendLine("");

                generateHelper.Append("public static boolean exists(");
                generateHelper.IndentSetAsCurrentPos();

                // build args and mandatory fields list
                mandatoryFields = "";
                bool isFirst = true;
                foreach (AxTableFieldParm df in Fields.OrderBy(x => x.Position))
                {
                    if (df.IsMandatory || df.FieldName == "RecId")
                    {
                        if (mandatoryFields.Length > 0)
                        {
                            mandatoryFields += " && ";
                        }
                        mandatoryFields += "_" + AxHelper.PrettyName(df.FieldName);
                    }

                    if (!isFirst)
                    {
                        generateHelper.AppendLine(",");
                    }
                    generateHelper.Append(df.FieldType, "Type");
                    generateHelper.Append($" _{AxHelper.PrettyName(df.FieldName)}");
                    isFirst = false;
                }

                generateHelper.AppendLine(")");

                //build method header
                generateHelper.IndentSetValue(0);
                generateHelper.AppendLine("{");
                generateHelper.IndentIncrease();

                generateHelper.AppendLine("boolean res;");
                generateHelper.AppendLine(";");

                //check for mandatory fields
                if (mandatoryFields != "")
                {
                    generateHelper.AppendLine("if (" + mandatoryFields + ")");
                    generateHelper.AppendLine("{");
                    generateHelper.IndentIncrease();
                }


                //build select query
                generateHelper.AppendLine("res = (select firstonly RecId from " + TableName);
                generateHelper.Append("        where ");
                generateHelper.IndentSetAsCurrentPos();

                isFirst = true;
                foreach (AxTableFieldParm df in Fields.OrderBy(x => x.Position))
                {
                    if (!isFirst)
                    {
                        generateHelper.AppendLine(" && ");
                    }
                    generateHelper.Append(TableName + ".");
                    generateHelper.Append(df.FieldName, "FieldName");

                    generateHelper.Append(" == _" + AxHelper.PrettyName(df.FieldName));
                    isFirst = false;
                }

                generateHelper.IndentRestorePrev();
                generateHelper.AppendLine(").RecId != 0;");

                //footer
                if (mandatoryFields != "")
                {
                    generateHelper.IndentDecrease();
                    generateHelper.AppendLine("}");
                }

                generateHelper.AppendLine("");
                generateHelper.AppendLine("return res;");
                generateHelper.IndentDecrease();

                generateHelper.AppendLine("}");
            }

            var methodText = generateHelper.ResultString.ToString();

            return(methodText);
        }
Exemple #22
0
        void SrcRun()
        {
            CodeGenerate.SetMethodName("run");
            CodeGenerate.AppendLine("public void run()");
            CodeGenerate.BeginBlock();

            foreach (RunBaseBuilderVar df in FieldsList)
            {
                CodeGenerate.AppendLine($"info(strFmt(\"{df.Name}=%1\", {df.Name}));");
            }
            if (IsAddFileUpload != FileUploadType.None)
            {
                CodeGenerate.AppendLine("System.IO.MemoryStream memoryStreamFile;");
                CodeGenerate.AppendLine("try");
                CodeGenerate.AppendLine("{");
                CodeGenerate.AppendLine("    if (!fileUploadResult)");
                CodeGenerate.AppendLine("    {");
                CodeGenerate.AppendLine("        throw error(\"File is empty\");");
                CodeGenerate.AppendLine("    }");
                CodeGenerate.AppendLine("    //get file names");
                CodeGenerate.AppendLine("    container fileNameCon = Docu::splitFilename(fileUploadResult.getFileName());");
                CodeGenerate.AppendLine("    if (!fileNameCon)");
                CodeGenerate.AppendLine("    {");
                CodeGenerate.AppendLine("        throw error(\"File is empty\");");
                CodeGenerate.AppendLine("    }");
                CodeGenerate.AppendLine("    str fileName   = strFmt('%1.%2', conPeek(fileNameCon, 1), conPeek(fileNameCon, 2));");
                CodeGenerate.AppendLine("    str folderName = strFmt('%1', conPeek(fileNameCon, 3));");
                CodeGenerate.AppendLine("    //get file data");
                CodeGenerate.AppendLine("    memoryStreamFile = fileUploadResult.openResult();");
                switch (IsAddFileUpload)
                {
                case FileUploadType.CSV:
                    CodeGenerate.AppendLine("    //https://github.com/TrudAX/XppTools#devcommon-model");
                    CodeGenerate.AppendLine("    DEVFileReaderCSV   fileReader   = new DEVFileReaderCSV();");
                    CodeGenerate.AppendLine("    fileReader.readCSVFile(memoryStreamFile);");
                    CodeGenerate.AppendLine("    fileReader.readHeaderRow();");
                    CodeGenerate.AppendLine("    while (fileReader.readNextRow())");
                    CodeGenerate.AppendLine("    {");
                    CodeGenerate.AppendLine("        info(strFmt(\"row: % 1\", fileReader.getCurRow()));");
                    CodeGenerate.AppendLine("        info(strFmt(\" % 1, % 2, % 3\",");
                    CodeGenerate.AppendLine("            fileReader.getStringByName('Main account'),");
                    CodeGenerate.AppendLine("            fileReader.getStringByName('BusinessUnit'),");
                    CodeGenerate.AppendLine("            fileReader.getRealByName('Amount')");
                    CodeGenerate.AppendLine("            ));");
                    CodeGenerate.AppendLine("    }");
                    break;

                case FileUploadType.Excel:
                    CodeGenerate.AppendLine("    //https://github.com/TrudAX/XppTools#devcommon-model");
                    CodeGenerate.AppendLine("    DEVFileReaderExcel   fileReader   = new DEVFileReaderExcel();");
                    CodeGenerate.AppendLine("    fileReader.openFile(memoryStreamFile);");
                    CodeGenerate.AppendLine("    fileReader.readHeaderRow();");
                    CodeGenerate.AppendLine("    while (fileReader.readNextRow())");
                    CodeGenerate.AppendLine("    {");
                    CodeGenerate.AppendLine("        info(strFmt(\"row: % 1\", fileReader.getCurRow()));");
                    CodeGenerate.AppendLine("        info(strFmt(\" % 1, % 2, % 3\",");
                    CodeGenerate.AppendLine("            fileReader.getStringByName(\"Main account\"),");
                    CodeGenerate.AppendLine("            fileReader.getStringByName(\"BusinessUnit\"),");
                    CodeGenerate.AppendLine("            fileReader.getRealByName(\"Amount\")");
                    CodeGenerate.AppendLine("            ));");
                    CodeGenerate.AppendLine("    }");
                    break;

                default:
                    CodeGenerate.AppendLine("    AsciiStreamIo asciiIo = AsciiStreamIo::constructForRead(memoryStreamFile);");
                    CodeGenerate.AppendLine("    asciiIo.inRecordDelimiter('\\n');");
                    CodeGenerate.AppendLine("    while (asciiIo.status() == IO_Status::Ok)");
                    CodeGenerate.AppendLine("    {");
                    CodeGenerate.AppendLine("        container c = asciiIo.read();");
                    CodeGenerate.AppendLine("        if (conLen(c) > 0)");
                    CodeGenerate.AppendLine("        {");
                    CodeGenerate.AppendLine("            info(strFmt(\"File data:%1\", conPeek(c, 1)));");
                    CodeGenerate.AppendLine("        }");
                    CodeGenerate.AppendLine("    }");
                    break;
                }


                CodeGenerate.AppendLine("}");
                CodeGenerate.AppendLine("catch (Exception::Error)");
                CodeGenerate.AppendLine("{");
                CodeGenerate.AppendLine("    exceptionTextFallThrough();");
                CodeGenerate.AppendLine("}");
                CodeGenerate.AppendLine("finally");
                CodeGenerate.AppendLine("{");
                CodeGenerate.AppendLine("    fileUploadResult.deleteResult();");
                CodeGenerate.AppendLine("    memoryStreamFile = null;");
                CodeGenerate.AppendLine("}");
            }

            if (!String.IsNullOrEmpty(QueryTable))
            {
                string queryCursor = AxHelper.GetVarNameFromType(QueryTable);
                CodeGenerate.AppendLine("int                     processedCounter;");
                CodeGenerate.AppendLine("QueryBuildDataSource    qBDS;");
                CodeGenerate.AppendLine($"{QueryTable}    {queryCursor};");
                CodeGenerate.AppendLine("");
                CodeGenerate.AppendLine($"qBDS = queryRun.query().dataSourceTable(tableNum({QueryTable}));");
                CodeGenerate.AppendLine($"SysQuery::findOrCreateRange(qBDS, fieldnum({QueryTable}, RecId)).value(queryValue(\"\"));");
                CodeGenerate.AppendLine("");
                CodeGenerate.AppendLine("this.progressInit(RunBase::getDescription(classIdGet(this)),");
                CodeGenerate.AppendLine("                  SysQuery::countTotal(queryRun),");
                CodeGenerate.AppendLine("                  #AviSearch);");
                CodeGenerate.AppendLine("");
                CodeGenerate.AppendLine("while (queryRun.next())");
                CodeGenerate.BeginBlock();
                CodeGenerate.AppendLine($"{queryCursor} = queryRun.get(tablenum({QueryTable}));");
                CodeGenerate.AppendLine("");
                CodeGenerate.AppendLine("processedCounter++;");
                CodeGenerate.AppendLine("progress.incCount();");
                CodeGenerate.EndBlock();
                CodeGenerate.AppendLine("info(strfmt(\" %1 record(s) processed\", processedCounter));");
            }
            else
            {
                if (IsAddFileUpload == FileUploadType.None)
                {
                    CodeGenerate.AppendLine("if (! this.validate())");
                    CodeGenerate.AppendLine("{");
                    CodeGenerate.AppendLine("    throw error(\"Validation error\");");
                    CodeGenerate.AppendLine("}");
                    CodeGenerate.AppendLine("");
                    CodeGenerate.AppendLine("ttsbegin;");
                    CodeGenerate.AppendLine("");
                    CodeGenerate.AppendLine("ttscommit;");
                }
            }
            CodeGenerate.EndBlock();
        }