SQL Table 自動產生Net底層-產生業務層Service

來源:互聯網
上載者:User

標籤:auto   返回   .text   class   erb   擷取   cti   app   one   

業務層介面

        public static string DataTableToBaseIService(string tableName, string nameSpace, string className)        {            var table = SqlTableHelper.GetSQLTableInfo(tableName);            StringBuilder reval = new StringBuilder();            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>        /// 擷取資料(分頁)        /// </summary>        /// <param name=""filterSql"">查詢條件</param>        /// <param name=""pageIndex"">頁碼</param>        /// <param name=""pageSize"">每頁顯示數量</param>        /// <param name=""total"">總行數</param>        /// <param name=""sort"">排序條件</param>        /// <returns>返回DataTable</returns>                 DataTable PageData(string filterSql,int pageIndex,int pageSize,out int total,string sort="""");        /// <summary>        /// 擷取資料(不分頁)        /// </summary>                 /// <param name=""filterSql"">查詢條件</param>        /// <param name=""sort"">排序條件</param>        /// <returns>返回DataTable</returns>                  DataTable PageData(string filterSql,string sort="""");        /// <summary>        /// 擷取單條資料        /// </summary>        /// <param name=""filterSql"">查詢條件</param>        /// <returns>返回DataTable</returns>           DataTable GetSingle(string filterSql);        /// <summary>        /// 刪除        /// </summary>                  int Delete({3} {4},ref string msg);    }}}}", nameSpace, className, tableName, SqlTableToMapping.ChangeType(table.Rows[0]["資料類型"].ToString()), table.Rows[0]["列名"]);            return reval.ToString();        }        public static string DataTableToUserIService(string nameSpace, string className)        {            StringBuilder reval = new StringBuilder();            reval.AppendFormat(@"       using System;using System.Collections.Generic;using System.Data;using {0}.Mapping;namespace {0}.IService{{    public partial interface {1}    {{         }}}}", nameSpace, className);            return reval.ToString();        }
View Code

實現業務層介面

        public static string DataTableToBaseService(DataTable dt, string tableName, string nameSpace)        {            string key = dt.Rows[0]["列名"].ToString();            StringBuilder sb = new StringBuilder();            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);            ///新增            sb.AppendFormat(@"        /// <summary>        /// 新增/修改        /// </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>        /// 擷取資料(分頁)        /// </summary>        /// <param name=""filterSql"">查詢條件</param>        /// <param name=""pageIndex"">頁碼</param>        /// <param name=""pageSize"">每頁顯示數量</param>        /// <param name=""total"">總行數</param>        /// <param name=""sort"">排序條件</param>        /// <returns>返回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>        /// 擷取資料(分頁)        /// </summary>        /// <param name=""filterSql"">查詢條件</param>        /// <param name=""sort"">排序條件</param>        /// <returns>返回DataTable</returns>           public DataTable PageData(string filterSql, string sort = """")        {{            return _{0}Repository.PageData(filterSql,sort);        }}        /// <summary>        /// 擷取單條資料        /// </summary>        /// <param name=""filterSql"">查詢條件</param>        /// <returns>返回DataTable</returns>           public DataTable GetSingle(string filterSql)        {{            return _{0}Repository.GetSingle(filterSql);        }}        /// <summary>        /// 刪除資料        /// </summary>        /// <param name=""key"">主鍵</param>        /// <returns>返回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]["資料類型"].ToString()));            sb.Append(@"    }}");            return sb.ToString();        }               #endregion        #region 產生自訂類        public static string DataTableToUserService(string tableName, string nameSpace)        {            StringBuilder reval = new StringBuilder();            reval.AppendFormat(@"       using System;using System.Collections.Generic;using System.Data;using System.Text;using System.Data.SqlClient;using {0}.Mapping;namespace {0}.Service{{    public partial class {1}Service    {{    }}}}", nameSpace, tableName);            return reval.ToString();        }
View Code

Autoface注入

        public static string AutofaceClass(string nameSpace, DataTable dt)        {            StringBuilder sb = new StringBuilder();            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 (var i = 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);        }    }}");            return sb.ToString();        }
View Code

 

SQL Table 自動產生Net底層-產生業務層Service

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.