Example #1
0
        /// <summary>
        /// Changeds the rep participant acceptance record.
        /// </summary>
        /// <returns></returns>
        public UPCRMRecord ChangedRepParticipantAcceptanceRecord()
        {
            if (this.Context.AcceptanceFieldId >= 0 && !string.IsNullOrEmpty(this.AcceptanceRecordIdentification) && this._originalAcceptance != this.AcceptanceText)
            {
                UPCRMRecord record = new UPCRMRecord(this.AcceptanceRecordIdentification);
                record.AddValue(new UPCRMFieldValue(this.AcceptanceText, this._originalAcceptance, record.InfoAreaId, this.Context.AcceptanceFieldId));
                return(record);
            }

            return(null);
        }
        /// <summary>
        /// Stores the request with offline records.
        /// </summary>
        /// <param name="_offlineRecords">The offline records.</param>
        /// <param name="rootRecord">The root record.</param>
        /// <returns>0, if successfull</returns>
        private int StoreRequestWithOfflineRecords(List <UPCRMRecord> _offlineRecords, UPCRMRecord rootRecord)
        {
            IOfflineStorage storage = this.Storage;

            storage.Database.BeginTransaction();

            if (this.RequestNr == -1)
            {
                if (!this.CreateRequest(storage.Database))
                {
                    storage.Database.Rollback();
                    return(1);
                }
            }

            int ret = storage.SaveDocumentUpload(this.Data, this.RequestNr, this.FileName, this.MimeType, this.RecordIdentification, this.FieldId, storage.Database);

            if (ret == 0 && _offlineRecords != null)
            {
                int  nextRecordNr           = 1;
                bool documentKeyFieldFilled = this.FieldId < 0;
                foreach (UPCRMRecord record in _offlineRecords)
                {
                    ret = storage.SaveRecord(record, this.RequestNr, nextRecordNr++, storage.Database);
                    if (ret != 0)
                    {
                        break;
                    }

                    if (rootRecord != null && !documentKeyFieldFilled && record.InfoAreaId == "D1")
                    {
                        documentKeyFieldFilled = true;
                        string documentKey = $"new:{record.RecordIdentification}";
                        rootRecord.AddValue(new UPCRMFieldValue(documentKey, rootRecord.InfoAreaId, this.FieldId, true));
                    }
                }
            }

            if (ret == 0)
            {
                storage.Database.Commit();
            }
            else
            {
                storage.Database.Rollback();
            }

            return(ret);
        }
        /// <summary>
        /// Applies the time zone record.
        /// </summary>
        /// <param name="timeZone">
        /// The time zone.
        /// </param>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ApplyTimeZoneRecord(UPCRMTimeZone timeZone, UPCRMRecord record)
        {
            DateTime?oldDate = null;
            DateTime?date    = null;

            if (this.DateFieldValue != null)
            {
                if (this.TimeFieldValue != null)
                {
                    if (!string.IsNullOrEmpty(this.DateFieldValue.OldValue) && !string.IsNullOrEmpty(this.TimeFieldValue.OldValue))
                    {
                        oldDate = timeZone.DateFromCurrentDataMMDateStringTimeString(
                            this.DateFieldValue.OldValue,
                            this.TimeFieldValue.OldValue);
                    }

                    if (!string.IsNullOrEmpty(this.DateFieldValue.Value) && !string.IsNullOrEmpty(this.TimeFieldValue.Value))
                    {
                        date = timeZone.DateFromCurrentDataMMDateStringTimeString(
                            this.DateFieldValue.Value,
                            this.TimeFieldValue.Value);
                    }
                }
                else if (!string.IsNullOrEmpty(this.DateFieldValue.TimeOriginalValue))
                {
                    if (!string.IsNullOrEmpty(this.DateFieldValue.OldValue))
                    {
                        oldDate = timeZone.DateFromCurrentDataMMDateStringTimeString(
                            this.DateFieldValue.OldValue,
                            this.DateFieldValue.TimeOriginalValue);
                    }

                    if (!string.IsNullOrEmpty(this.DateFieldValue.Value))
                    {
                        date = timeZone.DateFromCurrentDataMMDateStringTimeString(
                            this.DateFieldValue.Value,
                            this.DateFieldValue.TimeOriginalValue);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(this.TimeFieldValue.DateOriginalValue))
            {
                /* -> dateFieldValue == nil && timeFieldValue != nil */
                if (!string.IsNullOrEmpty(this.TimeFieldValue.OldValue))
                {
                    oldDate = timeZone.DateFromCurrentDataMMDateStringTimeString(
                        this.TimeFieldValue.DateOriginalValue,
                        this.TimeFieldValue.OldValue);
                }

                if (!string.IsNullOrEmpty(this.TimeFieldValue.Value))
                {
                    date = timeZone.DateFromCurrentDataMMDateStringTimeString(
                        this.TimeFieldValue.DateOriginalValue,
                        this.TimeFieldValue.Value);
                }
            }

            string changedOldDate = null;

            if (oldDate != null)
            {
                changedOldDate = timeZone.GetAdjustedClientDataMMDate(oldDate.Value);
                var changedOldTime = timeZone.GetAdjustedClientDataMMTime(oldDate.Value);
                if (!string.IsNullOrEmpty(this.DateFieldValue?.OldValue))
                {
                    this.DateFieldValue.OldValue = changedOldDate;
                }

                if (!string.IsNullOrEmpty(this.TimeFieldValue?.OldValue))
                {
                    this.TimeFieldValue.OldValue = changedOldTime;
                }
            }

            if (date != null)
            {
                var changedDate = timeZone.GetAdjustedClientDataMMDate(date.Value);
                var changedTime = timeZone.GetAdjustedClientDataMMTime(date.Value);
                if (!string.IsNullOrEmpty(this.DateFieldValue?.Value))
                {
                    this.DateFieldValue.ChangeValue = changedDate;
                }
                else if (this.DateFieldValue == null && !string.IsNullOrEmpty(changedOldDate) &&
                         !string.IsNullOrEmpty(changedDate) && !changedOldDate.Equals(changedDate))
                {
                    var v = new UPCRMFieldValue(
                        changedDate,
                        changedOldDate,
                        this.TimeFieldValue.InfoAreaId,
                        this.DateFieldId,
                        this.TimeFieldValue.OnlyOffline);
                    record.AddValue(v);
                }

                if (string.IsNullOrEmpty(this.TimeFieldValue.Value))
                {
                    this.TimeFieldValue.ChangeValue = changedTime;
                }
            }

            return(true);
        }
        private void ProcessResult(UPCRMResult result)
        {
            UPRecordCopyStep currentStep = this.stepQueue[0];

            this.stepQueue.RemoveAt(0);
            UPConfigQueryTable queryTable = currentStep.QueryTable;
            int count            = result.RowCount;
            int resultTableCount = result.NumberOfResultTables;
            UPContainerInfoAreaMetaInfo copyResultInfoArea = null;

            if (queryTable.InfoAreaId == currentStep.FieldControl.InfoAreaId)
            {
                copyResultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(0);
            }

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow row    = (UPCRMResultRow)result.ResultRowAtIndex(i);
                UPCRMRecord    record = new UPCRMRecord(queryTable.InfoAreaId);
                if (currentStep.DestinationRecord != null)
                {
                    record.AddLink(new UPCRMLink(currentStep.DestinationRecord, queryTable.LinkId));
                }

                for (int j = 1; j < resultTableCount; j++)
                {
                    string linkRecordIdentification = row.RecordIdentificationAtIndex(j);
                    if (string.IsNullOrEmpty(linkRecordIdentification) && !result.IsServerResult)
                    {
                        UPContainerInfoAreaMetaInfo resultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j);
                        UPCRMLinkReader             linkReader     = new UPCRMLinkReader(StringExtensions.InfoAreaIdRecordId(currentStep.FieldControl.InfoAreaId, row.RootRecordId),
                                                                                         $"{resultInfoArea.InfoAreaId}:{resultInfoArea.LinkId}", null);
                        linkRecordIdentification = linkReader.RequestLinkRecordOffline();
                    }

                    int linkId = -1;
                    if (linkRecordIdentification?.Length > 8)
                    {
                        if (currentStep.DestinationRecord == null || queryTable.LinkId != linkId ||
                            linkRecordIdentification.InfoAreaId() != currentStep.DestinationRecord.InfoAreaId)
                        {
                            record.AddLink(new UPCRMLink(linkRecordIdentification, linkId));
                        }
                    }
                }

                Dictionary <string, object> fieldsWithFunctions = row.ValuesWithFunctions();
                UPConfigQueryTable          replacedTable       = queryTable.QueryTableByApplyingValueDictionary(fieldsWithFunctions);
                if (copyResultInfoArea != null)
                {
                    foreach (UPContainerFieldMetaInfo field in copyResultInfoArea.Fields)
                    {
                        string val = row.RawValueAtIndex(field.PositionInResult);
                        if (!string.IsNullOrEmpty(val))
                        {
                            record.AddValue(new UPCRMFieldValue(val, field.InfoAreaId, field.FieldId));
                        }
                    }
                }

                if (replacedTable != null)
                {
                    record.ApplyValuesFromTemplateFilter(replacedTable, true);
                }

                int numberOfSubTables = queryTable.NumberOfSubTables;
                if (numberOfSubTables > 0)
                {
                    for (int k = 0; k < numberOfSubTables; k++)
                    {
                        UPRecordCopyStep subStep = new UPRecordCopyStep();
                        subStep.QueryTable = queryTable.SubTableAtIndex(k);
                        subStep.SourceRecordIdentification = row.RootRecordIdentification;
                        subStep.DestinationRecord          = record;
                        this.ConfigForStepFromQueryTable(subStep, subStep.QueryTable);
                        this.stepQueue.Add(subStep);
                    }
                }

                this.recordArray.Add(record);
            }

            this.ExecuteNextStep();
        }
Example #5
0
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <param name="rootRecord">The root record.</param>
        /// <param name="data">The data.</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords(UPCRMRecord rootRecord, Dictionary <string, object> data, bool ignoreDefault)
        {
            if (!this.Multiple)
            {
                return(this.SingleAnswerChangedRecords(rootRecord, data, false, ignoreDefault));
            }

            if (!this.Changed)
            {
                return(null);
            }

            string        infoAreaId      = this.Root.SurveyAnswerSearchAndList.InfoAreaId;
            List <string> recordsToDelete = new List <string>();

            foreach (UPSurveyAnswerSingle singleRecord in this.singleAnswerDictionary.Values)
            {
                if (singleRecord.Deleted && !string.IsNullOrEmpty(singleRecord.RecordIdentification))
                {
                    recordsToDelete.Add(singleRecord.RecordIdentification);
                }
            }

            List <UPCRMRecord> changedRecords = new List <UPCRMRecord>();

            foreach (UPSurveyAnswerSingle singleRecord in this.singleAnswerDictionary.Values)
            {
                if (!singleRecord.Deleted && string.IsNullOrEmpty(singleRecord.RecordIdentification))
                {
                    UPCRMRecord record;
                    if (recordsToDelete.Count > 0)
                    {
                        string reUseRecordIdentification = recordsToDelete[0];
                        recordsToDelete.RemoveAt(0);
                        record = new UPCRMRecord(reUseRecordIdentification);
                    }
                    else
                    {
                        record = new UPCRMRecord(infoAreaId);
                        record.AddLink(new UPCRMLink(rootRecord, -1));
                        if (this.Root.AnswerQuestionNumberField != null)
                        {
                            record.AddValue(new UPCRMFieldValue(this.Question.QuestionId, infoAreaId, this.Root.AnswerQuestionNumberField.FieldId));
                        }
                    }

                    if (this.Root.SurveyAnswerTemplateFilter != null)
                    {
                        UPConfigFilter filter = this.Root.SurveyAnswerTemplateFilter.FilterByApplyingValueDictionaryDefaults(data, true);
                        record.ApplyValuesFromTemplateFilter(filter);
                    }

                    if (!string.IsNullOrEmpty(this.Question.RecordIdentification) && this.Question.Questionnaire.Manager.LinkAnswerToQuestion)
                    {
                        record.AddLink(new UPCRMLink(this.Question.RecordIdentification));
                    }

                    if (this.Question.HasAnswerOptions)
                    {
                        if (this.Root.AnswerAnswerNumberField != null)
                        {
                            record.AddValue(new UPCRMFieldValue(singleRecord.AnswerId, infoAreaId, this.Root.AnswerAnswerNumberField.FieldId));
                        }

                        if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionAnswer && this.Question.HasAnswerOptions)
                        {
                            IQuestionnaireAnswerOption answerOption = this.Question.AnswerForId(singleRecord.AnswerId);
                            if (answerOption != null)
                            {
                                record.AddLink(new UPCRMLink(answerOption.RecordIdentification));
                            }
                        }
                    }
                    else
                    {
                        if (this.Root.AnswerAnswerTextField != null)
                        {
                            string text = singleRecord.AnswerId;
                            if (this.Question.AnswersFromCatalog && this.Question.Questionnaire.Manager.SaveCatalogValuesAsText)
                            {
                                text = this.Question.TextForAnswerId(this.AnswerText) ?? string.Empty;
                            }

                            record.AddValue(new UPCRMFieldValue(text, infoAreaId, this.Root.AnswerAnswerTextField.FieldId));
                        }
                    }

                    changedRecords.Add(record);
                }
            }

            changedRecords.AddRange(recordsToDelete.Select(deleteRecordId => new UPCRMRecord(deleteRecordId, "Delete")));
            return(changedRecords);
        }
Example #6
0
        /// <summary>
        /// Singles the answer changed records.
        /// </summary>
        /// <param name="rootRecord">The root record.</param>
        /// <param name="data">The data.</param>
        /// <param name="ignoreExisting">if set to <c>true</c> [ignore existing].</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> SingleAnswerChangedRecords(UPCRMRecord rootRecord, Dictionary <string, object> data, bool ignoreExisting, bool ignoreDefault)
        {
            if (this.Changed)
            {
                UPCRMRecord record;
                string      infoAreaId   = this.Root.SurveyAnswerSearchAndList.InfoAreaId;
                bool        existsRecord = false;
                if (!ignoreExisting && !string.IsNullOrEmpty(this.RecordIdentification))
                {
                    record       = new UPCRMRecord(this.RecordIdentification);
                    existsRecord = true;
                }
                else if (!ignoreDefault || !this.IsDefaultAnswer)
                {
                    record = new UPCRMRecord(infoAreaId);
                    record.AddLink(new UPCRMLink(rootRecord, -1));
                    if (this.Root.AnswerQuestionNumberField != null)
                    {
                        record.AddValue(new UPCRMFieldValue(this.Question.QuestionId, infoAreaId, this.Root.AnswerQuestionNumberField.FieldId));
                    }

                    if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionnaire)
                    {
                        record.AddLink(new UPCRMLink(this.Question.Questionnaire.RecordIdentification));
                    }

                    if (this.Question.Questionnaire.Manager.LinkAnswerToQuestion)
                    {
                        record.AddLink(new UPCRMLink(this.Question.RecordIdentification));
                    }
                }
                else
                {
                    return(null);
                }

                if (this.Root.SurveyAnswerTemplateFilter != null)
                {
                    UPConfigFilter filter = this.Root.SurveyAnswerTemplateFilter.FilterByApplyingValueDictionaryDefaults(data, true);
                    record.ApplyValuesFromTemplateFilter(filter);
                }

                if (this.Root.AnswerAnswerNumberField != null)
                {
                    record.AddValue(new UPCRMFieldValue(this.AnswerNumber, infoAreaId, this.Root.AnswerAnswerNumberField.FieldId));
                }

                if (this.Root.AnswerAnswerTextField != null)
                {
                    string text = this.AnswerText;
                    if (this.Question.AnswersFromCatalog && this.Question.Questionnaire.Manager.SaveCatalogValuesAsText)
                    {
                        text = this.Question.TextForAnswerId(this.AnswerText) ?? string.Empty;
                    }

                    record.AddValue(new UPCRMFieldValue(text, infoAreaId, this.Root.AnswerAnswerTextField.FieldId));
                }

                if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionAnswer && this.Question.HasAnswerOptions)
                {
                    IQuestionnaireAnswerOption answerOption = this.Question.AnswerForId(this.AnswerNumber);
                    if (answerOption != null)
                    {
                        if (existsRecord && this.Question.Questionnaire.Manager.DeleteAndInsertOnAnswerOptionChange)
                        {
                            UPCRMRecord        deleteRecord   = new UPCRMRecord(this.RecordIdentification, "Delete");
                            List <UPCRMRecord> createdRecords = this.SingleAnswerChangedRecords(rootRecord, data, true, ignoreDefault);
                            List <UPCRMRecord> changedRecords = new List <UPCRMRecord> {
                                deleteRecord
                            };
                            changedRecords.AddRange(createdRecords);
                            return(changedRecords);
                        }

                        record.AddLink(new UPCRMLink(answerOption.RecordIdentification));
                    }
                    else if (this.Question.Questionnaire.Manager.DeleteSingleAnswerOptionIfEmpty)
                    {
                        return(existsRecord ? new List <UPCRMRecord> {
                            new UPCRMRecord(record.RecordIdentification, "Delete")
                        } : null);
                    }
                }

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

            return(null);
        }
        /// <summary>
        /// Updateds the root record with template filter.
        /// </summary>
        /// <param name="templateFilter">The template filter.</param>
        /// <returns></returns>
        public override UPCRMRecord UpdatedRootRecordWithTemplateFilter(UPConfigFilter templateFilter)
        {
            UPCRMRecord record = base.UpdatedRootRecordWithTemplateFilter(templateFilter);

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

            if (this.DestRootFieldControl != null)
            {
                record.Mode = "Update";
                foreach (FieldControlTab tab in this.DestRootFieldControl.Tabs)
                {
                    foreach (UPConfigFieldControlField field in tab.Fields)
                    {
                        string value = null;
                        if (field.Attributes.Dontsave && field.Attributes.DontcacheOffline)
                        {
                            continue;
                        }

                        switch (field.Function)
                        {
                        case "Quantity":
                            value = this.UnitCount.ToString();
                            break;

                        case "EndPrice":
                            value = this.EndPrice.ToString("##.00");
                            break;

                        case "FreeGoods":
                            value = this.FreeGoodsCount.ToString();
                            break;

                        case "NetPrice":
                            value = this.NetPrice.ToString("##.00");
                            break;

                        case "Rebate":
                        case "Discount":
                            double rebate   = 0;
                            double endPrice = this.EndPrice;
                            if (endPrice > 0.0001)
                            {
                                rebate = 1 - (this.NetPrice / endPrice);
                            }

                            value = rebate.ToString("##.00000");
                            break;

                        default:
                            continue;
                        }

                        if (!string.IsNullOrEmpty(value))
                        {
                            record.AddValue(new UPCRMFieldValue(value, this.DestRootFieldControl.InfoAreaId, field.FieldId, field.Attributes.Dontsave));
                        }
                    }
                }
            }

            return(record);
        }