日期:2014-05-18  浏览次数:20612 次

关于三层结构的问题,代码用动软.Net代码自动生成器生成.
关于三层结构的问题,代码用动软.Net代码自动生成器生成.
三个层分别是:model,bll,dal
现在有一个方法,是从页面中传进来一个model,我按model是来查询,代码如下,现在我是写在Bll中
(不知道是否适当,还是写成dal层,这是我要提问的问题)
  /// <summary>
  /// 获得数据列表
  /// </summary>
  public DataSet GetList(int PageSize, int PageIndex, Qzf.Model.Folder.SysUser model)
  {
  StringBuilder strWhere = new StringBuilder();
  strWhere.Append("1=1");
  //如果model.Name的值为空就不按Name来查询,下面各个字段一样.
  if (model.Name != string.Empty)
  {
  strWhere.Append( " and Name like '%" + model.Name + "%'");
  }
  if (model.Tel != string.Empty)
  {
  strWhere.Append(" and Tel like '%" + model.Tel + "%'");
  }
  if (model.Sex != string.Empty)
  {
  strWhere.Append(" and Sex like '%" + model.Sex + "%'");
  }
  if (model.Address != string.Empty)
  {
  strWhere.Append(" and Address like '%" + model.Address + "%'");
  }
  return dal.GetList(PageSize, PageIndex, strWhere.ToString());
  }

在这里我是应该这样写还是应该
这样写:
bll层:
  /// <summary>
  /// 获得数据列表
  /// </summary>
  public DataSet GetList(int PageSize, int PageIndex, Qzf.Model.Folder.SysUser model)
  {
  return dal.GetList(PageSize, PageIndex, model);
  }
dal层:
  /// <summary>
  /// 获得数据列表
  /// </summary>
  public DataSet GetList(int PageSize, int PageIndex, Qzf.Model.Folder.SysUser model)
  {
  StringBuilder strWhere = new StringBuilder();
  strWhere.Append("1=1");
  //如果model.Name的值为空就不按Name来查询,下面各个字段一样.
  if (model.Name != string.Empty)
  {
  strWhere.Append( " and Name like '%" + model.Name + "%'");
  }
  if (model.Tel != string.Empty)
  {
  strWhere.Append(" and Tel like '%" + model.Tel + "%'");
  }
  if (model.Sex != string.Empty)
  {
  strWhere.Append(" and Sex like '%" + model.Sex + "%'");
  }
  if (model.Address != string.Empty)
  {
  strWhere.Append(" and Address like '%" + model.Address + "%'");
  }
  return GetList(PageSize, PageIndex, strWhere.ToString());
  }

总之我的问题就是,把model的值换成SQL语句,是放在bll层,还是dal层
也就这几行代码:
StringBuilder strWhere = new StringBuilder();
  strWhere.Append("1=1");
  //如果model.Name的值为空就不按Name来查询,下面各个字段一样.
  if (model.Name != string.Empty)
  {
  strWhere.Append( " and Name like '%" + model.Name + "%'");
  }
  if (model.Tel != string.Empty)
  {
  strWhere.Append(" and Tel like '%" + model.Tel + "%'");
  }
  if (model.Sex != string.Empt