public ReElement(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { try { _Value = info.GetString("_Value"); } catch { _Value = string.Empty; } try { _Frequence = info.GetInt32("_Frequence"); } catch { _Frequence = 0; } try { _FilterType = (Webb.Data.FilterTypes)info.GetValue("_FilterType", typeof(Webb.Data.FilterTypes)); } catch { _FilterType = FilterTypes.NumGreaterOrEqual; } try { _FollowedOperand = (Webb.Data.FilterOperands)info.GetValue("_FollowedOperand", typeof(Webb.Data.FilterOperands)); } catch { _FollowedOperand = FilterOperands.Or; } }
public BoolResult GetResultWithoutBracket(ArrayList arr, int start, int end) //Modified at 2009-2-16 16:20:18@Scott { int i = 0, j = 0, done = 0; bool curoperand = false, lastoperand = true; FilterOperands lastoperator = FilterOperands.And; i = start; if (arr.Count > 0) { while (i <= end) { if (((arr[i] as BoolResult).Operands == FilterOperands.And) && (lastoperator == FilterOperands.Or)) { j = i; done = 0; while (done == 0) { if ((j >= end) || ((arr[j] as BoolResult).Operands != FilterOperands.And)) { done = 1; } else { j = j + 1; } } curoperand = this.GetResultWithoutBracket(arr, i, j).Result; i = j; } else { curoperand = (arr[i] as BoolResult).Result; } if (lastoperator == FilterOperands.And) { lastoperand = lastoperand && curoperand; } else { lastoperand = lastoperand || curoperand; } lastoperator = (arr[i] as BoolResult).Operands; i = i + 1; } } BoolResult bRet = new BoolResult(lastoperand, Bracket.NONE, lastoperator); return(bRet); }
/// <summary> /// Create service model from api model /// </summary> public ContentFilterElementModel ToServiceModel() { return(new ContentFilterElementModel { FilterOperands = FilterOperands? .Select(f => f.ToServiceModel()) .ToList(), FilterOperator = FilterOperator }); }
//Methods public bool CheckResult(DataRow row, int start, int end) { int i = 0, j = 0, done = 0; bool curoperand = false, lastoperand = true; FilterOperands lastoperator = FilterOperands.And; i = start; if (this.Count > 0) { while (i <= end) { if ((this[i].FollowedOperand == FilterOperands.And) && (lastoperator == FilterOperands.Or)) { j = i; done = 0; while (done == 0) { if ((j >= end) || (this[j].FollowedOperand != FilterOperands.And)) { done = 1; } else { j = j + 1; } } curoperand = this.CheckResult(row, i, j); i = j; } else { curoperand = this[i].CheckResult(row); } if (lastoperator == FilterOperands.And) { lastoperand = lastoperand && curoperand; } else { lastoperand = lastoperand || curoperand; } lastoperator = this[i].FollowedOperand; i = i + 1; } } return(lastoperand); }
// public DBCondition(string i_ColName, FilterTypes i_FilterType, object i_Value, Bracket i_Bracket, FilterOperands i_FollowedOperand) { this._ColumnName = i_ColName; this._FilterType = i_FilterType; this._Value = i_Value; this._Bracket = i_Bracket; this._FollowedOperand = i_FollowedOperand; this._FilterCatalog = GetFilterCatalog(i_FilterType); this._IgnoreCase = true; }
/// <summary> /// Sets the operands for the element. /// </summary> /// <param name="operands">The list of the operands.</param> public void SetOperands(IEnumerable <FilterOperand> operands) { FilterOperands.Clear(); if (operands == null) { return; } foreach (FilterOperand operand in operands) { if (operand == null) { continue; } FilterOperands.Add(new ExtensionObject(operand)); } }
public static DBFilter ConvertToDBFilter(int i_FilterID, IDBManager i_DBManager) { DataTable m_FilterTable = GetFilterInfoTable(i_FilterID, i_DBManager); DBFilter m_DBFilter = new DBFilter(); foreach (DataRow i_Row in m_FilterTable.Rows) { string m_OP = i_Row["Lable"].ToString(); string m_Field = i_Row["FieldName"].ToString(); FilterTypes m_FilterType = FilterTypes.StrEqual; object m_Value = i_Row["Value"]; FilterOperands m_FilterOperand = FilterOperands.And; FilterCatalogs m_FilterCatalog = VictoryFilterHelper.GetCatalogFromFieldName(m_Field); switch (m_OP) { case "Any Entry": { continue; } case "No Entry": { return(null); } case "Equal": { if (m_FilterCatalog == FilterCatalogs.Number) { m_FilterType = FilterTypes.NumEqual; } else { m_FilterType = FilterTypes.StrEqual; } break; } case "Greater Than": { m_FilterType = FilterTypes.NumGreater; break; } case "Less Than": { m_FilterType = FilterTypes.NumLess; break; } case "Starts With": { m_FilterType = FilterTypes.StrStartWith; break; } case "Ends With": { m_FilterType = FilterTypes.StrEndWith; break; } case "Includes": { m_FilterType = FilterTypes.StrInclude; break; } case "From To": { m_FilterType = FilterTypes.NumLessOrEqual; m_Value = i_Row["vMax"]; //"From To" convert to two conditions DBCondition m_DBConditionAdd = new DBCondition(m_Field, FilterTypes.NumGreaterOrEqual, i_Row["vMin"], Bracket.NONE, m_FilterOperand); m_DBFilter.Add(m_DBConditionAdd); break; } case "Offense": case "Defense": case "Kick": case "Practice": case "1st Down": case "2nd Down": case "3rd Down": case "4th Down": case "Left": case "Right": case "Middle": case "Run": case "Pass": { m_FilterType = FilterTypes.StrEqual; m_Value = m_OP; break; } case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": case "10": { m_FilterType = FilterTypes.NumEqual; m_Value = m_OP; break; } default: continue; } //switch end DBCondition m_DBCondition = new DBCondition(m_Field, m_FilterType, m_Value, Bracket.NONE, m_FilterOperand); m_DBFilter.Add(m_DBCondition); } return(m_DBFilter); }
public bool CheckResultWithBracket(DataRow row) { try { //12-17-2007@Scott BoolStack stack = new BoolStack(); foreach (DBCondition condition in this) { bool bResult = condition.CheckResult(row); BoolResult br = new BoolResult(bResult, condition.Bracket, condition.FollowedOperand); if (condition.Bracket == Bracket.End) { BoolStack Bstack = new BoolStack(); FilterOperands oper = br.Operands; Bstack.Push(br); br = stack.Pop() as BoolResult; while (br.Bracket != Bracket.Start) { Bstack.Push(br); if (stack.Count == 0) { System.Windows.Forms.MessageBox.Show("Bad Bracket Count!"); return(false); } br = stack.Pop() as BoolResult; } Bstack.Push(br); br = Bstack.GetResultWithoutBracket(); br.Bracket = Bracket.NONE; br.Operands = oper; } stack.Push(br); } stack = stack.Reverse(); BoolResult result = stack.GetResultWithoutBracket(); return(result.Result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Check filter result error. Message:" + ex.Message); return(false); } }
public BoolResult(bool result, Bracket bracket, FilterOperands opr) { this._Result = result; this._Bracket = bracket; this._Operands = opr; }
//ctor public BoolResult() { this._Result = true; this._Bracket = Bracket.NONE; this._Operands = FilterOperands.And; }