/// <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> /// Creates the record. /// </summary> /// <param name="record">The record.</param> /// <param name="undo">if set to <c>true</c> [undo].</param> /// <returns>Record</returns> public DAL.Record CreateRecord(UPCRMRecord record, bool undo) { string infoAreaId = record.InfoAreaId; List <FieldIdType> fieldIds; List <string> linkFieldNames; bool checkDataModel = true; TableInfo tableInfo = this.DatabaseInstance.GetTableInfoByInfoArea(infoAreaId); if (tableInfo == null) { return(null); } int statNoField = 0, lnrField = 0; bool saveOfflineStationNumber = false; if (!undo && record.OfflineRecordNumber > 0 && record.OfflineStationNumber > 0) { statNoField = tableInfo.GetStatNoFieldId(); if (statNoField >= 0) { lnrField = tableInfo.GetLNrFieldId(); if (lnrField >= 0 && tableInfo.GetFieldInfo(statNoField) != null && tableInfo.GetFieldInfo(lnrField) != null) { saveOfflineStationNumber = true; } } } List <UPCRMFieldValue> fieldValues = record.FieldValues; int fieldCount = fieldValues?.Count ?? 0; int linkCount = record.Links?.Count ?? 0; if (undo) { linkCount = 0; } List <string> recordFieldValues = new List <string>(); if (fieldCount == 0) { fieldIds = null; } else { fieldIds = new List <FieldIdType>(); for (int i = 0; i < fieldCount; i++) { UPCRMFieldValue fieldValue = fieldValues[i]; FieldInfo fieldInfo = tableInfo.GetFieldInfo(fieldValue.FieldId); if (!checkDataModel || fieldInfo != null) { int currentFieldId = fieldValue.FieldId; fieldIds.Add((FieldIdType)currentFieldId); recordFieldValues.Add(undo ? fieldValue.OldValue : fieldValue.Value); if (saveOfflineStationNumber && (currentFieldId == statNoField || currentFieldId == lnrField)) { saveOfflineStationNumber = false; } } } if (saveOfflineStationNumber) { fieldIds.Add((FieldIdType)statNoField); recordFieldValues.Add(record.OfflineStationNumber.ToString()); fieldIds.Add((FieldIdType)lnrField); recordFieldValues.Add(record.OfflineRecordNumber.ToString()); } } if (record.Links != null && (record.Links.Count == 0 || undo)) { linkFieldNames = null; linkCount = 0; } else { linkFieldNames = new List <string>(); for (int i = 0; i < linkCount; i++) { UPCRMLink link = record.Links[i]; LinkInfo linkInfo = tableInfo.GetLink(link.LinkFieldName()) ?? tableInfo.GetLink(link.InfoAreaId, link.LinkId); if (linkInfo != null && linkInfo.HasColumn) { if (linkInfo.IsGeneric) { string targetInfoAreaId = this.RootPhysicalInfoAreaIdForInfoAreaId(link.InfoAreaId); recordFieldValues.Add(targetInfoAreaId); linkFieldNames.Add(linkInfo.InfoAreaColumnName); } recordFieldValues.Add(link.RecordId); linkFieldNames.Add(linkInfo.ColumnName); } } } var recordTemplate = new RecordTemplate( this.DatabaseInstance, false, infoAreaId, fieldIds?.Count ?? 0, fieldIds?.ToArray(), linkFieldNames.Count, linkFieldNames, false, false); Record rec = new Record(infoAreaId, record.RecordId); rec.SetTemplate(recordTemplate); for (var i = 0; i < recordFieldValues.Count; i++) { rec.SetValue(i, recordFieldValues[i]); } return(rec); }
/// <summary> /// Gets the changed records. /// </summary> /// <param name="rootTemplateFilter">The root template filter.</param> /// <param name="baseTemplateFilter">The base template filter.</param> /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param> /// <returns></returns> public List <UPCRMRecord> ChangedRecords(UPConfigFilter rootTemplateFilter, UPConfigFilter baseTemplateFilter, bool ignoreDefault) { UPCRMRecord rootRecord; bool changedRoot = false; if (!string.IsNullOrEmpty(this.AnswerRootRecordIdentification)) { rootRecord = new UPCRMRecord(this.AnswerRootRecordIdentification); } else { rootRecord = new UPCRMRecord(this.SurveySearchAndList.InfoAreaId); rootRecord.AddLink(new UPCRMLink(this.RootRecordIdentification)); if (this.Questionnaire.Manager.LinkSurveyToQuestionnaire) { rootRecord.AddLink(new UPCRMLink(this.Questionnaire.RecordIdentification)); } if (this.SurveyTemplateFilter != null) { UPConfigFilter filter = this.SurveyTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true); rootRecord.ApplyValuesFromTemplateFilter(filter); } changedRoot = true; } Dictionary <string, UPCRMRecord> foreignFieldDictionary = new Dictionary <string, UPCRMRecord>(); List <UPCRMRecord> answerRecords = new List <UPCRMRecord>(); foreach (UPQuestionnaireQuestion question in this.Questionnaire.Questions) { UPSurveyAnswer answer = this.surveyAnswers[question.QuestionId]; List <UPCRMRecord> currentAnswerRecords = answer.ChangedRecords(rootRecord, this.Parameters, ignoreDefault); if (currentAnswerRecords.Count > 0) { answerRecords.AddRange(currentAnswerRecords); } if (question.Save) { UPSurveyForeignField foreignField = answer.SurveyForeignField; if (!string.IsNullOrEmpty(foreignField.RecordIdentification) && !string.IsNullOrEmpty(foreignField.Value) && !string.IsNullOrEmpty(answer.Answer) && foreignField.Value != answer.Answer) { UPCRMRecord foreignRecord = foreignFieldDictionary.ValueOrDefault(foreignField.RecordIdentification); if (foreignRecord == null) { foreignRecord = new UPCRMRecord(foreignField.RecordIdentification); foreignFieldDictionary[foreignField.RecordIdentification] = foreignRecord; } UPCRMFieldValue fieldValue = new UPCRMFieldValue(answer.Answer, foreignRecord.InfoAreaId, foreignField.FieldInfo.FieldId, this.Questionnaire.Manager.AutomaticOnlineSaveOfForeignFields); foreignRecord.AddValue(fieldValue); } } } List <UPCRMRecord> changedRecords = new List <UPCRMRecord>(); if (changedRoot) { changedRecords.Add(rootRecord); } if (answerRecords.Count > 0) { changedRecords.AddRange(answerRecords); } if (changedRecords.Count > 0) { UPCRMRecord rootSyncRecord = new UPCRMRecord(rootRecord, "Sync"); changedRecords.Add(rootSyncRecord); } if (foreignFieldDictionary.Count > 0) { changedRecords.AddRange(foreignFieldDictionary.Values); } if (rootTemplateFilter != null) { rootTemplateFilter = rootTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true); if (rootTemplateFilter != null) { UPCRMRecord record = new UPCRMRecord(rootRecord); record.ApplyValuesFromTemplateFilter(rootTemplateFilter); changedRecords.Add(record); } } if (baseTemplateFilter != null) { baseTemplateFilter = baseTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true); if (baseTemplateFilter != null) { UPCRMRecord record = new UPCRMRecord(this.RecordIdentification); record.ApplyValuesFromTemplateFilter(baseTemplateFilter); changedRecords.Add(record); } } return(changedRecords); }