第三层、业务对象层,生成的源代码如下:
业务层对象主要提供了基于单条记录的对象和后台供二次开发的manager类
最后附上我开发的模板供大家参考:
开发模板
使用说明:
1.请使用以Batch开头的模板,这是批处理生成模板,可以同时针对多个数据库表生成代码。
2.由于在开发模板之前我已经开发出了很多基础类库所以有些对象可能无法正常工作如SqlHelper(针对Ms sql访问的帮助类)等等,但是大家依然可以从模板的源文件看到开发模板的方法:)
3.在对数据库中表命名的时候请加上前缀如A_,B_等等,本文中以A_为例,因为通常开发都是一个模块一个模块开发的,而代码也是一个模块一个模块生成的,因此我就在相同模块的表之前加相同的前缀,这样生成的时候只要输入前缀就可以生成指定的表,而不用每次都重新生成。
业务层对象主要提供了基于单条记录的对象和后台供二次开发的manager类
using System;
using System.Data;
using Keyss.Framework;
namespace Keyss.Framework
{
ArticleClass#region ArticleClass
public class ArticleClass:ArticleClassInf
{
public properties#region public properties
public bool Exists
{
get
{
return ArticleClassManager_Base.CheckByID(_iD);
}
}
#endregion
Tree Properties#region Tree Properties
public void AddChild(ArticleClassInf child)
{
child.ParentID = _iD;
ArticleClassManager_Base.Insert(child);
}
public void CopyChildren(Guid fromID)
{
ArticleClassManager_Base.CopyChildren(_iD,fromID);
}
public void DeleteChildren()
{
System.Data.DataTable table = GetChildren();
foreach(System.Data.DataRow row in table.Rows)
{
ArticleClassManager_Base.Delete((Guid)row["ID"]);
}
}
public void MoveTo(Guid newParentID)
{
ArticleClassManager_Base.MoveTo(_iD,newParentID);
}
public string GetFullName()
{
string result;
string paraStr = "Select [dbo].A_ArticleClass_GetFullName(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(string)helper.ExecuteScalar(paraStr);
return result;
}
public string GetFullID()
{
string result;
string paraStr = "Select [dbo].A_ArticleClass_GetFullID(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(string)helper.ExecuteScalar(paraStr);
return result;
}
public System.Data.DataTable GetChildren()
{
return ArticleClassManager_Base.GetChildren(_iD);
}
public System.Data.DataTable GetNonChildren()
{
return ArticleClassManager_Base.GetNonChildren(_iD);
}
public System.Data.DataTable GetParents()
{
return ArticleClassManager_Base.GetParents(_iD);
}
public int GetLevel()
{
int result;
string paraStr = "Select [dbo].A_ArticleClass_GetLevel(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(int)helper.ExecuteScalar(paraStr);
return result;
}
public ArticleClass GetParent()
{
if(_parentID==Guid.Empty)
return null;
else
return new ArticleClass(_parentID);
}
#endregion
public methods#region public methods
public void Populate(ArticleClassInf articleClassInf)
{
_iD = articleClassInf.ID;
_parentID = articleClassInf.ParentID;
_name = articleClassInf.Name;
_description = articleClassInf.Description;
_orderBy = articleClassInf.OrderBy;
_imgUrl = articleClassInf.ImgUrl;
_iconUrl = articleClassInf.IconUrl;
}
#endregion
construction#region construction
public ArticleClass(Guid iD)
{
ArticleClassInf inf = ArticleClassManager_Base.GetByID(iD);
this.Populate(inf);
}
#endregion
}
#endregion
ArticleClassManager#region ArticleClassManager
public class ArticleClassManager:ArticleClassManager_Base
{
}
#endregion
Article#region Article
public class Article:ArticleInf
{
public properties#region public properties
public bool Exists
{
get
{
return ArticleManager_Base.CheckByID(_iD);
}
}
#endregion
public methods#region public methods
public void Populate(ArticleInf articleInf)
{
_iD = articleInf.ID;
_articleClassID = articleInf.ArticleClassID;
_title = articleInf.Title;
_content = articleInf.Content;
_isNew = articleInf.IsNew;
_isTop = articleInf.IsTop;
_orderBy = articleInf.OrderBy;
_imgUrl = articleInf.ImgUrl;
_createTime = articleInf.CreateTime;
_userName = articleInf.UserName;
_author = articleInf.Author;
_keywords = articleInf.Keywords;
}
#endregion
construction#region construction
public Article(Guid iD)
{
ArticleInf inf = ArticleManager_Base.GetByID(iD);
this.Populate(inf);
}
#endregion
}
#endregion
ArticleManager#region ArticleManager
public class ArticleManager:ArticleManager_Base
{
}
#endregion
}
using System.Data;
using Keyss.Framework;
namespace Keyss.Framework
{
ArticleClass#region ArticleClass
public class ArticleClass:ArticleClassInf
{
public properties#region public properties
public bool Exists
{
get
{
return ArticleClassManager_Base.CheckByID(_iD);
}
}
#endregion
Tree Properties#region Tree Properties
public void AddChild(ArticleClassInf child)
{
child.ParentID = _iD;
ArticleClassManager_Base.Insert(child);
}
public void CopyChildren(Guid fromID)
{
ArticleClassManager_Base.CopyChildren(_iD,fromID);
}
public void DeleteChildren()
{
System.Data.DataTable table = GetChildren();
foreach(System.Data.DataRow row in table.Rows)
{
ArticleClassManager_Base.Delete((Guid)row["ID"]);
}
}
public void MoveTo(Guid newParentID)
{
ArticleClassManager_Base.MoveTo(_iD,newParentID);
}
public string GetFullName()
{
string result;
string paraStr = "Select [dbo].A_ArticleClass_GetFullName(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(string)helper.ExecuteScalar(paraStr);
return result;
}
public string GetFullID()
{
string result;
string paraStr = "Select [dbo].A_ArticleClass_GetFullID(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(string)helper.ExecuteScalar(paraStr);
return result;
}
public System.Data.DataTable GetChildren()
{
return ArticleClassManager_Base.GetChildren(_iD);
}
public System.Data.DataTable GetNonChildren()
{
return ArticleClassManager_Base.GetNonChildren(_iD);
}
public System.Data.DataTable GetParents()
{
return ArticleClassManager_Base.GetParents(_iD);
}
public int GetLevel()
{
int result;
string paraStr = "Select [dbo].A_ArticleClass_GetLevel(";
paraStr += string.Format("'{0}'",_iD);
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(int)helper.ExecuteScalar(paraStr);
return result;
}
public ArticleClass GetParent()
{
if(_parentID==Guid.Empty)
return null;
else
return new ArticleClass(_parentID);
}
#endregion
public methods#region public methods
public void Populate(ArticleClassInf articleClassInf)
{
_iD = articleClassInf.ID;
_parentID = articleClassInf.ParentID;
_name = articleClassInf.Name;
_description = articleClassInf.Description;
_orderBy = articleClassInf.OrderBy;
_imgUrl = articleClassInf.ImgUrl;
_iconUrl = articleClassInf.IconUrl;
}
#endregion
construction#region construction
public ArticleClass(Guid iD)
{
ArticleClassInf inf = ArticleClassManager_Base.GetByID(iD);
this.Populate(inf);
}
#endregion
}
#endregion
ArticleClassManager#region ArticleClassManager
public class ArticleClassManager:ArticleClassManager_Base
{
}
#endregion
Article#region Article
public class Article:ArticleInf
{
public properties#region public properties
public bool Exists
{
get
{
return ArticleManager_Base.CheckByID(_iD);
}
}
#endregion
public methods#region public methods
public void Populate(ArticleInf articleInf)
{
_iD = articleInf.ID;
_articleClassID = articleInf.ArticleClassID;
_title = articleInf.Title;
_content = articleInf.Content;
_isNew = articleInf.IsNew;
_isTop = articleInf.IsTop;
_orderBy = articleInf.OrderBy;
_imgUrl = articleInf.ImgUrl;
_createTime = articleInf.CreateTime;
_userName = articleInf.UserName;
_author = articleInf.Author;
_keywords = articleInf.Keywords;
}
#endregion
construction#region construction
public Article(Guid iD)
{
ArticleInf inf = ArticleManager_Base.GetByID(iD);
this.Populate(inf);
}
#endregion
}
#endregion
ArticleManager#region ArticleManager
public class ArticleManager:ArticleManager_Base
{
}
#endregion
}
最后附上我开发的模板供大家参考:
开发模板
使用说明:
1.请使用以Batch开头的模板,这是批处理生成模板,可以同时针对多个数据库表生成代码。
2.由于在开发模板之前我已经开发出了很多基础类库所以有些对象可能无法正常工作如SqlHelper(针对Ms sql访问的帮助类)等等,但是大家依然可以从模板的源文件看到开发模板的方法:)
3.在对数据库中表命名的时候请加上前缀如A_,B_等等,本文中以A_为例,因为通常开发都是一个模块一个模块开发的,而代码也是一个模块一个模块生成的,因此我就在相同模块的表之前加相同的前缀,这样生成的时候只要输入前缀就可以生成指定的表,而不用每次都重新生成。