I haven't written a blog for some time. Today, I want to write something. I decided to share with you how to build a basic application using EasyUI and ASP.NET to realize the basic operation of adding, deleting, modifying and searching database. First of all, we need to declare that this series of blogs only build a basic three-tier architecture, namely Model, DAL, BLL and UI. They do not involve Abstract Factory patterns in design patterns, and so on. It is mainly for your understanding that when you really do a project, you still want to define factories and interfaces in advance. List things to reduce the coupling of the system.
We should not be unfamiliar with the three-tier structure, comrades who do not know can also Baidu themselves. The basic three-tier architecture consists of four class libraries: Model (Entity) layer, DAL layer, BLL layer and UI layer. As follows:
The Model layer is a one-to-one mapping of data tables in a database. Its function, in my opinion, is to pass parameters as a data type. For example, I want to define a function that adds student information. If the basic data type data is still used as a parameter, then the function has to be written as follows:
public int AddStudentInfo(string id, string name, string gender, int? age, DateTime? birthday, string phoneNumber, string contactAddress) { //TODO: Specific code }
This function has too many parameters, which is neither easy to understand nor easy to expand. Therefore, we can consider establishing an entity class and passing this entity class as a parameter. The entity class code is as follows:
public class StudentModel { /// <summary> /// Student number /// </summary> public string Id { get; set; } /// <summary> /// Name /// </summary> public string Name { get; set; } /// <summary> /// Gender /// </summary> public string Gender { get; set; } /// <summary> /// Age /// </summary> public int? Age { get; set; } /// <summary> /// Birthday /// </summary> public DateTime? Birthday { get; set; } /// <summary> /// Telephone number /// </summary> public string PhoneNumber { get; set; } /// <summary> /// Contact address /// </summary> public string ContactAddress { get; set; } }
The corresponding function for adding student information can be written as follows:
public int AddStudentInfo(StudentModel model) { //TODO: Specific code }
If you have other tables in your database, just build the corresponding classes one by one. The test data of this series of blogs are attributes data of land, boundary point and boundary line, which will also be used in subsequent blogs. The specific codes are as follows:
Territorial category:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EasyUIApp.Entity { public class CadastreEntity { /// <summary> /// Number /// </summary> public int Id { get; set; } /// <summary> /// Identification code /// </summary> public int? BSM { get; set; } /// <summary> /// Element Code /// </summary> public string YSDM { get; set; } /// <summary> /// Block coding /// </summary> public string DKBM { get; set; } /// <summary> /// Classification of land masses /// </summary> public string DKLB { get; set; } /// <summary> /// East to East /// </summary> public string DKDZ { get; set; } /// <summary> /// Block West to /// </summary> public string DKXZ { get; set; } /// <summary> /// Block south to /// </summary> public string DKNZ { get; set; } /// <summary> /// Block northward to /// </summary> public string DKBZ { get; set; } /// <summary> /// Name of boundary person /// </summary> public string ZJRXM { get; set; } } }
Boundary Point Class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EasyUIApp.Entity { public class BoundaryPointEntity { /// <summary> /// Number /// </summary> public int Id { get; set; } /// <summary> /// Identification code /// </summary> public int? BSM { get; set; } /// <summary> /// Element Code /// </summary> public string YSDM { get; set; } /// <summary> /// Boundary address number /// </summary> public string JZDH { get; set; } /// <summary> /// Types of boundary markers /// </summary> public string JBLX { get; set; } /// <summary> /// Types of boundary points /// </summary> public string JZDLX { get; set; } /// <summary> /// Block coding /// </summary> public string DKBM { get; set; } /// <summary> /// X coordinate value /// </summary> public float? XZBZ { get; set; } /// <summary> /// Y coordinate value /// </summary> public float? YZBZ { get; set; } } }
Address Line Class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EasyUIApp.Entity { public class BoundaryLineEntity { /// <summary> /// Number /// </summary> public int Id { get; set; } /// <summary> /// Block coding /// </summary> public string DKBM { get; set; } /// <summary> /// Identification code /// </summary> public int? BSM { get; set; } /// <summary> /// Element Code /// </summary> public string YSDM { get; set; } /// <summary> /// Boundary Linear Properties /// </summary> public string JXXZ { get; set; } /// <summary> /// Address Line Category /// </summary> public string JZXLB { get; set; } /// <summary> /// Location of boundary line /// </summary> public string JZXWZ { get; set; } /// <summary> /// Address Line Number /// </summary> public string JZXH { get; set; } /// <summary> /// Starting Point Number /// </summary> public string QJZDH { get; set; } /// <summary> /// Terminal address number /// </summary> public string ZJZDH { get; set; } /// <summary> /// Description of boundary line /// </summary> public string JZXSM { get; set; } /// <summary> /// Right holder of adjacent land property /// </summary> public string PLDWQLR { get; set; } /// <summary> /// Adjacent to the Territory Indicator /// </summary> public string PLDWZJR { get; set; } } }
So far, the entity layer has been established, and the next blog will explain the construction of the data access layer.