找到在Scheduler Devexpress控件中将业务实体映射到约会时捕获错误的方法
本文关键字:约会 错误 方法 映射 业务 Devexpress Scheduler 控件 实体 | 更新日期: 2023-09-27 18:18:43
在我们的项目中,我们使用Devexpress调度器控件。我们的实体被正确映射,我们能够在视图中看到约会。除了现在我们需要在业务实体的setter中添加验证逻辑之外,一切都很好。现在,在运行时,如果约会结束违反了业务规则,那么当它被更改时,应用程序会崩溃,因为没有异常处理。当执行映射时,我找不到捕获此错误的方法。
有人可以建议如何/在哪里捕获这个错误时映射从/到约会?
有验证的属性代码:
public DateTime StartDateTime
{
get { return _startDateTime; }
set
{
if (_startDateTime != value)
{
OnSetStart(value);
_startDatetime = value;
NotifyPropertyChanged("StartDatetime");
}
}
}
public void OnSetSart(DateTime dateTime)
{
if(PisiblePeriodStart <= dateTime && dateTime <= PosiblePeriodEnd)
{
throw new Exception("Error")
}
}
这只是验证的样例代码。
如果你不想重复你的验证逻辑,你可以尝试这样做
bool IsStartValid;
public DateTime StartDate
{
get { return startDate; }
set
{
if (value > MaxValidDate)
{
IsStartValid = false;
throw new Exception("Error");//***
}
else
IsStartValid = true;
startDate=value;
}
}
你可以处理SchedulerControl的AppointmentDrop事件并检查IsStartValid属性
private void schedulerControl_AppointmentDrop(object sender, AppointmentDragEventArgs e)
{
YourClass temp = e.EditedAppointment.GetRow(schedulerStorage1) as YourClass;
if(temp.IsStartValid==false)
{
MessageBox.Show("Invalid Start");
e.Handled = true;
e.Allow = false;
}
// if (e.EditedAppointment.End < DateTime.Now)
// {
// MessageBox.Show("You can't move appointments to the past");
// e.Handled = true;
// e.Allow = false;
// }
}
对于AppointmentResizing事件也是一样
***这个异常是未处理的吗?