新建项目:
1. 项目引入GZFramwork.dll
NuGet地址:Install-Package GZFramwork
每个项目都引用
2.BLL层
设置数据库连接维护类:继承于:GZFramwork.DBUtility.FramworkDbConnection
代码:
using GZFramwork; using GZFramwork.DBUtility; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GZFramworkTest.BLL { public class FramworkDBProvider : GZFramwork.DBUtility.FramworkDbConnection { public override GZFramwork.DBUtility.ConnectionInfo DoDbInfo(string DBName) { if (DefaultConnection == null) { SQLConfig sc = new SQLConfig() { Server = "(local)", DataBase = "GZFramworkTest", UserID = "test", Password = "gzframwork" }; DefaultConnection = new ConnectionInfo(sc); } if (DBName == DefaultConnection.DBName) return DefaultConnection; else { throw new Exception("不能识别的数据库!"); //如果支持多数据库,在这里返回不同数据库名的ConnectionInfo实例 //return new ConnectionInfo() //{ // DBObject = DBObject.MSSQL, // DBName = DBName, // ConnectionStr = DefaultSQLConfig.GetConnectionStr(DBName) //}; } } } }Program 应用数据库连接维护:修改启动项目Program文件中Main函数:
项目主程序Main()函数中配置初始化
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);new GZFramwork.GZFramworkDBConfig<BLL.GZFramworkDBProvider>();//应用数据库连接维护
Application.Run(new Form1()); }
定义bllBusiness类,继承自GZFramwork.ORM.GZbllBaseBusiness
代码:
namespace GZFramworkTest.BLL { public class bllBusiness : GZFramwork.Lib.GZbllBaseBusiness { public bllBusiness(Type ORM_Main, string DocCode, int Length, params Type[] ORM_Details) { _DAL = new GZFramwork.Lib.GZdalBaseBusiness(ORM_Main, DocCode, Length, ORM_Details); } public bllBusiness(Type ORM_Main, params Type[] ORM_Details) { _DAL = new GZFramwork.Lib.GZdalBaseBusiness(ORM_Main, null, 0, ORM_Details); } public override string Account { //这里模拟登陆账号为GarsonZhang get { return "GarsonZhang"; } } public override string DefultDBName { //当前数据库 get { return "GZFramworkTest"; } } } }
本系列项目源码下载地址:https://github.com/GarsonZhang/GZFramework.Demo
系列文章
4. GZFramwork数据库层《二》单据表增删改查(自动生成单据号码)
6. GZFramwork数据库层《四》单据主从表增删改查(主键自动生成)
7. GZFramwork数据库层《五》高级主从表增删改查(主表明细表主键都自动生成)
8. GZFramwork数据库层《六》存储过程调用
9. GZFramwork数据库层《七》总结