Naviplat framework technical White Paper. Scenario Solutions

Source: Internet
Author: User

We have many solutions for different scenarios. The following solutions have been accumulated during daily development. I hope they will help you.

Scenario 1: retrieve database data

There are many methods, such as using SQL statements, including whether to use {0} to format SQL statements, and whether to use parameterized SQL statements; you can also use stored procedures. The returned value is a datatable object.

This class library contains the enumerated wherestyle, which indicates the splicing method of the where condition in the SQL statement. Currently, three methods are supported, as shown in-19.

Figure-19

Call method-20

Figure-20

Description

1. the input parameter is a dictionary generic object and is not a sqlparameter type or a {0} style. The reason is that the sqlparameter type data does not need to be referenced in the call place, and only dataset is used for the transfer before the layer and layer, datatable or dictionary generic object to maintain loose coupling between layers

2. when parameterization is used, @ is for sqlserver, which is for Oracle. when the background is Oracle, you can also use the @ keyword. because some people are used to SQL Server or Oracle. unified replacement will be performed in the background

Scenario 2: Operate other DB data

When developing database management software, when we maintain a fixed database connection, we will inevitably connect to other databases to operate the two databases at the same time. for example, data synchronization between two products. there are two cases: the first case is that the other party has a WebService interface that can be called directly; the other case is that there is nothing, only the DB connection string is provided, and you are not sure what the DB is, it may be oracle or sqlserver. therefore, you must obtain other databases at the same time. call and implementation methods-21 and figure-22

Figure-21

Figure-22

Description

1. inherited from Interface

2. databasetype is an enumeration type, indicating the DB type. Currently, sqlserver, Oracle, and oledb are supported.

Scenario 3: retrieve external file data

When developing dB software, you also need to interact with external files, such as Excel or Doc. we also need to provide a series of methods to support this operation. take an Excel file as an example. an xls file may contain multiple sheet pages. This type of Database supports obtaining multiple sheet pages of a file at the same time. implementation Method-23

Figure-23

Description

1. You only need to declare the parmxlsparm object and define the xls file name and sheet name. parm_xls.sheetname is an ilist <string> generic object and multiple sheetnames can be input.

2. The whole class library involves reading Excel files. We only need to call this method to ensure the uniqueness of the method function;

Scenario 4: Execute an SQL statement

Execute an SQL statement, that is, the data completed by operations on the UI Layer, which needs to be saved to the dB. The SQL statement may be a string or parameterized statement, or one or more SQL statements, if there are more than one, you need to use transactions. After the data commit fails, the errors must be recorded. the Class Library provides several methods, as shown in-24

Figure-24

Description

1. When we execute an SQL statement, the parameter is also a dictionary generic object, which is consistent with the previous database data acquisition.

2. Use the dbsqlstringandparameter object, and support oracleparameter and sqlparameter parameters, as shown in Figure 25 and Figure 26.

Figure-25

Figure-26

Description

1. dbparameter [] objects can be stored as sqlparameter [] or oracleparameter [] objects

Scenario 5: UI control assignment and assignment

After the data is obtained from db, it is displayed on the uicontrol, And the this.txt _ textbox is used for user operations. TEXT = xxx. if there are not many controls, this can be easily handled. If there are dozens of controls, it may be a little complicated. the solution for this type of library-27 and figure-28 are shown.

Figure-27

Figure-28

Description

1. The control assignment statement is this. setcontrolvaluebydatarow. This method has three parameters and is defined as follows:

Parameter 1: dictionary <string, string> adic_controlname,

Parameter 2: dictionary <string, string> adic_controltype

Parameter 3: datarow arow_data

The first two parameters are the controlname and controltype attributes defined in the object class constructor.

2. The control value statement is this. getdbcolumnvaluebycontroltodictionary. This method has two parameters and is defined as follows:

Parameter 1: dictionary <string, string> adic_controlname

Parameter 2: dictionary <string, string> adic_controltype

Scenario 6: Clear UI control values

After the data is saved, you need to initialize the control value. Here, the initial value has two meanings: 1st is empty, that is, the value is null, and 2nd is the control value before the restoration operation, for example, if there is an initial value a, it must be restored to a after the operation is complete. the Class Library provides four methods to complete this operation,

Figure-29

Scenario 7: execute a stored procedure

While executing SQL statements, we also need to execute stored procedures in the DB. In addition, the returned values or parameters of stored procedures are also different, which basically contains all the situations.-30 shows

Figure-30

The last method parameter of each group is described here.

String as_procedure // name of the stored procedure

Dictionary <string, Object> adic_parmname // list of stored procedure parameters

Dictionary <string, string> adic_parmdirection // direction of stored procedure parameters, including out and in

Ref dictionary <string, Object> adic_parmvalue // return value of stored procedure parameters

Scenario 8: Controls on multiple pages load data from the same table

When designing many pages, some basic data is very commonly used. example: department, inspection project, etc. that is to say, when we load the drop-down menu of different pages, their data sources are consistent. It is obviously inconvenient to obtain the SQL statements on each page. solution for such libraries-31

Figure-31

Note:

1. Place the real SQL statement in the configuration file and call it with the identifier. When the SQL statement changes, you only need to modify it in one place.

Scenario 9: different customers have different requirements for the same table

In this business scenario, 10 customers in a business table a share 15 of the 15 fields, but each customer has its own personalized field, for example, if customer 1 needs column1 and Customer 2 needs column2. in this case, it is very troublesome for us to interact data between the front and back ends. because we need to load different SQL statements according to different customers. configuration File-311, as shown in

Figure-311

The processing method for such libraries is

1. Reserve 20 string fields for table.

2. the fields used by each customer can be configured, and the true meaning of each field can be indicated at the same time. in this way, when using the object class to operate data, we only need to operate the fields involved by the customer.

3. this method has the disadvantage that it uses a limited solution to solve infinite demands instead of Dynamic Solutions. the alternative method is to create an additional 20 fields if the remaining 20 fields are not enough. create a separate table to save data.

Scenario 10: loading the menu bar and toolbar on the UI page

Data operations are required on the UI page. You may add a menu bar, toolbar, and right-click menu or button to add the operation function points. However, the customer's Function Points may change at any time, or the name of the function point is also frequently modified. ifCodeIf it is processed, it is not a good method. This library solution is shown in 32.

Figure-32

Figure-33

Figure 34

Description

1. Configure the menu items and toolbar to the DB table or XML file, as shown in-33. configure their names and titles here.

2. click Event binding is already handled in the underlying class library. You only need to override the Event code. -34. the advantage of such processing is that the event name is standardized and can be quickly located if any problem occurs.

Scenario 11: call at the Business Layer

This is not a scenario, but a solution that is more appropriate. this means that when we develop a product, we will divide the product into several modules manually, such as the invoicing in ERP. In this case, the invoicing module also distinguishes the general part and the non-General part, the non-General part is the business layer that we often talk about. It is developed based on different customers' customization.

Here we should first talk about the granularity of the business layer. Each module is divided into several sub-modules. The class creation at the business layer is based on the creation of a corresponding business class for each sub-module, create a large business class for this module, and then split it gradually. the solution for this library is the latter, as shown in-35

Figure-35

Scenario 12: Write SQL statements

When we open database software, we will certainly deal with the database. Writing SQL statements is a required course. how to better compile SQL statements is also a topic to be discussed. some of the companies I 've seen are directly written at the UI Layer, and sometimes associated with multiple tables. Their complexity makes it difficult for new developers to continue, I personally think this is not a good development method, because it exposes easily changed things to developers. if we need to add or modify a field, we will undoubtedly need to modify the page, compile and send the DLL file to the customer, thus increasing the development time.

The solution for this type of database is to place SQL statements in a unified configuration file (both dB and XML can be used) and called by a tag, as shown in-36.

Figure-36

During the call, only-37 is required.

Figure-37

Concatenate the where condition (Dictionary type) on the UI Layer and directly call the gettabledataareabyname method.

Description

1. complex SQL statements, such as multiple tables, can be made into views. In short, the complexity of SQL statements should be minimized.

2. If there are multiple conditions, you can use the {0}, {1} format. The UI Layer only needs to pass in the replacement parameter.

3. The called data can be stored in multiple places. For example, some data can be stored in dB and some data can be stored in XML. You only need to set the datalocation attribute to dbandxml.

Scenario 13: Log Management

Log is one of the necessary modules of management software, especially for developers. Good logs can help developers quickly find the problem.

The log solution of this type of database is to classify logs and process them individually. The log types include

L dB log

L User Logon log

L user Event Log

L user operation log

L exception information

-As shown in Figure 38, it is the logon log management in the log management module.

Figure-38

Scenario 14: Grid Control column settings

This scenario is actually very small. It is not necessary to use it here. the main technical point is to load the grid control column. For things displayed on the UI page, the customer may increase or decrease the number of fields when their minds are hot, and the field title may need to be changed, this is very likely. I used to handle a specific requirement, that is, to modify the grid controls on a page. now think about it, it is really unnecessary. if these items can be processed through the configuration file, the implementer can solve the problem. this requirement is shown in solution-39 of this class library.

Figure-39

Description

1. Configure the topic information of a grid control, including the topic name, title, length, check box, and drop-down menu.

2. You only need to modify the configuration file.

3. The loading method is shown in-40.

Figure-40

Scenario 15: Public Basic Encoding

When developing a product, we will inevitably use a lot of data, which requires creating many tables. however, some tables have similar functions and a small amount of data, which are very common. you can create a table to store the data in a unified manner. during maintenance, you only need to maintain the data in one place.

I believe this method is a common method for most people. Now let's talk about the solutions in this library. in addition to the preceding table creation, the common basic encoding is also saved through the storage of XML files. -41

Figure-41

In this way, we need to load two parts when loading the basic encoding. one is dB, and the other is XML. the reason for this design is that we may need to temporarily add some basic public code to the customer, but it is useless to other customers. it can be temporarily stored here. this is also one of the ways to deal with customer personalization

When the system loads data, you can call the method based on Scenario 12.

Scenario 16: hierarchical code Layout

I don't know if we have considered the optimal position for writing a line of code During code writing? In fact, the Code is also hierarchical and hierarchical. In layman's terms, we all know that the exported code should be written at the bottom layer, because this function is very basic and universal, and it is easier to write it at the bottom layer.

In the same way, this is also true when we compile code for common business modules. For example, this code string is called only by this module, and the code string is called by several modules in the same system, or the code may be called by several modules at the same time. Have we ever thought about how to deal with it?

Solution of this class library-42

Figure-42

Description

1. The suffix model is used for interaction between the UI Layer and the DB layer.

2. assicodemodel and toolbarmodel are the model classes of a function module in the author system function module.

3. moduauthormodel is a common model class in the author system function module. It can be called by each sub-module.

4. moduauthorfacade is an external interface of the author system function module.

5. The moduauthorbusiness class is equivalent to the business layer. In fact, it should be in another project (because the author function module is a required module, put it here !)

As a result, different codes are stored in different locations. We need to reserve such an interface to facilitate future expansion. Even porting is relatively simple!

 

The above section describes common business scenarios that can be solved by this framework. I hope you can develop more business scenarios and enrich this framework. Thank you!

Next, we will introduce the layout of the class library of this 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.