private static (CommandList, IEnumerable <Token>) ParseCommandList(IEnumerable <Token> tokens) { var input = tokens.Skip(0); var andors = new List <(AndOr, CCSeparator)>(); AndOr last = null; IEnumerable <Token> rest = null; do { (last, rest) = ParseAndOr(input); if (last == null) { return(null, null); } if (!rest.Any() || !ccseps.Contains(rest.First().Value)) { input = rest; break; } switch (rest.First().Value) { case "&": andors.Add((last, CCSeparator.AMPERSAND)); break; case ";": andors.Add((last, CCSeparator.SEMICOLON)); break; } input = rest.Skip(1); } while (true); andors.Add((last, CCSeparator.END)); return(new CommandList(andors), input); }
public void LoadXml(XElement InputXml) { if (InputXml == null) { return; } foreach (XElement subx in InputXml.Elements()) { IStringMatchingRule newrule = MatchingRuleFactory.GetRuleObject(subx, this._owner); if (newrule != null) { this._rules.Add(newrule); } } XAttribute xa = InputXml.Attribute("Type"); if (xa != null) { if (xa.Value == "AND") { this._ruletype = AndOr.AND; } } this.Not = XmlHandler.GetBoolFromXAttribute(InputXml, "Not", this.Not); }
public void AddFilter(BusinessFilter _filter, AndOr andor) { string strfilter; if (_filter == null || _filter.Filter == null || _filter.Filter.Equals(string.Empty)) { return; } strfilter = _filter.Filter.Trim(); if (strfilter.IndexOf(AndOr.AND.ToString(), 0, strfilter.Length) == 0) { strfilter = strfilter.Substring(4, strfilter.Length - 4); } else { strfilter = strfilter.Substring(3, strfilter.Length - 3); } if (this.filter == null || this.filter.Equals(string.Empty)) { this.filter = string.Format(" {0} ( {1} ) ", andor.ToString(), strfilter); } else { this.filter = string.Format("{0} {1} {2} )", this.filter, andor.ToString(), strfilter); } }
/// <summary> Custom contructor. Uses the default ArgumentOperator. </summary> /// <param name="Column"> Parameter Column. </param> /// <param name="Value"> Parameter Value. </param> /// <param name="Type"> Parameter Type. </param> /// <param name="AndOr"> Parameter AndOr. Chooses between AND or OR in your query. </param> /// <example> ArgumentType("Username", "ziggo", typeof(string), AndOr.OR); </example> public ArgumentType(string Column, string Value, Type Type, AndOr AndOr) { this.Column = Column; this.Value = Value; this.Type = Type; this.AndOr = AndOr; this.ArgsOp = ArgumentOperator.EQUEL; }
public void AddCustomerFilter(string where, AndOr andor) { if (where.Equals(string.Empty)) { return; } if (filter.Equals(string.Empty)) { this.filter = string.Format("{0} ({1} ", andor.ToString(), where); } else { this.filter = string.Format("{0} {1} {2} ", this.filter, andor.ToString(), where); } }
public ConditionAndOrBlock(string namePrefix, IExpressionViewModel expressionViewModel, string nameSuffix, bool isAddBlock) : base(namePrefix + " ... " + nameSuffix, expressionViewModel) { AndOr = new AndOr(); if (isAddBlock) { AndOr = WithElement(AndOr) as AndOr; } if (!string.IsNullOrEmpty(namePrefix)) { WithLabel(namePrefix); } AllAny = WithElement(new AllAny()) as AllAny; if (!string.IsNullOrEmpty(nameSuffix)) { WithLabel(nameSuffix); } }
/// <summary> /// Generate filter according to each query item(along with filter description) /// </summary> public BusinessFilter GetBusinessFilter(out string filterDescription) { BusinessFilter queryFilter = new BusinessFilter(this.BusinessObjectView.BusinessObjectName); HtmlTable queryTable = this.queryHolder.FindControl("__queryTable") as HtmlTable; AndOr filterJunction = GetFilterJunction(queryTable); StringBuilder queryDesc = new StringBuilder(); // queryTable的最后一行是queryType(满足全部、满足任一) for (int i = 0; i < queryTable.Rows.Count - 1; i++) { HtmlTableRow queryItem = queryTable.FindControl("__queryitem_" + i.ToString()) as HtmlTableRow; HtmlInputCheckBox checkbox = queryTable.FindControl("__checkbox_" + i.ToString()) as HtmlInputCheckBox; if (checkbox.Checked) { LiteralControl desc = queryTable.FindControl("__desc_" + i.ToString()) as LiteralControl; ViewItemDisplayType itemType = (ViewItemDisplayType)int.Parse(queryItem.Attributes["displayType"]); if (itemType == ViewItemDisplayType.CheckBox) { // Filter HtmlInputCheckBox boolCtl = queryTable.FindControl("__bool_" + i.ToString()) as HtmlInputCheckBox; if (queryItem.Attributes["isVirtual"] != "true") { queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], Convert.ToInt32(boolCtl.Checked).ToString(), Operation.Equal, FilterType.NumberType, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } else { queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + "=" + Convert.ToInt32(boolCtl.Checked).ToString(), queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } // Desc queryDesc.AppendFormat("{0}:{1}.", desc.Text, boolCtl.Checked); } else if (itemType == ViewItemDisplayType.Literal) { // Filter HtmlInputText textbox = queryTable.FindControl("__textbox_" + i.ToString()) as HtmlInputText; if (textbox.Value != string.Empty) { GlobalFacade.PageContext pgCtx = GlobalFacade.SystemContext.GetContext().GetPageContext(this.openerId); pgCtx.Parms.Clear(); RadioButtonList FuzzyEnquiry = queryTable.FindControl("__Fuzzytxt_" + i.ToString()) as RadioButtonList; if (queryItem.Attributes["isVirtual"] != "true") { if (FuzzyEnquiry != null) { if (FuzzyEnquiry.SelectedIndex == 0) { queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], textbox.Value.Replace("'", "''"), Operation.Like, FilterType.StringType, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } else { queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], textbox.Value.Replace("'", "''"), Operation.Equal, FilterType.StringType, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } } else { queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], textbox.Value.Replace("'", "''"), Operation.Like, FilterType.StringType, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } } else { if (FuzzyEnquiry != null) { if (FuzzyEnquiry.SelectedIndex == 0) { queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " LIKE '%" + textbox.Value.Replace("'", "''") + "%'", queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } else { queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " = '" + textbox.Value.Replace("'", "''") + "'", queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } } else { queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " LIKE '%" + textbox.Value.Replace("'", "''") + "%'", queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } } // if(queryItem.Attributes["isVirtual"] != "true") // queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], // textbox.Value.Replace("'", "''"), Operation.Like, FilterType.StringType, filterJunction); // 2007-4-5, Tony, 将单引号替换成两个单引号,避免查询时报错 // else // { // /* Andy Modify 2008-07-30 只有Client的Mobile、TelePhone、ChineseName、EnglishName用前匹配模糊查询 */ // if(this.BusinessObjectView.BusinessObjectName.ToLower() == "client") // { // if( queryItem.Attributes["fieldName"].ToLower().Trim().IndexOf("mobile") == -1 && // queryItem.Attributes["fieldName"].ToLower().Trim().IndexOf("telephone") == -1 && // queryItem.Attributes["fieldName"].ToLower().Trim().IndexOf("chinesename") == -1 && // queryItem.Attributes["fieldName"].ToLower().Trim().IndexOf("englishname") == -1) // { // queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " LIKE '%" + textbox.Value.Replace("'", "''") + "%'", filterJunction);// 2007-4-5, Tony, 将单引号替换成两个单引号,避免查询时报错 // } // else // queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " LIKE '" + textbox.Value.Replace("'", "''") + "%'", filterJunction); // } // else // queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " LIKE '%" + textbox.Value.Replace("'", "''") + "%'", filterJunction);// 2007-4-5, Tony, 将单引号替换成两个单引号,避免查询时报错 // } // Desc queryDesc.AppendFormat("{0}:{1}.", desc.Text, textbox.Value); } } else if (itemType == ViewItemDisplayType.DateTime) { // Filter HtmlInputText beginTime = queryTable.FindControl("__beginTime_" + i.ToString()) as HtmlInputText; HtmlInputText endTime = queryTable.FindControl("__endTime_" + i.ToString()) as HtmlInputText; BusinessFilter subFilter = new BusinessFilter(this.BusinessObjectView.BusinessObjectName); if (queryItem.Attributes["isVirtual"] != "true") { if (beginTime.Value != string.Empty) { subFilter.AddFilterItem(queryItem.Attributes["fieldName"], beginTime.Value, Operation.NotSmaller, FilterType.StringType, AndOr.AND); } if (endTime.Value != string.Empty) { subFilter.AddFilterItem(queryItem.Attributes["fieldName"], endTime.Value, Operation.Smaller, FilterType.StringType, AndOr.AND); } //endTime.Value, Operation.NotLarger, FilterType.StringType, AndOr.AND); } else { if (beginTime.Value != string.Empty) { subFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + ">= '" + beginTime.Value + "'", AndOr.AND); } if (endTime.Value != string.Empty) { subFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + "< '" + endTime.Value + "'", AndOr.AND); } //subFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + "<= '" + endTime.Value + "'", AndOr.AND); } queryFilter.AddFilter(subFilter, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); if (beginTime.Value != string.Empty || endTime.Value != string.Empty) { // Desc queryDesc.AppendFormat("{0}:从{1}至{2}.", desc.Text, beginTime.Value, endTime.Value); } } else if (itemType == ViewItemDisplayType.SingleObject) { // Filter GridPicker ucGridPicker = queryTable.FindControl("__ucGridPicker_" + i.ToString()) as GridPicker; if (ucGridPicker.SelectedValue != string.Empty) { if (queryItem.Attributes["isVirtual"] != "true") { queryFilter.AddFilterItem(queryItem.Attributes["fieldName"], ucGridPicker.SelectedValue, Operation.Equal, FilterType.NumberType, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } else { queryFilter.AddCustomerFilter(queryItem.Attributes["fieldName"] + " = " + ucGridPicker.SelectedValue, queryFilter.Filter != string.Empty ? filterJunction : AndOr.AND); } // Desc queryDesc.AppendFormat("{0}:{1}.", desc.Text, ucGridPicker.SelectedText); } } } } if (queryDesc.Length != 0) { filterDescription = queryDesc.AppendFormat("({0})", (filterJunction == AndOr.AND) ? "满足全部条件" : "满足任一条件").ToString(); } else { filterDescription = string.Empty; } BusinessFilter parentQueryFilter = new BusinessFilter(this.BusinessObjectView.BusinessObjectName); parentQueryFilter.AddCustomerFilter("1=1", AndOr.AND); parentQueryFilter.AddFilter(queryFilter, AndOr.AND); this.SaveQueryStatus(); return(parentQueryFilter); }
public Where(AndOr operand) : this() { this.Operator = operand; }
public CSFilter(CSFilter filter1, AndOr andOr, CSFilter filter2) { if (filter1.IsBlank && filter2.IsBlank) { _expression = ""; _parameters = new CSParameterCollection(); } else if (filter1.IsBlank) { _expression = "(" + filter2.Expression + ")"; _parameters = new CSParameterCollection(filter2.Parameters); return; } else if (filter2.IsBlank) { _expression = "(" + filter1.Expression + ")"; _parameters = new CSParameterCollection(filter1.Parameters); } else { _expression = "(" + filter1._expression + ") " + andOr.ToString() + " (" + filter2.Expression + ")"; _parameters = new CSParameterCollection(filter1.Parameters); _parameters.Add(filter2.Parameters); } }
public DataTable GetDataTableQ(Category c, Attrib attrib1, string attrib1T, Attrib attrib2, string attrib2T, AndOr sign) { string sql = "SELECT * FROM " + c.ToString() + " WHERE " + attrib1.ToString() + attrib1T + " " + sign.ToString() + " " + attrib2.ToString() + attrib2T + ";"; SQLiteCommand cmd = new SQLiteCommand(sql, dbConnection); SQLiteDataReader sdr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(sdr); return(dt); }
private void AOList_SelectedIndexChanged(object sender, EventArgs e) { System.Windows.Forms.ComboBox t = (System.Windows.Forms.ComboBox)sender; ao = (AndOr)t.SelectedIndex; }
public void AddFilterItem(string field, string Value, string operation, FilterType filterType, AndOr andor) { if (filterType == FilterType.StringType) { if (operation.ToLower().Trim().IndexOf("like") == -1) { if (!filter.Equals(string.Empty)) { filter = filter + string.Format(" {0} {1}.{2} {3} '{4}'", andor.ToString(), businessobject, field, operation.ToString(), Value); } else { filter = " " + andor.ToString() + " ( " + string.Format(" {0}.{1} {2} '{3}' ", businessobject, field, operation.ToString(), Value); } } else if (operation.ToLower().Trim() == "like") /* Andy Modify 2008-12-30 性能优化 */ { if (!filter.Equals(string.Empty)) { filter = filter + string.Format(" {0} {1}.{2} {3} '%{4}%' ", andor.ToString(), businessobject, field, Operation.Like, Value); } else { filter = " " + andor.ToString() + " (" + string.Format(" {0}.{1} {2} '%{3}%' ", businessobject, field, Operation.Like, Value); } } // /* Andy Modify 2008-07-30 只有Mobile、TelePhone、ChineseName、EnglishName用前匹配模糊查询 */ // if(operation.ToLower().Trim() == "like") // { // if(this.businessobject.ToLower() == "client") // { // if( field.ToLower().Trim().IndexOf("mobile") == -1 && // field.ToLower().Trim().IndexOf("telephone") == -1 && // field.ToLower().Trim().IndexOf("chinesename") == -1 && // field.ToLower().Trim().IndexOf("englishname") == -1) // { // if (!filter.Equals(string.Empty)) // { // filter = filter + string.Format(" {0} {1}.{2} {3} '%{4}%' ",andor.ToString(),businessobject,field,Operation.Like,Value); // } // else // { // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '%{3}%' ",businessobject,field,Operation.Like,Value); // } // } // else // { // if (!filter.Equals(string.Empty)) // { // filter = filter + string.Format(" {0} {1}.{2} {3} '{4}%' ",andor.ToString(),businessobject,field,Operation.Like,Value); // } // else // { // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '{3}%' ",businessobject,field,Operation.Like,Value); // } // } // } // else // { // if (!filter.Equals(string.Empty)) // { // filter = filter + string.Format(" {0} {1}.{2} {3} '%{4}%' ",andor.ToString(),businessobject,field,Operation.Like,Value); // } // else // { // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '%{3}%' ",businessobject,field,Operation.Like,Value); // } // } // } // if(operation.ToLower().Trim() == "like") // { // // if (!filter.Equals(string.Empty)) // { // // /* Andy Modify 2008-07-25 */ // // filter = filter + string.Format(" {0} {1}.{2} {3} '{4}%' ",andor.ToString(),businessobject,field,operation.ToString(),Value); // filter = filter + string.Format(" {0} {1}.{2} {3} '%{4}%' ",andor.ToString(),businessobject,field,Operation.Like,Value); // } // else // { // // /* Andy Modify 2008-07-25 */ // // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '{3}%' ",businessobject,field,operation.ToString(),Value); // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '%{3}%' ",businessobject,field,Operation.Like,Value); // } // } // else if(operation.ToLower().Trim() == "leftlike") // { // if (!filter.Equals(string.Empty)) // { // /* Andy Modify 2008-07-25 */ // filter = filter + string.Format(" {0} {1}.{2} {3} '%{4}' ",andor.ToString(),businessobject,field,Operation.LeftLike,Value); // } // else // { // /* Andy Modify 2008-07-25 */ // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '%{3}' ",businessobject,field,Operation.LeftLike,Value); // } // } // else if(operation.ToLower().Trim() == "rightlike") // { // if (!filter.Equals(string.Empty)) // { // /* Andy Modify 2008-07-25 */ // filter = filter + string.Format(" {0} {1}.{2} {3} '{4}%' ",andor.ToString(),businessobject,field,Operation.RightLike,Value); // } // else // { // /* Andy Modify 2008-07-25 */ // filter = " " + andor.ToString() + " (" +string.Format(" {0}.{1} {2} '{3}%' ",businessobject,field,Operation.RightLike,Value); // } // } } else if (filterType == FilterType.NumberType) { if (!filter.Equals(string.Empty)) { filter = filter + string.Format(" {0} {1}.{2} {3} {4} ", andor.ToString(), businessobject, field, operation.ToString(), Value); } else { filter = " " + andor.ToString() + " (" + string.Format("{0}.{1} {2} {3} ", businessobject, field, operation.ToString(), Value); } } }
private PersonFilter(AndOr andOr) { AndOr = andOr; }