Esempio n. 1
0
        private bool FillGroupWithLocalDocumentsResult(UPMDocumentsGroup group, UPCRMResult result)
        {
            if (this._sendEmailFieldgroup != null)
            {
                this._linkedRecordId = this.RecordIdentification;
            }

            int count = result.RowCount;

            if (count == 0)
            {
                return(false);
            }

            if (this.MaxResults > 0 && count > this.MaxResults)
            {
                count = this.MaxResults;
            }

            DocumentInfoAreaManager documentInfoAreaManager;

            if (this.fieldControl.InfoAreaId == "D3" && this.TabConfig.Type.StartsWith("D1"))
            {
                documentInfoAreaManager = new DocumentInfoAreaManager(this.fieldControl.InfoAreaId, this.fieldControl, 1, null);
            }
            else
            {
                documentInfoAreaManager = new DocumentInfoAreaManager(this.fieldControl.InfoAreaId, this.fieldControl, null);
            }

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow resultRow    = (UPCRMResultRow)result.ResultRowAtIndex(i);
                DocumentData   documentData = documentInfoAreaManager.DocumentDataForResultRow(resultRow);
                UPMDocument    document     = new UPMDocument(documentData);
                if (this._sendEmailFieldgroup != null)
                {
                    document.LinkedRecordId  = this._linkedRecordId;
                    document.EmailFieldgroup = this._sendEmailFieldgroup;
                }

                if (this.IsDocumentIncludedInGroup(document, group))
                {
                    group.AddField(document);
                }
            }

            if (group.Fields.Count == 0)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Searches the operation did finish with result.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="searchResult">The search result.</param>
        public void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult searchResult)
        {
            if (searchResult != null && searchResult.RowCount > 0)
            {
                DocumentInfoAreaManager documentInfoAreaManager = new DocumentInfoAreaManager(this.documentFieldControl.InfoAreaId, this.documentFieldControl, null);
                this.documentArray = new List <DocumentData>();
                for (int i = 0; i < searchResult.RowCount; i++)
                {
                    UPCRMResultRow resultRow = (UPCRMResultRow)searchResult.ResultRowAtIndex(i);
                    DocumentData   document  = documentInfoAreaManager.DocumentDataForResultRow(resultRow);
                    this.documentArray.Add(document);
                }
            }

            this.DocumentDelegate?.ObjectivesDocumentDidFinishFromSender(this);
        }
Esempio n. 3
0
        private bool FillPageWithDocumentsResult(UPMDocumentPage page, UPCRMResult result)
        {
            int count = result?.RowCount ?? 0;

            if (count == 0)
            {
                return(false);
            }

            UPMDocumentSection lastSection = null;
            int groupingIndex = -1;

            for (int i = 0; i < result.ColumnCount; i++)
            {
                if (result.ColumnFieldMetaInfoAtIndex(i).FunctionName == "groupingKey")
                {
                    groupingIndex = i;
                    break;
                }
            }

            page.AvailableGrouping = groupingIndex != -1;
            DocumentInfoAreaManager documentInfoAreaManager         = new DocumentInfoAreaManager(this.preparedSearch.CombinedControl.InfoAreaId, this.preparedSearch.CombinedControl, null);
            Dictionary <string, UPMDocumentSection> groupDictionary = new Dictionary <string, UPMDocumentSection>();

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow resultRow    = (UPCRMResultRow)result.ResultRowAtIndex(i);
                DocumentData   documentData = documentInfoAreaManager.DocumentDataForResultRow(resultRow);
                string         groupValue   = string.Empty;
                if (groupingIndex != -1)
                {
                    groupValue = resultRow.ValueAtIndex(groupingIndex);
                }

                UPMDocumentSection section;
                bool isLastSection;
                if (string.IsNullOrEmpty(groupValue))
                {
                    groupValue    = "#";
                    isLastSection = true;
                    section       = lastSection;
                }
                else
                {
                    isLastSection = false;
                    section       = groupDictionary.ValueOrDefault(groupValue);
                }

                if (section == null)
                {
                    section = new UPMDocumentSection(StringIdentifier.IdentifierWithStringId(groupValue))
                    {
                        GroupName = new UPMStringField(StringIdentifier.IdentifierWithStringId(groupValue))
                        {
                            StringValue = groupValue
                        }
                    };
                    if (isLastSection)
                    {
                        lastSection = section; // Dont add to page here # should always be the last
                    }
                    else
                    {
                        groupDictionary.SetObjectForKey(section, groupValue);
                        page.AddChild(section);
                    }
                }

                UPMDocument document = new UPMDocument(documentData);
                section.AddChild(document);
            }

            if (lastSection != null)
            {
                page.AddChild(lastSection);
            }

            return(true);
        }
        /// <summary>
        /// Starts the download.
        /// </summary>
        /// <returns>downloaded file counf</returns>
        public int StartDownload()
        {
            var fieldControl = ConfigurationUnitStore.DefaultStore.FieldControlByNameFromGroup(
                "List",
                this.FieldGroupName);

            if (fieldControl == null)
            {
                return(0);
            }

            var crmQuery = new UPContainerMetaInfo(fieldControl);
            var result   = crmQuery.ReadRecord(this.RecordIdentification);

            if (result.RowCount == 0)
            {
                return(0);
            }

            var resourceManager = SmartbookResourceManager.DefaultResourceManager;
            var currentSession  = ServerSession.CurrentSession;
            var row             = result.ResultRowAtIndex(0);

            if (this.DocumentFromFields)
            {
                var count = 0;
                foreach (var tab in fieldControl.Tabs)
                {
                    foreach (var field in tab.Fields)
                    {
                        string value = row.ValueAtIndex(field.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(value))
                        {
                            continue;
                        }

                        ++count;
                        var docData = this.DocumentManager.DocumentForKey(value);
                        if (docData != null)
                        {
                            resourceManager.QueueLowPriorityDownloadForResourceAtUrl(
                                currentSession.DocumentRequestUrlForRecordIdentification(this.RecordIdentification, docData.Title), docData.ServerUpdateDate);
                        }
                        else
                        {
                            resourceManager.QueueLowPriorityDownloadForResourceAtUrl(currentSession.DocumentRequestUrlForDocumentKey(value), null);
                        }
                    }
                }

                return(count);
            }

            var documentInfoAreaManager = new DocumentInfoAreaManager(fieldControl.InfoAreaId, fieldControl, null);
            var documentData            = documentInfoAreaManager.DocumentDataForResultRow(row as UPCRMResultRow);

            resourceManager.QueueLowPriorityDownloadForResourceAtUrl(
                currentSession.DocumentRequestUrlForRecordIdentification(this.RecordIdentification, documentData.Title), documentData.ServerUpdateDate);

            return(1);
        }