WinForm Development framework based on Enterprise Library to support extended operation of China Dream Database

Source: Internet
Author: User
Tags sqlite sqlite database

Due to the needs of a customer friend, need my WinForm development framework to support the operation of the national Dream database, this database has been heard very early, but the real general project with very little, generally in some special projects may need to use. Since my WinForm development framework is based on the implementation of the data access layer of Enterprise Library, it is easy to add support for a database, this article describes how to support this mysterious domestic database-the Dream database at the framework level. 1. A brief introduction to the Dream database

Dameng database management System is a high-performance database management system with complete independent intellectual property rights, referred to as DM. The latest version of the Dameng database management system is version 7.0, referred to as DM7. DM7 provides feature support for SQL92 and core-level support for SQL99, and supports a variety of database development interfaces, including Ole DB, ADO, ODBC, OCI, JDBC, Hibernate, PHP, PDO, DB Express, and. Net Dataprovider and so on.

Dameng database can be downloaded (http://www.dameng.com/) on the trial, the installation of a lot of management tools, after installation can let it create some instance database, so as to facilitate our understanding of the basic operation of the database, I do not know much about this database, However, it claims to support the SQL-92 standard, then use it will not have any problems, but some personalized syntax needs to query.

Dameng database parser, you can execute some of its own statements, note that its database table must take a schema prefix, similar to SQL Server DBO, but this is necessary.

2. Architecture support processing of WinForm development framework based on Enterprise Library

My Enterprise Library based development framework, the bottom of the use of Microsoft's data Access Components Enterprise Library to adapt to the operation of a variety of database types, its hierarchy is as follows, each DAL layer (such as Dalsql, Daloracle, etc.) all provide the implementation of the corresponding database, the interface layer below the hierarchical diagram as shown below.

If more than one database is added, we add one more component extension class for the Enterprise Library and add the corresponding DAL layer to the Business data module.

For the specific dalsql such as the data implementation layer, we do not need to take the data access processing operations in all classes to implement, we can abstract the way, the normal database processing operations on the base class, as shown below.

So in the BASEDALSQL layer (SQL Server database personalization implementation part), only need to implement some of the functions, we put most of the database operations, the most top-level database access to the base class Abstractbasedal class, This allows us to minimize the amount of code that needs to be rewritten by adding different database types.

In the end, we can add a data access layer to achieve the implementation of another database (the Dream database), the specific architecture design diagram is as follows.

3. Specific Access test case code

In the above section, we demonstrate the extensibility of the framework, and theoretically already has the support of the expansion of the Dream database, this section describes how to implement the database of the dream of the bottom access operation, and write a simple test example to test, confirm our implementation ideas.

We know that the Enterprise library to implement other database support, need to add a component extension class, such as EntLibContrib.Data.SQLite is used to support the SQLite database, ENTLIBCONTRIB.DATA.MYSQL is used to support MySQL, the content of this extension class is not many, mainly used to parse the following configuration file.

In order to be able to seamlessly integrate with Enterprise Library objects, we can refer to the MySQL database extension class ENTLIBCONTRIB.DATA.MYSQL approach, to create an enterprise based on the domestic Dream database Library extension class, the approximate project code is shown below.

So we can add the configuration file as shown below and it will parse and process it normally.

Let's write the code of the test to confirm our extension class, implement the WinForm development framework to support the extended operation of the domestic dream database.

We create an auxiliary class for the general operation of the database to be explained, as shown in the code below.

/// <summary>    ///data access testing based on Enterprise Library class libraries/// </summary>     Public classEntlibdmhelper { PublicEntlibdmhelper () {}/// <summary>            ///executes a SQL query statement that returns the first field of all records for the query results, separated by commas. /// </summary>            /// <param name= "SQL" >SQL statements</param>            /// <returns>            ///returns the first field of all records for the query result, separated by a comma. /// </returns>             Public stringSqlvaluelist (stringSQL) {Database db=databasefactory.createdatabase (); DbCommand Command=db.            Getsqlstringcommand (SQL); StringBuilder result=NewStringBuilder (); using(IDataReader dr =db. ExecuteReader (command)) { while(Dr. Read ()) {result. AppendFormat ("{0},", dr[0].                ToString ()); }            }            stringStrresult = result. ToString (). Trim (','); returnstrresult; }        /// <summary>            ///executes a SQL query statement that returns a DataTable collection of all records. /// </summary>            /// <param name= "SQL" >SQL query Statements</param>            /// <returns></returns>             PublicDataTable sqltable (stringSQL) {DataSet DS=NewDataSet (); Database DB=databasefactory.createdatabase (); DbCommand Command=db.            Getsqlstringcommand (SQL); returnDb. ExecuteDataset (command). tables[0]; }    }

Note that the above code is not used to reach the specific object of the dream, but the use of Enterprise library database and other objects to operate, so that is very convenient for us to interface abstraction processing, you can put more functions into the database to access the abstract class inside.

If you are using the object processing database of the. NET provider of the dream, then the specific code should be like this.

/// <summary>            ///executes a SQL query statement that returns the first field of all records for the query results, separated by commas. /// </summary>            /// <param name= "SQL" >SQL statements</param>            /// <returns>            ///returns the first field of all records for the query result, separated by a comma. /// </returns>             Public stringSqlvaluelist (stringSQL) {dmconnection Connection=Newdmconnection (ConnectionString); Dmcommand cmd=Newdmcommand (SQL, connection); Connection.            Open (); StringBuilder result=NewStringBuilder (); using(Dmdatareader dr =cmd. ExecuteReader ()) { while(Dr. Read ()) {result. AppendFormat ("{0},", dr[0].                ToString ()); }            }            stringStrresult = result. ToString (). Trim (','); returnstrresult; }        /// <summary>            ///executes a SQL query statement that returns a DataTable collection of all records. /// </summary>            /// <param name= "SQL" >SQL query Statements</param>            /// <returns></returns>             PublicDataTable sqltable (stringSQL) {DataSet DS=NewDataSet (); Dmdataadapter Adpater=Newdmdataadapter (SQL, ConnectionString); Adpater.            Fill (DS); returnDs. tables[0]; }

For the convenience of testing, I write a simple query example to introduce, as shown in the code below, we mainly use Entlibdmhelper this auxiliary class object, that is, the Enterprise Library based on the expansion of processing operations.

Private voidbtnSearch_Click (Objectsender, EventArgs e)        {Binddata (); }        Private voidBinddata () {stringCondition ="1=1"; if( This. txtAuthor.Text.Length >0) {Condition+=string. Format ("and Author like '%{0}% '", This. Txtauthor.text); }            if( This. txtName.Text.Length >0) {Condition+=string. Format ("and Name like '%{0}% '", This. txtName.Text); }            if( This. txtPublisher.Text.Length >0) {Condition+=string. Format ("and Publisher like '%{0}% '", This. Txtpublisher.text); }            stringsql ="Select * from PRODUCTION. Product Where"+condition; Entlibdmhelper Helper=NewEntlibdmhelper (); //Dmhelper helper = new Dmhelper ();DataTable dt =Helper.            sqltable (SQL);  This. Datagridview1.datasource =DT; SQL="Select Count (*) from PRODUCTION. Product Where"+condition; stringTotalCount =Helper.            Sqlvaluelist (SQL);  This. Lblcount.text =string. Format ("Total data: {0} bar", TotalCount); }

The final example runs with the following interface effect as shown below.

It basically confirms the integration of the framework, and realizes the extended operation of supporting the domestic Dream database. The rest is that we imitate the basedalsql such a base class, for the dream database to add a personalized database processing interface, you can achieve the support of the overall framework. For each module of data access, we need to add a daldm such an implementation layer, the base class point to BASEDALDM so it is possible.

WinForm Development framework based on Enterprise Library to support extended operation of China Dream Database

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.