执行多个lanmada表达式查询

 /// <summary>
        /// 执行多个lanmada表达式查询
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="row">每页条数</param>
        /// <param name="page">当前页</param>
        /// <param name="total">数据条数</param>
        /// <param name="wherelambdas">lanbda表达式集合</param>
        /// <returns></returns>
        public List<T> SearchByKey<T>(int row,int page,ref int total,List<Func<T, bool>> wherelambdas) where T : class,new()
        {
            //获取所有的数据集合
            List<T> list = LoadEntitiesss<T>(s => true);
            List<T> listNew = new List<T>();
            foreach (Func<T,bool> item in wherelambdas)
            {
               list =  list.Where<T>(item).ToList();
            }

            total = list.Count;//获取总条数
            int start = row * (page - 1);//开始数据
            int end = row * page;//结束数据

            if (total > start)
            {
                end = total < end ? total : end;//判断结束 是否大于数据总条数
                for (int i = start; i < end; i++)
                {
                    listNew.Add(list[i]);
                }
            }

            return listNew;
        }

使用方法:

SearchByKey() 放在公共方法中   写方法的时候 直接继承

public class WLConfirmEnteringWarehouseOrderBLL : BaseBLL

{

........

}

 /// <summary>
        /// 绑定数据
        /// </summary>
        /// <returns></returns>
        public string GetWLConfirmEnteringWarehouseOrderList()
        {
            string action = ResponseHelper.GetRequestParam("action");
            string first = ResponseHelper.GetRequestParam("first");

            int page = ConvertHelper.ToInt(ResponseHelper.GetRequestParam("page"));
            int row = ConvertHelper.ToInt(ResponseHelper.GetRequestParam("rows"));
            int total = 0;
            if (first.ToLower() == "first")
            {
                return LoadPagerEntities<TPMPurchaseOrder, int>(row, page, s => false, "asc", s => s.purchaseId);
            }
            else
            {
                //客户通知单号
                string custNoticeCode = ResponseHelper.GetRequestParam("custNoticeCode1") == null ? "" : ResponseHelper.GetRequestParam("custNoticeCode1");
                //客户
                string custId = ResponseHelper.GetRequestParam("custId1") == null ? "" : ResponseHelper.GetRequestParam("custId1");
                //内部通知单号
                string innerNoticeCode = ResponseHelper.GetRequestParam("innerNoticeCode1") == null ? "" : ResponseHelper.GetRequestParam("innerNoticeCode1");
                //验收日期
                string checkDateStart = ResponseHelper.GetRequestParam("checkDateStart") == null ? "" : ResponseHelper.GetRequestParam("checkDateStart");
                string checkDateEnd = ResponseHelper.GetRequestParam("checkDateEnd") == null ? "" : ResponseHelper.GetRequestParam("checkDateEnd");
                //上架日期
                string goShelfDateStart = ResponseHelper.GetRequestParam("goShelfDateStart") == null ? "" : ResponseHelper.GetRequestParam("goShelfDateStart");
                string goShelfDateEnd = ResponseHelper.GetRequestParam("goShelfDateEnd") == null ? "" : ResponseHelper.GetRequestParam("goShelfDateEnd");
                //上架确认日期
                string requestConfirmDateStart = ResponseHelper.GetRequestParam("requestConfirmDateStart") == null ? "" : ResponseHelper.GetRequestParam("requestConfirmDateStart");
                string requestConfirmDateEnd = ResponseHelper.GetRequestParam("requestConfirmDateEnd") == null ? "" : ResponseHelper.GetRequestParam("requestConfirmDateEnd");
                //状态
                string status = ResponseHelper.GetRequestParam("status1") == null ? "" : ResponseHelper.GetRequestParam("status1");
                List<Func<TPMPurchaseOrder, bool>> funcList = new List<Func<TPMPurchaseOrder, bool>>();
                #region 条件1
                Func<TPMPurchaseOrder, bool> condition1 = s => true;
                if (custId != "")
                {
                    condition1 = s => s.custId == ConvertHelper.ToInt(custId);
                }
                #endregion
                #region 条件2
                Func<TPMPurchaseOrder, bool> condition2 = s => true;
                if (status == "7")
                {
                    condition2 = s => s.custNoticeCode.Contains(custNoticeCode) && s.innerNoticeCode.Contains(innerNoticeCode) && (s.status == "3" || s.status == "4" || s.status == "5" || s.status == "6");
                }
                else
                {
                    condition2 = s => s.custNoticeCode.Contains(custNoticeCode) && s.innerNoticeCode.Contains(innerNoticeCode) && s.status == status;
                }
                #endregion
                #region 条件3
                //验收日期
                Func<TPMPurchaseOrder, bool> condition3 = s => true;
                if (checkDateStart != "" && checkDateEnd != "")
                {
                    DateTime checkDateStartDate = ConvertHelper.ToDateTime(checkDateStart, "");
                    DateTime checkDateEndDate = ConvertHelper.ToDateTime(checkDateEnd, "");
                    condition3 = s => s.checkDate >= checkDateStartDate && s.checkDate <= checkDateEndDate;
                }
                else if (checkDateStart != "")
                {
                    DateTime checkDateStartDate = ConvertHelper.ToDateTime(checkDateStart, "");
                    condition3 = s => s.checkDate >= checkDateStartDate;
                }
                else if (checkDateEnd != "")
                {
                    DateTime checkDateEndDate = ConvertHelper.ToDateTime(checkDateEnd, "");
                    condition3 = s => s.checkDate <= checkDateEndDate;
                }
                #endregion
                #region 条件4
                Func<TPMPurchaseOrder, bool> condition4 = s => true;
                //上架日期
                if (goShelfDateStart != "" && goShelfDateEnd != "")
                {
                    DateTime goShelfDateStartDate = ConvertHelper.ToDateTime(goShelfDateStart, "");
                    DateTime goShelfDateEndDate = ConvertHelper.ToDateTime(goShelfDateEnd, "");
                    condition4 = s => s.goShelfDate >= goShelfDateStartDate && s.goShelfDate >= goShelfDateEndDate;
                }
                else if (goShelfDateStart != "")
                {
                    DateTime goShelfDateStartDate = ConvertHelper.ToDateTime(goShelfDateStart, "");
                    condition4 = s => s.goShelfDate >= goShelfDateStartDate;
                }
                else if (goShelfDateEnd != "")
                {
                    DateTime goShelfDateEndDate = ConvertHelper.ToDateTime(goShelfDateEnd, "");
                    condition4 = s => s.goShelfDate <= goShelfDateEndDate;
                }
                #endregion
                #region 条件5
                Func<TPMPurchaseOrder, bool> condition5 = s => true;
                //上架确认日期
                if (requestConfirmDateStart != "" && requestConfirmDateEnd != "")
                {
                    DateTime requestConfirmDateStartDate = ConvertHelper.ToDateTime(requestConfirmDateStart, "");
                    DateTime requestConfirmDateEndDate = ConvertHelper.ToDateTime(requestConfirmDateEnd, "");
                    condition5 = s => s.requestGoShelfDate >= requestConfirmDateStartDate && s.requestGoShelfDate <= requestConfirmDateEndDate;
                }
                else if (requestConfirmDateStart != "")
                {
                    DateTime requestConfirmDateStartDate = ConvertHelper.ToDateTime(requestConfirmDateStart, "");
                    condition5 = s => s.requestGoShelfDate >= requestConfirmDateStartDate;
                }
                else if (requestConfirmDateEnd != "")
                {
                    DateTime requestConfirmDateEndDate = ConvertHelper.ToDateTime(requestConfirmDateEnd, "");
                    condition5 = s => s.requestGoShelfDate <= requestConfirmDateEndDate;
                }
                #endregion
                funcList.Add(condition1);
                funcList.Add(condition2);
                funcList.Add(condition3);
                funcList.Add(condition4);
                funcList.Add(condition5);
                List<TPMPurchaseOrder> tPMPurchaseOrderList = SearchByKey<TPMPurchaseOrder>(row, page, ref total, funcList);
                string r = JsonHelper.JsonSerialize(tPMPurchaseOrderList);
                return ResponseHelper.ResponseJson(total.ToString(), r);
            }
        }

  

时间: 2024-08-29 22:06:41

执行多个lanmada表达式查询的相关文章

CRL快速开发框架系列教程二(基于Lambda表达式查询)

本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框架系列教程四(删除数据) CRL快速开发框架系列教程五(使用缓存) CRL快速开发框架系列教程六(分布式缓存解决方案) CRL快速开发框架系列教程七(使用事务) CRL快速开发框架系列教程八(使用CRL.Package) CRL快速开发框架系列教程九(导入/导出数据) CRL快速开发框架系列教程十(

thinkphp的普通查询与表达式查询

一.普通查询方式 a.字符串:$arr=$m->where("sex=0 and username='gege'")->find();//字符串需要加引号 b.数组 $data['sex']=0; $data['username']='gege'; $arr=$m->where($data)->find();//传上一个数组进行查询,这种方式默认是and(并且)的关系 注意:如果使用or关系,需要添加数组值 $data['sex']=0; $data['user

thinkphp 表达式查询

上面的查询条件仅仅是一个简单的相等判断,可以使用查询表达式支持更多的SQL查询语法,也是ThinkPHP查询语言的精髓,查询表达式的使用格式: $map['字段名'] = array('表达式','查询条件'); 大理石平台规格 表达式不分大小写,支持的查询表达式有下面几种,分别表示的含义是: 表达式 含义 协助记忆 EQ 等于(=) equal NEQ 不等于(<>) not equal GT 大于(>) greater EGT 大于等于(>=) equal or greater

select语句执行的顺序,子查询和联合查询【这三点都是重点】

select (字段或表达式) (from 资源) where 1(用来先处理筛选后加条件) (AND条件附加)(group by)(order by)(limit); 1.group by分组[分组的作用在于分组统计上使用分组,每组正常只显示一条信息][基本都是用在分组统计方面,配合聚合函数进行处理] [这个重点] group_concat(函数):会将组内的元素进行拼接显示[这个能够显示分组后的组内的显示效果] 多字段分组[group by+多个字段并列即可] [分组字段的使用主要还是在统计

rPyc 模块应用:在远端上执行命令,并且获取查询结果

背景:最近项目里将自动化框架进行整改,中间就涉及到了自动化代理这块,原有的自动化代理服务端是用C++编写的,经常出现运行在system会话下,导致代理无法执行远程过来的命令,在百度上搜了下,发现Python有rPyc模块,于是拿来试了下看看是否满足要求.一用才发现rPyc真的是很强大,几行代码轻松搞定,所以在这里与大家一起分享下,也欢迎大家提建议和更好的方法. 目的:远端的执行机A上,能使用命令,在B机上查询相应的信息 上代码: 客户端代码: 1 # -*- coding:utf-8 -*- 2

@Scheduled执行定时任务与cron表达式

1 配置文件形式执行定时任务 1 1.X 版本与spring结合使用实例 1.1 常用maven管理 pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://

solr 通过【配置、多值字段、动态字段】来解决文本表达式查询精确到句子的问题20171214

一.Solr Multivalue field属性positionIncrementGap理解 分类:Lucene 2014-01-22 10:39阅读(3596)评论(0) 参考:http://rockiee281.blog.163.com/blog/static/19385222920127225619919/ Solr里头可以设计Field为Multivalue类型,这样的一个好处是可以很方便的设置copyField,在我们的项目中也有使用. 但是一直以来都有一个问题困扰着我,就是对mul

正确使用索引(sql优化),limit分页优化,执行计划,慢日志查询

查看表相关命令 - 查看表结构   desc 表名- 查看生成表的SQL   show create table 表名- 查看索引   show index from  表名 使用索引和不使用索引 由于索引是专门用于加速搜索而生,所以加上索引之后,查询效率会快到飞起来. # 有索引 mysql> select * from tb1 where name = 'zhangqiye'; +-----+-------------+---------------------+--------------

MySQL---正确使用索引、limit分页、执行计划、慢日志查询

正确使用索引 数据库表中添加索引后确实会让查询速度起飞,但前提必须是正确的使用索引来查询,如果以错误的方式使用,则即使建立索引也会不奏效.即使建立索引,索引也不会生效: 1 - like '%xx' 2 select * from tb1 where name like '%cn'; 3 - 使用函数 4 select * from tb1 where reverse(name) = 'wupeiqi'; 5 - or 6 select * from tb1 where nid = 1 or e