public object GetDynamicFormCode(string CallBack, Guid DynamicFormId, bool IsOnExitForm)
        {
            DesignCodeDTO model = null;

            using (DynamicFormService dynamicFormService = new DynamicFormService())
            {
                DynamicFormDTO DynamicFormDTO = new DynamicFormDTO(dynamicFormService.GetInfo(DynamicFormId));

                if (IsOnExitForm)
                {
                    model = new DesignCodeDTO()
                    {
                        Code          = DynamicFormDTO.OnExitFormCodeDesign.Code,
                        ID            = string.IsNullOrWhiteSpace(DynamicFormDTO.OnExitFormCodeDesign.ID) ? Guid.NewGuid().ToString() : DynamicFormDTO.OnExitFormCodeDesign.ID,
                        CodeType      = DesignCodeDTO.e_CodeType.DynamicForm,
                        CallBack      = CallBack,
                        Assemblies    = DynamicFormDTO.OnExitFormCodeDesign.Assemblies,
                        DynamicFormID = DynamicFormId,
                        DesignCode    = DynamicFormDTO.OnExitFormCodeDesign.DesignCode,
                        Diagram       = DynamicFormDTO.OnExitFormCodeDesign.Diagram.ToStringObj().Trim(),
                        CodeObjects   = DynamicFormDTO.OnExitFormCodeDesign.CodeObjects,
                    };
                }
                else
                {
                    model = new DesignCodeDTO()
                    {
                        Code          = DynamicFormDTO.OnEntryFormCodeDesign.Code,
                        ID            = string.IsNullOrWhiteSpace(DynamicFormDTO.OnEntryFormCodeDesign.ID) ? Guid.NewGuid().ToString() : DynamicFormDTO.OnEntryFormCodeDesign.ID,
                        CodeType      = DesignCodeDTO.e_CodeType.DynamicForm,
                        CallBack      = CallBack,
                        Assemblies    = DynamicFormDTO.OnEntryFormCodeDesign.Assemblies,
                        DynamicFormID = DynamicFormId,
                        DesignCode    = DynamicFormDTO.OnEntryFormCodeDesign.DesignCode,
                        Diagram       = DynamicFormDTO.OnEntryFormCodeDesign.Diagram.ToStringObj().Trim(),
                        CodeObjects   = DynamicFormDTO.OnEntryFormCodeDesign.CodeObjects,
                    };
                }
            }

            this.InitialData(model);
            return(model);
        }
 public object GetServiceTaskCode(string ElementId, Guid ProcessId)
 {
     using (TaskService taskService = new TaskService())
     {
         ServiceTaskDTO ServiceTaskDTO = new ServiceTaskDTO(taskService.GetInfo(ElementId, ProcessId));
         DesignCodeDTO  model          = new DesignCodeDTO()
         {
             Code        = ServiceTaskDTO.DesignCodeModel.Code,
             ID          = string.IsNullOrWhiteSpace(ServiceTaskDTO.DesignCodeModel.ID) ? Guid.NewGuid().ToString() : ServiceTaskDTO.DesignCodeModel.ID,
             CodeType    = DesignCodeDTO.e_CodeType.TaskServiceCode,
             CallBack    = "",
             Assemblies  = ServiceTaskDTO.DesignCodeModel.Assemblies,
             DesignCode  = ServiceTaskDTO.DesignCodeModel.DesignCode,
             Diagram     = ServiceTaskDTO.DesignCodeModel.Diagram.ToStringObj().Trim(),
             CodeObjects = ServiceTaskDTO.DesignCodeModel.CodeObjects,
         };
         this.InitialData(model);
         return(model);
     }
 }
        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);
            }
        }
        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>();
                }
            }
        }