VOL框架 GetPageData 前端加入自定义查询条件的处理方法
前端加入两个自定义条件:开始日期,结束日期
public override PageGridData<ST_QueryFeeReceiveable> GetPageData(PageDataOptions options) { QuerySql = $@"SELECT FeeReceivableID, R.FeeID, C.CustomerID FROM ST_FeeReceivable R left join ST_CodeMeter M on R.MeterId=M.MeterID where 1=1 "; string companycode = UserContext.Current.UserInfo.CompanyCode; if (companycode != "00") { QuerySql += $" and C.CompanyCode='{UserContext.Current.UserInfo.CompanyCode}'"; } //获取所有查询条件 List<SearchParameters> list = options.Wheres.DeserializeObject<List<SearchParameters>>(); if (list.Count>0) { //将自定义查询条件,加入到 QuerySql 中 foreach (SearchParameters item in list) { if (item.Name == "StartDate") { if (!string.IsNullOrEmpty(item.Value)) { QuerySql += $" and R.MeterMonth>='{item.Value}'"; } } if (item.Name == "EndDate") { if (!string.IsNullOrEmpty(item.Value)) { QuerySql += $" and R.MeterMonth<='{item.Value}'"; } } } } //调用 base.GetPageData 之前,排除掉自定义查询条件 var xx = list.Where(a => a.Name != "StartDate").Where(a => a.Name != "EndDate"); options.Wheres = JsonConvert.SerializeObject(xx); return base.GetPageData(options); }
标签:Name,自定义,VOL,GetPageData,QuerySql,item,options From: https://www.cnblogs.com/wishit/p/18104997