Validate the "Expire Date (when entering invalid dates), and display a custom message
· Field name is = tbToDate there only 1 field and I have code for 2 fields… bcz correct me…
private string CreateWhereStr()
{
string strWhere= "";
string strWhereFromDate = tbFromDate.Text.ToString();
string strWhereEndDate = tbToDate.Text.ToString();
try
{
if (( strWhereFromDate.ToString() != "" ) && (strWhereEndDate.ToString() != "" ))
{
DateTime WhereFromDate = ConvertDate(strWhereFromDate) ;
DateTime WhereEndDate = ConvertDate(tbToDate.Text.ToString()) ;
if (WhereFromDate.Date > WhereEndDate.Date )
{
throw new ArgumentException(" ‘To Date’ must be bigger than ‘From Date’.");
}
else
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) > to_date('" + strWhereFromDate.ToString() + "','dd/MM/yyyy') AND to_date(EXPIRE_DATE) < to_date('" + strWhereEndDate.ToString()+ "','dd/MM/yyyy')" ;
}
}
else if (( strWhereFromDate.ToString() != "" ) && (strWhereEndDate.ToString() == "" ))
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) > to_date('" + strWhereFromDate.ToString()+ " ' ,'dd/MM/yyyy')" ;
}
else if (( strWhereFromDate.ToString() == "" ) && (strWhereEndDate.ToString() != "" ))
{
strWhere = strWhere + " AND to_date(EXPIRE_DATE) < to_date ('" + strWhereEndDate.ToString()+ " ' ,'dd/MM/yyyy')" ;
}
}
catch( Exception ex)
{
throw new ArgumentException(ex.Message.ToString()) ;
}
return strWhere ;
}