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操作 插入( ...
随机推荐
- Ueditor 标签被过滤
1:将allowDivTransToP设置为false 2:将root.traversal方法中的switch注释
- C#操作xml SelectNodes,SelectSingleNode总是返回NULL 与 xPath 介绍
一. SelectNodes,SelectSingleNode总是返回NULL 下面以一个简单的xml为例: <?xml version="1.0"?> <mes ...
- centos6.6安装redis服务安装redis服务,对于discuz来说可以作为缓存使用,减轻服务器压力
获取redis源码包 #wget http://download.redis.io/releases/redis-stable.tar.gz 解压缩 #tar xf redis-stable.tar ...
- 编译工程时报illegal character:\65279--转
windows对UTF-8文件进行了特殊处理,对UTF-8的文本文件自动在前面加了三个byte(EF BB BF),javac编译时,读到最前面这三个byte时报错 illegal character ...
- C++11中的Lambda表达式
原文地址:C++中的Lambda表达式 作者:果冻想 一直都在提醒自己,我是搞C++的:但是当C++11出来这么长时间了,我却没有跟着队伍走,发现很对不起自己的身份,也还好,发现自己也有段时间没有写C ...
- HttpSessionBindingListener和HttpSessionAttributeListener区别 - gengkunpeng的专栏 - 博客频道 - CSDN.NET
分享到 一键分享 QQ空间 新浪微博 百度云收藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 HttpSession ...
- 在网页标题栏上和收藏夹显示网站logo
第一步,准备一个图标制作软件. 首先您必须了解所谓的图标(Icon)是一种特殊的图形文件格式,它是以.ico 作为扩展名.普通的图像设计软件无法使用这种格式,所以您需要到下载一个ico图标工具,本站常 ...
- 【linux】who&&w
who和w 看到目前服务器所登陆的用户,区别是w能看到更详细的信息. [root@andon tmp]# who admin tty5[tty指本地登陆] 2016-05-27 15:16[登陆时间] ...
- LintCode "Delete Digits"
Greedy: remove earliest down-edge: like "54", "97". class Solution { public: /** ...
- (转)VS.NET2010水晶报表安装部署[VS2010]
本文转载自:http://www.cnblogs.com/xiaofengfeng/p/3325793.html 欢迎C#高手加盟QQ群:9340166 水晶报表VS2010版IDE安装标准版SAP ...