您的位置:首页 > 运维架构 > 网站架构

比较多层架构查询功能的泛型接口(IList)和普通(dataset)实现

2012-03-09 11:36 447 查看
泛型接口
普通
表现层
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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐