动软代码生成模版
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了动软代码生成模版,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含24248字,纯文字阅读大概需要35分钟。
内容图文
json调用类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if
(context.Request[
"operate_type"
] ==
"operate_type1"
)
{
GetOperate_type1(context);
}
else
if
(context.Request[
"operate_type"
] ==
"operate_type2"
)
{
//GetOperate_type2(context);
}
}
private
void GetOperate_type1(HttpContext context)
{
context.Response.Clear();
context.Response.Buffer =
true
;
context.Response.ContentType =
"application/json"
;
context.Response.ContentEncoding.GetBytes(
"utf-8"
);
var
sql =
""
;
System.Data.DataTable dt_ = DBUtility.DBExecuteUtil.querySqlTable(sql);
string json =
"{\"rows\":["
;
for
(int i = 0; i < dt_.Rows.Count; i++)
{
json +=
"{\"col1\":\""
+ dt_.Rows[i][
"col1"
] +
"\",\"col2\":\""
+ dt_.Rows[i][
"col2"
] +
"\"},"
;
}
json = json.TrimEnd(
‘,‘
);
json +=
"]}"
;
context.Response.Write(json);
context.Response.Flush();
context.Response.End();
}
public bool IsReusable
{
get
{
return
false
;
}
}
}
|
BLL调用类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
<
#@ template language="c#" HostSpecific="True" #>
<
#@ output extension= ".cs" #>
<
#
TableHost host = (TableHost)(Host);
string ModelSpace = host.NameSpace+
".Model."
+ host.GetModelClass(host.TableName);
string DALSpace= host.NameSpace+
".DAL."
+ host.GetDALClass(host.TableName);
ColumnInfo identityKey=host.IdentityKey;
string returnValue =
"void"
;
if
(identityKey!=
null
)
{
returnValue = CodeCommon.DbTypeToCS(identityKey.TypeName);
}
#>
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using DAL;
using Model;
namespace BLL <
# if( host.Folder.Length > 0){ #>.<#= host.Folder #><# } #>
{
<
# if( host.TableDescription.Length > 0) {#>
//<#= host.TableDescription #>
<
# } #>
public partial
class
BLL<
#= host.GetBLLClass(host.TableName) #>
{
private
readonly DAL<
#= host.TableName #> dal=new DAL<#= host.TableName #>();
public BLL<
#= host.GetBLLClass(host.TableName) #>()
{}
#region 自动代码
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(<
#= CodeCommon.GetInParameter(host.Keys, false) #>)
{
return
dal.Exists(<
#= CodeCommon.GetFieldstrlist(host.Keys, false)#>);
}
/// <summary>
/// 增加一条数据
/// </summary>
public <
#= returnValue #> Add(<#= host.TableName #>Entity model)
{
<
#if (identityKey!=null) {#>
return
dal.Add(model);
<
#} else {#>
dal.Add(model);
<
#}#>
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(<
#= host.TableName #>Entity model)
{
return
dal.Update(model);
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(<
#=CodeCommon.GetInParameter(host.Keys, true)#>)
{
return
dal.Delete(<
#=CodeCommon.GetFieldstrlist(host.Keys, true)#>);
}
public bool Delete(string strWhere)
{
return
dal.Delete(strWhere);
}
<
#if (identityKey!=null) {#>
/// <summary>
/// 批量删除一批数据
/// </summary>
public bool DeleteList(string <
#=identityKey.ColumnName#>list )
{
return
dal.DeleteList(<
#=identityKey.ColumnName#>list );
}
<
#}#>
/// <summary>
/// 得到一个对象实体
/// </summary>
public <
#= host.TableName #>Entity GetModel(<#= CodeCommon.GetInParameter(host.Keys,true) #>)
{
return
dal.GetModel(<
#=CodeCommon.GetFieldstrlist(host.Keys, true)#>);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataTable GetAllList4Table()
{
return
GetList4Table(
""
);
}
/// <summary>
/// 获得数据列表
/// </summary>
public String[][] GetAllList4Array()
{
return
GetList4Array(
""
);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataTable GetList4Table(string strWhere)
{
return
dal.GetList4Table(strWhere);
}
/// <summary>
/// 获得数据列表
/// </summary>
public String[][] GetList4Array(string strWhere)
{
return
dal.GetList4Array(strWhere);
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataTable GetList4Table(int Top,string strWhere,string filedOrder)
{
return
dal.GetList4Table(Top,strWhere,filedOrder);
}
/// <summary>
/// 获得前几行数据
/// </summary>
public String[][] GetList4Array(int Top,string strWhere,string filedOrder)
{
return
dal.GetList4Array(Top,strWhere,filedOrder);
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<<
#= host.TableName #>Entity> GetModelList(string strWhere)
{
DataTable dt = dal.GetList4Table(strWhere);
return
DataTableToList(dt);
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<<
#= host.TableName #>Entity> DataTableToList(DataTable dt)
{
List<<
#= host.TableName #>Entity> modelList = new List<<#= host.TableName #>Entity>();
int rowsCount = dt.Rows.Count;
int result;
if
(rowsCount > 0)
{
<
#= host.TableName #>Entity model;
for
(int n = 0; n < rowsCount; n++)
{
model =
new
<
#= host.TableName #>Entity();
<
# foreach (ColumnInfo c in host.Fieldlist) { #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="int"||
CodeCommon.DbTypeToCS(c.TypeName)==
"long"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"float"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"DateTime"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"decimal"
)
{
#>
if
(dt.Rows[n][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>=<#=CodeCommon.DbTypeToCS(c.TypeName)#>.Parse(dt.Rows[n]["<#=c.ColumnName#>"].ToString());
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="string") {#>
model.<
#=c.ColumnName#>= dt.Rows[n]["<#=c.ColumnName#>"].ToString();
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="int") {#>
model.<
#=c.ColumnName#> = int.TryParse(dt.Rows[n]["<#=c.ColumnName#>"].ToString(), out result) ? result : 0;
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="byte[]") {#>
if
(dt.Rows[n][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>= (byte[])dt.Rows[n]["<#=c.ColumnName#>"];
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="Guid") {#>
if
(dt.Rows[n][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>= Guid.Parse(dt.Rows[n]["<#=c.ColumnName#>"].ToString());
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="bool") {#>
if
(dt.Rows[n][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
if
((dt.Rows[n][
"<#=c.ColumnName#>"
].ToString()==
"1"
)||(dt.Rows[n][
"<#=c.ColumnName#>"
].ToString().ToLower()==
"true"
))
{
model.<
#=c.ColumnName#>= true;
}
else
{
model.<
#=c.ColumnName#>= false;
}
}
<
# } #>
<
# } #>
modelList.Add(model);
}
}
return
modelList;
}
/// <summary>
/// 获得数据列表
/// </summary>
public int GetCount(string strWhere)
{
return
dal.GetCount(strWhere);
}
#endregion
#region 人工代码
/// <summary>
/// 获得分页数据
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="model"></param>
/// <returns></returns>
public DataTable GetPage(int pageIndex, int pageSize, <
#=host.TableName#>Entity model,out int count)
{
return
dal.GetPage(pageIndex, pageSize, model,out count);
}
#endregion
}
}
|
DAL调用类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
<
#@ template language="c#" HostSpecific="True" #>
<
#@ output extension= ".cs" #>
<
#
TableHost host = (TableHost)(Host);
string DbParaHead=host.DbParaHead;
string DbParaDbType=host.DbParaDbType;
string preParameter=host.preParameter;
string ModelSpace = host.NameSpace+
".Model."
+ host.GetModelClass(host.TableName);
ColumnInfo identityKey=host.IdentityKey;
string returnValue =
"void"
;
if
(identityKey!=
null
)
{
returnValue = CodeCommon.DbTypeToCS(identityKey.TypeName);
}
#>
using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using System.Collections;
using DBUtility;
using Model;
namespace DAL
<
# if( host.Folder.Length > 0){ #>
.<
#= host.Folder #>
<
# } #>
{
<
# if( host.TableDescription.Length > 0) {#>
//<#= host.TableDescription #>
<
# } #>
public partial
class
DAL<
#= host.GetDALClass(host.TableName) #>
{
#region 自动代码
public bool Exists(<
#= CodeCommon.GetInParameter(host.Keys, false) #>)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select count(1) from <#= host.TableName #>"
);
strSql.Append(
" where "
);
<
# for(int i=0;i< host.Keys.Count;i++)
{ ColumnInfo key = host.Keys[i];
#>
<
# if (key.IsPrimaryKey || !key.IsIdentity)
{
#>
strSql.Append(
" <#= key.ColumnName#> = <#=preParameter#><#=key.ColumnName#> <# if (i< host.Keys.Count-1 ) {#>and <#}#> "
);
<
#}#>
<
# }#>
<
#= CodeCommon.GetPreParameter(host.Keys, false, host.DbType) #>
return
DBExecuteUtil.Exists(strSql.ToString(),parameters);
}
/// <summary>
/// 增加一条数据
/// </summary>
public <
#= returnValue #> Add(<#= host.TableName #>Entity model)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"insert into <#= host.TableName #>("
);
strSql.Append(
"<# for(int i=0;i< host.Fieldlist.Count;i++) { ColumnInfo c = host.Fieldlist[i]; if (!c.IsIdentity) {#><#= c.ColumnName#><# if (i< host.Fieldlist.Count-1 ) {#>,<#}#><#}}#>"
);
strSql.Append(
") values ("
);
strSql.Append(
"<# for(int i=0;i< host.Fieldlist.Count;i++) { ColumnInfo c = host.Fieldlist[i]; if (!c.IsIdentity) {#><#=preParameter#><#= c.ColumnName#><# if (i< host.Fieldlist.Count-1 ) {#>,<#}#><#}}#>"
);
strSql.Append(
") "
);
<
#if (identityKey!=null) {#>strSql.Append(";select SCOPE_IDENTITY()");<#}#>
SqlParameter[] parameters = {
<
# for(int i=0;i< host.Fieldlist.Count;i++)
{
ColumnInfo c = host.Fieldlist[i];
if
(c.IsIdentity)
continue
;
#>
new
SqlParameter(
"<#=preParameter#><#=c.ColumnName#>"
, SqlDbType.<#=CodeCommon.DbTypeLength(host.DbType, c.TypeName, c.Length)#>) <#
if
(i< host.Fieldlist.Count-1 ) {#>,<#}#>
<
# }#>
};
<
# foreach (ColumnInfo c in host.Fieldlist) { if(c.IsIdentity) continue;#>
parameters[<
#= n #>].Value = <# if ("uniqueidentifier" == c.TypeName.ToLower()){#>Guid.NewGuid();<#} else {#>model.<#=c.ColumnName#>;<#} n=n+1; #>
<
# }#>
<
#if (identityKey!=null) {#>
DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(),parameters);
if
(dt.Rows.Count == 0)
{
<
# if ( returnValue=="int" )
{
#>
return
0;
<
#} else#>
<
# if ( returnValue=="long" )
{
#>
return
0;
<
#} else#>
<
# if ( returnValue=="decimal" )
{
#>
return
0;
<
#}#>
}
else
{
<
# if ( returnValue=="int" )
{
#>
return
Convert.ToInt32(dt.Rows[0][0].ToString());
<
#}#>
<
# if ( returnValue=="long" )
{
#>
return
Convert.ToInt64(dt.Rows[0][0].ToString());
<
#}#>
<
# if ( returnValue=="decimal" )
{
#>
return
Convert.ToDecimal(dt.Rows[0][0].ToString());
<
#}#>
}
<
#} else {#>
DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(),parameters);
<
#}#>
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(<
#= host.TableName #>Entity model)
{
StringBuilder strSql=
new
StringBuilder();
List<SqlParameter> parameters =
new
List<SqlParameter>();
strSql.Append(
"update <#= host.TableName #> set "
);
<
# for(int i=0;i< host.Fieldlist.Count;i++)
{ ColumnInfo c = host.Fieldlist[i];
#>
<
# if (!c.IsIdentity && !c.IsPrimaryKey) {#>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="string") {#>
if
(!string.IsNullOrEmpty(model.<
#=c.ColumnName#>)){
strSql.Append(
" <#= c.ColumnName #> = <#=preParameter#><#=c.ColumnName#> , "
);
parameters.Add(
new
SqlParameter(
"<#=preParameter#><#=c.ColumnName#>"
,model.<#=c.ColumnName#>));
}<
# }#>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="bool") {#>
strSql.Append(
" <#= c.ColumnName #> = <#=preParameter#><#=c.ColumnName#> , "
);
parameters.Add(
new
SqlParameter(
"<#=preParameter#><#=c.ColumnName#>"
,model.<#=c.ColumnName#>));
<
# }#>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="DateTime") {#>
if
(model.<
#=c.ColumnName#>!=null){
strSql.Append(
" <#= c.ColumnName #> = <#=preParameter#><#=c.ColumnName#> , "
);
parameters.Add(
new
SqlParameter(
"<#=preParameter#><#=c.ColumnName#>"
,model.<#=c.ColumnName#>));
}
<
# }#>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="int"||
CodeCommon.DbTypeToCS(c.TypeName)==
"long"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"float"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"decimal"
)
{
#>
if
(
true
){
strSql.Append(
" <#= c.ColumnName #> = <#=preParameter#><#=c.ColumnName#> , "
);
parameters.Add(
new
SqlParameter(
"<#=preParameter#><#=c.ColumnName#>"
,model.<#=c.ColumnName#>));
}
<
#}#>
<
#}#>
<
# }#>
strSql = strSql.Remove(strSql.Length - 2,2);
strSql.Append(
" where <#= CodeCommon.GetWhereParameterExpression(host.Keys, true ,host.DbType) #> "
);
<
# for(int i=0;i< host.Keys.Count;i++)
{ ColumnInfo key = host.Keys[i];
#>
<
# if (key.IsPrimaryKey || !key.IsIdentity)
{
#>
parameters.Add(
new
SqlParameter(
"<#=preParameter#><#=key.ColumnName#>"
,model.<#=key.ColumnName#>));
<
#}#>
<
# }#>
int rows=DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(),parameters.ToArray());
if
(rows > 0)
{
return
true
;
}
else
{
return
false
;
}
}
/// <summary>
/// 删除一条数据
/// </summary
public bool Delete(<
#=CodeCommon.GetInParameter(host.Keys, true)#>)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"delete from <#= host.TableName #> "
);
strSql.Append(
" where <#= CodeCommon.GetWhereParameterExpression(host.Keys, true, host.DbType)#>"
);
<
#= CodeCommon.GetPreParameter(host.Keys, true, host.DbType) #>
int rows=DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(),parameters);
if
(rows > 0)
{
return
true
;
}
else
{
return
false
;
}
}
public bool Delete(string strWhere)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"delete from <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+strWhere);
}
else
{
return
false
;
}
int rows = DBExecuteUtil.ExecuteSql(strSql.ToString());
if
(rows > 0)
{
return
true
;
}
else
{
return
false
;
}
}
<
#if (identityKey!=null) {#>
/// <summary>
/// 批量删除一批数据
/// </summary>
public bool DeleteList(string <
#=identityKey.ColumnName#>list )
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"delete from <#= host.TableName #> "
);
strSql.Append(
" where ID in ("
+<
#=identityKey.ColumnName#>list + ") ");
int rows=DBExecuteUtil.ExecuteSql(strSql.ToString());
if
(rows > 0)
{
return
true
;
}
else
{
return
false
;
}
}
<
#}#>
/// <summary>
/// 得到一个对象实体
/// </summary>
public <
#= host.TableName #>Entity GetModel(<#= CodeCommon.GetInParameter(host.Keys,true) #>)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select <# for(int i=0;i< host.Fieldlist.Count;i++) { #><#= host.Fieldlist[i].ColumnName #><# if(i< host.Fieldlist.Count-1 ) {#>,<# } #> <#}#> "
);
strSql.Append(
" from <#= host.TableName #> "
);
strSql.Append(
" where <#= CodeCommon.GetWhereParameterExpression(host.Keys, true, host.DbType) #>"
);
<
#=CodeCommon.GetPreParameter(host.Keys, true, host.DbType)#>
<
#= host.TableName #>Entity model=new <#= host.TableName #>Entity();
DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(),parameters);
if
(dt.Rows.Count>0)
{
<
# foreach (ColumnInfo c in host.Fieldlist) { #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="int"||
CodeCommon.DbTypeToCS(c.TypeName)==
"long"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"float"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"DateTime"
||
CodeCommon.DbTypeToCS(c.TypeName)==
"decimal"
)
{
#>
if
(dt.Rows[0][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>=<#=CodeCommon.DbTypeToCS(c.TypeName)#>.Parse(dt.Rows[0]["<#=c.ColumnName#>"].ToString());
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="string") {#>
model.<
#=c.ColumnName#>= dt.Rows[0]["<#=c.ColumnName#>"].ToString();
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="byte[]") {#>
if
(dt.Rows[0][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>= (byte[])dt.Rows[0]["<#=c.ColumnName#>"];
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="Guid") {#>
if
(dt.Rows[0][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
model.<
#=c.ColumnName#>= Guid.Parse(dt.Rows[0]["<#=c.ColumnName#>"].ToString());
}
<
# } #>
<
# if(CodeCommon.DbTypeToCS(c.TypeName)=="bool") {#>
if
(dt.Rows[0][
"<#=c.ColumnName#>"
].ToString()!=
""
)
{
if
((dt.Rows[0][
"<#=c.ColumnName#>"
].ToString()==
"1"
)||(dt.Rows[0][
"<#=c.ColumnName#>"
].ToString().ToLower()==
"true"
))
{
model.<
#=c.ColumnName#>= true;
}
else
{
model.<
#=c.ColumnName#>= false;
}
}
<
# } #>
<
# } #>
return
model;
}
else
{
return
null
;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
/// <param name="strWhere"></param>
/// <returns>datatable</returns>
public DataTable GetList4Table(string strWhere)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select * "
);
strSql.Append(
" FROM <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+strWhere);
}
return
DBExecuteUtil.querySqlTable(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
/// <param name="strWhere"></param>
/// <returns>array</returns>
public String[][] GetList4Array(string strWhere)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select * "
);
strSql.Append(
" FROM <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+strWhere);
}
return
DBExecuteUtil.querySqlArray(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
/// <param name="strWhere"></param>
/// <returns>datatable</returns>
public DataTable GetList4Table(int Top,string strWhere,string filedOrder)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select "
);
if
(Top>0)
{
strSql.Append(
" top "
+Top.ToString());
}
strSql.Append(
" * "
);
strSql.Append(
" FROM <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+ strWhere);
}
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" order by "
+ filedOrder);
}
return
DBExecuteUtil.querySqlTable(strSql.ToString());
}
/// <summary>
/// 获得数据列表
/// </summary>
/// <param name="strWhere"></param>
/// <returns>array</returns>
public String[][] GetList4Array(int Top,string strWhere,string filedOrder)
{
StringBuilder strSql=
new
StringBuilder();
strSql.Append(
"select "
);
if
(Top>0)
{
strSql.Append(
" top "
+Top.ToString());
}
strSql.Append(
" * "
);
strSql.Append(
" FROM <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+ strWhere);
}
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" order by "
+ filedOrder);
}
return
DBExecuteUtil.querySqlArray(strSql.ToString());
}
/// <summary>
/// 获取数据总数
/// </summary>
/// <param name="strWhere"></param>
/// <returns></returns>
public int GetCount(string strWhere)
{
StringBuilder strSql =
new
StringBuilder();
strSql.Append(
"select count(*) "
);
strSql.Append(
" FROM <#= host.TableName #> "
);
if
(!string.IsNullOrEmpty(strWhere))
{
strSql.Append(
" where "
+ strWhere);
}
string str_count = DBExecuteUtil.querySqlTable(strSql.ToString()).Rows[0][0].ToString();
int int_count = 0;
bool b_count = int.TryParse(str_count,out int_count);
return
int_count;
}
#endregion
#region 人工代码
/// <summary>
/// 获取分页数据
/// </summary>
/// <returns></returns>
public DataTable GetPage(int pageIndex, int pageSize,<
#= host.TableName #>Entity model,out int count)
{
count = 0;
SqlParameter[] items=
new
SqlParameter[]{
new
SqlParameter(
"pageIndex"
,pageIndex),
new
SqlParameter(
"pageSize"
,pageSize),
new
SqlParameter(
"count"
,count)
};
items[2].Direction = ParameterDirection.Output;
var
dt= DBStoreProUtil.queryProTable4Params(
"proc_<#= host.TableName #>_Pagedata"
, items);
count=int.Parse(items[2].Value.ToString());
return
dt;
}
#endregion
}
}
<
#+
int n=0;
#>
|
Model调用类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<
#@ template language="c#" HostSpecific="True" #>
<
#@ output extension= ".cs" #>
<
#
TableHost host = (TableHost)(Host);
host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
#>
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
namespace Model<
# if( host.Folder.Length > 0) {#>.<#= host.Folder #><# } #>
{
<
# if( host.TableDescription.Length > 0) {#>
//<#= host.TableDescription #>
<
# } #>
public
class
<
#= host.GetModelClass(host.TableName) #>Entity
{
<
# foreach (ColumnInfo c in host.Fieldlist)
{
#>
public <
#= CodeCommon.DbTypeToCS(c.TypeName) #> <#= c.ColumnName #>{get;set;}
<
# } #>
}
}
|
原文:http://www.cnblogs.com/TivonStone/p/3630943.html
内容总结
以上是互联网集市为您收集整理的动软代码生成模版全部内容,希望文章能够帮你解决动软代码生成模版所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。