Hi, All.
In my base object, I have start date and end date propery.
private
SmartDate _startDate = new SmartDate("",true ) ;public
string StartDateEndDate property is similiar as StarDate property and I won't repeat here.
I set the validation rule to force the end date is greater the start date.
ValidationRules.AddRule(CommonRules.StringRequired, "StartDate");
ValidationRules.AddRule(CommonRules.StringRequired, "EndDate");
ValidationRules.AddRule(BeginDateGTEndDate,
"StartDate");For example, the startDate is 8/16/2006. EndDate is 8/20/2006. it is fine and will be saved. If I modified endDate to 8/15/2006 and still keep the old start date, it will failed as it should be. If I changed start date to any date earlier than 8/15/2006. for example, 8/10/2006, it will be failed(in this case, I modify both start date and end date). Why? it should be ok because 8/10/2006 < 8/15/2006, and the function BeginDateGTEndDate return true. I tracked the code and find base.IsValid = false. I already modified the date and start date is less than end date. so, I find if I modified both properties and even BeginDateGTEndDate( ) return true, the object could not be saved.
If I modified on side, it will be ok. for example, the startDate is 8/16/2006. EndDate is 8/20/2006. it is fine and will be saved. if I modified end date to 8/5/2006, it will be failed as it should be. if I modified end date back to any date greater than start date (in the case, start date doesn't changed at all, still is 8/16/206). it will be ok and be saved.
Why I can not modify both property? Did I miss something or this is a CLAS bug?
Thanks for help
Brian
Andy,
Thank you, I'm use (CSLA 2.03). I did what you told me but I still have the same problem. At least, I know what kind of the problem it is.
Thank you very much and have a great one.
Brian
The code snippet like this
public string StartDate
{
get
{
CanReadProperty("StartDate", true);
return _startDate.Text;
}
set
{
CanWriteProperty("StartDate", true);
ValidationRules.CheckRules("EndDate");
if (!_startDate.Equals(value))
{
_startDate.Text = value;
PropertyHasChanged("StartDate");
}
}
}
public string StartDate
{
get
{
CanReadProperty("StartDate", true);
return _startDate.Text;
}
set
{
CanWriteProperty("StartDate", true);
if (!_startDate.Equals(value))
{
_startDate.Text = value;
ValidationRules.CheckRules("EndDate");
PropertyHasChanged("StartDate");
}
}
}
OR EVEN
public string EndDate
{
get
{
CanReadProperty("EndDate", true);
return _enddate.Text;
}
set
{
CanWriteProperty("EndDate", true);
if (!_enddate.Equals(value))
{
_enddate.Text
= value;
PropertyHasChanged("EndDate");
ValidationRules.CheckRules("StartDate");
}
}
}
Cheers,
Des Nolan
DesNolan:Not too familar with the use of ValidationRules.CheckRules...
but it appears you may not be doing it at the end o the setter as previously advised, you're calling the check rules before you set the value, try
public string StartDate
{
get
{
CanReadProperty("StartDate", true);
return _startDate.Text;
}
set
{
CanWriteProperty("StartDate", true);
if (!_startDate.Equals(value))
{
_startDate.Text = value;
ValidationRules.CheckRules("EndDate");
PropertyHasChanged("StartDate");
}
}
}
OR EVEN
public string EndDate
{
get
{
CanReadProperty("EndDate", true);
return _enddate.Text;
}
set
{
CanWriteProperty("EndDate", true);
if (!_enddate.Equals(value))
{
_enddate.Text = value;
PropertyHasChanged("EndDate");
ValidationRules.CheckRules("StartDate");
}
}
}
Cheers,
Des Nolan
It works now. :-)
Thanks for you guys help.
Brian Criswell:DesNolan:Not too familar with the use of ValidationRules.CheckRules...
but it appears you may not be doing it at the end o the setter as previously advised, you're calling the check rules before you set the value, try
public string StartDate
{
get
{
CanReadProperty("StartDate", true);
return _startDate.Text;
}
set
{
CanWriteProperty("StartDate", true);
if (!_startDate.Equals(value))
{
_startDate.Text = value;
ValidationRules.CheckRules("EndDate");
PropertyHasChanged("StartDate");
}
}
}
OR EVEN
public string EndDate
{
get
{
CanReadProperty("EndDate", true);
return _enddate.Text;
}
set
{
CanWriteProperty("EndDate", true);
if (!_enddate.Equals(value))
{
_enddate.Text = value;
PropertyHasChanged("EndDate");
ValidationRules.CheckRules("StartDate");
}
}
}
Cheers,
Des Nolan
You do it the other way because the validation check has to come before the PropertyChanged event raised by PropertyHasChanged().
Copyright (c) Marimer LLC