Example #1
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="editableRoot">The editable root.</param>
        /// <returns></returns>
        public object GetValue(DetailsSaveFieldModel field, IEditableRoot editableRoot)
        {
            if (field.Settings == null)
                return null;

            var fileFieldOptions = field.Settings.ToObject<FileFieldOptions>();
            if (fileFieldOptions == null)
                return null;

            IFileProcess fileEdit = editableRoot.GetValueByPropertyName(field.SystemName);
            if (fileEdit == null)
                return null;

            fileEdit.FileName = fileFieldOptions.FileName;
            fileEdit.OriginalFileName = fileFieldOptions.OriginalFileName;

            if (!fileFieldOptions.Locked)
            {
                fileEdit.LockedDate = null;
            }
            else if (!fileEdit.Locked.HasValue || !fileEdit.Locked.Value)
            {
                fileEdit.LockedDate = DateTime.Now;
            }
            fileEdit.Locked = fileFieldOptions.Locked;
            fileEdit.LockedByAccountId = fileFieldOptions.LockedByAccountId;
            fileEdit.LockedByAccountName = fileFieldOptions.LockedByAccountName;

            if (fileFieldOptions.AuditLog != null)
            {
                fileEdit.FileChangeInfo = new AuditLogInfo
                {
                    LogType = fileFieldOptions.AuditLog.LogType,
                    ProcessName = fileFieldOptions.AuditLog.ProcessName,
                    ItemId = fileFieldOptions.AuditLog.ItemId,
                    FieldName = fileFieldOptions.AuditLog.FieldName,
                    OldValue = fileFieldOptions.AuditLog.OldValue,
                    NewValue = fileFieldOptions.AuditLog.NewValue,
                    DateUpdated = fileFieldOptions.AuditLog.DateUpdated,
                    User = fileFieldOptions.AuditLog.User
                };
            }

            var newModel = ((IBusinessBase)fileEdit).Save();

            if (fileFieldOptions.FileId == 0)
            {
                editableRoot.SetValueByPropertyName(string.Format("{0}Id", field.SystemName), ((IDynamicObject)newModel).Id);
            }

            return newModel;
        }
        /// <summary>
        /// Updates the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        public void Update(IDynamicObject source, IEditableRoot destination)
        {
            var filterList = new List<ColumnFilter>();

            foreach (var filterBuilder in _filterBuilders)
            {
                ColumnFilter filter;
                if (!filterBuilder.TryGetFilter(source, out filter))
                    return;
                filterList.Add(filter);
            }

            var itemIds = RuntimeDatabase.FindItems(_referencedProcess, filterList);
            if (itemIds.Count <= 0)
                return;

            if (_allowMultiple)
            {
                var crList = (ICrossRefItemList)destination.GetValueByPropertyName(_property.Name);

                if (crList == null)
                    return;

                foreach (var id in itemIds.Where(id => !crList.Contains(id)))
                {
                    crList.Assign(id);
                }
            }
            else
            {
                destination.SetValueByPropertyName(_property.Name, itemIds[0]);
            }
        }
        /// <summary>
        /// Updates the specified item.
        /// </summary>
        /// <param name="dataContext">
        /// The data context.
        /// </param>
        /// <param name="item">
        /// The destination item.
        /// </param>
        public void Update(IDataContext dataContext, IEditableRoot item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            try
            {
                var checklist = (ChecklistEdit)item.GetValueByPropertyName(FieldName);
                if (checklist == null || checklist.AnswerProcessList == null)
                {
                    checklist = CreateNewChecklist();
                    item.SetValueByPropertyName(FieldName, checklist);
                }

                if (ValueExpression != null)
                {
                    var items = ValueExpression(dataContext) as IEnumerable;

                    if (items != null)
                    {
                        var enumerator = items.GetEnumerator();

                        while (enumerator.MoveNext())
                        {
                            InsertOrUpdateChildren(dataContext, checklist);
                        }
                    }
                }
                else
                {
                    InsertOrUpdateChildren(dataContext, checklist);
                }
            }
            catch (Exception ex)
            {
                var message = new StringBuilder();
                message.AppendFormat(CultureInfo.InvariantCulture, "Could not update the field \"{0}\" in process \"{1}\".", DisplayName, item.ProcessDisplayName);

                throw new InvalidOperationException(message.ToString(), ex);
            }
        }
        /// <summary>
        /// Updates the field value.
        /// </summary>
        /// <param name="destination">
        /// The destination.
        /// </param>
        public void Update(IEditableRoot destination)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");

            destination.SetValueByPropertyName(FieldName, NewValue);
        }
Example #5
0
        /// <summary>
        /// Updates the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <exception cref="System.ArgumentNullException">
        /// source
        /// or
        /// destination
        /// </exception>
        public void Update(IDynamicObject source, IEditableRoot destination)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (destination == null)
                throw new ArgumentNullException("destination");

            if (IsLocalizable)
            {
                foreach (var localizationInfo in _property.DeclaringType.GetCustomAttributes<LocalizationInfoAttribute>())
                {
                    var cultureName = localizationInfo.CultureName;
                    var fieldName = LocalizationUtils.GetLocalizedFieldName(_property.Name, cultureName);

                    destination.SetValueByPropertyName(fieldName, GetValue(source, cultureName));
                }
            }
            else
            {
                destination.SetValueByPropertyName(_property.Name, GetValue(source, DefaultCultureName));
            }

            if (_property.Name == Constants.IdColumnName)
                destination.DisableIdGeneration = true;
        }
        private void ExecuteUnlink(IEditableRoot source, IEditableRoot destination)
        {
            var currentId = destination.GetValueByPropertyName(Property.Name) as int?;
            if (currentId == null)
                return;

            var item = GetSourceItem(CreateLinkedItemFilter(currentId.Value), CreateSourceDataFilter(source));
            if (item == null)
                return;

            var ancestor = item.GetAncestorByProcessName(ReferencedProcessName);
            if (ancestor == null || ancestor.Id != currentId)
                return;

            destination.SetValueByPropertyName(Property.Name, null);
        }
Example #7
0
        private static void UpdateModelDefaultValues(IEditableRoot model)
        {
            using (new BypassPropertyCheckContext())
            {
                foreach (var prop in model.GetAllPropertiesByFieldType(ColumnTypes.SampleType))
                {
                    var value = model.GetValueByPropertyName(prop.Name);
                    if (string.IsNullOrWhiteSpace(value))
                    {
                        model.SetValueByPropertyName(prop.Name, SampleTypes.Number.ToString());
                    }
                }

                //ELMTSUP 2512
                //foreach (var prop in model.GetAllPropertiesByFieldType(ColumnTypes.SamplingTechnique))
                //{
                //    var value = model.GetValueByPropertyName(prop.Name);
                    //if (string.IsNullOrWhiteSpace(value))
                    //{
                    //    model.SetValueByPropertyName(prop.Name, SampleSizeTypes.Fixed.ToString());
                    //}
                //}
            }
        }
        private void ExecuteLink(IEditableRoot source, IEditableRoot destination)
        {
            var infoItem = GetSourceItem(CreateSourceDataFilter(source));
            if (infoItem == null)
                return;

            var ancestor = infoItem.GetAncestorByProcessName(ReferencedProcessName);
            if (ancestor == null)
                return;

            if (destination.GetValueByPropertyName(Property.Name) == ancestor.Id)
                return;

            destination.SetValueByPropertyName(Property.Name, ancestor.Id);

            if (FieldUpdaters.Count == 0)
                return;

            var criteria = new DetailCriteria(infoItem.Id) { AllowLazyLoading = true };
            var editItem = DynamicTypeManager.GetEditableRoot<IEditableRoot>(SourceDataProcessName, criteria);
            if (editItem == null || editItem.Id <= 0)
                return;

            var sourceData = new DataTriggerSourceData();
            sourceData.SourceItems[DataTriggerFieldMappingExpressionNames.SourceDataProcess] = editItem;

            UpdateFieldValues(sourceData, editItem);
            ((ISavable)editItem).Save();
        }
        private void UpdateInternal(IDataContext dataContext, IEditableRoot item)
        {
            try
            {
                if (ValueExpression != null)
                {
                    item.SetValueByPropertyName(Property.Name, TypeConverter.Convert<int?>(ValueExpression(dataContext)));
                }
                else
                {
                    var filters = new List<ColumnFilter>();

                    foreach (var fieldMapping in ChildMappings.Where(m => m.IsKey))
                    {
                        ColumnFilter filter;
                        if (!fieldMapping.TryCreateFilter(dataContext, out filter))
                            return;

                        filters.Add(filter);
                    }

                    var itemIds = RuntimeDatabase.FindItems(ReferencedProcessName, filters);
                    if (itemIds.Count > 0)
                    {
                        UpdateChild(dataContext, itemIds[0]);
                        item.SetValueByPropertyName(Property.Name, itemIds[0]);
                    }
                    else
                    {
                        var child = CreateChild(dataContext);
                        item.SetValueByPropertyName(Property.Name, child.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                var message = new StringBuilder();
                message.AppendFormat(
                    CultureInfo.InvariantCulture,
                    "Could not update the field \"{0}\" in process \"{1}\".",
                    DisplayName,
                    item.ProcessDisplayName);

                throw new InvalidOperationException(message.ToString(), ex);
            }
        }
Example #10
0
        /// <summary>
        /// Updates destination field.
        /// </summary>
        /// <param name="destination">The destination item.</param>
        public void Update(IEditableRoot destination)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");

            if (FieldName == Constants.CurrentStateColumnName)
            {
                UpdateCurrentState(destination);
            }
            else
            {
                if (AllowLocalizedData)
                {
                    foreach (var localization in SupportedLocalizations)
                    {
                        var cultureName = localization.CultureName;
                        destination.SetValueByPropertyName(LocalizationUtils.GetLocalizedFieldName(FieldName, cultureName), GetValue(cultureName));
                    }
                }
                else
                {
                    destination.SetValueByPropertyName(FieldName, GetValue(DefaultCultureName));
                }
            }
        }
Example #11
0
        /// <summary>
        /// Updates the specified item.
        /// </summary>
        /// <param name="dataContext">
        /// The data context.
        /// </param>
        /// <param name="item">
        /// The destination item.
        /// </param>
        public void Update(IDataContext dataContext, IEditableRoot item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            try
            {
                switch (Property.Name)
                {
                    case Constants.IdColumnName:
                        UpdateIdField(dataContext, item);
                        break;

                    case Constants.CurrentStateColumnName:
                        UpdateCurrentState(dataContext, item);
                        break;

                    default:
                        {
                            if (AllowLocalizedData)
                            {
                                foreach (var localization in SupportedLocalizations)
                                {
                                    object value;

                                    using (new CultureContext(localization.CultureName))
                                    {
                                        value = GetValue(dataContext);
                                        if (IsKey && value == null)
                                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The key field \"{0}\" is null.", FieldName));
                                    }

                                    item.SetValueByPropertyName(LocalizationUtils.GetLocalizedFieldName(Property.Name, localization.CultureName), value);
                                }
                            }
                            else
                            {
                                var value = GetValue(dataContext);
                                if (IsKey && value == null)
                                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The key field \"{0}\" is null.", FieldName));

                                item.SetValueByPropertyName(Property.Name, value);
                            }
                        }

                        break;
                }
            }
            catch (Exception ex)
            {
                var message = new StringBuilder();
                message.AppendFormat(
                    CultureInfo.InvariantCulture,
                    "Could not update the field \"{0}\" in process \"{1}\".",
                    DisplayName,
                    item.ProcessDisplayName);

                throw new InvalidOperationException(message.ToString(), ex);
            }
        }
Example #12
0
        /// <summary>
        /// Copies the answer data.
        /// </summary>
        /// <param name="answerFieldValues">
        /// The answer field values.
        /// </param>
        /// <param name="answerItem">
        /// The answer item.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerFieldValues"/> parameter is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="answerItem"/> parameter is null.
        /// </exception>
        public static void CopyAnswerData(ICollection<ChecklistAnswerFieldValue> answerFieldValues, IEditableRoot answerItem)
        {
            if (answerFieldValues == null)
                throw new ArgumentNullException("answerFieldValues");

            if (answerItem == null)
                throw new ArgumentNullException("answerItem");

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                foreach (var fieldValue in answerFieldValues.Where(f => f.Value != null))
                {
                    var answerProperty = answerItem.GetPropertyByName(fieldValue.FieldName);
                    var answerValue = answerItem.GetValueByPropertyName(fieldValue.FieldName);

                    if (fieldValue.Value is ICrossRefItemList && answerValue is ICrossRefItemList)
                    {
                        var qList = (ICrossRefItemList)fieldValue.Value;
                        var aList = (ICrossRefItemList)answerValue;

                        aList.Clear();
                        foreach (var crItem in qList.Cast<ICrossRefItemInfo>())
                        {
#if !SILVERLIGHT
                            aList.Assign(crItem.Id);
#else
                            aList.Assign(crItem.Id, (o, e) => { });
#endif
                        }

                        continue;
                    }

                    if (answerProperty.PropertyType.IsInstanceOfType(fieldValue.Value))
                    {
                        answerItem.SetValueByPropertyName(fieldValue.FieldName, fieldValue.Value);
                    }
                    else
                    {
                        throw new VeyronException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Cannot assign value of type \"{0}\" to property \"{1}\".",
                                fieldValue.Value.GetType().AssemblyQualifiedName,
                                fieldValue.FieldName));
                    }
                }
            }
        }