Пример #1
0
        private UPMGroup GroupFromRow(UPCRMResultRow resultRow)
        {
            UPMDocumentsGroup docGroup             = null;
            string            recordIdentification = resultRow.RootRecordIdentification;
            int             fieldCount             = this.TabConfig.NumberOfFields;
            DocumentManager documentManager        = new DocumentManager();

            for (int j = 0; j < fieldCount; j++)
            {
                UPConfigFieldControlField fieldConfig = this.TabConfig.FieldAtIndex(j);
                string documentKey = resultRow.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                if (!string.IsNullOrEmpty(documentKey))
                {
                    DocumentData documentData = documentManager.DocumentForKey(documentKey);
                    if (documentData != null)
                    {
                        if (docGroup == null)
                        {
                            docGroup           = new UPMDocumentsGroup(this.TabIdentifierForRecordIdentification(recordIdentification));
                            docGroup.LabelText = this.TabLabel;
                        }

                        UPMDocument document = new UPMDocument(new RecordIdentifier(recordIdentification), fieldConfig.Label,
                                                               documentData.DateString, documentData.SizeString, null, documentData.Url, documentData.Title,
                                                               documentData.ServerUpdateDate, documentData.DisplayText, null);

                        docGroup.AddField(document);
                    }
                }
            }

            this.ControllerState = docGroup != null ? GroupModelControllerState.Finished : GroupModelControllerState.Empty;
            this.Group           = docGroup;
            return(docGroup);
        }
Пример #2
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);
        }
Пример #3
0
        private bool IsDocumentIncludedInGroup(UPMDocument document, UPMDocumentsGroup group)
        {
            var imageExtensions = new List <string> {
                ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".tif", ".bmp"
            };

            switch (group.Style)
            {
            case UPMDocumentsGroupStyle.Image:
            case UPMDocumentsGroupStyle.NoImages:
                bool   withImage  = group.Style == UPMDocumentsGroupStyle.Image;
                string lowerFname = document.LocalFileName.ToLower();
                return(imageExtensions.Any(extension => lowerFname.EndsWith(extension)) ? withImage : !withImage);

            default:
                return(true);
            }
        }
Пример #4
0
        /// <summary>
        /// The has local version of resource for document.
        /// </summary>
        /// <param name="resourceManager">
        /// The resource manager.
        /// </param>
        /// <param name="document">
        /// The document.
        /// </param>
        /// <returns>
        /// <see cref="bool"/>.
        /// </returns>
        public static bool HasLocalVersionOfResourceForDocument(
            this ResourceManager resourceManager,
            UPMDocument document)
        {
            var localVersion = false;

            if (document.Url != null)
            {
                localVersion = resourceManager.HasLocalVersionOfResourceForUrl(document.Url, document.LocalFileName);
            }

            if (!localVersion)
            {
                if (document.D1Url != null)
                {
                    localVersion = resourceManager.HasLocalVersionOfResourceForUrl(
                        document.D1Url,
                        document.LocalFileName);
                }
            }

            return(localVersion);
        }
Пример #5
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);
        }
Пример #6
0
 /// <summary>
 /// Sets the image for organizer header.
 /// </summary>
 /// <param name="imageDocument">The image document.</param>
 public void SetImageForOrganizerHeader(UPMDocument imageDocument)
 {
     this.Organizer.ImageDocument = imageDocument;
     this.InformAboutDidChangeTopLevelElement(this.Organizer, this.Organizer, null, UPChangeHints.ChangeHintsWithHint("RecordDataChanged"));
 }
Пример #7
0
        /// <summary>
        /// The resource for document.
        /// </summary>
        /// <param name="resourceManager">
        /// The resource manager.
        /// </param>
        /// <param name="document">
        /// The document.
        /// </param>
        /// <returns>
        /// The <see cref="UPResource"/>.
        /// </returns>
        public static Resource ResourceForDocument(this ResourceManager resourceManager, UPMDocument document)
        {
            Resource resource = null;

            if (document.Url != null)
            {
                resource = resourceManager.ResourceForUrl(document.Url, document.LocalFileName);
            }

            if (resource == null)
            {
                if (document.D1Url != null)
                {
                    resource = resourceManager.ResourceForUrl(document.D1Url, document.LocalFileName);
                }
            }

            return(resource);
        }
Пример #8
0
        private void LoadData(UPMObjectivesPage objectivesPage)
        {
            int itemCounter    = 0;
            int sectionCounter = 0;

            foreach (UPObjectivesGroup group in this.objectivesGroupArray)
            {
                UPMObjectivesSection section = this.CreateSectionIdentfier(group.Label, StringIdentifier.IdentifierWithStringId(group.GroupKey));
                foreach (UPObjectivesItem item in group.Items)
                {
                    UPMObjective mobjective = this.CreateObjectiveIdentfier(item, StringIdentifier.IdentifierWithStringId($"ObjectiveItem_{itemCounter}"));
                    if (item.Documents != null)
                    {
                        UPMDocumentsGroup documentGroup = new UPMDocumentsGroup(StringIdentifier.IdentifierWithStringId($"documentgroup{itemCounter}"));
                        foreach (DocumentData document in item.Documents)
                        {
                            UPMDocument documentModel = new UPMDocument(document);
                            documentGroup.AddChild(documentModel);
                        }

                        mobjective.AddGroup(documentGroup);
                    }

                    mobjective.ObjectiveItem = item;
                    Dictionary <string, UPEditFieldContext> itemEditFields = new Dictionary <string, UPEditFieldContext>();
                    for (int additionalFieldIndex = 0; additionalFieldIndex < item.AdditionalFields.Count; additionalFieldIndex++)
                    {
                        UPConfigFieldControlField field           = item.AdditionalFields[additionalFieldIndex];
                        RecordIdentifier          fieldIdentifier = new RecordIdentifier(field.Identification);
                        UPEditFieldContext        fieldContext    = null;
                        FieldAttributes           attributes      = field.Attributes;
                        if (attributes != null && attributes.Hide)
                        {
                            fieldContext = UPEditFieldContext.HiddenFieldFor(field, fieldIdentifier, item.Values[additionalFieldIndex]);
                        }
                        else if (attributes != null && attributes.ReadOnly)
                        {
                            fieldContext = UPEditFieldContext.ReadonlyFieldFor(field, fieldIdentifier, item.Values[additionalFieldIndex]);
                        }
                        else
                        {
                            fieldContext = UPEditFieldContext.FieldContextFor(field, fieldIdentifier, item.Values[additionalFieldIndex], (List <UPEditFieldContext>)null);
                        }

                        if (fieldContext?.Field != null)
                        {
                            string fieldIdentification = this.FieldIdentificationSectionCounterItemCounter(field.Field, sectionCounter, itemCounter);
                            this.editPageContext.EditFields.SetObjectForKey(fieldContext, fieldIdentification);
                            itemEditFields.SetObjectForKey(fieldContext, fieldIdentification);
                            if (fieldContext.EditField != null)
                            {
                                fieldContext.EditField.EditFieldsContext = this.editPageContext;
                                mobjective.AddField(fieldContext.EditField);
                            }
                            else
                            {
                                mobjective.AddField(fieldContext.Field);
                            }
                        }
                    }

                    this.HandleDependentFieldsSectionCounterItemCounter(itemEditFields, sectionCounter, itemCounter);
                    if (item.ButtonActions.Count > 0)
                    {
                        List <UPMOrganizerAction> buttonActions = new List <UPMOrganizerAction>();
                        foreach (UPConfigButton button in item.ButtonActions)
                        {
                            StringIdentifier   fieldIdentifier = StringIdentifier.IdentifierWithStringId("button");
                            UPMOrganizerAction action          = new UPMOrganizerAction(fieldIdentifier);
                            //action.SetTargetAction(this.ParentOrganizerModelController, PerformObjectivesAction);
                            action.ViewReference = button.ViewReference.ViewReferenceWith(item.Record.RecordIdentification);
                            action.LabelText     = button.Label;
                            buttonActions.Add(action);
                        }

                        mobjective.Actions = buttonActions;
                    }

                    section.AddChild(mobjective);
                    itemCounter++;
                }

                if (section.Children.Count > 0)
                {
                    objectivesPage.AddChild(section);
                }
            }

            if (objectivesPage.Children.Count == 0)
            {
                UPMMessageStatus messageStatus = new UPMMessageStatus(StringIdentifier.IdentifierWithStringId("messageIdentifier"));
                UPMStringField   messageField  = new UPMStringField(StringIdentifier.IdentifierWithStringId("statusFieldIdentifier"));
                messageField.FieldValue          = LocalizedString.Localize(LocalizationKeys.TextGroupBasic, LocalizationKeys.KeyBasicNoObjectives);
                messageStatus.DetailMessageField = messageField;
                objectivesPage.Status            = messageStatus;
            }
        }
        /// <summary>
        /// Searches the operation did finish with result.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="result">The result.</param>
        public void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult result)
        {
            if (this.documentQuery != null && result.MetaInfo == this.documentQuery)
            {
                if (result.RowCount > 0)
                {
                    string documentKey = result.ResultRowAtIndex(0).RawValueAtIndex(0);
                    if (!string.IsNullOrEmpty(documentKey))
                    {
                        DocumentData documentData = new DocumentManager().DocumentForKey(documentKey);
                        if (documentData != null)
                        {
                            bool            downloaded      = false;
                            Uri             downloadUrl     = ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(documentData.RecordIdentification, documentData.Title);
                            ResourceManager resourceManager = SmartbookResourceManager.DefaultResourceManager;
                            Resource        resource        = resourceManager.ResourceForUrl(downloadUrl, documentData.Title);
                            if (resource == null && this.reportFileName != null && this.reportFileName != documentData.Title)
                            {
                                Uri alternateDownloadUrl = ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(documentData.RecordIdentification, this.reportFileName);
                                resource = resourceManager.ResourceForUrl(alternateDownloadUrl, this.reportFileName);
                                if (resource != null)
                                {
                                    UPMDocument document = new UPMDocument(documentData);
                                    resourceManager.QueueHighPriorityDownloadForResourceAtUrl(document.Url, document.LocalFileName, document.ModificationDate, true);
                                }
                            }

                            if (resource != null)
                            {
                                //NSFileManager fileManager = NSFileManager.DefaultManager();
                                //NSDictionary attributes = fileManager.AttributesOfItemAtPathError(resource.LocalUrl.Path, null);
                                //if (attributes.FileSize)
                                //{
                                //    downloaded = true;
                                //}
                                //else
                                //{
                                //    fileManager.RemoveItemAtPathError(resource.LocalUrl.Path, null);
                                //}
                            }

                            this.LocalUrlOfReportPdf = resource.LocalUrl;
                            if (!downloaded)
                            {
                                UPMDocument      document = new UPMDocument(documentData);
                                ResourceDownload download = resourceManager.QueueHighPriorityDownloadForResourceAtUrl(document.Url, document.LocalFileName, document.ModificationDate, true);
                                this.LocalUrlOfReportPdf = download.LocalUrl;
                            }
                        }
                    }
                }

                this.documentQuery = null;
                Page oldPage = this.Page;
                base.BuildPage();
                if (this.Page != oldPage)
                {
                    base.UpdateElementForCurrentChanges(null);
                }

                return;
            }

            if (result.MetaInfo == this.currentQuery)
            {
                if (result.RowCount >= 1)
                {
                    this.SerialEntryApproved = UPMSerialEntryState.Approved;
                    ((UPWebContentMetadataClientReport)this.WebContentMetadata).ClearSignature();
                }
                else
                {
                    this.SerialEntryApproved = UPMSerialEntryState.NotApproved;
                }

                this.currentQuery = null;
            }

            if (result.MetaInfo == this.emailFilterQuery)
            {
                this.SendByEmailButtonIsShown = result.RowCount >= 1;
                this.emailFilterQuery         = null;
            }

            if (this.emailFilterQuery == null)
            {
                this.shouldWaitForPendingChanges = false;
                if (this.unreportedRecordChanges != null)
                {
                    List <IIdentifier> changedRecords = this.unreportedRecordChanges;
                    this.unreportedRecordChanges = null;
                    this.ParentOrganizerModelController.ProcessChanges(changedRecords);
                }
                else
                {
                    base.BuildClientReportForPage((UPMWebContentPage)this.Page, false);
                }
            }
            else
            {
                this.emailFilterQuery.Find(UPRequestOption.FastestAvailable, this);
            }
        }