ABP 框架代碼批量生成器

 

須要最新源碼,或技術提問,請加QQ羣:538327407css

個人各類github 開源項目和代碼:https://github.com/linbin524git

簡介github

用abp 框架快兩年了,用它完成了多個項目,做爲CTO同時也做爲架構師,在應對中小型項目時候,咱們一般選擇ABP(內部大型的物聯網架構採用本身的框架),感受這款框架真心不錯。雖然開源社區有也有不少寫了幾套代碼生成器,可是我用完以後,老是感受不能達到我本身想要的效果,我我的仍是比較喜歡一步到位,批量生成,因此就寫了這套基於codesmith的代碼生成器,這一套在項目中還算穩定。web

 

模板介紹 正則表達式

先看一下代碼結構數據庫

 

 咱們的項目中我規劃使用的是spa的,因此通常會生成常規 四個目錄,分別是以下bootstrap

 

 

 

其他的中英文,還有權限、以及DbContext 部分相對數量比較少,統一改造,生成單個文件進行copy。api

最後使用TemplateBuid 自動生成上面的批量文件。架構

 

代碼解析和使用app

每一個代碼生成器部分須要先配置對應的項目名稱,和model等,細節須要本身去了解

 

 

 常規簡單操做

 

通常須要咱們用powerdesign等設計工具,設計好對應的表,標註要註釋,先臨時生成一個數據庫,經過codesmith 生成代碼後,在經過code first 形式,真正在abp 對應的數據庫中生成數據庫表。

 如下文件是TemplateBuid.Cst 文件,配置完成後,

 

生成代碼操做,先編譯,後生成。

 

 詳細代碼舉例說明

 

因爲篇幅有限,我就簡單說明一下Repository、AppAuthorizationProvider、view中的createOrEditModal 進行簡單說明

 

一、repository 

常規封裝增刪改查等操做,我在項目中重寫了基類方法,封裝了批量等操做,但沒有和代碼生成器組合起來,常規的業務裏面不須要批量操做

 

其中 默認主鍵都是位ID,若是實際項目中有需求,主鍵要爲其餘字段,須要手動修改。目前我封裝的主要針對ID 是int 類型、GUid 類型作了不一樣代碼輸出

  1 <%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Description="Generates a single entity business class." Debug="True" %>
  2 <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="2.數據庫" Description="Database table that this entity should be based on." %>
  3 <%@ Property Name="TablePrefixes" Type="String" Default="" Optional="True" Category="2.數據庫" Description="The table prefix to be cut from the class name" %>
  4 <%@ Property Name="RootNamespace" Type="String" Default="HashBlockChain" Optional="False" Category="1.名稱空間" Description="系統名稱空間的根名稱." %>
  5 <%@ Property Name="Namespace" Type="String" Default="ZLDB_Domain" Optional="False" Category="1.名稱空間" Description="系統當前所屬文件夾的名稱(命名空間相關)." %>
  6 <%@ Property Name="FolderNamespace" Type="String" Default="" Optional="true" Category="1.名稱空間" Description="系統名稱空間的Model名稱." %>
  7 <%@ Property Name="PrefixLength" Type="Int32" Default="0" Optional="False" Category="2.數據庫" Description="數據表前綴截取長度." %>
  8 <%@ Assembly Name="SchemaExplorer" %>
  9 <%@ Assembly Name="CodeSmith.BaseTemplates" %>
 10 <%@ Assembly Name="System.Data" %>
 11 <%@ Import Namespace="SchemaExplorer" %>
 12 <%@ Import Namespace="System.Data" %>
 13 <%string tableClass=GetClassName(SourceTable, "", 0); %>
 14 <% FolderNamespace=SourceTable.Name.ToString();%>
 15 <%string tableName=SourceTable.Name.ToString(); %>
 16 <%string paramName=GetParamName(tableName); %>
 17 
 18 using Abp.Application.Services;
 19 using Abp.Application.Services.Dto;
 20 using Abp.AutoMapper;
 21 using Abp.Domain.Repositories;
 22 using Abp.Domain.Uow;
 23 using AutoMapper;
 24 using System;
 25 using System.Collections.Generic;
 26 using System.Data.Entity;
 27 using System.Linq;
 28 using System.Linq.Expressions;
 29 using System.Text;
 30 using System.Threading.Tasks;
 31 using System.Linq.Dynamic;
 32 using Abp.Linq.Extensions;
 33 using <%= RootNamespace %>.<%=Namespace%>.Dtos;
 34 using <%= RootNamespace %>.Dto;
 35 using <%= RootNamespace %>.Authorization.<%=tableName%>.Exporting;
 36 namespace <%= RootNamespace %>.<%=Namespace%>
 37 {
 38 
 39  <% foreach (ColumnSchema column in SourceTable.Columns) { %>            
 40          <% if (column.IsPrimaryKeyMember) {  %>
 41          
 42           <%string tempType = GetCSharpVariableType(column); %>
 43          
 44           <% if (tempType=="Guid") {  %>
 45     /// <summary>
 46     /// <%=SourceTable.Description%> 業務實現接口
 47     /// </summary>
 48     public class <%=tableName%>AppService : AbpZeroTemplateAppServiceBase, I<%=tableName%>AppService
 49     {
 50         private readonly IRepository<<%=tableName%>, Guid> _<%=paramName%>Repository;
 51         private readonly I<%=tableName%>ListExcelExporter _i<%=tableName%>ListExcelExporter;
 52 
 53         /// <summary>
 54         /// 構造函數自動注入咱們所須要的類或接口
 55         /// </summary>
 56         public <%=tableName%>AppService(IRepository<<%=tableName%>, Guid> <%=paramName%>Repository,I<%=tableName%>ListExcelExporter i<%=tableName%>ListExcelExporter)
 57         {
 58             _<%=paramName%>Repository = <%=paramName%>Repository;
 59             _i<%=tableName%>ListExcelExporter = i<%=tableName%>ListExcelExporter;
 60          
 61         }
 62 
 63         /// <summary>
 64         /// 獲取全部數據列表
 65         /// </summary>
 66         /// <returns>返回數據集合</returns>
 67         public async Task<List<<%=tableName%>Dto>> GetAllList()
 68         {
 69             //調用Task倉儲的特定方法GetAllWithPeople
 70             var resultList = await _<%=paramName%>Repository.GetAllListAsync();
 71             return Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
 72         }
 73         
 74         /// <summary>
 75         /// 獲取分頁數據列表 分頁具體代碼須要適當修改,如orderby 須要匹配 建立時間 或者其餘數據Id(int)
 76         /// </summary>
 77         /// <returns>返回數據集合</returns>
 78         public async Task<PagedResultDto<<%=tableName%>Dto>> GetPagedListAsync(PagedAndFilteredInputDto input)
 79         {
 80             var query = _<%=paramName%>Repository.GetAll();
 81             //TODO:根據傳入的參數添加過濾條件
 82 
 83             var resultCount = await query.CountAsync();
 84             var result<%=paramName%> = await query
 85             .OrderBy(x=>x.Id)
 86             .PageBy(input)
 87             .ToListAsync();
 88 
 89             var resultListDtos = result<%=paramName%>.MapTo<List<<%=tableName%>Dto>>();
 90             
 91             if (!string.IsNullOrEmpty(input.Sorting)) {
 92                 resultListDtos = resultListDtos.OrderBy(input.Sorting).ToList();
 93             }
 94             
 95             return new PagedResultDto<<%=tableName%>Dto>(
 96             resultCount,
 97             resultListDtos
 98             );
 99         }
100 
101          /// <summary>
102         /// 獲取指定條件的數據列表  webapi 沒法使用
103         /// </summary>
104         /// <returns>返回數據集合</returns>
105         public async Task<List<<%=tableName%>Dto>> GetListByCodition(Expression<Func<<%=tableName%>, bool>> predicate)
106         {
107 
108             var resultList = await _<%=paramName%>Repository.GetAllListAsync(predicate);
109             return Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
110         }
111 
112 
113          /// <summary>
114         /// 導出excel 具體方法
115         /// </summary>
116         /// <returns>excel文件</returns>
117        /// public async Task<FileDto> Get<%=tableName%>ToExcel()
118         ///{
119         ///    var resultList = await _<%=paramName%>Repository.GetAllListAsync();
120         ///   var <%=paramName%>Dtos= Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
121         ///   return _i<%=tableName%>ListExcelExporter.ExportToFile(<%=paramName%>Dtos);
122        /// }
123 
124         /// <summary>
125         /// 根據指定id 獲取數據實體
126         /// </summary>
127         /// <param name="input">當前id</param>
128         /// <returns></returns>
129         public async Task<<%=tableName%>Dto> Get<%=tableName%>ForEditAsync(NullableIdDto<System.Guid> input)
130         {
131             var output = new <%=tableName%>Dto();
132 
133            <%=tableName%>Dto <%=paramName%>EditDto;
134 
135             if (input.Id.HasValue)
136             {
137                 var entity = await _<%=paramName%>Repository.GetAsync(input.Id.Value);
138                 <%=paramName%>EditDto = entity.MapTo<<%=tableName%>Dto>();
139             }
140             else
141             {
142                 <%=paramName%>EditDto = new <%=tableName%>Dto();
143             }
144 
145             output = <%=paramName%>EditDto;
146             return output;
147         }
148 
149         /// <summary>
150         /// 根據Id建立或編輯操做
151         /// </summary>
152         /// <param name="input">實體</param>
153         /// <returns></returns>
154         public async Task CreateOrUpdate<%=tableName%>Async(<%=tableName%>Dto input)
155         {
156             if (!string.IsNullOrWhiteSpace(input.Id))
157             {
158                 await Update(input);
159             }
160             else
161             {
162                 await Create(input);
163             }
164         }
165 
166         /// <summary>
167         /// 新增 
168         /// </summary>
169         /// <param name="input">新增參數</param>
170         /// <returns>新增實體</returns>
171         public async Task<Guid> Create(<%=tableName%>Dto input)
172         {
173             input.Id = new <%=tableName%>().Id.ToString(); 
174             var resultObj = input.MapTo<<%=tableName%>>();
175             var result = await _<%=paramName%>Repository.InsertAsync(resultObj);
176 
177             return result.Id;
178         }
179 
180         /// <summary>
181         /// 修改
182         /// </summary>
183         /// <param name="input">修改參數</param>
184         /// <returns>修改實體</returns>
185         public async Task<<%=tableName%>Dto> Update(<%=tableName%>Dto input)
186         {
187             <%=tableName%> obj = await _<%=paramName%>Repository.GetAsync(new Guid(input.Id));
188             input.MapTo(obj);
189             var result = await _<%=paramName%>Repository.UpdateAsync(obj);
190             return obj.MapTo<<%=tableName%>Dto>();
191         }
192 
193         /// <summary>
194         /// 刪除
195         /// </summary>
196         /// <param name="input">刪除Dto</param>
197         /// <returns>無返回值</returns>
198         public async System.Threading.Tasks.Task Delete(EntityDto<string> input)
199         {
200             await _<%=paramName%>Repository.DeleteAsync(new Guid(input.Id));
201         }
202 
203         /// <summary>
204         /// 刪除 webapi 沒法使用
205         /// </summary>
206         /// <param name="predicate">刪除條件</param>
207         /// <returns>無返回值</returns>
208         public async System.Threading.Tasks.Task DeleteByCondition(Expression<Func<<%=tableName%>, bool>> predicate)
209         {
210             await _<%=paramName%>Repository.DeleteAsync(predicate);
211           
212         }
213     }
214 
215 
216             <%  } else {%>
217               /// <summary>
218     /// <%=SourceTable.Description%> 業務實現接口
219     /// </summary>
220     public class <%=tableName%>AppService : AbpZeroTemplateAppServiceBase, I<%=tableName%>AppService
221     {
222         private readonly IRepository<<%=tableName%>, <%=tempType%>> _<%=paramName%>Repository;
223         private readonly I<%=tableName%>ListExcelExporter _i<%=tableName%>ListExcelExporter;
224 
225         /// <summary>
226         /// 構造函數自動注入咱們所須要的類或接口
227         /// </summary>
228         public <%=tableName%>AppService(IRepository<<%=tableName%>,  <%=tempType%>> <%=paramName%>Repository,I<%=tableName%>ListExcelExporter i<%=tableName%>ListExcelExporter)
229         {
230             _<%=paramName%>Repository = <%=paramName%>Repository;
231             _i<%=tableName%>ListExcelExporter = i<%=tableName%>ListExcelExporter;
232          
233         }
234 
235         /// <summary>
236         /// 獲取全部數據列表
237         /// </summary>
238         /// <returns>返回數據集合</returns>
239         public async Task<List<<%=tableName%>Dto>> GetAllList()
240         {
241             //調用Task倉儲的特定方法GetAllWithPeople
242             var resultList = await _<%=paramName%>Repository.GetAllListAsync();
243             return Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
244         }
245         
246         /// <summary>
247         /// 獲取分頁數據列表 分頁具體代碼須要適當修改,如orderby 須要匹配 建立時間 或者其餘數據Id(int)
248         /// </summary>
249         /// <returns>返回數據集合</returns>
250         public async Task<PagedResultDto<<%=tableName%>Dto>> GetPagedListAsync(PagedAndFilteredInputDto input)
251         {
252             var query = _<%=paramName%>Repository.GetAll();
253             //TODO:根據傳入的參數添加過濾條件
254 
255             var resultCount = await query.CountAsync();
256             var result<%=paramName%> = await query
257             .OrderBy(x=>x.Id)
258             .PageBy(input)
259             .ToListAsync();
260 
261             var resultListDtos = result<%=paramName%>.MapTo<List<<%=tableName%>Dto>>();
262             return new PagedResultDto<<%=tableName%>Dto>(
263             resultCount,
264             resultListDtos
265             );
266         }
267 
268          /// <summary>
269         /// 獲取指定條件的數據列表  webapi 沒法使用
270         /// </summary>
271         /// <returns>返回數據集合</returns>
272         public async Task<List<<%=tableName%>Dto>> GetListByCodition(Expression<Func<<%=tableName%>, bool>> predicate)
273         {
274 
275             var resultList = await _<%=paramName%>Repository.GetAllListAsync(predicate);
276             return Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
277         }
278 
279 
280          /// <summary>
281         /// 導出excel 具體方法
282         /// </summary>
283         /// <returns>excel文件</returns>
284        /// public async Task<FileDto> Get<%=tableName%>ToExcel()
285         ///{
286         ///    var resultList = await _<%=paramName%>Repository.GetAllListAsync();
287         ///   var <%=paramName%>Dtos= Mapper.Map<List<<%=tableName%>Dto>>(resultList).ToList();
288         ///   return _i<%=tableName%>ListExcelExporter.ExportToFile(<%=paramName%>Dtos);
289        /// }
290 
291         /// <summary>
292         /// 根據指定id 獲取數據實體
293         /// </summary>
294         /// <param name="input">當前id</param>
295         /// <returns></returns>
296         public async Task<<%=tableName%>Dto> Get<%=tableName%>ForEditAsync(NullableIdDto<<%=tempType%>> input)
297         {
298             var output = new <%=tableName%>Dto();
299 
300            <%=tableName%>Dto <%=paramName%>EditDto;
301 
302             if (Convert.ToInt32(input.Id)>0)
303             {
304                 var entity = await _<%=paramName%>Repository.GetAsync(Convert.ToInt32(input.Id));
305                 <%=paramName%>EditDto = entity.MapTo<<%=tableName%>Dto>();
306             }
307             else
308             {
309                 <%=paramName%>EditDto = new <%=tableName%>Dto();
310             }
311 
312             output = <%=paramName%>EditDto;
313             return output;
314         }
315 
316         /// <summary>
317         /// 根據Id建立或編輯操做
318         /// </summary>
319         /// <param name="input">實體</param>
320         /// <returns></returns>
321         public async Task CreateOrUpdate<%=tableName%>Async(<%=tableName%>Dto input)
322         {
323             if (Convert.ToInt32(input.Id)>0)
324             {
325                 await Update(input);
326             }
327             else
328             {
329                 await Create(input);
330             }
331         }
332 
333         /// <summary>
334         /// 新增 
335         /// </summary>
336         /// <param name="input">新增參數</param>
337         /// <returns>新增實體</returns>
338         public async Task<<%=tempType%>> Create(<%=tableName%>Dto input)
339         {
340             input.Id = new <%=tableName%>().Id.ToString(); 
341             var resultObj = input.MapTo<<%=tableName%>>();
342             var result = await _<%=paramName%>Repository.InsertAsync(resultObj);
343 
344             return result.Id;
345         }
346 
347         /// <summary>
348         /// 修改
349         /// </summary>
350         /// <param name="input">修改參數</param>
351         /// <returns>修改實體</returns>
352         public async Task<<%=tableName%>Dto> Update(<%=tableName%>Dto input)
353         {
354             <%=tableName%> obj = await _<%=paramName%>Repository.GetAsync(Convert.ToInt32(input.Id));
355             input.MapTo(obj);
356             var result = await _<%=paramName%>Repository.UpdateAsync(obj);
357             return obj.MapTo<<%=tableName%>Dto>();
358         }
359 
360         /// <summary>
361         /// 刪除
362         /// </summary>
363         /// <param name="input">刪除Dto</param>
364         /// <returns>無返回值</returns>
365         public async System.Threading.Tasks.Task Delete(EntityDto<string> input)
366         {
367             await _<%=paramName%>Repository.DeleteAsync(Convert.ToInt32(input.Id));
368         }
369 
370         /// <summary>
371         /// 刪除 webapi 沒法使用
372         /// </summary>
373         /// <param name="predicate">刪除條件</param>
374         /// <returns>無返回值</returns>
375         public async System.Threading.Tasks.Task DeleteByCondition(Expression<Func<<%=tableName%>, bool>> predicate)
376         {
377             await _<%=paramName%>Repository.DeleteAsync(predicate);
378           
379         }
380     }
381 
382 
383             <%  }%> 
384       <%  }%> <%  }%>
385 
386    
387 }
388 
389 
390  
391 
392 <script runat="template">
393 <!-- #include file="TemplateUtilities.cs" -->
394 </script>

 

 

 

二、AppAuthorizationProvider.cst 是要和AppPermissions.cst 一塊兒使用的,我在實際項目中拆分了原有abp代碼,實現了本身的整合的版本,儘可能減小對abp 原有代碼的耦合

 AbpZeroTemplateApplicationModule 中的Configuration.Authorization.Providers.Add<CustomsAppAuthorizationProvider>(); 確保注入

 

<%-- 
Name:
Author: 
Description: 
--%>
<%@ Template Language="C#" TargetLanguage="Text" Src="" Inherits=""Debug="False" CompilerVersion="v4.0" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceDatabase" DeepLoad="True" Type="SchemaExplorer.DatabaseSchema" %>
<%@ Property Name="Tables" Type="TableSchemaCollection" Optional="True" Category="2.數據庫" Description="Tables to Inclue" %>
<%@ Template Language="C#" TargetLanguage="Text" %>
<%@ Property Name="SampleStringProperty" Default="SomeValue" Type="System.String" %>
<%@ Property Name="SampleBooleanProperty" Default="True" Type="System.Boolean" %>
<%@ Property Name="RootNamespace" Type="String" Default="HashBlockChain" Optional="False" Category="1.名稱空間" Description="系統名稱空間的根名稱." %>
<%@ Property Name="Namespace" Type="String" Default="ZLDB_Domain" Optional="False" Category="1.名稱空間" Description="系統當前所屬文件夾的名稱(命名空間相關)." %>
My static content here.
My dynamic content here: "<%= SampleStringProperty %>"
Call a script method: <%= SampleMethod() %>
<% if (SampleBooleanProperty) { %>
My conditional content here.
<% } %>
<script runat="template">
// My methods here.
public string SampleMethod()
{
  return "Method output.";
}

</script>


using System.Linq;
using Abp.Authorization;
using Abp.Localization;
using <%=RootNamespace%>.Authorization;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
//簡介:Abp 權限配置,生成後要在 AbpZeroTemplateApplicationModule 中的Configuration.Authorization.Providers.Add<CustomsAppAuthorizationProvider>(); 確保注入
//
//
//
//
//做者:
//--------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace <%= RootNamespace %>.<%=Namespace%>.Authorization
{
    /// <summary>
    /// 權限配置都在這裏。
    /// 給權限默認設置服務
    /// See <see cref="CustomsAppPermissions"/> for all permission names.
    /// </summary>
    public class CustomsAppAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //在這裏配置了自定義 的權限。

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var entityNameModel = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_Administration)
              ?? pages.CreateChildPermission(AppPermissions.Pages_Administration, L("Administration"));

                 <% foreach(TableSchema t in Tables){ %>
                 <%string tableName=t.Name.ToString(); %>
                 <%string paramName=GetParamName(tableName); %>
                 //<%=t.Description%> 權限
                 var <%=paramName%> = entityNameModel.CreateChildPermission(CustomsAppPermissions.<%=t.Name %>, L("<%=t.Name %>"));
                     <%=paramName%>.CreateChildPermission(CustomsAppPermissions.<%=t.Name %>_Create<%=t.Name %>, L("Create<%=t.Name %>"));
                     <%=paramName%>.CreateChildPermission(CustomsAppPermissions.<%=t.Name %>_Edit<%=t.Name %>, L("Edit<%=t.Name %>"));
                     <%=paramName%>.CreateChildPermission(CustomsAppPermissions.<%=t.Name %>_Delete<%=t.Name %>, L("Delete<%=t.Name %>"));

                <% }%>

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AbpZeroTemplateConsts.LocalizationSourceName);
        }
    }

}

<script runat="template">
<!-- #include file="TemplateUtilities.cs" -->
</script>

 

 三、view 文件夾中的createOrEditModal.cst 

這個是view 視圖中基於angular.js,我在這上面封裝數據驗證,若是不須要的能夠本身手動調整,而且 主動拆分爲單列和兩列的模板,須要自動手動改動

<%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Description="Generates a single entity business class." Debug="True" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="2.數據庫" Description="Database table that this entity should be based on." %>
<%@ Property Name="TablePrefixes" Type="String" Default="" Optional="True" Category="2.數據庫" Description="The table prefix to be cut from the class name" %>
<%@ Property Name="RootNamespace" Type="String" Default="ManagementSystem" Optional="False" Category="1.名稱空間" Description="系統名稱空間的根名稱." %>
<%@ Property Name="Title" Type="String" Default="createOrEditModal" Optional="False" Category="1.名稱空間" Description="系統名稱空間的Model名稱." %>
<%@ Property Name="PrefixLength" Type="Int32" Default="0" Optional="False" Category="2.數據庫" Description="數據表前綴截取長度." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="CodeSmith.BaseTemplates" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>

<%string tableClass=GetClassName(SourceTable, "", 0); %>
<%string tableName=SourceTable.Name.ToString(); %>
<%string paramName=GetParamName(tableName); %>
<%string tableDescString=GetTableDescriptionName(SourceTable.Description);%>
        

@using Abp.Web.Mvc.Extensions
@using <%=RootNamespace%>.Web.Bundling
@using <%=RootNamespace%>.AbpZeroTemplate
@{
    LocalizationSourceName = AbpZeroTemplateConsts.LocalizationSourceName;
}

@section Styles
{
    @*@Html.IncludeStyle("~/libs/bootstrap-daterangepicker/daterangepicker.css")*@

}

@section Scripts
{

    @*@Html.IncludeScript(ScriptPaths.Angular_DateRangePicker)*@
}

<div>
    @*//mark 1*@
    <form name="<%=paramName%>CreateOrEditForm" role="form" novalidate class="form-validation">
        <div class="modal-header">
            <h4 class="modal-title">
                <span ng-if="vm.<%=paramName%>.id">編輯信息:{{vm.<%=paramName%>.name}}</span>
                <span ng-if="!vm.<%=paramName%>.id">新增信息</span>
            </h4>
        </div>
        <div class="modal-body">
        
        /* 兩列模板
        
         <div class="row">
                <div class="col-sm-6">
                
                   //單列的具體代碼1
                   
                </div>
                
                 <div class="col-sm-6">
                   
                   //單列的具體代碼2
                   
                </div>
           </div>     
        
        */
          <% foreach (ColumnSchema column in SourceTable.Columns) { %> 
          <% if(column.Size>100) {%>
           <div class="form-group form-md-line-input form-md-floating-label no-hint">
                <textarea auto-focus class="form-control" name="<%=GetParamName(column.Name)%>" style="resize: none;" ng-class="{'edited':vm.<%=paramName%>.<%=GetParamName(column.Name)%>}" ng-model="vm.<%=paramName%>.<%=GetParamName(column.Name)%>" required ng-pattern="{填寫具體正則表達式}" ng-minlength="10" ng-maxlength="<%=column.Size%>"></textarea>
                <label><%=column.Description%></label>
            </div>
            <div ng-messages="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error" ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error">
                <ul class="help-block text-danger">
                    <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.pattern" ng-message="pattern"><%=column.Description%>格式不正確{具體本身再次更改}!</li>
                    <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.required" ng-message="required"><%=column.Description%>不能爲空!</li>
                    <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.minlength" ng-message="minlength"><%=column.Description%>最小長度爲10!</li>
                    <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.maxlength" ng-message="maxlength"><%=column.Description%>最大長度爲<%=column.Size%>!</li>
                </ul>
            </div>
          <%}else {%>
                    <div class="form-group form-md-line-input form-md-floating-label no-hint">
                        <input type="text" class="form-control" name="<%=GetParamName(column.Name)%>" ng-class="{'edited':vm.<%=paramName%>.<%=GetParamName(column.Name)%>}" ng-pattern="{填寫具體正則表達式}" ng-model="vm.<%=paramName%>.<%=GetParamName(column.Name)%>" required ng-minlength="10" ng-maxlength="<%=column.Size%>" />
                        <label><%=column.Description%></label>
                    </div>
                    <div ng-messages="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error" ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error">
                        <ul class="help-block text-danger">
                            <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.pattern" ng-message="pattern"><%=column.Description%>格式不正確{具體本身再次更改}!</li>
                            <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.required" ng-message="required"><%=column.Description%>不能爲空!</li>
                            <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.minlength" ng-message="minlength"><%=column.Description%>最小長度爲10!</li>
                            <li ng-show="<%=paramName%>CreateOrEditForm.<%=GetParamName(column.Name)%>.$error.maxlength" ng-message="maxlength"><%=column.Description%>最大長度爲<%=column.Size%>!</li>
                        </ul>
                    </div>
          <% }%>
        <% } %>
        </div>
        <div class="modal-footer">
            <button ng-disabled="vm.saving" type="button" class="btn btn-default" ng-click="vm.cancel()">@L("Cancel")</button>
            <button type="submit" button-busy="vm.saving" busy-text="@L("SavingWithThreeDot")" class="btn btn-primary blue" ng-click="vm.save()" ng-disabled="<%=paramName%>CreateOrEditForm.$invalid"><i class="fa fa-save"></i> <span>@L("Save")</span></button>
        </div>
    </form>
</div>
<script runat="template">
<!-- #include file="../TemplateUtilities.cs" -->
</script>

 

結果局部展現

 

 

model 實體

using System;
using Abp.Authorization.Users;
using Abp.Extensions;
using Microsoft.AspNet.Identity;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

using Abp;
//----------------------------------------------
//簡介:HashBlockChain.ZLDB_Domain  Entity 數據庫對應實體
//
//
//
//auther:
//----------------------------------------------
namespace HashBlockChain.ZLDB_Domain
{




    //獲取主鍵Id的命名


    ///鏈信息表 
    [Table("ChainInfo")]
    public partial class ChainInfo : Entity<int>
    {
        #region Declarations

        /// <summary>
        /// 鏈名稱
        /// </summary>
        [DisplayName("鏈名稱")]
        [StringLength(30)]

        public virtual string ChainName { get; set; }



        /// <summary>
        /// 鏈Id
        /// </summary>
        [DisplayName("鏈Id")]
        [StringLength(30)]

        public virtual string ChainId { get; set; }



        /// <summary>
        /// 鏈描述
        /// </summary>
        [DisplayName("鏈描述")]
        [StringLength(200)]

        public virtual string ChainDescription { get; set; }



        /// <summary>
        /// 鏈狀態
        /// </summary>

        public virtual int? ChainStatus { get; set; }



        /// <summary>
        /// 排序
        /// </summary>

        public virtual int? Sort { get; set; }



        /// <summary>
        /// 是否可見
        /// </summary>

        public virtual bool? IsEnabled { get; set; }



        /// <summary>
        /// 建立人
        /// </summary>

        public virtual int? CreateUserId { get; set; }



        /// <summary>
        /// 建立時間
        /// </summary>

        public virtual DateTime? CreateDateTime { get; set; }



        /// <summary>
        /// 最後一次修改人
        /// </summary>

        public virtual int? LastEditUserId { get; set; }



        /// <summary>
        /// 最後一次修改時間
        /// </summary>

        public virtual DateTime? LastEditDateTime { get; set; }



        /// <summary>
        /// 節點個數
        /// </summary>

        public virtual int? PeerCount { get; set; }



        /// <summary>
        /// 區塊鏈高度
        /// </summary>

        public virtual long? BlockHeight { get; set; }


        #endregion
    }
}

中英文 中文顯示

 

 

部分權限生成的代碼

 

相關文章
相關標籤/搜索