List<FilterValue> _Items; // list of FilterValue #endregion Fields #region Constructors internal FilterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) { FilterValue f; _Items = new List<FilterValue>(); // Loop thru all the child nodes foreach(XmlNode xNodeLoop in xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) continue; switch (xNodeLoop.Name) { case "FilterValue": f = new FilterValue(r, this, xNodeLoop); break; default: f=null; // don't know what this is // don't know this element - log it OwnerReport.rl.LogError(4, "Unknown FilterValues element '" + xNodeLoop.Name + "' ignored."); break; } if (f != null) _Items.Add(f); } if (_Items.Count == 0) OwnerReport.rl.LogError(8, "For FilterValues at least one FilterValue is required."); else _Items.TrimExcess(); }
List <FilterValue> _Items; // list of FilterValue internal FilterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) { FilterValue f; _Items = new List <FilterValue>(); // Loop thru all the child nodes foreach (XmlNode xNodeLoop in xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) { continue; } switch (xNodeLoop.Name) { case "FilterValue": f = new FilterValue(r, this, xNodeLoop); break; default: f = null; // don't know what this is // don't know this element - log it OwnerReport.rl.LogError(4, "Unknown FilterValues element '" + xNodeLoop.Name + "' ignored."); break; } if (f != null) { _Items.Add(f); } } if (_Items.Count == 0) { OwnerReport.rl.LogError(8, "For FilterValues at least one FilterValue is required."); } else { _Items.TrimExcess(); } }
private void ApplyTopBottomFilter(Report rpt, Rows data) { if (data.Data.Count <= 0) // No data; nothing to do { return; } // Get the filter value and validate it FilterValue fv = this._FilterValues.Items[0]; double val = fv.Expression.EvaluateDouble(rpt, data.Data[0]); if (val <= 0) // if less than equal 0; then request results in no data { data.Data.Clear(); return; } // Calculate the row number of the affected item and do additional validation int ival; if (_FilterOperator == FilterOperatorEnum.TopN || _FilterOperator == FilterOperatorEnum.BottomN) { ival = (int)val; if (ival != val) { throw new Exception(string.Format(Strings.Filter_Error_TopNAndBottomNRequireInt, val)); } if (ival >= data.Data.Count) // includes all the data? { return; } ival--; // make zero based } else { if (val >= 100) // greater than 100% means all the data { return; } ival = (int)(data.Data.Count * (val / 100)); if (ival <= 0) // if less than equal 0; then request results in no data { data.Data.Clear(); return; } if (ival >= data.Data.Count) // make sure rounding hasn't forced us past 100% { return; } ival--; // make zero based } // Sort the data by the FilterExpression List <RowsSortExpression> sl = new List <RowsSortExpression>(); sl.Add(new RowsSortExpression(this._FilterExpression)); data.SortBy = sl; // update the sort by data.Sort(); // sort the data // reverse the order of the data for top so that data is in the beginning if (_FilterOperator == FilterOperatorEnum.TopN || _FilterOperator == FilterOperatorEnum.TopPercent) { data.Data.Reverse(); } List <Row> ar = data.Data; TypeCode tc = _FilterExpression.GetTypeCode(); object o = this._FilterExpression.Evaluate(rpt, data.Data[ival]); // adjust the ival based on duplicate values ival++; while (ival < ar.Count) { object n = this._FilterExpression.Evaluate(rpt, data.Data[ival]); if (ApplyCompare(tc, o, n) != 0) { break; } ival++; } if (ival < ar.Count) // if less than we need to remove the rest of the rows { ar.RemoveRange(ival, ar.Count - ival); } return; }