-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.cs
344 lines (286 loc) · 9.18 KB
/
Helper.cs
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
using Hyc.DbDriver.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Hyc.DbDriver
{
public class Helper<Entity> where Entity : class,new()
{
/// <summary>
/// 数据库类型
/// </summary>
public String DbProvider { get; set; }
/// <summary>
/// 表前缀
/// </summary>
public String TablePrefix { get; set; }
private string tableName = "";
IDbHelper DbHelper = null;
public Helper(string DBConnectString, string DbProvider, string TablePrefix)
{
this.TablePrefix = TablePrefix;
tableName = new Entity().GetType().Name;
string tmpTable = TableAttributeHelper<Entity>.TableName();
if (!string.IsNullOrEmpty(tmpTable))
tableName = tmpTable;
//System.Web.HttpContext.Current.Response.Write(tableName);
switch (DbProvider.ToLower())
{
case "mssql":
DbHelper = new SqlServer.DbHelper(DBConnectString, tableName, TablePrefix);
break;
case "mysql":
DbHelper = new MySql.DbHelper(DBConnectString, tableName, TablePrefix);
break;
default:
DbHelper = new SqlServer.DbHelper(DBConnectString, tableName, TablePrefix);
break;
}
}
public object CreateRecord(Entity model)
{
return DbHelper.CreateRecord<Entity>(model);
}
public object CreateRecord(Hashtable myhash)
{
return DbHelper.CreateRecord<Entity>(myhash);
}
public object UpdateRecord(Hashtable myhash)
{
return DbHelper.UpdateRecord<Entity>(myhash);
}
public void UpdateRecord(Hashtable myhash, Hashtable update_hash)
{
DbHelper.UpdateRecord<Entity>(myhash, update_hash);
}
/// <summary>
/// 根据主键删除记录
/// </summary>
/// <param name="Code"></param>
public void DeleteRecord(object Code)
{
DbHelper.DeleteRecord<Entity>(Code);
}
/// <summary>
/// 删除记录
/// </summary>
/// <param name="Code"></param>
public void DeleteRecord(string strwhere)
{
DbHelper.DeleteRecord<Entity>(strwhere);
}
public void DeleteRecord(Expression<Func<Entity, bool>> where)
{
DbHelper.DeleteRecord<Entity>(where);
}
public bool Exists(string strwhere)
{
return DbHelper.Exists<Entity>(strwhere);
}
public bool Exists(string strwhere, Hashtable myhash)
{
return DbHelper.Exists<Entity>(strwhere,myhash);
}
/// <summary>
/// 获得一个值
/// </summary>
public object GetColObject(string Col, string strWhere)
{
return DbHelper.GetColObject<Entity>(Col, strWhere);
}
/// <summary>
/// 统计数量
/// </summary>
/// <param name="strwhere"></param>
/// <returns></returns>
public Int32 GetTableTotal(string strwhere)
{
return DbHelper.GetTableTotal<Entity>(strwhere);
}
/// <summary>
/// 获得一个值
/// </summary>
public Int32 GetTableSum(string col,string strWhere)
{
return DbHelper.GetTableSum<Entity>(col,strWhere);
}
public void UpdateByCol(string Col, string Value, string CodeCol, int code)
{
DbHelper.UpdateByCol<Entity>(Col,Value,CodeCol,code);
}
public void UpdateByCol(string[] Col, string[] Value, string CodeCol, int code)
{
DbHelper.UpdateByCol<Entity>(Col, Value, CodeCol, code);
}
public void UpdateByCol(string Col, string Value, string CodeCol, string code)
{
DbHelper.UpdateByCol<Entity>(Col, Value, CodeCol, code);
}
public void UpdateByCol(string[] Col, string[] Value, string CodeCol, string code)
{
DbHelper.UpdateByCol<Entity>(Col, Value, CodeCol, code);
}
/// <summary>
/// 自增
/// </summary>
/// <param name="ColName">自增字段</param>
/// <param name="IncValue">自增基数</param>
/// <param name="CodeCol"></param>
/// <param name="code"></param>
public void Inc(string ColName, int IncValue, string CodeCol, string code)
{
DbHelper.Inc<Entity>(ColName, IncValue, CodeCol, code);
}
/// <summary>
/// 自增
/// </summary>
/// <param name="ColName">自增字段</param>
/// <param name="IncValue">自增基数</param>
/// <param name="strwhere"></param>
public void Inc(string ColName, int IncValue, string strwhere)
{
DbHelper.Inc<Entity>(ColName, IncValue, strwhere);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet FindList(string strWhere, string order)
{
return DbHelper.FindList<Entity>(strWhere, order);
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet FindList(string Column, string strWhere, string order)
{
return DbHelper.FindList<Entity>(Column,strWhere, order);
}
/// <summary>
/// 分页显示数据
/// </summary>
public DataSet FindByPage(string FieldKey, int PageSize, int PageIndex, string strWhere, string Column, string FieldOrder)
{
return DbHelper.FindByPage<Entity>(FieldKey, PageSize, PageIndex, strWhere, Column, FieldOrder);
}
/// <summary>
/// 分页显示数据
/// </summary>
public DataSet FindByPage(string FieldKey, int PageSize, int PageIndex, Expression<Func<Entity, bool>> where, string Column, string FieldOrder)
{
return DbHelper.FindByPage<Entity>(FieldKey, PageSize, PageIndex, where, Column, FieldOrder);
}
/// <summary>
/// 分页显示数据
/// </summary>
public DataSet FindByPage(string FieldKey, int PageSize, int PageIndex, string strWhere, string Column, string FieldOrder, ref int RecordCount)
{
return DbHelper.FindByPage<Entity>(FieldKey, PageSize, PageIndex, strWhere, Column, FieldOrder, ref RecordCount);
}
public Entity TryFind(string column, string where)
{
return DbHelper.TryFind<Entity>(column,where);
}
public Entity TryFind(string where)
{
return DbHelper.TryFind<Entity>(where);
}
public Entity TryFind(string column, string where, Hashtable table)
{
return DbHelper.TryFind<Entity>(column,where,table);
}
public Entity TryFind(string where, Hashtable table)
{
return DbHelper.TryFind<Entity>(where, table);
}
public List<Entity> ToList(DataSet table)
{
return DbHelper.ToList<Entity>(table);
}
/// <summary>
/// 获取最大字段
/// </summary>
/// <param name="Column"></param>
/// <param name="where"></param>
/// <returns></returns>
public object FindMaxColumn(string Column, string where)
{
return DbHelper.FindMaxColumn<Entity>(Column,where);
}
/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="ProcName"></param>
/// <param name="p"></param>
public int Procedure(string ProcName, DbParameter[] p)
{
return DbHelper.Procedure(ProcName, p);
}
/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="ProcName"></param>
/// <param name="p"></param>
public int ProcedureByErr(string ProcName, DbParameter[] p, ref String ErrString)
{
return DbHelper.ProcedureByErr(ProcName, p, ref ErrString);
}
/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="ProcName"></param>
/// <param name="p"></param>
public DataSet ProDataSet(string ProcName, DbParameter[] p)
{
return DbHelper.ProDataSet(ProcName, p);
}
/// <summary>
/// 执行sql语句
/// </summary>
/// <param name="sql"></param>
/// <returns></returns>
public DataSet Query(string sql)
{
return DbHelper.Query(sql);
}
public DataSet Query(string sql, DbParameter[] p)
{
return DbHelper.Query(sql,p);
}
public Int32 ExecuteNonQuery(string sql, DbParameter[] p)
{
return DbHelper.ExecuteNonQuery(sql, p);
}
public Int32 ExecuteNonQuery(string sql, Hashtable table)
{
return DbHelper.ExecuteNonQuery<Entity>(sql, table);
}
/// <summary>
/// 支持sql2005以上分页
/// </summary>
/// <param name="Table">表,支持多表,使用sql语句</param>
/// <param name="ColName">查询的字段</param>
/// <param name="OrderString">排序(必填)</param>
/// <param name="strWhere">条件</param>
/// <param name="para">参数</param>
/// <param name="page">页码</param>
/// <param name="PageSize">每页显示数</param>
/// <returns></returns>
public DataSet FindSetBySql(string tableName, string ColName, string OrderString, string strWhere, DbParameter[] para, int page, int PageSize)
{
return DbHelper.FindSetBySql(tableName, ColName, OrderString, strWhere, para, page, PageSize);
}
public DataSet FindSetBySql(string tableName, string ColName, string OrderString, string strWhere, Hashtable table, int page, int PageSize)
{
return DbHelper.FindSetBySql<Entity>(tableName, ColName, OrderString, strWhere, table, page, PageSize);
}
public List<DbParameter> DbParameter(Dictionary<string, object> dict)
{
return DbHelper.DbParameter(dict);
}
}
}