Пример #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);
        }