Need help with design ReadOnlyListBase (Insert, Update, Delete from ReadOnlyListBase)
原文地址:http://forums.lhotka.net/forums/p/3166/21214.aspx
My task is:
For select client, I have a modal form (frmSelectClient) with grid. Datasourse for grid is root readonly list of Clients (ReadOnlyListBase). If user can't find client in the list, he would like to add new. I create and show a modal form (frmEditClient) with editable root (BusinessBase) for add a new Client to DB. This frmEditClient can reuse also to edit existing Client.
My question:
What is the best solution to update readonly clients list on frmSelectClient, that a user can see their newly inserted clients or updated clients info. Now I make "fullrefresh" data in root readonly list of Clients, but think that is a bad approach :-(
Answer:
The general answer is to use the Observer design pattern.
Set up an Observer to watch for new items being added. The new item is, by definition, an editable root, or was saved through an editable root, which means that a Saved event is raised when the object is saved.
The Observer handles that event, and relays the information to anyone who cares - such as your ROL.
The ROL can then just add that one new item.
The easiest way to do this is to use .NET events as the "Observer".
In your editable root:
public static event EventHandler ProjectSaved; protected static void OnProjectSaved(Project project)
{
if (ProjectSaved != null)
ProjectSaved(project, EventArgs.Empty);
} public override Project Save()
{
Project result = base.Save();
OnProjectSaved(result);
return result;
}
The Save() override raises the static event any time any Project object is inserted or updated.
And in your ROL you handle that event:
private ProjectList()
{
Project.ProjectSaved += new EventHandler(Project_ProjectSaved);
} void Project_ProjectSaved(object sender, EventArgs e)
{
Project project = sender as Project;
if (project != null)
{
IsReadOnly = false;
try
{
for (int i = ; i < this.Count -; i++)
{
if (thisIdea [I].Id.Equals(project.Id))
{
// item exists - update with new data
thisIdea [I] = new ProjectInfo(project.Id, project.Name);
return;
}
}
// insert item
this.Add(new ProjectInfo(project.Id, project.Name));
}
finally
{
IsReadOnly = true;
}
}
}
When the event is handled, sender is the new item. You can search the current list to see if that item already exists, and then replace it with an updated version. If it doesn't exist you simply add a new item.
Need help with design ReadOnlyListBase (Insert, Update, Delete from ReadOnlyListBase)的更多相关文章
- [Hive - LanguageManual] DML: Load, Insert, Update, Delete
LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...
- 关于MyBatis mapper的insert, update, delete返回值
这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...
- PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)
原文: PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD) PHP 5 及以上版本建议使用以下方式连接 MySQL ...
- mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干
1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...
- insert update delete 语法 以及用法
insert update delete 被称为 数据定义语句语句 也就是数据的增加 修改 删除 其中不包括查询 譬如: create database -创建数据库 alter database - ...
- sql中同一个Trigger里同时包含Insert,Update,Delete
sql中同一个Trigger里同时包含Insert,Update,Delete SQLServer是靠Inserted表和Deleted表来处理的,判断一下就可以了,只不过比ORACLE麻烦一点 cr ...
- mybatis select/insert/update/delete
这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...
- mysql数据恢复 insert\update\delete 工具MyFlash
一.简介MyFlash是由美团点评公司技术工程部开发维护的一个回滚DML操作的工具.该工具通过解析v4版本的binlog,完成回滚操作.相对已有的回滚工具,其增加了更多的过滤选项,让回滚更加容易. 该 ...
- LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作
我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作.这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作 插入( ...
随机推荐
- 【转】WMI使用的WIN32_类库名
ShadowBy--Win32_ShadowContext--Win32_ShadowCopy--Win32_ShadowDiffVolumeSupport--Win32_ShadowFor--Win ...
- HDFS 文件读写过程
HDFS 文件读写过程 HDFS 文件读取剖析 客户端通过调用FileSystem对象的open()来读取希望打开的文件.对于HDFS来说,这个对象是分布式文件系统的一个实例. Distributed ...
- SQL SERVER 生成MYSQL建表脚本
/****** Object: StoredProcedure [dbo].[GET_TableScript_MYSQL] Script Date: 06/15/2012 13:05:14 ***** ...
- wap图片滚动特效_无css3 元素js脚本编写
手机图片滑动切换,网上有很多这样的例子,但都借助于其他组件,让代码混乱的不行:还有就是用到css3里的 transform:translate(x,y);移动元素,不过发现在不支持css3的设备上马上 ...
- jQuery checkbox相关
搬家来的~~~ $('#checkbox').attr('checked'); 返回的是checked或者是undefined解决办法 分类: Jquery2014-03-18 17:10 5523 ...
- (转)Android-Mac电脑如何进行APK反编译-使用apktool、jd-gui
最近群里有人问如何在mac下进行apk反编译,我也没试过,以前都是在windows下进行反编译的,windows下很简单,有许多比较好的集成工具,如apkide(改之理),不过我猜mac下应该和win ...
- HackerRank "Morgan and a String"
I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution: for _ in range ...
- PHP析构函数与垃圾回收
析构函数:当某个对象成为垃圾或者当对象被显式销毁时执行. GC (Garbage Collector) 在PHP中,没有任何变量指向这个对象时,这个对象就成为垃圾.PHP会将其在内存中销毁.这是PHP ...
- 激活Maven profile的几种方式
首先简单介绍下 Maven 的 profile 是什么.对于人来说,profile 是指人的肖像,轮廓,比如论坛里每个人注册了帐号后,可以设置自己的 profile,放上照片,介绍等等.对于 Mave ...
- nsq的erlang客户端
nsq是基于golang开发的分布式消息系统,这里仅仅贴个和erlang之间的通信demo rebar-creator create-app test_nsq rebar.config % -*- e ...