Need Help and Design readonlylistbase (Insert, Update, Delete from Readonlylistbase)

Source: Internet
Author: User

Original address: Http://forums.lhotka.net/forums/p/3166/21214.aspx

My task is:
For select client, I has 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 as 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's the best solution to update readonly clients list on frmselectclient, which a user can see their newly inserted CLI Ents or updated clients info. Now I make "Fullrefresh" data in the root readonly list of clients, but think that's a bad approach :-(


Answer:
The general answer are to use the Observer design pattern.

Set up a Observer to watch for new items being added. The new item is, by definition, an editable root, or were saved through an editable root, which means. 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-to-do-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, Project object is inserted or updated.
And in your ROL your handle that event:

 Privateprojectlist () {project.projectsaved+=NewEventHandler (project_projectsaved); }    voidProject_projectsaved (Objectsender, EventArgs e) {Project Project= Sender asProject; if(Project! =NULL) {isreadonly=false; Try        {           for(inti =0; I < This. Count-1; i++)          {            if(Thisidea [I]. Id.equals (Project. Id)) {//item exists-update with new dataThisidea [I] =NewProjectInfo (Project. Id, Project.              Name); return; }          }          //Insert Item           This. ADD (NewProjectInfo (Project. Id, Project.        Name)); }        finally{isreadonly=true; }      }    }

When the event was handled, sender is the new item. You can search the current list for 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 and Design readonlylistbase (Insert, Update, Delete from Readonlylistbase)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.