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操作 插入( ...
随机推荐
- 控制台程序实现利用CRM组织服务和SqlConnection对数据库中数据的增删改查操作
一.首先新建一个控制台程序.命名为TestCol. 二.打开App.config在里面加入,数据库和CRM连接字符串 <connectionStrings> <add name=&q ...
- C转义字符
C语言输出特殊字符 C语言转义字符意义大体同于前面的C#转义字符,这里列出用c语言,输出%d.\n等特殊字符的方法. #include <stdio.h> int main() { pri ...
- Linux下 RabbitMQ的安装与配置
以下教程摘录自互联网并做了适当修改,测试的rabbitmq 版本为:rabbitmq-server-generic-unix-3.5.6 各版本之间会有差异!!! 一 Erlang安装 Rabbit ...
- CCS float vs clear
有人已经写过了.(*^__^*) 嘻嘻…… 为啥我不能写, ( ‵o′)凸 float 首先,HTML的布局是流布局.其元素是分为行内元素和块级元素的. 所谓行内元素就是接着写不会发生换行的元素如&l ...
- Hibernate延迟加载机制详解
摘自 http://blog.chinaunix.net/uid-20577907-id-3129234.html 1 延迟加载: 延迟加载机制是为了避免一些无谓的性能开销而提出来的,所谓延迟加载就是 ...
- 程序员书单_UML篇
UML基础与Rose建模教程 http://download.csdn.net/detail/shenzhq1980/9076199 UML和模式应用1 Applying UML and Patter ...
- IsolatedStorageException for Silverlight Application
if you are using the IsolatedStorage for application configuration storage, and when you get the Iso ...
- 深入了解iPad上的MouseEvent【转】
iPad上没有鼠标,所以手指在触发触摸事件(TouchEvent)的时候,系统也会产生出模拟的鼠标事件(MouseEvent). 这对于普通网页的浏览需求而言,基本可以做到与PC端浏览器无明显 ...
- LintCode "Coins in a Line II" !
Nice one to learn: DP + Game Theoryhttps://lefttree.gitbooks.io/leetcode/content/dynamicProgramming2 ...
- 剑指offer系列27--表示数值的字符串
[题目]请实现一个函数用来判断字符串是否表示数值(包括整数和小数). 例如,字符串”+100”,”5e2”,”-123”,”3.1416”和”-1E-16”都表示数值. 但是”12e”,”1a3.14 ...