| | |
| | | } |
| | | } |
| | | |
| | | protected string ValidatePageOptions(PageDataOptions options) |
| | | { |
| | | options = options ?? new PageDataOptions(); |
| | | string where = ""; |
| | | List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | if (options.Filter != null && options.Filter.Count > 0) |
| | | { |
| | | searchParametersList.AddRange(options.Filter); |
| | | } |
| | | else if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | try |
| | | { |
| | | searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | options.Filter = searchParametersList; |
| | | } |
| | | catch { } |
| | | } |
| | | QueryRelativeList?.Invoke(searchParametersList); |
| | | |
| | | for (int i = 0; i < searchParametersList.Count; i++) |
| | | { |
| | | if (string.IsNullOrEmpty(searchParametersList[i].Value)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault(); |
| | | |
| | | if (property == null) continue; |
| | | |
| | | (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value); |
| | | if (!result.Item1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | if (expressionType == LinqExpressionType.Equal) |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | { |
| | | // 閽堝瀛楃涓茬被鍨嬬殑瀛楁浣跨敤妯$硦鏌ヨ |
| | | //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $"[{searchParametersList[i].Name}] like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 閽堝甯冨皵绫诲瀷瀛楁杩涜绮剧‘鏌ヨ |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $" and [{searchParametersList[i].Name}] like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (searchParametersList[i].DisplayType.GetLinqCondition() == LinqExpressionType.ThanOrEqual) |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | where += $"{searchParametersList[i].Name} >= '{searchParametersList[i].Value}'"; |
| | | else |
| | | where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType.GetLinqCondition()} '{searchParametersList[i].Value}'"; |
| | | } |
| | | else if (searchParametersList[i].DisplayType.GetLinqCondition() == LinqExpressionType.LessThanOrEqual) |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | where += $"{searchParametersList[i].Name} <= '{searchParametersList[i].Value}'"; |
| | | else |
| | | where += $" and {searchParametersList[i].Name} <= '{searchParametersList[i].Value}'"; |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | else |
| | | where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | } |
| | | } |
| | | } |
| | | return where; |
| | | } |
| | | |
| | | protected Expression<Func<TEntity, bool>> GetWhereExpression(string propertyName, object propertyValue, ParameterExpression parameter, LinqExpressionType expressionType) |
| | | { |
| | | Type? proType = typeof(TEntity).GetProperty(propertyName)?.PropertyType; |