private UPMGroup GroupFromRow(UPCRMResultRow resultRow)
        {
            if (resultRow.IsNewRow)
            {
                if (this.AddRecordEnabled)
                {
                    this.Group           = this.GroupFromChildResult(null);
                    this.ControllerState = GroupModelControllerState.Finished;
                }
                else
                {
                    this.Group           = null;
                    this.ControllerState = GroupModelControllerState.Empty;
                }

                return(this.Group);
            }

            UPContainerMetaInfo childMetaInfo = new UPContainerMetaInfo(this.ChildFieldControl);

            this.LinkRecordIdentification = resultRow.RootRecordIdentification;
            childMetaInfo.SetLinkRecordIdentification(this.LinkRecordIdentification, this.LinkId);
            if (this.RequestOption == UPRequestOption.Offline || this.RequestOption == UPRequestOption.FastestAvailable)
            {
                UPCRMResult childResult = childMetaInfo.Find();
                if (childResult.RowCount > 0)
                {
                    this.ControllerState = GroupModelControllerState.Finished;
                    return(this.GroupFromChildResult(childResult));
                }
            }

            if (this.RequestOption != UPRequestOption.Offline)
            {
                Operation operation = childMetaInfo.Find(this);
                if (operation != null)
                {
                    this.ControllerState = GroupModelControllerState.Error;
                    return(null);
                }
                else
                {
                    this.ControllerState = GroupModelControllerState.Pending;
                    return(null);
                }
            }
            else
            {
                this.ControllerState = GroupModelControllerState.Empty;
                return(this.GroupFromChildResult(null));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPSyncDocumentDownloadFieldGroupUrlCache"/> class.
        /// </summary>
        /// <param name="fieldGroupName">
        /// Name of the field group.
        /// </param>
        public UPSyncDocumentDownloadFieldGroupUrlCache(string fieldGroupName)
        {
            this.FieldControl = ConfigurationUnitStore.DefaultStore?.FieldControlByNameFromGroup("List", fieldGroupName);
            if (this.FieldControl != null)
            {
                var crmQuery = new UPContainerMetaInfo(this.FieldControl);
                this.result = crmQuery.Find();
                var count = this.result?.RowCount ?? 0;
                this.resultDictionary = new Dictionary <string, ICrmDataSourceRow>(count);
                for (var i = 0; i < count; i++)
                {
                    var row = this.result?.ResultRowAtIndex(i);
                    var rid = row?.RootRecordId;
                    if (!string.IsNullOrEmpty(rid))
                    {
                        this.resultDictionary[rid] = row;
                    }
                }
            }

            var fieldMapping = this.FieldControl?.FunctionNames();
            var field        = fieldMapping?.ValueOrDefault("UpdDate");

            this.ServerModifyDateFieldIndex = field?.TabIndependentFieldIndex ?? -1;

            field = fieldMapping?.ValueOrDefault("UpdTime");
            this.ServerModifyTimeFieldIndex = field?.TabIndependentFieldIndex ?? -1;

            this.HasServerDateTime = this.ServerModifyDateFieldIndex >= 0 && this.ServerModifyTimeFieldIndex >= 0;
        }
Ejemplo n.º 3
0
        private string LoadRootRecordIdentification()
        {
            string rootIdentification;

            // load objectives linked to a call
            if (!string.IsNullOrEmpty(this.ParentLink))
            {
                UPContainerMetaInfo personLoadContainer = new UPContainerMetaInfo(Constants.PersonInfoArea);
                personLoadContainer.SetLinkRecordIdentification(this.RecordIdentification);
                UPCRMResult personResult = personLoadContainer.Find();

                // person related record...load objectives for person
                if (personResult.RowCount == 1)
                {
                    rootIdentification = personResult.ResultRowAtIndex(0).RootRecordIdentification;
                }
                else
                {
                    // company related record..load objectives for company
                    UPContainerMetaInfo companyLoadContainer = new UPContainerMetaInfo(Constants.AccountInfoArea);
                    companyLoadContainer.SetLinkRecordIdentification(this.RecordIdentification);
                    UPCRMResult companyResult = companyLoadContainer.Find();
                    rootIdentification = companyResult.RowCount == 1
                        ? companyResult.ResultRowAtIndex(0).RootRecordIdentification
                        : this.RecordIdentification;
                }
            }
            else
            {
                rootIdentification = this.RecordIdentification;
            }

            return(rootIdentification);
        }
        private void UpdatePage(UPContainerMetaInfo containerMetaInfo)
        {
            if (this.RequestOption != UPRequestOption.Offline)
            {
                // read record asynchronously online
                Operation operation;
                if (string.IsNullOrWhiteSpace(this.LinkRecordIdentification))
                {
                    operation = containerMetaInfo.ReadRecord(this.recordId, UPRequestOption.Online, this);
                }
                else
                {
                    containerMetaInfo.DisableVirtualLinks = true;
                    containerMetaInfo.SetLinkRecordIdentification(this.LinkRecordIdentification, this.LinkId);
                    operation = containerMetaInfo.Find(UPRequestOption.Online, this);
                }

                if (operation == null)
                {
                    this.UpdatePageWithResult(null);
                }
            }
            else
            {
                this.UpdatePageWithResult(null);
            }
        }
        /// <summary>
        /// Filters for configuration filter.
        /// </summary>
        /// <param name="configFilter">The configuration filter.</param>
        /// <param name="searchAndListName">Name of the search and list.</param>
        /// <param name="filterParameters">The filter parameters.</param>
        /// <param name="singleSelect">if set to <c>true</c> [single select].</param>
        /// /// <returns>Filter</returns>
        public static UPMFilter FilterForConfigFilter(UPConfigFilter configFilter, string searchAndListName, Dictionary <string, object> filterParameters, bool singleSelect)
        {
            if (string.IsNullOrEmpty(searchAndListName))
            {
                return(null);
            }

            IConfigurationUnitStore configStore   = ConfigurationUnitStore.DefaultStore;
            SearchAndList           searchAndList = configStore.SearchAndListByName(searchAndListName);

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

            FieldControl listControl = configStore.FieldControlByNameFromGroup("List", searchAndList.FieldGroupName);

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

            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(searchAndListName, filterParameters);

            UPCRMResult result = crmQuery.Find();
            int         count  = result.RowCount;

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

            UPCRMListFormatter                  listFormatter = new UPCRMListFormatter(listControl.TabAtIndex(0));
            StringIdentifier                    identifier    = StringIdentifier.IdentifierWithStringId("SelectFilter");
            UPMSelectCatalogFilter              filter        = new UPMSelectCatalogFilter(identifier);
            Dictionary <string, string>         dict          = new Dictionary <string, string>(count);
            Dictionary <string, UPCRMResultRow> rowDict       = new Dictionary <string, UPCRMResultRow>(count);

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow row        = (UPCRMResultRow)result.ResultRowAtIndex(i);
                string         fieldValue = listFormatter.StringFromRowForPosition(row, 0);
                dict[row.RootRecordIdentification]    = fieldValue;
                rowDict[row.RootRecordIdentification] = row;
            }

            filter.CrmResult             = result;
            filter.FilterParameters      = filterParameters;
            filter.ResultRowDictionary   = rowDict;
            filter.ExplicitCatalogValues = dict;
            filter.ParameterName         = "Select";
            filter.Name = configFilter.UnitName;

            filter.DisplayName = !string.IsNullOrEmpty(configFilter.DisplayName) ? configFilter.DisplayName : configFilter.UnitName;

            filter.SingleSelect = singleSelect;
            return(filter);
        }
        /// <summary>
        /// The document data for record id.
        /// </summary>
        /// <param name="recordId">
        /// The record id.
        /// </param>
        /// <returns>
        /// The <see cref="DocumentData"/>.
        /// </returns>
        public DocumentData DocumentDataForRecordId(string recordId)
        {
            UPContainerMetaInfo query = new UPContainerMetaInfo(this.FieldControl);

            query.SetLinkRecordIdentification(this.InfoAreaId.InfoAreaIdRecordId(recordId));
            UPCRMResult result = query.Find();

            return(result.RowCount > 0 ? this.DocumentDataForResultRow(result.ResultRowAtIndex(0) as UPCRMResultRow) : null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Copies the field values for record identification.
        /// </summary>
        /// <param name="recordIdentification">The record identification.</param>
        /// <returns></returns>
        public Dictionary <string, object> CopyFieldValuesForRecordIdentification(string recordIdentification)
        {
            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(this.FieldControlConfiguration);

            crmQuery.SetLinkRecordIdentification(recordIdentification);
            UPCRMResult result = crmQuery.Find();

            return(result.RowCount >= 1 ? this.CopyFieldValuesForResult((UPCRMResultRow)result.ResultRowAtIndex(0)) : null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// The read link record identification from row.
        /// </summary>
        /// <param name="row">
        /// The row.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string ReadLinkRecordIdentificationFromRow(UPCRMResultRow row)
        {
            if (!this.LinkInfo.UseLinkFields)
            {
                return(null);
            }

            int    nextIndex              = this.StartingPosition;
            string targetInfoAreaId       = this.LinkInfo.TargetInfoAreaId;
            UPContainerMetaInfo query     = new UPContainerMetaInfo(new List <UPCRMField>(), targetInfoAreaId);
            UPInfoAreaCondition condition = null;

            foreach (UPCRMLinkInfoField linkInfoField in this.LinkInfo.LinkFieldArray)
            {
                UPInfoAreaCondition leaf;
                if (linkInfoField.FieldId >= 0)
                {
                    string value = row.RawValueAtIndex(nextIndex++);
                    if (linkInfoField.TargetFieldId < 0)
                    {
                        if (!value.Equals(linkInfoField.TargetValue))
                        {
                            return(null);
                        }
                    }

                    leaf = new UPInfoAreaConditionLeaf(targetInfoAreaId, linkInfoField.TargetFieldId, value);
                }
                else
                {
                    leaf = new UPInfoAreaConditionLeaf(
                        targetInfoAreaId,
                        linkInfoField.TargetFieldId,
                        linkInfoField.SourceValue);
                }

                condition = condition != null?condition.InfoAreaConditionByAppendingAndCondition(leaf) : leaf;
            }

            if (condition != null)
            {
                query.RootInfoAreaMetaInfo.AddCondition(condition);
            }

            UPCRMResult result = query.Find();

            if (result.RowCount >= 1)
            {
                return(((UPCRMResultRow)result.ResultRowAtIndex(0)).RootRecordIdentification);
            }

            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the node sub nodes.
        /// </summary>
        public virtual void LoadNodeSubNodes()
        {
            UPContainerMetaInfo query = this.CreateQuery(((RecordIdentifier)this.RootNode.Identifier).RecordIdentification);

            if (query != null)
            {
                query.Find(this.requestOption, this);
            }
            else
            {
                this.TheDelegate.NodesLoadFailedError(this, null);
            }
        }
Ejemplo n.º 10
0
        private void ProcessConfiguration(
            IEnumerable <object> listConfigurations,
            bool noLink,
            string parentRecordIdentification)
        {
            var duplicatePostfix = 0;

            foreach (var configName in listConfigurations)
            {
                var crmQuery = new UPContainerMetaInfo(configName as string, this.FilterParameters);
                if (!noLink && !string.IsNullOrEmpty(parentRecordIdentification))
                {
                    crmQuery.SetLinkRecordIdentification(parentRecordIdentification);
                }

                var result = crmQuery.Find();
                var count  = result.RowCount;
                for (var index = 0; index < count; index++)
                {
                    var option = new UPSelectorOption(
                        result.ResultRowAtIndex(index) as UPCRMResultRow,
                        crmQuery.SourceFieldControl);
                    if (this.PossibleValues == null)
                    {
                        this.PossibleValues = new Dictionary <string, UPSelectorOption> {
                            { option.Name, option }
                        };
                        this.ExplicitKeyOrder = new List <string> {
                            option.Name
                        };
                        this.PossibleValuesWithLabel = new Dictionary <string, object> {
                            { option.Name, option.Name }
                        };
                    }
                    else if (this.PossibleValues.ValueOrDefault(option.Name) == null)
                    {
                        this.PossibleValues[option.Name] = option;
                        this.ExplicitKeyOrder.Add(option.Name);
                        this.PossibleValuesWithLabel[option.Name] = option.Name;
                    }
                    else if (this.Definition.ValueOrDefault("DuplicateNames").ToInt() != 0)
                    {
                        var key = $"{option.Name}_{++duplicatePostfix}";
                        this.PossibleValues[key] = option;
                        this.ExplicitKeyOrder.Add(key);
                        this.PossibleValuesWithLabel[key] = option.Name;
                    }
                }
            }
        }
        /// <summary>
        /// Records the exists offline.
        /// </summary>
        /// <param name="recordIdentification">
        /// The record identification.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool RecordExistsOffline(string recordIdentification)
        {
            if (recordIdentification == null)
            {
                return(false);
            }

            var crmQuery = new UPContainerMetaInfo(null, recordIdentification.InfoAreaId());

            crmQuery.SetLinkRecordIdentification(recordIdentification);
            var result = crmQuery.Find();

            return(result?.RowCount > 0);
        }
        /// <summary>
        /// Loads the node sub nodes.
        /// </summary>
        public override void LoadNodeSubNodes()
        {
            this.tmpGroupNode = null;
            string recordIdentification = this.RootNode.GroupNode
                ? ((RecordIdentifier)this.RootNode.Parent.Identifier).RecordIdentification
                : ((RecordIdentifier)this.RootNode.Identifier).RecordIdentification;

            if ((this.childrenTreeConfig.Flags & UPConfigTreeViewTableFlags.HideGroupNode) > 0 || this.RootNode.GroupNode)
            {
                UPContainerMetaInfo query = this.CreateQueryWithRecordIdentifier(recordIdentification);
                if (query != null)
                {
                    query.Find(this.requestOption, this);
                }
                else
                {
                    SimpleIoc.Default.GetInstance <ILogger>().LogWarn("Nodes not loaded. SearchAndList missing?");
                    this.TheDelegate.NodesLoadFailedError(this, null);
                }
            }
            else
            {
                // Create static Group Nodes
                IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore;

                // Create Node
                // id ParentNodeId + SearchAndListName
                string idString = $"Node {this.childrenTreeConfig.SearchAndListName}, {recordIdentification}";
                this.tmpGroupNode        = new UPMCoINode(StringIdentifier.IdentifierWithStringId(idString));
                this.tmpGroupNode.Parent = this.RootNode;
                UPMStringField titleField = new UPMStringField(StringIdentifier.IdentifierWithStringId($"Title {this.childrenTreeConfig.SearchAndListName}"));
                titleField.StringValue = this.childrenTreeConfig.Label;
                List <UPMStringField> fields = new List <UPMStringField> {
                    titleField
                };
                this.tmpGroupNode.Fields     = fields;
                this.tmpGroupNode.InfoFields = fields;
                this.tmpGroupNode.GroupNode  = true;
                //this.tmpGroupNode.Icon = UIImage.UpImageWithFileName(configStore.InfoAreaConfigById(this.childrenTreeConfig.InfoAreaId).ImageName);  // CRM-5007

                // load next Level directly to avoid Empty Static Nodes
                CoITreeNodeLoader loader = new CoITreeNodeLoader(this.tmpGroupNode, this.childrenTreeConfig, this.viewReference, 0, this.vistedNodes, this.nodeConfigMapping, this.recordIdentifierInfoAreaConfigMapping);
                loader.Mode        = CoINodeLoaderMode.InitialLoad;
                loader.TheDelegate = this;
                this.subNodeLoader.Add(loader);
                this.pendingCount++;
                loader.LoadNodeSubNodes();
            }
        }
        private bool UpdateReportButtonState()
        {
            string         filterName = this.ViewReference.ContextValueForKey("ButtonShowFilter");
            UPConfigButton button     = null;
            string         buttonName = this.ViewReference.ContextValueForKey("ButtonName");

            if (!string.IsNullOrEmpty(buttonName))
            {
                button = ConfigurationUnitStore.DefaultStore.ButtonByName(buttonName);
            }

            UPConfigFilter buttonFilter = ConfigurationUnitStore.DefaultStore.FilterByName(filterName);

            if (buttonFilter != null || this.sendByEmailFilter != null)
            {
                this.shouldWaitForPendingChanges = true;
                if (buttonFilter != null)
                {
                    this.ApprovedText = buttonFilter.DisplayName;
                    if (string.IsNullOrEmpty(button?.Label))
                    {
                        this.ApprovedText = LocalizedString.TextProcessOrderWasApproved;
                    }

                    this.currentQuery = new UPContainerMetaInfo(new List <UPCRMField>(), buttonFilter.InfoAreaId);
                    this.currentQuery.ApplyFilter(buttonFilter);
                    this.currentQuery.SetLinkRecordIdentification(this.RecordIdentification);
                }
                else
                {
                    this.SerialEntryApproved = UPMSerialEntryState.NotApproved;
                }

                if (this.sendByEmailFilter != null)
                {
                    this.emailFilterQuery = new UPContainerMetaInfo(new List <UPCRMField>(), this.sendByEmailFilter.InfoAreaId);
                    this.emailFilterQuery.ApplyFilter(this.sendByEmailFilter);
                    this.emailFilterQuery.SetLinkRecordIdentification(this.RecordIdentification);
                }

                UPContainerMetaInfo queryToExecute = this.currentQuery ?? this.emailFilterQuery;
                queryToExecute.Find(UPRequestOption.FastestAvailable, this);
                return(true);
            }

            this.SerialEntryApproved = UPMSerialEntryState.NotApproved;
            return(false);
        }
        private UPCRMResult GetResultFromContainerMetaInfo(IConfigurationUnitStore configStore)
        {
            UPCRMResult result = null;

            var containerMetaInfo = new UPContainerMetaInfo(this.detailsControl)
            {
                ReplaceCaseSensitiveCharacters =
                    configStore.ConfigValueIsSet("Search.ReplaceCaseSensitiveCharacters")
            };

            // read record synchronously offline
            if (this.RequestOption == UPRequestOption.Default ||
                this.RequestOption == UPRequestOption.FastestAvailable ||
                this.RequestOption == UPRequestOption.Offline)
            {
                if (string.IsNullOrWhiteSpace(this.LinkRecordIdentification))
                {
                    result = containerMetaInfo.ReadRecord(
                        StringExtensions.InfoAreaIdRecordId(this.infoAreaId, this.recordId));
                }
                else
                {
                    containerMetaInfo.SetLinkRecordIdentification(this.LinkRecordIdentification, this.LinkId);
                    containerMetaInfo.DisableVirtualLinks = true;
                    result = containerMetaInfo.Find();
                    if (result.RowCount >= 1)
                    {
                        this.recordId = result.ResultRowAtIndex(0).RootRecordId;
                    }
                }
            }

            if (result == null || result.RowCount < 1)
            {
                this.UpdatePage(containerMetaInfo);
            }
            else
            {
                var resultRow = result.ResultRowAtIndex(0) as UPCRMResultRow;
                this.ApplySubTitleFromResultRow(resultRow);
                this.FillPageWithResultRow(
                    this.Page,
                    resultRow,
                    (resultRow?.IsServerResponse ?? true) ? UPRequestOption.Online : UPRequestOption.Offline);
            }

            return(result);
        }
        /// <summary>
        /// Searches the operation did fail with error.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="error">The error.</param>
        public void SearchOperationDidFailWithError(Operation operation, Exception error)
        {
            if (this.RequestOption == UPRequestOption.BestAvailable && error.IsConnectionOfflineError())
            {
                UPContainerMetaInfo childMetaInfo = new UPContainerMetaInfo(this.ChildFieldControl);
                childMetaInfo.SetLinkRecordIdentification(this.LinkRecordIdentification, this.LinkId);
                UPCRMResult childResult = childMetaInfo.Find();
                this.ControllerState = childResult.RowCount > 0 ? GroupModelControllerState.Finished : GroupModelControllerState.Empty;
            }
            else
            {
                this.ControllerState = GroupModelControllerState.Error;
            }

            this.Delegate.GroupModelControllerFinished(this);
        }
        /// <summary>
        /// The start.
        /// </summary>
        /// <param name="requestOption">
        /// The request option.
        /// </param>
        public void Start(UPRequestOption requestOption)
        {
            Dictionary <string, UPCRMField> fields = this.rootExpand?.FieldsForAlternateExpands(true);

            if (fields == null || fields?.Count == 0)
            {
                this.SearchOperationDidFinishWithResult(null, null);
                return;
            }

            var fieldValues = fields.Values.Select(x => x).ToList();
            var crmQuery    = new UPContainerMetaInfo(fieldValues, this.rootExpand.InfoAreaId);

            crmQuery.SetLinkRecordIdentification(this.recordIdentification);
            crmQuery.Find(requestOption, this);
        }
        /// <summary>
        /// Loads the documents with maximum results.
        /// </summary>
        /// <param name="maxResults">The maximum results.</param>
        public void LoadDocumentsWithMaxResults(int maxResults)
        {
            if (this.Record != null)
            {
                IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore;
                this.documentFieldControl = configStore.FieldControlByNameFromGroup("List", "D3DocData");
                UPContainerMetaInfo containerMetaInfo = new UPContainerMetaInfo(this.documentFieldControl);
                containerMetaInfo.SetLinkRecordIdentification(this.Record.OriginalRecordIdentification, 127);
                if (maxResults > 0)
                {
                    containerMetaInfo.MaxResults = maxResults;
                }

                Operation operation = containerMetaInfo.Find(this.Group.Objectives.RequestOption, this);
                if (operation == null)
                {
                    //DDLogError("Could not create operation for loading documents.{}");
                    Logger.LogError($"Could not create operation for loading documents. {this.Group.Objectives.RequestOption.ToString()}");
                }
            }
        }
        /// <summary>
        /// Results for row row.
        /// </summary>
        /// <param name="_serialEntry">The serial entry.</param>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        public UPCRMResult ResultForRowRow(UPSerialEntry _serialEntry, UPSERow row)
        {
            IConfigurationUnitStore configStore          = ConfigurationUnitStore.DefaultStore;
            FieldControl            documentFieldControl = configStore.FieldControlByNameFromGroup("List", "D1DocData");
            UPContainerMetaInfo     crmQuery             = new UPContainerMetaInfo(documentFieldControl);
            UPConfigFilter          filter = configStore.FilterByName(this.FilterName);

            if (filter != null)
            {
                Dictionary <string, object>     valuesForFunction  = new Dictionary <string, object>();
                Dictionary <string, UPSEColumn> columnsForFunction = _serialEntry.DestColumnsForFunction;
                foreach (string functionName in columnsForFunction.Keys)
                {
                    UPSEColumn column = columnsForFunction.ValueOrDefault(functionName) ??
                                        columnsForFunction.ValueOrDefault($"$par{functionName}");

                    if (column != null)
                    {
                        string value = row.StringValueAtIndex(column.Index);
                        if (!string.IsNullOrEmpty(value))
                        {
                            valuesForFunction.SetObjectForKey(value, functionName);
                        }
                    }
                }

                UPConfigFilter replacedFilter = filter.FilterByApplyingValueDictionaryDefaults(valuesForFunction, true);
                crmQuery.ApplyFilter(replacedFilter);
            }
            else
            {
                crmQuery.MaxResults = 10;
            }

            UPCRMResult crmResult = crmQuery.Find();

            return(crmResult);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// The request link record offline.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string RequestLinkRecordOffline()
        {
            this.linkContexts = this.LinkReaderContextsForParentLinkString(this.ParentLinkString);
            if (this.linkContexts == null || this.linkContexts.Count == 0)
            {
                return(null);
            }

            if (this.linkContexts.Count == 1)
            {
                UPCRMLinkReaderLinkContext context = this.linkContexts[0];
                if (context.LinkInfo.IsGeneric)
                {
                    UPContainerMetaInfo crmQuery = this.QueryForLinkLinkRecord(context.LinkInfo, this.SourceRecordIdentification);
                    UPCRMResult         result   = crmQuery.Find();
                    if (result.RowCount > 0)
                    {
                        UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(0);
                        return(row.RootRecordIdentification);
                    }

                    return(null);
                }
            }

            UPContainerMetaInfo crmQuery2 = this.ClientQuery();
            UPCRMResult         result2   = crmQuery2.Find();

            if (result2.RowCount == 0)
            {
                return(null);
            }

            UPCRMResultRow row2 = (UPCRMResultRow)result2.ResultRowAtIndex(0);

            return(this.RecordIdentificationFromResultRow(row2));
        }
Ejemplo n.º 20
0
        private bool ProcessNoLink(string linkInfoAreaId, ref string parentRecordIdentification)
        {
            if (string.IsNullOrWhiteSpace(linkInfoAreaId))
            {
                linkInfoAreaId = this.InfoAreaId;
                if (string.IsNullOrWhiteSpace(linkInfoAreaId))
                {
                    return(true);
                }
            }

            if (linkInfoAreaId.Equals(this.RecordIdentification.InfoAreaId()))
            {
                parentRecordIdentification = this.RecordIdentification;
            }
            else if (!string.IsNullOrWhiteSpace(this.RecordIdentification))
            {
                var crmQuery = new UPContainerMetaInfo(new List <UPCRMField>(), linkInfoAreaId)
                {
                    DisableVirtualLinks = true
                };

                crmQuery.SetLinkRecordIdentification(this.RecordIdentification, this.LinkId);
                var result = crmQuery.Find();
                if (result.RowCount > 0)
                {
                    parentRecordIdentification = result.ResultRowAtIndex(0).RootRecordId;
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 21
0
        private void ContinueLoadWithFieldValueDictionary(Dictionary <string, object> fieldValueDictionary)
        {
            IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore;

            if (fieldValueDictionary != null)
            {
                if (this.copyFieldsDictionary == null)
                {
                    this.copyFieldsDictionary = new Dictionary <string, Dictionary <string, object> >();
                }

                this.copyFieldsDictionary.SetObjectForKey(fieldValueDictionary, this.currentSectionConfiguration.SourceFieldControl.UnitName);
            }

            this.currentCopyFields = null;
            FieldControl   destinationFieldControl = this.currentSectionConfiguration.DestinationFieldControl;
            string         destinationFilterName   = this.currentSectionConfiguration.DestinationFilterName;
            UPConfigFilter companyRelatedFilter    = null;

            if (this.companyRelated)
            {
                string companyFilterName = $"{destinationFieldControl.InfoAreaId}.CompanyRelated";
                companyRelatedFilter = configStore.FilterByName(companyFilterName);
            }

            UPContainerMetaInfo container = new UPContainerMetaInfo(destinationFieldControl);

            container.SetLinkRecordIdentification(this.rootRecordIdentification);
            List <UPConfigFilter> appliedFilters = new List <UPConfigFilter>();
            UPConfigFilter        filter         = configStore.FilterByName(destinationFilterName);

            if (filter != null)
            {
                filter = filter.FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(fieldValueDictionary));
                container.ApplyFilter(filter);
                appliedFilters.Add(filter);
            }

            if (companyRelatedFilter != null && this.currentSectionConfiguration.SourceFieldControl != null)
            {
                companyRelatedFilter = companyRelatedFilter.FilterByApplyingReplacements(new UPConditionValueReplacement(fieldValueDictionary));
                container.ApplyFilter(companyRelatedFilter);
                appliedFilters.Add(companyRelatedFilter);
            }

            this.objectivesForRecordOperation = null;
            this.rightFilterOperation         = null;
            this.filterLoaded = true;
            if (this.RightsFilter != null && this.filterItemsResult == null)
            {
                this.filterLoaded = false;
            }

            if (this.currentSectionConfiguration.ExecuteActionFilter != null)
            {
                this.currentSectionConfiguration.ExecuteActionFilter = this.currentSectionConfiguration.ExecuteActionFilter.FilterByApplyingValueDictionaryDefaults(fieldValueDictionary, true);
                if (this.currentSectionConfiguration.ExecuteActionFilter != null)
                {
                    this.currentSectionConfiguration.FilterBasedDecision = new UPCRMFilterBasedDecision(this.currentSectionConfiguration.ExecuteActionFilter);
                    List <UPCRMField> fields = this.currentSectionConfiguration.FilterBasedDecision.FieldDictionary.Values.ToList();
                    if (fields.Count > 0)
                    {
                        container.AddCrmFields(fields);
                    }

                    this.currentSectionConfiguration.FilterBasedDecision.UseCrmQuery(container);
                }
            }

            this.objectivesForRecordOperation = container.Find(this.RequestOption, this);
            if (this.objectivesForRecordOperation == null)
            {
                SimpleIoc.Default.GetInstance <ILogger>().LogError("Could not create operation for loading objectives.");
                this.FailWithError(new Exception("ConnectionOfflineError"));
            }

            if (this.RightsFilter != null && this.filterItemsResult == null)
            {
                UPContainerMetaInfo clonedContainer = new UPContainerMetaInfo(new List <UPCRMField>(), destinationFieldControl.InfoAreaId);
                clonedContainer.SetLinkRecordIdentification(this.rootRecordIdentification);
                clonedContainer.ApplyFilter(this.RightsFilter);
                foreach (UPConfigFilter filter1 in appliedFilters)
                {
                    clonedContainer.ApplyFilter(filter1);
                }

                this.rightFilterOperation = clonedContainer.Find(this.RequestOption, this);
                if (this.rightFilterOperation == null)
                {
                    SimpleIoc.Default.GetInstance <ILogger>().LogError("Could not create operation for filtering objectives.");
                    this.FailWithError(new Exception("ConnectionOfflineError"));
                }
            }
        }
        /// <summary>
        /// Offlines the request data online context did finish with result.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="data">The data.</param>
        /// <param name="online">if set to <c>true</c> [online].</param>
        /// <param name="context">The context.</param>
        /// <param name="result">The result.</param>
        public void OfflineRequestDidFinishWithResult(UPOfflineRequest request, object data, bool online, object context, Dictionary <string, object> result)
        {
            if (this.uploadDocumentRequest != null)
            {
                this.uploadDocumentRequest = null;
                if (this.disable85106)
                {
                    this.ApproveAction.PerformAction(this.approveActionDelegate);
                }

                this.pageBuilt = false;
                if (this.ParentOrganizerModelController is DetailOrganizerModelController)
                {
                    ((DetailOrganizerModelController)this.ParentOrganizerModelController).RefreshAfterDocumentUploaded(this.RecordIdentification);
                }

                if (!this.disable85106)
                {
                    this.ShouldWaitForPendingChanges = true;
                }
            }
            else
            {
                this.buttonRequest       = null;
                this.pageBuilt           = false;
                this.SerialEntryApproved = UPMSerialEntryState.Approved;
                if (!this.disable85106)
                {
                    this.ShouldWaitForPendingChanges = false;
                }
                else
                {
                    List <UPCRMRecord> records = (List <UPCRMRecord>)data;
                    if (records.Count > 0)
                    {
                        UPCRMRecord      record           = records[0];
                        RecordIdentifier recordIdentifier = new RecordIdentifier(record.RecordIdentification);
                        UPChangeManager.CurrentChangeManager.RegisterChanges(new List <IIdentifier> {
                            recordIdentifier
                        });
                        if (this.ParentOrganizerModelController is DetailOrganizerModelController)
                        {
                            List <IIdentifier> changes = UPChangeManager.CurrentChangeManager.ChangesToApplyForCurrentViewController();
                            if (this.sendByEmailFilter != null)
                            {
                                this.unreportedRecordChanges = changes;
                            }
                            else
                            {
                                this.ParentOrganizerModelController.ProcessChanges(changes);
                            }
                        }
                    }

                    if (this.sendByEmailFilter != null)
                    {
                        UPContainerMetaInfo _emailFilterQuery = new UPContainerMetaInfo(new List <UPCRMField>(), this.sendByEmailFilter.InfoAreaId);
                        this.emailFilterQuery = _emailFilterQuery;
                        _emailFilterQuery.ApplyFilter(this.sendByEmailFilter);
                        _emailFilterQuery.SetLinkRecordIdentification(this.RecordIdentification);
                        _emailFilterQuery.Find(UPRequestOption.FastestAvailable, this);
                    }
                    else
                    {
                        this.SetShouldWaitForPendingChangesWithoutPageUpdate(false, true);
                    }
                }
            }
        }
        /// <summary>
        /// Results for row.
        /// </summary>
        /// <param name="serialEntryRow">The serial entry row.</param>
        /// <returns></returns>
        public override UPSerialEntryInfoResult ResultForRow(UPSERow serialEntryRow)
        {
            string sourceRecordIdentification           = StringExtensions.InfoAreaIdRecordId(serialEntryRow.SerialEntry.SourceInfoAreaId, serialEntryRow.RowRecordId);
            UPSerialEntryInfoResultFromCRMResult result = this.cachedResults.ValueOrDefault(sourceRecordIdentification);

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

            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(this.FieldControl);

            if (!this.IgnoreSourceRecord)
            {
                crmQuery.SetLinkRecordIdentification(sourceRecordIdentification);
            }

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

            if (this.Filter != null)
            {
                Dictionary <string, object> parameterValues = serialEntryRow.SourceFunctionValues();
                if (this.SerialEntry.InitialFieldValuesForDestination.Count > 0)
                {
                    if (parameterValues.Count > 0)
                    {
                        Dictionary <string, object> dict = new Dictionary <string, object>(this.SerialEntry.InitialFieldValuesForDestination);
                        foreach (var entry in parameterValues)
                        {
                            dict[entry.Key] = entry.Value;
                        }

                        parameterValues = dict;
                    }
                    else
                    {
                        parameterValues = this.SerialEntry.InitialFieldValuesForDestination;
                    }
                }

                if (parameterValues.Count > 0)
                {
                    UPConfigFilter applyFilter = this.Filter.FilterByApplyingReplacements(UPConditionValueReplacement.ReplacementsFromValueParameterDictionary(parameterValues));
                    if (applyFilter != null)
                    {
                        crmQuery.ApplyFilter(applyFilter);
                    }
                }
                else
                {
                    crmQuery.ApplyFilter(this.Filter);
                }
            }

            UPCRMResult crmResult = crmQuery.Find();

            result = new UPSerialEntryInfoResultFromCRMResult(crmResult, this);
            if (this.cachedResults == null)
            {
                this.cachedResults = new Dictionary <string, UPSerialEntryInfoResultFromCRMResult> {
                    { sourceRecordIdentification, result }
                };
            }
            else
            {
                this.cachedResults[sourceRecordIdentification] = result;
            }

            return(result);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Reads the rep with identifier.
        /// </summary>
        /// <param name="repId">The rep identifier.</param>
        /// <returns></returns>
        public UPCRMRep ReadRepWithId(string repId)
        {
            if (string.IsNullOrEmpty(repId))
            {
                return(null);
            }

            if (this.missingRepDictionary == null)
            {
                this.missingRepDictionary = new Dictionary <string, UPCRMRep>();
            }
            else
            {
                var returnRep = this.missingRepDictionary.ValueOrDefault(repId);
                if (returnRep != null)
                {
                    return(returnRep);
                }

                if (this.emptyRepDictionary.ValueOrDefault(repId) != null)
                {
                    return(null);
                }
            }

            var          configStore      = ConfigurationUnitStore.DefaultStore;
            var          repSearchAndList = configStore.SearchAndListByName("IDSystem");
            FieldControl fieldControl     = null;

            if (repSearchAndList != null)
            {
                fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem");
            }

            if (fieldControl?.Fields == null ||
                fieldControl.Fields.Count == 0)
            {
                return(null);
            }

            UPCRMField vField        = fieldControl.Fields[0].Field;
            var        fromCondition = new UPInfoAreaConditionLeaf(fieldControl.InfoAreaId, vField.FieldId, "=", repId);
            var        metaInfo      = new UPContainerMetaInfo(fieldControl);

            metaInfo.RootInfoAreaMetaInfo.AddCondition(fromCondition);
            UPCRMResult result = metaInfo.Find();
            int         count  = result.RowCount;

            if (count > 0)
            {
                lock (this.missingRepDictionary)
                {
                    for (var i = 0; i < count; i++)
                    {
                        var row = result.ResultRowAtIndex(i);
                        var rep = new UPCRMRep(
                            row.RawValueAtIndex(0),
                            row.RawValueAtIndex(2),
                            row.RawValueAtIndex(1),
                            row.RootRecordId,
                            this.RepTypeFromStringRepTypeId(row.RawValueAtIndex(3)));

                        this.missingRepDictionary[rep.RepId] = rep;
                    }

                    foreach (var rep in this.repArray)
                    {
                        if (string.IsNullOrEmpty(rep.RepOrgGroupId))
                        {
                            continue;
                        }

                        var parentRep = this.missingRepDictionary.ValueOrDefault(rep.RepOrgGroupId);
                        parentRep?.AddChildRep(rep);
                    }
                }

                return(this.missingRepDictionary.ValueOrDefault(repId));
            }

            if (this.emptyRepDictionary == null)
            {
                this.emptyRepDictionary = new Dictionary <string, string>();
            }

            this.emptyRepDictionary[repId] = repId;
            return(null);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Records the identification for link information area identifier link identifier.
        /// </summary>
        /// <param name="infoAreaId">
        /// The information area identifier.
        /// </param>
        /// <param name="linkId">
        /// The link identifier.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string RecordIdentificationForLinkInfoAreaIdLinkId(string infoAreaId, int linkId)
        {
            var position = this.Result.MetaInfo.IndexOfResultInfoAreaIdLinkId(infoAreaId, linkId);

            if (position >= 0)
            {
                return(this.RecordIdentificationAtIndex(position));
            }

            var rootInfoAreaId = this.PhysicalInfoAreaIdAtIndex(0);
            var tableInfo      = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(rootInfoAreaId);
            var linkInfo       = tableInfo.LinkInfoForTargetInfoAreaIdLinkId(infoAreaId, linkId);

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

            if (linkInfo.IsFieldLink && linkInfo.LinkFieldArray?.Count == 1)
            {
                var arNoString = this.RawValueForFieldIdInfoAreaIdLinkId(
                    linkInfo.FirstField.FieldId,
                    linkInfo.InfoAreaId,
                    -1);
                if (string.IsNullOrEmpty(arNoString))
                {
                    return(null);
                }

                var crmQuery         = new UPContainerMetaInfo(new List <UPCRMField>(), linkInfo.TargetInfoAreaId);
                var infoAreaMetaInfo = crmQuery.RootInfoAreaMetaInfo;
                infoAreaMetaInfo.Condition = new UPInfoAreaConditionLeaf(
                    linkInfo.TargetInfoAreaId,
                    linkInfo.FirstField.TargetFieldId,
                    "=",
                    arNoString);
                var res = crmQuery.Find();
                if (res.RowCount > 0)
                {
                    return(res.ResultRowAtIndex(0).RootRecordIdentification);
                }
            }
            else if (linkInfo.HasColumn && !this.IsNewRow &&
                     !ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82339"))
            {
                var crmQuery = new UPContainerMetaInfo(new List <UPCRMField>(), rootInfoAreaId);
                crmQuery.AddCrmFields(
                    new List <UPCRMField>
                {
                    new UPCRMLinkField(linkInfo.TargetInfoAreaId, linkInfo.LinkId, rootInfoAreaId)
                });
                crmQuery.SetLinkRecordIdentification(this.RootRecordIdentification);
                var res = crmQuery.Find();
                if (res.RowCount != 1)
                {
                    return(null);
                }

                var linkRecordId = res.ResultRowAtIndex(0).RawValueAtIndex(0);
                if (!string.IsNullOrEmpty(linkRecordId))
                {
                    return(linkInfo.TargetInfoAreaId.InfoAreaIdRecordId(linkRecordId));
                }
            }

            SimpleIoc.Default.GetInstance <ILogger>().LogWarn($"RecordSelector: could not determine linkRecord for infoArea:{infoAreaId} linkId:{linkId}");
            return(null);
        }
Ejemplo n.º 26
0
        private void Search(object _docPage)
        {
            UPMDocumentPage docPage = (UPMDocumentPage)_docPage;

            this.currentSearchOperation?.Cancel();
            if (this.preparedSearch == null)
            {
                this.preparedSearch = new UPSearchPageModelControllerPreparedSearch(this.InfoAreaId, this.ConfigName, this.filterName);
            }

            if (this.preparedSearch.CombinedControl == null)
            {
                this.SearchOperationDidFinishWithResult(null, null);
                return;     // dont crash but do nothing if no list exists
            }

            IConfigurationUnitStore configStore   = ConfigurationUnitStore.DefaultStore;
            FieldControl            searchControl = configStore.FieldControlByNameFromGroup("Search", this.preparedSearch.SearchConfiguration.FieldGroupName);

            if (searchControl != null)
            {
                string searchLabel = string.Empty;
                int    count       = searchControl.NumberOfFields;
                for (int i = 0; i < count; i++)
                {
                    searchLabel = i == 0 ? searchControl.FieldAtIndex(i).Label : $"{searchLabel} | {searchControl.FieldAtIndex(i).Label}";
                }

                docPage.SearchPlaceholder = searchLabel;
            }

            if (string.IsNullOrEmpty(docPage.SearchText))
            {
                int range = this.ViewReference.ContextValueForKey("SearchOptions")?.IndexOf("NoEmptySearch") ?? 0;
                if (range >= 0)
                {
                    this.SearchOperationDidFinishWithResult(null, null);
                    return;
                }
            }

            List <UPConfigFilter> configFilters     = UPMFilter.ActiveFiltersForFilters(docPage.AvailableFilters);
            UPContainerMetaInfo   containerMetaInfo = this.preparedSearch.CrmQueryForValue(docPage.SearchText, configFilters, this.fullTextSearch);

            if (this.recordIdentification.IsRecordIdentification())
            {
                containerMetaInfo.SetLinkRecordIdentification(this.recordIdentification, 126, 127);
            }

            if (docPage.SearchType == SearchPageSearchType.OfflineSearch)
            {
                this.currentSearchOperation = containerMetaInfo.Find(UPRequestOption.Offline, this);
            }
            else if (docPage.SearchType == SearchPageSearchType.OnlineSearch)
            {
                this.currentSearchOperation = containerMetaInfo.Find(this);
            }
            else
            {
                SimpleIoc.Default.GetInstance <ILogger>().LogError($"Unknown search type: {docPage.SearchType}");
            }
        }
        /// <summary>
        /// Updates the page with result.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        public void UpdatePageWithResult(UPCRMResult result)
        {
            if (result == null)
            {
                return;
            }

            var oldPage = this.Page;
            var newPage = (MDetailPage)this.InstantiatePage();

            newPage.LabelText = oldPage.LabelText;
            newPage.Invalid   = false;
            newPage.Status    = null;
            if (result.RowCount == 0)
            {
                if (this.RequestOption == UPRequestOption.BestAvailable)
                {
                    var containerMetaInfo = new UPContainerMetaInfo(this.detailsControl)
                    {
                        ReplaceCaseSensitiveCharacters =
                            ConfigurationUnitStore.DefaultStore.ConfigValueIsSet(
                                "Search.ReplaceCaseSensitiveCharacters")
                    };

                    if (string.IsNullOrWhiteSpace(this.LinkRecordIdentification))
                    {
                        result = containerMetaInfo.ReadRecord(this.infoAreaId.InfoAreaIdRecordId(this.recordId));
                    }
                    else
                    {
                        containerMetaInfo.SetLinkRecordIdentification(this.LinkRecordIdentification, this.LinkId);
                        result = containerMetaInfo.Find();
                    }

                    if (result.RowCount == 0)
                    {
                        var errorStatus = UPMErrorStatus.ErrorStatusWithMessageDetails("Loading error", null);
                        newPage.Status       = errorStatus;
                        newPage.Invalid      = true;
                        this.TopLevelElement = newPage;
                        this.InformAboutDidFailTopLevelElement(this.Page);
                        return;
                    }
                }
                else
                {
                    var errorStatus = UPMErrorStatus.ErrorStatusWithMessageDetails("Loading error", null);
                    newPage.Status       = errorStatus;
                    newPage.Invalid      = true;
                    this.TopLevelElement = newPage;
                    this.InformAboutDidFailTopLevelElement(this.Page);
                    return;
                }
            }

            var resultRow = result.ResultRowAtIndex(0) as UPCRMResultRow;

            this.FillPageWithResultRow(
                newPage,
                resultRow,
                resultRow.IsServerResponse ? UPRequestOption.Online : UPRequestOption.Offline);
            this.ApplySubTitleFromResultRow(resultRow);
            this.TopLevelElement = newPage;
            this.InformAboutDidChangeTopLevelElement(oldPage, newPage, null, null);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Loads the reps.
        /// </summary>
        public void LoadReps()
        {
            lock (this)
            {
                if (this.repDictionary != null)
                {
                    return;
                }

                var            configStore      = ConfigurationUnitStore.DefaultStore;
                var            repSearchAndList = configStore.SearchAndListByName("IDSystem");
                FieldControl   fieldControl;
                UPConfigFilter filter = null;
                if (repSearchAndList != null)
                {
                    fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem");
                    if (!string.IsNullOrEmpty(repSearchAndList.FilterName))
                    {
                        filter = configStore.FilterByName(repSearchAndList.FilterName);
                    }
                }
                else
                {
                    fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem");
                }

                if (fieldControl == null)
                {
                    return;
                }

                var metaInfo = new UPContainerMetaInfo(fieldControl);
                if (filter != null)
                {
                    metaInfo.ApplyFilter(filter);
                }

                var result = metaInfo.Find();
                var count  = result != null ? result.RowCount : 0;
                if (count <= 0)
                {
                    return;
                }

                var _repDictionary = new Dictionary <string, UPCRMRep>(count);
                var _repArray      = new List <UPCRMRep>(count);
                for (var i = 0; i < count; i++)
                {
                    var row = result.ResultRowAtIndex(i);
                    var rep = new UPCRMRep(
                        row.RawValueAtIndex(0),
                        row.RawValueAtIndex(2),
                        row.RawValueAtIndex(1),
                        row.RootRecordId,
                        this.RepTypeFromStringRepTypeId(row.RawValueAtIndex(3)));
                    _repDictionary[rep.RepId] = rep;
                    _repArray.Add(rep);
                }

                foreach (var rep in _repArray)
                {
                    if (string.IsNullOrEmpty(rep.RepOrgGroupId))
                    {
                        continue;
                    }

                    var parentRep = _repDictionary.ValueOrDefault(rep.RepOrgGroupId);
                    parentRep?.AddChildRep(rep);
                }

                this.repDictionary = _repDictionary;
                this.repArray      = _repArray;
            }
        }