Пример #1
0
 private ConditionOperation ToConditionOperation(short?op)
 {
     if (op == null)
     {
         return(ConditionOperation.Exp);
     }
     return(CompareOperationConverter.CompareToCondition((short)op));
 }
Пример #2
0
        private static void BuildCondition(SqlQuery query, ReportDef report, ReportConditionItemDef item, SqlQueryCondition parentCondition, IDictionary <Guid, SqlQuerySource> mapper, bool isHaving)
        {
            var condition = item as ReportConditionDef;

            if (condition != null)
            {
                var source           = mapper[condition.LeftAttribute.SourceId];
                var reportSource     = report.GetSourceDef(condition.LeftAttribute.SourceId);
                var reportSourceAttr = reportSource.Attributes != null
                    ? reportSource.Attributes.FirstOrDefault(a => a.Id == condition.LeftAttribute.AttributeId)
                    : null;

                var attr = reportSourceAttr == null?source.GetAttribute(condition.LeftAttribute.AttributeId) : source.GetAttribute(reportSourceAttr.Ident);

                var attrRef  = new SqlQuerySourceAttributeRef(source, attr);
                var leftPart = new SqlQueryConditionPart();
                leftPart.Attributes.Add(attrRef);

                var rightPart = BuildConditionPart(query, report, condition, mapper);

                if (parentCondition != null)
                {
                    parentCondition.Conditions.Add(new SqlQueryCondition(item.Operation, leftPart,
                                                                         CompareOperationConverter.CompareToCondition(condition.Condition), rightPart));
                }
                else if (isHaving)
                {
                    query.HavingConditions.Add(new SqlQueryCondition(item.Operation, leftPart,
                                                                     CompareOperationConverter.CompareToCondition(condition.Condition),
                                                                     rightPart));
                }
                else
                {
                    query.Conditions.Add(new SqlQueryCondition(item.Operation, leftPart,
                                                               CompareOperationConverter.CompareToCondition(condition.Condition),
                                                               rightPart));
                }
            }
            else
            {
                var expCondition = item as ReportExpConditionDef;
                if (expCondition != null && expCondition.Conditions != null)
                {
                    var exp = query.AddExpCondition(item.Operation, parentCondition);

                    foreach (var child in expCondition.Conditions)
                    {
                        BuildCondition(query, report, child, exp, mapper, isHaving);
                    }
                }
            }
        }