Exemple #1
0
        /// <summary>
        /// Searches the operation did finish with result.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="result">The result.</param>
        public virtual void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult result)
        {
            int count = result.RowCount;

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(i);
                var            rowValues = resultRow.ValuesWithFunctions();

                string rep   = (string)rowValues.ValueOrDefault(Constants.UPRepAcceptanceFunctionName_RepId);
                int    repId = rep.ToInt();

                if (repId > 0)
                {
                    rep = StringExtensions.NineDigitStringFromRep(Convert.ToInt32(rep));

                    var repParticipant = this.ParticipantWithKey(rep);

                    if (repParticipant is UPCRMRepParticipant)
                    {
                        string acceptance = (string)rowValues[Constants.UPRepAcceptanceFunctionName_Acceptance];
                        ((UPCRMRepParticipant)repParticipant).AcceptanceFromRecordIdentification(acceptance, resultRow.RootRecordIdentification);
                    }
                }
            }

            this.repAcceptanceCrmQuery = null;
            this.Loaded();
        }
Exemple #2
0
        /// <summary>
        /// Loads the with result.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public override bool LoadWithResult(UPCRMResult result)
        {
            if (result.RowCount > 0)
            {
                return(this.LoadWithResultRow((UPCRMResultRow)result.ResultRowAtIndex(0)));
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// The handle result client.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        public void HandleResultClient(UPCRMResult result, bool client)
        {
            if (this.queryWithLinkRecord)
            {
                if (result.RowCount > 0)
                {
                    UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(0);
                    this.DestinationRecordIdentification = resultRow.RootRecordIdentification;
                }
            }
            else
            {
                UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(0);
                if (client)
                {
                    this.DestinationRecordIdentification = this.RecordIdentificationFromResultRow(row);
                }
                else
                {
                    int position = 0;
                    Dictionary <string, int> linkPositions = new Dictionary <string, int>();
                    foreach (UPCRMLinkReaderLinkContext context in this.linkContexts)
                    {
                        string linkKey = $"{context.LinkInfo.TargetInfoAreaId}_{(context.LinkInfo.LinkId < 0 ? 0 : context.LinkInfo.LinkId)}";
                        if (linkPositions.ValueOrDefault(linkKey) == 0)
                        {
                            continue;
                        }

                        this.DestinationRecordIdentification = row.RecordIdentificationAtIndex(++position);
                        if (!string.IsNullOrEmpty(this.DestinationRecordIdentification))
                        {
                            break;
                        }

                        linkPositions[linkKey] = position - 1;
                    }
                }
            }

            this.TheDelegate?.LinkReaderDidFinishWithResult(this, this.DestinationRecordIdentification);
        }
Exemple #4
0
 /// <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 (result.RowCount == 0)
     {
         this.Tiles.TileFinishedWithError(this, new Exception($"Record Not found: {this.recordIdentification}"));
     }
     else
     {
         this.LoadWithResultRow((UPCRMResultRow)result.ResultRowAtIndex(0));
     }
 }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// Searches the operation did finish with result.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="result">The result.</param>
        public override void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult result)
        {
            if (this.crmQuery != null)
            {
                int count         = result.RowCount;
                int infoAreaCount = result.MetaInfo.NumberOfResultInfoAreaMetaInfos();

                for (int i = 0; i < count; i++)
                {
                    UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(i);

                    for (int j = 1; j < infoAreaCount; j++)
                    {
                        string linkRecordIdentification = resultRow.RecordIdentificationAtIndex(j);
                        if (linkRecordIdentification?.Length > 6)
                        {
                            UPCRMLinkParticipant linkParticipant = new UPCRMLinkParticipant(resultRow, j);
                            this.AddLinkParticipant(linkParticipant);

                            if (!string.IsNullOrEmpty(this.ProtectedLinkRecordIdentification) && this.ProtectedLinkRecordIdentification == linkParticipant.LinkRecordIdentification)
                            {
                                linkParticipant.MayNotBeDeleted = true;
                            }

                            break;
                        }
                        else
                        {
                            UPContainerInfoAreaMetaInfo iaMeta      = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j);
                            UPCRMLinkReader             _linkReader = new UPCRMLinkReader(resultRow.RootRecordIdentification, iaMeta.InfoAreaIdWithLink, null);
                            string linkRecordId = _linkReader.RequestLinkRecordOffline();

                            if (!string.IsNullOrEmpty(linkRecordId) && UPCRMDataStore.DefaultStore.RecordExistsOffline(linkRecordId))
                            {
                                UPCRMLinkParticipant linkParticipant = new UPCRMLinkParticipant(resultRow, linkRecordId);
                                this.AddLinkParticipant(linkParticipant);
                                break;
                            }
                        }
                    }
                }

                this.Finished(null);
            }
            else
            {
                base.SearchOperationDidFinishWithResult(operation, result);
            }
        }
Exemple #7
0
        /// <summary>
        /// Merges the server result with local results.
        /// </summary>
        /// <param name="serverResult">
        /// The server result.
        /// </param>
        /// <param name="localResults">
        /// The local results.
        /// </param>
        public void MergeServerResultWithLocalResults(UPCRMResult serverResult, Dictionary <string, object> localResults)
        {
            var resultsOfCurrentQuery = new List <ICrmDataSourceRow>();

            for (var i = 0; i < serverResult.RowCount; i++)
            {
                var serverResultRow = (UPCRMResultRow)serverResult.ResultRowAtIndex(i);
                var localResultRow  = localResults.ValueOrDefault(serverResultRow.RootRecordId) as UPCRMResultRow;
                if (localResultRow != null)
                {
                    serverResultRow.SetHasLocalCopy(true);
                }

                resultsOfCurrentQuery.Add(serverResultRow);
            }

            this.AddResult(serverResult);
            this.SetResultRows(resultsOfCurrentQuery);
        }
Exemple #8
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));
        }
Exemple #9
0
        /// <summary>
        /// Sources the field result row for link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <returns></returns>
        List <string> SourceFieldResultRowForLink(UPCRMLink link)
        {
            UPCRMTableInfo sourceTableInfo = this.dataStore.TableInfoForInfoArea(link.InfoAreaId);
            UPCRMLinkInfo  linkInfo        = this.tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId);
            bool           noFields        = true;

            if (sourceTableInfo == null || linkInfo?.LinkFieldArray == null)
            {
                return(null);
            }

            List <UPCRMFieldSetterField> fieldMap = new List <UPCRMFieldSetterField>(linkInfo.LinkFieldArray.Count);

            foreach (UPCRMLinkInfoField field in linkInfo.LinkFieldArray)
            {
                UPCRMFieldInfo fieldInfo = sourceTableInfo.FieldInfoForFieldId(field.TargetFieldId);
                if (fieldInfo != null)
                {
                    fieldMap.Add(new UPCRMFieldSetterSourceField(field.TargetFieldId));
                    noFields = false;
                }
                else
                {
                    UPCRMFieldSetterSourceLink sourceLink = null;
                    List <UPCRMLinkInfo>       allLinks   = sourceTableInfo.LinksWithField();
                    foreach (UPCRMLinkInfo currentLinkInfo in allLinks)
                    {
                        foreach (UPCRMLinkInfoField linkInfoField in currentLinkInfo.LinkFieldArray)
                        {
                            if (linkInfoField.FieldId == field.TargetFieldId)
                            {
                                UPCRMTableInfo parentTableInfo = this.dataStore.TableInfoForInfoArea(currentLinkInfo.TargetInfoAreaId);
                                UPCRMLinkInfo  parentIdentLink = parentTableInfo.IdentLink;
                                if (parentIdentLink != null)
                                {
                                    if (parentIdentLink.FirstField.TargetFieldId == linkInfoField.TargetFieldId)
                                    {
                                        sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 0);
                                        break;
                                    }

                                    if (parentIdentLink.SecondField.TargetFieldId == linkInfoField.TargetFieldId)
                                    {
                                        sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 1);
                                        break;
                                    }
                                }
                            }
                        }

                        if (sourceLink != null)
                        {
                            break;
                        }
                    }

                    if (sourceLink != null)
                    {
                        fieldMap.Add(sourceLink);
                        noFields = false;
                    }
                    else
                    {
                        fieldMap.Add(new UPCRMFieldSetterField());
                    }
                }
            }

            if (noFields)
            {
                return(null);
            }

            List <UPCRMField> queryFields = new List <UPCRMField>();
            int resultPosition            = 0;

            foreach (UPCRMFieldSetterField fieldSetterField in fieldMap)
            {
                if (fieldSetterField.IsField)
                {
                    queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId));
                    fieldSetterField.ResultPosition = resultPosition++;
                }
            }

            foreach (UPCRMFieldSetterField fieldSetterField in fieldMap)
            {
                if (fieldSetterField.IsLink)
                {
                    queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId));
                    fieldSetterField.ResultPosition = resultPosition++;
                }
            }

            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(queryFields, linkInfo.TargetInfoAreaId);
            UPCRMResult         result   = crmQuery.ReadRecord(link.RecordIdentification);

            if (result != null && result.RowCount == 1)
            {
                UPCRMResultRow row         = (UPCRMResultRow)result.ResultRowAtIndex(0);
                List <string>  resultArray = new List <string>(fieldMap.Count);
                foreach (UPCRMFieldSetterField field in fieldMap)
                {
                    if (field.IsField)
                    {
                        resultArray.Add(row.RawValueAtIndex(field.ResultPosition));
                    }
                    else if (field.IsLink)
                    {
                        string recordId = row.RawValueAtIndex(field.ResultPosition);
                        if (string.IsNullOrEmpty(recordId))
                        {
                            resultArray.Add(string.Empty);
                        }
                        else if (recordId.StartsWith("new") && recordId.Length == 15)
                        {
                            long offlineLnr = (Convert.ToInt64(recordId.Substring(3, 8), 16) << 16) + Convert.ToInt64(recordId.Substring(11, 4), 16);
                            if (this.offlineStationNumber > 0 && offlineLnr > 0)
                            {
                                if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0)
                                {
                                    resultArray.Add(this.offlineStationNumber.ToString());
                                }
                                else
                                {
                                    resultArray.Add(offlineLnr.ToString());
                                }
                            }
                        }
                        else if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0)
                        {
                            resultArray.Add(recordId.StatNoFromRecordIdString());
                        }
                        else
                        {
                            resultArray.Add(recordId.RecordNoFromRecordIdString());
                        }
                    }
                    else
                    {
                        resultArray.Add(string.Empty);
                    }
                }

                return(resultArray);
            }

            return(null);
        }
        /// <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);
        }