private string CreateFolderDelegate(string parentFolderId, string childrenFolderId, bool withSubfolders)
    {
        if (string.IsNullOrEmpty(parentFolderId) || string.IsNullOrEmpty(childrenFolderId))
        {
            return(null);
        }

        Folder childrenFolder = folderCard.GetFolder(new Guid(childrenFolderId));

        if (childrenFolder == null)
        {
            return(null);
        }

        // Если папка там уже создана, то ничего не делаем
        string insideFolderId = findFolder(parentFolderId.ToString(), childrenFolder.Name);

        if (insideFolderId != null)
        {
            return(null);
        }

        Folder folderDelegate = folderCard.CreateFolder(new Guid(parentFolderId.ToString()), childrenFolder.Name);

        folderDelegate.Type          = FolderTypes.Delegate;
        folderDelegate.RefId         = new Guid(childrenFolder.Id.ToString());
        folderDelegate.DefaultViewId = childrenFolder.DefaultViewId;
        if (withSubfolders)
        {
            folderDelegate.Flags = FolderFlags.VirtualWithSubfolders;
        }
        return(folderDelegate.Id.ToString());
    }
        /// <summary>
        /// Инициализирует папку заданными значениями.
        /// </summary>
        /// <param name="Device">Прибор.</param>
        /// <param name="CodeID">ID кода СКБ.</param>
        /// <param name="CodeName">Отобразаемое значение кода СКБ.</param>
        /// <param name="DocumentID">ID документа.</param>
        /// <param name="DocumentName">Название документа.</param>
        /// <param name="FolderID">ID папки.</param>
        public DocumentsFolder(Folder ParentFolder, CardData Document, SavedSearchGroup SearchGroup, SavedView View, FolderCard FolderCard)
        {
            this.ParentFolder = ParentFolder;
            this.Document     = Document;
            DocumentID        = Document.Id;

            SectionData Properties = Document.Sections[CardOrd.Properties.ID];

            DocumentType = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.FileType + "'").GetString("Value");
            RowData Code = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Code + "'");

            CodeID   = Code.GetGuid("Value").Value;
            CodeName = Code.GetString("DisplayValue");
            RowData Applicable = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Applicable + "'");

            Applicability = Applicable.GetString("DisplayValue");
            RowData Name = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.DocumentName + "'");

            string ShortType = DocumentType == "СД - Спецификация (не платы)" || DocumentType == "СП - Спецификация платы" ? "" : DocumentType.Remove(DocumentType.IndexOf(" - "));

            DocumentName = CodeName + " " + ShortType + " " + Name.GetString("Value");

            Folder      = FolderCard.CreateFolder(ParentFolder.Id, DocumentName);
            Folder.Type = FolderTypes.Virtual;

            if (!SearchGroup.Queries.Any(row => row.Name == DocumentName))
            {
                SearchQuery   Query    = FolderCard.Session.CreateSearchQuery();
                CardTypeQuery CardType = Query.AttributiveSearch.CardTypeQueries.AddNew(CardOrd.ID);
                SectionQuery  Section  = CardType.SectionQueries.AddNew(CardOrd.MainInfo.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.MainInfo.Type, FieldType.RefId, ConditionOperation.Equals, MyHelper.RefType_CD);

                Section           = CardType.SectionQueries.AddNew(CardOrd.Properties.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.Unistring, ConditionOperation.Equals, DocumentType);
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.FileType);

                Section           = CardType.SectionQueries.AddNew(CardOrd.Properties.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.RefId, ConditionOperation.Equals, CodeID);
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.Code);
                Query.Limit = 0;
                SearchGroup.Queries.AddNew(DocumentName).Import(Query);
            }
            SavedSearchQuery SavedQuery = SearchGroup.Queries.First(row => row.Name == DocumentName);

            Folder.RefId = SavedQuery.Id;

            Folder.CurrentViewId = View.Id;
            Folder.DefaultViewId = View.Id;
        }