In this series of tutorials, we take the complete development process of a large CMS system as an example to discuss with you the experiences and lessons of net development. In this program, we adopt the popular three-layer/N-layer framework + warehouse mode architecture model. Project hierarchy:
Main purposes of each layer:
- EasyFast. Web-UI display layer, system operation interface.
- EasyFast. BLL-business logic layer, used to process business logic in a program.
- EasyFast. Model -- used to transmit data between layers.
- EasyFast. Utility -- public class library
- EasyFast. Repository -- Data Operations (Data Warehousing layer)
- EasyFast. DBContext -- ORM tool Layer
Basic Framework code:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Data;using System.Data.SqlClient; namespace EasyFast.Repository.Interface{ public interface IRepository<T> where T : class { T GetById(int id); T Find(string where, string orderColumn, List<SqlParameter> parameters); int Add(T model); int Delete(int id); int Update(T model); int GetPageCount(string tableName, string where, List<SqlParameter> parameters); DataTable GetPageList(string tableName, string fieldNames, string where, string orderColumn, int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters); DataTable GetDataTable(string tableName, string fieldNames, string where, string orderColumn, List<SqlParameter> parameters); }}
-- Directory structure: EasyFast. Repository. Interface. IRepository
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using EasyFast.Repository.Interface;using System.Data;using System.Data.SqlClient; namespace EasyFast.Repository{ public class Repository<T> : IRepository<T> where T : class { public T GetById(int id) { T model = default(T); return model; } public T Find(string where, string orderColumn, List<SqlParameter> parameters) { T model = default(T); return model; } public int Add(T model) { int _result = 0; return _result; } public int Delete(int id) { int _result = 0; return _result; } public int Update(T model) { int _result = 0; return _result; } public int GetPageCount(string tableName, string where, List<SqlParameter> parameters) { int _result = 0; return _result; } public DataTable GetPageList(string tableName, string fieldNames, string where, string orderColumn, int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { DataTable dt = new DataTable(); return dt; } public DataTable GetDataTable(string tableName, string fieldNames, string where, string orderColumn, List<SqlParameter> parameters) { DataTable dt = new DataTable(); return dt; } }}
-- Directory structure: EasyFast. Repository. Repository
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. data; using System. data. sqlClient; using EasyFast. repository; using EasyFast. repository. interface; namespace EasyFast. BLL {public class BaseBLL <T> where T: class {IRepository <T> repository = new Repository <T> (); protected readonly Object lockHelper = new object (); # region get model public T GetById (int id) {return repository. getById (id);} public T Find (string where) {return repository. find (where, "", null);} public T Find (string where, List <SqlParameter> parameters) {return repository. find (where, "", parameters);} public T Find (string where, string orderColumn, List <SqlParameter> parameters) {return repository. find (where, orderColumn, parameters) ;}# endregion # region adds a record public int Add (T model) {return repository. add (model) ;}# endregion # region deletes a public int Delete (int id) {return repository. delete (id) ;}# endregion # region updates a record public int Update (T model) {return repository. update (model) ;}# endregion # region obtains the public virtual DataTable GetDataTable (string tableName, string fieldNames, string where, string orderColumn, List <SqlParameter> parameters) record set of the specified condition) {return repository. getDataTable (tableName, fieldNames, where, orderColumn, parameters);} public virtual DataTable GetDataTable (string fieldNames, string where, string orderColumn, List <SqlParameter> parameters) {return repository. getDataTable ("", fieldNames, where, orderColumn, parameters);} public virtual DataTable GetDataTable (string fieldNames, string where, List <SqlParameter> parameters) {return repository. getDataTable ("", fieldNames, where, "", parameters);} public virtual DataTable GetDataTable (string where, List <SqlParameter> parameters) {return repository. getDataTable ("", "*", where, "", parameters);} public virtual DataTable GetDataTable (string where) {return repository. getDataTable ("", "*", where, "", null);} public virtual DataTable GetDataTable () {return repository. getDataTable ("", "*", "", "", null) ;}# endregion # region obtains the number of records for a specified condition. public virtual int GetPageCount (string tableName, string where, list <SqlParameter> parameters) {return repository. getPageCount (tableName, where, parameters);} public virtual int GetPageCount (string where, List <SqlParameter> parameters) {return repository. getPageCount ("", where, parameters);} public virtual int GetPageCount (string where) {return repository. getPageCount ("", where, null);} public virtual int GetPageCount () {return repository. getPageCount ("", "", null) ;}# endregion # obtain the record of the specified condition by PAGE public virtual DataTable GetPageList (string tableName, string fieldNames, string where, string orderColumn, int startRecordIndex, int endRecordIndex, List <SqlParameter> parameters) {return repository. getPageList (tableName, fieldNames, where, orderColumn, startRecordIndex, parameters, parameters);} public virtual DataTable GetPageList (string tableName, string fieldNames, string where, int startRecordIndex, int endRecordIndex, list <SqlParameter> parameters) {return repository. getPageList (tableName, fieldNames, where, "", startRecordIndex, endRecordIndex, parameters);} public virtual DataTable GetPageList (string fieldNames, string where, int startRecordIndex, int endRecordIndex, list <SqlParameter> parameters) {return repository. getPageList ("", fieldNames, where, "", startRecordIndex, endRecordIndex, parameters);} public virtual DataTable GetPageList (string where, int startRecordIndex, int endRecordIndex, List <SqlParameter parameters) {return repository. getPageList ("", "*", where, "", startRecordIndex, endRecordIndex, parameters);} public virtual DataTable GetPageList (string where, int startRecordIndex, int endRecordIndex) {return repository. getPageList ("", "*", where, "", startRecordIndex, endRecordIndex, null);} public virtual DataTable GetPageList (int startRecordIndex, int endRecordIndex) {return repository. getPageList ("", "*", "", "", startRecordIndex, endRecordIndex, null) ;}# endregion }}
-- Directory structure: EasyFast. BLL. BaseBLL
Sample Code download: EasyFastCMS-2014.05.28.zip