Exemplo n.º 1
0
 public bool IsEmptyFilter(FilterCustom filter)
 {
     if (filter.MaxCost == 0 && filter.MinCost == 0 && filter.AircraftModelId == 0 && filter.AirlineId == 0)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        private void WriteFilter(StringWriter w, FilterItemBase filter, string parent, ref int varindex)
        {
            List <string> parameters = new List <string>();

            switch (filter.FilterType)
            {
            case EFilterType.Custom:
            {
                w.Write(parent + ".AddExpression(item => ");
                FilterCustom custom = (FilterCustom)filter;
                var          result = CodeParameterPattern.Matches(custom.Code);
                foreach (Match item in result)
                {
                    var name = item.Groups[1].Value;
                    if (!parameters.Contains(name))
                    {
                        parameters.Add(name);
                    }
                }
                if (parameters.Count == 0)
                {
                    w.Write(custom.Code);
                }
                else
                {
                    w.Write(CodeParameterPattern.Replace(custom.Code, m => m.Groups[1].Value));
                }
            }
            break;

            case EFilterType.MultiValue:
            {
                FilterMultiValue stan = (FilterMultiValue)filter;
                string           expression;
                EDataBaseType    expressionDataType;
                ProcessExpression(stan.Name, stan.Function, stan.FunctionParemeter, out expression, out expressionDataType);
                switch (stan.Operator)
                {
                case EOperator.Between:
                case EOperator.NotBetween:
                    string        value1     = QueryMetadata.GetRightExpression(expressionDataType, stan.Value1Type, stan.Value1, parameters, false);
                    List <string> valueNames = new List <string>();
                    if (stan.Value1Type != EValueType.Property)
                    {
                        value1 = ProcessVariable(w, value1, ref varindex);
                        if (stan.Value1Type == EValueType.Const && stan.Value1.StartsWith("@"))
                        {
                            valueNames.Add(value1);
                        }
                    }
                    string value2 = QueryMetadata.GetRightExpression(expressionDataType, stan.Value2Type, stan.Value2, parameters, false);
                    if (stan.Value2Type != EValueType.Property)
                    {
                        value2 = ProcessVariable(w, value2, ref varindex);
                        if (stan.Value2Type == EValueType.Const && stan.Value2.StartsWith("@"))
                        {
                            valueNames.Add(value2);
                        }
                    }
                    if (valueNames.Count > 0)
                    {
                        w.WriteLine($"if({string.Join(" && ", valueNames.Select(a => a + " != null").ToArray())})");
                    }
                    w.Write(parent + ".AddExpression(item => ");
                    w.Write(QueryMetadata.Operators[stan.Operator], expression, value1, value2);
                    break;
                }
            }
            break;

            case EFilterType.Standard:
            {
                FilterStandard stan = (FilterStandard)filter;
                string         expression;
                EDataBaseType  expressionDataType;
                ProcessExpression(stan.Name, stan.Function, stan.FunctionParemeter, out expression, out expressionDataType);

                switch (stan.Operator)
                {
                case EOperator.IsNull:
                case EOperator.NotIsNull:
                    w.Write(parent + ".AddExpression(item => ");
                    w.Write(QueryMetadata.Operators[stan.Operator], expression);
                    break;

                default:
                    bool   isArray = stan.Operator == EOperator.IN;
                    string value   = QueryMetadata.GetRightExpression(expressionDataType, stan.ValueType, stan.Value, parameters, isArray);
                    if (stan.ValueType != EValueType.Property)
                    {
                        value = ProcessVariable(w, value, ref varindex);
                        if (stan.ValueType == EValueType.Const && stan.Value.StartsWith("@"))
                        {
                            w.WriteLine($"if({value}!=null)");
                        }
                    }
                    w.Write(parent + ".AddExpression(item => ");
                    w.Write(QueryMetadata.Operators[stan.Operator], expression, value);
                    break;
                }
            }
            break;
            }
            w.Write(",EExpressionConnect." + filter.Connection.ToString());
            if (parameters.Count > 0)
            {
                w.Write(",new string[] { " + string.Join(",", parameters.Distinct().Select(a => "\"" + a + "\"").ToArray()) + " }");
            }
            w.WriteLine(");");
        }