private void UpdatePageFromQueryResult(UPCRMResult result)
        {
            this.QueryResult = result;
            UPMGridPage      searchPage = (UPMGridPage)this.CreatePageInstance();
            Page             oldPage = this.Page;
            int              i, j;
            int              columnCount         = result.ColumnCount;
            StringIdentifier identifier          = StringIdentifier.IdentifierWithStringId("columnHeader");
            UPMResultSection section             = new UPMResultSection(identifier);
            UPMResultRow     columnHeaderListRow = new UPMResultRow(identifier);
            var              fieldArray          = new List <UPMField>();

            searchPage.FixedFirstColumn = false;
            searchPage.ShowMenu         = true;
            searchPage.SumRowAtEnd      = false;
            for (i = 0; i < columnCount; i++)
            {
                UPContainerFieldMetaInfo fieldMetaInfo = result.ColumnFieldMetaInfoAtIndex(i);
                string fieldType = fieldMetaInfo.CrmFieldInfo.FieldType;
                if (fieldType == "F" || fieldType == "L" || fieldType == "S")
                {
                    searchPage.SetColumnInfoAtIndexDataTypeSpecialSort(i, UPMColumnDataType.Numeric, false);
                }
                else if (fieldType == "D")
                {
                    searchPage.SetColumnInfoAtIndexDataTypeSpecialSort(i, UPMColumnDataType.Date, true);
                }

                UPMGridColumnHeaderStringField field = new UPMGridColumnHeaderStringField(StringIdentifier.IdentifierWithStringId($"col {i}"))
                {
                    StringValue = result.ColumnNameAtIndex(i)
                };
                fieldArray.Add(field);
            }

            columnHeaderListRow.Fields = fieldArray;
            section.AddResultRow(columnHeaderListRow);
            searchPage.AddResultSection(section);
            int           numberOfResultTables = result.NumberOfResultTables;
            List <object> contextMenuOptions   = new List <object>(numberOfResultTables);
            var           configStore          = ConfigurationUnitStore.DefaultStore;

            for (j = 0; j < numberOfResultTables; j++)
            {
                string infoAreaId    = result.ResultTableAtIndex(j).InfoAreaId;
                string infoAreaLabel = string.Empty;
                if (infoAreaId?.Length > 0)
                {
                    InfoArea       configInfoArea = configStore.InfoAreaConfigById(infoAreaId);
                    UPConfigExpand expand         = configStore.ExpandByName(infoAreaId);
                    FieldControl   fieldControl   = configStore.FieldControlByNameFromGroup("Details", expand.FieldGroupName);
                    if (configInfoArea != null && expand != null && fieldControl != null)
                    {
                        infoAreaLabel = LocalizedString.TextAnalysesShowParam.Replace("%@", configInfoArea.SingularName);
                    }
                }

                contextMenuOptions.Add(infoAreaLabel);
            }

            for (i = 0; i < result.RowCount; i++)
            {
                identifier = StringIdentifier.IdentifierWithStringId($"row {i}");
                var listRow = new UPMResultRow(identifier);
                var crmRow  = result.ResultRowAtIndex(i) as UPCRMResultRow;
                fieldArray = new List <UPMField>();
                var v = crmRow.Values();
                for (j = 0; j < v.Count; j++)
                {
                    UPMStringField field2 = new UPMStringField(StringIdentifier.IdentifierWithStringId($"cell{i}_{j}"))
                    {
                        StringValue    = v[j],
                        RawStringValue = crmRow.RawValueAtIndex(j)
                    };
                    fieldArray.Add(field2);
                }

                listRow.Fields = fieldArray;
                section.AddResultRow(listRow);
                for (j = 0; j < numberOfResultTables; j++)
                {
                    var label = contextMenuOptions[j] as string;
                    if (label.Length == 0)
                    {
                        continue;
                    }

                    string recordIdentification = crmRow.RecordIdentificationAtIndex(j);
                    if (recordIdentification?.Length > 0)
                    {
                        UPMOrganizerAnalysisShowRecordAction showRecordAction = new UPMOrganizerAnalysisShowRecordAction(StringIdentifier.IdentifierWithStringId($"action.row {i} record {j}"))
                        {
                            RecordIdentification = recordIdentification
                        };
                        showRecordAction.SetTargetAction(this, this.PerformShowRecordAction);
                        showRecordAction.LabelText = label;
                        listRow.AddDetailAction(showRecordAction);
                    }
                }
            }

            this.TopLevelElement = searchPage;
            this.InformAboutDidChangeTopLevelElement(oldPage, searchPage, null, null);
        }
Exemple #2
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);
        }