Beispiel #1
0
        void DrawButton(GraphicsCache cache)
        {
            int imageIndex = -1;

            switch (this.InfoText.Text[1])
            {
            case '-':
                imageIndex = IsActive ? 1 : 0;
                break;

            case '*':
                imageIndex = IsActive ? 3 : 2;
                break;

            case '+':
                imageIndex = IsActive ? 5 : 4;
                break;

            case '#':
                NodeElement element = this.InfoText.Tag as NodeElement;
                ClauseNode  node    = (ClauseNode)element.GetFocusInfo().Node;
                object      obj     = node.AdditionalOperands[element.GetFocusInfo().ElementIndex - 2];
                imageIndex = (IsActive ? 7 : 6) + (obj is OperandValue ? 2 : 0);
                break;
            }
            if (imageIndex == -1)
            {
                return;
            }
            int y = this.TextElement.Y + (this.TextElement.Height - FilterControl.NodeImages.ImageSize.Height) / 2;
            int x = this.TextElement.X + (this.TextElement.Width - FilterControl.NodeImages.ImageSize.Width) / 2;

            x = Math.Max(x, this.TextElement.X);
            cache.Paint.DrawImage(cache.Graphics, FilterControl.NodeImages.Images[imageIndex], new Point(x, y));
        }
Beispiel #2
0
        void DrawTestEditor(GraphicsCache cache, string text)
        {
            if (FilterViewInfo.Owner.OwnerControl.FocusedItem == this &&
                FilterViewInfo.Owner.OwnerControl.ActiveEditor != null)
            {
                return;
            }
            ClauseNode node = FilterViewInfo.Owner as ClauseNode;

            if (node == null)
            {
                return;
            }
            RepositoryItem ri = node.OwnerControl.GetRepositoryItem(node).Clone() as RepositoryItem;

            ri.BorderStyle = FilterViewInfo.Owner.OwnerControl.FocusedItem == this ? DevExpress.XtraEditors.Controls.BorderStyles.Default : DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            BaseEditPainter  p  = ri.CreatePainter();
            BaseEditViewInfo vi = ri.CreateViewInfo();

            vi.EditValue = this.TextElement.Text;
            vi.PaintAppearance.Assign(FilterViewInfo.Owner.OwnerControl.FilterViewInfo.PaintAppearance);
            vi.Bounds = LabelInfoHelper.GetEditorBoundsByElement(this);
            vi.CalcViewInfo(cache.Graphics);
            p.Draw(new ControlGraphicsInfoArgs(vi, cache, vi.Bounds));
        }
Beispiel #3
0
 public void CreateLabelInfoTexts(Node node)
 {
     SuspendTextChanges();
     try
     {
         Texts.Clear();
         if (node is GroupNode)
         {
             AddLabelInfoText(OperationHelper.GetMenuStringByType(((GroupNode)node).NodeType), new FilterControlFocusInfo(node, 0), Owner.OwnerControl.AppearanceGroupOperatorColor, ElementType.Group, true);
             if (node.OwnerControl.ShowGroupCommandsIcon)
             {
                 AddLabelInfoText("@*", new FilterControlFocusInfo(node, 0), Color.Empty, ElementType.NodeAction, true);
             }
             AddLabelInfoText("@+", new FilterControlFocusInfo(node, 0), Color.Empty, ElementType.NodeAdd, true);
         }
         ClauseNode clauseNode = node as ClauseNode;
         if (clauseNode != null)
         {
             AddLabelInfoText(GetDisplayText(clauseNode.FirstOperand), new FilterControlFocusInfo(clauseNode, 0), Owner.OwnerControl.AppearanceFieldNameColor, ElementType.Property, true);
             AddSpace();
             AddLabelInfoText(OperationHelper.GetMenuStringByType(clauseNode.Operation), new FilterControlFocusInfo(clauseNode, 1), Owner.OwnerControl.AppearanceOperatorColor, ElementType.Operation, true);
             AddSpace();
             AddAdditionalOperands(clauseNode);
             AddLabelInfoText("@-", new FilterControlFocusInfo(node, 0), Color.Empty, ElementType.NodeRemove, true);
         }
     }
     finally
     {
         ResumeTextChanges();
     }
     Invalidate();
 }
        protected override ClauseNode CreateDefaultClauseNode(IBoundProperty property, IBoundPropertyCollection currentFilterProperties)
        {
            ClauseNode result = base.CreateDefaultClauseNode(property, FilterProperties);

            result.Operation = ((CustomFilterControl)Control).GetDefaultOperationCore(result.Property, result.Operation);
            return(result);
        }
 void OnFilterControlPopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
 {
     if (e.MenuType == FilterControlMenuType.Group)
     {
         // Hide commands
         e.Menu.Remove(GroupType.NotAnd);
         e.Menu.Remove(GroupType.NotOr);
         //Locate and then disable and rename commands.
         e.Menu.Find(StringId.FilterMenuGroupAdd).Enabled = false;
         e.Menu.Find(StringId.FilterMenuClearAll).Caption = "Remove All";
     }
     // Hide all operators except Equals and DoesNotEqual for the "ID" field
     if (e.MenuType == FilterControlMenuType.Clause)
     {
         ClauseNode node = e.CurrentNode as ClauseNode;
         if (node.Property.Name == "ID")
         {
             DXMenuItem itemEqual    = e.Menu.Find(ClauseType.Equals);
             DXMenuItem itemNotEqual = e.Menu.Find(ClauseType.DoesNotEqual);
             for (int i = e.Menu.Items.Count - 1; i >= 0; i--)
             {
                 DXMenuItem item = e.Menu.Items[i];
                 if (!item.Equals(itemEqual) && !item.Equals(itemNotEqual))
                 {
                     item.Visible = false;
                 }
             }
         }
     }
 }
            public void Assert(BaseTerm assertion, bool asserta)
            {
                BaseTerm       head;
                TermNode       body = null;
                PredicateDescr pd;

                if (assertion.HasFunctor(PrologParser.IMPLIES))
                {
                    head = assertion.Arg(0);
                    body = assertion.Arg(1).ToGoalList();
                }
                else
                {
                    head = assertion;
                }

                if (!head.IsCallable)
                {
                    IO.Error("Illegal predicate head '{0}'", head.ToString());
                }

                string key = head.Key;

                if ((predefineds.Contains(key)) || (head.Precedence >= 1000))
                {
                    IO.Error("assert/1 cannot be applied to predefined predicate or operator '{0}'",
                             assertion.Index);
                }

                predTable.TryGetValue(key, out pd);
                ClauseNode newC = new ClauseNode(head, body);

                if (pd == null) // first head
                {
                    SetClauseList(head.FunctorToString, head.Arity, newC);
                    ResolveIndices();
                }
                else if (pd.IsCacheable)
                {
                    IO.Error("assert/1 cannot be applied to cached predicate '{0}'",
                             assertion.Index);
                }
                else if (asserta)                    // at beginning
                {
                    newC.NextClause = pd.ClauseList; // pd.ClauseList may be null
                    SetClauseList(head.FunctorToString, head.Arity, newC);
#if arg1index
                    pd.CreateFirstArgIndex(); // re-create
#endif
                }
                else // at end
                {
                    pd.AppendToClauseList(newC);
#if arg1index
                    pd.CreateFirstArgIndex(); // re-create
#endif
                }

                InvalidateCrossRef();
            }
        void ri_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e)
        {
            e.Value = dateEdit1.EditValue;
            DateTime               date  = Convert.ToDateTime(e.Value);
            PropertyInfo           pi    = typeof(FilterControl).GetProperty("FocusInfo", BindingFlags.Instance | BindingFlags.NonPublic);
            FilterControlFocusInfo focus = (FilterControlFocusInfo)pi.GetValue(filterControl1, null);
            ClauseNode             cnode = focus.Node as ClauseNode;

            if (cnode == null)
            {
                return;
            }
            if (cnode.Operation == ClauseType.Between)
            {
                if (focus.ElementIndex == 2)
                {
                    PatchOperator(cnode.AdditionalOperands[1] as OperandValue, date, comboBoxEdit1.Text, true);
                }
                else if (focus.ElementIndex == 3)
                {
                    PatchOperator(cnode.AdditionalOperands[0] as OperandValue, date, comboBoxEdit1.Text, false);
                }
                cnode.RecalcLabelInfo();
            }
        }
Beispiel #8
0
 public void Clear()
 {
     term       = null;
     nextNode   = null;
     nextClause = null;
     level      = 0;
 }
 public void Uncache()
 {
     if (HasCachedValues) // let clauseList start at the first non-cached clause again
     {
         clauseList       = lastCachedClause.NextClause;
         lastCachedClause = null;
     }
 }
 public void AdjustClauseListEnd() // forward clauseListEnd to the last clause
 {
     if ((clauseListEnd = clauseList) != null)
     {
         while (clauseListEnd.NextClause != null)
         {
             clauseListEnd = clauseListEnd.NextClause;
         }
     }
 }
            public void SetClauseListHead(ClauseNode c)
            {
                clauseList = clauseListEnd = c;

                while (clauseListEnd.NextClause != null)
                {
                    clauseListEnd = clauseListEnd.NextClause;
                }

                DestroyFirstArgIndex();
            }
            public void AppendToClauseList(ClauseNode c) // NextClause and ClauseListEnd are != null
            {
                clauseListEnd.NextClause = c;

                do
                {
                    clauseListEnd = clauseListEnd.NextClause;
                }while
                (clauseListEnd.NextClause != null);

                DestroyFirstArgIndex();
            }
            public PredicateDescr(string module, string definingFile, string functor, int arity, ClauseNode clauseList)
            {
                this.module       = module;
                this.definingFile = (definingFile == null) ? "predefined or asserted predicate" : definingFile;
                this.functor      = functor;
                this.arity        = arity;
#if enableSpying
                spyMode = SpyPort.None;
#endif
                this.clauseList       = clauseListEnd = clauseList;
                this.lastCachedClause = null; // no cached clauses (yet)
            }
            public bool ListClause(PredicateDescr pd, string functor, int arity, int seqno, out string outputString)
            {
                ClauseNode clause = null;
                string     details;
                var        sb = new StringBuilder();

                outputString = string.Empty;

                if ((clause = pd.ClauseList) == null)
                {
                    return(false);
                }

                details = "source: " + pd.DefiningFile;

                //        if (pd.IsFirstArgIndexed) details += "; arg1-indexed (jump points marked with '.')";

                sb.AppendFormat("\r\n{0}/{1}: ({2}) {3}", functor, arity, details,
                                ((seqno == 1) ? "" : (seqno.ToString().Packed())));
                sb.AppendLine();

                while (clause != null)
                {
                    bool currCachedClauseMustFail =
                        (clause is CachedClauseNode && !((CachedClauseNode)clause).Succeeds);

                    TermNode next;

                    //          // prefix a clause that is pointed to by first-argument indexing with '.'
                    //          IO.Write (" {0}{1}", (pd.IsFirstArgMarked (clause))?".":" ", nextClause.Term);
                    sb.AppendFormat("  {0}", clause.Term);

                    if (currCachedClauseMustFail)
                    {
                        sb.Append(" :- !, fail");
                    }
                    else if ((next = clause.NextNode) != null)
                    {
                        BI builtinId = next.BuiltinId;
                        sb.AppendFormat(" :-{0}", (builtinId == BI.none)
                    ? next.ToString()
                    : Environment.NewLine + builtinId.ToString());
                    }

                    sb.AppendLine(".");
                    clause = clause.NextClause;
                }

                outputString = sb.ToString();

                return(true);
            }
Beispiel #15
0
            void SetupCrossRefTable() //TODO (later...): deal with arguments of not/1 and call/1
            {
                if (!crossRefInvalid)
                {
                    return;
                }

                crossRefTable.Reset();
                PredicateDescr pd;

                foreach (KeyValuePair <string, PredicateDescr> kv in predTable)
                {
                    pd = kv.Value;
                    bool       isPredefined = IsPredefined(kv.Key);
                    ClauseNode clause       = pd.ClauseList;

                    if (!isPredefined)
                    {
                        crossRefTable.AddPredicate(pd);
                    }

                    // iterate over NextClause and NextClause.NextNode
                    while (clause != null)
                    {
                        TermNode node = clause.NextNode;

                        while (node != null)
                        {
                            if (node.PredDescr != null && !isPredefined)
                            {
                                PredicateDescr npd;
                                //IO.WriteLine ("{0} uses {1}", pd.Name, node.PredDescr.Name);
                                crossRefTable[pd, npd = node.PredDescr] = false;

                                if (npd.Name == "not/1" || npd.Name == "call/1") // add args to cref
                                {
                                    TermNode arg = node.NextNode;
                                    IO.WriteLine("{0} arg is {1}", npd.Name, arg);
                                }
                            }

                            node = node.NextNode;
                        }

                        clause = clause.NextClause;
                    }
                }

                crossRefTable.CalculateClosure();
                crossRefInvalid = false;
            }
            // put the predicate definition (if found) into the TermNode if it is not already there
            public bool FindPredicateDefinition(PredicateTable predicateTable)
            {
                if (predDescr == null)
                {
                    //IO.WriteLine ("predDescr == null for {0}", term.Name);
                    if ((predDescr = predicateTable [term.Key]) == null)
                    {
                        return(false);
                    }
                }

#if arg1index // first-argument indexing enabled
                BaseTerm arg;

                // caching would disturb the search process (since caching does not
                // cause the arg0Index to be rebuild, since this might be to costly)
                if (predDescr.IsFirstArgIndexed && !predDescr.HasCachedValues)
                {
                    if ((arg = term.Arg(0)).IsVar)
                    {
                        nextClause = predDescr.FirstArgVarClause();
                    }
                    else // not a variable
                    {
                        nextClause = predDescr.FirstArgNonvarClause(arg.FunctorToString);

                        // check whether there is an indexed var clause
                        if (nextClause == null)
                        {
                            nextClause = predDescr.FirstArgVarClause();
                        }

                        // if the above failed, the entire predicate fails (no unification possible)
                        if (nextClause == null)
                        {
                            nextClause = ClauseNode.FAIL;
                        }
                    }

                    if (nextClause == null)
                    {
                        nextClause = predDescr.ClauseList;
                    }
                }
                else // not indexed
#endif
                nextClause = predDescr.ClauseList;

                return(true);
            }
 private void OnPopupMenuShowing(object sender, DevExpress.XtraEditors.Filtering.PopupMenuShowingEventArgs e)
 {
     if (e.MenuType == FilterControlMenuType.Clause)
     {
         ClauseNode node = e.CurrentNode as ClauseNode;
         if (node != null && node.Property.Type == typeof(DateTime))
         {
             e.Menu.Hide(ClauseType.Equals);
             e.Menu.Remove(ClauseType.DoesNotEqual);
             e.Menu.Hide(DevExpress.XtraEditors.Controls.StringId.FilterAdvancedDateTimeOperatorMenuCaption);
             var menuItem = e.Menu.Find(ClauseType.Between);
             menuItem.Caption = "Between A and B";
             //menuItem.ImageOptions.SvgImage = MySvgImage1;
         }
     }
 }
Beispiel #18
0
        private void BuildClauseSQL(StringBuilder SQLQuery, ClauseNode ClauseNode)
        {
            // Non-group node
            var operation = ClauseNode.Operation;

            // Check for values that arent filled in.
            if (ClauseNode.AdditionalOperands.Count > 0
                && ClauseNode.AdditionalOperands[0] is DevExpress.Data.Filtering.OperandValue
                && ((DevExpress.Data.Filtering.OperandValue)ClauseNode.AdditionalOperands[0]).Value == null)
            {
                if (ErrorOnMissingFilters)
                    throw new ArgumentException("Not all filters are properly filled in. If you need to search for blanks or nulls please use the is blank operator.");
                else
                    operation = ClauseType.IsNull;
            }

            string[ addlOper = Array.ConvertAll<object, string>(ClauseNode.AdditionalOperands.ToArray(), delegate(object o) { return o.ToString(); });
            // CACHEING CURRENTLY NOT USED
            #region Cacheing
            // Cache -- analogous to asserting a fact, but specifically for cacheing.
            // Cached terms are inserted at the very beginning of the predicate's clause
            // chain, in the order in which they were determined.
            public void Cache(BaseTerm cacheTerm, bool succeeds)
            {
                IO.WriteLine("Cacheing {0}{1}", cacheTerm, succeeds ? null : " :- !, fail");

                CachedClauseNode newCachedClause = new CachedClauseNode(cacheTerm, null, succeeds);

                if (lastCachedClause == null) // about to add the first cached term
                {
                    newCachedClause.NextClause = clauseList;
                    clauseList = newCachedClause;
                }
                else
                {
                    newCachedClause.NextClause  = lastCachedClause.NextClause;
                    lastCachedClause.NextClause = newCachedClause;
                }

                lastCachedClause = newCachedClause;
            }
Beispiel #20
0
            PredicateDescr SetClauseList(string f, int a, ClauseNode c)
            {
                string         key = BaseTerm.MakeKey(f, a);
                PredicateDescr pd  = this[key];

                if (pd == null)
                {
                    this[key] = pd =
                        new PredicateDescr(null, ConsultFileName, f, a, c);
                }
                else
                {
                    pd.SetClauseListHead(c);
                }

                pd.AdjustClauseListEnd();

                return(pd);
            }
            public bool IsFirstArgMarked(ClauseNode c)
            {
                if (arg0Index == null)
                {
                    return(false);
                }

                BaseTerm   t = c.Term.Arg(0);
                ClauseNode result;

                if (t.IsVar)
                {
                    arg0Index.TryGetValue(VARARG, out result);
                }
                else
                {
                    arg0Index.TryGetValue(t.FunctorToString, out result);
                }

                return(result == c);
            }
Beispiel #22
0
            public void AddPredefined(ClauseNode clause)
            {
                BaseTerm       head = clause.Head;
                string         key  = head.Key;
                PredicateDescr pd   = this[key];

                if (pd == null)
                {
                    predefineds[key] = true;                                 // any value != null will do
                    SetClauseList(head.FunctorToString, head.Arity, clause); // create a PredicateDescr
                }
                else if (prevIndex != null && key != prevIndex)
                {
                    IO.Error("Definition for predefined predicate '{0}' must be contiguous", head.Index);
                }
                else
                {
                    pd.AppendToClauseList(clause);
                }

                prevIndex = key;
            }
Beispiel #23
0
            // A predicate consists of one or more clauses. A clause consist of a head and optionally a
            // body. A head is a term, the body is a sequence of terms. A predicate is stored as a chain
            // of TermNodes, where each TermNode represents a clause. These TermNodes are linked via the
            // nextClause field. In each nextClause/TermNode the clause head is stored in term, and the
            // clause body (which may be null) in NextNode.

            public IEnumerator <BaseTerm> GetEnumerator()
            {
                if (pd == null)
                {
                    yield break;
                }

                ClauseNode clause = pd.ClauseList;

                while (clause != null) // iterate over all clauses of this predicate
                {
                    TermNode bodyNode = clause.NextNode;

                    int marker = varStack.Count; // register the point to which we must undo unification

                    if (clause.Head.Unify(clauseHead, varStack))
                    {
                        if (bodyNode == null) // a fact
                        {
                            clauseBody = new BoolTerm(true);
                        }
                        else if (bodyNode.BuiltinId == BI.none)
                        {
                            clauseBody = bodyNode.TermSeq();
                        }
                        else
                        {
                            clauseBody = new StringTerm("<builtin>");
                        }

                        yield return(clauseBody);
                    }

                    // undo unification with clauseHead before attempting the next clause head
                    BaseTerm.UnbindToMarker(varStack, marker);
                    clause = clause.NextClause;
                }
            }
Beispiel #24
0
            void ResolveIndex(PredicateDescr pd)
            {
                ClauseNode clause = pd.ClauseList;

                while (clause != null)                 // iterate over all clauses of this predicate. NextClause.BaseTerm contains predicate clauseHead
                {
                    BaseTerm clauseHead = clause.Head; // clause = clauseHead :- clauseTerm*
                    TermNode clauseTerm = clause.NextNode;

                    while (clauseTerm != null) // non-facts only. Iterate over all clauseTerm-terms at of this clause
                    {
                        if (clauseTerm.BuiltinId == BI.none)
                        {
                            clauseTerm.PredDescr = this[clauseTerm.Term.Key];
                        }
                        // builtins (>=0) are handled differently (in Execute ())

                        clauseTerm = clauseTerm.NextNode;
                    }
                    clause = clause.NextClause;
                }
                return;
            }
Beispiel #25
0
            void FindUndefined(SortedList sd, PredicateDescr pd)
            {
                ClauseNode clause = pd.ClauseList;
                TermNode   clauseTerm;

                while (clause != null) // iterate over all clauses of this predicate
                {
                    clauseTerm = clause.NextNode;

                    while (clauseTerm != null) // non-facts only. Iterate over all clauseTerm-terms of this clause
                    {
                        if (clauseTerm.BuiltinId == BI.none && clauseTerm.PredDescr == null)
                        {
                            sd[clauseTerm.Term.Index] = null;
                        }

                        clauseTerm = clauseTerm.NextNode;
                    }

                    clause = clause.NextClause;
                }

                return;
            }
        private void BuildClauseSQL(StringBuilder SQLQuery, ClauseNode ClauseNode)
        {
            // Non-group node
            var operation = ClauseNode.Operation;
            // Check for values that arent filled in.
            if (ClauseNode.AdditionalOperands.Count > 0
                && ClauseNode.AdditionalOperands[0] is DevExpress.Data.Filtering.OperandValue
                && ((DevExpress.Data.Filtering.OperandValue)ClauseNode.AdditionalOperands[0]).Value == null)
            {
                if (ErrorOnMissingFilters)
                    throw new ArgumentException("Not all filters are properly filled in. If you need to search for blanks or nulls please use the is blank operator.");
                else
                    operation = ClauseType.IsNull;
            }

            CriteriaOperator[] criterias = new CriteriaOperator[ClauseNode.AdditionalOperands.Count];
            for (int k = 0; k < ClauseNode.AdditionalOperands.Count; k++)
            {
                criterias[k] = ClauseNode.AdditionalOperands[k];
            }

            //string[] addlOper = Array.ConvertAll<object, string>(ClauseNode.AdditionalOperands.ToArray(),
            //    delegate(object o) { return o.ToString(); }
            //);

            string[] addlOper = Array.ConvertAll<object, string>(criterias,
                delegate(object o) { return o.ToString(); }
            );
            string oper = "";
            // Hook into parameter system
            if (_useParams)
                ConvertDataToParams(addlOper, operation, ClauseNode);
            if (addlOper.Length > 0)
            {
                oper = addlOper[0];
            }
            string stmt = "";
            string field = ClauseNode.FirstOperand.PropertyName;

            switch (operation)
            {
                case ClauseType.AnyOf:
                    stmt = GetAnyOf(field, addlOper);
                    break;
                case ClauseType.BeginsWith:
                    stmt = GetBeginWith(field, oper);
                    break;
                case ClauseType.Between:
                    stmt = GetBetween(field, addlOper[0], addlOper[1]);
                    break;
                case ClauseType.Contains:
                    stmt = GetContain(field, oper);
                    break;
                case ClauseType.DoesNotContain:
                    stmt = GetNotContain(field, oper);
                    break;
                case ClauseType.DoesNotEqual:
                    stmt = GetNotEqual(field, oper);
                    break;
                case ClauseType.EndsWith:
                    stmt = GetEndsWith(field, oper);
                    break;
                case ClauseType.Equals:
                    stmt = GetEqual(field, oper);
                    break;
                case ClauseType.Greater:
                    stmt = GetGreaterThan(field, oper);
                    break;
                case ClauseType.GreaterOrEqual:
                    stmt = GetGreaterThanOrEqual(field, oper);
                    break;
                case ClauseType.IsNotNull:
                    stmt = GetNotBlank(field);
                    break;
                case ClauseType.IsNull:
                    stmt = GetBlank(field);
                    break;
                case ClauseType.Less:
                    stmt = GetLessThan(field, oper);
                    break;
                case ClauseType.LessOrEqual:
                    stmt = GetLessThanOrEqual(field, oper);
                    break;
                case ClauseType.Like:
                    stmt = GetLike(field, oper);
                    break;
                case ClauseType.NoneOf:
                    stmt = GetNotAnyOf(field, oper);
                    break;
                case ClauseType.NotBetween:
                    stmt = GetNotBetween(field, addlOper[0], addlOper[1]);
                    break;
                case ClauseType.NotLike:
                    stmt = GetNotLike(field, oper);
                    break;
                default:
                    throw new NotImplementedException("Unknown enum for the node's operation type.");
            }
            if (SQLQuery.Length > 0 && !SQLQuery.ToString().EndsWith(GetStartGroup()))
                SQLQuery.AppendFormat(" {0} ", _groupClauseStack.Peek());
            SQLQuery.Append(stmt);
        }
Beispiel #27
0
            public bool RetractAll(BaseTerm t, VarStack varStack)
            {
                // remark: first-argument indexing is not affected by deleting clauses

                string key = t.Key;

                if (predefineds.Contains(key))
                {
                    IO.Error("retract of predefined predicate {0} not allowed", key);
                }

                PredicateDescr pd = this[key];

                if (pd == null)
                {
                    return(true);
                }

                ClauseNode c     = pd.ClauseList;
                ClauseNode prevc = null;
                bool       match = false;

                while (c != null)
                {
                    BaseTerm cleanTerm = c.Term.Copy();

                    if (cleanTerm.IsUnifiableWith(t, varStack)) // match found -- remove this head from the chain
                    {
                        match = true;                           // to indicate that at least one head was found

                        if (prevc == null)                      // remove first clause
                        {
                            if (c.NextClause == null)           // we are about to remove the last remaining clause for this predicate
                            {
                                predTable.Remove(key);          // ... so remove its PredicateDescr as well

                                break;
                            }
                            else
                            {
                                pd.SetClauseListHead(c.NextClause);
                            }
                        }
                        else // not the first
                        {
                            prevc.NextClause = c.NextClause;
                            prevc            = c;
                        }
                    }
                    else
                    {
                        prevc = c;
                    }

                    c = c.NextClause;
                }

                if (match)
                {
#if arg1index
                    pd.DestroyFirstArgIndex(); // rebuilt by ResolveIndices()
#endif
                    pd.AdjustClauseListEnd();
                    ResolveIndices();
                }

                return(true);
            }
Beispiel #28
0
            public bool Retract(BaseTerm t, VarStack varStack, BaseTerm where)
            {
                string key = t.Key;

                if (predefineds.Contains(key))
                {
                    IO.Error("retract of predefined predicate {0} not allowed", key);
                }

                PredicateDescr pd = this[key];

                if (pd == null)
                {
                    return(false);
                }

                InvalidateCrossRef();
                ClauseNode c     = pd.ClauseList;
                ClauseNode prevc = null;
                BaseTerm   cleanTerm;
                int        top;

                while (c != null)
                {
                    cleanTerm = c.Head.Copy();

                    top = varStack.Count;

                    if (cleanTerm.Unify(t, varStack))     // match found -- remove this term from the chain
                    {
                        if (prevc == null)                // remove first clause
                        {
                            if (c.NextClause == null)     // we are about to remove the last remaining clause for this predicate
                            {
                                predTable.Remove(key);    // ... so remove its PredicateDescr as well
#if arg1index
                                pd.CreateFirstArgIndex(); // re-create
#endif
                                ResolveIndices();
                            }
                            else
                            {
                                pd.SetClauseListHead(c.NextClause);
                            }
                        }
                        else // not the first
                        {
                            prevc.NextClause = c.NextClause;
                            prevc            = c;
                            pd.AdjustClauseListEnd();
#if arg1index
                            pd.CreateFirstArgIndex(); // re-create
#endif
                        }

                        return(true); // possible bindings must stay intact (e.g. if p(a) then retract(p(X)) yields X=a)
                    }

                    Variable s;
                    for (int i = varStack.Count - top; i > 0; i--) // unbind all vars that got bound by the above Unification
                    {
                        s = (Variable)varStack.Pop();
                        s.Unbind();
                    }

                    prevc = c;
                    c     = c.NextClause;
                }

                ResolveIndices();

                return(false);
            }
Beispiel #29
0
            public void AddClause(ClauseNode clause)
            {
                BaseTerm head = clause.Head;

                string key   = head.Key;
                string index = head.Index;

                if (predefineds.Contains(key))
                {
                    IO.Error("Modification of predefined predicate {0} not allowed", index);
                }

                if (prevIndex == key) // previous clause was for the same predicate
                {
                    PredicateDescr pd = this[key];
                    pd.AppendToClauseList(clause);
                }
                else // first predicate or different predicate
                {
                    PredicateDescr pd = this[key];

                    if (!definedInCurrFile.Contains(key)) //  very first clause of this predicate in this file -- reset at start of consult
                    {
                        if (pd != null && pd.DefinitionFile != ConsultFileName)
                        {
                            IO.Error("Predicate '{0}' is already defined in {1}", index, pd.DefinitionFile);
                        }

                        definedInCurrFile[key] = true;
                        pd = SetClauseList(head.FunctorToString, head.Arity, clause); // implicitly erases all previous definitions
                        pd.IsDiscontiguous = (isDiscontiguous.Contains(key) || allDiscontiguous);
                        prevIndex          = key;
                    }
                    else // not the first clause. First may be from another definitionFile (which is an error).
                    {    // If from same, IsDiscontiguous must hold, unless DiscontiguousAllowed = "1" in .config
                        bool b = false;

                        if (pd.IsDiscontiguous || (b = ConfigSettings.DiscontiguousAllowed))
                        {
                            if (b)
                            {
                                IO.Warning("Predicate '{0}' is defined discontiguously but is not declared as such", index);
                            }

                            if (pd.DefinitionFile == ConsultFileName)
                            {
                                pd.AppendToClauseList(clause);
                            }
                            else // OK
                            {
                                IO.Error("Discontiguous predicate {0} must be in one file (also found in {1})", index, pd.DefinitionFile);
                            }
                        }
                        else if (pd.DefinitionFile == ConsultFileName) // Warning or Error?
                        {
                            IO.Error("Predicate '{0}' occurs discontiguously but is not declared as such", index);
                        }
                        else
                        {
                            IO.Error("Predicate '{0}' is already defined in {1}", index, pd.DefinitionFile);
                        }
                    }
                }
            }
        /// <summary>
        /// Converts data into parameters and adds to the dictionary collection
        /// </summary>
        /// <param name="Data"></param>
        private void ConvertDataToParams(string[] Data, ClauseType operation, ClauseNode ClauseNode)
        {
            for (int i = 0; i < Data.Length; i++)
            {
                string s = Data[i];
                string paramName = string.Format("@PM{0}", _params.Count + 1);
                // Strip the single quotes when adding parameters.
                if (s.StartsWith("'") || s.EndsWith("'"))
                    _params.Add(paramName, s.Substring(1, s.Length - 2));
                else
                    _params.Add(paramName, s);

                object value = ((DevExpress.Data.Filtering.OperandValue)ClauseNode.AdditionalOperands[0]).Value;
                _paramDataTypes.Add(paramName, value);

                if (HelpDBExt.GetDbType(value) == System.Data.DbType.String)
                {
                    switch (operation)
                    {
                        case ClauseType.BeginsWith:
                            _params[paramName] = string.Format("{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.EndsWith:
                            _params[paramName] = string.Format("%{0}", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.Contains:
                            _params[paramName] = string.Format("%{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.DoesNotContain:
                            _params[paramName] = string.Format("%{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.Like:
                            break;
                        case ClauseType.NotLike:
                            break;
                    }
                }

                Data[i] = paramName;
            }
        }
Beispiel #31
0
        void AddAdditionalOperands(ClauseNode node)
        {
            List <CriteriaOperator> list = node.AdditionalOperands;
            ClauseNode cNode             = node as ClauseNode;
            bool       collection        = IsCollectionClause(cNode.Operation);
            bool       twoFields         = IsTwoFieldsClause(cNode.Operation);

            if (list.Count > 1 && collection)
            {
                AddLabelInfoText("(", new FilterControlFocusInfo(node, 2), Owner.OwnerControl.FilterViewInfo.PaintAppearance.ForeColor, ElementType.None, false);
            }
            for (int i = 0; i < list.Count; i++)
            {
                CriteriaOperator       op = list[i];
                FilterControlFocusInfo fi = new FilterControlFocusInfo(node, i + 2);
                string text = StringAdaptation(GetDisplayText(node.FirstOperand, op));
                if (text == null || text.Length == 0)
                {
                    text = "''";
                }
                Color       color;
                ElementType elementType;
                if (op is OperandProperty)
                {
                    color       = Owner.OwnerControl.AppearanceFieldNameColor;
                    elementType = ElementType.Property;
                }
                else
                {
                    color       = Owner.OwnerControl.AppearanceValueColor;
                    elementType = ElementType.Value;
                    if (op.ToString() == "?")
                    {
                        text  = ("<请输入值>");
                        color = Owner.OwnerControl.AppearanceEmptyValueColor;
                    }
                }
                AddLabelInfoText(text, fi, color, elementType, true);
                if (node.ShowOperandTypeIcon)
                {
                    AddLabelInfoText("@#", fi, Color.Empty, ElementType.FieldAction, true);
                }
                if (i < list.Count - 1 && collection)
                {
                    AddLabelInfoText(", ", new FilterControlFocusInfo(node, 1), Owner.OwnerControl.FilterViewInfo.PaintAppearance.ForeColor, ElementType.None, false);
                }
                if (i < list.Count - 1 && twoFields)
                {
                    AddLabelInfoText(" " + "到" + " ", new FilterControlFocusInfo(node, 1), Owner.OwnerControl.AppearanceOperatorColor, ElementType.None, false);
                    //AddLabelInfoText(" " + Localizer.Active.GetLocalizedString(StringId.FilterClauseBetweenAnd) + " ", new FilterControlFocusInfo(node, 1), Owner.OwnerControl.AppearanceOperatorColor, ElementType.None, false);
                }
            }
            if (collection)
            {
                if (list.Count > 1)
                {
                    AddLabelInfoText(")", new FilterControlFocusInfo(node, list.Count + 1), Owner.OwnerControl.FilterViewInfo.PaintAppearance.ForeColor, ElementType.None, false);
                }
                AddLabelInfoText("@+", new FilterControlFocusInfo(node, 0), Color.Empty, ElementType.CollectionAction, true);
            }
        }
            public bool CreateFirstArgIndex(bool force) // Create the index if the predicate qualifies
            {
                if (arg0Index != null && !force)
                {
                    return(false);                     // index already exists
                }
                // Check each nextClause whether with the addition of this nextClause the predicate
                // still qualifies for first argument indexing.
                // Indexing y/n must be (re)determined after a file consult or an assert.

                ClauseNode c         = clauseList;
                short      arg0Count = 0;

                while (c != null)
                {
                    if (c.Head.Arity != 0) // no first arg
                    {
                        arg0Count++;       // Indexing not worthwile if only a few number of clauses

                        if (c.Head.Arg(0).IsVar)
                        {
                            break;
                        }
                    }

                    c = c.NextClause;
                }

                if (arg0Count < ARG0COUNT_MIN)
                {
                    return(false);
                }

                // second pass: build the index

                arg0Index = new Dictionary <object, ClauseNode> ();
                c         = clauseList;

                while (c != null)
                {
                    string s;

                    BaseTerm t = c.Head.Arg(0);

                    if (t.IsVar)
                    {
                        arg0Index [VARARG] = c; // stop immediately after having included the first variable

                        break;
                    }
                    else if (!arg0Index.ContainsKey(s = t.FunctorToString))
                    {
                        arg0Index [s] = c;
                    }

                    c = c.NextClause;
                }

                if (arg0Index.Count == 1) // e.g. c(a(1)), c(a(2)), c(a(3)), ...
                {
                    arg0Index = null;

                    return(false);
                }
                else
                {
                    return(true);
                }
            }