原文地址: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. 解决Oracle安装完成后,随便输入用户名密码只要选择DBA身份就能登陆进去的问题

    以sysdba身份登录既采用的是本地(系统)认证方式, 将%ORACLE_HOME%\network\admin\sqlnet.ora中的SQLNET.AUTHENTICATION_SERVICES= ...

  2. [mysql] mysql 5.6.27 innodb 相关参数

    mysql> show variables like '%innodb%';+------------------------------------------+--------------- ...

  3. Hibernate入门学习(一)

    一.Hibernate是什么 Hibernate主要用来实现Java对象和数据表之间的映射,除此之外还提供数据查询和获取数据的方法,可以大幅度减少开发时人工使用SQL和JDBC处理数据的时间.Hibe ...

  4. Panel扩展 圆角边框,弧形边框

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...

  5. 深入了解iPad上的MouseEvent【转】

    iPad上没有鼠标,所以手指在触发触摸事件(TouchEvent)的时候,系统也会产生出模拟的鼠标事件(MouseEvent).     这对于普通网页的浏览需求而言,基本可以做到与PC端浏览器无明显 ...

  6. vs2012 遇到 “此操作要求使用 IIS 集成管线模式。”

    这个项目是VS2013开发的,我用2012打开想调试,但报这个错误. 最后安装2013,然后调试则正常.

  7. 【Redis】配置redis主从复制

    阅读目录 redis-3.2.1.master tar zxvf redis-3.2.1.tar.gz mv redis-3.2.1 redis-3.2.1.slave-1 tar zxvf redi ...

  8. TX Textcontrol 使用总结三——禁用右键、模版合并

    一.Tx Textcontrol如何禁用右键快捷菜单? ==> 添加txContent_TextContextMenuOpening事件,实现方式如下所示: private void txCon ...

  9. nginx的https配置

    测试自签名的ssl证书 首先执行如下命令生成一个key openssl genrsa -des3 - 然后他会要求你输入这个key文件的密码.不推荐输入.因为以后要给nginx使用.每次reload ...

  10. 怎样减少FLASH影片文件过大——绝对好用

    网站建设中怎样减少FLASH影片文件过大 一,制作前的处理  1声音(mp3):   GoldWave中打开需要处理的mp3,然后把它另存为---在最下一栏的属性中选择较低的字节数,例如,本来的mp3 ...