ldj/codeSmith/template/logic.cst

148 lines
3.5 KiB
Plaintext
Raw Permalink Normal View History

2023-05-23 16:13:17 +08:00
<%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="This template demonstrates using properties defined in external assemblies." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="The table to use for this sample." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<script runat="template">
public string getObjClassName()
{
string tablename = this.SourceTable.Name.Substring(2);
string firstChar = tablename.Substring(0,1);
string className = firstChar.ToUpper() + tablename.Substring(1);
return className ;
}
</script>
/// <summary>
///LOGIC CLASS FOR TABLE <%=this.SourceTable.Name%>
///By wm with codesmith.
///on <%= DateTime.Now.ToString("MM/dd/yyyy")%>
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeiNiu.wms.Data.Model;
using System.Data;
using System.Transactions;
namespace DeiNiu.wms.Logical
{
[Serializable]
public class l<%= getObjClassName() %> :lbase
{
<%= getObjClassName() %> _obj;
public l<%= getObjClassName() %>()
{
initialize();
}
public <%= getObjClassName() %> get<%= getObjClassName() %>
{
get
{
if (_obj == null)
{
_obj = new <%= getObjClassName() %>();
}
_obj.operater = operId;
return _obj;
}
}
public l<%= getObjClassName() %>(int operId)
: base(operId)
{
initialize();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllData()
{
return _obj.Query();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllActiveData()
{
return _obj.QueryActived();
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(int id)
{
_obj = id != 0 ? new <%= getObjClassName() %>(id) : new <%= getObjClassName() %>();
}
/// <summary>
/// get a record by id 0
/// </summary>
public void initialize()
{
initialize(0);
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(DataRow dr)
{
_obj = new <%= getObjClassName() %>(dr);
}
protected override DeiNiu.Data.BaseObject.BaseModel getModel()
{
return _obj;
}
//begin cust db operation, query, excute sql etc.
internal int add(<%= getObjClassName() %> obj)
{
return obj.Add();
}
/// <summary>
/// update in a transaction scrop
/// </summary>
public void update()
{
if (valid())
{
using (TransactionScope scope = new TransactionScope())
{
//Node tmp = new Node();
//tmp.parentid = 1;
//tmp.name = "test trans" + DateTime.Now;
//tmp.description = "this is for transTest";
//tmp.Add();
_obj.Update();
scope.Complete();
}
}
}
private bool valid()
{
return true;
}
}
}