|
泛型接口 |
普通 |
表现层 |
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;
} |
|