GZFramwork数据库层《前言》DLL项目引用

时间:2023-12-16 13:34:26

新建项目:

GZFramwork数据库层《前言》DLL项目引用

1. 项目引入GZFramwork.dll

NuGet地址:Install-Package GZFramwork

GZFramwork数据库层《前言》DLL项目引用

GZFramwork数据库层《前言》DLL项目引用

每个项目都引用

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, , ORM_Details);
} public override string Account
{
//这里模拟登陆账号为GarsonZhang
get { return "GarsonZhang"; }
} public override string DefultDBName
{
//当前数据库
get { return "GZFramworkTest"; }
}
}
}

本系列项目源码下载地址:https://github.com/GarsonZhang/GZFramework.Demo

系列文章

1. GZFramwork数据库层《前言》Demo简介

2. GZFramwork数据库层《前言》DLL项目引用

3. GZFramwork数据库层《一》普通表增删改查

4. GZFramwork数据库层《二》单据表增删改查(自动生成单据号码)

5. GZFramwork数据库层《三》普通主从表增删改查

6. GZFramwork数据库层《四》单据主从表增删改查(主键自动生成)

7. GZFramwork数据库层《五》高级主从表增删改查(主表明细表主键都自动生成)

8. GZFramwork数据库层《六》存储过程调用

9. GZFramwork数据库层《七》总结