Exemple #1
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);
        }
Exemple #2
0
        private void AddValuesToRecordContextRecordId(Dictionary <string, object> functionValueMapping, UPCRMRecord changedRecord, string contectRecordIdentification)
        {
            Dictionary <string, object> contextValuesWithFunctions = null;

            for (int row = 0; row < this.contextResult.RowCount; row++)
            {
                var resultRow = (UPCRMResultRow)this.contextResult.ResultRowAtIndex(row);
                if (resultRow.RecordIdentificationAtFieldIndex(0) == contectRecordIdentification)
                {
                    contextValuesWithFunctions = resultRow.ValuesWithFunctions();
                    break;
                }
            }

            foreach (string function in functionValueMapping.Keys)
            {
                if (contextValuesWithFunctions == null)
                {
                    if (functionValueMapping.ValueOrDefault(function) != null)
                    {
                        changedRecord.NewValueFieldId(functionValueMapping.ValueOrDefault(function) as string,
                                                      this.FieldControl.FunctionNames().ValueOrDefault(function).FieldId);
                    }
                    else
                    {
                        changedRecord.NewValueFieldId(null, this.FieldControl.FunctionNames().ValueOrDefault(function).FieldId);
                    }
                }
                else
                {
                    if (functionValueMapping.ValueOrDefault(function) != null)
                    {
                        changedRecord.NewValueFromValueFieldId(
                            functionValueMapping.ValueOrDefault(function) as string,
                            contextValuesWithFunctions.ValueOrDefault(function) as string,
                            this.FieldControl.FunctionNames().ValueOrDefault(function).FieldId);
                    }
                    else
                    {
                        changedRecord.NewValueFromValueFieldId(null, contextValuesWithFunctions.ValueOrDefault(function) as string,
                                                               this.FieldControl.FunctionNames().ValueOrDefault(function).FieldId);
                    }
                }
            }
        }
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords()
        {
            UPCRMRecord changedRecord = null;

            if (this.Deleted && this.Record != null)
            {
                changedRecord = new UPCRMRecord(this.Record.RecordIdentification, "Delete");
            }
            else
            {
                if (this.Created && this.Record == null)
                {
                    UPObjectives objectives = this.Group.Objectives;
                    changedRecord = new UPCRMRecord(this.Group.Configuration.DestinationFieldControl.InfoAreaId);
                    changedRecord.AddLink(new UPCRMLink(objectives.RecordIdentification));
                    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)
                {
                    changedRecord = new UPCRMRecord(this.Record.RecordIdentification);
                    changedRecord.AddLink(new UPCRMLink(this.Group.Objectives.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);
                        }
                    }

                    if (this.completed != this.originalCompleted)
                    {
                        string sCompleted         = StringExtensions.CrmValueFromBool(this.completed);
                        string sOriginalCompleted = StringExtensions.CrmValueFromBool(this.originalCompleted);
                        if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedFunction) != null)
                        {
                            changedRecord.NewValueFromValueFieldId(sCompleted, sOriginalCompleted, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedFunction).FieldId);
                        }

                        if (this.completed)
                        {
                            if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedOnFunction) != null)
                            {
                                changedRecord.NewValueFromValueFieldId(StringExtensions.CrmValueFromDate(DateTime.UtcNow), string.Empty, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedOnFunction).FieldId);
                            }

                            if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedByFunction) != null)
                            {
                                changedRecord.NewValueFieldId(ServerSession.CurrentSession.CurRep, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedByFunction).FieldId);
                            }
                        }
                    }
                }
            }

            return(changedRecord != null ? new List <UPCRMRecord> {
                changedRecord
            } : null);
        }