让知识更加联贯 让技术走进生活
我的博客
我的程序 我的网络
------郑紫至
E-mail:zhengzizhi@yahoo.com.cn
地磅称量系统
53. 在LWSMapping封装对象的类库中新建一名称为BaseBusiness的基本业务对象基类
代码如下:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.ComponentModel;
namespace
LWSMapping
{
public class BaseBusiness : IDataErrorInfo
{
private Dictionary<string, string> validationErrors;
public BaseBusiness()
{
this.validationErrors = new Dictionary<string, string>();
}
protected void AddError(string columnName, string msg)
{
if (!this.validationErrors.ContainsKey(columnName))
{
this.validationErrors.Add(columnName, msg);
}
}
protected void RemoveError(string columnName)
{
if (this.validationErrors.ContainsKey(columnName))
{
this.validationErrors.Remove(columnName);
}
}
public string Error
{
get
{
if (this.validationErrors.Count > 0)
{
return string.Format("{0} data is invalid.", this.GetType().ToString());
}
return null;
}
}
public virtual bool HasErrors
{
get
{
return (this.validationErrors.Count > 0);
}
}
public string this[string columnName]
{
get
{
if (this.validationErrors.ContainsKey(columnName))
{
return this.validationErrors[columnName].ToString();
}
return null;
}
}
}
}