public override WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null) { Expression member = Expression.Property(parent, param.WSColumnRef.NAME); WSCombineFilter filter = new WSCombineFilter(); if (param != null && param.isValid) { try { if (WSConstants.ALIACES.EXIST.Match(Value) || WSConstants.ALIACES.EMPTY.Match(Value) || WSConstants.ALIACES.IS_OWN.Match(Value)) { state = Value; } #region Read WSEntity (Ready) if (!string.IsNullOrEmpty(state) && (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)) || param.DataType.IsCollectionOf <WSEntity>())) { if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)) && WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(state))) { filter.Save(new WSEntityFFilter(param, member, WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(state))) { Value = null }); } else if (param.DataType.IsCollectionOf <WSEntity>() && WSEntityListFFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(state))) { filter.Save(new WSEntityListFFilter(param, member, WSEntityListFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(state))) { Value = null }); } } #endregion #region Read primitive else { dynamic dVal = null; #region Numeric (Ready) if (param.DataType.IsNumeric()) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSNumericFFilter(param, member, WSNumericFFilter.OPERATIONS.NotEqual) { Value = null }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSNumericFFilter(param, member, null) { Value = null }); } #endregion #endregion #region If Value (Ready) else { if (param.DataType.Read(Value, out dVal)) { Type dType = dVal == null ? param.DataType : dVal.GetType(); WSOperation operation = WSNumericFFilter.OPERATIONS.GetOperation(state); if (operation.Match("max") && dType.IsCollection()) { dVal = ((List <dynamic>)dVal).Max(x => x); } else if (operation.Match("min") && dType.IsCollection()) { dVal = ((List <dynamic>)dVal).Min(x => x); } filter.Save(new WSNumericFFilter(param, member, operation) { Value = dVal }); } } #endregion } #endregion #region bool (Ready) else if (typeof(bool?).IsAssignableFrom(param.DataType)) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSBoolFFilter(param, member, WSBoolFFilter.OPERATIONS.NotEqual) { Value = null }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSBoolFFilter(param, member, null) { Value = null }); } #endregion #endregion #region If Value (Ready) else { if (param.DataType.Read(Value, out dVal)) { filter.Save(new WSBoolFFilter(param, member, WSBoolFFilter.OPERATIONS.GetOperation(state)) { Value = dVal }); } } #endregion } #endregion #region string (Ready) else if (typeof(string).IsAssignableFrom(param.DataType)) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value)) { if (param.DataType.IsNullable()) { filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.NotEqual) { Value = null }); } filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.NotEqual) { Value = string.Empty }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value)) { WSCombineFilter cFilter = new WSCombineFilter(WSCombineFilter.SQLMode.Or);; if (param.DataType.IsNullable()) { cFilter.Save(new WSStringFFilter(param, member, null) { Value = null }); } cFilter.Save(new WSStringFFilter(param, member, null) { Value = string.Empty }); filter.Save(cFilter); } #endregion #endregion #region If Value (Ready) else if (param.DataType.IsNullable() || !string.IsNullOrEmpty(Value)) { if (param.DataType.Read(Value, out dVal)) { filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.GetOperation(state)) { Value = dVal }); } } #endregion } #endregion #region Guid (Ready) else if (typeof(Guid?).IsAssignableFrom(param.DataType)) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSGuidFFilter(param, member, WSGuidFFilter.OPERATIONS.NotEqual) { Value = null }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSGuidFFilter(param, member, null) { Value = null }); } #endregion #endregion #region If Value (Ready) else { if (param.DataType.Read(Value, out dVal, null, WSConstants.GUID_LIST_SEPARATORS)) { filter.Save(new WSGuidFFilter(param, member, WSGuidFFilter.OPERATIONS.GetOperation(state)) { Value = dVal }); } } #endregion } #endregion #region DateTime (Ready) else if (typeof(DateTime?).IsAssignableFrom(param.DataType)) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSDateFFilter(param, member, WSDateFFilter.OPERATIONS.NotEqual) { Value = null }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSDateFFilter(param, member, null) { Value = null }); } #endregion #endregion #region If Value (Ready) else { WSOperation operation = Value.IsTrue() ? WSDateFFilter.OPERATIONS.LessOrEqual : (Value.IsFalse() && !(param.DataType.IsNullable())) ? WSDateFFilter.OPERATIONS.GreaterThanOrEqual : WSDateFFilter.OPERATIONS.GetOperation(state); WSDateFFilter mainFilter = null; if (operation != null && operation.Match(WSDateFFilter.OPERATIONS.WeekDayEqual)) { mainFilter = new WSDateFFilter(param, member, operation) { Value = Value }; } else if (param.DataType.Read(Value, out dVal, new char[] { }, WSConstants.DATE_LIST_SEPARATORS, param.WSColumnRef.NAME)) { Type dType = dVal == null ? param.DataType : dVal.GetType(); if (dType.IsCollection() && operation != null) { dVal = operation.Match(WSDateFFilter.OPERATIONS.LessOrEqual) ? ((List <dynamic>)dVal).Max(x => x) : operation.Match(WSDateFFilter.OPERATIONS.GreaterThanOrEqual) ? ((List <dynamic>)dVal).Min(x => x) : dVal; } mainFilter = new WSDateFFilter(param, member, operation) { Value = dVal }; } if (param.DataType.IsNullable()) { WSCombineFilter cf = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso); if (mainFilter.Value != null) { cf.Save(new WSDateFFilter(param, member, WSDateFFilter.OPERATIONS.NotEqual) { Value = null }); } cf.Save(mainFilter); filter.Save(cf); } else { filter.Save(mainFilter); } } #endregion } #endregion #region TimeSpan (Ready) else if (typeof(TimeSpan?).IsAssignableFrom(param.DataType)) { #region SPECIAL CASES #region If Exists (Ready) if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSTimeFFilter(param, member, WSTimeFFilter.OPERATIONS.NotEqual) { Value = null }); } #endregion #region If Empty (Ready) else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable()) { filter.Save(new WSTimeFFilter(param, member, null) { Value = null }); } #endregion #endregion #region If Value (Ready) else { if (param.DataType.Read(Value, out dVal, new char[] { }, WSConstants.DATE_LIST_SEPARATORS)) { WSOperation operation = WSTimeFFilter.OPERATIONS.GetOperation(state); Type dType = dVal == null ? param.DataType : dVal.GetType(); if (dType.IsCollection() && operation != null) { dVal = operation.Match("max") ? ((List <dynamic>)dVal).Max(x => x) : operation.Match("min") ? ((List <dynamic>)dVal).Min(x => x) : dVal; } if (param.DataType.IsNullable()) { WSCombineFilter cf = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso); if (Value != null) { cf.Save(new WSTimeFFilter(param, member, WSTimeFFilter.OPERATIONS.NotEqual) { Value = null }); } cf.Save(new WSTimeFFilter(param, member, operation) { Value = dVal }); filter.Save(cf); } else { filter.Save(new WSTimeFFilter(param, member, operation) { Value = dVal }); } } } #endregion } #endregion } #endregion } catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); if (CFunc != null) { CFunc.RegError(GetType(), e, ref status); } } } return(filter.Any() ? (filter.Count == 1 && !filter.Negate) ? filter.FirstOrDefault() : filter : null); }
public bool Match(object _matchValue, string _matchOperation, Type vType = null) { try { vType = vType != null ? vType : _matchValue == null ? null : _matchValue.GetType(); if (vType != null) { dynamic matchVal = _matchValue != null && vType.Read(_matchValue, out matchVal) ? matchVal : null; dynamic tempVal = Value != null && vType.Read(Value, out tempVal) ? tempVal : null; #region Numeric (Ready) if (vType.IsNumeric()) { WSOperation operation = WSNumericFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSNumericFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || matchVal == tempVal); } else if (operation.Match(WSNumericFFilter.OPERATIONS.NotEqual)) { return(!((matchVal == null && tempVal == null) || matchVal == tempVal)); } else if (operation.Match(WSNumericFFilter.OPERATIONS.GreaterThan)) { return(matchVal != null && tempVal != null && matchVal > tempVal); } else if (operation.Match(WSNumericFFilter.OPERATIONS.GreaterThanOrEqual)) { return(matchVal != null && tempVal != null && matchVal >= tempVal); } else if (operation.Match(WSNumericFFilter.OPERATIONS.LessThan)) { return(matchVal != null && tempVal != null && matchVal < tempVal); } else if (operation.Match(WSNumericFFilter.OPERATIONS.LessThanOrEqual)) { return(matchVal != null && tempVal != null && matchVal <= tempVal); } } #endregion #region bool (Ready) else if (typeof(bool?).IsAssignableFrom(vType)) { WSOperation operation = WSBoolFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSBoolFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || (matchVal != null && tempVal != null && matchVal == tempVal)); } else if (operation.Match(WSBoolFFilter.OPERATIONS.NotEqual)) { return(!((matchVal == null && tempVal == null) || (matchVal != null && tempVal != null && matchVal == tempVal))); } } #endregion #region string (Ready) else if (typeof(string).IsAssignableFrom(vType)) { WSOperation operation = WSStringFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSStringFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || (matchVal).Equals(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.EndsWith)) { return(matchVal.EndsWith(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.StartsWith)) { return(matchVal.StartsWith(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.Like)) { return(matchVal.Contains(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.NotEqual)) { return(!((matchVal == null && tempVal == null) || (matchVal).Equals(tempVal))); } else if (operation.Match(WSStringFFilter.OPERATIONS.NotEndsWith)) { return(matchVal != null && !matchVal.EndsWith(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.NotStartsWith)) { return(matchVal != null && !matchVal.StartsWith(tempVal)); } else if (operation.Match(WSStringFFilter.OPERATIONS.NotLike)) { return(matchVal != null && !matchVal.Contains(tempVal)); } } #endregion #region Guid (Ready) else if (typeof(Guid?).IsAssignableFrom(vType)) { WSOperation operation = WSGuidFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSGuidFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || matchVal.Equals(tempVal)); } else if (operation.Match(WSGuidFFilter.OPERATIONS.NotEqual)) { return(!(matchVal == null && tempVal == null) || matchVal.Equals(tempVal)); } } #endregion #region DateTime (Ready) else if (typeof(DateTime?).IsAssignableFrom(vType)) { WSOperation operation = WSDateFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSDateFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || matchVal.Equals(tempVal)); } else if (operation.Match(WSDateFFilter.OPERATIONS.NotEqual)) { return(!((matchVal == null && tempVal == null) || matchVal.Equals(tempVal))); } else if (operation.Match(WSDateFFilter.OPERATIONS.GreaterThanOrEqual)) { return(matchVal >= tempVal); } else if (operation.Match(WSDateFFilter.OPERATIONS.LessOrEqual)) { return(matchVal <= tempVal); } } #endregion #region TimeSpan (Ready) else if (typeof(TimeSpan?).IsAssignableFrom(vType)) { WSOperation operation = WSTimeFFilter.OPERATIONS.GetOperation(_matchOperation); if (operation.Match(WSTimeFFilter.OPERATIONS.Equal)) { return((matchVal == null && tempVal == null) || matchVal.Equals(tempVal)); } else if (operation.Match(WSTimeFFilter.OPERATIONS.NotEqual)) { return(!((matchVal == null && tempVal == null) || matchVal.Equals(tempVal))); } } #endregion } } catch (Exception) { } return(false); }