Realization of data Immediate updating in WinForm development framework of ASP.net

Source: Internet
Author: User
Tags exception handling inheritance

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

The use of form inheritance, to a large extent, unifies the interface, and the commonly used interface operation, provides a good encapsulation, such as the basic data editing, new form accumulation encapsulation of carriage return, direction keys, data refresh, exception handling, data inspection, data storage, data updates and other interfaces, for the form of data processing provides a great convenience.
The data query display form takes into account the needs of multiple document display, generally inherit the appropriate base class, encapsulate some commonly used interface layout, in order to achieve the corresponding interface processing effect.

The three types of forms mentioned above, the base class of the inherited interface are the following. The normal form inherits from the BaseForm, the edit form inherits from the Baseeditform, and the list display form inherits from Basedock. The works are shown below.

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

Baseeditform is relatively more complex than the other two base class forms, and he can look at the data before and after it, in addition to providing a few data-saving buttons, and his initialization interface and application example interface are shown below.

2, WinForm Development framework for the implementation of real-time data update

After introducing the above inheritance relationship, let's take a look at how to implement the data in a timely manner based on this inheritance pattern, that is, the effect of data record synchronization in the list after the data is saved form and the data is saved.

1 first Add event handling in the base class interface Baseeditform

The code is as follows Copy Code
public partial class Baseeditform:baseform
{
Public event EventHandler ondatasaved;//Child form data Save trigger


2) then add the processing of the event, as shown below.

The code is as follows Copy Code
<summary>
Handle event firings 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

The code is as follows Copy Code

<summary>
Save data (new and edited Save)
</summary>
Public virtual bool Saveentity ()
{
BOOL result = FALSE;
if (!string. IsNullOrEmpty (ID))
{
Saved by Edit
result = saveupdated ();
}
Else
{
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;
}

<summary>
Save
</summary>
<param name= "Close" > Closing 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 ("Save Success");
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;
}
}
}

The above data save operations belong to the base class, we pay special attention to this code can

The code is as follows Copy Code
if (this. Saveentity ()) {
Processdatasaved (This.btnok, New EventArgs ());

4 The Operation realization of the list display interface

After you do this, you don't need to do anything with the Baseeditform subclass, just implement the following code in the concrete list presentation interface class.

We know that the list interface generally has a specific data refresh function package (such as the Binddata function), then we are in the new data, the implementation of the code is this.

The code is as follows Copy Code

<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 ();
}

So when we maintain data in a new form (data addition, data editing), these latest data records are displayed in the list once the save operation is triggered.

Finally put on a WinForm development framework of the interface for reference.

Related Article

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.