Exemple #1
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>
        /// Uploads the file.
        /// </summary>
        /// <param name="file">The file.</param>
        public void UploadFile(UPMInboxFile file)
        {
            this.uploadingFile = file;
            byte[] data     = null; //NSData.DataWithContentsOfURL(file.URL);
            string fileName = file.Name;

            foreach (UPEditFieldContext changedField in this.editFieldContexts.Values)
            {
                if (changedField.FieldConfig.Function == "Filename" && !string.IsNullOrEmpty(changedField.Value))
                {
                    fileName = changedField.Value;
                    // New filename has no extension. Add original extension
                    //if (fileName.PathExtension().Length == 0)
                    //{
                    //    fileName = $"{fileName}.{file.Path.PathExtension()}";
                    //}

                    break;
                }
            }

            this.docUploadRequest = new UPOfflineUploadDocumentRequest(data, -1, fileName, file.MimeTye, this.recordIdentification, -1);
            List <UPCRMRecord> docUploadRecords = this.docUploadRequest.CreateOfflineRecords();
            string             d1RecordId       = docUploadRecords[0].RecordId;
            string             d3RecordId       = docUploadRecords[1].RecordId;
            UPCRMRecord        d1Record         = new UPCRMRecord(d1RecordId, "Update");
            UPCRMRecord        d3Record         = new UPCRMRecord(d3RecordId, "Update");

            this.editRecordRequest = new UPOfflineEditRecordRequest(UPOfflineRequestMode.OnlineConfirm, this.ViewReference);
            foreach (UPEditFieldContext changedField in this.editFieldContexts.Values)
            {
                UPCRMRecord record = changedField.FieldConfig.InfoAreaId == "D1" ? d1Record : d3Record;
                if (changedField.FieldConfig.Function == "Filename")
                {
                    continue;
                }

                UPCRMFieldValue fieldValue = record.NewValueFieldId(changedField.Value, changedField.FieldId);
                if (!string.IsNullOrEmpty(changedField.DateOriginalValue))
                {
                    fieldValue.DateOriginalValue = changedField.DateOriginalValue;
                }
                else if (!string.IsNullOrEmpty(changedField.TimeOriginalValue))
                {
                    fieldValue.TimeOriginalValue = changedField.TimeOriginalValue;
                }
            }

            this.editRecordRequest.TitleLine   = "FieldUploadFields";
            this.editRecordRequest.DetailsLine = "";
            this.multiRequest = new UPOfflineMultiRequest(this);
            this.multiRequest.AddRequest(this.docUploadRequest);
            this.multiRequest.AddRequest(this.editRecordRequest);
            this.multiRequest.Start();
        }
        /// <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);
        }