第三层、业务对象层,生成的源代码如下:
业务层对象主要提供了基于单条记录的对象和后台供二次开发的manager类

生成工具-CodeSmith-享受编程的乐趣(三)using System;
生成工具-CodeSmith-享受编程的乐趣(三)
using System.Data;
生成工具-CodeSmith-享受编程的乐趣(三)
using Keyss.Framework;
生成工具-CodeSmith-享受编程的乐趣(三)
生成工具-CodeSmith-享受编程的乐趣(三)
namespace Keyss.Framework
{
生成工具-CodeSmith-享受编程的乐趣(三)

生成工具-CodeSmith-享受编程的乐趣(三)
public class ArticleClass:ArticleClassInf
{

生成工具-CodeSmith-享受编程的乐趣(三)    
public bool Exists
{
生成工具-CodeSmith-享受编程的乐趣(三)        
get 
{
生成工具-CodeSmith-享受编程的乐趣(三)            
return ArticleClassManager_Base.CheckByID(_iD);
生成工具-CodeSmith-享受编程的乐趣(三)        }

生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)    
public void AddChild(ArticleClassInf child)
{
生成工具-CodeSmith-享受编程的乐趣(三)        child.ParentID 
= _iD;
生成工具-CodeSmith-享受编程的乐趣(三)        ArticleClassManager_Base.Insert(child);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public void CopyChildren(Guid fromID)
{
生成工具-CodeSmith-享受编程的乐趣(三)        ArticleClassManager_Base.CopyChildren(_iD,fromID);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public void DeleteChildren()
{
生成工具-CodeSmith-享受编程的乐趣(三)        System.Data.DataTable table 
= GetChildren();
生成工具-CodeSmith-享受编程的乐趣(三)        
foreach(System.Data.DataRow row in table.Rows)
{
生成工具-CodeSmith-享受编程的乐趣(三)            ArticleClassManager_Base.Delete((Guid)row[
"ID"]);
生成工具-CodeSmith-享受编程的乐趣(三)        }

生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public void MoveTo(Guid newParentID)
{
生成工具-CodeSmith-享受编程的乐趣(三)        ArticleClassManager_Base.MoveTo(_iD,newParentID);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public string GetFullName()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
string result;
生成工具-CodeSmith-享受编程的乐趣(三)        
string paraStr = "Select [dbo].A_ArticleClass_GetFullName(";
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= string.Format("'{0}'",_iD);
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= ")";
生成工具-CodeSmith-享受编程的乐趣(三)        SqlHelper helper 
= KeyssConfig.DatabaseHelper;
生成工具-CodeSmith-享受编程的乐趣(三)        result 
=(string)helper.ExecuteScalar(paraStr);
生成工具-CodeSmith-享受编程的乐趣(三)        
return result;
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public string GetFullID()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
string result;
生成工具-CodeSmith-享受编程的乐趣(三)        
string paraStr = "Select [dbo].A_ArticleClass_GetFullID(";
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= string.Format("'{0}'",_iD);
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= ")";
生成工具-CodeSmith-享受编程的乐趣(三)        SqlHelper helper 
= KeyssConfig.DatabaseHelper;
生成工具-CodeSmith-享受编程的乐趣(三)        result 
=(string)helper.ExecuteScalar(paraStr);
生成工具-CodeSmith-享受编程的乐趣(三)        
return result;
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public System.Data.DataTable GetChildren()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
return ArticleClassManager_Base.GetChildren(_iD);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public System.Data.DataTable GetNonChildren()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
return ArticleClassManager_Base.GetNonChildren(_iD);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public System.Data.DataTable GetParents()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
return ArticleClassManager_Base.GetParents(_iD);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public int GetLevel()
{    
生成工具-CodeSmith-享受编程的乐趣(三)        
int result;
生成工具-CodeSmith-享受编程的乐趣(三)        
string paraStr = "Select [dbo].A_ArticleClass_GetLevel(";
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= string.Format("'{0}'",_iD);
生成工具-CodeSmith-享受编程的乐趣(三)        paraStr 
+= ")";
生成工具-CodeSmith-享受编程的乐趣(三)        SqlHelper helper 
= KeyssConfig.DatabaseHelper;
生成工具-CodeSmith-享受编程的乐趣(三)        result 
=(int)helper.ExecuteScalar(paraStr);
生成工具-CodeSmith-享受编程的乐趣(三)        
return result;
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
public ArticleClass GetParent()
{
生成工具-CodeSmith-享受编程的乐趣(三)        
if(_parentID==Guid.Empty)
生成工具-CodeSmith-享受编程的乐趣(三)            
return null;
生成工具-CodeSmith-享受编程的乐趣(三)        
else    
生成工具-CodeSmith-享受编程的乐趣(三)            
return new ArticleClass(_parentID);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)    
public void Populate(ArticleClassInf articleClassInf)
{
生成工具-CodeSmith-享受编程的乐趣(三)        _iD 
= articleClassInf.ID;
生成工具-CodeSmith-享受编程的乐趣(三)        _parentID 
= articleClassInf.ParentID;
生成工具-CodeSmith-享受编程的乐趣(三)        _name 
= articleClassInf.Name;
生成工具-CodeSmith-享受编程的乐趣(三)        _description 
= articleClassInf.Description;
生成工具-CodeSmith-享受编程的乐趣(三)        _orderBy 
= articleClassInf.OrderBy;
生成工具-CodeSmith-享受编程的乐趣(三)        _imgUrl 
= articleClassInf.ImgUrl;
生成工具-CodeSmith-享受编程的乐趣(三)        _iconUrl 
= articleClassInf.IconUrl;
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)    
public ArticleClass(Guid iD)
{
生成工具-CodeSmith-享受编程的乐趣(三)        ArticleClassInf inf 
= ArticleClassManager_Base.GetByID(iD);
生成工具-CodeSmith-享受编程的乐趣(三)        
this.Populate(inf);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion
生成工具-CodeSmith-享受编程的乐趣(三)}

生成工具-CodeSmith-享受编程的乐趣(三)
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)
public class ArticleClassManager:ArticleClassManager_Base
{
生成工具-CodeSmith-享受编程的乐趣(三)
生成工具-CodeSmith-享受编程的乐趣(三)}

生成工具-CodeSmith-享受编程的乐趣(三)
#endregion
生成工具-CodeSmith-享受编程的乐趣(三)

生成工具-CodeSmith-享受编程的乐趣(三)
public class Article:ArticleInf
{

生成工具-CodeSmith-享受编程的乐趣(三)    
public bool Exists
{
生成工具-CodeSmith-享受编程的乐趣(三)        
get 
{
生成工具-CodeSmith-享受编程的乐趣(三)            
return ArticleManager_Base.CheckByID(_iD);
生成工具-CodeSmith-享受编程的乐趣(三)        }

生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)    
public void Populate(ArticleInf articleInf)
{
生成工具-CodeSmith-享受编程的乐趣(三)        _iD 
= articleInf.ID;
生成工具-CodeSmith-享受编程的乐趣(三)        _articleClassID 
= articleInf.ArticleClassID;
生成工具-CodeSmith-享受编程的乐趣(三)        _title 
= articleInf.Title;
生成工具-CodeSmith-享受编程的乐趣(三)        _content 
= articleInf.Content;
生成工具-CodeSmith-享受编程的乐趣(三)        _isNew 
= articleInf.IsNew;
生成工具-CodeSmith-享受编程的乐趣(三)        _isTop 
= articleInf.IsTop;
生成工具-CodeSmith-享受编程的乐趣(三)        _orderBy 
= articleInf.OrderBy;
生成工具-CodeSmith-享受编程的乐趣(三)        _imgUrl 
= articleInf.ImgUrl;
生成工具-CodeSmith-享受编程的乐趣(三)        _createTime 
= articleInf.CreateTime;
生成工具-CodeSmith-享受编程的乐趣(三)        _userName 
= articleInf.UserName;
生成工具-CodeSmith-享受编程的乐趣(三)        _author 
= articleInf.Author;
生成工具-CodeSmith-享受编程的乐趣(三)        _keywords 
= articleInf.Keywords;
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)    
public Article(Guid iD)
{
生成工具-CodeSmith-享受编程的乐趣(三)        ArticleInf inf 
= ArticleManager_Base.GetByID(iD);
生成工具-CodeSmith-享受编程的乐趣(三)        
this.Populate(inf);
生成工具-CodeSmith-享受编程的乐趣(三)    }

生成工具-CodeSmith-享受编程的乐趣(三)    
#endregion
生成工具-CodeSmith-享受编程的乐趣(三)}

生成工具-CodeSmith-享受编程的乐趣(三)
#endregion

生成工具-CodeSmith-享受编程的乐趣(三)
public class ArticleManager:ArticleManager_Base
{
生成工具-CodeSmith-享受编程的乐趣(三)
生成工具-CodeSmith-享受编程的乐趣(三)}

生成工具-CodeSmith-享受编程的乐趣(三)
#endregion
生成工具-CodeSmith-享受编程的乐趣(三)}

生成工具-CodeSmith-享受编程的乐趣(三)

最后附上我开发的模板供大家参考:

开发模板

使用说明:
1.请使用以Batch开头的模板,这是批处理生成模板,可以同时针对多个数据库表生成代码。
2.由于在开发模板之前我已经开发出了很多基础类库所以有些对象可能无法正常工作如SqlHelper(针对Ms sql访问的帮助类)等等,但是大家依然可以从模板的源文件看到开发模板的方法:)
3.在对数据库中表命名的时候请加上前缀如A_,B_等等,本文中以A_为例,因为通常开发都是一个模块一个模块开发的,而代码也是一个模块一个模块生成的,因此我就在相同模块的表之前加相同的前缀,这样生成的时候只要输入前缀就可以生成指定的表,而不用每次都重新生成。

相关文章:

  • 2021-11-08
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-10-17
  • 2021-04-03
猜你喜欢
  • 2022-01-25
  • 2022-01-02
  • 2021-05-19
  • 2021-12-24
  • 2021-05-16
  • 2021-09-16
  • 2022-03-04
相关资源
相似解决方案