原文地址: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)的更多相关文章

  1. [Hive - LanguageManual] DML: Load, Insert, Update, Delete

    LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...

  2. 关于MyBatis mapper的insert, update, delete返回值

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  3. PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)

    原文: PHP5: mysqli 插入, 查询, 更新和删除  Insert Update Delete Using mysqli (CRUD) PHP 5 及以上版本建议使用以下方式连接 MySQL ...

  4. mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干

    1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...

  5. insert update delete 语法 以及用法

    insert update delete 被称为 数据定义语句语句 也就是数据的增加 修改 删除 其中不包括查询 譬如: create database -创建数据库 alter database - ...

  6. sql中同一个Trigger里同时包含Insert,Update,Delete

    sql中同一个Trigger里同时包含Insert,Update,Delete SQLServer是靠Inserted表和Deleted表来处理的,判断一下就可以了,只不过比ORACLE麻烦一点 cr ...

  7. mybatis select/insert/update/delete

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  8. mysql数据恢复 insert\update\delete 工具MyFlash

    一.简介MyFlash是由美团点评公司技术工程部开发维护的一个回滚DML操作的工具.该工具通过解析v4版本的binlog,完成回滚操作.相对已有的回滚工具,其增加了更多的过滤选项,让回滚更加容易. 该 ...

  9. LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作

    我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作.这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作 插入( ...

随机推荐

  1. 【转载】onclick与onCommand的区别

    这两个事件没有本质区别,都是点击执行一个事件.不同在于传递的参数不一 样,OnClick (object sender, EventArgs e),OnCommand (object sender, ...

  2. JavaScript对象就是一组属性(方法)的集合

    在JavaScript中,每个对象可以看作是多个属性(方法)的集合,引用一个属性(方法) 很简单,即: 对象名.属性(方法)名 除此之外,还可以用方括号的形式来引用: 对象名[“属性(方法)名”] 注 ...

  3. android数据存储之File

    android中使用File进行存储主要使用到OpenFileOutput和OpenFileInput两个方法,下面直接用一个例子来说明一下. (1)布局文件main.xml文件 <?xml v ...

  4. Oracle NoLogging Append 方式减少批量insert的redo_size

    业务处理中,很多时候使用实表临时表处理中间结果,而实表的Insert操作缺省会记录redo log,针对此问题收集相关测试总结信息如下: [转] 常见dml.ddl语句使用nologging选项所生成 ...

  5. Redis Cluster 在PHP上的实践

    版本:redis3.0.3 redis——slot: 'master' => [ '192.168.1.55:7000'=>[0,5460], '192.168.1.55:7001'=&g ...

  6. window.location.search

    http://i.cnblogs.com/EditPosts.aspx?opt=1&opt2=x 就拿上面这个URL来说window.location.search的返回值为opt=1& ...

  7. [结]Oracle trigger(触发器)摘录

    1.触发器: 是许多关系数据库系统都提供的一项技术.在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处理过程的PL/SQL块. 触发器在数据库里以独立的对象存储,它与存储过程和函数不同 ...

  8. css之四大类选择器

    一.选择器: 关于组合选择器之间的区别: 后代选择器(A B)与子选择器(A>B)之间的区别: 后代选择器: 子选择器: 总结:后代选择器的作用范围是一个元素里面包含的所有元素,即包括的是所有的 ...

  9. python 深入理解 赋值、引用、拷贝、作用域

    在 python 中赋值语句总是建立对象的引用值,而不是复制对象.因此,python 变量更像是指针,而不是数据存储区域, 这点和大多数 OO 语言类似吧,比如 C++.java 等 ~ 1.先来看个 ...

  10. Spring进阶之路(1)-Spring核心机制:依赖注入/控制反转

    原文地址:http://blog.csdn.net/wangyang1354/article/details/50757098 我们经常会遇到这样一种情景,就是在我们开发项目的时候经常会在一个类中调用 ...