Business Layer Interface
Public Static stringDatatabletobaseiservice (stringTableName,stringNameSpace,stringclassName) { varTable =Sqltablehelper.getsqltableinfo (tableName); StringBuilder Reval=NewStringBuilder (); Reval. AppendFormat (@" Using system;using system.collections.generic;using system.data;using {0}. Mapping;namespace {0}. iservice{{public partial Interface {1} {///<summary>////</summary> int Save ({2} model,ref string msg); <summary>///Data Acquisition (pagination)///</summary>/<param name= "" Filtersql "> Query criteria </pa ram>//<param name= "" PageIndex "" > Page number </param>//<param name= "" PageSize "" > Display quantity per page </p aram>//<param name= "Total" > Number of Rows </param>//<param name= "Sort" > Sorting criteria </param> <returns> return datatable</returns> DataTable pagedata (String Filtersql,int pageindex,i NT Pagesize,out int total,string sort= "" "); <summary>///Data acquisition (no paging)///</summary>//<param name= "" Filtersql "" > Check Enquiry </param>//<param name= "" Sort ""> Sort conditions </param>//<returns> return datatable</returns> DataTable pagedata (String fi Ltersql,string sort= "" ""); <summary>///Get Single data///</summary>//<param name= "" Filtersql "> Query criteria </para m>//<returns> returns datatable</returns> DataTable getsingle (string filtersql); <summary>///delete//</summary> int Delete ({3} {4},ref string msg); }}}}", NameSpace, ClassName, TableName, sqltabletomapping.changetype (table. rows[0]["Data Type"]. ToString ()), table. rows[0]["Column Name"]); returnReval. ToString (); } Public Static stringDatatabletouseriservice (stringNameSpace,stringclassName) {StringBuilder Reval=NewStringBuilder (); Reval. AppendFormat (@"using system;using system.collections.generic;using system.data;using {0}. Mapping;namespace {0}. iservice{{public partial Interface {1} {{} }}", NameSpace, className); returnReval. ToString (); }
View Code
Implementing the Business Layer interface
Public Static stringDatatabletobaseservice (DataTable DT,stringTableName,stringnameSpace) { stringkey = dt. rows[0]["Column Name"]. ToString (); StringBuilder SB=NewStringBuilder (); Sb. AppendFormat (@"using system;using system.collections.generic;using system.data;using system.text;using System.Data.SqlClient; Using {0}. mapping;using {0}. irepository;using {0}. Iservice;namespace {0}. service{{public partial class {1}service:i{1}service {{", NameSpace, tableName); Sb. AppendFormat (@"private readonly i{0}repository _{0}repository; public {0}service (I{0}repository {0}repository) {this._{0}repository = {0}repository; }}", TableName); ///NewSb. AppendFormat (@" <summary>//new/modified///modify///</summary> public int Save ({0} model,ref string msg) {{var iret =-1; try {{iret = _{0}repository.save (model); }} catch (Exception e) {{msg = e.message; }} return iret; }}///<summary>///For data (paging)///</summary>//<param name= "" Filtersql "" > Check Conditions </param>//<param name= "" PageIndex "" > Page number </param>//<param name= "" PageSize "" > per page Display quantity </param>//<param name= "Total" > Total rows </param>//<param name= "Sort" > Sort conditions < /param>//<returns> return datatable</returns> public DataTable pagedata (string filtersql, int PageIndex, int pageSize, out int total, string sort = "" ") {{return _{0}repository.pagedata (filtersql , Pageindex,pagesIze,out total,sort); }}///<summary>///For data (paging)///</summary>//<param name= "" Filtersql "" > Check Enquiry </param>//<param name= "Sort" > Sorting criteria </param>//<returns> return Datatable</retur Ns> Public DataTable pagedata (string filtersql, string sort = "" ") {{return _{0}repositor Y.pagedata (Filtersql,sort); }}///<summary>///Get Single data///</summary>//<param name= "" Filtersql "> Query Bar Pieces </param>///<returns> return datatable</returns> public DataTable getsingle (string filtersq L) {{return _{0}repository.getsingle (filtersql); }}///<summary>//delete data///</summary>//<param name= "" Key "" > Primary key </para m>//<returns> return datatable</returns> public int Delete ({2} {1},ref string msg) {{ var iret =-1; try {{iret = _{0}repository.delete ({1}); }} catch (Exception e) {{msg = e.message; }} return iret; }}", TableName, Key, Sqltabletomapping.changetype (dt. rows[0]["Data Type"]. ToString ())); Sb. Append (@" }}"); returnsb. ToString (); } #endregion #regionTo build a custom class Public Static stringDatatabletouserservice (stringTableName,stringnameSpace) {StringBuilder Reval=NewStringBuilder (); Reval. AppendFormat (@"using system;using system.collections.generic;using system.data;using system.text;using System.Data.SqlClient;u Sing {0}. Mapping;namespace {0}. service{{public partial class {1}service {{} }}}", NameSpace, tableName); returnReval. ToString (); }
View Code
Autoface Injection
Public Static stringAutofaceclass (stringnameSpace, DataTable DT) {StringBuilder SB=NewStringBuilder (); Sb. AppendFormat (@"using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Using autofac;using {0}. mapping;using {0}. Iservice;namespace {0}. service{{public class Servicemodule:module {{protected override void Load (Containerbuilder builder) {{", NameSpace); for(vari =0; i < dt. Rows.Count; i++) {sb. AppendFormat (@"Builder. Registertype<{0}> (). As<{1}> ();"Dt. rows[i]["name"] +"Service","I"+ dt. rows[i]["name"] +"Service"); } sb. Append (@"base. Load (builder); } }}"); returnsb. ToString (); }
View Code
SQL Table Auto-generate net bottom-generate business layer service