You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
6.3 KiB
207 lines
6.3 KiB
<%@ CodeTemplate Language="C#" ClassName="Service" TargetLanguage="C#" Debug="False" Description="" %>
|
|
<%@ Property Name="databaseProjectName" Type="String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
|
|
<%@ Property Name="nameSpace" Type="System.String" Default="Service" Optional="True" Category="Context" Description="" %>
|
|
<%
|
|
DbEntity db = Template.GetDataBase(databaseProjectName);
|
|
|
|
foreach(Table tb in db.Tables)
|
|
{
|
|
OpenResponse(databaseProjectName+"\\Service\\"+tb.ModuleName+"\\"+tb.PropertyName+"Service.cs");
|
|
string noDefaultFields = "";
|
|
string noDefaultFieldFormats = "";
|
|
string noDefaultFieldValues = "";
|
|
int iField = 0;
|
|
foreach(Field fd in tb.Fields)
|
|
{
|
|
if( (fd.DefaultValue != "" || fd.DefaultValue != null) && fd.Identity.Enable == false)
|
|
{
|
|
noDefaultFields += "\t\t\t\t\t"+fd.PropertyName+",\r\n";
|
|
if( fd.DataType.GroupName.ToUpper() == "STRING")
|
|
noDefaultFieldValues += "\t\t\t\t\tFormatCom.String("+tb.MemberName+"."+fd.PropertyName+"),\r\n";
|
|
else if( fd.DataType.GroupName.ToUpper() == "DATETIME")
|
|
noDefaultFieldValues += "\t\t\t\t\tDBAccess.DateStr("+tb.MemberName+"."+fd.PropertyName+"),\r\n";
|
|
else
|
|
noDefaultFieldValues += "\t\t\t\t\t"+tb.MemberName+"."+fd.PropertyName+",\r\n";
|
|
if( fd.DataType.GroupName.ToUpper() == "NUMBER")
|
|
noDefaultFieldFormats += "{"+iField.ToString()+"},";
|
|
//else if( fd.DataType.GroupName.ToUpper() == "DATETIME")
|
|
// noDefaultFieldFormats += "{"+iField.ToString()+"},";
|
|
else
|
|
noDefaultFieldFormats += "'{"+iField.ToString()+"}',";
|
|
iField++;
|
|
}
|
|
}
|
|
if( noDefaultFields.EndsWith(",\r\n"))
|
|
noDefaultFields = noDefaultFields.Substring(0,noDefaultFields.Length-3);
|
|
if( noDefaultFieldValues.EndsWith(",\r\n"))
|
|
noDefaultFieldValues = noDefaultFieldValues.Substring(0,noDefaultFieldValues.Length-3);
|
|
noDefaultFieldFormats = noDefaultFieldFormats.Trim(',');
|
|
|
|
%>
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
|
|
using Model;
|
|
using Dto;
|
|
using Dal;
|
|
|
|
/*******************************************************/
|
|
/*Project:
|
|
Module :
|
|
Description :
|
|
Date : <%=DateTime.Now.ToString()%>
|
|
Create : lxc
|
|
Update :
|
|
TODO : */
|
|
/*******************************************************/
|
|
|
|
namespace EC.Service.<%=nameSpace%>
|
|
{
|
|
public class <%=tb.PropertyName%>Service
|
|
{
|
|
public <%=tb.PropertyName%>Service()
|
|
{
|
|
}
|
|
|
|
public static <%=tb.PropertyName%>Model DtoToModel(<%=tb.PropertyName%>Dto dto)
|
|
{
|
|
<%=tb.PropertyName%>Model model= new <%=tb.PropertyName%>Model();
|
|
<%foreach(Field fd in tb.Fields)
|
|
{
|
|
%>
|
|
model.<%=fd.MemberName%>=dto.<%=fd.MemberName%>;
|
|
<% }%>
|
|
return model;
|
|
}
|
|
public static <%=tb.PropertyName%>Dto ModelToDto(<%=tb.PropertyName%>Model model)
|
|
{
|
|
<%=tb.PropertyName%>Dto dto= new <%=tb.PropertyName%>Dto();
|
|
<%foreach(Field fd in tb.Fields)
|
|
{
|
|
%>
|
|
dto.<%=fd.MemberName%>=model.<%=fd.MemberName%>;
|
|
<% }%>
|
|
return dto;
|
|
}
|
|
#region Insert
|
|
public static int Insert(<%=tb.PropertyName%>Dto <%=tb.MemberName%>)
|
|
{
|
|
<%=tb.PropertyName%>Model model=DtoToModel(<%=tb.MemberName%>);
|
|
return <%=tb.PropertyName%>Dal.Insert(model);
|
|
}
|
|
#endregion
|
|
|
|
#region Update
|
|
public static int Update(<%=tb.PropertyName%>Dto dto)
|
|
{
|
|
<%=tb.PropertyName%>Model model=DtoToModel(dto);
|
|
return <%=tb.PropertyName%>Dal.Update(model);
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region Delete
|
|
public static int Delete(int id)
|
|
{
|
|
|
|
|
|
return <%=tb.PropertyName%>Dal.Delete(id);
|
|
}
|
|
#endregion
|
|
|
|
#region Select
|
|
<%
|
|
string fieldstr = "a.*";
|
|
string tablestr = tb.PropertyName+" a ";
|
|
foreach(Field fd in tb.Fields)
|
|
{
|
|
FieldRel fieldRel = new FieldRel(fd.Code);
|
|
if( fieldRel.RelTable != "")
|
|
{
|
|
fieldstr +=","+fieldRel.RelTableAlias+"."+fieldRel.RelShowField;
|
|
if( fieldRel.RelShowFieldAlias != fieldRel.RelShowField)
|
|
fieldstr += " as "+fieldRel.RelShowFieldAlias;
|
|
|
|
tablestr +=" inner join "+fieldRel.RelTable;
|
|
if( fieldRel.RelTableAlias != fieldRel.RelTable)
|
|
tablestr += " "+fieldRel.RelTableAlias;
|
|
tablestr +=" on a."+fd.PropertyName+"="+fieldRel.RelTableAlias+"."+fieldRel.RelField;
|
|
}
|
|
}
|
|
string sqlHead = "select "+fieldstr+" from "+tablestr;
|
|
%>
|
|
|
|
|
|
public static <%=tb.PropertyName%>Dto Select(int id)
|
|
{
|
|
<%=tb.PropertyName%>Dto dto = new <%=tb.PropertyName%>Dto();
|
|
<%=tb.PropertyName%>Model model = <%=tb.PropertyName%>Dal.Select(id);
|
|
if(model !=null)
|
|
{
|
|
dto = ModelToDto(model);
|
|
}
|
|
return dto ;
|
|
}
|
|
/*
|
|
/// <summary>
|
|
/// ����where ��ҳ���� ��ѯ
|
|
/// </summary>
|
|
/// <param name="where"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public static <%=tb.PropertyName%>PageDto SelectList(string where,int pageIndex, int pageSize)
|
|
{
|
|
int count ;
|
|
<%=tb.PropertyName%>PageDto pageDto= new <%=tb.PropertyName%>PageDto();
|
|
List<<%=tb.PropertyName%>Model> modelLst = <%=tb.PropertyName%>Dal.SelectModelList(where, pageIndex, pageSize, out count);//(pageindex,userid);
|
|
pageDto.count = count;
|
|
pageDto.pageIndex = pageIndex;
|
|
|
|
int x = 0;
|
|
foreach (<%=tb.PropertyName%>Model model in modelLst)
|
|
{
|
|
|
|
<%=tb.PropertyName%>Dto dto = ModelToDto(model);
|
|
pageDto.rows.Add(dto);
|
|
x++;
|
|
|
|
}
|
|
pageDto.pageCount = (pageDto.count / pageSize) + 1;
|
|
|
|
return pageDto;
|
|
}
|
|
*/
|
|
/// <summary>
|
|
/// ����where ���� ��ѯ
|
|
/// </summary>
|
|
/// <param name="where"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public static List<<%=tb.PropertyName%>Dto> SelectList(string where)
|
|
{
|
|
int count ;
|
|
List< <%=tb.PropertyName%>Dto> dtoLst= new List<<%=tb.PropertyName%>Dto>();
|
|
List<<%=tb.PropertyName%>Model> modelLst = <%=tb.PropertyName%>Dal.SelectModelList(where);//
|
|
|
|
|
|
|
|
foreach (<%=tb.PropertyName%>Model model in modelLst)
|
|
{
|
|
<%=tb.PropertyName%>Dto dto = ModelToDto(model);
|
|
dtoLst.Add(dto);
|
|
}
|
|
return dtoLst;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
<%
|
|
|
|
CloseResponse();
|
|
}
|
|
%>
|
|
|