数据编辑基类模板
2006-10-07 14:45
246 查看
/// <summary>
/// 数据模型操作基础类
/// </summary>
/// <typeparam name="T">模型类型</typeparam>
/// <typeparam name="KT">主索引类型</typeparam>
public abstract class ModelLogicAdapter<T,KT> : System.MarshalByRefObject, IModelLogic where T:new()
{
#region IModelLogic 成员
private T mItem= new T();
public T Item
{
get
{
return mItem;
}
set
{
mItem = value;
}
}
public void Add()
{
OnCheckModel();
OnAdd();
}
public void Edit()
{
OnCheckModel();
OnEdit();
}
public void Load(KT index)
{
OnLoad(index);
}
public void Delete()
{
OnCheckModel();
OnDelete();
}
#endregion
protected virtual void OnAdd()
{
DAOContext.Add(Item);
}
protected virtual void OnDelete()
{
DAOContext.Delete(Item);
}
protected virtual void OnEdit()
{
DAOContext.Edit(Item);
}
protected virtual void OnLoad(KT index)
{
mItem = DAOContext.Load<T>(index);
}
protected virtual void OnCheckModel()
{
if(Item == null)
throw new LogicException("object is null!");
}
}
应用例程:
public class User:BaseModel<Entities.SysUser,string>
{
protected override void OnAdd()
{
if ((Entities.DBMapping.SysUser.UserCode == Item.UserCode).CountOf() > 0)
{
throw (new HFSoft.BusinessLogic.LogicException(Properties.Resources.USER_HAVED));
}
base.OnAdd();
}
private bool mLoadRoles = false;
/// <summary>
/// 是否加载相关用户角色
/// </summary>
public bool LoadRoles
{
get
{
return mLoadRoles;
}
set
{
mLoadRoles = value;
}
}
private List<Entities.Role> mRoles = new List<IDC.Entities.Role>();
public List<Entities.Role> Roles
{
get
{
return mRoles;
}
}
protected override void OnLoad(string index)
{
base.OnLoad(index);
if (LoadRoles)
{
mRoles = (Entities.DBMapping.Role.RoleUser == (
Entities.DBMapping.UserRole.UserCode == (string)index)).List<Entities.Role>();
}
}
}
/// 数据模型操作基础类
/// </summary>
/// <typeparam name="T">模型类型</typeparam>
/// <typeparam name="KT">主索引类型</typeparam>
public abstract class ModelLogicAdapter<T,KT> : System.MarshalByRefObject, IModelLogic where T:new()
{
#region IModelLogic 成员
private T mItem= new T();
public T Item
{
get
{
return mItem;
}
set
{
mItem = value;
}
}
public void Add()
{
OnCheckModel();
OnAdd();
}
public void Edit()
{
OnCheckModel();
OnEdit();
}
public void Load(KT index)
{
OnLoad(index);
}
public void Delete()
{
OnCheckModel();
OnDelete();
}
#endregion
protected virtual void OnAdd()
{
DAOContext.Add(Item);
}
protected virtual void OnDelete()
{
DAOContext.Delete(Item);
}
protected virtual void OnEdit()
{
DAOContext.Edit(Item);
}
protected virtual void OnLoad(KT index)
{
mItem = DAOContext.Load<T>(index);
}
protected virtual void OnCheckModel()
{
if(Item == null)
throw new LogicException("object is null!");
}
}
应用例程:
public class User:BaseModel<Entities.SysUser,string>
{
protected override void OnAdd()
{
if ((Entities.DBMapping.SysUser.UserCode == Item.UserCode).CountOf() > 0)
{
throw (new HFSoft.BusinessLogic.LogicException(Properties.Resources.USER_HAVED));
}
base.OnAdd();
}
private bool mLoadRoles = false;
/// <summary>
/// 是否加载相关用户角色
/// </summary>
public bool LoadRoles
{
get
{
return mLoadRoles;
}
set
{
mLoadRoles = value;
}
}
private List<Entities.Role> mRoles = new List<IDC.Entities.Role>();
public List<Entities.Role> Roles
{
get
{
return mRoles;
}
}
protected override void OnLoad(string index)
{
base.OnLoad(index);
if (LoadRoles)
{
mRoles = (Entities.DBMapping.Role.RoleUser == (
Entities.DBMapping.UserRole.UserCode == (string)index)).List<Entities.Role>();
}
}
}
相关文章推荐
- gridview取编辑时模板列表格数据:出现未将对象引用设置到对象的实例
- ArcMap如何创建数据编辑模板,高效完成数据采集
- umbraco如何设定模板编辑特定类型的数据?
- 一个html数据编辑模板
- pb9中数据窗口的XML特性(二、编辑导出模板)
- CodeFactory数据查询和数据编辑模板
- 用C#读取GPS数据的基类.
- 用模板和基类巧妙实现类方法的回调(消息映射的基本原理)
- Swt/Jface tableViewer入门教程三(加入在表格上直接编辑数据)
- 用基类指针创建的派生类对象,无法访问派生类对象的数据和成员
- Asp.net Dynamic Data之三改变编辑和操作数据的现实方式
- extjs 可编辑列批量录入数据
- ArcGIS for Android 离线数据编辑原理
- 基于ODP的数据层基类C#源码
- vimrc模板编辑及shell 脚本 模板编辑
- 小猫统计form方式编辑数据使用下拉框出现错误提示
- DataList编辑,更新,删除及模板的使用
- thinphp 自定义标签,非常方便在模板读取数据。
- ListView的item中EditText编辑(或者其他控件)修改本行数据
- 一个内存分配器 模板基类