首页 > 数据库 >C# Sqlserver 分页查询-微商城

C# Sqlserver 分页查询-微商城

时间:2022-10-31 18:00:36浏览次数:43  
标签:string QueryPageEntity C# Sqlserver IsNull null response 商城 sqlPage2Where

  C# Sqlserver 分页查询-微商城

#region----分页查询订单流水状态----
        /// <summary>
        /// 分页查询订单流水状态
        /// </summary>
        /// <param name="context"></param>
        public void DoQueryStoredCardRechargeFlow(HttpContext context)
        {
            //商家BID
            int bID = obAdmin.BID;

            int pageSize;//每页大小
            int pageNumber;//当前页是第几页,索引0就是第一页,索引1就是第二页
            string pageSizeStr = context.Request["PageSize"];
            string pageNumberStr = context.Request["PageNumber"];
            if (RegExpHelper.IsNull(pageSizeStr) || !RegExpHelper.IsNumber(pageSizeStr))
            {
                pageSize = 10;
            }
            if (RegExpHelper.IsNull(pageNumberStr) || !RegExpHelper.IsNumber(pageNumberStr))
            {
                pageNumber = 0;
            }
            pageSize = Convert.ToInt32(pageSizeStr);
            pageNumber = Convert.ToInt32(pageNumberStr);

            //会员卡号
            string cardID = context.Request["CardID"];
            if (RegExpHelper.IsNull(cardID))
            {
                cardID = null;
            }

            //订单号
            string tradeID = context.Request["TradeID"];
            if (RegExpHelper.IsNull(tradeID))
            {
                tradeID = null;
            }

            //下单时间
            DateTime? fromTime;
            DateTime? toTime;
            string fromTimeStr = context.Request["FromTime"];
            string toTimeStr = context.Request["ToTime"];
            if (RegExpHelper.IsNull(fromTimeStr))
            {
                fromTime = null;
            }
            else
            {
                fromTime = Convert.ToDateTime(fromTimeStr);
            }
            if (RegExpHelper.IsNull(toTimeStr))
            {
                toTime = null;
            }
            else
            {
                toTime = Convert.ToDateTime(toTimeStr);
            }

            //微信交易号
            string outerID = context.Request["OuterID"];
            if (RegExpHelper.IsNull(outerID))
            {
                outerID = null;
            }

            //微信昵称
            string nickName = context.Request["NickName"];
            if (RegExpHelper.IsNull(nickName))
            {
                nickName = null;
            }

            //订支付状态
            string statusStr = context.Request["Status"];//订单支付状态,0待支付,1已支付,2已完成,3所有关闭的交易    
            int? status;
            if (RegExpHelper.IsNull(statusStr))
            {
                status = null;
            }
            else
            {
                status = Convert.ToInt32(statusStr);
            }

            //decOpenID,2018-01-18统计新增
            string decOPenID = context.Request["OpenID"];
            if (RegExpHelper.IsNull(decOPenID))
            {
                decOPenID = null;
            }

            DoQueryStoredCardRechargeFlow queryStoredCardEntity = new Entity.MembershipCard.DoQueryStoredCardRechargeFlow()
            {
                PageSize = pageSize,
                PageNumber = pageNumber,
                Status = status,
                CardID = cardID,
                TradeID = tradeID,
                FromTime = fromTime,
                ToTime = toTime,
                OuterID = outerID,
                NickName = nickName,
                BID = bID,
                decOpenID = decOPenID
            };
            var response = _valueCardSaveTradeLogServices.QueryPageIsDealWithByIndexAndSize(queryStoredCardEntity);
            if (response.Status == BaseResponseStatusEnum.Error)
            {
                BaseJsonResult.PrintJson("-1", response.Msg);
                return;
            }
            else if (response.Status == BaseResponseStatusEnum.Default)
            {
                BaseJsonResult.PrintJson("0", response.Msg);
                return;
            }
            BaseJsonResult.PrintJson("1", response.PageCount, response.Total, JsonConvert.SerializeObject(response.Result));
            return;
        }
        #endregion

 

#region  ----后台,分页查询后台数据,根据当前页和每页大小,分页查询订单处理状态和支付状态----
        /// <summary>
        /// 后台,根据当前页和每页大小,分页查询订单处理状态和支付状态。
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public BasePageResponse<ValueCardSaveTradeLogWxUsers> QueryPageIsDealWithByIndexAndSize(DoQueryStoredCardRechargeFlow QueryPageEntity)
        {
            BasePageResponse<ValueCardSaveTradeLogWxUsers> response = new BasePageResponse<ValueCardSaveTradeLogWxUsers>();
            string currentMethodLog = "[QueryPageIsDealWithByIndexAndSize()]分页查询储值订单,";
            try
            {
                string sqlPage2Where = string.Empty;

                //支付状态
                int? status = QueryPageEntity.Status;
                //0待支付,1已支付代充值,2已完成 , 其他数字是全部状态
                if (status == (int)StoredCardTradeLogStatus.NotPay)
                {
                    sqlPage2Where += " and status like '%" + StoredCardTradeLogStatus.NotPay.ToString() + "%'";//还没支付
                }
                else if (status == (int)StoredCardTradeLogStatus.HadPayNotInsert)
                {
                    sqlPage2Where += " and status like '%" + StoredCardTradeLogStatus.HadPayNotInsert.ToString() + "%'";//已经支付但是没有充值进去数据库
                }
                else if (status == (int)StoredCardTradeLogStatus.FinishPay)
                {
                    sqlPage2Where += " and status like '%" + StoredCardTradeLogStatus.FinishPay.ToString() + "%'";//已经完成支付
                }
                else
                {
                    sqlPage2Where += " ";
                }

                //会员卡号              
                if (!RegExp.IsNull(QueryPageEntity.CardID))
                {
                    sqlPage2Where += " and VCSTL.CardID like '%' + @CardID + '%'";
                }

                //订单号
                if (!RegExp.IsNull(QueryPageEntity.TradeID))
                {
                    sqlPage2Where += " and TradeId like '%' + @TradeID + '%'";
                }

                //下单时间段
                DateTime? fromTime = QueryPageEntity.FromTime;//开始时间
                DateTime? toTime = QueryPageEntity.ToTime;//结束时间               
                if (fromTime == null && toTime == null)
                {
                    sqlPage2Where += "";
                }
                else if (fromTime != null && toTime == null)
                {
                    sqlPage2Where += " and CreateDate between  @FromTime  and '5000-01-01'";
                }
                else if (fromTime == null && toTime != null)
                {
                    //因为默认时间2017-09-05 00:00:00:000后面的时钟数是0,所以加上一天,让当日的时间都匹配。
                    //前端细分到“日”才会写这个,如果时间细分到“时分”这里就不用了加1天了
                    //(QueryPageEntity.ToTime) = Convert.ToDateTime(ToTime).AddDays(1);
                    sqlPage2Where += " and CreateDate between '1800-01-01' and @ToTime ";
                }
                else
                {
                    //因为默认时间2017-09-05 00:00:00:000后面的时钟数是0,所以加上一天,让当日的时间都匹配。
                    //前端细分到“日”才会写这个,如果时间细分到“时分”这里就不用了加1天了
                    //(QueryPageEntity.ToTime) = Convert.ToDateTime(ToTime).AddDays(1);
                    sqlPage2Where += " and CreateDate between  @FromTime   and  @ToTime ";
                }

                //微信交易号            
                if (!RegExp.IsNull(QueryPageEntity.OuterID))
                {
                    sqlPage2Where += " and OuterID like '%' + @OuterID + '%'";
                }

                //微信昵称        
                if (!RegExp.IsNull(QueryPageEntity.NickName))
                {
                    sqlPage2Where += " and VCSTL.OpenID in (select OpenID from wxUsers where NickName like '%'+ @NickName+ '%')";
                }

                //解密OpenID         
                if (!RegExp.IsNull(QueryPageEntity.decOpenID))
                {
                    sqlPage2Where += " and VCSTL.OpenID=@decOpenID ";
                }

                StringBuilder sbSql = new StringBuilder();

                var sqlPage1 = @"
                    select * from ( ";
                //sqlPage2的作用是:可以查询总行数
                var sqlPage2 = @" select Row_number() over(order by  VCSTL.CreateDate desc ) as rownum,
                                VCSTL.* ,
                                WU.NickName,WU.PicUrl,WU.RealName 
                                from ValueCardSaveTradeLog as VCSTL 
                                left join  WxUsers as WU 
                                on VCSTL.CardID=WU.CardID and VCSTL.BID=WU.BID 
                                where VCSTL.TradeID=VCSTL.TradeID  and VCSTL.BID=convert(varchar,@BID) 
                            " + sqlPage2Where;

                //------------中间位置插入条件语句
                var sqlPage3 = @" ) as t1 where t1.rownum>=(@PageNumber)*@PageSize+1 and t1.rownum<=((@PageNumber+1)*@PageSize)
                      ";
                sbSql.Append(sqlPage1);
                sbSql.Append(sqlPage2);
                sbSql.Append(sqlPage3);

                //执行查询
                List<ValueCardSaveTradeLogWxUsers> valueCardSaveTradeLogList =
                    _dbBase.Query<ValueCardSaveTradeLogWxUsers>(sbSql.ToString(), QueryPageEntity).ToList();
                //查询出结果后继续查行数
                if (valueCardSaveTradeLogList != null && valueCardSaveTradeLogList.Count > 0)
                {                   
                    response.Result = valueCardSaveTradeLogList;
                    //总行数 recordCount
                    string recordCountSql = "select count(1) from  (" + sqlPage2 + ") as A";
                    int recordCount = _dbBase.Query<int>(recordCountSql, QueryPageEntity).FirstOrDefault();
                    //总页数(pageCount)  = 总行数 / PageSize
                    decimal pageCountDecimal = Math.Ceiling((decimal)recordCount / (decimal)QueryPageEntity.PageSize);
                    int pageCount = Convert.ToInt32(pageCountDecimal);

                    response.Total = recordCount;//总行数
                    response.PageCount = pageCount;//总页数

                    response.Status = BaseResponseStatusEnum.Success;
                    response.Msg = "查询成功";
                    return response;
                }
                else
                {
                    response.Status = BaseResponseStatusEnum.Default;
                    response.Msg = "查询数据为0";
                    return response;
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Log(LogTypeEnum.ServicesLog, LogLevelEnum.Error,
                    currentMethodLog + "查询报错", ex);
                response.Status = BaseResponseStatusEnum.Error;
                response.Msg = currentMethodLog + "查询报错";
                return response;
            }
        }
        #endregion

 

搜索

复制

标签:string,QueryPageEntity,C#,Sqlserver,IsNull,null,response,商城,sqlPage2Where
From: https://www.cnblogs.com/jankie1122/p/11118600.html

相关文章

  • errorcode: 200 uid: -1 appid -1 msg: APP不存在
    Android手机调用百度地图SDK,报错:​​errorcode:200uid:-1appid-1msg:APP不存在​​出现该问题,不是SHA1和包什么的问题。请检查AndroidManifest.xml中的key的值,多半......
  • React进阶篇——十三、注意事项
    十三、注意事项为了在开发和调试阶段更好的区别包装了不同组件的高阶组件,需要对高阶组件的显示名称做自定义处理。常用的处理方法是,把被包装组件的显示名称也包到高阶组......
  • Flask学习笔记(十七)-Memcached的基本使用
    一、Flask中使用Memcachedpipinstall-ihttps://pypi.tuna.tsinghua.edu.cn/simple--trusted-hostpypi.tuna.tsinghua.edu.cnpython-memcached安装成功以后,就可以在......
  • sqlserver 游标
     sqlserver游标declare@BIDInt,@GiveToUserIDint,@NickNamenvarchar(100),@StartTimedatetime,@EndTimedatetime,@PageNumberint,@PageSizeintset@BI......
  • sqlserver执行语句返回刚刚插入的ID
     sqlserver执行语句返回刚刚插入的ID #region----新增一条活动表数据----///<summary>///新增一条活动表数据///</summary>/......
  • Jenkins Blue Ocean
    介绍BlueOcean是pipeline的可视化UI。同时兼容经典的自由模式的job。JenkinsPipeline从头开始设计,但仍与自由式作业兼容,BlueOcean减少了经典模式下的混乱并为团......
  • AI人脸检测识别EasyCVR视频融合平台告警预案的配置操作与使用
    我们在前期的文章中为大家介绍了EasyCVR新增的告警预案功能,感兴趣的用户可以戳这篇文章:《AI人脸检测智能视频融合平台EasyCVR新增告警预案功能》。  告警预案可以根......
  • sqlserver 分区函数去重复排序
     sqlserver分区函数去重复排序--获取,FlowID去重复的,按时间排序的,前一行select*from(select*,row_number()over(partitionbyFlowIDorderbyConfirmDat......
  • not present in DVTPlugInCompatibilityUUIDs
    2022-10-3117:24:38.827xcodebuild[43498:351656][MT]PluginLoading:Requiredplug-incompatibilityUUID57505DC8-7C02-42C5-9C44-13FD1CB92B41forplug......
  • Centos7虚拟机,共享主机文件夹挂载,运行go中带c的程序
    md由于不会用java去转c写的加密,就必须用公司原来的加密方法,原来的是c写的,然后跟go结合着用,问题就是在windows上装了c的环境还是不能跑加密的,所以只能先试试用Linux的系统能......