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;

     

            }

     

  • 相关阅读:
    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++4.2 failed with exit code 1
    Mark !
    delphi 与 C++ 进程之间的命名管道通信
    delphi 获取网页所有链接并访问赚取金币
    char类型转化为string类型 string(int n, char c)
    游戏接入支付宝遇到的一些问题
    mac下versions 提交提示 SVN Working Copy xxx locked
    上周项目遇到的问题
    使用elementPlus组件,分页功能[Pagination]时,字段:total="XXX"时,实际样式显示为 Total {total} 问题的解决办法
    Vue3+Module功能+指定Getter模块+获取不到资源
  • 原文地址:https://www.cnblogs.com/swarb/p/9924439.html
Copyright © 2011-2022 走看看