针对于李天平代码生成器的数据访问层查询的改进

对于代码生成器,复杂的查询在数据访问层和事务没有提供方法,所以针对于实际项目应用,我自己在李天平的框架上拓展了新的数据访问接口。

IDAL的接口如下

 

      IBaseDataHelper

 

/// <summary>

    /// 公用数据接口主要用于查询,事务等复杂的数据操作

    /// </summary>

    public interface IBaseDataHelper

    {

        /// <summary>

        /// 通过SQL语句返回DataSet

        /// </summary>

        /// <param name="strSql">传入的SQL语句</param>

        /// <returns></returns>

        DataSet BaseQuery(string strSql);

        /// <summary>

        /// SQL语句执行

        /// </summary>

        /// <param name="strSql">传入的SQL语句</param>

        /// <returns>影响的行数</returns>

        int ExecuteSql(string strSql);

       /// <summary>

       /// 执行事务

       /// </summary>

       /// <param name="SQLStringList">传入的SQL语句数组</param>

       /// <returns>是否成功</returns>

        bool ExecuteSqlTran(ArrayList SQLStringList);

        /// <summary>

        /// 执行事务

        /// </summary>

        /// <param name="SQLStringList">传入的SQL语句HashTable</param>

        /// <returns>是否成功</returns>

        bool ExecuteSqlTran(Hashtable SQLStringList);

        /// <summary>

        /// 通过SQL语句得到单个数据

        /// </summary>

        /// <param name="strSql">传入的SQL语句</param>

        /// <returns>数据对象</returns>

        object GetSingle(string strSql);

    }

OracelDAL实现代码如下:

 

 public class BaseDataHelper : IBaseDataHelper
    {

 

        #region IBaseDataHelper 成员

        public System.Data.DataSet BaseQuery(string strSql)
        {
            try
            {
                return DbHelperOra.Query(strSql);
            }
            catch(System.Data.OracleClient.OracleException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        #endregion

        #region IBaseDataHelper 成员


        public int ExecuteSql(string strSql)
        {
            try
            {
                return DbHelperOra.ExecuteSql(strSql);
            }
            catch (System.Data.OracleClient.OracleException ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public bool ExecuteSqlTran(ArrayList SQLStringList)
        {
            try
            {
                DbHelperOra.ExecuteSqlTran(SQLStringList);
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
            return true;
        }

        public bool ExecuteSqlTran(Hashtable SQLStringList)
        {
            try
            {
                DbHelperOra.ExecuteSqlTran(SQLStringList);
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
            return true;
        }
        #endregion

        #region IBaseDataHelper 成员


        public object GetSingle(string strSql)
        {
            try
            {
                return DbHelperOra.GetSingle(strSql);
            }
            catch (System.Data.OracleClient.OracleException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        #endregion
    }

 

你可能感兴趣的:(代码生成)