zoukankan      html  css  js  c++  java
  • 比较多层架构查询功能的泛型接口(IList)和普通(dataset)实现

     

     

    泛型接口

    普通

    表现层

            string strWhere = "1=1 order by ID desc";

            InfoMgr mgr = new InfoMgr(new InfoEntity());

            IList<ViewInfoEntity> result = mgr.GetViewInfoSelf(strWhere);

            SmartGridView1.DataSource = result;

            SmartGridView1.DataBind();

            BLL.TblNewsClassMgr classmgr = new BLL.TblNewsClassMgr();

            DataSet ds = classmgr.GetAll();

     

            GridView1.DataSource = ds.Tables[0].DefaultView;

            GridView1.DataBind();

    业务层

            public IList<ViewInfoEntity> GetViewInfoSelf(string strWhere)

            {

                ViewInfoService service = new ViewInfoService(new ViewInfoEntity());

                return service.SelectViewInfo(strWhere);

            }

            public DataSet GetAll()

            {

                return du.GetAll();

            }

    数据层

             /// <summary>

            /// 自定义检索

            /// </summary>

            /// <returns></returns>

            public IList<ViewInfoEntity> SelectViewInfo(string whereSqlString)

            {          

                IList<ViewInfoEntity> result=new List<ViewInfoEntity>();

                DAOBase dao = new ViewInfoDAO(entity);

                dao.WhereSQLString=whereSqlString;

                  DataSet ret=dao.Select();

                  if (ret != null)

                {

                    if (ret.Tables[0].Rows.Count > 0)

                    {

                        foreach(DataRow row in ret.Tables[0].Rows)

                        {

                            ViewInfoEntity _entity = new ViewInfoEntity();

                                if(row["ID"]!=null)

                                {

                                _entity.ID=int.Parse(row["ID"].ToString());

                                }

                                _entity.ValidDate=System.DateTime.Parse(row["ValidDate"].ToString());

                                }

                                }

                            result.Add(_entity);

                        }

                    }

                }

                return result;

            }

            public DataSet GetAll()

            {

                StringBuilder sql = new StringBuilder();

                sql.Append("select * from Users");

     

                return SQLHelper.GetList(sql.ToString(), "user");

            }

    公共数据层

            /// <summary>

            /// 检索全部

            /// </summary>

            /// <returns></returns>

            public DataSet Select()

            {

                DataSet result = null;

                try

                {

                    result = SelectData();

                }

                catch (HuaSi.ExceptionProcessor.CustomDAOException ex)

                {

                    bool rethrow = ExceptionPolicy.HandleException(ex, "DBOperatePolicy");

                    if (rethrow)

                    {

                        throw;

                    }

     

                }

                return result;

            }

            /// <summary>

            /// 执行一个T-SQL查询,返回DataSet对象

            /// </summary>

            /// <param name="query">查询的SQL语句</param>

            /// <param name="TableName">DataSet结果中的表名</param>

            /// <returns></returns>

            public static DataSet GetList(string query, string TableName)

            {

                InitConn();

                SqlDataAdapter sda = new SqlDataAdapter(query, conn);

                DataSet ds = new DataSet();

                sda.Fill(ds, TableName);

                CloseConn();

                return ds;

            }

     

            private DataSet SelectData()

            {

                DataSet result = null;

                IDataAccessState state = new SelectState(this.tableName, this);

                result = (DataSet)state.Execute();

                return result;

     

            }

     

  • 相关阅读:
    数据结构算法C语言实现(十五)---4.3 串的模式匹配算法
    数据结构算法C语言实现(十四)--- 4.1&4.2串的类型定义、表示及实现
    数据结构算法C语言实现(十三)--- 3.5离散事件模拟
    数据结构算法C语言实现(十二)--- 3.4循环队列&队列的顺序表示和实现
    数据结构算法C语言实现(十一)--- 3.4队列的链式表示和实现
    数据结构算法C语言实现(十)--- 3.3栈与递归的实现
    数据结构算法C语言实现(九)--- 拓展:由迷宫问题引申的AI贪吃蛇
    数据结构算法C语言实现(八)--- 3.2栈的应用举例:迷宫求解与表达式求值
    数据结构算法C语言实现(七)--- 3.1栈的线性实现及应用举例
    数据结构算法C语言实现(六)---2.4一元多项式的表示及相加
  • 原文地址:https://www.cnblogs.com/swarb/p/9924439.html
Copyright © 2011-2022 走看看