mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)

简介: mvc.net分页查询案例——DLL数据访问层(HouseDLL.cs)
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;
        }
    }
}


相关文章
|
4月前
|
前端开发 Java 数据库
springBoot:template engine&自定义一个mvc&后端给前端传数据&增删改查 (三)
本文介绍了如何自定义一个 MVC 框架,包括后端向前端传递数据、前后端代理配置、实现增删改查功能以及分页查询。详细展示了代码示例,从配置文件到控制器、服务层和数据访问层的实现,帮助开发者快速理解和应用。
|
4月前
|
前端开发 Java
【案例+源码】详解MVC框架模式及其应用
【案例+源码】详解MVC框架模式及其应用
262 0
|
4月前
|
数据采集
爬虫案例—爬取ChinaUnix.net论坛板块标题
爬虫案例—爬取ChinaUnix.net论坛板块标题
72 0
爬虫案例—爬取ChinaUnix.net论坛板块标题
|
6月前
|
JSON 前端开发 Java
Spring MVC返回JSON数据
综上所述,Spring MVC提供了灵活、强大的方式来支持返回JSON数据,从直接使用 `@ResponseBody`及 `@RestController`注解,到通过配置消息转换器和异常处理器,开发人员可以根据具体需求选择合适的实现方式。
213 4
|
7月前
|
开发框架 JSON 前端开发
利用查询条件对象,在Asp.net Web API中实现对业务数据的分页查询处理
利用查询条件对象,在Asp.net Web API中实现对业务数据的分页查询处理
|
7月前
|
前端开发 Java Spring
Spring MVC中使用ModelAndView传递数据
Spring MVC中使用ModelAndView传递数据
|
8月前
|
前端开发
Spring-MVC的数据响应-19
Spring-MVC的数据响应-19
|
8月前
|
JSON 前端开发 Java
Springboot mvc开发之Rest风格及RESTful简化开发案例
Springboot mvc开发之Rest风格及RESTful简化开发案例
104 2
|
8月前
|
安全 前端开发 测试技术
安全开发-PHP应用&模版引用&Smarty渲染&MVC模型&数据联动&RCE安全&TP框架&路由访问&对象操作&内置过滤绕过&核心漏洞
安全开发-PHP应用&模版引用&Smarty渲染&MVC模型&数据联动&RCE安全&TP框架&路由访问&对象操作&内置过滤绕过&核心漏洞
|
9月前
|
开发框架 前端开发 JavaScript
采用C#.Net +JavaScript 开发的云LIS系统源码 二级医院应用案例有演示
技术架构:Asp.NET CORE 3.1 MVC + SQLserver + Redis等 开发语言:C# 6.0、JavaScript 前端框架:JQuery、EasyUI、Bootstrap 后端框架:MVC、SQLSugar等 数 据 库:SQLserver 2012
86 0

热门文章

最新文章