【发布时间】:2014-11-20 19:19:19
【问题描述】:
在我的要求中,我将居住历史详细信息插入到 GridView... 它还包含 FromDate 和 ToDate... 所以对于第一行,没有条件.. 在插入第二行时,FromDate 和 ToDate 不应与我的第一行日期范围发生冲突。 有什么办法可以避免吗????
FromDate ToDate 地点
12/10/2012 12/05/2013 XXXXX
12/05/2004 12/09/2014 YYYYY
第二行不应该被允许.. Bcoz 在 2004 - 2014 年,已经提到了 2012 - 2013 时间段.. 所以,这个东西不应该添加到 GridView 中
我的代码:
protected bool ValidateResidenceDates(DateTime frmDate, DateTime toDate)
{
bool isValid = true;
DataTable dt = (DataTable)Session["ResidenceNew"];
if(dt != null)
{
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
DateTime dtFromDate = Convert.ToDateTime(dr["HKR_FromDate"], ci);
DateTime dtToDate = Convert.ToDateTime(dr["HKR_ToDate"], ci);
if (frmDate > dtFromDate && frmDate < dtToDate)
{
Com.MessageBox("From Date is Already Mentioned in the Residence History Date Range", UpdatePanel1);
SetFocus(txtResideFromDate);
isValid = false;
return isValid;
}
if (toDate > dtFromDate && toDate < dtToDate)
{
Com.MessageBox("To Date is Already Mentioned in the Residence History Date Range", UpdatePanel1);
SetFocus(txtResideToDate);
isValid = false;
return isValid;
}
}
}
}
return isValid;
}
【问题讨论】:
-
插入时比较 fromdate 和 todate 与第一行日期范围
-
我已经尝试过了.. 但这不起作用
-
请发布您用于检查和插入行的代码
-
上述场景,不适合您的想法...
-
您尝试过什么,什么不起作用?