Example #1
0
        private static void BuildCondition(SqlQuery query, QueryConditionDef condition, DocDef docDef, SqlQueryCondition parentCondition)
        {
            if (condition.Condition != ConditionOperation.Include && condition.Condition != ConditionOperation.Exp)
            {
                if (condition.SubQueryDef != null)
                {
                    var subQuery = Build(query.DataContext, condition.SubQueryDef);
                    if (String.IsNullOrEmpty(condition.AttributeName))
                    {
                        query.AddCondition(condition.Operation, docDef, condition.AttributeId, condition.Condition,
                                           subQuery, condition.SubQueryAttribute, parentCondition);
                    }
                    else
                    {
                        query.AddCondition(condition.Operation, docDef, condition.AttributeName, condition.Condition,
                                           subQuery, condition.SubQueryAttribute, parentCondition);
                    }
                }
                else
                if (String.IsNullOrEmpty(condition.AttributeName))
                {
                    query.AddCondition(condition.Operation, docDef, condition.AttributeId, condition.Condition, condition.Values, parentCondition);
                }
                else
                {
                    query.AddCondition(condition.Operation, docDef, condition.AttributeName, condition.Condition,
                                       condition.Values, parentCondition);
                }
            }
            else if (condition.Condition == ConditionOperation.Include && condition.Conditions != null && condition.Conditions.Count > 0)
            {
                var attrDef = String.IsNullOrEmpty(condition.AttributeName)
                                  ? docDef.Attributes.First(a => a.Id == condition.AttributeId)
                                  : docDef.Attributes.First(
                    a => String.Equals(a.Name, condition.AttributeName, StringComparison.OrdinalIgnoreCase));
                query.JoinSource(query.FindSourceByDocDef(docDef), attrDef.DocDefType.Id, SqlSourceJoinType.Inner, attrDef.Id);

                foreach (var child in condition.Conditions)
                {
                    BuildCondition(query, child, attrDef.DocDefType.Id, parentCondition);
                }
            }
            else if (condition.Condition == ConditionOperation.Exp && condition.Conditions != null)
            {
                var exp = query.AddExpCondition(condition.Operation, parentCondition);

                foreach (var child in condition.Conditions)
                {
                    BuildCondition(query, child, docDef, exp);
                }
            }
        }
Example #2
0
        /*private static void AddFormControls(SqlQuery query, SqlQuerySource source, IEnumerable<BizControl> children)
         * {
         *  if (children == null) return;
         *
         *  foreach(var control in children)
         *  {
         *      if (control is BizDataControl && ((BizDataControl)control).AttributeDefId != null)
         *      {
         *          if (control is BizDocumentControl && control.Children != null && control.Children.Count > 0)
         *          {
         *              var docControl = (BizDocumentControl) control;
         *              var attr = source.GetDocDef().Attributes.First(a => a.Id == (Guid) docControl.AttributeDefId);
         *
         *              var slave = query.JoinSource(source, attr.DocDefType, SqlSourceJoinType.Inner, attr.Id);
         *
         *              AddFormControls(query, slave, control.Children);
         *          }
         *          else
         *              query.AddAttribute(source, (Guid) ((BizDataControl) control).AttributeDefId);
         *      }
         *
         *  }
         * }*/

        public static void AddDocConditions(SqlQuery query, SqlQuerySource source, Doc filter)
        {
            if (filter == null)
            {
                return;
            }

            foreach (var attr in filter.Attributes)
            {
                if (attr is DocAttribute)
                {
                    if (((DocAttribute)attr).Document != null && HasDocumentValue(((DocAttribute)attr).Document))
                    {
                        AddJoinDocConditions(query, source, (DocAttribute)attr);
                    }
                }
                else if (attr is DocListAttribute)
                {
                    //                    if (((DocListAttribute)attr).AddedDocIds != null)
                }
                else if (attr.ObjectValue != null)
                {
                    if (attr is TextAttribute)
                    {
                        var txt = ((TextAttribute)attr).Value;
                        if (!String.IsNullOrEmpty(txt))
                        {
                            query.AddCondition(ExpressionOperation.And, attr.AttrDef.Id, ConditionOperation.Like, txt);
                        }
                    }
                    else
                    {
                        query.AddCondition(ExpressionOperation.And, attr.AttrDef.Id, ConditionOperation.Equal, attr.ObjectValue);
                    }
                }
            }
        }