C#•Trigger Validations

Listing 2. The SmartDS class's OnColumnChanging method intercepts all data-field changes and triggers any associated validation checks that the DataSet XML schema declares for the relevant column.

virtual protected void OnColumnChanging(
	 object sender, DataColumnChangeEventArgs e) {
	string l_erdescr;
//Module Hook Validation
if (e.Column.ExtendedProperties.Contains 
	("ruleassembly")) {
	string l_ruleassembly = e.Column.ExtendedProperties[
		"ruleassembly"].ToString ();
	string l_ruleclass= 
		e.Column.ExtendedProperties[
		"ruleclass"].ToString ();
	ValidationRulesBase.IValidateProp l_iv =
		(ValidationRulesBase.IValidateProp)
		(Activator.CreateInstance 
	(l_ruleassembly,l_ruleclass).Unwrap());
	l_iv.validateProp(e.Row ,e.Column.ColumnName 
		,e.ProposedValue,out l_erdescr); 
}
//Required Value Validation
else if (e.Column.ExtendedProperties.Contains 
	("required")) {
	if (e.ProposedValue.ToString ()=="") {
	throw new Exception ("This field can't be empty");
	}
}
//Regular Expression Validation
else if (e.Column.ExtendedProperties.Contains 
	("regexpconstraint")) {
	int l_ret = 
	ValidationRulesBase.CRegExValidate.ValidateRegEx (
	e.Column.ExtendedProperties[
		"regexpconstraint"].ToString (),
		e.ProposedValue.ToString (),out l_erdescr);
	if(l_ret != 0) {
		throw new Exception ("validation failed. regexp: " +  
		e.Column.ExtendedProperties.Contains 
		("regexpconstraint") +
	" value: " + e.ProposedValue );
	}
	}
}