Exemple #1
0
        private void btCopy_Click(object sender, EventArgs e)
        {
            if (curItem == null)
            {
                return;
            }


            string schemaName;

            if (!I3GetStringForm.Excute("输入方案名称", "", out schemaName, false, false))
            {
                return;
            }
            if (settingItems.Keys.Contains(schemaName))
            {
                MessageBox.Show("方案名称已存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //保存当前数据
            SaveItem();
            //新增
            SettingItem settingItem = new SettingItem(schemaName);

            I3ObjectUtil.DeepCopyProperty(curItem, settingItem); //复制属性
            settingItem.SchemaName = schemaName;                 //重新设置名称

            settingItems.Add(settingItem.SchemaName, settingItem);
            LoadItems();
            CurItem = settingItem;
        }
        /// <summary>
        /// 添加一个原始值,如果已经有了,则覆盖
        /// </summary>
        /// <param name="entity"></param>
        private void AddOriginalEntity(T entity)
        {
            object id = idProperty.GetValue(entity, null);

            if (originalEntityDic.ContainsKey(id))
            {
                originalEntityDic.Remove(id);
            }
            T originalEntity = (T)Activator.CreateInstance(typeof(T));

            I3ObjectUtil.DeepCopyProperty(entity, originalEntity);
            originalEntityDic.Add(id, originalEntity);
        }
        /// <summary>
        /// unChangedList列表中实例属性改变事件,将实例移动到changeList
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void entity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            T    entity         = sender as T;
            T    originalEntity = this.originalEntityDic[idProperty.GetValue(entity, null)];
            bool changed        = !I3ObjectUtil.CompareProperty(entity, originalEntity);


            if (this.unChangedList.Contains(entity)) //在未改变列表中
            {
                if (changed)                         //已改变
                {
                    this.unChangedList.Remove(entity);
                    this.changedList.Add(entity);
                }
            }
            else if (this.changedList.Contains(entity)) //在已改变列表中
            {
                if (!changed)                           //未改变
                {
                    this.changedList.Remove(entity);
                    this.unChangedList.Add(entity);
                }
            }
        }