/// <summary>
        /// 设置脏属性值
        /// </summary>
        /// <param name="propertyLambda">含类属性的 lambda 表达式</param>
        /// <param name="newValue">新属性值</param>
        public void SetDirtyValue(Expression <Func <T, object> > propertyLambda, object newValue)
        {
            IsSelfDirty = true;
            Property property = SelfSheet.GetProperty(this.GetType(), Utilities.GetPropertyInfo <T>(propertyLambda).Name);

            property.Field.Set(this, newValue);
            DirtyPropertyNames[property.PropertyInfo.Name] = true;
        }
Exemple #2
0
        /// <summary>
        /// 设置脏属性值
        /// </summary>
        /// <param name="propertyLambda">含类属性的 lambda 表达式</param>
        /// <param name="newValue">新属性值</param>
        public void SetDirtyValue(Expression <Func <T, object> > propertyLambda, object newValue)
        {
            IsSelfDirty = true;
            Property property = SelfSheet.GetProperty(propertyLambda);

            if (property.Field != null)
            {
                property.Field.Set(this, newValue);
            }
            else
            {
                property.Set(this, newValue);
            }
            DirtyPropertyNames[property.PropertyInfo.Name] = true;
        }
        /// <summary>
        /// 设置脏属性值
        /// </summary>
        /// <param name="source">数据源</param>
        public bool SetDirtyValues(T source)
        {
            if (IsSelfDirty)
            {
                throw new InvalidOperationException("禁止导入已处于编辑状态的对象");
            }

            bool result = false;
            Dictionary <string, object> oldPropertyValues  = new Dictionary <string, object>(StringComparer.Ordinal);
            Dictionary <string, bool?>  dirtyPropertyNames = new Dictionary <string, bool?>(StringComparer.Ordinal);

            foreach (KeyValuePair <string, Property> kvp in SelfSheet.GetProperties(this.GetType()))
            {
                if (kvp.Value.Column.TableColumn == null)
                {
                    continue;
                }
                if (kvp.Value.Column.TableColumn.IsWatermarkColumn)
                {
                    continue;
                }

                object value = kvp.Value.Field.GetValue(this);
                oldPropertyValues.Add(kvp.Key, value);
                object sourceValue = kvp.Value.Field.GetValue(source);
                if (!object.Equals(value, sourceValue))
                {
                    result = true;
                    kvp.Value.Field.Set(this, sourceValue);
                    dirtyPropertyNames.Add(kvp.Key, true);
                }
            }

            if (result)
            {
                _oldPropertyValues  = oldPropertyValues;
                _dirtyPropertyNames = dirtyPropertyNames;
                _executeAction      = _executeAction | ExecuteAction.Update;

                FillReservedFields(false, true);
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 设置脏属性值
        /// </summary>
        /// <param name="source">数据源</param>
        public bool SetDirtyValues(T source)
        {
            if (IsSelfDirty)
            {
                throw new System.ComponentModel.DataAnnotations.ValidationException("禁止导入已处于编辑状态的对象");
            }

            bool result = false;
            Dictionary <string, object> oldPropertyValues  = new Dictionary <string, object>(StringComparer.Ordinal);
            Dictionary <string, bool?>  dirtyPropertyNames = new Dictionary <string, bool?>(StringComparer.Ordinal);

            foreach (KeyValuePair <string, Property> kvp in SelfSheet.GetProperties(this.GetType(), TargetTable, false))
            {
                object value = kvp.Value.Field != null?kvp.Value.Field.GetValue(this) : kvp.Value.GetValue(this);

                oldPropertyValues.Add(kvp.Key, value);
                object sourceValue = kvp.Value.Field != null?kvp.Value.Field.GetValue(source) : kvp.Value.GetValue(source);

                if (!object.Equals(value, sourceValue))
                {
                    result = true;
                    if (kvp.Value.Field != null)
                    {
                        kvp.Value.Field.Set(this, sourceValue);
                    }
                    else
                    {
                        kvp.Value.Set(this, sourceValue);
                    }
                    dirtyPropertyNames.Add(kvp.Key, true);
                }
            }

            if (result)
            {
                _oldPropertyValues  = oldPropertyValues;
                _dirtyPropertyNames = dirtyPropertyNames;
                _executeAction      = _executeAction | ExecuteAction.Update;

                FillReservedFields(ExecuteAction.Update);
            }

            return(result);
        }
        /// <summary>
        /// 提取脏属性值
        /// </summary>
        protected PropertyValue[] GetDirtValues()
        {
            if (_oldPropertyValues == null)
            {
                return(null);
            }

            List <PropertyValue> result = new List <PropertyValue>(_oldPropertyValues.Count);
            Sheet targetTable           = SelfSheet.GetProperty <T>(p => p.Id).Column.TableColumn.Owner;

            foreach (KeyValuePair <string, Property> kvp in SelfSheet.GetProperties(this.GetType(), targetTable))
            {
                if (kvp.Value.Column.TableColumn.IsWatermarkColumn)
                {
                    continue;
                }

                if (_oldPropertyValues.TryGetValue(kvp.Key, out object oldValue))
                {
                    if (DirtyPropertyNames.TryGetValue(kvp.Key, out bool?isDirty) && isDirty.HasValue)
                    {
                        if (isDirty.Value)
                        {
                            result.Add(new PropertyValue(kvp.Value, oldValue, kvp.Value.Field.GetValue(this)));
                        }
                    }
                    else
                    {
                        object newValue = kvp.Value.Field.GetValue(this);
                        if (!object.Equals(oldValue, newValue))
                        {
                            result.Add(new PropertyValue(kvp.Value, oldValue, newValue));
                        }
                    }
                }
            }

            return(result.ToArray());
        }
Exemple #6
0
        /// <summary>
        /// 提取脏属性值
        /// </summary>
        protected IDictionary <string, object> GetDirtValues()
        {
            if (_oldPropertyValues == null)
            {
                return(null);
            }

            Dictionary <string, object> result = new Dictionary <string, object>(_oldPropertyValues.Count);

            foreach (KeyValuePair <string, Property> kvp in SelfSheet.GetProperties(this.GetType(), TargetTable, false))
            {
                if (_oldPropertyValues.TryGetValue(kvp.Key, out object oldValue))
                {
                    if (DirtyPropertyNames.TryGetValue(kvp.Key, out bool?isDirty) && isDirty.HasValue)
                    {
                        if (isDirty.Value)
                        {
                            object value = kvp.Value.Field != null?kvp.Value.Field.GetValue(this) : kvp.Value.GetValue(this);

                            result.Add(kvp.Key, value);
                        }
                    }
                    else
                    {
                        object value = kvp.Value.Field != null?kvp.Value.Field.GetValue(this) : kvp.Value.GetValue(this);

                        if (!object.Equals(oldValue, value))
                        {
                            result.Add(kvp.Key, value);
                        }
                    }
                }
            }

            return(result);
        }