Exemple #1
0
        private static void UpdateToolStripItem(ToolStripItem item, PredicateItem selection)
        {
            var builder = item as IPredicateBuilder;

            item.Enabled = (selection != null) &&
                           ((builder == null) || selection.CanAdd(builder.CreatePredicate(false)));
            var dropDown = item as ToolStripDropDownItem;

            if (dropDown != null)
            {
                foreach (ToolStripItem x in dropDown.DropDownItems)
                {
                    UpdateToolStripItem(x, selection);
                }
            }
        }
        /// <summary>Renders CONTAINS predicate as compatible LIKE predicate.</summary>
        /// <param name="contains">Contains predicate.</param>
        /// <param name="dbms">Target DBMS.</param>
        /// <param name="output">StringBuilder to which SQL is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        public void Render(ContainsPredicate contains, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            output.Append("(");
            contains.PredicateItems[0].Render(dbms, output, parameters);
            if (contains.Negate)
                output.Append(" NOT LIKE ");
            else
                output.Append(" LIKE ");

            IDbColumn field = (IDbColumn)contains.PredicateItems[0].Item;
            string pattern = (string)(contains.PredicateItems[1].Item as DbParameter).Value;
            pattern = "%" + pattern + "%";

            PredicateItem parametrizedPattern = new PredicateItem(pattern, DbType.String, field.MaxLengthIfText, field.GetPrefixedAlias());
            parametrizedPattern.Render(dbms, output, parameters);
            output.Append(")");
        }
        public void Render(ContainsPredicate contains, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            output.Append("(");
            if (contains.Negate)
                output.Append("NOT CONTAINS(");
            else
                output.Append("CONTAINS(");

            contains.PredicateItems[0].Render(dbms, output, parameters);
            output.Append(", ");

            IDbColumn field = (IDbColumn)contains.PredicateItems[0].Item;
            string term = (string)(contains.PredicateItems[1].Item as DbParameter).Value;
            if (contains.TermType == ContainsTermType.PrefixTerm)
                term = '"' + term + '"';
            else
                term = '"' + term + "*\"";

            PredicateItem parametrizedTerm = new PredicateItem(term, DbType.String, field.MaxLengthIfText, field.GetPrefixedAlias());
            parametrizedTerm.Render(dbms, output, parameters);
            output.Append(")");
            output.Append(")");
        }
Exemple #4
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public PredicateEditorForm(ILocPredicate predicate, IRailway railway)
        {
            this.predicate = predicate;
            InitializeComponent();
            if (predicate != null)
            {
                rootNode      = predicate.Accept(Default <ItemBuilder> .Instance, railway);
                rootNode.Text = "Permissions";
                tvItems.Nodes.Add(rootNode);
                tvItems.ExpandAll();

                // Locs
                foreach (var locRef in railway.Locs)
                {
                    ILoc loc;
                    if (locRef.TryResolve(out loc))
                    {
                        var menuItem = new LocEqualsMenuItem(loc, railway);
                        menuItem.Click += (s, x) => Execute(menuItem);
                        tbAddLocs.DropDownItems.Add(menuItem);
                    }
                }

                // LocGroups
                foreach (var group in railway.LocGroups)
                {
                    var menuItem = new LocGroupEqualsMenuItem(group, railway);
                    menuItem.Click += (s, x) => Execute(menuItem);
                    tbAddLocGroups.DropDownItems.Add(menuItem);
                }

                // Specials
                {
                    // Change direction
                    {
                        var menuItem = new LocCanChangeDirectionMenuItem(railway);
                        menuItem.Click += (s, x) => Execute(menuItem);
                        tbAddSpecial.DropDownItems.Add(menuItem);
                    }
                    // Time predicate
                    {
                        var menuItem = new LocTimeMenuItem(railway);
                        menuItem.Click += (s, x) => Execute(menuItem);
                        tbAddSpecial.DropDownItems.Add(menuItem);
                    }
                    // AND
                    {
                        var menuItem = new LocAndMenuItem(railway);
                        menuItem.Click += (s, x) => Execute(menuItem);
                        tbAddSpecial.DropDownItems.Add(menuItem);
                    }
                    // OR
                    {
                        var menuItem = new LocOrMenuItem(railway);
                        menuItem.Click += (s, x) => Execute(menuItem);
                        tbAddSpecial.DropDownItems.Add(menuItem);
                    }
                }

                UpdateToolbar();
            }
        }
Exemple #5
0
 /// <summary>
 /// Remove the given predicate from this node?
 /// </summary>
 internal abstract void Remove(PredicateItem child);
Exemple #6
0
 /// <summary>
 /// Can the given predicate be removed from this node?
 /// </summary>
 internal abstract bool CanRemove(PredicateItem child);
Exemple #7
0
 /// <summary>
 /// Remove the given predicate from this node?
 /// </summary>
 internal override void Remove(PredicateItem child)
 {
     // Do nothing
 }
Exemple #8
0
 /// <summary>
 /// Can the given predicate be removed from this node?
 /// </summary>
 internal override bool CanRemove(PredicateItem child)
 {
     return(false);
 }
Exemple #9
0
 /// <summary>
 /// Remove the given predicate from this node?
 /// </summary>
 internal override void Remove(PredicateItem child)
 {
     Nodes.Remove(child);
 }