这是一个小逻辑问题。我的数据网格按时间顺序包含日期时间值。 如果用户输入无序日期时间,程序应该突出显示无序的行。 例如:这是最初的订单。查看时间顺序并返回错误排
10/5/2010 11:59:59
10/6/2010 00:00:00
10/6/2010 11:59:59
假设用户输入
10/5/2010 11:59:59
***10/7/2010 00:00:00***
10/6/2010 11:59:59
10/7/2010 00:00:00
10/7/2010 00:00:00
这里是无序和程序正确行为。
假设用户输入
10/5/2010 11:59:59
10/6/2010 00:00:00
***10/5/2010 11:59:59***
10/7/2010 00:00:00
这里10/5/2010 11:59:59
是出或命令行。但该计划突出显示10/6/2010 00:00:00
。
这是我的代码来检查上述:
for (int nRow = 1; nRow < pSeries.Count; ++nRow)
{
// validation1
if (!check_range(nRow, i, pSeries[nRow].tim))
{
row = nRow;
err = (short)err_typ.e_out_range;
goto err_exit;
}
}
public bool check_range(int np, int nCol, DateTime dt)
{
DataArray pdata = GetDataArray(nCol);
bool valid = (np <= 0 || pdata[np - 1].Datetim <= dt) &&
(np >= (pdata.Count - 1) || dt <= pdata[np + 1].Datetim);
return valid;
}
DataArray
是日期时间值的用户定义的阵列。 pSeries
,pData
的类型为DataArray
。 所以当我说pdata[np - 1].DateTime
它指的是日期时间单元格。
看看“正则表达式”类,它应该能够解决您的问题。 – dotTutorials 2012-08-10 17:42:41
是不是正则表达式类用于匹配模式?你有没有例子? – user1580726 2012-08-10 17:50:16