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;

     

            }

     

  • 相关阅读:
    MD5 带salt 加密
    生成包含数字和大小写字母的随机码
    多读好代码助于提高
    Winform程序窗体间的跳转
    Sql Server 存储过程
    GDI+的学习
    管理人生的8个危机
    马云语录
    无边框窗体的拖动和拉伸
    安装oracle时遇到 环境变量path的值超过1023字符,无法设置该值
  • 原文地址:https://www.cnblogs.com/swarb/p/9924439.html
Copyright © 2011-2022 走看看