Summary of C/S simple UI framework development (2)

Source: Internet
Author: User

I have read a lot of replies. Thank you for your attention!

Today, I want to write an example to illustrate how to use this framework to start a new project and implement a typical crud function. During this period, I also want to talk about information interaction and scheduling among various UI components. This component has been being repaired and supplemented. After it is basically stable, I have not carefully considered whether there is a better implementation method. I hope to clarify my ideas through simple instructions. There are also a lot of bricks.

To start a new project, you must first create a main form that can be inherited directly from workbenchbase.

Partial class mainform

Inherits component. workbenchbase

................

End Class

After the above Code is completed, you can get such a form with the basic menu, accordion, and user component area.

The business functions are not implemented, so there is nothing in the accordion menu. In addition to the "edit" menu closely related to business actions, workbenchbase is provided by default for other menu items in the main menu.

After the main form is available, we can implement a typical crud function.

As mentioned in the previous article, the entity Editing Component (entitycontrol) is used to process the user interaction interface of a business entity. To do the crud function at a time, you must first create a custom control and then modify the code, let him inherit from entitycontrol.

 

<Global. Microsoft. VisualBasic. compilerservices. designergenerated ()> _

Public class myentitycontorl

Inherits component. entitycontrol

................

End Class

Then, you need to define the field controls in the object one by one on this control, as shown in figure

 

To automatically assign values to components and business entities, you must enter the corresponding object attribute name for the tag attribute of the control for data interaction.

 

If the entity component has components that need to be bound to data, such as ComboBox, rewrite the initbindablecontrol method to implement the binding in this method.

Public class myentitycontorl

''' <Summary>

''' To bind Components

''' </Summary>

''' <Remarks> </remarks>

Public overrides sub initbindablecontrol ()

Mybase. initbindablecontrol ()

End sub

End Class

The object component calls the corresponding method through reflection to complete the CRUD operation. The default method name is newly added as "insert", deleted as "delete", and changed to "Update ". If you need to change the corresponding method name, you can rewrite the following attributes.

Public overrides readonly property insertmethodname () as string

Get

Return mybase. insertmethodname

End get

End Property

 

Public overrides readonly property updatemethodname () as string

Get

Return mybase. updatemethodname

End get

End Property

 

Public overrides readonly property deletemethodname () as string

Get

Return mybase. deletemethodname

End get

End Property

If the entity control also needs to provide additional business operations (such as review), you can add the corresponding method by yourself.

At this time, the user editing component does not know what the business entity object to be edited is. Because most of the crud operations are initiated in the grid component (gridview, in this scenario, the gridview automatically assigns a value to the datasource of the user editing component. In a few scenarios, if a user editing component needs to be used independently, the user needs to encode the datasource and State (new, modify, delete, and other States) attributes for the user editing component, this allows the user to edit the component to know the object to be processed and the processing method. The following code:

 

Entitycontrolhost. State = new entitycontrolhostaddnewstate ()

Entitycontrolhost. entitycontrol. datasource = r

By now, an entity editing component has been completed, including data interaction with business entities and automatic scheduling of crud business actions. The implementation process of crud is not described due to the introduction of the UI framework.

In practice, there are two display modes for the interface organization of a program: MDI and SDI. The Framework supports both methods through layoutbehavier, but some of the features in the system can only be displayed in the MDI format, which may cause some normal SDI components to display exceptions in the MDI, therefore, we need to define a container for each entity editing component. This container can provide SDI and MDI support, and also implement command buttons. Business scheduling is loosely coupled with the entity editing component, avoid reuse limitations. The containers of the object editing component are classified into two types: entitytabbedhost and entitydialoghost, which are classified into the corresponding MDI and SDI. Entitydialoghost can be automatically used in MDI and SDI. entitytabbedhost can only be used in MDI.

You can define a container for myentitycontrol,

 

Let this component integrate entitydialoghost to get the following form:

 

Then add the completed entity editing component to the form.

Enter the following content in the Code:

Public overridable property entitycontrol () as entitycontrol implements ientitycontrolhost. entitycontrol

Get

Return myentitycontrol1

End get

Set (byval value as entitycontrol)

Myentitycontrol1 = Value

End set

End Property

At this point, a complete entity editing function is complete. It has basic command buttons such as Save and delete, and implements the corresponding scheduling function. If you need to add additional business commands, simply add a button and complete the corresponding processing code.

We are working on a grid component for this entity to make this function more complete.

Texture is too difficult, it is very simple, I will describe the text, first define a custom component, let this component integrate the gridview, then get the following control.

 

You can use the designer to add columns to define grid components. If the entity editing component has additional business processing (such as review), it can be defined in the form of a menu item in the editing or system, and the subsequent framework will be automatically merged with the main menu. To ensure consistency of Framework service scheduling and presentation.

In this case, the component already has grid customization (columns, condition styles, etc. In fact, this is a feature integration of the Janus component) and scheduling capabilities of crud and other business functions.

In addition, it is easy to define it out of the box, because the system automatically determines the display form based on layoutbehavier's MDI and SDI status.

Now all the crud functions have been completed, and the rest is to assemble this function.

The assembly process was originally based on the sharpdeveploer plug-ins, including dependencies. Later, I felt that the development scale was limited and debugging was troublesome and I gave up.

To put it simply, in the assembly process, a business function corresponds to a folderitem, multiple folderitems constitute a folder, and one folder corresponds to a group of Accordion menus on the left of the main form.

To add the above business functions to the system, you need the following code:

Public class customerfolder

Inherits component. Folder

Public sub new ()

Init ()

End sub

 

Sub Init ()

 

Dim item as folderitem

Item = new folderitem

TEXT = "XXXXX Management"

Imagename = application. startuppath + "\ images \ basedata.bmp"

Item. Foldername = "XXXXX Management"

Item. folderorder = 1

Item. foldergroup = "XXXXX Management"

Item. iconname = "small75.bmp"

Item. Subject = "XXXXX Management"

Item. viewfullname = "customerview"

Item. businessservicefullname = "Dal. customerprovider"

Item. businessmethodfullname = "getall"

Addfolderitem (item)

End sub

End Class

Then, rewrite the createfolders () method in mainform (Workbench ).

Public overrides function createfolders () as component. folderkeeper

Dim folders as new component. customerfolder

Dim B as basefolder = new basefolder

Folders. Add (B)

Return folders

End Function

In fact, the above information was previously uninstalled from the configuration file or database, so that the code is clean and tidy, but the readability will be a little poor, it is not satisfied with the change, tangle.

The startup code is completed below, and the major achievement is ~

''' <Remarks> </remarks>

Public sub Main ()

Application. setcompatibletextrenderingdefault (false)

Application. enablevisualstyles ()

 

Dim mainform as new mainform

Mainform. businessbehavier = new wcfbusinessbehavier

Mainform. layoutbehavier = new tabbedlayoutbehavier

Mainform. servicemanager = new component. servicemanager

Mainform. servicemanager. validateservice = new validateservice

'The other services and bevhavier are not required at the moment.

System. Windows. Forms. application. Run (mainform)

End sub

Of course, there is a lot of work to do if it is perfect, but the basic functions are described. Run it:

 

The simplest crud does this, saving the trouble of assigning values. The interface style is uniform, and business function consistency is guaranteed, and no repeated writing is required for all scheduling functions.

Let's talk about it. You are welcome to throw the jade. It's best to say "Lan Tianyu.

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.