[C#]分享一个以前的项目使用的DataBaseAccess类

最近在整理以前的资料时,看到了以前我们在项目中经常用的一个数据库访问类,虽然现在已经可以用代码生成工具生成比较完整的数据库访问类,但是这个类在我们以前的项目中久经考验,所以我觉得还是比较好用,废话不多说了,上代码:

//======================================================================
//
//        filename : DataBaseAccess.cs
//
//        description:  1. data base access operation class DataBaseAccess.
//                      2. data base access operation help class SQLHelper.
//
//      
//
//======================================================================

using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;

namespace DAL
{
    #region Database Access
    /// <summary>
    /// DataBase Operate Class DataBaseAccess
    /// </summary>
    public class DataBaseAccess
    {


        /// <summary>
        /// DataBase Connection
        /// </summary>
        private SqlConnection conn = new SqlConnection(SQLHelper.StrConn);
        /// <summary>
        /// DataBase Connection
        /// </summary>
        public SqlConnection Conn
        {
            get
            {
                return conn;
            }
        }
        /// <summary>
        /// Construct
        /// </summary>
        public DataBaseAccess()
        {

}

/// <summary>
        /// Destruct
        /// </summary>
        ~DataBaseAccess()
        {
            CloseDB();
        }

#region "***** Debug Configuration *****"       
        /// <summary>
        ///Judge whether the state is Debug
        /// </summary>
        /// <returns>if the state is Debug return true,else false</returns>
        private bool JudgeDebug()
        {
            bool bIsDebug = false;

#if DEBUG

string strIsDebug = ConfigurationManager.AppSettings["IsDebug"];
            bIsDebug = ((bIsDebug || (strIsDebug != null && strIsDebug.Equals("true"))) ? true : false);

#endif

return bIsDebug;
        }       

/// <summary>
        /// Output the Debug Information
        /// </summary>
        /// <param>Debug Information</param>
        private void debug(object objDebugInfo)
        {
            #if DEBUG
            //if open debug,output the debug information into the file(the Directory in which Current programe run and the file name is DebugInfo\[日期].ini)
            if (JudgeDebug())
            {
                string strPath = System.Environment.CurrentDirectory + "\\DebugInfo\\";
                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjwyj.html