public object PostLoadEmailForm(PostLoadEmailFormDTO model)
        {
            Guid?        dynamicFormId = model.DynamicFormId.ToGuidObjNull();
            DCEmailModel designCode    = null;

            if (!string.IsNullOrWhiteSpace(model.XmlB64Model))
            {
                designCode = DesignCodeUtility.GetObjectOfDesignCode <DCEmailModel>(model.XmlB64Model.ToStringObj().FromBase64());

                designCode.IsOutputYes = model.IsOutputYes;
            }
            else
            {
                designCode = new DCEmailModel(Guid.NewGuid().ToString(), "Email", model.ShapeId.ToStringObj(),
                                              model.ParentShapeId.ToStringObj(), model.IsOutputYes, model.IsFirst.ToBoolObj(), string.Empty, Guid.Empty, "", "", "");
            }

            using (DynamicFormService dynamicFormService = new DynamicFormService())
                using (EmailAccountService emailAccountService = new EmailAccountService())
                    return new
                           {
                               ListEmailAccounts = emailAccountService.GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.Systemic, null, null).Select(c => new QueryModel(c.ID.ToString(), c.Email)).ToList(),
                               DynamicFormId     = dynamicFormId,
                               ProcessControls   = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                   dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                               Model = designCode
                           };
        }
        public object PostLoadConditionForm(PostLoadConditionFormDTO model)
        {
            Guid?            dynamicFormId = model.DynamicFormId.ToGuidObjNull();
            DCConditionModel designCode;

            if (!string.IsNullOrWhiteSpace(model.Data))
            {
                designCode = DesignCodeUtility.GetObjectOfDesignCode <DCConditionModel>(model.Data.ToStringObj().FromBase64());

                designCode.IsOutputYes = model.IsOutputYes.ToBoolObjNull();
                if (string.IsNullOrWhiteSpace(designCode.FuncName))
                {
                    designCode.FuncName = DesignCodeUtility.GetFunctionName(designCode.ShapeID);
                }
            }
            else
            {
                designCode = new DCConditionModel(Guid.NewGuid().ToString(), model.Name.ToStringObj(),
                                                  model.ShapeId.ToStringObj(), model.ParentShapeId.ToStringObj(),
                                                  model.IsOutputYes.ToBoolObjNull(), new List <DCRowConditionModel>(), model.IsFirst.ToBoolObj(), null);
            }

            using (VariableService variableService = new VariableService())
                using (DynamicFormService dynamicFormService = new DynamicFormService())
                    return new
                           {
                               ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                 dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                               ListOperationTypes = EnumObjHelper.GetEnumList <DCRowConditionModel.e_OperationType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(),
                               Model = designCode
                           };
        }
        public object PostLoadSqlFunctionForm(PostLoadSqlFunctionFormDTO model)
        {
            Guid?dynamicFormId            = model.DynamicFormId.ToGuidObjNull();
            DCSqlFunctionModel designCode = null;

            if (!string.IsNullOrWhiteSpace(model.XmlB64Model))
            {
                designCode = DesignCodeUtility.GetObjectOfDesignCode <DCSqlFunctionModel>(model.XmlB64Model.ToStringObj().FromBase64());

                designCode.IsOutputYes = model.IsOutputYes;
            }
            else
            {
                designCode = new DCSqlFunctionModel(Guid.NewGuid().ToString(), "Sql Query", string.Empty, string.Empty
                                                    , model.ShapeId.ToStringObj(), model.ParentShapeId.ToStringObj(),
                                                    model.IsOutputYes, null, model.IsFirst.ToBoolObj(), string.Empty);
            }

            using (DynamicFormService dynamicFormService = new DynamicFormService())
                return new
                       {
                           ListMethodTypes = EnumObjHelper.GetEnumList <DCSqlFunctionModel.e_MethodType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(),
                           DynamicFormId   = dynamicFormId,
                           ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                             dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                           Model = designCode
                       };
        }
        public object PostLoadCallMethodForm(PostLoadCallMethodFormDTO model)
        {
            Guid?dynamicFormId = model.DynamicFormId.ToGuidObjNull();

            DCCallMethodModel designCode = null;

            if (!string.IsNullOrWhiteSpace(model.XmlB64Model.ToStringObj()))
            {
                designCode = DesignCodeUtility.GetObjectOfDesignCode <DCCallMethodModel>(model.XmlB64Model.ToStringObj().FromBase64());

                designCode.IsOutputYes = model.IsOutputYes;
            }
            else
            {
                designCode = new DCCallMethodModel(Guid.NewGuid().ToString(), string.Empty, model.ShapeId.ToStringObj(),
                                                   model.ParentShapeId.ToStringObj(), model.IsOutputYes, model.IsFirst, model.DefaultMethodID,
                                                   model.DefaultMethodGroupType);
            }
            using (DynamicFormService dynamicFormService = new DynamicFormService())
                return new
                       {
                           DynamicFormId   = dynamicFormId,
                           ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                             dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                           Model = designCode
                       };
        }
 public object GetJavaScriptIndex([System.Web.Http.FromUri] JavaScriptDesignCodeDTO codeVM)
 {
     if (codeVM != null && codeVM.Code.ToStringObj().ToLower().Trim() == "null")
     {
         codeVM.Code = string.Empty;
     }
     using (DynamicFormService dynamicFormService = new DynamicFormService())
         codeVM.GetControls = dynamicFormService.GetControls(dynamicFormService.GetInfo(codeVM.DynamicFormId)).Select(c => new QueryModel(c.Key, c.Value)).ToList();
     codeVM.GetAllJavaMethods = DesignCodeUtility.GetAllJavaMethods().Select(c => new QueryModel(c, c)).ToList();
     return(codeVM);
 }
        public object PostLoadExpressionCodeForm(PostLoadExpressionCodeFormDTO model)
        {
            DCExpressionModel designCode;
            Guid?dynamicFormId = model.DynamicFormId.ToGuidObjNull();

            if (!string.IsNullOrWhiteSpace(model.Data))
            {
                designCode             = DesignCodeUtility.GetObjectOfDesignCode <DCExpressionModel>(model.Data.FromBase64());
                designCode.IsOutputYes = model.IsOutputYes;
                if (string.IsNullOrWhiteSpace(designCode.FuncName))
                {
                    designCode.FuncName = DesignCodeUtility.GetFunctionName(designCode.ShapeID);
                }
            }
            else
            {
                designCode = new DCExpressionModel(Guid.NewGuid().ToString(), model.Name.ToStringObj(),
                                                   model.ShapeId.ToStringObj(), model.ParentShapeId.ToStringObj(),
                                                   "", model.IsOutputYes, model.IsFirst.ToBoolObj(), null);
            }
            designCode.Assemblies     = string.Join(",", designCode.Assemblies.ToStringObj().Split(',').Select(c => c.Trim()).ToList());
            designCode.ExpressionCode = designCode.ExpressionCode.ToStringObj().Replace("\\", "\\\\");
            using (DocumentFolderService documentFolderService = new DocumentFolderService())
                using (DepartmentService departmentService = new DepartmentService())
                    using (LURowService luRowService = new LURowService())
                        using (VariableService variableService = new VariableService())
                            using (DynamicFormService dynamicFormService = new DynamicFormService())
                                return new
                                       {
                                           GetAllSysMethods    = DesignCodeUtility.GetAllSysMethods().Select(c => new { Key = c }).ToList(),
                                           GetVariableMethods  = DesignCodeUtility.GetVariableMethods().Select(c => new { Key = c }).ToList(),
                                           GetMessageMethods   = DesignCodeUtility.GetMessageMethods().Select(c => new { Key = c }).ToList(),
                                           GetAccessMethods    = DesignCodeUtility.GetAccessMethods().Select(c => new { Key = c }).ToList(),
                                           GetHelperMethods    = DesignCodeUtility.GetHelperMethods().Select(c => new { Key = c }).ToList(),
                                           GetDocumentMethods  = DesignCodeUtility.GetDocumentMethods().Select(c => new { Key = c }).ToList(),
                                           GetAllSysProperties = DesignCodeUtility.GetAllSysProperties().Select(c => new { Key = c }).ToList(),

                                           AssembliesJson   = (Directory.Exists(BPMSResources.FilesRoot + BPMSResources.AssemblyRoot) ? new DirectoryInfo(BPMSResources.FilesRoot + BPMSResources.AssemblyRoot).GetFiles("*.dll").Select(c => new AssemblyDTO(c)).Select(c => new ComboTreeModel()
                                    {
                                        id = c.FileName, title = c.FileName
                                    }).ToList() : new List <ComboTreeModel>()),
                                           ApplicationPages = dynamicFormService.GetList(null, null, true, string.Empty, null, null).Select(c => new QueryModel(c.ApplicationPageID.ToString(), c.Name)).ToList(),
                                           DepartmentRoles  = luRowService.GetList("DepartmentRoleLU").Select(c => new LURowDTO(c)).ToList(),
                                           DepartmentList   = departmentService.GetList(true, "", null).Select(c => new { ID = $"new Guid(\"{ c.ID }\")", c.Name }),
                                           DocumentFolders  = documentFolderService.GetList(null, "", "", true).Select(c => new QueryModel(c.ID.ToString(), c.DisplayName)).ToList(),
                                           ProcessVariables = variableService.GetVariableAsComboTree(base.ProcessId, base.ApplicationPageId, null, "{0}"),
                                           ProcessControls  = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                              dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                                           Model = designCode
                                       };
        }
        private void InitialData(DesignCodeDTO codeDTO, Guid?dynamicFormId = null)
        {
            //codeDTO.DesignCodeData = (string.Join(",", codeDTO.CodeObjects.Select(c => string.Format("{{data:'{0}',shapeId:'{1}',id:'{2}'}}", (DesignCodeUtility.ConvertDesignCodeObjectToXml((c)).ToBase64()), ((DCBaseModel)c).ShapeID, ((DCBaseModel)c).ID))));
            codeDTO.DesignCodeData = codeDTO.CodeObjects.Select(c => new { data = DesignCodeUtility.ConvertDesignCodeObjectToXml((c)).ToBase64(), shapeId = ((DCBaseModel)c).ShapeID, id = ((DCBaseModel)c).ID }).ToList();
            using (VariableService variableService = new VariableService())
                codeDTO.ProcessVariables = variableService.GetVariableAsComboTree(base.ProcessId, base.ApplicationPageId, null, "{0}");
            codeDTO.AssembliesJson = Directory.Exists(BPMSResources.FilesRoot + BPMSResources.AssemblyRoot) ? new DirectoryInfo(BPMSResources.FilesRoot + BPMSResources.AssemblyRoot).GetFiles("*.dll").Select(c => new AssemblyDTO(c)).Select(c => new ComboTreeModel()
            {
                id = c.FileName, title = c.FileName
            }).ToList() : new List <ComboTreeModel>();
            using (DynamicFormService dynamicFormService = new DynamicFormService())
                codeDTO.ApplicationPages = dynamicFormService.GetList(null, null, true, string.Empty, null, null).Select(c => new QueryModel(c.ApplicationPageID.ToString(), c.Name)).ToList();

            using (LURowService luRowService = new LURowService())
                codeDTO.DepartmentRoles = luRowService.GetList("DepartmentRoleLU").Select(c => new LURowDTO(c)).ToList();
            using (DepartmentService departmentService = new DepartmentService())
                codeDTO.DepartmentList = departmentService.GetList(true, "", null).Select(c => new QueryModel($"new Guid(\"{ c.ID }\")", c.Name)).ToList();
            using (DocumentFolderService documentFolderService = new DocumentFolderService())
                codeDTO.DocumentFolders = documentFolderService.GetList(null, "", "", true).Select(c => new DocumentFolderDTO(c)).ToList();
            using (DynamicFormService dynamicFormService = new DynamicFormService())
            {
                if (dynamicFormId != Guid.Empty && dynamicFormId.HasValue)
                {
                    codeDTO.ProcessControls = dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList();
                }
                else
                if (base.ApplicationPageId.HasValue)
                {
                    codeDTO.ProcessControls = dynamicFormService.GetControls(dynamicFormService.GetInfoByPageID(base.ApplicationPageId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList();
                }
                else
                {
                    codeDTO.ProcessControls = new List <QueryModel>();
                }
            }
        }
        public object GetDynamicFormOnloadJavaCode(Guid DynamicFormId)
        {
            using (DynamicFormService dynamicFormService = new DynamicFormService())
            {
                JavaScriptDesignCodeDTO codeVM = new JavaScriptDesignCodeDTO()
                {
                    Code              = dynamicFormService.GetInfo(DynamicFormId).ConfigXmlModel?.OnLoadFunctionBody ?? string.Empty,
                    CallBack          = null,
                    GetControls       = dynamicFormService.GetControls(dynamicFormService.GetInfo(DynamicFormId)).Select(c => new QueryModel(c.Key, c.Value)).ToList(),
                    GetAllJavaMethods = DesignCodeUtility.GetAllJavaMethods().Select(c => new QueryModel(c, c)).ToList(),
                };

                return(codeVM);
            }
        }
        public object PostIndex(PostDesignCodePostIndexDTO requestModel)
        {
            Guid?           dynamicFormId = requestModel.DynamicFormId.ToGuidObjNull();
            DesignCodeModel codeModel     = DesignCodeUtility.GetDesignCodeFromXml(requestModel.DesignCode.ToStringObj());
            DesignCodeDTO   model         = new DesignCodeDTO()
            {
                Code          = codeModel?.Code,
                CodeType      = (DesignCodeDTO.e_CodeType)requestModel.CodeType,
                CallBack      = requestModel.CallBack.ToStringObj(),
                Assemblies    = codeModel?.Assemblies,
                ID            = string.IsNullOrWhiteSpace(codeModel.ID) ? Guid.NewGuid().ToString() : codeModel.ID,
                CodeObjects   = codeModel.CodeObjects,
                DynamicFormID = dynamicFormId,
                DesignCode    = codeModel.DesignCode,
                Diagram       = codeModel.Diagram.ToStringObj().Trim(),
            };

            if (model.CodeType == DesignCodeDTO.e_CodeType.ConditionCode)
            {
                Random           random           = new Random();
                DCConditionModel dcConditionModel = (DCConditionModel)model.CodeObjects?.FirstOrDefault() ??
                                                    new DCConditionModel(Guid.NewGuid().ToString(), "Condition", string.Empty, string.Empty, null, new List <DCRowConditionModel>(), true, "func" + random.Next(100, 100));
                using (VariableService variableService = new VariableService())
                    using (DynamicFormService dynamicFormService = new DynamicFormService())
                        return new
                               {
                                   OpenDirectly    = true,
                                   DesignCodeDTO   = model,
                                   ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                     dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                                   ProcessVariables   = variableService.GetVariableAsComboTree(base.ProcessId, base.ApplicationPageId, null, "{0}"),
                                   ListOperationTypes = EnumObjHelper.GetEnumList <DCRowConditionModel.e_OperationType>().Select(c => new QueryModel(c.Key.ToString(), c.Value)).ToList(),
                                   Model = dcConditionModel
                               };
            }
            else
            {
                this.InitialData(model, dynamicFormId);
                return(model);
            }
        }
        public object PostLoadEntityForm(PostLoadEntityFormDTO model)
        {
            Guid?         dynamicFormId = model.DynamicFormId.ToGuidObjNull();
            DCEntityModel designCode    = null;

            if (!string.IsNullOrWhiteSpace(model.XmlB64Model))
            {
                designCode             = DesignCodeUtility.GetObjectOfDesignCode <DCEntityModel>(model.XmlB64Model.ToStringObj().FromBase64());
                designCode.IsOutputYes = model.IsOutputYes;
            }
            else
            {
                designCode = new DCEntityModel(Guid.NewGuid().ToString(), string.Empty, model.ShapeId.ToStringObj(),
                                               model.ParentShapeId.ToStringObj(), model.IsOutputYes.ToBoolObjNull(),
                                               new List <DCEntityParametersModel>(), model.IsFirst.ToBoolObj(), model.DefaultMethodType);
            }

            using (EntityDefService entityDefService = new EntityDefService())
            {
                var listENtities = entityDefService.GetList(null, true);
                if (designCode.EntityDefID != Guid.Empty)
                {
                    designCode.Rows.ForEach((item) =>
                    {
                        item.IsRequired = listENtities.FirstOrDefault(c => c.ID == designCode.EntityDefID).AllProperties.FirstOrDefault(d => d.Name == item.ParameterName).Required;
                    });
                }
                using (DynamicFormService dynamicFormService = new DynamicFormService())
                    return new
                           {
                               ListEntities    = listENtities.Select(c => new EntityDefDTO(c)).ToList(),
                               DynamicFormId   = dynamicFormId,
                               ProcessControls = dynamicFormId != Guid.Empty && dynamicFormId.HasValue ?
                                                 dynamicFormService.GetControls(dynamicFormService.GetInfo(dynamicFormId.Value)).Select(c => new QueryModel(c.Key, c.Value)).ToList() : new List <QueryModel>(),
                               Model = designCode
                           };
            }
        }