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); } } } }
private static ReportConditionItemDef FindConditionById(ReportConditionItemDef condition, Guid conditionId) { if (condition.Id == conditionId) { return(condition); } var exp = condition as ReportExpConditionDef; if (exp != null && exp.Conditions != null) { return(exp.Conditions.Select(c => FindConditionById(c, conditionId)).FirstOrDefault(c => c != null)); } return(null); }