Ejemplo n.º 1
0
        public void CopyFrom(BaseObjectList value, int startIndex, int endIndex)
        {
            //整个复制过程完成后,再通知列表发生变化了
            objects.CollectionChanged -= this.OnCollectionChanged;
            this.Clear();
            _copyed.Clear();
            if (endIndex > this.objects.Count)
            {
                endIndex = value.objects.Count;
            }
            for (int i = startIndex; i < endIndex; i++)
            {
                GeneralObject obj = value[i];
                GeneralObject ngo = new GeneralObject();
                ngo.CopyFrom(obj);
                Add(ngo);
                _copyed.Add(ngo);
            }
            //发送列表变化通知, 新增对象为列表本身
            NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);

            this.OnCollectionChanged(args);
            //还原继续监听列表单个数据变化过程
            objects.CollectionChanged += this.OnCollectionChanged;
            IsModified = false;
        }
Ejemplo n.º 2
0
        public void CopyFrom(BaseObjectList value)
        {
            //整个复制过程完成后,再通知列表发生变化了
            objects.CollectionChanged -= this.OnCollectionChanged;
            this.Clear();
            _copyed.Clear();
            foreach (GeneralObject obj in value)
            {
                //如果对象是列表中新增的编辑对象,不复制
                if (obj.List != null && obj.List.EmptyRow == obj)
                {
                    continue;
                }
                GeneralObject ngo = new GeneralObject();
                ngo.CopyFrom(obj);
                Add(ngo);
                _copyed.Add(ngo);
            }
            //发送列表变化通知, 新增对象为列表本身
            NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);

            this.OnCollectionChanged(args);
            //还原继续监听列表单个数据变化过程
            objects.CollectionChanged += this.OnCollectionChanged;
            IsModified = false;
        }
Ejemplo n.º 3
0
        public void NewPropertyValue(string propertyName)
        {
            //有属性默认值
            var p = (from ps in PropertySetters where ps.PropertyName == propertyName select ps).FirstOrDefault();

            if (p != null && p.Default != null)
            {
                //设置默认属性结果
                SetPropertyValue(propertyName, p.Default, true, true);
                //如果默认属性是列表,调用列表的New过程
                if (p.Default is BaseObjectList)
                {
                    (p.Default as BaseObjectList).New();
                }
            }
            //有默认对象,复制默认对象
            else if (p != null && p.DefaultObject != null)
            {
                if (p.DefaultObject is GeneralObject)
                {
                    //复制默认对象到新对象
                    GeneralObject go  = p.DefaultObject as GeneralObject;
                    GeneralObject ngo = new GeneralObject();
                    ngo.CopyFrom(go);
                    p.Object.SetPropertyValue(p.PropertyName, ngo, false, true);
                }
                else if (p.DefaultObject is ObjectList)
                {
                    //复制默认对象到新对象
                    ObjectList go  = p.DefaultObject as ObjectList;
                    ObjectList ngo = new ObjectList();
                    ngo.CopyFrom(go);
                    p.Object.SetPropertyValue(p.PropertyName, ngo, false, true);
                }
            }
            else
            {
                //如果属性是集合
                if (GetProperty(propertyName).PropertyType == typeof(BaseObjectList))
                {
                    //如果属性存在,清空集合
                    BaseObjectList old = (BaseObjectList)this.GetPropertyValue(propertyName);
                    if (old != null)
                    {
                        old.New();
                    }
                    //否则,无不置空标记,设置一个空集合
                    else if (!NotEmpty)
                    {
                        SetPropertyValue(propertyName, new ObjectList(), true);
                    }
                }
                else
                {
                    SetPropertyValue(propertyName, null, true, true);
                }
            }
        }
Ejemplo n.º 4
0
        private static void OnHasEmptyRowChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            BaseObjectList list = (BaseObjectList)o;

            if (e.NewValue != null && (bool)e.NewValue)
            {
                list.CreateEmpty();
            }
        }
Ejemplo n.º 5
0
        public static void OnDefaultChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args)
        {
            BaseObjectList ol = (BaseObjectList)dp;

            //如果列表为空,把默认值添加到列表中
            if (ol.Count == 0)
            {
                ol.Add(ol.Default);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 路径改变时,获取数据
        /// </summary>
        /// <param name="dp">自身</param>
        /// <param name="args">新值参数</param>
        public static void OnPathChanged(DependencyObject dp, DependencyPropertyChangedEventArgs args)
        {
            //分页组件有MultiPath时,在MultiPath时加载数据,Path发生改变时不加载数据
            if (dp is PagedObjectList && ((PagedObjectList)dp).MultiPath != null)
            {
                return;
            }
            BaseObjectList ol = (BaseObjectList)dp;

            //如果指明Path改变时,不加载数据,则只有当外界要求,加载数据时,才加载
            if (ol.LoadOnPathChanged)
            {
                ol.Load();
            }
        }
Ejemplo n.º 7
0
        //设置列表属性,设置时,将监听其IsModified属性改变事件
        private void SetCollectionProperty(string key, BaseObjectList ol)
        {
            //如果有默认对象,且要设置的列表为空,采用默认对象的复制结果
            var p = (from ps in PropertySetters where ps.PropertyName == key select ps).FirstOrDefault();

            if (p != null && p.DefaultObject != null && (ol == null || ol.Count == 0))
            {
                //复制默认对象到新对象
                ObjectList go  = p.DefaultObject as ObjectList;
                ObjectList ngo = new ObjectList();
                ngo.CopyFrom(go);
                ol = ngo;
            }
            SetPropertyValue(key, ol, true);
            ol.Watch("IsModified", ol_PropertyChanged);
        }
Ejemplo n.º 8
0
        private static void OnEmptyRowChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            BaseObjectList list = (BaseObjectList)o;

            //清除旧的空行的监听
            if (e.OldValue != null)
            {
                GeneralObject go = (GeneralObject)e.OldValue;
                go.DynamicPropertyChanged -= list.EmptyRowChanged;
            }
            //新加空行在动态属性变化后,在列表最后添加新空行
            if (e.NewValue != null)
            {
                GeneralObject go = (GeneralObject)e.NewValue;
                go.DynamicPropertyChanged += list.EmptyRowChanged;
            }
        }
Ejemplo n.º 9
0
        private static void OnSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            BaseObjectList list = (BaseObjectList)o;

            list.OnSourceChanged();
        }
Ejemplo n.º 10
0
 public MyList(BaseObjectList list)
 {
     _list = list;
     list.PropertyChanged += list_PropertyChanged;
 }
Ejemplo n.º 11
0
 public int IndexOf(BaseObjectList list)
 {
     return(list.IndexOf(this));
 }