GZFramwork数据库《一》项目引用及初始化

1. 项目引入GZFramwork.dll

NuGet地址:Install-Package GZFramwork

技术分享

技术分享

2.BLL层

   重载FramworkDbConnection

namespace TestBLL
{
    public class GZFramWorkDBConfig : FramworkDbConnection
    {
        public override ConnectionInfo DoDbInfo(string DBName)
        {
            if (DefaultConnection == null)
            {
                SQLConfig sc = new SQLConfig()
                {
                    Server = "(local)",
                    DataBase = "Test",
                    UserID = "sa",
                    Password = "garson2839"
                };

                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)
                //};
            }
        }
    }
}

项目主程序Main()函数中配置初始化

         /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //初始化数据库配置
             new GZFramwork.GZFramworkDBConfig<TestBLL.GZFramWorkDBConfig>();
            Application.Run(new Form1());
        }

 

定义bllBusiness类

public class bllBusiness : GZFramwork.ORM.GZbllBaseBusiness
    {
        public bllBusiness(Type TypeMain, string sDocCode, int sLength, params Type[] TypeDetail)
        {
            _DAL = new GZdalBaseBusiness(TypeMain, sDocCode, sLength, TypeDetail);
        }

        public bllBusiness(Type TypeMain, params Type[] TypeDetail)
        {
            _DAL = new GZdalBaseBusiness(TypeMain, null, 0, TypeDetail);
        }

        /// <summary>
        /// 当前账号
        /// </summary>
        public override string Account
        {
            get { return Loginer.CurrentLoginer.Account; }
        }
        /// <summary>
        /// 当前数据库
        /// </summary>
        public override string DefultDBName
        {
            get { return Loginer.CurrentLoginer.LoginName; }
        }

    }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。