当前位置: 首页>>代码示例>>C#>>正文


C# Rows.Sort方法代码示例

本文整理汇总了C#中Rows.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# Rows.Sort方法的具体用法?C# Rows.Sort怎么用?C# Rows.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rows的用法示例。


在下文中一共展示了Rows.Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyTopBottomFilter

        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("Filter operators TopN and BottomN require an integer value got {0}.", 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;
        }
开发者ID:bittercoder,项目名称:odd-reports,代码行数:71,代码来源:Filter.cs


注:本文中的Rows.Sort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。