else if ( (!isValid) && (i > 0))
{
Row.SetColumnError(fieldName, GetFieldNumberError(ErrorField));
return false;
}
return true;
}
#endregion
}
}
//在继承了基类的BusinessRule中使用校验的方法
/// <summary>
/// 使用上面的方法对数据进行有效性校验
/// </summary>
/// <param name="Row">数据行</param>
/// <returns>通过--true 不通过--false</returns>
public bool Validate(DataRow Row)
{
bool isValid;
Row.ClearErrors();
isValid = IsValidField(Row, "name", 20 ,"姓名",false);
isValid &= IsValidZip(Row, "zip", 6,"邮编",true);
isValid &= IsValidNumber(Row, "age","年龄",false);
isValid &= IsValidEmail(Row,"email",50,"电子邮件" ,true);
return isValid;
}
//在WebUI中显示错误提示信息
/// <summary>
/// 显示提交数据返回的错误信息
/// </summary>
private void DisplayErrors()
{
String fieldErrors="";
String tmpfieldErrors="";
DataRow Row = ds.Tables[0].Rows[0];
foreach (DataColumn Column in ds.Tables[0].Columns)
{
tmpfieldErrors = Row.GetColumnError(Column.ColumnName.ToString());
if (tmpfieldErrors!="")
{
fieldErrors += "<li>" + tmpfieldErrors + "<br>";
}
}
//显示错误信息
this.lblError.Text = fieldErrors;
}