コード例 #1
0
        /// <summary>
        /// Offlines the record for count.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public UPCRMRecord OfflineRecordForCount(int count)
        {
            if (this.QuotaHandler.QuotaEditFieldControl == null)
            {
                return(null);
            }

            UPCRMRecord record;

            if (!string.IsNullOrEmpty(this.RecordIdentification))
            {
                record = new UPCRMRecord(this.RecordIdentification, "UpdateOffline", null);
            }
            else
            {
                record      = UPCRMRecord.CreateNew(this.QuotaHandler.QuotaEditFieldControl.InfoAreaId);
                record.Mode = "NewOffline";
                UPConfigFilter templateFilter = this.QuotaHandler.QuotaTemplateFilter;
                if (templateFilter != null && this.QuotaHandler.FilterParameters.Count > 0)
                {
                    templateFilter = templateFilter.FilterByApplyingValueDictionaryDefaults(this.QuotaHandler.FilterParameters, true);
                }

                if (templateFilter != null)
                {
                    record.ApplyValuesFromTemplateFilter(templateFilter);
                }

                foreach (UPConfigFieldControlField field in this.QuotaHandler.QuotaEditFieldControl.Fields)
                {
                    if (field.Function == "StartDate")
                    {
                        string dateString = StringExtensions.CrmValueFromDate(this.FirstStartDate != null ? this.QuotaStartDateForPeriod() : DateTime.UtcNow);

                        record.AddValue(new UPCRMFieldValue(dateString, record.InfoAreaId, field.FieldId));
                    }
                    else if (field.Function == "EndDate")
                    {
                        string dateString = StringExtensions.CrmValueFromDate(this.QuotaEndDateForPeriod());
                        record.AddValue(new UPCRMFieldValue(dateString, record.InfoAreaId, field.FieldId));
                    }
                    else if (field.Function == this.QuotaHandler.ItemNumberFunctionName)
                    {
                        record.AddValue(new UPCRMFieldValue(this.ItemNumber, record.InfoAreaId, field.FieldId));
                    }
                }

                record.AddLink(new UPCRMLink(this.QuotaHandler.LinkRecord.RecordIdentification, this.QuotaHandler.QuotaLinkId));
            }

            foreach (UPConfigFieldControlField field in this.QuotaHandler.QuotaEditFieldControl.Fields)
            {
                if (field.Function == "Items" || field.Function.StartsWith("Items:"))
                {
                    record.AddValue(new UPCRMFieldValue(count.ToString(), record.InfoAreaId, field.FieldId, true));
                }
            }

            return(record);
        }
コード例 #2
0
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords()
        {
            UPCRMRecord changedRecord = null;

            if (this.Deleted && this.Record != null)
            {
                if (this.Deleted && this.Created)
                {
                    // This happens during conflict handling. Saved offline with new RecordId and in conflict handling remove again.
                    // Remove from crmdata only.
                    this.Record.Deleted = true;
                    changedRecord       = this.Record;
                }
                else
                {
                    changedRecord = new UPCRMRecord(this.Record.RecordIdentification, "Delete", null);
                }
            }
            else
            {
                if (this.Created)
                {
                    changedRecord = this.Record == null?UPCRMRecord.CreateNew(this.Group.Characteristics.DestinationFieldControl.InfoAreaId)
                                        : new UPCRMRecord(this.Record.RecordIdentification);

                    UPCharacteristics characteristics = this.Group.Characteristics;
                    changedRecord.AddLink(new UPCRMLink(characteristics.RecordIdentification));
                    changedRecord.NewValueFieldId(this.Group.CatalogValue, characteristics.DestinationGroupField.FieldId);
                    changedRecord.NewValueFieldId(this.CatalogValue, characteristics.DestinationItemField.FieldId);

                    for (int i = 0; i < this.AdditionalFields?.Count; i++)
                    {
                        string newValue = this.values[i];
                        if (!string.IsNullOrEmpty(newValue))
                        {
                            UPConfigFieldControlField field = this.AdditionalFields[i];
                            changedRecord.NewValueFieldId(newValue, field.FieldId);
                        }
                    }
                }
                else if ((this.Changed && this.Record != null) || (this.Created && this.Record != null))
                {
                    changedRecord = new UPCRMRecord(this.Record.RecordIdentification);
                    for (int i = 0; i < this.AdditionalFields?.Count; i++)
                    {
                        string originalValue = this.OriginalValues[i];
                        string newValue      = this.values[i];
                        if (originalValue != newValue)
                        {
                            UPConfigFieldControlField field = this.AdditionalFields[i];
                            changedRecord.NewValueFromValueFieldId(newValue, originalValue, field.FieldId);
                        }
                    }
                }
            }

            return(changedRecord != null ? new List <UPCRMRecord> {
                changedRecord
            } : null);
        }
コード例 #3
0
        /// <summary>
        /// Create Changed UPCRMRecord
        /// </summary>
        /// <param name="functionValueMapping">
        /// Dictionary to store To/From time range.
        /// </param>
        /// <param name="functionValueMappingNullValue">
        /// Dictionary to store To/From null values if any.
        /// </param>
        /// <param name="timeType">
        /// timeType
        /// </param>
        /// <param name="contactRecordIdentification">
        /// contact Record Id
        /// </param>
        /// <param name="weekDayU7">
        /// weekday under 7
        /// </param>
        /// <returns>
        /// <see cref="UPCRMRecord"/>
        /// </returns>
        private UPCRMRecord CreateChangedUPCRMRecordRecord(
            Dictionary <string, object> functionValueMapping,
            Dictionary <string, object> functionValueMappingNullValue,
            string timeType,
            string contactRecordIdentification,
            int weekDayU7)
        {
            var changedRecord = (UPCRMRecord)null;

            functionValueMapping["DAYOFWEEK"] = $"{weekDayU7}";
            functionValueMapping["TYPE"]      = timeType;
            if (contactRecordIdentification != null && functionValueMapping.Keys.Count == 2)
            {
                changedRecord = new UPCRMRecord(contactRecordIdentification, Delete, null);
            }
            else if (contactRecordIdentification == null && functionValueMapping.Keys.Count > 2)
            {
                changedRecord = UPCRMRecord.CreateNew(infoAreaid);
                changedRecord.AddLink(new UPCRMLink(RecordIdentification));

                functionValueMapping.Append(functionValueMappingNullValue);

                AddValuesToRecordContextRecordId(functionValueMapping, changedRecord, contactRecordIdentification);
            }
            else if (contactRecordIdentification != null && !IsRecordEqual(contactRecordIdentification, functionValueMapping))
            {
                changedRecord = new UPCRMRecord(contactRecordIdentification);

                functionValueMapping.Append(functionValueMappingNullValue);

                AddValuesToRecordContextRecordId(functionValueMapping, changedRecord, contactRecordIdentification);
            }

            return(changedRecord);
        }
        private UPCRMRecord CreateNewRecord(
            UPCRMRecord parentRecord,
            UPCRMLinkParticipant participant,
            bool hasRequirement,
            UPMEditField requirementField,
            bool hasAcceptance,
            UPMEditField acceptanceField)
        {
            var record = UPCRMRecord.CreateNew(this.ParticipantsControl.LinkParticipantsInfoAreaId);

            if (parentRecord.IsNew && (parentRecord.Links == null || parentRecord.Links.Count == 0))
            {
                parentRecord.AddLink(new UPCRMLink(participant.LinkRecordIdentification));
            }

            this.ApplyTemplateFilterToRecord(record);
            record.AddLink(new UPCRMLink(parentRecord, -1));
            record.AddLink(new UPCRMLink(participant.LinkRecordIdentification));
            if (hasRequirement)
            {
                record.NewValueFieldId(requirementField.StringValue, participant.Context.RequirementField.FieldId);
            }

            if (hasAcceptance)
            {
                record.NewValueFieldId(acceptanceField.StringValue, participant.Context.AcceptanceField.FieldId);
            }

            return(record);
        }
コード例 #5
0
        /// <summary>
        /// Changeds the record.
        /// </summary>
        /// <returns></returns>
        public UPCRMRecord ChangedRecord()
        {
            if (this.positions.Count > 0 && this.DestinationRecord == null)
            {
                this.DestinationRecord = UPCRMRecord.CreateNew(this.SerialEntry.DestParentInfoAreaId);
                if (this.SerialEntry.DestinationParentTemplateFilter != null)
                {
                    this.DestinationRecord.ApplyValuesFromTemplateFilter(this.SerialEntry.DestinationParentTemplateFilter);
                }

                if (this.SerialEntry.DestParentEditFieldControl != null)
                {
                    foreach (FieldControlTab tab in this.SerialEntry.DestParentEditFieldControl.Tabs)
                    {
                        foreach (UPConfigFieldControlField field in tab.Fields)
                        {
                            if (field.Attributes.Dontsave && field.Attributes.DontcacheOffline)
                            {
                                continue;
                            }

                            if (string.IsNullOrEmpty(field.Function))
                            {
                                continue;
                            }

                            string val = this.SerialEntry.InitialFieldValuesForDestination.ValueOrDefault(field.Function) as string;
                            if (!string.IsNullOrEmpty(val))
                            {
                                if (field.Attributes.Dontsave)
                                {
                                    this.DestinationRecord.NewValueFromValueFieldIdOnlyOffline(val, null, field.FieldId, true);
                                }
                                else
                                {
                                    this.DestinationRecord.NewValueFromValueFieldId(val, null, field.FieldId);
                                }
                            }
                        }
                    }
                }

                this.DestinationRecord.AddLink(new UPCRMLink(this.SerialEntry.Record, -1));
                this.DestinationRecord.AddLink(new UPCRMLink(this.SourceRecordIdentification, -1));
                return(this.DestinationRecord);
            }

            return(string.IsNullOrEmpty(this.DestinationRecord.RecordIdentification) ? this.DestinationRecord : null);
        }
コード例 #6
0
        /// <summary>
        /// Requests add as favorite.
        /// </summary>
        /// <param name="recordIdentification">The record identification.</param>
        /// <returns></returns>
        public bool RequestAddAsFavorite(string recordIdentification)
        {
            this.currentRequest = new UPOfflineRecordRequest();
            UPCRMRecord record = UPCRMRecord.CreateNew(Constants.FAVORITES_INFOAREAID);

            if (this.TemplateFilter != null)
            {
                record.ApplyValuesFromTemplateFilter(this.TemplateFilter);
            }

            record.AddLink(new UPCRMLink(recordIdentification, Constants.FAVORITES_LINKID));
            return(this.currentRequest.StartRequest(this.OfflineRequestMode, new List <UPCRMRecord> {
                record
            }, this));
        }
        /// <summary>
        /// CRMs the records for parameters record add root.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="record">The record.</param>
        /// <param name="addRoot">if set to <c>true</c> [add root].</param>
        /// <returns></returns>
        public List <UPCRMRecord> CrmRecordsForParametersRecordAddRoot(Dictionary <string, object> parameters, UPCRMRecord record, bool addRoot)
        {
            List <UPCRMRecord> recordArray    = new List <UPCRMRecord>();
            UPCRMRecord        documentRecord = null;

            if (this.TemplateFilter != null)
            {
                UPConfigFilter filter = this.TemplateFilter.FilterByApplyingValueDictionary(parameters);
                if (filter != null)
                {
                    documentRecord      = UPCRMRecord.CreateNew(filter.InfoAreaId);
                    documentRecord.Mode = "NewOffline";
                    documentRecord.ApplyValuesFromTemplateFilter(filter);
                    recordArray.Add(documentRecord);
                }
            }

            if (!string.IsNullOrEmpty(this.DocumentLinkInfoAreaId) && documentRecord != null)
            {
                UPCRMRecord documentLinkRecord = UPCRMRecord.CreateNew(this.DocumentLinkInfoAreaId);
                documentLinkRecord.Mode = "NewOffline";
                UPConfigFilter filter = this.LinkTemplateFilter?.FilterByApplyingValueDictionary(parameters);
                if (filter != null)
                {
                    documentLinkRecord.ApplyValuesFromTemplateFilter(filter);
                }

                documentLinkRecord.AddLink(new UPCRMLink(record, this.RecordLinkId));
                documentLinkRecord.AddLink(new UPCRMLink(documentRecord, this.DocumentLinkLinkId));
                recordArray.Add(documentLinkRecord);
            }
            else if (string.IsNullOrEmpty(this.DocumentLinkInfoAreaId))
            {
                documentRecord?.AddLink(new UPCRMLink(record, this.RecordLinkId));
            }

            if (addRoot && recordArray.Count > 0)
            {
                recordArray.Add(record);
            }

            return(recordArray.Count > 0 ? recordArray : null);
        }
        private UPCRMRecord CreateNewRecord(
            UPCRMLinkParticipant participant,
            bool hasRequirement,
            UPMEditField requirementField,
            bool hasAcceptance,
            UPMEditField acceptanceField)
        {
            var record = UPCRMRecord.CreateNew(participant.RecordIdentification);

            this.ApplyTemplateFilterToRecord(record);
            if (hasRequirement && requirementField.StringValue != participant.RequirementText)
            {
                record.NewValueFromValueFieldId(requirementField.StringValue, participant.RequirementText, participant.Context.RequirementField.FieldId);
            }

            if (hasAcceptance && acceptanceField.StringValue != participant.AcceptanceText)
            {
                record.NewValueFromValueFieldId(acceptanceField.StringValue, participant.AcceptanceText, participant.Context.AcceptanceField.FieldId);
            }

            return(record);
        }
        /// <summary>
        /// Changeds the records for context new record link user changes only.
        /// </summary>
        /// <param name="childEditContext">The child edit context.</param>
        /// <param name="newRecord">if set to <c>true</c> [new record].</param>
        /// <param name="link">The link.</param>
        /// <param name="userChangesOnly">if set to <c>true</c> [user changes only].</param>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecordsForContextNewRecordLinkUserChangesOnly(UPChildEditContext childEditContext, bool newRecord, UPCRMLink link, bool userChangesOnly)
        {
            if (childEditContext.DeleteRecord)
            {
                if (newRecord)
                {
                    return(null);
                }

                UPCRMRecord record = new UPCRMRecord(childEditContext.RecordIdentification);
                record.Deleted = true;
                return(new List <UPCRMRecord> {
                    record
                });
            }

            Dictionary <string, UPEditFieldContext> changedFields = null;

            if (newRecord && !userChangesOnly)
            {
                if (this.combinedInitialValues != null)
                {
                    foreach (string fieldIdentification in this.combinedInitialValues.Keys)
                    {
                        int fieldId = fieldIdentification.FieldIdFromStringWithInfoAreaId(this.ChildInfoAreaId);
                        if (fieldId >= 0)
                        {
                            UPEditFieldContext initialValueEditField = new UPEditFieldContext(fieldId, this.combinedInitialValues[fieldIdentification] as string);
                            if (changedFields == null)
                            {
                                changedFields = new Dictionary <string, UPEditFieldContext> {
                                    { initialValueEditField.Key, initialValueEditField }
                                };
                            }
                            else
                            {
                                changedFields.SetObjectForKey(initialValueEditField, initialValueEditField.Key);
                            }
                        }
                    }
                }
            }

            foreach (UPEditFieldContext editFieldContext in childEditContext.EditFieldContext.Values)
            {
                if (editFieldContext.WasChanged(userChangesOnly))
                {
                    if (changedFields != null)
                    {
                        changedFields.SetObjectForKey(editFieldContext, editFieldContext.Key);
                    }
                    else
                    {
                        changedFields = new Dictionary <string, UPEditFieldContext> {
                            { editFieldContext.Key, editFieldContext }
                        };
                    }
                }
            }

            List <UPCRMRecord>      additionalRecords = null;
            ICollection <UPCRMLink> changedLinks      = (ICollection <UPCRMLink>)childEditContext.ChangedLinkArray ?? new List <UPCRMLink>();

            if (changedFields?.Count > 0 || changedLinks?.Count > 0)
            {
                UPCRMRecord record;
                if (newRecord)
                {
                    record = childEditContext.RecordIdentification.RecordId().Length > 6
                        ? new UPCRMRecord(childEditContext.RecordIdentification)
                        : UPCRMRecord.CreateNew(childEditContext.RecordIdentification.InfoAreaId());

                    record.AddLink(link);
                    UPConfigFilter createFilter = ConfigurationUnitStore.DefaultStore.FilterByName($"{record.InfoAreaId}.ChildCreateTemplate");
                    createFilter      = createFilter.FilterByApplyingDefaultReplacements();
                    additionalRecords = record.ApplyValuesFromTemplateFilter(createFilter, false);
                }
                else
                {
                    record = new UPCRMRecord(childEditContext.RecordIdentification);
                }

                foreach (UPEditFieldContext changedField in changedFields.Values)
                {
                    if (newRecord)
                    {
                        record.NewValueFieldId(changedField.Value, changedField.FieldId);
                    }
                    else
                    {
                        record.NewValueFromValueFieldId(changedField.Value, changedField.OriginalValue, changedField.FieldId);
                    }
                }

                foreach (UPCRMLink changedLink in changedLinks)
                {
                    record.AddLink(changedLink);
                }

                if (additionalRecords?.Count > 0)
                {
                    List <UPCRMRecord> arr = new List <UPCRMRecord> {
                        record
                    };
                    arr.AddRange(additionalRecords);
                    return(arr);
                }

                return(new List <UPCRMRecord> {
                    record
                });
            }

            return(null);
        }
コード例 #10
0
        private void ContinueRecordDoesNotExist()
        {
            string requestModeString         = this.ViewReference.ContextValueForKey("RequestMode");
            UPOfflineRequestMode requestMode = UPOfflineRequest.RequestModeFromString(requestModeString, UPOfflineRequestMode.OnlineOnly);
            string filterName   = this.ViewReference.ContextValueForKey("TemplateFilter");
            string infoAreaId   = this.ViewReference.ContextValueForKey("InfoAreaId");
            string linkIdString = this.ViewReference.ContextValueForKey("LinkId");

            if (string.IsNullOrEmpty(infoAreaId))
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorParameterEmpty, "InfoAreaId"), true);
                return;
            }

            int  linkId = -1;
            bool noLink = false;

            if (!string.IsNullOrEmpty(linkIdString))
            {
                if (linkIdString == "NoLink")
                {
                    noLink = true;
                }

                linkId = Convert.ToInt32(linkIdString);
            }

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

            if (filter == null)
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorFilterMissing, filterName), true);
                return;
            }

            filter      = filter.FilterByApplyingValueDictionaryDefaults(this.sourceCopyFields, true);
            this.record = UPCRMRecord.CreateNew(infoAreaId);
            if (!noLink && !string.IsNullOrEmpty(this.LinkRecordIdentification))
            {
                this.record.AddLink(new UPCRMLink(this.LinkRecordIdentification, linkId));
            }

            this.record.ApplyValuesFromTemplateFilter(filter);
            UPOfflineEditRecordRequest request = new UPOfflineEditRecordRequest(0);
            string optionsString = this.ViewReference.ContextValueForKey("Options");

            if (!string.IsNullOrEmpty(optionsString))
            {
                Dictionary <string, object> options = optionsString.JsonDictionaryFromString();
                if (Convert.ToInt32(options["ComputeLinks"]) != 0)
                {
                    request.AlwaysSetImplicitLinks = true;
                }
            }

            List <UPCRMRecord> recordArray = new List <UPCRMRecord> {
                this.record
            };
            string syncParentInfoAreaIdString = this.ViewReference.ContextValueForKey("SyncParentInfoAreaIds");

            if (!string.IsNullOrEmpty(syncParentInfoAreaIdString))
            {
                var syncParentInfoAreaIds = syncParentInfoAreaIdString.Split(',');
                foreach (string syncParentInfoAreaId in syncParentInfoAreaIds)
                {
                    var infoAreaIdParts = syncParentInfoAreaId.Split(':');
                    if (infoAreaIdParts.Length == 1)
                    {
                        recordArray.Add(new UPCRMRecord(syncParentInfoAreaId, new UPCRMLink(this.record, -1)));
                    }
                    else if (infoAreaIdParts.Length > 1)
                    {
                        recordArray.Add(new UPCRMRecord(infoAreaIdParts[0], new UPCRMLink(this.record, Convert.ToInt32(infoAreaIdParts[1]))));
                    }
                }
            }

            if (this.ModelController.SetOfflineRequest(request, true))
            {
                if (request.StartRequest(requestMode, recordArray, this) == false)
                {
                    this.ModelController.SetOfflineRequest(null, true);
                    return;
                }
            }
            else
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorActionNotPossible, LocalizedString.TextErrorActionPending, true);
            }
        }