zoukankan      html  css  js  c++  java
  • 执行多个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);
                }
            }
    

      

  • 相关阅读:
    远程桌面无法复制粘贴
    软件无法启动,不提示具体错误
    从数据库统计出某张表中某个字段重复次数
    程序员何去何从
    SQL Server中TRUNCATE 和 DELETE的区别
    关于C#自定义控件注释说明
    C#的winform程序下如何实现文本编辑框(TextBox)的Hint提示文字效果
    ubuntu固定内网ip地址
    数据库的优化处理 Memory cached
    MYSQL管理之主从同步管理
  • 原文地址:https://www.cnblogs.com/jiao28/p/4012974.html
Copyright © 2011-2022 走看看