Implementation of real-time data update in the Winform development framework in asp.net, asp. netwinform

Source: Internet
Author: User

Implementation of real-time data update in the Winform development framework in asp.net, asp. netwinform

Before starting, we will first introduce the inheritance relationships of the interface layer in the Winform development framework. First, I will divide all forms into three types: common forms and editing forms, another type is the list display form. Form integration can encapsulate and process many things. Good encapsulation and inheritance can improve our efficiency and reduce repeated code. Its role is not discussed and emphasized here.

It adopts form inheritance, which greatly unifies the interface and provides good encapsulation for common interface operations, for example, basic data editing and new forms are encapsulated with interfaces such as carriage return, direction keys, data refresh, exception handling, Data check, data storage, and data update, it provides great convenience for form data processing.
While the data query display form takes into account the need of Multi-document display, it generally inherits appropriate base classes and encapsulates some commonly used interface la s to achieve corresponding interface processing results.

In the three types of forms described above, the inherited interface base classes are the following. The normal form inherits from BaseForm, the edit form inherits from BaseEditForm, And the list shows that the form inherits from BaseDock. The project is as follows.

 

In the UML design diagram, we can see that the relationship is as follows. The Green Border is the base class above us, and the red border is our actual form object. From this figure, we can clearly see their associations.

 

BaseEditForm is relatively more complex than the other two base-class forms. In addition to providing the buttons required for saving data, it can also view data before and after it, the initialization interface and application example interface are as follows.

 

 

2. Implementation of real-time data update in the Winform development framework
After introducing the inheritance relationship above, let's take a look at how to update data in a timely manner based on this inheritance mode, that is, after the data is saved in a form and saved, the effect of data records synchronized to the list.

1) First, add event processing in BaseEditForm on the base interface.

The Code is as follows:
Public partial class BaseEditForm: BaseForm
{
Public event EventHandler OnDataSaved; // trigger for saving sub-form data


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

The Code is as follows:
/// <Summary>
/// Triggered when the stored data is processed
/// </Summary>
Public virtual void ProcessDataSaved (object sender, EventArgs e)
{
If (OnDataSaved! = Null)
{
OnDataSaved (sender, e );
}
}

3) trigger an instant data update event when data is saved.

The Code is as follows:
/// <Summary>
/// Save data (new and edited storage)
/// </Summary>
Public virtual bool SaveEntity ()
{
Bool result = false;
If (! String. IsNullOrEmpty (ID ))
{
// Save the edited content
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;
}

(Www.111cn.net) // <summary>
/// Save
/// </Summary>
/// <Param name = "close"> close the form </param>
Private void SaveEntity (bool close)
{
// Check the input Validity
If (this. CheckInput ())
{
// Set the mouse busy status
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 the default mouse status
This. Cursor = Cursors. Default;
}
}
}

The above is the data storage operation of the base class. Pay special attention to this code.

 

The Code is as follows:
If (this. SaveEntity ()){
ProcessDataSaved (this. btnOK, new EventArgs ());

4) operation implementation of the list display interface

After the above operations are implemented, you do not need to perform any operations on the sub-classes of BaseEditForm. You only need to implement the following code in the interface class of the specific list display.

As we know, the list interface generally has a specific data refresh function encapsulation (such as the BindData function), so the implementation code is like this when we create data.

The Code is as follows:
/// <Summary>
/// Add data operation
/// </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 ();
}

In this way, when we maintain data in the new form (Data addition and data editing), once the save operation is triggered, these latest data records are also displayed in the list.
From: http://www.111cn.net/net/171/43076.htm


C # How to implement real-time update of data in two windows of the winform Program

The simplest method:
Add a method to the Form1 class. Form1 has a dataGirdview or textBox.
Public partial class Form1: Form {public Form1 () {InitializeComponent ();} // Add a method to update textBox1 public void UpdateTextBox (string newData) {this. textBox1.Text = newData} // click the button to display the private void buttonShowForm2_Click (object sender, EventArgs e) in the Form2 window {// use the new Constructor (see the Form2 class below ), create a Form2 instance Form2 form2 = new Form2 (this); form2.Show () ;}// other code ...... } In Form2, add a new constructor and a new method.
Public partial class Form2: Form {private Form1 _ form1; public Form2 () {InitializeComponent () ;}// Add a constructor public Form2 (Form1 form): this () {_ form1 = form;} // when data is updated, call this method to send the data back to Form1 and update the display private void UpdateFrom1 (string newData) {_ from1.UpdateTextBox (string newData);} // other code ......}

Differences between winform and Web in ASPNET

1. UI Layout
HTML has perfect layout capabilities, including layout based on text streams, including various paragraphs, pictures, left-right alignment of text in a paragraph, indentation of the beginning of a paragraph, line spacing, and avoidance of first and last characters; HTML tables have a strong layout function. You can divide the UI into different proportions and scale them proportionally. the position and size of HTML elements can be pixels or percentages; vector graphs can be implemented through VML. Before any element is output as a bitmap, it can be converted using a filter. WinForm is mainly output in a window by using GDI, which is theoretically useless. Of course, it is unrealistic to implement HTML. The advantage of GDI is that it is fast, saving the overhead of parsing HTML. 2. Custom Control Capabilities
You can customize HTC and WinForm in a browser, and have a large number of third-party controls. DHTML has a very complete DOM model, and various object attributes, methods, and events are very complete. Unfortunately, you can only perform operations in the script language on the page.
The object model of Control in WinForm is also good, but the main reason is that there is no complete object model of HTML. Currently, it is a window Control and there is no window Control. The problem of Web development is that the client does not have a sound development environment and development language, and only scripts can be used.
WinForm has strong language support and a complete class library. You can write your own control library. The WinForm program has. net framework on the client. We can use any. net framework data type, such as dataset. We can bind the data and then only submit the changed data to the server. 3. communication capability with servers
Different submission methods (such as Form submission and XmlHttp) in Web applications lead to status issues. WinForm does not, and WinForm can be connected to the server, it is useful in some applications, such as querying large data volumes by page. WinForm can also implement the event communication mechanism with the server. For a data entry-based application, it interacts with the server several times. WinForm is more advantageous. (WinForm can use a lot of means to communicate with the server, such as WebService, Remoting, Http, Socket ....) we can draw a conclusion that the display-oriented program uses HTML for better interface performance, while the WinForm program should be better for programs that are related to data input and frequently interact with servers.
The most important thing is that developers need to master two systems when using Web development. 4. Authentication and local access permissions the Web application authentication method is set by the server, and the client is implemented through a browser.
As the client, the WinForm program can provide authentication information in various ways.
In Web applications, what can a program control and everything can be set by a browser, for example, automatic login or password authentication, while the WinForm program can determine the account to log on to and which authentication method to use.
The local access permissions of Web applications are simple and general, including internet, local intranet, trusted sites, and restricted sites. Basically, access permissions to resources, such as file system network access, are not involved.

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.