本文整理汇总了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;
}