예제 #1
0
        internal static void Parse(out ConditionList conditions,
            out OrderingList orderings,
            params IParameterMarker[] queryDesignerParameters)
        {
            conditions = new ConditionList();
            orderings = new OrderingList();

            foreach (IParameterMarker parameter in queryDesignerParameters)
            {
                if (parameter != null)
                {
                    if (parameter is ConditionList)
                    {
                        conditions.AddConditions(parameter as IEnumerable<BaseCondition>);
                    }
                    else if (parameter is OrderingList)
                    {
                        orderings.AddOrderings(parameter as OrderingList);
                    }
                    else
                    {
                        throw new NotSupportedException("parameter");
                    }
                }
                conditions.RemoveDuplicates();
                orderings.RemoveDuplicates();
            }
        }
        public void TestAggregateConditionAll()
        {
            const int freight = 0;
            var count = (from customer in context.Customers
                         where customer.Orders.All(order => order.Freight >= freight)
                         select customer).Count();

            QueryDesigner queryDesigner = new QueryDesigner(context, typeof(Customers));
            ConditionList conditions = new ConditionList(new Condition("Freight", freight, ConditionOperator.GreaterThanOrEqualTo));
            PredicateAggregationCondition predicateAggregationCondition = new AllCondition("Orders", conditions);
            queryDesigner.Where(predicateAggregationCondition);

            List<Customers> customers = queryDesigner.Cast<Customers>().ToList();

            Assert.AreEqual(count, customers.Count);

            count = (from customer in context.Customers
                     where !customer.Orders.All(order => order.Freight >= freight)
                     select customer).Count();

            queryDesigner = new QueryDesigner(context, typeof(Customers));
            conditions = new ConditionList(new Condition("Freight", freight, ConditionOperator.GreaterThanOrEqualTo));
            predicateAggregationCondition = new AllCondition("Orders", conditions, false);
            queryDesigner.Where(predicateAggregationCondition);

            customers = queryDesigner.Cast<Customers>().ToList();

            Assert.AreEqual(count, customers.Count);
        }
        public void TestAggregateConditionCount()
        {
            const int freight = 10;
            const int firstCountValue = 0;
            var count = (from customer in context.Customers
                         where customer.Orders.Count(order => order.Freight >= freight) > firstCountValue
                         select customer).Count();

            QueryDesigner queryDesigner = new QueryDesigner(context, typeof(Customers));
            ConditionList conditions = new ConditionList(new Condition("Freight", freight, ConditionOperator.GreaterThanOrEqualTo));
            PredicateAggregationCondition predicateAggregationCondition = new CountCondition("Orders", conditions, firstCountValue, ConditionOperator.GreaterThan);
            queryDesigner.Where(predicateAggregationCondition);

            List<Customers> customers = queryDesigner.Cast<Customers>().ToList();

            Assert.AreEqual(count, customers.Count);

            const int secondCountValue = 5;
            count = (from customer in context.Customers
                     where customer.Orders.Count(order => order.Freight >= freight) <= secondCountValue
                     select customer).Count();

            queryDesigner = new QueryDesigner(context, typeof(Customers));
            conditions = new ConditionList(new Condition("Freight", freight, ConditionOperator.GreaterThanOrEqualTo));
            predicateAggregationCondition = new CountCondition("Orders", conditions, secondCountValue, ConditionOperator.LessThanOrEqualTo);
            queryDesigner.Where(predicateAggregationCondition);

            customers = queryDesigner.Cast<Customers>().ToList();

            Assert.AreEqual(count, customers.Count);
        }
        public void TestExcept()
        {
            const int resultRowCount = 2;
            // create QueryDesigner with ElementType == Product
            var queryDesinger = new QueryDesigner(context, typeof(Product));

            //create root node which elementType has the same type in queryDesigner
            var root = new JoinNode(typeof(Product));

            // create child node Category with propertyName "Products".
            // Because Category linked with Product by next property:
            // public EntitySet<Product> Products
            var categoryNode = new JoinNode(typeof(Category),  "Category", "Products");

            // add categoryNode to root node
            root.AddChildren(categoryNode);

            // create filter by Product.ProductName like "%l%"
            var productNameCondition = new Condition("ProductName", "l", ConditionOperator.Like);
            // create filter by Category.Description like "Sweet%"
            var categoryNameCondition = new Condition("Description", "Sweet", ConditionOperator.StartsWith, typeof(Category));

            // create condition list with already created conditions
            var conditionList = new ConditionList(productNameCondition, categoryNameCondition);

            // make join Product table with Category filtered by conditions
            // and ordered by already created ordering
            queryDesinger = queryDesinger.Join(root, conditionList);

            QueryDesigner cloneQueryDesigner = (QueryDesigner)queryDesinger.Clone();

            queryDesinger = queryDesinger.Skip(0).Take(3);
            cloneQueryDesigner = cloneQueryDesigner.Skip(2).Take(4);

            queryDesinger = queryDesinger.Except(cloneQueryDesigner);

            var list = new List<Product>(queryDesinger.Cast<Product>());
            Assert.AreEqual(resultRowCount, list.Count);
        }
예제 #5
0
    public void Awake()
    {
        conditionListComponent = gameObject.GetComponent <ConditionList>();

        loader = GetComponent <LevelLoader>();
    }
        public void TestDataInNullableCondition()
        {
            var queryable = from order in context.Orders
                            where order.OrderDate < DateTime.Now
                            select order;
            var count = queryable.Count();

            var queryDesigner = new QueryDesigner(context, typeof(Order));
            var conditions = new ConditionList(new Condition("OrderDate", DateTime.Now, ConditionOperator.LessThan));
            queryDesigner = queryDesigner.Where(conditions);

            var resultCount = queryDesigner.Count();

            Assert.AreEqual(count, resultCount);
        }
예제 #7
0
 public void RemoveAt(int index)
 {
     ConditionList.RemoveAt(index);
 }
예제 #8
0
        public ConditionListView()
        {
            InitializeComponent();

            conditions = new ConditionList();

            Variables = new VariableList();
            Variables.Add(new Variable("Value0", 0));
            Variables.Add(new Variable("Value1", 1));
            Variables.Add(new Variable("Value2", 2));
            Variables.Add(new Variable("Value3", 3));
            Variables.Add(new Variable("Value4", 4));
            Variables.Add(new Variable("Value5", 5));
            Variables.Add(new Variable("Value6", 6));
            Variables.Add(new Variable("Value7", 7));
            Variables.Add(new Variable("Value8", 8));
            Variables.Add(new Variable("Value9", 9));
            Variables.Add(new Variable("Value10", 10));

            int testNum = 6;

            switch (testNum)
            {
            case 1:
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[4], Operator.EqualTo, 10));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                // Outcome:
                break;

            case 2:
                conditions.Add(new Condition(Variables[10], Operator.GreaterThan, 8, Grouping.OpenGrouping, Connector.And));
                // Outcome:
                break;

            case 3:
                conditions.Add(new Condition(Variables[7], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 10));
                // Outcome:
                break;

            case 4:
                conditions.Add(new Condition(Variables[1], Operator.NotEqualTo, 1, Grouping.OpenAndCloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 5:
                conditions.Add(new Condition(Variables[9], Operator.GreaterThanOrEqualTo, 8, Grouping.OpenGrouping, Connector.Xor));
                conditions.Add(new Condition(Variables[6], Operator.EqualTo, 6, Grouping.CloseGrouping, Connector.And));
                // Outcome:
                break;

            case 6:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[9], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[7], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[8], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[4], Operator.GreaterThanOrEqualTo, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[8], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[9], Operator.GreaterThan, 4, Grouping.NoGrouping, Connector.And));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                // Outcome: true
                break;

            case 7:
                conditions.Add(new Condition(Variables[1], Operator.LessThan, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[3], Operator.GreaterThan, 2, Grouping.OpenGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.EqualTo, 4));
                conditions.Add(new Condition(Variables[6], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.GreaterThan, 5, Grouping.CloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 8:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.And));
                // Outcome:
                break;

            case 9:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[1], Operator.GreaterThan, 4));
                conditions.Add(new Condition(Variables[2], Operator.LessThan, 5, Grouping.CloseGrouping, Connector.Or));
                // Outcome:
                break;

            case 10:
                conditions.Add(new Condition(Variables[10], Operator.EqualTo, 8, Grouping.OpenGrouping, Connector.And));
                conditions.Add(new Condition(Variables[9], Operator.LessThan, 15, Grouping.CloseGrouping, Connector.Or));
                conditions.Add(new Condition(Variables[5], Operator.NotEqualTo, 6, Grouping.NoGrouping, Connector.Or));
                // Outcome:
                break;

            default:
                break;
            }

            LoadList();
        }
예제 #9
0
 public void Insert(int index, Condition item)
 {
     ConditionList.Insert(index, item);
 }
예제 #10
0
 public bool Remove(Condition item)
 {
     return(ConditionList.Remove(item));
 }
예제 #11
0
 public int IndexOf(Condition item)
 {
     return(ConditionList.IndexOf(item));
 }
예제 #12
0
 public void CopyTo(Condition[] array, int arrayIndex)
 {
     ConditionList.CopyTo(array, arrayIndex);
 }
예제 #13
0
 /// <summary> 
 /// Required method for Designer support - do not modify 
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ConditionListButtons));
     this.conditionList = new Maestro.Editors.LayerDefinition.Vector.Scales.ConditionList();
     this.label1 = new System.Windows.Forms.Label();
     this.label3 = new System.Windows.Forms.Label();
     this.label4 = new System.Windows.Forms.Label();
     this.AddRuleButton = new System.Windows.Forms.Button();
     this.CopyRuleButton = new System.Windows.Forms.Button();
     this.CreateThemeButton = new System.Windows.Forms.Button();
     this.MoveRuleDownButton = new System.Windows.Forms.Button();
     this.MoveRuleUpButton = new System.Windows.Forms.Button();
     this.panel1 = new System.Windows.Forms.Panel();
     this.btnExplodeTheme = new System.Windows.Forms.Button();
     this.ShowInLegend = new System.Windows.Forms.CheckBox();
     this.toolTips = new System.Windows.Forms.ToolTip(this.components);
     this.panel1.SuspendLayout();
     this.SuspendLayout();
     //
     // conditionList
     //
     resources.ApplyResources(this.conditionList, "conditionList");
     this.conditionList.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
     this.conditionList.Name = "conditionList";
     this.conditionList.ItemChanged += new System.EventHandler(this.conditionList_ItemChanged);
     //
     // label1
     //
     resources.ApplyResources(this.label1, "label1");
     this.label1.Name = "label1";
     //
     // label3
     //
     resources.ApplyResources(this.label3, "label3");
     this.label3.Name = "label3";
     //
     // label4
     //
     resources.ApplyResources(this.label4, "label4");
     this.label4.Name = "label4";
     //
     // AddRuleButton
     //
     this.AddRuleButton.Image = global::Maestro.Editors.Properties.Resources.plus_circle;
     resources.ApplyResources(this.AddRuleButton, "AddRuleButton");
     this.AddRuleButton.Name = "AddRuleButton";
     this.toolTips.SetToolTip(this.AddRuleButton, resources.GetString("AddRuleButton.ToolTip"));
     this.AddRuleButton.UseVisualStyleBackColor = true;
     this.AddRuleButton.Click += new System.EventHandler(this.AddRuleButton_Click);
     //
     // CopyRuleButton
     //
     resources.ApplyResources(this.CopyRuleButton, "CopyRuleButton");
     this.CopyRuleButton.Image = global::Maestro.Editors.Properties.Resources.document_copy;
     this.CopyRuleButton.Name = "CopyRuleButton";
     this.toolTips.SetToolTip(this.CopyRuleButton, resources.GetString("CopyRuleButton.ToolTip"));
     this.CopyRuleButton.UseVisualStyleBackColor = true;
     this.CopyRuleButton.Click += new System.EventHandler(this.CopyRuleButton_Click);
     //
     // CreateThemeButton
     //
     resources.ApplyResources(this.CreateThemeButton, "CreateThemeButton");
     this.CreateThemeButton.Name = "CreateThemeButton";
     this.toolTips.SetToolTip(this.CreateThemeButton, resources.GetString("CreateThemeButton.ToolTip"));
     this.CreateThemeButton.UseVisualStyleBackColor = true;
     this.CreateThemeButton.Click += new System.EventHandler(this.CreateThemeButton_Click);
     //
     // MoveRuleDownButton
     //
     resources.ApplyResources(this.MoveRuleDownButton, "MoveRuleDownButton");
     this.MoveRuleDownButton.Image = global::Maestro.Editors.Properties.Resources.arrow_270;
     this.MoveRuleDownButton.Name = "MoveRuleDownButton";
     this.toolTips.SetToolTip(this.MoveRuleDownButton, resources.GetString("MoveRuleDownButton.ToolTip"));
     this.MoveRuleDownButton.UseVisualStyleBackColor = true;
     this.MoveRuleDownButton.Click += new System.EventHandler(this.MoveRuleDownButton_Click);
     //
     // MoveRuleUpButton
     //
     resources.ApplyResources(this.MoveRuleUpButton, "MoveRuleUpButton");
     this.MoveRuleUpButton.Image = global::Maestro.Editors.Properties.Resources.arrow_090;
     this.MoveRuleUpButton.Name = "MoveRuleUpButton";
     this.toolTips.SetToolTip(this.MoveRuleUpButton, resources.GetString("MoveRuleUpButton.ToolTip"));
     this.MoveRuleUpButton.UseVisualStyleBackColor = true;
     this.MoveRuleUpButton.Click += new System.EventHandler(this.MoveRuleUpButton_Click);
     //
     // panel1
     //
     this.panel1.Controls.Add(this.btnExplodeTheme);
     this.panel1.Controls.Add(this.ShowInLegend);
     this.panel1.Controls.Add(this.MoveRuleUpButton);
     this.panel1.Controls.Add(this.MoveRuleDownButton);
     this.panel1.Controls.Add(this.CreateThemeButton);
     this.panel1.Controls.Add(this.CopyRuleButton);
     this.panel1.Controls.Add(this.AddRuleButton);
     this.panel1.Controls.Add(this.label4);
     this.panel1.Controls.Add(this.label3);
     this.panel1.Controls.Add(this.label1);
     resources.ApplyResources(this.panel1, "panel1");
     this.panel1.Name = "panel1";
     //
     // btnExplodeTheme
     //
     this.btnExplodeTheme.Image = global::Maestro.Editors.Properties.Resources.arrow_split;
     resources.ApplyResources(this.btnExplodeTheme, "btnExplodeTheme");
     this.btnExplodeTheme.Name = "btnExplodeTheme";
     this.toolTips.SetToolTip(this.btnExplodeTheme, resources.GetString("btnExplodeTheme.ToolTip"));
     this.btnExplodeTheme.UseVisualStyleBackColor = true;
     this.btnExplodeTheme.Click += new System.EventHandler(this.btnExplodeTheme_Click);
     //
     // ShowInLegend
     //
     resources.ApplyResources(this.ShowInLegend, "ShowInLegend");
     this.ShowInLegend.Checked = true;
     this.ShowInLegend.CheckState = System.Windows.Forms.CheckState.Checked;
     this.ShowInLegend.Name = "ShowInLegend";
     this.toolTips.SetToolTip(this.ShowInLegend, resources.GetString("ShowInLegend.ToolTip"));
     this.ShowInLegend.UseVisualStyleBackColor = true;
     this.ShowInLegend.CheckedChanged += new System.EventHandler(this.ShowInLegend_CheckedChanged);
     //
     // ConditionListButtons
     //
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
     this.Controls.Add(this.conditionList);
     this.Controls.Add(this.panel1);
     this.Name = "ConditionListButtons";
     resources.ApplyResources(this, "$this");
     this.panel1.ResumeLayout(false);
     this.panel1.PerformLayout();
     this.ResumeLayout(false);
 }
예제 #14
0
        private ServiceEntity(XmlElement definition)
        {
            XmlHelper h = new XmlHelper(definition);
            this.SQLTemplate = h.GetText("SQLTemplate");
            ResponseRecordElement = h.GetText("ResponseRecordElement");
            RequestRecordElement = h.GetText("RequestRecordElement");
            FieldList = new FieldList(h.GetElement("FieldList"));
            ConditionList = new ConditionList(h.GetElement("Conditions"));
            Orders = new OrderList(h.GetElement("Orders"));
            Pagination = new Pagination(h.GetElement("Pagination"));
           
            ServiceAction action = ServiceAction.Select;
            if (!Enum.TryParse<ServiceAction>(h.GetText("Action"), true, out action))
                action = ServiceAction.Select;
            Action = action;

            this.Variables = new List<IVariable>();
            foreach (XmlElement varElement in h.GetElements("InternalVariable/Variable"))
            {
                IVariable v = VariableFactory.Parse(varElement);
                if (v != null)
                    Variables.Add(v);
            }

            this.Converters = new List<IConverter>();
            foreach (XmlElement cvElement in h.GetElements("Converters/Converter"))
            {
                string type = cvElement.GetAttribute("Type");
                IConverter c = ConverterProvider.CreateConverter(type);
                c.Load(cvElement);

                this.Converters.Add(c);
            }

            this.Preprocesses = new List<Preprocess>();
            foreach (XmlElement preElement in h.GetElements("Preprocesses/Preprocess"))
            {
                Preprocess p = Preprocess.Parse(preElement);
                this.Preprocesses.Add(p);
            }
        }
예제 #15
0
 IEnumerator <Condition> IEnumerable <Condition> .GetEnumerator()
 {
     return(ConditionList.GetEnumerator());
 }
        public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");
            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Delete.ToString());
            
            XmlElement sqlTmp = h.AddElement(".", "SQLTemplate");
            XmlCDataSection section = sqlTmp.OwnerDocument.CreateCDataSection(this.txtSQLTemplate.Text);
            sqlTmp.AppendChild(section);

            h.AddElement(".", "RequestRecordElement", txtRequestElement.Text);

            ConditionList conditions = new ConditionList(this.txtConditionName.Text, this.txtConditionSource.Text,chkRequired.Checked);
            foreach (DataGridViewRow row in this.dgConditions.Rows)
            {
                Condition condition = Condition.Parse(row);
                conditions.Conditions.Add(condition);
            }
            h.AddElement(".", conditions.GetXml());

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");                
                foreach (IVariable v in this.Service.Variables)                
                    h.AddElement("InternalVariable", v.GetXml());                
            }

            if (this.Service.Converters.Count > 0)
            {
                XmlElement cvElement = h.AddElement(".", "Converters");
                foreach (IConverter c in this.Service.Converters)
                    h.AddElement("Converters", c.Output());
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null) continue;

                    h.AddElement("Preprocesses", pp.GetXml());                    
                }
            }
            return h.GetElement(".");
        }
예제 #17
0
 public void Clear()
 {
     ConditionList.Clear();
 }
예제 #18
0
 public override void FinishWork()
 {
     CurrentDataSource.FinishWork();
     ConditionList.ForEach(v => v.FinishWork());
     PredicateList.ForEach(v => v.FinishWork());
 }
예제 #19
0
 public IEnumerator GetEnumerator()
 {
     return(ConditionList.GetEnumerator());
 }
예제 #20
0
        public void TestNullInNullableCondition()
        {
            var queryable = from order in context.Orders
                            where order.OrderDate == null
                            select order;
            var count = queryable.Count();

            var queryDesigner = new QueryDesigner(context, typeof(Order));
            var conditions = new ConditionList(new Condition("OrderDate", null));
            queryDesigner = queryDesigner.Where(conditions);

            var resultCount = queryDesigner.Count();

            Assert.AreEqual(count, resultCount);
        }
예제 #21
0
 public void Add(Condition item)
 {
     ConditionList.Add(item);
 }
예제 #22
0
        public void TestEnumInCondition()
        {
            var count = (from order in context.Orders
                         where order.OrderDate.Value.DayOfWeek == DayOfWeek.Monday
                         select order).Count();

            QueryDesigner queryDesigner = new QueryDesigner(context, typeof(Order));
            ConditionList conditions = new ConditionList(new Condition("OrderDate.Value.DayOfWeek", DayOfWeek.Monday));
            queryDesigner = queryDesigner.Where(conditions);

            var resultCount = queryDesigner.Count();

            Assert.AreEqual(count, resultCount);
        }
예제 #23
0
 public bool Contains(Condition item)
 {
     return(ConditionList.Contains(item));
 }
예제 #24
0
        public void TestFirstOrDefault()
        {
            // create QueryDesigner with ElementType == Product
            var queryDesinger = new QueryDesigner(context, typeof(Product));

            //create root node which elementType has the same type in queryDesigner
            var root = new JoinNode(typeof(Product));

            // create child node Category with propertyName "Products".
            // Because Category linked with Product by next property:
            // public EntitySet<Product> Products
            var categoryNode = new JoinNode(typeof(Category),  "Category", "Products");

            // add categoryNode to root node
            root.AddChildren(categoryNode);

            // create filter by Product.ProductName like "%l%"
            var productNameCondition = new Condition("ProductName", "l", ConditionOperator.Like);
            // create filter by Category.Description like "Sweet%"
            var categoryNameCondition = new Condition("Description", "Sweet", ConditionOperator.StartsWith, typeof(Category));

            // create condition list with already created conditions
            var conditionList = new ConditionList(productNameCondition, categoryNameCondition);

            // make join Product table with Category filtered by conditions
            // and ordered by already created ordering
            queryDesinger.Join(root, conditionList);

            object first = queryDesinger.FirstOrDefault();

            Assert.IsInstanceOfType(typeof(Product), first);
        }
예제 #25
0
        /// <summary>
        /// 初始化写数函数
        /// </summary>
        /// <param name="FunctionInfo"></param>
        public void InitFunctionInfo(WriteDataFunctionInfo FunctionInfo)
        {
            this.FunctionInfo = FunctionInfo;
            //显示写数函数的名称
            TextBox_FunctionName.Text = FunctionInfo.Name;
            ReadFromTableName         = FunctionInfo.ReadOutTableIndex;

            //显示写数函数的写入数据的数据表
            if (!string.IsNullOrEmpty(FunctionInfo.WriteInTableIndex))
            {
                TreeNode[] Nodes = SheetList.Nodes.Find(FunctionInfo.WriteInTableIndex, true);
                if (Nodes.Length > 0)
                {
                    SheetList.SelectedNode = Nodes[0];
                    InitFields(Nodes[0]);
                }
            }

            //显示写数函数的过滤条件

            //绑定数据时保证显示第一行,以免报错“System.ArgumentOutOfRangeException: Invalid low bound argument”
            if (ConditionList.ActiveSheet.Rows.Count > 0)
            {
                ConditionList.ShowRow(ConditionList.GetActiveRowViewportIndex(), 0, VerticalPosition.Top);
            }

            ConditionList.ActiveSheet.Rows.Count = 0;
            ConditionList.ActiveSheet.Rows.Count = 600;
            foreach (ExpressionInfo Info in FunctionInfo.Conditions)
            {
                ConditionList.ActiveSheet.Rows.Add(0, 1);
                ConditionList.ActiveSheet.Rows[0].Tag = Info;

                foreach (FieldInfo fieldInfo in WriteToTable_DataItem_Editor.Items)
                {
                    if (fieldInfo.Name == Info.DataItem.Name)
                    {
                        ConditionList.ActiveSheet.Cells[0, 0].Value = fieldInfo;
                        break;
                    }
                }

                TreeNode[] dropDownNodes = WriteToTable_Value_Editor.DropDownControl.Nodes.Find(Info.DataValue.Name, true);
                if (dropDownNodes.Length > 0)
                {
                    WriteToTable_Value_Editor.DropDownControl.SelectedNode = dropDownNodes[0];
                    ConditionList.ActiveSheet.Cells[0, 2].Value            = dropDownNodes[0].Tag as FieldInfo;
                }

                ConditionList.ActiveSheet.Cells[0, 1].Value = Info.Operation;
            }

            //显示写数函数的修改数据项

            //绑定数据时保证显示第一行,以免报错“System.ArgumentOutOfRangeException: Invalid low bound argument”
            if (ModificationList.ActiveSheet.Rows.Count > 0)
            {
                ModificationList.ShowRow(ModificationList.GetActiveRowViewportIndex(), 0, VerticalPosition.Top);
            }

            ModificationList.ActiveSheet.Rows.Count = 0;
            ModificationList.ActiveSheet.Rows.Count = 600;
            foreach (ExpressionInfo Info in FunctionInfo.Modifications)
            {
                ModificationList.ActiveSheet.Rows.Add(0, 1);
                ModificationList.ActiveSheet.Rows[0].Tag = Info;

                foreach (FieldInfo fieldInfo in Modification_DataItem_Editor.Items)
                {
                    if (fieldInfo.Name == Info.DataItem.Name)
                    {
                        ModificationList.ActiveSheet.Cells[0, 0].Value = fieldInfo;
                        break;
                    }
                }

                TreeNode[] dropDownNodes = ModificationValue_Editor.DropDownControl.Nodes.Find(Info.DataValue.Name, true);
                if (dropDownNodes.Length > 0)
                {
                    ModificationValue_Editor.DropDownControl.SelectedNode = dropDownNodes[0];
                    ModificationList.ActiveSheet.Cells[0, 2].Value        = dropDownNodes[0].Tag as FieldInfo;
                }

                ModificationList.ActiveSheet.Cells[0, 1].Value = Info.Operation;
            }
        }
        private Expression MakeInnerJoin(Expression outerExpression, Expression innerExpression,
            string[] leftFieldsNames, string[] rightFieldsNames,
            ConditionList conditions)
        {
            Checker.CheckArgumentNull(outerExpression, "outerExpression");
            Checker.CheckArgumentNull(innerExpression, "innerExpression");
            Checker.CheckArgumentNull(leftFieldsNames, "leftFieldsNames");
            Checker.CheckArgumentNull(outerExpression, "outerExpression");

            int fieldsCount = leftFieldsNames.Length;
            if (fieldsCount != rightFieldsNames.Length)
            {
                throw new SpoltyException("Number of fields mismatch");
            }

            Type outerType = ExpressionHelper.GetGenericType(outerExpression);
            ParameterExpression outerParam = ExpressionHelper.CreateOrGetParameterExpression(outerType, outerType.Name, Factory.Store);
            Type innerType = ExpressionHelper.GetGenericType(innerExpression);
            ParameterExpression innerParam = ExpressionHelper.CreateOrGetParameterExpression(innerType, innerType.Name, Factory.Store);

            var clw = new ConditionList();

            for (int index = 1; index < fieldsCount; index++)
            {
                var fieldCondition =
                    new FieldCondition(leftFieldsNames[index],
                                       ConditionOperator.EqualTo, rightFieldsNames[index], outerType, innerType);
                clw.Add(fieldCondition);
            }

            PropertyInfo outerPropertyInfo = outerType.GetProperty(leftFieldsNames[0]);
            if (outerPropertyInfo == null)
            {
                throw new SpoltyException("Property not found");
            }
            PropertyInfo innerPropertyInfo = innerType.GetProperty(rightFieldsNames[0]);
            if (innerPropertyInfo == null)
            {
                throw new SpoltyException("Property not found");
            }

            Expression outerPropertyExpression = Expression.Property(outerParam, outerPropertyInfo);
            Expression innerPropertyExpression = Expression.Property(innerParam, innerPropertyInfo);

            Type type = outerPropertyInfo.PropertyType;
            innerPropertyExpression =
                ExpressionHelper.ConvertOrCastInnerPropertyExpression(type, innerPropertyInfo, innerPropertyExpression);

            LambdaExpression outerKeySelector = Expression.Lambda(outerPropertyExpression, outerParam);
            LambdaExpression innerKeySelector = Expression.Lambda(innerPropertyExpression, innerParam);
            LambdaExpression resultSelector = Expression.Lambda(outerParam, outerParam, innerParam);

            if (conditions != null && conditions.Count > 0)
            {
                clw.AddConditions(conditions);
            }

            Expression resultJoinExpression = CallJoinMethod(outerExpression, innerExpression, outerKeySelector,
                                                             innerKeySelector,
                                                             resultSelector);
            resultJoinExpression = Factory.CreateConditionExpressionMaker().Make(clw, resultJoinExpression);
            return resultJoinExpression;
        }
예제 #27
0
 void OnEnable()
 {
     t         = (ConditionList)target;
     GetTarget = new SerializedObject(t);
     ThisList  = GetTarget.FindProperty("conditionList"); // Find the List in our script and create a refrence of it
 }
        public void TestComplicatedJoinWithFilters()
        {
            const int regionId = 4;
            const string territoryDescription = "Orlando";
            const int resultRowCount = 23;
            //create root node
            var root = new JoinNode(typeof(Products));

            // add second child node Order_Details. PropertyName not defined
            // because Order_Details linked with Products by next property:
            // public Products Products - name of property is equal name of type
            var orderDetailNode = new JoinNode(typeof(Order_Details), "Order_Detail", "Products");
            var categoryNode = new JoinNode(typeof(Categories), "Category", "Products", JoinType.LeftOuterJoin);
            var supplierNode = new JoinNode(typeof(Suppliers), "Supplier", "Products");
            root.AddChildren(orderDetailNode, categoryNode, supplierNode);

            var orderNode = new JoinNode(typeof(Orders), "Order", "Order_Details");
            orderDetailNode.AddChildren(orderNode);

            var employeeNode = new JoinNode(typeof(Employees), "Employee", "Orders");
            orderNode.AddChildren(employeeNode);

            var territoryNode = new JoinNode(typeof(Territories), "Territory", "Employees");
            employeeNode.AddChildren(territoryNode);

            var regionNode = new JoinNode(typeof(Region), "Region", "Territories");
            territoryNode.AddChildren(regionNode);

            var queryDesinger = new QueryDesigner(context, root);

            // create conditions for filtering by RegionID = 4 and TerritoryDescription like "Orlando%" and (CategoryID == 4 or CategoryID == 5 or CategoryID == 6)
            var regionCondition = new Condition("RegionID", regionId, ConditionOperator.EqualTo, typeof(Region));
            var territoryCondition = new Condition("TerritoryDescription", territoryDescription,
                                                   ConditionOperator.StartsWith, typeof(Territories));
            OrCondition categoryIDsCondition = OrCondition.Create("CategoryID", new object[] { 4, 5, 6 }, ConditionOperator.EqualTo, typeof(Categories));

            var conditionals = new ConditionList(regionCondition, territoryCondition, categoryIDsCondition);

            // assign conditions
            queryDesinger.Where(conditionals);

            // make Distinct
            IQueryable<Products> distictedProducts = queryDesinger.Distinct().Cast<Products>();

            var list = new List<Products>(distictedProducts);
            Assert.AreEqual(resultRowCount, list.Count);

            string query =
                @"SELECT  DISTINCT  Products.ProductID, Products.ProductName, Products.SupplierID, Products.CategoryID, Products.QuantityPerUnit, Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Products.Discontinued
                  FROM         Orders
                          INNER JOIN [Orders Details] ON Orders.OrderID = [Orders Details].OrderID
                          INNER JOIN Products ON [Orders Details].ProductID = Products.ProductID
                          INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
                          INNER JOIN EmployeeTerritories ON Employees.EmployeeID = EmployeeTerritories.EmployeeID
                          INNER JOIN Territories ON EmployeeTerritories.TerritoryID = Territories.TerritoryID
                          INNER JOIN Region ON Territories.RegionID = Region.RegionID
                  WHERE     (Region.RegionID = 4) AND (Territories.TerritoryDescription like 'Orlando%') AND
                              (Products.CategoryID IN (4, 5, 6)) ";

            CheckDataWithExecuteReaderResult(query, resultRowCount, list);
        }
예제 #29
0
 public Condition this[string input] => ConditionList.FirstOrDefault(x => x.Input.Equals(input));
        public void TestJoinWithTwoChildrenAndComplicatedFilterAndOrderings()
        {
            const string productName = "Louisiana";
            const string categoryName = "Condiments";
            const int resultRowCount = 9;
            //create root node
            var root = new JoinNode(typeof(Products));

            // add first child node Categories with propertyName "Products".
            // Because Categories linked with Products by next property:
            // public EntitySet<Products> Products
            var categoryNode = new JoinNode(typeof(Categories), "Category", "Products");
            root.AddChildren(categoryNode);

            // add second child node Order_Details. PropertyName not defined
            // because Order_Details linked with Products by next property:
            // public Products Products - name of property is equal name of type
            var orderDetailNode = new JoinNode(typeof(Order_Details), "Order_Detail", "Products");

            root.AddChildren(orderDetailNode);

            var queryDesinger = new QueryDesigner(context, root);

            // create conditions for filtering by ProductName Like "Louisiana%" Or CategoryName == "Condiments"
            var productCondition = new Condition("ProductName", productName, ConditionOperator.StartsWith,
                                                 typeof(Products));
            var categoryCondition = new Condition("CategoryName", categoryName, ConditionOperator.EqualTo,
                                                  typeof(Categories));
            var orCondition = new OrCondition(productCondition, categoryCondition);

            // create condition for filtering by [Orders Details].Discount > 0.15
            var discountCondition = new Condition("Discount", 0.15F, ConditionOperator.GreaterThan,
                                                  typeof(Order_Details));

            var conditionals = new ConditionList(orCondition, discountCondition);

            // assign conditions
            //            queryDesinger.Where(conditionals);

            // make Distinct
            queryDesinger.Distinct();

            // make orderings by ProductName and CategoryName
            var productNameOrder = new Ordering("ProductName", SortDirection.Ascending, typeof(Products));
            //            var categoryNameOrder = new Ordering("CategoryName", SortDirection.Descending, typeof(Categories));

            queryDesinger.OrderBy(new OrderingList(productNameOrder/*, categoryNameOrder*/));

            IQueryable<Products> distictedProducts = queryDesinger.Cast<Products>();

            var list = new List<Products>(distictedProducts);
            Assert.AreEqual(resultRowCount, list.Count);

            string query =
                @" SELECT   DISTINCT  Products.ProductID, Products.ProductName, Products.SupplierID, Products.CategoryID, Products.QuantityPerUnit, Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Products.Discontinued
                           FROM         Products
                                   INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID
                                   INNER JOIN [Orders Details] ON Products.ProductID = [Orders Details].ProductID
                           WHERE   [Orders Details].Discount > 0.15
                                   AND ((Products.ProductName LIKE N'Louisiana%') OR (Categories.CategoryName = N'Condiments'))";

            CheckDataWithExecuteReaderResult(query, resultRowCount, list);
        }
        public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");
            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Select.ToString());
            
            XmlElement sqlTmp = h.AddElement(".", "SQLTemplate");
            XmlCDataSection section = sqlTmp.OwnerDocument.CreateCDataSection(this.txtSQLTemplate.Text);
            sqlTmp.AppendChild(section);

            h.AddElement(".", "ResponseRecordElement", txtRequestElement.Text);
            FieldList fields = new FieldList(this.txtFieldListName.Text, this.txtFieldListSource.Text);
            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                Field f = Field.Parse(row);
                fields.Fields.Add(f);
            }
            h.AddElement(".", fields.GetXml(ServiceAction.Select));

            ConditionList conditions = new ConditionList(this.txtConditionName.Text, this.txtConditionSource.Text,chkRequired.Checked);
            foreach (DataGridViewRow row in this.dgConditions.Rows)
            {
                Condition condition = Condition.Parse(row);
                conditions.Conditions.Add(condition);
            }
            h.AddElement(".", conditions.GetXml());

            OrderList orders = new OrderList(txtOrderName.Text, txtOrderSource.Text);
            foreach (DataGridViewRow row in dgOrder.Rows)
            {
                string target = row.Cells[colOrderTarget.Name].Value + string.Empty;
                string source = row.Cells[colOrderSource.Name].Value + string.Empty;
                Order o = new Order(target,source);
                orders.Orders.Add(o);
            }
            h.AddElement(".", orders.GetXml());

            int max = 0;
            if (!int.TryParse(txtMaxPageSize.Text, out max))
                max = 0;
            Pagination p = new Pagination(chkAllowPagination.Checked, max);
            h.AddElement(".", p.GetXml());

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");                
                foreach (IVariable v in this.Service.Variables)                
                    h.AddElement("InternalVariable", v.GetXml());                
            }

            if (this.Service.Converters.Count > 0)
            {
                XmlElement cvElement = h.AddElement(".", "Converters");
                foreach (IConverter c in this.Service.Converters)
                    h.AddElement("Converters", c.Output());
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null) continue;

                    h.AddElement("Preprocesses", pp.GetXml());                    
                }
            }
            return h.GetElement(".");
        }
        private Expression MakeSimpleCondition(
            Condition condition,
            Expression parameterExpression,
            ref Expression sourceExpression)
        {
            Expression body = null;
            const int mainPropertyIndex = 0;
            const int secondaryPropertyIndex = 1;
            string[] properties = condition.FieldName.Split('.');
            Type sourceType = ExpressionHelper.GetGenericType(sourceExpression);
            Type parameterType = ExpressionHelper.GetGenericType(parameterExpression);

            Type workType = sourceType.Name == parameterType.Name ? sourceType : parameterType;
            PropertyInfo propertyInfo = workType.GetProperty(properties[mainPropertyIndex]);

            if (propertyInfo != null)
            {
                Expression memberExpression = Expression.Property(parameterExpression, propertyInfo);
                PropertyInfo childPropertyInfo = propertyInfo;
                var value = condition.Value;
                for (int index = secondaryPropertyIndex; index < properties.Length; index++)
                {
                    if (childPropertyInfo != null)
                    {
                        childPropertyInfo = childPropertyInfo.PropertyType.GetProperty(properties[index]);
                    }

                    if (childPropertyInfo == null)
                    {
                        if (ReflectionHelper.IsImplementingInterface(propertyInfo.PropertyType, ExpressionHelper.GenericIEnumerableType))
                        {
                            int previousIndex = index - 1;
                            var innerCondition =
                                new Condition(condition.FieldName.Remove(0, properties[previousIndex].Length + 1), value,
                                              condition.Operator);
                            var innerConditions = new ConditionList(innerCondition);

                            IQueryable innerSource = Factory.GetTable(ReflectionHelper.GetGenericType(propertyInfo.PropertyType));

                            Expression innerExpression = Make(innerConditions, innerSource.Expression);

                            //TODO: new JoinExpressionMaker(Factory).MakeInnerJoin
                            sourceExpression = new JoinExpressionMaker(Factory).MakeInnerJoin(sourceExpression, innerExpression,
                                                                                              innerSource.ElementType,
                                                                                              sourceType);
                        }

                        return body;
                    }
                    memberExpression = Expression.Property(memberExpression, childPropertyInfo);
                }

                Expression constantExpression;

                Type propertyType = ReflectionHelper.GetGenericType(childPropertyInfo.PropertyType);

                Type valueType;
                if (ReflectionHelper.IsNullableType(childPropertyInfo.PropertyType) && value == null)
                {
                    valueType = propertyType;
                }
                else
                {
                    valueType = value.GetType();
                }

                if (valueType == propertyType || !ReflectionHelper.IsConvertible(propertyType))
                {
                    constantExpression = Expression.Constant(value, childPropertyInfo.PropertyType);
                }
                else
                {
                    constantExpression = Expression.Constant(Convert.ChangeType(value, propertyType),
                                                             childPropertyInfo.PropertyType);
                }

                body = MakeComparisonExpression(memberExpression, constantExpression, condition.Operator);
            }

            return body;
        }
예제 #33
0
 public override void SaveOriginalStatus()
 {
     CurrentDataSource.SaveOriginalStatus();
     ConditionList.ForEach(v => v.SaveOriginalStatus());
     PredicateList.ForEach(v => v.SaveOriginalStatus());
 }
예제 #34
0
        /// <summary>
        /// Creates <see cref="OrCondition"/> with the same <paramref name="fieldName"/> cref="fieldName"/> and differents <paramref name="values"/>.
        /// </summary>
        /// <param name="fieldName">name of a field which mapped with table.</param>
        /// <param name="values"></param>
        /// <param name="operator"></param>
        /// <param name="entityType">defines filtering Entity.</param>
        /// <returns><see cref="OrCondition"/> which contains <see cref="Condition"/> where the same 
        /// <paramref name="fieldName"/> and differents <paramref name="values"/>.
        /// </returns>
        public static OrCondition Create(string fieldName, object[] values, ConditionOperator @operator, Type entityType)
        {
            Checker.CheckArgumentNull(fieldName, "fieldName");

            if (values == null || values.Length == 0)
            {
                throw new ArgumentNullException("values");
            }

            var conditionList = new ConditionList();
            conditionList.AddConditions(fieldName, values, @operator, entityType);

            return new OrCondition(conditionList);
        }
        public XmlElement GetResult()
        {
            //TODO
            XmlHelper h = new XmlHelper("<Definition />");

            h.SetAttribute(".", "Type", "DBHelper");
            h.AddElement(".", "Action", ServiceAction.Update.ToString());

            XmlElement      sqlTmp  = h.AddElement(".", "SQLTemplate");
            XmlCDataSection section = sqlTmp.OwnerDocument.CreateCDataSection(this.txtSQLTemplate.Text);

            sqlTmp.AppendChild(section);

            h.AddElement(".", "RequestRecordElement", txtRequestElement.Text);
            FieldList fields = new FieldList(this.txtFieldListName.Text, this.txtFieldListSource.Text);

            foreach (DataGridViewRow row in this.dgFieldList.Rows)
            {
                Field f = Field.Parse(row);
                fields.Fields.Add(f);
            }
            h.AddElement(".", fields.GetXml(ServiceAction.Update));

            ConditionList conditions = new ConditionList(this.txtConditionName.Text, this.txtConditionSource.Text, chkRequired.Checked);

            foreach (DataGridViewRow row in this.dgConditions.Rows)
            {
                Condition condition = Condition.Parse(row);
                conditions.Conditions.Add(condition);
            }
            h.AddElement(".", conditions.GetXml());

            if (this.Service.Variables.Count > 0)
            {
                XmlElement varElement = h.AddElement(".", "InternalVariable");
                foreach (IVariable v in this.Service.Variables)
                {
                    h.AddElement("InternalVariable", v.GetXml());
                }
            }

            if (this.Service.Converters.Count > 0)
            {
                XmlElement cvElement = h.AddElement(".", "Converters");
                foreach (IConverter c in this.Service.Converters)
                {
                    h.AddElement("Converters", c.Output());
                }
            }

            if (this.dgProcessor.Rows.Count > 0)
            {
                XmlElement proElement = h.AddElement(".", "Preprocesses");
                foreach (DataGridViewRow row in this.dgProcessor.Rows)
                {
                    Preprocess pp = row.Tag as Preprocess;
                    if (pp == null)
                    {
                        continue;
                    }

                    h.AddElement("Preprocesses", pp.GetXml());
                }
            }
            return(h.GetElement("."));
        }