#region 验证非空
if (e.NewValues["Driver"] == null || e.NewValues["Driver"].ToString().Trim() == "")
{
UseUtility.Alert("汽车司机不能为空!", this.Page);
e.Cancel = true;
return;
}
if (e.NewValues["AutomobileLicensePlate"] == null || e.NewValues["AutomobileLicensePlate"].ToString().Trim() == "")
{
UseUtility.Alert("汽车牌照不能为空!", this.Page);
e.Cancel = true;
return;
}
if (e.NewValues["AutomobileType"] == null || e.NewValues["AutomobileType"].ToString().Trim() == "")
{
UseUtility.Alert("汽车型号不能为空!", this.Page);
e.Cancel = true;
return;
}
#endregion
#region 验证非法输入
int seat, Capacity;
try
{
seat = Convert.ToInt32(e.NewValues["AutomobileSeatings"]); //座位号
Capacity = Convert.ToInt32(e.NewValues["AutomobileCapacity"]); //载重
}
catch
{
UseUtility.Alert("输入有误,请重新输入!", this.Page);
e.Cancel = true;
return;
}
if (seat <= 0)
{
UseUtility.Alert("座位号必须大于零!", this.Page);
e.Cancel = true;
return;
}
if (Capacity <= 0)
{
UseUtility.Alert("载重必须大于零!", this.Page);
e.Cancel = true;
return;
}
#endregion
本文介绍了一个用于验证汽车数据输入完整性和合法性的逻辑实现。主要内容包括:确保汽车司机、汽车牌照和汽车型号等基本信息不为空;检查汽车座位数和载重是否为有效的正整数,并且大于零。
1305

被折叠的 条评论
为什么被折叠?



