Implementation of data Immediate updating in ASP. WinForm Development Framework

Source: Internet
Author: User

Before the opening, first introduce the WinForm development framework of the interface layer of the inheritance relationship, first I put all the form area into three categories, one is a normal form, a class of editing forms, there is a list of display forms. The integration of forms can encapsulate a lot of things, good encapsulation and inheritance, can improve our efficiency, reduce duplication of code, its role is no longer discussed and emphasized here.

The use of form inheritance, greatly unified the interface, and the common interface operation, provides a good package, such as basic data editing, new form accumulation encapsulates the carriage return, direction keys, data refresh, exception handling, data inspection, data preservation, data update and other interfaces, for the form of data processing provides a great convenience.
While the data query display form takes into account the needs of multi-document display, generally inherits the appropriate base class, encapsulates some commonly used interface layout, in order to achieve the corresponding interface processing effect.

The three types of forms described above inherit the following interface base classes, respectively. Normal forms inherit from BaseForm, the edit form inherits from Baseeditform, and the list shows that the form inherits from Basedock. This is shown in the project.

In the UML design diagram, we see his relationship as shown below, where the green border is the base class above us, and the red border is our actual form object, from which we can clearly see his association.

Baseeditform is relatively more complex than the other two base-class forms, and in addition to providing several buttons to save the data, he can view the data before and after, and his initialization interface and application example interface are shown below.

2, the implementation of the WinForm development framework of data Immediate updating
After introducing the above inheritance, we take a look at how the data is updated in a timely manner based on this inheritance pattern, that is, when the data is saved and the data is saved, the data record synchronizes the effect in the list.

1) First add event handling in base class interface Baseeditform

Code to copy code as follows
public partial class Baseeditform:baseform
{
Public event EventHandler ondatasaved;//Subform Data Save Trigger


2) then add the processing action for the event as shown below.

Code to copy code as follows
<summary>
Handling event triggering after data is saved
</summary>
public virtual void Processdatasaved (object sender, EventArgs e)
{
if (ondatasaved! = null)
{
Ondatasaved (sender, E);
}
}

3) events that trigger immediate updating of data when data is saved

Code to copy code as follows
<summary>
Save data (new and edited saves)
</summary>
Public virtual bool Saveentity ()
{
BOOL result = FALSE;
if (!string. IsNullOrEmpty (ID))
{
Save for edits
result = saveupdated ();
}
Else
{
The new Save
result = Saveaddnew ();
}

return result;
}

<summary>
Update existing data
</summary>
<returns></returns>
Public virtual bool Saveupdated ()
{
return true;
}

<summary>
Save the new data
</summary>
<returns></returns>
Public virtual bool Saveaddnew ()
{
return true;
}

(www.111cn.net)//<summary>
Save
</summary>
<param name= "Close" > Close form </param>
private void Saveentity (bool close)
{
Check the validity of the input
if (this. Checkinput ())
{
Set Mouse Busy state
This. Cursor = Cursors.waitcursor;
Try
{
if (this. Saveentity ())
{
Processdatasaved (This.btnok, New EventArgs ());

Messagedxutil.showtips ("saved successfully");
if (Close)
{
This. DialogResult = DialogResult.OK;
This. Close ();
}
Else
{
This. Clearscreen ();
}
}
}
catch (Exception ex)
{
This. ProcessException (ex);
}
Finally
{
Set Mouse default state
This. Cursor = Cursors.Default;
}
}
}

These are the data preservation operations of the base class, and we pay special attention to this code to

Code to copy code as follows
if (this. Saveentity ()) {
Processdatasaved (This.btnok, New EventArgs ());

4) Operation implementation of the list display interface

After implementing the above operation, these do not need to do anything in the Baseeditform subclass, just implement the following code in the specific list display interface class.

We know that the list interface will generally have specific data refresh function encapsulation (such as the Binddata function), then we create new data, the implementation code is the case.

Code to copy code as follows
<summary>
New Data operations
</summary>
private void Btnaddnew_click (object sender, EventArgs e)
{
Frmeditlaw dlg = new Frmeditlaw ();
Dlg. ondatasaved + = new EventHandler (dlg_ondatasaved);
Dlg. ShowDialog ();
}

void Dlg_ondatasaved (object sender, EventArgs e)
{
Binddata ();
}

When we maintain the data in the new form (data addition, data editing), the latest data records are displayed in the list once the save operation is triggered.
From:http://www.111cn.net/net/171/43076.htm

Implementation of data Immediate updating in ASP. WinForm Development Framework

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.