mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
2017-07-07 07:33
351 查看
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel; using System.Data.SqlClient; using System.Data; using HouseSys.Models; using System.Data.SqlClient; namespace HouseSys.DLL { /// <summary> /// 房屋的数据访问层 /// </summary> public class HouseDLL { /// <summary> /// 分页查询所有房屋信息 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public List<HouseModel> GetHousesAll(int pageIndex,int pageSize,ConditionModel cond) { List<HouseModel> houseList = new List<HouseModel>(); string sql = "select top "+pageSize+" * from house where HouseId not in (select top "+(pageIndex-1)*pageSize+" HouseId from House where 1=1) and 1=1 "; //动态查询 if(cond!=null) { //根据标题 if (cond.Title != null) { sql += " and Title like"+cond.Title; } //最低价格到最高价格 if (cond.StartPrice != null && cond.EndPrice != null) { sql += " and Price >=" + cond.StartPrice + " and Price <= " + cond.EndPrice; } //根据最低的面积 if(cond.StartProportion!=null && cond.EndProportion!=null) { sql += " and floorage >=" + cond.StartProportion + " and floorage<="+cond.EndProportion; } } using (SqlDataReader reader = SqlHelper.ExcuteReader(sql, CommandType.Text, null)) { while(reader.Read()) { HouseModel house = new HouseModel(); house.Contract = reader["Contract"].ToString(); house.Description = reader["Description"].ToString(); house.Floorage = Convert.ToDouble(reader["Floorage"]); house.HouseId = Convert.ToInt32(reader["houseid"]); house.Price = Convert.ToDouble(reader["Price"]); house.PublishTime = Convert.ToDateTime(reader["PublishTime"]); house.PublishUser = new UserDLL().GetUserById(Convert.ToInt32(reader["PublishUser"])); house.Street = new StreetDLL().GetStreetById(Convert.ToInt32(reader["streetid"])); house.Title = reader["title"].ToString(); house.Type = new HouseTypeDLL().GetHouseTypeById(Convert.ToInt32(reader["typeid"])); houseList.Add(house); } } return houseList; } /// <summary> /// 查询总记录数 /// </summary> /// <returns></returns> public int GetHouseCount() { string sql = "select count(1) from House"; int rel = Convert.ToInt32(SqlHelper.ExecuteScalar(sql,CommandType.Text,null)); return rel; } } }
相关文章推荐
- mvc.net分页查询案例——实体层(HouseModel.cs)
- mvc.net分页查询案例——业务逻辑层BLL(HouseBLL.cs)
- mvc.net分页查询案例——控制器(HomeController.cs)
- mvc.net分页查询案例——前台页面(Index.aspx)
- asp.net mvc + dwz 分页查询的详细使用方法
- asp.net mvc jqgrid 同一个页面查询不同的表,jqgrid显示不同表的表头和数据并且分页
- .Net Mvc Repository.cs 单表自连接 查询 [2]
- .NET+MVC+ORACLE存储分页查询一后端实现
- (easyui datagrid+mvc+json)之asp.net分页查询
- Asp.Net MVC EasyUI DataGrid查询分页
- ASP.NET MVC实现(查询+分页)
- 让Asp.net mvc WebAPI 支持OData协议进行分页查询操作
- .NET+MVC+ORACLE存储分页查询一前端实现
- Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
- (easyui datagrid+mvc+json)之asp.net分页查询
- 在ASP.NET MVC中使用Boostrap实现产品的展示、查询、排序、分页
- ASP.NET MVC 2入门演练 6 —— 分页查询数据
- ASP.NET MVC实践系列8-对查询后分页处理的解决方案
- ASP.NET MVC 入门2、项目的目录结构与核心的DLL
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第六篇:拦截器