Example of a three-tier winform Architecture

Source: Internet
Author: User

In web development, the three-tier architecture of the factory mode is often used. Currently, this architecture method has been applied in winform, and many attempts have been made. It also imitates the classic example petshop, but it still does not work.
I have taken some online examples. Now I will briefly introduce the entire production process of this example. (This example introduces a three-tier structure, so it is only a simple application. If you think this method is good, please implement it on your own.
Other modules)
Structure:
------- PMIS -------- master Program Code
Presentation layer, responsible for application presentation and user experience.
------- Dalfactory ----- Abstract Factory
Abstract Factory is used to create various data objects. configuration files and reflection are used here.
------- Idal -------- data interface layer (controls the type of database to be selected)
Data operation interface. The data access layer implements its interface and overwrites it (reflecting the interface-oriented programming idea ).
------- BLL ------
The business logic of the application is called by the presentation layer.
------- Model ------- construct the model (corresponding to the database field)
Model assembly, which stores entity classes for data access layer and logic layer calls
------- Sqlserverdal ---- sqlserver data access layer
The data access layer implements specific select, update, delete... operations and overwrites the idal interface.
------- Dbutility ---- public data access layer
The data processing layer implements specific executereader, executedatatable, and executenonquery.
------- Utility ---- public Layer
Read the database connection string from the configuration file.
1. Database Structure
Database Name PMIS
Table Admin
[ID] [bigint] No.
[Name] [varchar] (10) Name
[Password] [varchar] (100) password
......
Table creation statement
Create Table [DBO]. [admin] (
[ID] [bigint] identity (1, 1) not null,
[Name] [varchar] (10) Collate chinese_prc_ci_as not null,
[Password] [varchar] (100) Collate chinese_prc_ci_as not null,
[Purviewid] [int] not null,
[Remember] [int] Null,
[Autorun] [int] Null,
[Departmentsid] [bigint] Null,
Constraint [pK _ administrator _ 1] primary key clustered
(
[ID] ASC
) On [primary]
) On [primary]
2. Create a database model.
Model
# Region internal Member Fields
Private int _ id;
Private string _ name;
Private string _ password;
...
# Endregion
# Region Method
Public admininfo (){}

Public admininfo (string username, string password)
{
This. _ name = username;
This. _ password = password;
}
# Endregion
3. Create a dalfactory ----- Abstract Factory
Public static idal. iadmin create ()
{
String Path = system. configuration. configurationsettings. receivettings ["Dal"];
String classname = "sqlserverdal. admin ";

Idal. iadmin acount = (idal. iadmin) Assembly. Load (PATH). createinstance (classname );
Return acount;
}
4. Create idal -------- Data Interface Layer
Public interface iadmin
{
Admininfo login (string username, string password );
Int insert (admininfo account );
Int Update (admininfo account );
}
5. Create utility-Public Layer
Public static string connectionstring ()
{
Return (configurationsettings. etettings ["connectionstring"]);
}
6. Create dbutility-public data access layer and sqlserver data access layer
Create sqlhelper class in dbutility
The admin class of sqlserverdal must inherit iadmin
Public class admin: iadmin
{}
Admin class mainly implements User Login
7. established business logic Zeng BLL
Method public static admininfo login (string username, string password ){}
8. Add the application configuration file app. config for the PMIS main program.
Add <deleetask>
<Add key = "connectionstring" value = "Server =.; uid = sa; Pwd =; database = PMIS"> </Add>
<Add key = "Dal" value = "sqlserverdal"> </Add>
</Appsettings>
Add controls in the form of the main program and add events for buttons
If (BLL. admin. login (parameter) = NULL)
{
// Process...
}
Else
{
// Process...
}

Sample Code download

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.