/// <summary> /// Loads for link record. /// </summary> /// <param name="linkRecord">The link record.</param> /// <param name="filterParameters">The filter parameters.</param> public void LoadForLinkRecord(UPCRMRecord linkRecord, Dictionary <string, object> filterParameters) { this.FilterParameters = filterParameters; this.LinkRecord = linkRecord; this.loadStep = 0; if (this.ParentLinkString != null) { this.linkReader = new UPCRMLinkReader(this.LinkRecord.RecordIdentification, this.ParentLinkString, this); this.linkReader.Start(); } else { this.linkRecordIdentification = this.LinkRecord.RecordIdentification; this.LoadArticleConfigurations(); } }
/// <summary> /// Method changes record variante, not having TYPE key. /// </summary> /// <returns> /// List of <see cref="UPCRMRecords" />. /// </returns> private List <UPCRMRecord> ChangedRecordsVrianteWithoutType() { var changedRecords = new List <UPCRMRecord>(); for (var weekDay = 0; weekDay < weekDayArray.Length; weekDay++) { var functionValueMapping = new Dictionary <string, object>(); var functionValueMappingNullValue = new Dictionary <string, object>(); var changedRecord = (UPCRMRecord)null; var weekDayU7 = weekDayArray[weekDay]; if (weekDayU7 > 1) { weekDayU7--; } else { weekDayU7 = 7; } var contactRecordIdentification = SetFunctionValueMapping(weekDay, functionValueMapping, functionValueMappingNullValue); functionValueMapping["DAYOFWEEK"] = $"{weekDayU7}"; if (contactRecordIdentification != null && functionValueMapping.Keys.Count == 1) { changedRecord = new UPCRMRecord(contactRecordIdentification, "Delete"); } else if (contactRecordIdentification == null && functionValueMapping.Keys.Count > 1) { changedRecord = new UPCRMRecord(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); } if (changedRecord != null) { changedRecords.Add(changedRecord); } } return(changedRecords); }
/// <summary> /// Approves the specified dummy. /// </summary> /// <param name="dummy">The dummy.</param> public void Approve(object dummy) { if (this.disableSigning) { return; } string recordIdentification = this.buttonViewReference.ContextValueForKey("RecordId"); string filterName = this.buttonViewReference.ContextValueForKey("TemplateFilter"); if (string.IsNullOrEmpty(recordIdentification)) { this.ParentOrganizerModelController.HandleOrganizerActionError( LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorParameterEmpty, "RecordId"), true); return; } UPConfigFilter filter = ConfigurationUnitStore.DefaultStore.FilterByName(filterName); if (filter == null) { this.HandlePageErrorDetails(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorFilterMissing, filterName)); return; } filter = filter.FilterByApplyingValueDictionaryDefaults(this.FieldValueDictionary, true); UPCRMRecord record = new UPCRMRecord(recordIdentification); record.ApplyValuesFromTemplateFilter(filter); UPOfflineEditRecordRequest request = new UPOfflineEditRecordRequest(0); this.buttonRequest = request; string requestOptionString = this.buttonViewReference.ContextValueForKey("RequestOption"); UPOfflineRequestMode requestMode = UPOfflineRequest.RequestModeFromString(requestOptionString, UPOfflineRequestMode.OnlineConfirm); if (request.StartRequest(requestMode, new List <UPCRMRecord> { record }, this) == false) { this.buttonRequest = null; } else { this.ShouldWaitForPendingChanges = true; } }
/// <summary> /// Returns changed child records list for given parent record /// </summary> /// <param name="parentRecord">Parent record</param> /// <param name="userChangesOnly">User changes only</param> /// <returns> /// <see cref="List{UPCRMRecord}" /> /// </returns> public override List <UPCRMRecord> ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly) { List <UPCRMRecord> changedChildRecords = null; if (this.ChildEditContexts != null) { foreach (UPChildEditContext childEditContext in this.ChildEditContexts.Values) { List <UPCRMRecord> records = this.ChangedRecordsForContextNewRecordLinkUserChangesOnly(childEditContext, false, null, userChangesOnly); if (records?.Count > 0) { if (changedChildRecords != null) { changedChildRecords.AddRange(records); } else { changedChildRecords = new List <UPCRMRecord>(records); } } } if (this.AddedChildEditContexts != null) { UPCRMLink link = new UPCRMLink(parentRecord, -1); foreach (UPChildEditContext childEditContext in this.AddedChildEditContexts) { List <UPCRMRecord> records = this.ChangedRecordsForContextNewRecordLinkUserChangesOnly(childEditContext, true, link, userChangesOnly); if (records?.Count > 0) { if (changedChildRecords != null) { changedChildRecords.AddRange(records); } else { changedChildRecords = new List <UPCRMRecord>(records); } } } } } return(changedChildRecords?.Count > 0 ? changedChildRecords : null); }
/// <inheritdoc/> public override List <UPCRMRecord> ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly) { List <UPCRMRecord> childRecords = null; string skipRecordIdentification = null; var skipFirst = false; if (!this.noAutoParticipant) { if (this.fixedFirstParticipant || (this.isNew && parentRecord.IsNew && (parentRecord.Links == null || parentRecord.Links.Count == 0))) { skipFirst = true; } else if (this.isNew && parentRecord.IsNew && parentRecord.Links?.Count > 0) { skipRecordIdentification = parentRecord.Links.First().RecordIdentification; } } foreach (var participant in this.ParticipantsControl.LinkParticipants) { var record = this.CreateRecord(parentRecord, participant, userChangesOnly); if (record == null) { continue; } skipFirst = this.UpdateRecord(record, skipFirst, skipRecordIdentification); if (childRecords != null) { childRecords.Add(record); } else { childRecords = new List <UPCRMRecord> { record }; } } return(childRecords); }
/// <inheritdoc/> public override List <UPCRMRecord> ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly) { var childRecords = this.ParticipantsControl.ChangedRepParticipantAcceptanceRecords(); if (!userChangesOnly && !string.IsNullOrEmpty(this.ParticipantsControl.RepAcceptanceInfoAreaId) && !parentRecord.IsNew) { var sync = new UPCRMRecord(this.ParticipantsControl.RepAcceptanceInfoAreaId, "Sync", null); sync.AddLink(new UPCRMLink(parentRecord, this.ParticipantsControl.RepAcceptanceLinkId)); if (childRecords == null) { childRecords = new List <UPCRMRecord>(); } childRecords.Add(sync); } return(childRecords); }
/// <summary> /// Stores the request. /// </summary> /// <param name="database">The database.</param> /// <returns>0, if success</returns> public override int StoreRequest(IDatabase database) { List <UPCRMRecord> _offlineRecords = this.OfflineRecords(); UPCRMRecord d3Record = null; UPCRMRecord d1Record = null; UPCRMRecord rootRecord = null; if (_offlineRecords.Count > 0) { foreach (UPCRMRecord rec in _offlineRecords) { if (rec.InfoAreaId == "D3") { d3Record = rec; } else if (rec.InfoAreaId == "D1") { d1Record = rec; } else { rootRecord = rec; } } } int ret = this.StoreRequestWithOfflineRecords(_offlineRecords, rootRecord); if (ret == 0) { this.RecordsToCacheWithRollback(_offlineRecords, UPCRMDataStore.DefaultStore, true); string documentRecordIdentification = d1Record.RecordIdentification != null ? d1Record.RecordIdentification : d3Record.RecordIdentification; if (documentRecordIdentification != null) { ResourceManager resourceManager = SmartbookResourceManager.DefaultResourceManager; Uri url = ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(documentRecordIdentification, this.FileName); string localURL = resourceManager.LocalPathForResourceAtUrl(url, resourceManager.LocalPathForTransientResources, this.FileName); SimpleIoc.Default.GetInstance <IPlatformService>().StorageProvider.SaveFile(localURL, this.Data); } } return(ret); }
/// <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); }
/// <summary> /// Links the reader did finish with result. /// </summary> /// <param name="linkReader">The link reader.</param> /// <param name="result">The result.</param> public void LinkReaderDidFinishWithResult(UPCRMLinkReader linkReader, object result) { this.LinkReader = null; if (linkReader.DestinationRecordIdentification.IsRecordIdentification()) { this.CurrentCheckedLinkRecord.UpdateRecordInformationWithRecordIdentification(linkReader.DestinationRecordIdentification, true); this.RecordsToSave.Add(this.CurrentCheckedLinkRecord); this.CurrentCheckedLinkRecord = null; } if (this.OpenChildRecords != null) { this.ContinueWithLinkRecords(this.OpenChildRecords); } else { this.ContinueWithRecords(this.RecordsToSave); } }
/// <summary> /// Sets properties according on changed child records /// </summary> /// <param name="rootRecord">The root record</param> /// <param name="parentRecord">The parent record</param> /// <returns>The list of UPCRMRecord</returns> public List <UPCRMRecord> ChangedChildRecordsForRootRecordParentRecord( UPCRMRecord rootRecord, UPCRMRecord parentRecord) { this.count = this.SerialEntry.Columns.Count; if (!string.IsNullOrWhiteSpace(this.SerialEntryRecordId) && this.SerialEntryRecordId != IdNew) { this.destinationRootRecord = new UPCRMRecordWithParameter(this.SerialEntry.DestInfoAreaId, this.SerialEntryRecordId); this.DestinationRootRecord = this.destinationRootRecord; } else if (this.DestinationRootRecord == null) { this.ProcessDestinationRootRecordNull(rootRecord, parentRecord); } else if (this.DestinationRootRecord is UPCRMRecordWithParameter) { this.destinationRootRecord = (UPCRMRecordWithParameter)this.DestinationRootRecord; if (this.destinationRootRecord.IsNew && this.SerialEntry.DestinationTemplateFilter != null) { this.additionalDestinationTemplateFilterRecords = this.destinationRootRecord.ApplyValuesFromTemplateFilter( this.SerialEntry.DestinationTemplateFilter, false); } } if (this.SerialEntry.ChildrenCount != 0) { this.destinationChildRecords = new List <UPCRMRecordWithParameter>(this.SerialEntry.ChildrenCount); this.tentativeChildRecords = new List <UPCRMRecordWithParameter>(this.SerialEntry.ChildrenCount); for (var childIndex = 0; childIndex < this.SerialEntry.ChildrenCount; childIndex++) { this.destinationChildRecords.Add(null); this.tentativeChildRecords.Add(null); } } this.ProcessSerialEntryColumns(rootRecord); return(this.ProcessDestinations()); }
/// <summary> /// Changeds the records. /// </summary> /// <returns></returns> public List <UPCRMRecord> ChangedRecords() { UPCRMRecord syncRecord = new UPCRMRecord(this.QuotaSearchAndList.InfoAreaId, "Sync"); syncRecord.AddLink(new UPCRMLink(this.linkRecordIdentification, this.QuotaLinkId)); List <UPCRMRecord> changedRecords = new List <UPCRMRecord> { syncRecord }; foreach (UPSERowQuota rowQuota in this.rowQuotaDictionary.Values) { List <UPCRMRecord> changedRecordsForRow = rowQuota.ChangedRecords(); if (changedRecordsForRow.Count > 0) { changedRecords.AddRange(changedRecordsForRow); } } return(changedRecords); }
private UPCRMRecord CreateRecord(UPCRMRecord parentRecord, UPCRMLinkParticipant participant, bool userChangesOnly) { UPCRMRecord record = null; var hasAcceptance = this.ParticipantsControl.RequirementField != null; var hasRequirement = this.ParticipantsControl.AcceptanceField != null; var participantIdentification = participant.RecordIdentification?.Length > 6 ? participant.RecordIdentification : participant.Key; var editGroup = this.EditGroupForKey(participantIdentification); var dependsEditField = (UPMDependsEditField)editGroup.Fields.FirstOrDefault(); if (dependsEditField == null) { throw new InvalidOperationException("Collection must contain UPMDependsEditField"); } var acceptanceField = dependsEditField.DependField; var requirementField = dependsEditField.DependField2; if (participant.MarkAsDeleted) { if (!string.IsNullOrWhiteSpace(participant.RecordIdentification)) { record = new UPCRMRecord(participant.RecordIdentification, "Delete", null); } } else if ((!userChangesOnly || !participant.NoUserChanges) && (participant.RecordIdentification == null || participant.RecordIdentification.Length < 5) && !string.IsNullOrWhiteSpace(participant.LinkRecordIdentification)) { record = this.CreateNewRecord(parentRecord, participant, hasRequirement, requirementField, hasAcceptance, acceptanceField); } else if (requirementField != null && acceptanceField != null && (requirementField.Changed || acceptanceField.Changed)) { record = this.CreateNewRecord(participant, hasRequirement, requirementField, hasAcceptance, acceptanceField); } return(record); }
/// <summary> /// Undoes the record. /// </summary> /// <param name="record">The record.</param> /// <returns></returns> public int UndoRecord(UPCRMRecord record) { CRMDatabase database = this.DatabaseInstance; Record rec = this.CreateRecord(record, true); if (rec == null) { return(-1); } database.BeginTransaction(); int ret = rec.Update(); if (ret == 0 && !this.Disable86326) { this.UpdateParticipantsTablesForRecord(rec, database); } database.Commit(); return(ret); }
/// <summary> /// Saves the record rollback request nr. /// </summary> /// <param name="record">The record.</param> /// <param name="requestNr">The request nr.</param> /// <returns></returns> public int SaveRecordRollbackRequestNr(UPCRMRecord record, int requestNr) { CRMDatabase database = this.DatabaseInstance; Record rec = this.CreateRecord(record); if (rec == null) { return(-1); } database.BeginTransaction(); int ret = rec.InsertOrUpdate(); if (ret == 0 && !this.Disable86326) { this.UpdateParticipantsTablesForRecord(rec, database); } database.Commit(); return(ret); }
/// <summary> /// Offlines the records. /// </summary> /// <returns></returns> public List <UPCRMRecord> OfflineRecords() { if (this.offlineRecords != null) { return(this.offlineRecords); } UPCRMOfflineDocumentRecordCreator offlineRecordCreator = UPCRMOfflineDocumentRecordCreator.Create(this.NoD3Link); if (offlineRecordCreator == null) { return(null); } Dictionary <string, object> parameterDictionary = offlineRecordCreator.ParametersForDocument(this.FileName, this.MimeType, StringExtensions.CrmValueFromDate(DateTime.UtcNow), this.Data.Length); UPCRMRecord rootRecord = new UPCRMRecord(this.RecordIdentification); this.offlineRecords = offlineRecordCreator.CrmRecordsForParametersRecordAddRoot(parameterDictionary, rootRecord, this.FieldId >= 0); return(this.offlineRecords); }
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); }
ArrayList ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly) { ArrayList childRecords = this.ParticipantsControl.ChangedRepParticipantAcceptanceRecords(); if (!userChangesOnly && this.ParticipantsControl.RepAcceptanceInfoAreaId.Length && !parentRecord.IsNew) { UPCRMRecord sync = new UPCRMRecord(this.ParticipantsControl.RepAcceptanceInfoAreaId, "Sync"); sync.AddLink(new UPCRMLink(parentRecord, this.ParticipantsControl.RepAcceptanceLinkId)); if (childRecords) { return(childRecords.ArrayByAddingObject(sync)); } else { return(NSMutableArray.ArrayWithObject(sync)); } } else { return(childRecords); } }
/// <summary> /// Creates the controller with offline request. /// </summary> /// <param name="offlineRequest">The offline request.</param> /// <returns></returns> public static UPCharacteristicsEditOrganizerModelController Create(UPOfflineCharacteristicsRequest offlineRequest) { ViewReference viewReference = new ViewReference(offlineRequest.Json, Constants.CharateristicsEditViewConfigurationName); string recordIdentification = viewReference.ContextValueForKey("RecordId"); if (string.IsNullOrEmpty(recordIdentification) || recordIdentification.Contains("new")) { UPCRMRecord firstRecord = offlineRequest.FirstRecord; if (firstRecord?.Links != null) { foreach (UPCRMLink link in firstRecord.Links) { if (link.InfoAreaId == recordIdentification.InfoAreaId()) { viewReference = new ViewReference(viewReference, recordIdentification, link.RecordIdentification, null); } } } } return(new UPCharacteristicsEditOrganizerModelController(offlineRequest, viewReference, UPOrganizerInitOptions.AddNoAutoBuildToOptions(null))); }
/// <summary> /// Applies the changes from record. /// </summary> /// <param name="record">The record.</param> public void ApplyChangesFromRecord(UPCRMRecord record) { UPCRMTableInfo tableInfo = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()); if (record.FieldValues != null) { foreach (UPCRMFieldValue value in record.FieldValues) { UPCRMFieldInfo fieldInfo = tableInfo.FieldInfoForFieldId(value.FieldId); if (fieldInfo != null) { UPCRMUndoField undoField = new UPCRMUndoField(fieldInfo.DatabaseFieldName, value.Value, null); this.AddFieldValue(undoField); } } } if (record.Links != null) { foreach (UPCRMLink link in record.Links) { UPCRMLinkInfo linkInfo = tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId); if (linkInfo?.HasColumn ?? false) { UPCRMUndoField undoField = new UPCRMUndoField(linkInfo.LinkFieldName, link.RecordId, null); this.AddFieldValue(undoField); string infoAreaColumnName = linkInfo.InfoAreaLinkFieldName; if (!string.IsNullOrEmpty(infoAreaColumnName)) { undoField = new UPCRMUndoField(infoAreaColumnName, link.InfoAreaId, null); this.AddFieldValue(undoField); } } } } }
private void SetRecordIdentificationForRecords(List <UPCRMRecord> records, List <IIdentifier> changedIdentifiers) { int count = records.Count; bool originalRecordChanged = false; string firstRecordIdentification = null; int i; for (i = 0; i < count; i++) { UPCRMRecord record = records[i]; changedIdentifiers.Add(new RecordIdentifier(record.InfoAreaId, record.RecordId)); if (record.RecordIdentification != this.RecordIdentification) { originalRecordChanged = true; } if (i == 0) { firstRecordIdentification = record.RecordIdentification; } } if (!originalRecordChanged) { changedIdentifiers.Add(new RecordIdentifier(this.InfoAreaId, this.RecordIdentification.RecordId())); UPCRMRecord record = records[i]; changedIdentifiers.AddRange(record.Links.Select(link => new RecordIdentifier(link.RecordIdentification))); } if (!string.IsNullOrEmpty(this.LinkRecordIdentification)) { changedIdentifiers.Add(new RecordIdentifier(this.LinkRecordIdentification)); } this.RecordIdentification = firstRecordIdentification; }
private bool UpdateRecord(UPCRMRecord record, bool skipFirst, string skipRecordIdentification) { if (skipFirst) { skipFirst = false; if (this.keyField) { record.EnableKeyFields(); } else { record.Mode = "NewOffline"; } } else if (!string.IsNullOrWhiteSpace(skipRecordIdentification)) { foreach (var link in record.Links) { if (skipRecordIdentification == link.RecordIdentification) { if (this.keyField) { record.EnableKeyFields(); } else { record.Mode = "NewOffline"; } break; } } } return(skipFirst); }
/// <summary> /// Initializes a new instance of the <see cref="UPCRMLink"/> class. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="linkId"> /// The link identifier. /// </param> public UPCRMLink(UPCRMRecord record, int linkId) : this(record, linkId, false) { }
/// <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); }
/// <summary> /// Edits the contexts for result row. /// </summary> /// <param name="resultRow">The result row.</param> /// <param name="tabConfig">The tab configuration.</param> /// <param name="editFieldDictionary">The edit field dictionary.</param> /// <param name="initialValues">The initial values.</param> /// <param name="fieldPostfix">The field postfix.</param> /// <param name="initialRecords">The initial records.</param> /// <returns></returns> public List <object> EditContextsForResultRow(UPCRMResultRow resultRow, FieldControlTab tabConfig, Dictionary <string, UPEditFieldContext> editFieldDictionary, Dictionary <string, object> initialValues, string fieldPostfix, List <UPCRMRecord> initialRecords) { var recordIdentification = resultRow?.RecordIdentificationAtIndex(0); var fieldArray = new List <object>(); UPCRMRecord offlineRootRecord = null; if (initialRecords?.Count > 0) { offlineRootRecord = initialRecords.FirstOrDefault(); } var identifierPrefix = recordIdentification; if (string.IsNullOrEmpty(identifierPrefix)) { identifierPrefix = $"{this.TabConfig.FieldControl.UnitName}_{this.TabIndex}"; } var fieldCount = tabConfig?.NumberOfFields ?? 0; for (var j = 0; j < fieldCount; j++) { var fieldConfig = tabConfig?.FieldAtIndex(j); if (fieldConfig == null) { continue; } var fieldAttributes = fieldConfig.Attributes; var currentInfoAreaId = fieldConfig.InfoAreaId; var currentLinkId = fieldConfig.LinkId; var fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(identifierPrefix, fieldConfig.Identification); UPSelector selector = null; var selectorDef = fieldConfig.Attributes?.Selector; if (selectorDef != null) { var filterParameters = this.EditPageContext?.ViewReference?.ContextValueForKey("copyFields")?.JsonDictionaryFromString(); if (resultRow?.Result != null && resultRow.IsNewRow) { selector = UPSelector.SelectorFor( resultRow.RootRecordIdentification?.InfoAreaId(), resultRow.Result.ParentRecordIdentification, resultRow.Result.LinkId, selectorDef, filterParameters, fieldConfig); } else { selector = UPSelector.SelectorFor(resultRow?.RootRecordIdentification, selectorDef, filterParameters, fieldConfig); } selector.Build(); if (selector.OptionCount == 0 && selector.IsStaticSelector) { selector = null; } } var isEditField = this.enableLinkedEditFields || selector != null || (tabConfig.FieldControl.InfoAreaId == currentInfoAreaId && currentLinkId <= 0); var isHidden = fieldAttributes.Hide; var isReadOnly = isEditField && fieldAttributes.ReadOnly; var rawFieldValue0 = resultRow?.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex); var fieldInfo = fieldConfig.Field.FieldInfo; if (isEditField && !isReadOnly && !(selector is UPRecordSelector && ((UPRecordSelector)selector).IgnoreFieldInfo)) { if (fieldInfo.IsReadOnly) { isReadOnly = true; } else if (resultRow?.IsNewRow == true || string.IsNullOrEmpty(rawFieldValue0)) { if (fieldInfo.LockedOnNew) { isReadOnly = true; } } else if (fieldInfo.LockedOnUpdate && !fieldInfo.IsEmptyValue(rawFieldValue0)) { isReadOnly = true; } } string offlineValue = null; bool offlineChanged; string rawFieldValue; UPEditFieldContext editFieldContext; if (isEditField) { List <UPEditFieldContext> childFields = null; if (fieldAttributes.FieldCount > 1 && selector == null) { childFields = new List <UPEditFieldContext>(); for (var k = 1; k < fieldAttributes.FieldCount; k++) { var childFieldConfig = tabConfig.FieldAtIndex(++j); if (childFieldConfig != null) { rawFieldValue = resultRow.RawValueAtIndex(childFieldConfig.TabIndependentFieldIndex); if (initialValues != null) { rawFieldValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, childFieldConfig, initialValues); } offlineChanged = false; if (offlineRootRecord != null) { offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(childFieldConfig.FieldId); if (offlineValue != null && !offlineValue.Equals(rawFieldValue)) { offlineChanged = true; } } editFieldContext = UPEditFieldContext.ChildFieldContextForFieldConfigValue(childFieldConfig, rawFieldValue); if (offlineChanged) { editFieldContext.SetOfflineChangeValue(offlineValue); } childFields.Add(editFieldContext); } } } var markAsChanged = false; rawFieldValue = rawFieldValue0; if (initialValues != null) { string initialValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, fieldConfig, initialValues); if (!rawFieldValue.Equals(initialValue)) { markAsChanged = true; rawFieldValue = initialValue; } } offlineChanged = false; offlineValue = null; if (offlineRootRecord != null) { offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(fieldConfig.FieldId); if (offlineValue != null && !offlineValue.Equals(rawFieldValue)) { offlineChanged = true; } } if (selector != null) { // Sometimes it makes sense to add the Link field , so you have the link information on the EditPage , but the field is not displayed . // Thus, the field is interpreted as EditField Selector must be set. if (isHidden) { editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else if (isReadOnly && ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82213")) { editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else { editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, selector); } } else { if (isHidden) { editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else if (isReadOnly) { editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue); } else { editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, childFields as List <UPEditFieldContext>); } } if (fieldInfo.DateFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId) { editFieldContext.DateOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.DateFieldId, currentInfoAreaId, -1); } else if (fieldInfo.TimeFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId) { editFieldContext.TimeOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.TimeFieldId, currentInfoAreaId, -1); } if (offlineChanged) { editFieldContext.SetOfflineChangeValue(offlineValue); } else if (markAsChanged) { editFieldContext.SetChanged(true); } if (editFieldContext != null) { if (!string.IsNullOrEmpty(fieldPostfix)) { editFieldContext.FieldLabelPostfix = fieldPostfix; } if (editFieldDictionary != null) { editFieldDictionary.SetObjectForKey(editFieldContext, fieldConfig.Identification); if (childFields != null) { foreach (var childFieldContext in childFields) { editFieldDictionary.SetObjectForKey(childFieldContext, childFieldContext.FieldConfig.Identification); } } } fieldArray.Add(editFieldContext); } } else { string fieldValue; if (fieldAttributes.FieldCount > 1) { fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues); } var values = !string.IsNullOrEmpty(fieldValue) ? new List <string> { fieldValue } : new List <string>(); for (var k = 1; k < fieldAttributes.FieldCount; k++) { var childfieldConfig = tabConfig.FieldAtIndex(++j); if (childfieldConfig == null) { continue; } fieldValue = resultRow?.ValueAtIndex(childfieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(childfieldConfig, initialValues); } if (string.IsNullOrEmpty(fieldValue)) { fieldValue = string.Empty; } values.Add(fieldValue); } fieldValue = fieldAttributes.FormatValues(values); } else { fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex); if (string.IsNullOrEmpty(fieldValue)) { fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues); } } UPMField field; if (!isHidden && !string.IsNullOrEmpty(fieldValue)) { field = new UPMStringField(fieldIdentifier); ((UPMStringField)field).StringValue = fieldValue; } else { field = null; } if (field != null) { if (!fieldConfig.Attributes.NoLabel) { field.LabelText = fieldConfig.Label; } SetAttributesOnField(fieldAttributes, field); fieldArray.Add(field); } } } return(fieldArray); }
/// <summary> /// Initializes a new instance of the <see cref="UPCRMLink"/> class. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="linkId"> /// The link identifier. /// </param> /// <param name="onlyOffline"> /// if set to <c>true</c> [only offline]. /// </param> public UPCRMLink(UPCRMRecord record, int linkId, bool onlyOffline) { this.Record = record; this.LinkId = linkId; this.OnlyOffline = onlyOffline; }
/// <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); }
private void HandleDestinationResult(UPCRMResult result) { int count = result.RowCount; bool expandOnData = ConfigurationUnitStore.DefaultStore.ConfigValue("Characteristics.CollapseGroups") == "empty"; for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string groupKey = row.RawValueAtIndex(this.DestinationGroupField.TabIndependentFieldIndex); UPCharacteristicsGroup group = this.groupDict.ValueOrDefault(groupKey); if (group != null) { if (expandOnData) { group.ShowExpanded = true; } string itemKey = row.RawValueAtIndex(this.DestinationItemField.TabIndependentFieldIndex); UPCharacteristicsItem item = group.ItemDictionary.ValueOrDefault(itemKey); UPCRMRecord conflictRecord = null; if (this.conflictOfflineRequest != null) { foreach (UPCRMRecord currentConflictRecord in this.conflictOfflineRequest.Records) { if (currentConflictRecord.RecordIdentification == row.RecordIdentificationAtFieldIndex(0)) { conflictRecord = currentConflictRecord; break; } } } if (conflictRecord == null) { item?.SetFromResultRow(row); } else if (conflictRecord.Deleted) { item?.SetFromRecord(conflictRecord); } else { item?.SetFromResultRow(row); foreach (UPCRMFieldValue fieldValue in conflictRecord.FieldValues) { int position = this.PositionForCrmFieldId(fieldValue.FieldId); if (position >= 0) { item.SetValueForAdditionalFieldPosition(fieldValue.Value, position); } } } } } if (this.conflictOfflineRequest != null) { foreach (UPCRMRecord conflictRecord in this.conflictOfflineRequest.Records) { if (conflictRecord.IsNew) { string groupKey = conflictRecord.StringFieldValueForFieldIndex(this.DestinationGroupField.TabIndependentFieldIndex); UPCharacteristicsGroup group = this.groupDict.ValueOrDefault(groupKey); if (group != null) { string itemKey = conflictRecord.StringFieldValueForFieldIndex(this.DestinationItemField.TabIndependentFieldIndex); UPCharacteristicsItem item = group.ItemDictionary[itemKey]; item.SetFromRecord(conflictRecord); } } } } if (!this.EditMode) { this.RemoveEmptyItems(); } this.TheDelegate.CharacteristicsDidFinishWithResult(this, this); }
/// <summary> /// Adds the page model controllers. /// </summary> public override void AddPageModelControllers() { this.RecordIdentification = this.ViewReference.ContextValueForKey("RecordId"); this.RecordIdentification = UPCRMDataStore.DefaultStore.ReplaceRecordIdentification(this.RecordIdentification); ViewReference viewReference = this.ViewReference; if (this.OfflineRequest != null) { if (this.RecordIdentification.Contains("new")) { UPCRMRecord rootRecord = ((UPOfflineRecordRequest)this.OfflineRequest).FirstRecordWithInfoAreaId(this.RecordIdentification.InfoAreaId()); if (rootRecord != null) { viewReference = new ViewReference(this.ViewReference, this.RecordIdentification, rootRecord.RecordIdentification, null); this.RecordIdentification = rootRecord.RecordIdentification; } } } UPMOrganizer editOrganizer = new UPMOrganizer(StringIdentifier.IdentifierWithStringId("Edit")); this.TopLevelElement = editOrganizer; SerialEntryPageModelController tmpSerialEntryPageModelController = new SerialEntryPageModelController(viewReference, (UPOfflineSerialEntryRequest)this.OfflineRequest); //tmpSerialEntryPageModelController.AddObserverForKeyPathOptionsContext(this, "hasRunningChangeRequests", NSKeyValueObservingOptionNew, null); tmpSerialEntryPageModelController.Delegate = this; Page overviewPage = tmpSerialEntryPageModelController.Page; string organizerHeaderText; string organizerDetailText = null; if (this.ExpandConfig != null) { UPConfigHeader header = ConfigurationUnitStore.DefaultStore.HeaderByNameFromGroup("Edit", this.ExpandConfig.HeaderGroupName); if (header != null) { organizerDetailText = header.Label; tmpSerialEntryPageModelController.Page.LabelText = organizerDetailText; } } if (string.IsNullOrEmpty(organizerDetailText)) { if (!string.IsNullOrEmpty(this.InfoAreaId)) { organizerDetailText = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(this.InfoAreaId).Label; } else { organizerDetailText = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()).Label; } } IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; string rootRecordIdentification = this.RecordIdentification; if (string.IsNullOrEmpty(rootRecordIdentification)) { rootRecordIdentification = this.LinkRecordIdentification; } UPConfigTableCaption tableCaption = configStore.TableCaptionByName(rootRecordIdentification.InfoAreaId()); string recordTableCaption = null; if (tableCaption != null) { recordTableCaption = tableCaption.TableCaptionForRecordIdentification(rootRecordIdentification); } if (string.IsNullOrEmpty(recordTableCaption)) { if (!string.IsNullOrEmpty(organizerDetailText)) { organizerHeaderText = organizerDetailText; organizerDetailText = null; } else { organizerHeaderText = rootRecordIdentification; } } else { organizerHeaderText = recordTableCaption; } this.Organizer.TitleText = organizerHeaderText; this.Organizer.SubtitleText = organizerDetailText; this.AddPageModelController(tmpSerialEntryPageModelController); this.Organizer.AddPage(overviewPage); this.AddRemainingPageModelController(); this.AddOrganizerActions(); editOrganizer.ExpandFound = true; }
/// <summary> /// Initializes a new instance of the <see cref="UPCRMRecordWithHierarchy"/> class. /// </summary> /// <param name="record"> /// The record. /// </param> public UPCRMRecordWithHierarchy(UPCRMRecord record) { this.OnlyLink = false; }
private bool SetControlsFromParameters() { ViewReference viewReference = null; if (this.Parameters.ContainsKey("viewReference")) { viewReference = (ViewReference)this.Parameters["viewReference"]; } // create rightsfilter string rightsFilterName = viewReference?.ContextValueForKey(Constants.RightsFilterConfigurationName); if (!string.IsNullOrEmpty(rightsFilterName)) { IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore; this.RightsFilter = configStore.FilterByName(rightsFilterName); } if (this.RightsFilter != null) { #if PORTING NSDictionary filterParameters = (NSDictionary)viewReference.ContextValueForKey(Constants.RightsFilterCopyFieldConfigurationName); if (filterParameters != null) { UPConditionValueReplacement replacement = new UPConditionValueReplacement(filterParameters); this.RightsFilter = this.RightsFilter.FilterByApplyingReplacements(replacement); } else #endif { this.RightsFilter = this.RightsFilter.FilterByApplyingDefaultReplacements(); } } this.RequestOption = UPCRMDataStore.RequestOptionFromString(viewReference?.ContextValueForKey(Constants.RequestOptionConfigurationName), UPRequestOption.Offline); this.groupConfigurations = new List <UPObjectivesConfiguration>(); UPObjectivesConfiguration individualConfiguration = UPObjectivesConfiguration.Create(viewReference, Constants.IndividualSectionPostFix, this.Parameters, this.EditMode); if (individualConfiguration != null) { this.groupConfigurations.Add(individualConfiguration); } UPObjectivesConfiguration salesConfiguration = UPObjectivesConfiguration.Create(viewReference, Constants.SalesSectionPostFix, this.Parameters, this.EditMode); if (salesConfiguration != null) { this.groupConfigurations.Add(salesConfiguration); } List <string> additionalFieldGroups = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalFieldgroupsConfigurationName)); // load additional sections if (additionalFieldGroups?.Count > 0) { List <string> additionalDestinationFilter = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalFilterConfigurationName)); List <string> additionalSourceFieldControl = this.StringsFromCommaSeparatedString(viewReference?.ContextValueForKey(Constants.AdditionalSourceFieldControlConfigurationName)); if ((additionalDestinationFilter != null && additionalSourceFieldControl != null) && (additionalFieldGroups.Count == additionalDestinationFilter.Count) && (additionalDestinationFilter.Count == additionalSourceFieldControl.Count)) { Dictionary <string, object> additionalParameterDictionary = new Dictionary <string, object>(this.Parameters); for (int additionalSectionIndex = 0; additionalSectionIndex < additionalDestinationFilter.Count; additionalSectionIndex++) { string sectionName = $"AdditionalSection_{additionalSectionIndex}"; string destinationFieldGroupName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterDestinationFieldGroupConfigurationName, sectionName); string destinationFilterName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterDestinationFilterConfigurationName, sectionName); string sourceFieldControlName = UPObjectivesConfiguration.CombineConfigurationNameWithSection(Constants.ParameterSourceFieldControlConfigurationName, sectionName); additionalParameterDictionary[destinationFieldGroupName] = additionalFieldGroups[additionalSectionIndex]; additionalParameterDictionary[destinationFilterName] = additionalDestinationFilter[additionalSectionIndex]; additionalParameterDictionary.SetObjectForKey(additionalSourceFieldControl[additionalSectionIndex], sourceFieldControlName); UPObjectivesConfiguration additionalConfiguration = UPObjectivesConfiguration.Create(viewReference, sectionName, additionalParameterDictionary, this.EditMode); if (additionalConfiguration != null) { this.groupConfigurations.Add(additionalConfiguration); } } } } this.record = new UPCRMRecord(this.RecordIdentification); this.ParentLink = viewReference?.ContextValueForKey("ParentLink"); return(true); }