(08)通用的数据访问 OleDbHelper
2008-06-25 09:36 通用C#系统架构 阅读(3513) 评论(11) 编辑 收藏 举报
(08)通用的数据访问 OleDbHelper
Code
1//------------------------------------------------------------
2// All Rights Reserved , Copyright (C) 2008 , Jirisoft , Ltd.
3//------------------------------------------------------------
4
5using System;
6using System.Data;
7using System.Data.Common;
8using System.IO;
9using System.Text;
10using System.Globalization;
11using System.Data.OleDb;
12using System.Reflection;
13using System.Diagnostics;
14
15namespace Jirisoft.Common.DbUtilities
16{
17 using Jirisoft.Common;
18 using Jirisoft.Common.Utilities;
19
20 /**//// <summary>
21 /// OleDbHelper
22 /// 有关数据库连接的方法。
23 ///
24 /// 修改纪录
25 ///
26 /// 2008.06.01 版本:5.4 JiRiGaLa 数据库连接获得方式进行改进,构造函数获得调通。
27 /// 2008.05.31 版本:5.3 JiRiGaLa 参数命名param前缀替换为小写字母开始。
28 /// 2008.05.09 版本:5.2 JiRiGaLa InTransaction 命名改进。
29 /// 2008.05.07 版本:5.1 JiRiGaLa AddParameter 方法改进。
30 /// 2008.03.27 版本:5.1 JiRiGaLa 完善写日志功能。
31 /// 2008.02.24 版本:5.0 JiRiGaLa 修改函数名为 OleDbHelper, 增加日志功能, 增加异步调用功能, 增加 DataReader 功能。
32 /// 2008.02.23 版本:4.9 JiRiGaLa 增加 OleDbTransaction 事务处理功能。
33 /// 2008.02.21 版本:4.8 JiRiGaLa 函数获得服务器时间函数 GetDBDateTime()。
34 /// 2007.12.25 版本:4.7 JiRiGaLa 函数增加 TimeFormat 时间格式定义。
35 /// 2007.11.29 版本:4.6 JiRiGaLa SqlSafe() 函数增加,判断参数的安全性。
36 /// 2007.11.28 版本:4.5 JiRiGaLa Open() 时间不需要每次都读配置信息,只读取一次就够了。
37 /// 2007.10.26 版本:4.4 JiRiGaLa 增加填充 DataTable 功能。
38 /// 2007.07.30 版本:4.2 JiRiGaLa 配置信息从 Instance 读取。
39 /// 2007.07.20 版本:4.1 JiRiGaLa 修改 IsUseTransaction 标志信息错误。
40 /// 2007.06.23 版本:4.0 JiRiGaLa 改进 ExecuteScalar,ExecuteNonQuery 方法,完善方法。
41 /// 2007.05.23 版本:3.9 JiRiGaLa 改进 Environment.TickCount 方法,性能改进。
42 /// 2007.05.07 版本:3.8 JiRiGaLa 改进 BeginTransaction() 方法,满足更灵活的需求。
43 /// 2007.04.14 版本:3.7 JiRiGaLa 检查程序格式通过,不再进行修改代码操作。
44 /// 2007.01.07 版本:3.6 JiRiGaLa 增加简单的注册功能部分。
45 /// 2006.11.17 版本:3.5 JiRiGaLa 改进使用事务部分。
46 /// 2006.09.11 版本:3.4 JiRiGaLa 改进使用存储过程的。
47 /// 2006.04.18 版本:3.3 JiRiGaLa 重新调整代码的规范化。
48 /// 2006.02.04 版本:3.2 JiRiGaLa 用System.DateTime.Now.Ticks进行性能测试用。
49 /// 2006.02.04 版本:3.1 JiRiGaLa #if (DEBUG) #endif(ok) 添加条件编译选项。
50 /// 2006.02.02 版本:3.0 JiRiGaLa 删除数据库连接池的想法(ok)。
51 /// 2006.02.01 版本:2.9 JiRiGaLa 还想改进成支持事务类型的(ok)。
52 /// 2005.12.29 版本:2.8 JiRiGaLa 数据库类型等用枚举类型的方式进行改进。
53 /// 2005.08.19 版本:2.7 JiRiGaLa 代码继续改进一次。
54 /// 2005.08.14 版本:2.6 JiRiGaLa 参数有效化。
55 /// 2005.08.08 版本:2.5 JiRiGaLa 修改注册表读写方法。
56 /// 2005.07.10 版本:2.4 JiRiGaLa 改进类名称。
57 /// 2005.03.07 版本:2.3 JiRiGaLa 改进排版根式。
58 /// 2004.11.18 版本:2.2 JiRiGaLa 改进代码编排格式。
59 /// 2004.08.24 版本:2.1 JiRiGaLa 增加Access连接字符串。
60 /// 2004.08.22 版本:2.0 JiRiGaLa 增加空的构造方法。
61 /// 2004.07.30 版本:1.9 JiRiGaLa 改进数据库连接池功能。
62 /// 2004.06.09 版本:1.8 JiRiGaLa 改进数据库了连接池功能,得经过一段时间的测试比较好。
63 /// 2004.03.21 版本:1.7 JiRiGaLa 改进读取注册表的方法,可以不从注册表读取参数,可以指定参数。
64 /// 2004.02.17 版本:1.6 JiRiGaLa 重新整理一些方法,命名方式等适当修改,全局变量,局部变量等重新命名。
65 /// 2004.02.17 版本:1.5 JiRiGaLa 将变量名字中的_符号尽量去掉了,局部变量采用_开头的变量名。
66 /// 2004.02.17 版本:1.4 JiRiGaLa 并且采用了String.Format方法,字符串看起来更顺眼,加强了抛出异常throw的方法。
67 /// 2003.11.26 版本:1.3 JiRiGaLa 数据库丢失连接的改进,设置过期时间,为了提高运行效率仍然使用保持连接方式。
68 /// 2003.10.24 版本:1.2 JiRiGaLa 数据库不采用保持连接的方式,注释文件的编写方式改变。
69 /// 2003.10.24 版本:1.1 JiRiGaLa 将类改进为静太方式,不用创建新的类,就可以获得数据库连接。
70 /// 2003.10.14 版本:1.0 JiRiGaLa 改进成以后可以扩展到多种数据库的结构形式。
71 ///
72 /// 版本:5.0
73 ///
74 /// <author>
75 /// <name>JiRiGaLa</name>
76 /// <date>2008.02.24</date>
77 /// </author>
78 /// </summary>
79 public class OleDbHelper : IDbHelper, IDisposable
80 {
81 public OleDbConnection myOleDbConnection = new OleDbConnection();
82 public OleDbCommand myOleDbCommand = new OleDbCommand();
83 public OleDbDataAdapter myOleDbDataAdapter = new OleDbDataAdapter();
84 public OleDbTransaction myOleDbTransaction;
85 private bool inTransaction; // 是否已在事务之中
86
87 public String FileName = "OleDbHelper.txt"; // SQL查询语句日志
88
89 public OleDbHelper()#region public OleDbHelper()
90 /**//// <summary>
91 /// 构造方法
92 /// </summary>
93 public OleDbHelper()
94 {
95 }
96 #endregion
97
98 public OleDbHelper(String connectionString)#region public OleDbHelper(String connectionString)
99 /**//// <summary>
100 /// 设定软件名称
101 /// </summary>
102 /// <param name="connectionString">数据连接</param>
103 public OleDbHelper(String connectionString) : this()
104 {
105 this.myOleDbConnection.ConnectionString = connectionString;
106 }
107 #endregion
108
109 public String GetDBNow()#region public String GetDBNow()
110 /**//// <summary>
111 /// 获得数据库日期时间
112 /// </summary>
113 /// <returns>日期时间</returns>
114 public String GetDBNow()
115 {
116 String returnValue = " Getdate() ";
117 switch (BaseConfiguration.Instance.DataBaseType)
118 {
119 case DataBaseType.Access:
120 returnValue = "'" + DateTime.Now.ToString() + "'";
121 break;
122 case DataBaseType.Sqlserver:
123 returnValue = " GetDate() ";
124 break;
125 case DataBaseType.Oracle:
126 returnValue = " SYSDATE ";
127 break;
128 }
129 return returnValue;
130 }
131 #endregion
132
133 public DateTime GetDBDateTime() 获得数据库日期时间#region public DateTime GetDBDateTime() 获得数据库日期时间
134 /**//// <summary>
135 /// 获得数据库日期时间
136 /// </summary>
137 /// <returns>日期时间</returns>
138 public DateTime GetDBDateTime()
139 {
140 String sqlQuery = this.GetDBNow();
141 Object myObject = this.ExecuteScalar(sqlQuery);
142 return DateTime.Parse(myObject.ToString());
143 }
144 #endregion
145
146 public bool InTransaction 是否已采用事务#region public bool InTransaction 是否已采用事务
147 /**//// <summary>
148 /// 是否已采用事务
149 /// </summary>
150 /// <returns>采用事务</returns>
151 public bool InTransaction
152 {
153 get
154 {
155 return this.inTransaction;
156 }
157 set
158 {
159 this.inTransaction = value;
160 }
161 }
162 #endregion
163
164 public IDbConnection GetDbConnection() 获取数据库连接#region public IDbConnection GetDbConnection() 获取数据库连接
165 /**//// <summary>
166 /// 获取数据库连接
167 /// </summary>
168 /// <returns>数据库连接</returns>
169 public IDbConnection GetDbConnection()
170 {
171 return this.myOleDbConnection;
172 }
173 #endregion
174
175 public IDbTransaction GetDbTransaction() 获取数据源上执行的事务#region public IDbTransaction GetDbTransaction() 获取数据源上执行的事务
176 /**//// <summary>
177 /// 获取数据源上执行的事务
178 /// </summary>
179 /// <returns>数据源上执行的事务</returns>
180 public IDbTransaction GetDbTransaction()
181 {
182 return this.myOleDbTransaction;
183 }
184 #endregion
185
186 public IDbCommand GetDbCommand() 获取数据源上命令#region public IDbCommand GetDbCommand() 获取数据源上命令
187 /**//// <summary>
188 /// 获取数据源上命令
189 /// </summary>
190 /// <returns>数据源上命令</returns>
191 public IDbCommand GetDbCommand()
192 {
193 return this.myOleDbCommand;
194 }
195 #endregion
196
197
198 public IDbConnection Open()#region public IDbConnection Open()
199 /**//// <summary>
200 /// 这时主要的获取数据库连接的方法
201 /// </summary>
202 /// <returns>数据库连接</returns>
203 public IDbConnection Open()
204 {
205 #if (DEBUG)
206 int milliStart = Environment.TickCount;
207 #endif
208 if (String.IsNullOrEmpty(this.myOleDbConnection.ConnectionString))
209 {
210 // 这里是获取一个连接的详细方法
211 if (this.myOleDbConnection.ConnectionString.Length == 0)
212 {
213 BaseConfiguration.Instance.GetSetting();
214 }
215 this.Open(BaseConfiguration.Instance.OleDbConnection);
216 }
217 // 写入调试信息
218 #if (DEBUG)
219 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
220 #endif
221 return this.myOleDbConnection;
222 }
223 #endregion
224
225 public IDbConnection Open(String connectionString)#region public IDbConnection Open(String connectionString)
226 /**//// <summary>
227 /// 获得新的数据库连接
228 /// </summary>
229 /// <param name="connectionString">数据库连接字符串</param>
230 /// <returns>数据库连接</returns>
231 public IDbConnection Open(String connectionString)
232 {
233 // 写入调试信息
234 #if (DEBUG)
235 int milliStart = Environment.TickCount;
236 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
237 #endif
238 // 这里数据库连接打开的时候,就判断注册属性的有效性
239 if (!BaseCodeChange.Instance.CheckRegister())
240 {
241 // 若没有进行注册,让程序无法打开数据库比较好。
242 this.myOleDbConnection.ConnectionString = String.Empty;
243 // 抛出异常信息显示给客户
244 throw new Exception(BaseConfiguration.Instance.ExceptionInfo);
245 }
246 if (this.myOleDbConnection.State == ConnectionState.Closed)
247 {
248 this.myOleDbConnection.ConnectionString = connectionString;
249 this.myOleDbConnection.Open();
250 // 创建对象
251 this.myOleDbCommand = new OleDbCommand(String.Empty, this.myOleDbConnection);
252 this.myOleDbDataAdapter = new OleDbDataAdapter(String.Empty, this.myOleDbConnection);
253 // 写入调试信息
254 #if (DEBUG)
255 int milliEnd = Environment.TickCount;
256 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
257 #endif
258 }
259 return this.myOleDbConnection;
260 }
261 #endregion
262
263
264 public bool TestConn(String dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)#region public bool TestConn(String dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)
265 /**//// <summary>
266 /// 测试数据库连接是否成功,这里抛出异常进行加强,充分使用系统的异常功能。
267 /// </summary>
268 /// <param name="dataBaseType">数据库类别</param>
269 /// <param name="dataBase">数据库名称</param>
270 /// <param name="userName">用户名</param>
271 /// <param name="password">密码</param>
272 /// <param name="workstation">服务器名称</param>
273 /// <param name="trustLink">是否信任的连接</param>
274 /// <returns>是否连接成功</returns>
275 public bool TestConn(DataBaseType dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)
276 {
277 // 写入调试信息
278 #if (DEBUG)
279 int milliStart = Environment.TickCount;
280 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
281 #endif
282 bool returnValue = false; // 连接是否成功
283 String connectionString = String.Empty; // 连接字符传
284 OleDbConnection DbConnection = null; // 数据库连接
285 connectionString = BaseConfiguration.Instance.GetOleDbConnection(dataBaseType, dataBase, userName, password, workstation, trustLink);
286 DbConnection = (OleDbConnection)this.Open(connectionString);
287 try
288 {
289 if (DbConnection.State == ConnectionState.Closed)
290 {
291 DbConnection.Open();
292 }
293 DbConnection.Close();
294 returnValue = true;
295 }
296 catch (OleDbException myOleDbException)
297 {
298 DbConnection = null;
299 throw myOleDbException;
300 }
301 // 写入调试信息
302 #if (DEBUG)
303 int milliEnd = Environment.TickCount;
304 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
305 #endif
306 return returnValue;
307 }
308 #endregion
309
310 public String SqlSafe(String value) 检查参数的安全性#region public String SqlSafe(String value) 检查参数的安全性
311 /**//// <summary>
312 /// 检查参数的安全性
313 /// </summary>
314 /// <param name="value">参数</param>
315 /// <returns>安全的参数</returns>
316 public String SqlSafe(String value)
317 {
318 value = value.Replace("'", "''");
319 // value = value.Replace("%", "'%");
320 return value;
321 }
322 #endregion
323
324 public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues)#region public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues)
325 /**//// <summary>
326 /// 获取参数
327 /// </summary>
328 /// <param name="targetFiled">目标字段</param>
329 /// <param name="targetValue">值</param>
330 /// <returns>参数集</returns>
331 public DbParameter[] GetParameters(String[] targetFileds, Object[] myTargetValues)
332 {
333 DbParameter[] myDbParameters = new DbParameter[0];
334 if (targetFileds != null && myTargetValues != null)
335 {
336 myDbParameters = new DbParameter[targetFileds.Length];
337 for (int i = 0; i < targetFileds.Length; i++)
338 {
339 myDbParameters[i] = this.GetParameter(targetFileds[i], myTargetValues[i]);
340 }
341 }
342 return myDbParameters;
343 }
344 #endregion
345
346 public DbParameter GetParameter(String targetFiled, Object targetValue)#region public DbParameter GetParameter(String targetFiled, Object targetValue)
347 /**//// <summary>
348 /// 获取参数
349 /// </summary>
350 /// <param name="targetFiled">目标字段</param>
351 /// <param name="targetValue">值</param>
352 /// <returns>参数</returns>
353 public DbParameter GetParameter(String targetFiled, Object myTargetValue)
354 {
355 OleDbParameter myDbParameter = null;
356 if (myTargetValue is String)
357 {
358 myDbParameter = new OleDbParameter(targetFiled, OleDbType.VarChar);
359 }
360 else
361 {
362 if (myTargetValue is Boolean)
363 {
364 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Boolean);
365 }
366 else
367 {
368 if (myTargetValue is DateTime)
369 {
370 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Date);
371 }
372 else
373 {
374 if (myTargetValue is int)
375 {
376 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Integer);
377 }
378 else
379 {
380 if (myTargetValue is Int64)
381 {
382 myDbParameter = new OleDbParameter(targetFiled, OleDbType.BigInt);
383 }
384 else
385 {
386 if (myTargetValue is Double)
387 {
388 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Double);
389 }
390 else
391 {
392 if (myTargetValue is Byte[])
393 {
394 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Binary);
395 }
396 else
397 {
398 myDbParameter = new OleDbParameter(targetFiled, OleDbType.VarChar);
399 }
400 }
401 }
402 }
403 }
404 }
405 }
406 myDbParameter.Value = myTargetValue;
407 return myDbParameter;
408 }
409 #endregion
410
411 public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue)#region public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue)
412 /**//// <summary>
413 /// 添加参数
414 /// </summary>
415 /// <param name="myTargetDbCommand">数据库命令</param>
416 /// <param name="targetFiled">目标字段</param>
417 /// <param name="targetValue">值</param>
418 public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object myTargetValue)
419 {
420 ((OleDbCommand)myTargetDbCommand).Parameters.Add(this.GetParameter(targetFiled, myTargetValue));
421 }
422 #endregion
423
424 public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句#region public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句
425 /**//// <summary>
426 /// 获得条件语句
427 /// </summary>
428 /// <param name="names">字段名</param>
429 /// <param name="values">字段值</param>
430 /// <param name="relation">逻辑关系</param>
431 /// <returns>字符串</returns>
432 public String GetWhereString(String[] names, ref Object[] values, String relation)
433 {
434 String returnValue = String.Empty;
435 String subSqlQuery = String.Empty;
436 for (int i = 0; i < names.Length; i++)
437 {
438 if ((names[i] != null) && (names[i].Length > 0))
439 {
440 if (values[i] == null)
441 {
442 subSqlQuery = " (" + names[i] + " IS NULL) ";
443 }
444 else
445 {
446 // 这里操作,就会有些重复了,不应该进行处理
447 // values[i] = this.SqlSafe(values[i].ToString());
448 subSqlQuery = " (" + names[i] + " = " + this.GetParameter(names[i]) + ") ";
449
450 if ((values[i].ToString().IndexOf('[') >= 0) || (values[i].ToString().IndexOf(']') >= 0))
451 {
452 values[i] = values[i].ToString().Replace("[", "/[");
453 values[i] = values[i].ToString().Replace("]", "/]");
454 values[i] = this.SqlSafe(values[i].ToString());
455 subSqlQuery = " (" + names[i] + " LIKE '" + values[i] + "' ESCAPE '/') ";
456 values[i] = null;
457 // subSqlQuery = " (" + names[i] + " LIKE ? ESCAPE '/') ";
458 }
459 }
460 returnValue += subSqlQuery + relation;
461 }
462 }
463 if (returnValue.Length > 0)
464 {
465 returnValue = returnValue.Substring(0, returnValue.Length - relation.Length - 1);
466 }
467 return returnValue;
468 }
469 #endregion
470
471 String GetParameter(String parameter) 获得参数Sql表达式#region String GetParameter(String parameter) 获得参数Sql表达式
472 /**//// <summary>
473 /// 获得参数Sql表达式
474 /// </summary>
475 /// <param name="parameter">参数名称</param>
476 /// <returns>字符串</returns>
477 public String GetParameter(String parameter)
478 {
479 return " ? ";
480 }
481 #endregion
482
483 public String PlusSign() 字符串相加符号#region public String PlusSign() 字符串相加符号
484 /**//// <summary>
485 /// 字符串相加符号
486 /// </summary>
487 /// <returns>字符加</returns>
488 public String PlusSign()
489 {
490 String returnValue = " + ";
491 switch (BaseConfiguration.Instance.DataBaseType)
492 {
493 case DataBaseType.Access:
494 case DataBaseType.Sqlserver:
495 returnValue = " + ";
496 break;
497 case DataBaseType.Oracle:
498 returnValue = " || ";
499 break;
500 }
501 return returnValue;
502 }
503 #endregion
504
505
506 public IDataReader ExecuteReader(String sqlQuery)#region public IDataReader ExecuteReader(String sqlQuery)
507 /**//// <summary>
508 /// 执行查询
509 /// </summary>
510 /// <param name="sqlQuery">sql查询</param>
511 /// <returns>结果集流</returns>
512 public IDataReader ExecuteReader(String sqlQuery)
513 {
514 // 写入调试信息
515 #if (DEBUG)
516 int milliStart = Environment.TickCount;
517 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
518 #endif
519 this.myOleDbCommand.CommandType = CommandType.Text;
520 this.myOleDbCommand.CommandText = sqlQuery;
521 if (this.InTransaction)
522 {
523 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
524 }
525 OleDbDataReader myOleDbDataReader = this.myOleDbCommand.ExecuteReader();
526 // 写入调试信息
527 #if (DEBUG)
528 int milliEnd = Environment.TickCount;
529 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
530 #endif
531 // 写入日志
532 this.WriteLog(sqlQuery);
533 return myOleDbDataReader;
534 }
535 #endregion
536
537 public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters);#region public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters);
538 /**//// <summary>
539 /// 执行查询
540 /// </summary>
541 /// <param name="sqlQuery">sql查询</param>
542 /// <param name="myDbParameterCollection">参数集</param>
543 /// <returns>结果集流</returns>
544 public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters)
545 {
546 return this.ExecuteReader(CommandType.Text, sqlQuery, myDbParameters);
547 }
548 #endregion
549
550 public IDataReader ExecuteReader(String sqlQuery, String name, Object value)#region public IDataReader ExecuteReader(String sqlQuery, String name, Object value)
551 /**//// <summary>
552 /// 执行查询
553 /// </summary>
554 /// <param name="myDataSet">数据集</param>
555 /// <param name="sqlQuery">sql查询</param>
556 /// <param name="name">参数名</param>
557 /// <param name="value">参数值</param>
558 /// <returns>结果集流</returns>
559 public IDataReader ExecuteReader(String sqlQuery, String name, Object value)
560 {
561 String[] names = new String[1] { name };
562 Object[] values = new Object[1] { value };
563 return this.ExecuteReader(CommandType.Text, sqlQuery, names, values);
564 }
565 #endregion
566
567 public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)
568 /**//// <summary>
569 /// 执行查询
570 /// </summary>
571 /// <param name="sqlQuery">sql查询</param>
572 /// <param name="names">参数名</param>
573 /// <param name="values">参数值</param>
574 /// <returns>结果集流</returns>
575 public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)
576 {
577 return this.ExecuteReader(CommandType.Text, sqlQuery, names, values);
578 }
579 #endregion
580
581 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
582 /**//// <summary>
583 /// 执行查询
584 /// </summary>
585 /// <param name="myCommandType">命令分类</param>
586 /// <param name="sqlQuery">sql查询</param>
587 /// <param name="myDbParameterCollection">参数集</param>
588 /// <returns>结果集流</returns>
589 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
590 {
591 // 写入调试信息
592 #if (DEBUG)
593 int milliStart = Environment.TickCount;
594 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
595 #endif
596 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
597 this.myOleDbCommand.CommandType = myCommandType;
598 if (myOleDbTransaction != null)
599 {
600 this.myOleDbCommand.Transaction = myOleDbTransaction;
601 }
602 if (myDbParameters != null)
603 {
604 this.myOleDbCommand.Parameters.Clear();
605 for (int i = 0; i < myDbParameters.Length; i++)
606 {
607 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
608 }
609 }
610 OleDbDataReader myOleDbDataReader = this.myOleDbCommand.ExecuteReader();
611 this.myOleDbCommand.Parameters.Clear();
612 // 写入调试信息
613 #if (DEBUG)
614 int milliEnd = Environment.TickCount;
615 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
616 #endif
617 // 写入日志
618 this.WriteLog(sqlQuery);
619 return myOleDbDataReader;
620 }
621 #endregion
622
623 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
624 /**//// <summary>
625 /// 执行查询
626 /// </summary>
627 /// <param name="myCommandType">命令分类</param>
628 /// <param name="sqlQuery">sql查询</param>
629 /// <param name="names">参数名</param>
630 /// <param name="values">参数值</param>
631 /// <returns>结果集流</returns>
632 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
633 {
634 return this.ExecuteReader(myCommandType, sqlQuery, this.GetParameters(names, values));
635 }
636 #endregion
637
638
639 public int ExecuteNonQuery(String sqlQuery)#region public int ExecuteNonQuery(String sqlQuery)
640 /**//// <summary>
641 /// 执行查询, SQL BUILDER 用了这个东西?参数需要保存, 不能丢失.
642 /// </summary>
643 /// <param name="sqlQuery">sql查询</param>
644 /// <returns>影响行数</returns>
645 public int ExecuteNonQuery(String sqlQuery)
646 {
647 // 写入调试信息
648 #if (DEBUG)
649 int milliStart = Environment.TickCount;
650 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
651 #endif
652 this.myOleDbCommand.CommandType = CommandType.Text;
653 this.myOleDbCommand.CommandText = sqlQuery;
654 if (this.InTransaction)
655 {
656 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
657 }
658 int returnValue = this.myOleDbCommand.ExecuteNonQuery();
659 // 写入调试信息
660 #if (DEBUG)
661 int milliEnd = Environment.TickCount;
662 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
663 #endif
664 // 写入日志
665 this.WriteLog(sqlQuery);
666 return returnValue;
667 }
668 #endregion
669
670 public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters);#region public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters);
671 /**//// <summary>
672 /// 执行查询
673 /// </summary>
674 /// <param name="sqlQuery">sql查询</param>
675 /// <param name="myDbParameterCollection">参数集</param>
676 /// <returns>影响行数</returns>
677 public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters)
678 {
679 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, myDbParameters);
680 }
681 #endregion
682
683 public int ExecuteNonQuery(String sqlQuery, String name, Object value)#region public int ExecuteNonQuery(String sqlQuery, String name, Object value)
684 /**//// <summary>
685 /// 执行查询
686 /// </summary>
687 /// <param name="myDataSet">数据集</param>
688 /// <param name="sqlQuery">sql查询</param>
689 /// <param name="name">参数名</param>
690 /// <param name="value">参数值</param>
691 /// <returns>影响行数</returns>
692 public int ExecuteNonQuery(String sqlQuery, String name, Object value)
693 {
694 String[] names = new String[1] { name };
695 Object[] values = new Object[1] { value };
696 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values);
697 }
698 #endregion
699
700 public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)
701 /**//// <summary>
702 /// 执行查询
703 /// </summary>
704 /// <param name="sqlQuery">sql查询</param>
705 /// <param name="names">参数名</param>
706 /// <param name="values">参数值</param>
707 /// <returns>影响行数</returns>
708 public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)
709 {
710 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values);
711 }
712 #endregion
713
714 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
715 /**//// <summary>
716 /// 执行查询
717 /// </summary>
718 /// <param name="myCommandType">命令分类</param>
719 /// <param name="sqlQuery">sql查询</param>
720 /// <param name="myDbParameterCollection">参数集</param>
721 /// <returns>影响行数</returns>
722 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
723 {
724 OleDbTransaction myOleDbTransaction = null;
725 if (this.InTransaction)
726 {
727 myOleDbTransaction = this.myOleDbTransaction;
728 }
729 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, myDbParameters);
730 }
731 #endregion
732
733 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
734 /**//// <summary>
735 /// 执行查询
736 /// </summary>
737 /// <param name="myCommandType">命令分类</param>
738 /// <param name="sqlQuery">sql查询</param>
739 /// <param name="names">参数名</param>
740 /// <param name="values">参数值</param>
741 /// <returns>影响行数</returns>
742 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
743 {
744 OleDbTransaction myOleDbTransaction = null;
745 if (this.InTransaction)
746 {
747 myOleDbTransaction = this.myOleDbTransaction;
748 }
749 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, names, values);
750 }
751 #endregion
752
753 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
754 /**//// <summary>
755 /// 执行查询
756 /// </summary>
757 /// <param name="myOleDbTransaction">数据库事务</param>
758 /// <param name="myCommandType">命令分类</param>
759 /// <param name="sqlQuery">sql查询</param>
760 /// <param name="myDbParameterCollection">参数集</param>
761 /// <returns>影响行数</returns>
762 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
763 {
764 // 写入调试信息
765 #if (DEBUG)
766 int milliStart = Environment.TickCount;
767 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
768 #endif
769 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
770 this.myOleDbCommand.CommandType = myCommandType;
771 if (myOleDbTransaction != null)
772 {
773 this.myOleDbCommand.Transaction = (OleDbTransaction)myOleDbTransaction;
774 }
775 if (myDbParameters != null)
776 {
777 this.myOleDbCommand.Parameters.Clear();
778 for (int i = 0; i < myDbParameters.Length; i++)
779 {
780 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
781 }
782 }
783 int returnValue = this.myOleDbCommand.ExecuteNonQuery();
784 this.myOleDbCommand.Parameters.Clear();
785 // 写入调试信息
786 #if (DEBUG)
787 int milliEnd = Environment.TickCount;
788 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
789 #endif
790 // 写入日志
791 this.WriteLog(sqlQuery);
792 return returnValue;
793 }
794 #endregion
795
796 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
797 /**//// <summary>
798 /// 执行查询
799 /// </summary>
800 /// <param name="myOleDbTransaction">数据库事务</param>
801 /// <param name="myCommandType">命令分类</param>
802 /// <param name="sqlQuery">sql查询</param>
803 /// <param name="names">参数名</param>
804 /// <param name="values">参数值</param>
805 /// <returns>影响行数</returns>
806 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
807 {
808 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, this.GetParameters(names, values));
809 }
810 #endregion
811
812
813 public Object ExecuteScalar(String sqlQuery)#region public Object ExecuteScalar(String sqlQuery)
814 /**//// <summary>
815 /// 执行查询
816 /// </summary>
817 /// <param name="sqlQuery">sql查询</param>
818 /// <returns>object</returns>
819 public Object ExecuteScalar(String sqlQuery)
820 {
821 return this.ExecuteScalar(CommandType.Text, sqlQuery, null, null);
822 }
823 #endregion
824
825 public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)
826 /**//// <summary>
827 /// 执行查询
828 /// </summary>
829 /// <param name="sqlQuery">sql查询</param>
830 /// <param name="myDbParameterCollection">参数集</param>
831 /// <returns>Object</returns>
832 public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)
833 {
834 return this.ExecuteScalar(CommandType.Text, sqlQuery, myDbParameters);
835 }
836 #endregion
837
838 public Object ExecuteScalar(String sqlQuery, String name, Object value)#region public Object ExecuteScalar(String sqlQuery, String name, Object value)
839 /**//// <summary>
840 /// 执行查询
841 /// </summary>
842 /// <param name="sqlQuery">sql查询</param>
843 /// <param name="name">参数名</param>
844 /// <param name="value">参数值</param>
845 /// <returns>Object</returns>
846 public Object ExecuteScalar(DataSet myDataSet, String sqlQuery, String name, Object value)
847 {
848 String[] names = new String[1] { name };
849 Object[] values = new Object[1] { value };
850 return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values);
851 }
852 #endregion
853
854 public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)
855 /**//// <summary>
856 /// 执行查询
857 /// </summary>
858 /// <param name="sqlQuery">sql查询</param>
859 /// <param name="names">参数名</param>
860 /// <param name="values">参数值</param>
861 /// <returns>影响行数</returns>
862 public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)
863 {
864 return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values);
865 }
866 #endregion
867
868 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
869 /**//// <summary>
870 /// 执行查询
871 /// </summary>
872 /// <param name="myCommandType">命令分类</param>
873 /// <param name="sqlQuery">sql查询</param>
874 /// <param name="myDbParameterCollection">参数集</param>
875 /// <returns>Object</returns>
876 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
877 {
878 OleDbTransaction myOleDbTransaction = null;
879 if (this.InTransaction)
880 {
881 myOleDbTransaction = this.myOleDbTransaction;
882 }
883 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, myDbParameters);
884 }
885 #endregion
886
887 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
888 /**//// <summary>
889 /// 执行查询
890 /// </summary>
891 /// <param name="myCommandType">命令分类</param>
892 /// <param name="sqlQuery">sql查询</param>
893 /// <param name="names">参数名</param>
894 /// <param name="values">参数值</param>
895 /// <returns>影响行数</returns>
896 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
897 {
898 OleDbTransaction myOleDbTransaction = null;
899 if (this.InTransaction)
900 {
901 myOleDbTransaction = this.myOleDbTransaction;
902 }
903 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, names, values);
904 }
905 #endregion
906
907 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
908 /**//// <summary>
909 /// 执行查询
910 /// </summary>
911 /// <param name="myOleDbTransaction">数据库事务</param>
912 /// <param name="myCommandType">命令分类</param>
913 /// <param name="sqlQuery">sql查询</param>
914 /// <param name="myDbParameterCollection">参数集</param>
915 /// <returns>Object</returns>
916 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
917 {
918 // 写入调试信息
919 #if (DEBUG)
920 int milliStart = Environment.TickCount;
921 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
922 #endif
923 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
924 this.myOleDbCommand.CommandType = myCommandType;
925 if (myOleDbTransaction != null)
926 {
927 this.myOleDbCommand.Transaction = (OleDbTransaction)myOleDbTransaction;
928 }
929 if (myDbParameters != null)
930 {
931 this.myOleDbCommand.Parameters.Clear();
932 for (int i = 0; i < myDbParameters.Length; i++)
933 {
934 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
935 }
936 }
937 Object returnValue = this.myOleDbCommand.ExecuteScalar();
938 this.myOleDbCommand.Parameters.Clear();
939 // 写入调试信息
940 #if (DEBUG)
941 int milliEnd = Environment.TickCount;
942 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
943 #endif
944 // 写入日志
945 this.WriteLog(sqlQuery);
946 return returnValue;
947 }
948 #endregion
949
950 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
951 /**//// <summary>
952 /// 执行查询
953 /// </summary>
954 /// <param name="myOleDbTransaction">数据库事务</param>
955 /// <param name="myCommandType">命令分类</param>
956 /// <param name="sqlQuery">sql查询</param>
957 /// <param name="names"></param>
958 /// <param name="values"></param>
959 /// <returns>影响行数</returns>
960 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
961 {
962 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, this.GetParameters(names, values));
963 }
964 #endregion
965
966
967 public DataTable Fill(DataTable myDataTable, String sqlQuery)#region public DataTable Fill(DataTable myDataTable, String sqlQuery)
968 /**//// <summary>
969 /// 填充数据表
970 /// </summary>
971 /// <param name="myDataTable">目标数据表</param>
972 /// <param name="sqlQuery">查询</param>
973 /// <returns>数据表</returns>
974 public DataTable Fill(DataTable myDataTable, String sqlQuery)
975 {
976 return this.Fill(myDataTable, CommandType.Text, sqlQuery, null, null);
977 }
978 #endregion
979
980 public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)
981 /**//// <summary>
982 /// 填充数据表
983 /// </summary>
984 /// <param name="myDataTable">目标数据表</param>
985 /// <param name="sqlQuery">sql查询</param>
986 /// <param name="myDbParameterCollection">参数集</param>
987 /// <returns>数据表</returns>
988 public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)
989 {
990 return this.Fill(myDataTable, CommandType.Text, sqlQuery, myDbParameters);
991 }
992 #endregion
993
994 public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)
995 /**//// <summary>
996 /// 填充数据表
997 /// </summary>
998 /// <param name="myDataSet">目标数据表</param>
999 /// <param name="sqlQuery">sql查询</param>
1000 /// <param name="name">参数名</param>
1001 /// <param name="value">参数值</param>
1002 /// <returns>数据表</returns>
1003 public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)
1004 {
1005 String[] names = new String[1] { name };
1006 Object[] values = new Object[1] { value };
1007 return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values);
1008 }
1009 #endregion
1010
1011 public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)
1012 /**//// <summary>
1013 /// 填充数据表
1014 /// </summary>
1015 /// <param name="myDataSet">目标数据表</param>
1016 /// <param name="sqlQuery">sql查询</param>
1017 /// <param name="names">参数名</param>
1018 /// <param name="values">参数值</param>
1019 /// <returns>数据表</returns>
1020 public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)
1021 {
1022 return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values);
1023 }
1024 #endregion
1025
1026 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
1027 /**//// <summary>
1028 /// 填充数据表
1029 /// </summary>
1030 /// <param name="myDataSet">目标数据表</param>
1031 /// <param name="myCommandType">命令分类</param>
1032 /// <param name="sqlQuery">sql查询</param>
1033 /// <param name="myDbParameterCollection">参数集</param>
1034 /// <returns>数据表</returns>
1035 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
1036 {
1037 // 写入调试信息
1038 #if (DEBUG)
1039 int milliStart = Environment.TickCount;
1040 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1041 #endif
1042 this.myOleDbDataAdapter = new OleDbDataAdapter(sqlQuery, this.myOleDbConnection);
1043 this.myOleDbDataAdapter.SelectCommand.CommandType = myCommandType;
1044 if (this.InTransaction)
1045 {
1046 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1047 }
1048 if (myDbParameters != null)
1049 {
1050 this.myOleDbCommand.Parameters.Clear();
1051 for (int i = 0; i < myDbParameters.Length; i++)
1052 {
1053 this.myOleDbDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]);
1054 }
1055 }
1056 this.myOleDbDataAdapter.Fill(myDataTable);
1057 this.myOleDbDataAdapter.SelectCommand.Parameters.Clear();
1058 // 写入调试信息
1059 #if (DEBUG)
1060 int milliEnd = Environment.TickCount;
1061 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1062 #endif
1063 // 写入日志
1064 this.WriteLog(sqlQuery);
1065 return myDataTable;
1066 }
1067 #endregion
1068
1069 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1070 /**//// <summary>
1071 /// 填充数据表
1072 /// </summary>
1073 /// <param name="myDataSet">目标数据表</param>
1074 /// <param name="myCommandType">命令分类</param>
1075 /// <param name="sqlQuery">sql查询</param>
1076 /// <param name="names">参数名</param>
1077 /// <param name="values">参数值</param>
1078 /// <returns>数据表</returns>
1079 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1080 {
1081 return this.Fill(myDataTable, myCommandType, sqlQuery, this.GetParameters(names, values));
1082 }
1083 #endregion
1084
1085
1086 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)
1087 /**//// <summary>
1088 /// 填充数据集
1089 /// </summary>
1090 /// <param name="myDataSet">目标数据集</param>
1091 /// <param name="sqlQuery">查询</param>
1092 /// <param name="tableName">填充表</param>
1093 /// <returns>数据集</returns>
1094 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)
1095 {
1096 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, null, null);
1097 }
1098 #endregion
1099
1100 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1101 /**//// <summary>
1102 /// 填充数据集
1103 /// </summary>
1104 /// <param name="myDataSet">数据集</param>
1105 /// <param name="sqlQuery">sql查询</param>
1106 /// <param name="tableName">填充表</param>
1107 /// <param name="myDbParameterCollection">参数集</param>
1108 /// <returns>数据集</returns>
1109 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1110 {
1111 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, myDbParameters);
1112 }
1113 #endregion
1114
1115 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)
1116 /**//// <summary>
1117 /// 填充数据集
1118 /// </summary>
1119 /// <param name="myDataSet">数据集</param>
1120 /// <param name="sqlQuery">sql查询</param>
1121 /// <param name="tableName">填充表</param>
1122 /// <param name="name">参数名</param>
1123 /// <param name="value">参数值</param>
1124 /// <returns>DataSet</returns>
1125 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)
1126 {
1127 String[] names = new String[1] { name };
1128 Object[] values = new Object[1] { value };
1129 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values);
1130 }
1131 #endregion
1132
1133 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)
1134 /**//// <summary>
1135 /// 填充数据集
1136 /// </summary>
1137 /// <param name="myDataSet">数据集</param>
1138 /// <param name="sqlQuery">sql查询</param>
1139 /// <param name="tableName">填充表</param>
1140 /// <param name="names">参数名</param>
1141 /// <param name="values">参数值</param>
1142 /// <returns>DataSet</returns>
1143 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)
1144 {
1145 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values);
1146 }
1147 #endregion
1148
1149 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)#region public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1150 /**//// <summary>
1151 /// 填充数据集
1152 /// </summary>
1153 /// <param name="myDataSet">数据集</param>
1154 /// <param name="myCommandType">命令分类</param>
1155 /// <param name="sqlQuery">sql查询</param>
1156 /// <param name="tableName">填充表</param>
1157 /// <param name="myDbParameterCollection">参数集</param>
1158 /// <returns>数据集</returns>
1159 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1160 {
1161 // 写入调试信息
1162 #if (DEBUG)
1163 int milliStart = Environment.TickCount;
1164 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1165 #endif
1166 this.myOleDbDataAdapter = new OleDbDataAdapter(sqlQuery, this.myOleDbConnection);
1167 this.myOleDbDataAdapter.SelectCommand.CommandType = myCommandType;
1168 if (this.InTransaction)
1169 {
1170 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1171 }
1172 if (myDbParameters != null)
1173 {
1174 this.myOleDbCommand.Parameters.Clear();
1175 for (int i = 0; i < myDbParameters.Length; i++)
1176 {
1177 this.myOleDbDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]);
1178 }
1179 }
1180 this.myOleDbDataAdapter.Fill(myDataSet, tableName);
1181 this.myOleDbDataAdapter.SelectCommand.Parameters.Clear();
1182 // 写入调试信息
1183 #if (DEBUG)
1184 int milliEnd = Environment.TickCount;
1185 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1186 #endif
1187 // 写入日志
1188 this.WriteLog(sqlQuery);
1189 return myDataSet;
1190 }
1191 #endregion
1192
1193 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)#region public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)
1194 /**//// <summary>
1195 /// 填充数据集
1196 /// </summary>
1197 /// <param name="myDataSet">数据集</param>
1198 /// <param name="myCommandType">命令分类</param>
1199 /// <param name="sqlQuery">sql查询</param>
1200 /// <param name="tableName">填充表</param>
1201 /// <param name="names">参数名</param>
1202 /// <param name="values">参数值</param>
1203 /// <returns>DataSet</returns>
1204 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)
1205 {
1206 return this.Fill(myDataSet, myCommandType, sqlQuery, tableName, this.GetParameters(names, values));
1207 }
1208 #endregion
1209
1210
1211 public int ExecuteProcedure(String procedureName)#region public int ExecuteProcedure(String procedureName)
1212 /**//// <summary>
1213 /// 执行数据库查询
1214 /// </summary>
1215 /// <param name="procedureName">存储过程</param>
1216 /// <returns>int</returns>
1217 public int ExecuteProcedure(String procedureName)
1218 {
1219 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, null, null);
1220 }
1221 #endregion
1222
1223 public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)#region public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)
1224 /**//// <summary>
1225 /// 执行存储过程
1226 /// </summary>
1227 /// <param name="procedureName">存储过程名</param>
1228 /// <param name="myDbParameterCollection">参数集</param>
1229 /// <returns>影响行数</returns>
1230 public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)
1231 {
1232 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, myDbParameters);
1233 }
1234 #endregion
1235
1236 public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程#region public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程
1237 /**//// <summary>
1238 /// 执行存储过程
1239 /// </summary>
1240 /// <param name="procedureName">存储过程名</param>
1241 /// <param name="name">参数名</param>
1242 /// <param name="value">参数值</param>
1243 /// <returns>影响行数</returns>
1244 public int ExecuteProcedure(String procedureName, String name, String value)
1245 {
1246 String[] names = new String[1];
1247 Object[] values = new Object[1];
1248 int returnValue = 0;
1249 names[0] = name;
1250 values[0] = value;
1251 returnValue = this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values);
1252 return returnValue;
1253 }
1254 #endregion
1255
1256 public int ExecuteProcedure(String procedureName, String[] names, Object[] values)#region public int ExecuteProcedure(String procedureName, String[] names, Object[] values)
1257 /**//// <summary>
1258 /// 执行数据库脚本
1259 /// </summary>
1260 /// <param name="procedureName">存储过程</param>
1261 /// <param name="names">参数名</param>
1262 /// <param name="values">参数值</param>
1263 /// <returns>影响行数</returns>
1264 public int ExecuteProcedure(String procedureName, String[] names, Object[] values)
1265 {
1266 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values);
1267 }
1268 #endregion
1269
1270 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)#region public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)
1271 /**//// <summary>
1272 /// 执行数据库脚本
1273 /// </summary>
1274 /// <param name="myDataSet">数据集</param>
1275 /// <param name="procedureName">存储过程</param>
1276 /// <param name="tableName">填充表</param>
1277 /// <param name="myDbParameterCollection">参数集</param>
1278 /// <returns>数据集</returns>
1279 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)
1280 {
1281 return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, myDbParameters);
1282 }
1283 #endregion
1284
1285 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)#region public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)
1286 /**//// <summary>
1287 /// 执行数据库脚本
1288 /// </summary>
1289 /// <param name="myDataSet">数据集</param>
1290 /// <param name="procedureName">存储过程</param>
1291 /// <param name="tableName">填充表</param>
1292 /// <param name="names">参数名</param>
1293 /// <param name="values">参数值</param>
1294 /// <returns>影响行数</returns>
1295 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)
1296 {
1297 return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, names, values);
1298 }
1299 #endregion
1300
1301
1302 public IDbTransaction BeginTransaction()#region public IDbTransaction BeginTransaction()
1303 /**//// <summary>
1304 /// 事务开始
1305 /// </summary>
1306 /// <returns>事务</returns>
1307 public IDbTransaction BeginTransaction()
1308 {
1309 // 写入调试信息
1310 #if (DEBUG)
1311 int milliStart = Environment.TickCount;
1312 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1313 #endif
1314 if (!this.InTransaction)
1315 {
1316 this.InTransaction = true;
1317 this.myOleDbTransaction = this.myOleDbConnection.BeginTransaction();
1318 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
1319 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1320 }
1321 // 写入调试信息
1322 #if (DEBUG)
1323 int milliEnd = Environment.TickCount;
1324 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1325 #endif
1326 return this.myOleDbTransaction;
1327 }
1328 #endregion
1329
1330 public void CommitTransaction()#region public void CommitTransaction()
1331 /**//// <summary>
1332 /// 递交事务
1333 /// </summary>
1334 public void CommitTransaction()
1335 {
1336 // 写入调试信息
1337 #if (DEBUG)
1338 int milliStart = Environment.TickCount;
1339 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1340 #endif
1341 if (this.InTransaction)
1342 {
1343 // 事务已经完成了,一定要更新标志信息
1344 this.InTransaction = false;
1345 this.myOleDbTransaction.Commit();
1346 }
1347 // 写入调试信息
1348 #if (DEBUG)
1349 int milliEnd = Environment.TickCount;
1350 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1351 #endif
1352 }
1353 #endregion
1354
1355 public void RollbackTransaction()#region public void RollbackTransaction()
1356 /**//// <summary>
1357 /// 回滚事务
1358 /// </summary>
1359 public void RollbackTransaction()
1360 {
1361 // 写入调试信息
1362 #if (DEBUG)
1363 int milliStart = Environment.TickCount;
1364 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1365 #endif
1366 if (this.InTransaction)
1367 {
1368 this.InTransaction = false;
1369 this.myOleDbTransaction.Rollback();
1370 }
1371 // 写入调试信息
1372 #if (DEBUG)
1373 int milliEnd = Environment.TickCount;
1374 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1375 #endif
1376 }
1377 #endregion
1378
1379
1380 public delegate int Asyncdelegate();
1381
1382 private void CallbackMethod(IAsyncResult myIAsyncResult) 异步调用的挂接代理#region private void CallbackMethod(IAsyncResult myIAsyncResult) 异步调用的挂接代理
1383 /**//// <summary>
1384 /// 异步调用的挂接代理
1385 /// </summary>
1386 /// <param name="myIAsyncResult">回调</param>
1387 private void CallbackMethod(IAsyncResult myIAsyncResult)
1388 {
1389 Asyncdelegate myAsyncdelegate = (Asyncdelegate)myIAsyncResult.AsyncState;
1390 myAsyncdelegate.EndInvoke(myIAsyncResult);
1391 }
1392 #endregion
1393
1394 // 定义与方法同签名的委托
1395 private delegate int DelegateExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values);
1396
1397 private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1398 /**//// <summary>
1399 /// 异步调用数据库查询
1400 /// </summary>
1401 /// <param name="myCommandType">命令分类</param>
1402 /// <param name="sqlQuery">sql查询</param>
1403 /// <param name="names">参数名</param>
1404 /// <param name="values">参数值</param>
1405 /// <returns>影响行数</returns>
1406 private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1407 {
1408 int returnValue = 0;
1409 this.Open();
1410 returnValue = this.ExecuteNonQuery(myCommandType, sqlQuery, names, values);
1411 this.Close();
1412 return returnValue;
1413 }
1414 #endregion
1415
1416 public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1417 /**//// <summary>
1418 /// 异步调用数据库查询
1419 /// </summary>
1420 /// <param name="myCommandType">命令分类</param>
1421 /// <param name="sqlQuery">sql查询</param>
1422 /// <param name="names">参数名</param>
1423 /// <param name="values">参数值</param>
1424 public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1425 {
1426 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1427
1428 DelegateExecuteNonQuery myDelegateExecuteNonQuery = new DelegateExecuteNonQuery(AsyncExecuteNonQuery);
1429 myDelegateExecuteNonQuery.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null);
1430 }
1431 #endregion
1432
1433 // 定义与方法同签名的委托
1434 private delegate Object DelegateExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values);
1435
1436 private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1437 /**//// <summary>
1438 /// 异步调用数据库查询
1439 /// </summary>
1440 /// <param name="myCommandType">命令分类</param>
1441 /// <param name="sqlQuery">sql查询</param>
1442 /// <param name="names">参数名</param>
1443 /// <param name="values">参数值</param>
1444 /// <returns>对象</returns>
1445 private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1446 {
1447 Object returnValue = null;
1448 this.Open();
1449 returnValue = this.ExecuteScalar(myCommandType, sqlQuery, names, values);
1450 this.Close();
1451 return returnValue;
1452 }
1453 #endregion
1454
1455 public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1456 /**//// <summary>
1457 /// 异步调用数据库查询
1458 /// </summary>
1459 /// <param name="myCommandType">命令分类</param>
1460 /// <param name="sqlQuery">sql查询</param>
1461 /// <param name="names">参数名</param>
1462 /// <param name="values">参数值</param>
1463 public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1464 {
1465 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1466
1467 DelegateExecuteScalar myDelegateExecuteScalar = new DelegateExecuteScalar(AsyncExecuteScalar);
1468 myDelegateExecuteScalar.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null);
1469 }
1470 #endregion
1471
1472 // 定义与方法同签名的委托
1473 private delegate int DelegateExecuteProcedure(String procedureName, String[] names, Object[] values);
1474
1475 private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values) 异步调用数据库查询#region private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values) 异步调用数据库查询
1476 /**//// <summary>
1477 /// 异步调用数据库查询
1478 /// </summary>
1479 /// <param name="procedureName">存储过程</param>
1480 /// <param name="names">参数名</param>
1481 /// <param name="values">参数值</param>
1482 /// <returns>影响行数</returns>
1483 private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values)
1484 {
1485 int returnValue = 0;
1486 this.Open();
1487 returnValue = this.ExecuteProcedure(procedureName, names, values);
1488 this.Close();
1489 return returnValue;
1490 }
1491 #endregion
1492
1493 public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values) 异步调用数据库查询
1494 /**//// <summary>
1495 /// 异步调用数据库查询
1496 /// </summary>
1497 /// <param name="procedureName">存储过程</param>
1498 /// <param name="names">参数名</param>
1499 /// <param name="values">参数值</param>
1500 public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values)
1501 {
1502 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1503
1504 DelegateExecuteProcedure myDelegateExecuteProcedure = new DelegateExecuteProcedure(AsyncExecuteProcedure);
1505 myDelegateExecuteProcedure.BeginInvoke(procedureName, names, values, myAsyncCallback, null);
1506 }
1507 #endregion
1508
1509
1510 public void WriteLog(String sqlQuery) 写入SQL查询语句日志#region public void WriteLog(String sqlQuery) 写入SQL查询语句日志
1511 /**//// <summary>
1512 /// 写入SQL查询语日志
1513 /// </summary>
1514 /// <param name="sqlQuery">SQL查询语</param>
1515 public void WriteLog(String sqlQuery)
1516 {
1517 this.WriteLog(DateTime.Now.ToString(BaseSystemInfo.DateFormat) + "_" + this.FileName, sqlQuery);
1518 // 将调试信息输出到屏幕上
1519 #if DEBUG
1520 System.Console.WriteLine(sqlQuery);
1521 #endif
1522 }
1523 #endregion
1524
1525 public void WriteLog(String fileName, String sqlQuery) 写入SQL查询语句日志#region public void WriteLog(String fileName, String sqlQuery) 写入SQL查询语句日志
1526 /**//// <summary>
1527 /// 写入SQL查询语句
1528 /// </summary>
1529 /// <param name="fileName">文件名</param>
1530 /// <param name="sqlQuery">异常</param>
1531 public void WriteLog(String fileName, String sqlQuery)
1532 {
1533 String returnValue = String.Empty;
1534 // 系统里应该可以配置是否记录异常现象
1535 if (!BaseSystemInfo.LogSQL)
1536 {
1537 return;
1538 }
1539 // 将异常信息写入本地文件中
1540 String logDirectory = BaseSystemInfo.StartupPath + @"\\Log\\Query";
1541 if (!System.IO.Directory.Exists(logDirectory))
1542 {
1543 System.IO.Directory.CreateDirectory(logDirectory);
1544 }
1545 String writerFileName = logDirectory + "\\" + fileName;
1546 if (!File.Exists(writerFileName))
1547 {
1548 FileStream myFileStream = new FileStream(writerFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
1549 myFileStream.Close();
1550 }
1551 StreamWriter myStreamWriter = new StreamWriter(writerFileName, true, Encoding.Default);
1552 myStreamWriter.WriteLine(DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " " + sqlQuery);
1553 myStreamWriter.Close();
1554 }
1555 #endregion
1556
1557
1558 public void Close()#region public void Close()
1559 /**//// <summary>
1560 /// 关闭数据库连接
1561 /// </summary>
1562 public void Close()
1563 {
1564 // 写入调试信息
1565 #if (DEBUG)
1566 int milliStart = Environment.TickCount;
1567 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1568 #endif
1569 if (this.myOleDbConnection != null)
1570 {
1571 this.myOleDbConnection.Close();
1572 this.myOleDbConnection.Dispose();
1573 }
1574 // 写入调试信息
1575 #if (DEBUG)
1576 int milliEnd = Environment.TickCount;
1577 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1578 #endif
1579 }
1580 #endregion
1581
1582 private void Dispose(bool disposing)#region private void Dispose(bool disposing)
1583 /**//// <summary>
1584 /// 卸载
1585 /// </summary>
1586 /// <param name="disposing">卸载</param>
1587 private void Dispose(bool disposing)
1588 {
1589 if (disposing)
1590 {
1591 this.myOleDbCommand.Dispose();
1592 this.myOleDbDataAdapter.Dispose();
1593 this.myOleDbTransaction.Dispose();
1594 this.myOleDbConnection.Dispose();
1595 }
1596 }
1597 #endregion
1598
1599 public void Dispose()#region public void Dispose()
1600 /**//// <summary>
1601 /// 卸载
1602 /// </summary>
1603 public void Dispose()
1604 {
1605 Dispose(true);
1606 GC.SuppressFinalize(this);
1607 }
1608 #endregion
1609 }
1610}
1//------------------------------------------------------------
2// All Rights Reserved , Copyright (C) 2008 , Jirisoft , Ltd.
3//------------------------------------------------------------
4
5using System;
6using System.Data;
7using System.Data.Common;
8using System.IO;
9using System.Text;
10using System.Globalization;
11using System.Data.OleDb;
12using System.Reflection;
13using System.Diagnostics;
14
15namespace Jirisoft.Common.DbUtilities
16{
17 using Jirisoft.Common;
18 using Jirisoft.Common.Utilities;
19
20 /**//// <summary>
21 /// OleDbHelper
22 /// 有关数据库连接的方法。
23 ///
24 /// 修改纪录
25 ///
26 /// 2008.06.01 版本:5.4 JiRiGaLa 数据库连接获得方式进行改进,构造函数获得调通。
27 /// 2008.05.31 版本:5.3 JiRiGaLa 参数命名param前缀替换为小写字母开始。
28 /// 2008.05.09 版本:5.2 JiRiGaLa InTransaction 命名改进。
29 /// 2008.05.07 版本:5.1 JiRiGaLa AddParameter 方法改进。
30 /// 2008.03.27 版本:5.1 JiRiGaLa 完善写日志功能。
31 /// 2008.02.24 版本:5.0 JiRiGaLa 修改函数名为 OleDbHelper, 增加日志功能, 增加异步调用功能, 增加 DataReader 功能。
32 /// 2008.02.23 版本:4.9 JiRiGaLa 增加 OleDbTransaction 事务处理功能。
33 /// 2008.02.21 版本:4.8 JiRiGaLa 函数获得服务器时间函数 GetDBDateTime()。
34 /// 2007.12.25 版本:4.7 JiRiGaLa 函数增加 TimeFormat 时间格式定义。
35 /// 2007.11.29 版本:4.6 JiRiGaLa SqlSafe() 函数增加,判断参数的安全性。
36 /// 2007.11.28 版本:4.5 JiRiGaLa Open() 时间不需要每次都读配置信息,只读取一次就够了。
37 /// 2007.10.26 版本:4.4 JiRiGaLa 增加填充 DataTable 功能。
38 /// 2007.07.30 版本:4.2 JiRiGaLa 配置信息从 Instance 读取。
39 /// 2007.07.20 版本:4.1 JiRiGaLa 修改 IsUseTransaction 标志信息错误。
40 /// 2007.06.23 版本:4.0 JiRiGaLa 改进 ExecuteScalar,ExecuteNonQuery 方法,完善方法。
41 /// 2007.05.23 版本:3.9 JiRiGaLa 改进 Environment.TickCount 方法,性能改进。
42 /// 2007.05.07 版本:3.8 JiRiGaLa 改进 BeginTransaction() 方法,满足更灵活的需求。
43 /// 2007.04.14 版本:3.7 JiRiGaLa 检查程序格式通过,不再进行修改代码操作。
44 /// 2007.01.07 版本:3.6 JiRiGaLa 增加简单的注册功能部分。
45 /// 2006.11.17 版本:3.5 JiRiGaLa 改进使用事务部分。
46 /// 2006.09.11 版本:3.4 JiRiGaLa 改进使用存储过程的。
47 /// 2006.04.18 版本:3.3 JiRiGaLa 重新调整代码的规范化。
48 /// 2006.02.04 版本:3.2 JiRiGaLa 用System.DateTime.Now.Ticks进行性能测试用。
49 /// 2006.02.04 版本:3.1 JiRiGaLa #if (DEBUG) #endif(ok) 添加条件编译选项。
50 /// 2006.02.02 版本:3.0 JiRiGaLa 删除数据库连接池的想法(ok)。
51 /// 2006.02.01 版本:2.9 JiRiGaLa 还想改进成支持事务类型的(ok)。
52 /// 2005.12.29 版本:2.8 JiRiGaLa 数据库类型等用枚举类型的方式进行改进。
53 /// 2005.08.19 版本:2.7 JiRiGaLa 代码继续改进一次。
54 /// 2005.08.14 版本:2.6 JiRiGaLa 参数有效化。
55 /// 2005.08.08 版本:2.5 JiRiGaLa 修改注册表读写方法。
56 /// 2005.07.10 版本:2.4 JiRiGaLa 改进类名称。
57 /// 2005.03.07 版本:2.3 JiRiGaLa 改进排版根式。
58 /// 2004.11.18 版本:2.2 JiRiGaLa 改进代码编排格式。
59 /// 2004.08.24 版本:2.1 JiRiGaLa 增加Access连接字符串。
60 /// 2004.08.22 版本:2.0 JiRiGaLa 增加空的构造方法。
61 /// 2004.07.30 版本:1.9 JiRiGaLa 改进数据库连接池功能。
62 /// 2004.06.09 版本:1.8 JiRiGaLa 改进数据库了连接池功能,得经过一段时间的测试比较好。
63 /// 2004.03.21 版本:1.7 JiRiGaLa 改进读取注册表的方法,可以不从注册表读取参数,可以指定参数。
64 /// 2004.02.17 版本:1.6 JiRiGaLa 重新整理一些方法,命名方式等适当修改,全局变量,局部变量等重新命名。
65 /// 2004.02.17 版本:1.5 JiRiGaLa 将变量名字中的_符号尽量去掉了,局部变量采用_开头的变量名。
66 /// 2004.02.17 版本:1.4 JiRiGaLa 并且采用了String.Format方法,字符串看起来更顺眼,加强了抛出异常throw的方法。
67 /// 2003.11.26 版本:1.3 JiRiGaLa 数据库丢失连接的改进,设置过期时间,为了提高运行效率仍然使用保持连接方式。
68 /// 2003.10.24 版本:1.2 JiRiGaLa 数据库不采用保持连接的方式,注释文件的编写方式改变。
69 /// 2003.10.24 版本:1.1 JiRiGaLa 将类改进为静太方式,不用创建新的类,就可以获得数据库连接。
70 /// 2003.10.14 版本:1.0 JiRiGaLa 改进成以后可以扩展到多种数据库的结构形式。
71 ///
72 /// 版本:5.0
73 ///
74 /// <author>
75 /// <name>JiRiGaLa</name>
76 /// <date>2008.02.24</date>
77 /// </author>
78 /// </summary>
79 public class OleDbHelper : IDbHelper, IDisposable
80 {
81 public OleDbConnection myOleDbConnection = new OleDbConnection();
82 public OleDbCommand myOleDbCommand = new OleDbCommand();
83 public OleDbDataAdapter myOleDbDataAdapter = new OleDbDataAdapter();
84 public OleDbTransaction myOleDbTransaction;
85 private bool inTransaction; // 是否已在事务之中
86
87 public String FileName = "OleDbHelper.txt"; // SQL查询语句日志
88
89 public OleDbHelper()#region public OleDbHelper()
90 /**//// <summary>
91 /// 构造方法
92 /// </summary>
93 public OleDbHelper()
94 {
95 }
96 #endregion
97
98 public OleDbHelper(String connectionString)#region public OleDbHelper(String connectionString)
99 /**//// <summary>
100 /// 设定软件名称
101 /// </summary>
102 /// <param name="connectionString">数据连接</param>
103 public OleDbHelper(String connectionString) : this()
104 {
105 this.myOleDbConnection.ConnectionString = connectionString;
106 }
107 #endregion
108
109 public String GetDBNow()#region public String GetDBNow()
110 /**//// <summary>
111 /// 获得数据库日期时间
112 /// </summary>
113 /// <returns>日期时间</returns>
114 public String GetDBNow()
115 {
116 String returnValue = " Getdate() ";
117 switch (BaseConfiguration.Instance.DataBaseType)
118 {
119 case DataBaseType.Access:
120 returnValue = "'" + DateTime.Now.ToString() + "'";
121 break;
122 case DataBaseType.Sqlserver:
123 returnValue = " GetDate() ";
124 break;
125 case DataBaseType.Oracle:
126 returnValue = " SYSDATE ";
127 break;
128 }
129 return returnValue;
130 }
131 #endregion
132
133 public DateTime GetDBDateTime() 获得数据库日期时间#region public DateTime GetDBDateTime() 获得数据库日期时间
134 /**//// <summary>
135 /// 获得数据库日期时间
136 /// </summary>
137 /// <returns>日期时间</returns>
138 public DateTime GetDBDateTime()
139 {
140 String sqlQuery = this.GetDBNow();
141 Object myObject = this.ExecuteScalar(sqlQuery);
142 return DateTime.Parse(myObject.ToString());
143 }
144 #endregion
145
146 public bool InTransaction 是否已采用事务#region public bool InTransaction 是否已采用事务
147 /**//// <summary>
148 /// 是否已采用事务
149 /// </summary>
150 /// <returns>采用事务</returns>
151 public bool InTransaction
152 {
153 get
154 {
155 return this.inTransaction;
156 }
157 set
158 {
159 this.inTransaction = value;
160 }
161 }
162 #endregion
163
164 public IDbConnection GetDbConnection() 获取数据库连接#region public IDbConnection GetDbConnection() 获取数据库连接
165 /**//// <summary>
166 /// 获取数据库连接
167 /// </summary>
168 /// <returns>数据库连接</returns>
169 public IDbConnection GetDbConnection()
170 {
171 return this.myOleDbConnection;
172 }
173 #endregion
174
175 public IDbTransaction GetDbTransaction() 获取数据源上执行的事务#region public IDbTransaction GetDbTransaction() 获取数据源上执行的事务
176 /**//// <summary>
177 /// 获取数据源上执行的事务
178 /// </summary>
179 /// <returns>数据源上执行的事务</returns>
180 public IDbTransaction GetDbTransaction()
181 {
182 return this.myOleDbTransaction;
183 }
184 #endregion
185
186 public IDbCommand GetDbCommand() 获取数据源上命令#region public IDbCommand GetDbCommand() 获取数据源上命令
187 /**//// <summary>
188 /// 获取数据源上命令
189 /// </summary>
190 /// <returns>数据源上命令</returns>
191 public IDbCommand GetDbCommand()
192 {
193 return this.myOleDbCommand;
194 }
195 #endregion
196
197
198 public IDbConnection Open()#region public IDbConnection Open()
199 /**//// <summary>
200 /// 这时主要的获取数据库连接的方法
201 /// </summary>
202 /// <returns>数据库连接</returns>
203 public IDbConnection Open()
204 {
205 #if (DEBUG)
206 int milliStart = Environment.TickCount;
207 #endif
208 if (String.IsNullOrEmpty(this.myOleDbConnection.ConnectionString))
209 {
210 // 这里是获取一个连接的详细方法
211 if (this.myOleDbConnection.ConnectionString.Length == 0)
212 {
213 BaseConfiguration.Instance.GetSetting();
214 }
215 this.Open(BaseConfiguration.Instance.OleDbConnection);
216 }
217 // 写入调试信息
218 #if (DEBUG)
219 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
220 #endif
221 return this.myOleDbConnection;
222 }
223 #endregion
224
225 public IDbConnection Open(String connectionString)#region public IDbConnection Open(String connectionString)
226 /**//// <summary>
227 /// 获得新的数据库连接
228 /// </summary>
229 /// <param name="connectionString">数据库连接字符串</param>
230 /// <returns>数据库连接</returns>
231 public IDbConnection Open(String connectionString)
232 {
233 // 写入调试信息
234 #if (DEBUG)
235 int milliStart = Environment.TickCount;
236 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
237 #endif
238 // 这里数据库连接打开的时候,就判断注册属性的有效性
239 if (!BaseCodeChange.Instance.CheckRegister())
240 {
241 // 若没有进行注册,让程序无法打开数据库比较好。
242 this.myOleDbConnection.ConnectionString = String.Empty;
243 // 抛出异常信息显示给客户
244 throw new Exception(BaseConfiguration.Instance.ExceptionInfo);
245 }
246 if (this.myOleDbConnection.State == ConnectionState.Closed)
247 {
248 this.myOleDbConnection.ConnectionString = connectionString;
249 this.myOleDbConnection.Open();
250 // 创建对象
251 this.myOleDbCommand = new OleDbCommand(String.Empty, this.myOleDbConnection);
252 this.myOleDbDataAdapter = new OleDbDataAdapter(String.Empty, this.myOleDbConnection);
253 // 写入调试信息
254 #if (DEBUG)
255 int milliEnd = Environment.TickCount;
256 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
257 #endif
258 }
259 return this.myOleDbConnection;
260 }
261 #endregion
262
263
264 public bool TestConn(String dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)#region public bool TestConn(String dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)
265 /**//// <summary>
266 /// 测试数据库连接是否成功,这里抛出异常进行加强,充分使用系统的异常功能。
267 /// </summary>
268 /// <param name="dataBaseType">数据库类别</param>
269 /// <param name="dataBase">数据库名称</param>
270 /// <param name="userName">用户名</param>
271 /// <param name="password">密码</param>
272 /// <param name="workstation">服务器名称</param>
273 /// <param name="trustLink">是否信任的连接</param>
274 /// <returns>是否连接成功</returns>
275 public bool TestConn(DataBaseType dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink)
276 {
277 // 写入调试信息
278 #if (DEBUG)
279 int milliStart = Environment.TickCount;
280 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
281 #endif
282 bool returnValue = false; // 连接是否成功
283 String connectionString = String.Empty; // 连接字符传
284 OleDbConnection DbConnection = null; // 数据库连接
285 connectionString = BaseConfiguration.Instance.GetOleDbConnection(dataBaseType, dataBase, userName, password, workstation, trustLink);
286 DbConnection = (OleDbConnection)this.Open(connectionString);
287 try
288 {
289 if (DbConnection.State == ConnectionState.Closed)
290 {
291 DbConnection.Open();
292 }
293 DbConnection.Close();
294 returnValue = true;
295 }
296 catch (OleDbException myOleDbException)
297 {
298 DbConnection = null;
299 throw myOleDbException;
300 }
301 // 写入调试信息
302 #if (DEBUG)
303 int milliEnd = Environment.TickCount;
304 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
305 #endif
306 return returnValue;
307 }
308 #endregion
309
310 public String SqlSafe(String value) 检查参数的安全性#region public String SqlSafe(String value) 检查参数的安全性
311 /**//// <summary>
312 /// 检查参数的安全性
313 /// </summary>
314 /// <param name="value">参数</param>
315 /// <returns>安全的参数</returns>
316 public String SqlSafe(String value)
317 {
318 value = value.Replace("'", "''");
319 // value = value.Replace("%", "'%");
320 return value;
321 }
322 #endregion
323
324 public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues)#region public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues)
325 /**//// <summary>
326 /// 获取参数
327 /// </summary>
328 /// <param name="targetFiled">目标字段</param>
329 /// <param name="targetValue">值</param>
330 /// <returns>参数集</returns>
331 public DbParameter[] GetParameters(String[] targetFileds, Object[] myTargetValues)
332 {
333 DbParameter[] myDbParameters = new DbParameter[0];
334 if (targetFileds != null && myTargetValues != null)
335 {
336 myDbParameters = new DbParameter[targetFileds.Length];
337 for (int i = 0; i < targetFileds.Length; i++)
338 {
339 myDbParameters[i] = this.GetParameter(targetFileds[i], myTargetValues[i]);
340 }
341 }
342 return myDbParameters;
343 }
344 #endregion
345
346 public DbParameter GetParameter(String targetFiled, Object targetValue)#region public DbParameter GetParameter(String targetFiled, Object targetValue)
347 /**//// <summary>
348 /// 获取参数
349 /// </summary>
350 /// <param name="targetFiled">目标字段</param>
351 /// <param name="targetValue">值</param>
352 /// <returns>参数</returns>
353 public DbParameter GetParameter(String targetFiled, Object myTargetValue)
354 {
355 OleDbParameter myDbParameter = null;
356 if (myTargetValue is String)
357 {
358 myDbParameter = new OleDbParameter(targetFiled, OleDbType.VarChar);
359 }
360 else
361 {
362 if (myTargetValue is Boolean)
363 {
364 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Boolean);
365 }
366 else
367 {
368 if (myTargetValue is DateTime)
369 {
370 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Date);
371 }
372 else
373 {
374 if (myTargetValue is int)
375 {
376 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Integer);
377 }
378 else
379 {
380 if (myTargetValue is Int64)
381 {
382 myDbParameter = new OleDbParameter(targetFiled, OleDbType.BigInt);
383 }
384 else
385 {
386 if (myTargetValue is Double)
387 {
388 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Double);
389 }
390 else
391 {
392 if (myTargetValue is Byte[])
393 {
394 myDbParameter = new OleDbParameter(targetFiled, OleDbType.Binary);
395 }
396 else
397 {
398 myDbParameter = new OleDbParameter(targetFiled, OleDbType.VarChar);
399 }
400 }
401 }
402 }
403 }
404 }
405 }
406 myDbParameter.Value = myTargetValue;
407 return myDbParameter;
408 }
409 #endregion
410
411 public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue)#region public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue)
412 /**//// <summary>
413 /// 添加参数
414 /// </summary>
415 /// <param name="myTargetDbCommand">数据库命令</param>
416 /// <param name="targetFiled">目标字段</param>
417 /// <param name="targetValue">值</param>
418 public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object myTargetValue)
419 {
420 ((OleDbCommand)myTargetDbCommand).Parameters.Add(this.GetParameter(targetFiled, myTargetValue));
421 }
422 #endregion
423
424 public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句#region public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句
425 /**//// <summary>
426 /// 获得条件语句
427 /// </summary>
428 /// <param name="names">字段名</param>
429 /// <param name="values">字段值</param>
430 /// <param name="relation">逻辑关系</param>
431 /// <returns>字符串</returns>
432 public String GetWhereString(String[] names, ref Object[] values, String relation)
433 {
434 String returnValue = String.Empty;
435 String subSqlQuery = String.Empty;
436 for (int i = 0; i < names.Length; i++)
437 {
438 if ((names[i] != null) && (names[i].Length > 0))
439 {
440 if (values[i] == null)
441 {
442 subSqlQuery = " (" + names[i] + " IS NULL) ";
443 }
444 else
445 {
446 // 这里操作,就会有些重复了,不应该进行处理
447 // values[i] = this.SqlSafe(values[i].ToString());
448 subSqlQuery = " (" + names[i] + " = " + this.GetParameter(names[i]) + ") ";
449
450 if ((values[i].ToString().IndexOf('[') >= 0) || (values[i].ToString().IndexOf(']') >= 0))
451 {
452 values[i] = values[i].ToString().Replace("[", "/[");
453 values[i] = values[i].ToString().Replace("]", "/]");
454 values[i] = this.SqlSafe(values[i].ToString());
455 subSqlQuery = " (" + names[i] + " LIKE '" + values[i] + "' ESCAPE '/') ";
456 values[i] = null;
457 // subSqlQuery = " (" + names[i] + " LIKE ? ESCAPE '/') ";
458 }
459 }
460 returnValue += subSqlQuery + relation;
461 }
462 }
463 if (returnValue.Length > 0)
464 {
465 returnValue = returnValue.Substring(0, returnValue.Length - relation.Length - 1);
466 }
467 return returnValue;
468 }
469 #endregion
470
471 String GetParameter(String parameter) 获得参数Sql表达式#region String GetParameter(String parameter) 获得参数Sql表达式
472 /**//// <summary>
473 /// 获得参数Sql表达式
474 /// </summary>
475 /// <param name="parameter">参数名称</param>
476 /// <returns>字符串</returns>
477 public String GetParameter(String parameter)
478 {
479 return " ? ";
480 }
481 #endregion
482
483 public String PlusSign() 字符串相加符号#region public String PlusSign() 字符串相加符号
484 /**//// <summary>
485 /// 字符串相加符号
486 /// </summary>
487 /// <returns>字符加</returns>
488 public String PlusSign()
489 {
490 String returnValue = " + ";
491 switch (BaseConfiguration.Instance.DataBaseType)
492 {
493 case DataBaseType.Access:
494 case DataBaseType.Sqlserver:
495 returnValue = " + ";
496 break;
497 case DataBaseType.Oracle:
498 returnValue = " || ";
499 break;
500 }
501 return returnValue;
502 }
503 #endregion
504
505
506 public IDataReader ExecuteReader(String sqlQuery)#region public IDataReader ExecuteReader(String sqlQuery)
507 /**//// <summary>
508 /// 执行查询
509 /// </summary>
510 /// <param name="sqlQuery">sql查询</param>
511 /// <returns>结果集流</returns>
512 public IDataReader ExecuteReader(String sqlQuery)
513 {
514 // 写入调试信息
515 #if (DEBUG)
516 int milliStart = Environment.TickCount;
517 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
518 #endif
519 this.myOleDbCommand.CommandType = CommandType.Text;
520 this.myOleDbCommand.CommandText = sqlQuery;
521 if (this.InTransaction)
522 {
523 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
524 }
525 OleDbDataReader myOleDbDataReader = this.myOleDbCommand.ExecuteReader();
526 // 写入调试信息
527 #if (DEBUG)
528 int milliEnd = Environment.TickCount;
529 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
530 #endif
531 // 写入日志
532 this.WriteLog(sqlQuery);
533 return myOleDbDataReader;
534 }
535 #endregion
536
537 public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters);#region public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters);
538 /**//// <summary>
539 /// 执行查询
540 /// </summary>
541 /// <param name="sqlQuery">sql查询</param>
542 /// <param name="myDbParameterCollection">参数集</param>
543 /// <returns>结果集流</returns>
544 public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters)
545 {
546 return this.ExecuteReader(CommandType.Text, sqlQuery, myDbParameters);
547 }
548 #endregion
549
550 public IDataReader ExecuteReader(String sqlQuery, String name, Object value)#region public IDataReader ExecuteReader(String sqlQuery, String name, Object value)
551 /**//// <summary>
552 /// 执行查询
553 /// </summary>
554 /// <param name="myDataSet">数据集</param>
555 /// <param name="sqlQuery">sql查询</param>
556 /// <param name="name">参数名</param>
557 /// <param name="value">参数值</param>
558 /// <returns>结果集流</returns>
559 public IDataReader ExecuteReader(String sqlQuery, String name, Object value)
560 {
561 String[] names = new String[1] { name };
562 Object[] values = new Object[1] { value };
563 return this.ExecuteReader(CommandType.Text, sqlQuery, names, values);
564 }
565 #endregion
566
567 public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)
568 /**//// <summary>
569 /// 执行查询
570 /// </summary>
571 /// <param name="sqlQuery">sql查询</param>
572 /// <param name="names">参数名</param>
573 /// <param name="values">参数值</param>
574 /// <returns>结果集流</returns>
575 public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)
576 {
577 return this.ExecuteReader(CommandType.Text, sqlQuery, names, values);
578 }
579 #endregion
580
581 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
582 /**//// <summary>
583 /// 执行查询
584 /// </summary>
585 /// <param name="myCommandType">命令分类</param>
586 /// <param name="sqlQuery">sql查询</param>
587 /// <param name="myDbParameterCollection">参数集</param>
588 /// <returns>结果集流</returns>
589 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
590 {
591 // 写入调试信息
592 #if (DEBUG)
593 int milliStart = Environment.TickCount;
594 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
595 #endif
596 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
597 this.myOleDbCommand.CommandType = myCommandType;
598 if (myOleDbTransaction != null)
599 {
600 this.myOleDbCommand.Transaction = myOleDbTransaction;
601 }
602 if (myDbParameters != null)
603 {
604 this.myOleDbCommand.Parameters.Clear();
605 for (int i = 0; i < myDbParameters.Length; i++)
606 {
607 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
608 }
609 }
610 OleDbDataReader myOleDbDataReader = this.myOleDbCommand.ExecuteReader();
611 this.myOleDbCommand.Parameters.Clear();
612 // 写入调试信息
613 #if (DEBUG)
614 int milliEnd = Environment.TickCount;
615 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
616 #endif
617 // 写入日志
618 this.WriteLog(sqlQuery);
619 return myOleDbDataReader;
620 }
621 #endregion
622
623 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
624 /**//// <summary>
625 /// 执行查询
626 /// </summary>
627 /// <param name="myCommandType">命令分类</param>
628 /// <param name="sqlQuery">sql查询</param>
629 /// <param name="names">参数名</param>
630 /// <param name="values">参数值</param>
631 /// <returns>结果集流</returns>
632 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
633 {
634 return this.ExecuteReader(myCommandType, sqlQuery, this.GetParameters(names, values));
635 }
636 #endregion
637
638
639 public int ExecuteNonQuery(String sqlQuery)#region public int ExecuteNonQuery(String sqlQuery)
640 /**//// <summary>
641 /// 执行查询, SQL BUILDER 用了这个东西?参数需要保存, 不能丢失.
642 /// </summary>
643 /// <param name="sqlQuery">sql查询</param>
644 /// <returns>影响行数</returns>
645 public int ExecuteNonQuery(String sqlQuery)
646 {
647 // 写入调试信息
648 #if (DEBUG)
649 int milliStart = Environment.TickCount;
650 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
651 #endif
652 this.myOleDbCommand.CommandType = CommandType.Text;
653 this.myOleDbCommand.CommandText = sqlQuery;
654 if (this.InTransaction)
655 {
656 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
657 }
658 int returnValue = this.myOleDbCommand.ExecuteNonQuery();
659 // 写入调试信息
660 #if (DEBUG)
661 int milliEnd = Environment.TickCount;
662 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
663 #endif
664 // 写入日志
665 this.WriteLog(sqlQuery);
666 return returnValue;
667 }
668 #endregion
669
670 public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters);#region public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters);
671 /**//// <summary>
672 /// 执行查询
673 /// </summary>
674 /// <param name="sqlQuery">sql查询</param>
675 /// <param name="myDbParameterCollection">参数集</param>
676 /// <returns>影响行数</returns>
677 public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters)
678 {
679 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, myDbParameters);
680 }
681 #endregion
682
683 public int ExecuteNonQuery(String sqlQuery, String name, Object value)#region public int ExecuteNonQuery(String sqlQuery, String name, Object value)
684 /**//// <summary>
685 /// 执行查询
686 /// </summary>
687 /// <param name="myDataSet">数据集</param>
688 /// <param name="sqlQuery">sql查询</param>
689 /// <param name="name">参数名</param>
690 /// <param name="value">参数值</param>
691 /// <returns>影响行数</returns>
692 public int ExecuteNonQuery(String sqlQuery, String name, Object value)
693 {
694 String[] names = new String[1] { name };
695 Object[] values = new Object[1] { value };
696 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values);
697 }
698 #endregion
699
700 public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)
701 /**//// <summary>
702 /// 执行查询
703 /// </summary>
704 /// <param name="sqlQuery">sql查询</param>
705 /// <param name="names">参数名</param>
706 /// <param name="values">参数值</param>
707 /// <returns>影响行数</returns>
708 public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)
709 {
710 return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values);
711 }
712 #endregion
713
714 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
715 /**//// <summary>
716 /// 执行查询
717 /// </summary>
718 /// <param name="myCommandType">命令分类</param>
719 /// <param name="sqlQuery">sql查询</param>
720 /// <param name="myDbParameterCollection">参数集</param>
721 /// <returns>影响行数</returns>
722 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
723 {
724 OleDbTransaction myOleDbTransaction = null;
725 if (this.InTransaction)
726 {
727 myOleDbTransaction = this.myOleDbTransaction;
728 }
729 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, myDbParameters);
730 }
731 #endregion
732
733 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
734 /**//// <summary>
735 /// 执行查询
736 /// </summary>
737 /// <param name="myCommandType">命令分类</param>
738 /// <param name="sqlQuery">sql查询</param>
739 /// <param name="names">参数名</param>
740 /// <param name="values">参数值</param>
741 /// <returns>影响行数</returns>
742 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
743 {
744 OleDbTransaction myOleDbTransaction = null;
745 if (this.InTransaction)
746 {
747 myOleDbTransaction = this.myOleDbTransaction;
748 }
749 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, names, values);
750 }
751 #endregion
752
753 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
754 /**//// <summary>
755 /// 执行查询
756 /// </summary>
757 /// <param name="myOleDbTransaction">数据库事务</param>
758 /// <param name="myCommandType">命令分类</param>
759 /// <param name="sqlQuery">sql查询</param>
760 /// <param name="myDbParameterCollection">参数集</param>
761 /// <returns>影响行数</returns>
762 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
763 {
764 // 写入调试信息
765 #if (DEBUG)
766 int milliStart = Environment.TickCount;
767 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
768 #endif
769 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
770 this.myOleDbCommand.CommandType = myCommandType;
771 if (myOleDbTransaction != null)
772 {
773 this.myOleDbCommand.Transaction = (OleDbTransaction)myOleDbTransaction;
774 }
775 if (myDbParameters != null)
776 {
777 this.myOleDbCommand.Parameters.Clear();
778 for (int i = 0; i < myDbParameters.Length; i++)
779 {
780 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
781 }
782 }
783 int returnValue = this.myOleDbCommand.ExecuteNonQuery();
784 this.myOleDbCommand.Parameters.Clear();
785 // 写入调试信息
786 #if (DEBUG)
787 int milliEnd = Environment.TickCount;
788 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
789 #endif
790 // 写入日志
791 this.WriteLog(sqlQuery);
792 return returnValue;
793 }
794 #endregion
795
796 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
797 /**//// <summary>
798 /// 执行查询
799 /// </summary>
800 /// <param name="myOleDbTransaction">数据库事务</param>
801 /// <param name="myCommandType">命令分类</param>
802 /// <param name="sqlQuery">sql查询</param>
803 /// <param name="names">参数名</param>
804 /// <param name="values">参数值</param>
805 /// <returns>影响行数</returns>
806 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
807 {
808 return this.ExecuteNonQuery(myOleDbTransaction, myCommandType, sqlQuery, this.GetParameters(names, values));
809 }
810 #endregion
811
812
813 public Object ExecuteScalar(String sqlQuery)#region public Object ExecuteScalar(String sqlQuery)
814 /**//// <summary>
815 /// 执行查询
816 /// </summary>
817 /// <param name="sqlQuery">sql查询</param>
818 /// <returns>object</returns>
819 public Object ExecuteScalar(String sqlQuery)
820 {
821 return this.ExecuteScalar(CommandType.Text, sqlQuery, null, null);
822 }
823 #endregion
824
825 public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)
826 /**//// <summary>
827 /// 执行查询
828 /// </summary>
829 /// <param name="sqlQuery">sql查询</param>
830 /// <param name="myDbParameterCollection">参数集</param>
831 /// <returns>Object</returns>
832 public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)
833 {
834 return this.ExecuteScalar(CommandType.Text, sqlQuery, myDbParameters);
835 }
836 #endregion
837
838 public Object ExecuteScalar(String sqlQuery, String name, Object value)#region public Object ExecuteScalar(String sqlQuery, String name, Object value)
839 /**//// <summary>
840 /// 执行查询
841 /// </summary>
842 /// <param name="sqlQuery">sql查询</param>
843 /// <param name="name">参数名</param>
844 /// <param name="value">参数值</param>
845 /// <returns>Object</returns>
846 public Object ExecuteScalar(DataSet myDataSet, String sqlQuery, String name, Object value)
847 {
848 String[] names = new String[1] { name };
849 Object[] values = new Object[1] { value };
850 return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values);
851 }
852 #endregion
853
854 public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)
855 /**//// <summary>
856 /// 执行查询
857 /// </summary>
858 /// <param name="sqlQuery">sql查询</param>
859 /// <param name="names">参数名</param>
860 /// <param name="values">参数值</param>
861 /// <returns>影响行数</returns>
862 public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)
863 {
864 return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values);
865 }
866 #endregion
867
868 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
869 /**//// <summary>
870 /// 执行查询
871 /// </summary>
872 /// <param name="myCommandType">命令分类</param>
873 /// <param name="sqlQuery">sql查询</param>
874 /// <param name="myDbParameterCollection">参数集</param>
875 /// <returns>Object</returns>
876 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
877 {
878 OleDbTransaction myOleDbTransaction = null;
879 if (this.InTransaction)
880 {
881 myOleDbTransaction = this.myOleDbTransaction;
882 }
883 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, myDbParameters);
884 }
885 #endregion
886
887 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
888 /**//// <summary>
889 /// 执行查询
890 /// </summary>
891 /// <param name="myCommandType">命令分类</param>
892 /// <param name="sqlQuery">sql查询</param>
893 /// <param name="names">参数名</param>
894 /// <param name="values">参数值</param>
895 /// <returns>影响行数</returns>
896 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
897 {
898 OleDbTransaction myOleDbTransaction = null;
899 if (this.InTransaction)
900 {
901 myOleDbTransaction = this.myOleDbTransaction;
902 }
903 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, names, values);
904 }
905 #endregion
906
907 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
908 /**//// <summary>
909 /// 执行查询
910 /// </summary>
911 /// <param name="myOleDbTransaction">数据库事务</param>
912 /// <param name="myCommandType">命令分类</param>
913 /// <param name="sqlQuery">sql查询</param>
914 /// <param name="myDbParameterCollection">参数集</param>
915 /// <returns>Object</returns>
916 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
917 {
918 // 写入调试信息
919 #if (DEBUG)
920 int milliStart = Environment.TickCount;
921 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
922 #endif
923 this.myOleDbCommand = new OleDbCommand(sqlQuery, this.myOleDbConnection);
924 this.myOleDbCommand.CommandType = myCommandType;
925 if (myOleDbTransaction != null)
926 {
927 this.myOleDbCommand.Transaction = (OleDbTransaction)myOleDbTransaction;
928 }
929 if (myDbParameters != null)
930 {
931 this.myOleDbCommand.Parameters.Clear();
932 for (int i = 0; i < myDbParameters.Length; i++)
933 {
934 this.myOleDbCommand.Parameters.Add(myDbParameters[i]);
935 }
936 }
937 Object returnValue = this.myOleDbCommand.ExecuteScalar();
938 this.myOleDbCommand.Parameters.Clear();
939 // 写入调试信息
940 #if (DEBUG)
941 int milliEnd = Environment.TickCount;
942 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
943 #endif
944 // 写入日志
945 this.WriteLog(sqlQuery);
946 return returnValue;
947 }
948 #endregion
949
950 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
951 /**//// <summary>
952 /// 执行查询
953 /// </summary>
954 /// <param name="myOleDbTransaction">数据库事务</param>
955 /// <param name="myCommandType">命令分类</param>
956 /// <param name="sqlQuery">sql查询</param>
957 /// <param name="names"></param>
958 /// <param name="values"></param>
959 /// <returns>影响行数</returns>
960 public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
961 {
962 return this.ExecuteScalar(myOleDbTransaction, myCommandType, sqlQuery, this.GetParameters(names, values));
963 }
964 #endregion
965
966
967 public DataTable Fill(DataTable myDataTable, String sqlQuery)#region public DataTable Fill(DataTable myDataTable, String sqlQuery)
968 /**//// <summary>
969 /// 填充数据表
970 /// </summary>
971 /// <param name="myDataTable">目标数据表</param>
972 /// <param name="sqlQuery">查询</param>
973 /// <returns>数据表</returns>
974 public DataTable Fill(DataTable myDataTable, String sqlQuery)
975 {
976 return this.Fill(myDataTable, CommandType.Text, sqlQuery, null, null);
977 }
978 #endregion
979
980 public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)
981 /**//// <summary>
982 /// 填充数据表
983 /// </summary>
984 /// <param name="myDataTable">目标数据表</param>
985 /// <param name="sqlQuery">sql查询</param>
986 /// <param name="myDbParameterCollection">参数集</param>
987 /// <returns>数据表</returns>
988 public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)
989 {
990 return this.Fill(myDataTable, CommandType.Text, sqlQuery, myDbParameters);
991 }
992 #endregion
993
994 public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)
995 /**//// <summary>
996 /// 填充数据表
997 /// </summary>
998 /// <param name="myDataSet">目标数据表</param>
999 /// <param name="sqlQuery">sql查询</param>
1000 /// <param name="name">参数名</param>
1001 /// <param name="value">参数值</param>
1002 /// <returns>数据表</returns>
1003 public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)
1004 {
1005 String[] names = new String[1] { name };
1006 Object[] values = new Object[1] { value };
1007 return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values);
1008 }
1009 #endregion
1010
1011 public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)
1012 /**//// <summary>
1013 /// 填充数据表
1014 /// </summary>
1015 /// <param name="myDataSet">目标数据表</param>
1016 /// <param name="sqlQuery">sql查询</param>
1017 /// <param name="names">参数名</param>
1018 /// <param name="values">参数值</param>
1019 /// <returns>数据表</returns>
1020 public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)
1021 {
1022 return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values);
1023 }
1024 #endregion
1025
1026 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
1027 /**//// <summary>
1028 /// 填充数据表
1029 /// </summary>
1030 /// <param name="myDataSet">目标数据表</param>
1031 /// <param name="myCommandType">命令分类</param>
1032 /// <param name="sqlQuery">sql查询</param>
1033 /// <param name="myDbParameterCollection">参数集</param>
1034 /// <returns>数据表</returns>
1035 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)
1036 {
1037 // 写入调试信息
1038 #if (DEBUG)
1039 int milliStart = Environment.TickCount;
1040 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1041 #endif
1042 this.myOleDbDataAdapter = new OleDbDataAdapter(sqlQuery, this.myOleDbConnection);
1043 this.myOleDbDataAdapter.SelectCommand.CommandType = myCommandType;
1044 if (this.InTransaction)
1045 {
1046 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1047 }
1048 if (myDbParameters != null)
1049 {
1050 this.myOleDbCommand.Parameters.Clear();
1051 for (int i = 0; i < myDbParameters.Length; i++)
1052 {
1053 this.myOleDbDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]);
1054 }
1055 }
1056 this.myOleDbDataAdapter.Fill(myDataTable);
1057 this.myOleDbDataAdapter.SelectCommand.Parameters.Clear();
1058 // 写入调试信息
1059 #if (DEBUG)
1060 int milliEnd = Environment.TickCount;
1061 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1062 #endif
1063 // 写入日志
1064 this.WriteLog(sqlQuery);
1065 return myDataTable;
1066 }
1067 #endregion
1068
1069 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1070 /**//// <summary>
1071 /// 填充数据表
1072 /// </summary>
1073 /// <param name="myDataSet">目标数据表</param>
1074 /// <param name="myCommandType">命令分类</param>
1075 /// <param name="sqlQuery">sql查询</param>
1076 /// <param name="names">参数名</param>
1077 /// <param name="values">参数值</param>
1078 /// <returns>数据表</returns>
1079 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1080 {
1081 return this.Fill(myDataTable, myCommandType, sqlQuery, this.GetParameters(names, values));
1082 }
1083 #endregion
1084
1085
1086 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)
1087 /**//// <summary>
1088 /// 填充数据集
1089 /// </summary>
1090 /// <param name="myDataSet">目标数据集</param>
1091 /// <param name="sqlQuery">查询</param>
1092 /// <param name="tableName">填充表</param>
1093 /// <returns>数据集</returns>
1094 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)
1095 {
1096 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, null, null);
1097 }
1098 #endregion
1099
1100 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1101 /**//// <summary>
1102 /// 填充数据集
1103 /// </summary>
1104 /// <param name="myDataSet">数据集</param>
1105 /// <param name="sqlQuery">sql查询</param>
1106 /// <param name="tableName">填充表</param>
1107 /// <param name="myDbParameterCollection">参数集</param>
1108 /// <returns>数据集</returns>
1109 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1110 {
1111 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, myDbParameters);
1112 }
1113 #endregion
1114
1115 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)
1116 /**//// <summary>
1117 /// 填充数据集
1118 /// </summary>
1119 /// <param name="myDataSet">数据集</param>
1120 /// <param name="sqlQuery">sql查询</param>
1121 /// <param name="tableName">填充表</param>
1122 /// <param name="name">参数名</param>
1123 /// <param name="value">参数值</param>
1124 /// <returns>DataSet</returns>
1125 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value)
1126 {
1127 String[] names = new String[1] { name };
1128 Object[] values = new Object[1] { value };
1129 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values);
1130 }
1131 #endregion
1132
1133 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)
1134 /**//// <summary>
1135 /// 填充数据集
1136 /// </summary>
1137 /// <param name="myDataSet">数据集</param>
1138 /// <param name="sqlQuery">sql查询</param>
1139 /// <param name="tableName">填充表</param>
1140 /// <param name="names">参数名</param>
1141 /// <param name="values">参数值</param>
1142 /// <returns>DataSet</returns>
1143 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values)
1144 {
1145 return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values);
1146 }
1147 #endregion
1148
1149 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)#region public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1150 /**//// <summary>
1151 /// 填充数据集
1152 /// </summary>
1153 /// <param name="myDataSet">数据集</param>
1154 /// <param name="myCommandType">命令分类</param>
1155 /// <param name="sqlQuery">sql查询</param>
1156 /// <param name="tableName">填充表</param>
1157 /// <param name="myDbParameterCollection">参数集</param>
1158 /// <returns>数据集</returns>
1159 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters)
1160 {
1161 // 写入调试信息
1162 #if (DEBUG)
1163 int milliStart = Environment.TickCount;
1164 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1165 #endif
1166 this.myOleDbDataAdapter = new OleDbDataAdapter(sqlQuery, this.myOleDbConnection);
1167 this.myOleDbDataAdapter.SelectCommand.CommandType = myCommandType;
1168 if (this.InTransaction)
1169 {
1170 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1171 }
1172 if (myDbParameters != null)
1173 {
1174 this.myOleDbCommand.Parameters.Clear();
1175 for (int i = 0; i < myDbParameters.Length; i++)
1176 {
1177 this.myOleDbDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]);
1178 }
1179 }
1180 this.myOleDbDataAdapter.Fill(myDataSet, tableName);
1181 this.myOleDbDataAdapter.SelectCommand.Parameters.Clear();
1182 // 写入调试信息
1183 #if (DEBUG)
1184 int milliEnd = Environment.TickCount;
1185 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1186 #endif
1187 // 写入日志
1188 this.WriteLog(sqlQuery);
1189 return myDataSet;
1190 }
1191 #endregion
1192
1193 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)#region public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)
1194 /**//// <summary>
1195 /// 填充数据集
1196 /// </summary>
1197 /// <param name="myDataSet">数据集</param>
1198 /// <param name="myCommandType">命令分类</param>
1199 /// <param name="sqlQuery">sql查询</param>
1200 /// <param name="tableName">填充表</param>
1201 /// <param name="names">参数名</param>
1202 /// <param name="values">参数值</param>
1203 /// <returns>DataSet</returns>
1204 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values)
1205 {
1206 return this.Fill(myDataSet, myCommandType, sqlQuery, tableName, this.GetParameters(names, values));
1207 }
1208 #endregion
1209
1210
1211 public int ExecuteProcedure(String procedureName)#region public int ExecuteProcedure(String procedureName)
1212 /**//// <summary>
1213 /// 执行数据库查询
1214 /// </summary>
1215 /// <param name="procedureName">存储过程</param>
1216 /// <returns>int</returns>
1217 public int ExecuteProcedure(String procedureName)
1218 {
1219 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, null, null);
1220 }
1221 #endregion
1222
1223 public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)#region public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)
1224 /**//// <summary>
1225 /// 执行存储过程
1226 /// </summary>
1227 /// <param name="procedureName">存储过程名</param>
1228 /// <param name="myDbParameterCollection">参数集</param>
1229 /// <returns>影响行数</returns>
1230 public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)
1231 {
1232 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, myDbParameters);
1233 }
1234 #endregion
1235
1236 public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程#region public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程
1237 /**//// <summary>
1238 /// 执行存储过程
1239 /// </summary>
1240 /// <param name="procedureName">存储过程名</param>
1241 /// <param name="name">参数名</param>
1242 /// <param name="value">参数值</param>
1243 /// <returns>影响行数</returns>
1244 public int ExecuteProcedure(String procedureName, String name, String value)
1245 {
1246 String[] names = new String[1];
1247 Object[] values = new Object[1];
1248 int returnValue = 0;
1249 names[0] = name;
1250 values[0] = value;
1251 returnValue = this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values);
1252 return returnValue;
1253 }
1254 #endregion
1255
1256 public int ExecuteProcedure(String procedureName, String[] names, Object[] values)#region public int ExecuteProcedure(String procedureName, String[] names, Object[] values)
1257 /**//// <summary>
1258 /// 执行数据库脚本
1259 /// </summary>
1260 /// <param name="procedureName">存储过程</param>
1261 /// <param name="names">参数名</param>
1262 /// <param name="values">参数值</param>
1263 /// <returns>影响行数</returns>
1264 public int ExecuteProcedure(String procedureName, String[] names, Object[] values)
1265 {
1266 return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values);
1267 }
1268 #endregion
1269
1270 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)#region public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)
1271 /**//// <summary>
1272 /// 执行数据库脚本
1273 /// </summary>
1274 /// <param name="myDataSet">数据集</param>
1275 /// <param name="procedureName">存储过程</param>
1276 /// <param name="tableName">填充表</param>
1277 /// <param name="myDbParameterCollection">参数集</param>
1278 /// <returns>数据集</returns>
1279 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)
1280 {
1281 return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, myDbParameters);
1282 }
1283 #endregion
1284
1285 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)#region public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)
1286 /**//// <summary>
1287 /// 执行数据库脚本
1288 /// </summary>
1289 /// <param name="myDataSet">数据集</param>
1290 /// <param name="procedureName">存储过程</param>
1291 /// <param name="tableName">填充表</param>
1292 /// <param name="names">参数名</param>
1293 /// <param name="values">参数值</param>
1294 /// <returns>影响行数</returns>
1295 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values)
1296 {
1297 return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, names, values);
1298 }
1299 #endregion
1300
1301
1302 public IDbTransaction BeginTransaction()#region public IDbTransaction BeginTransaction()
1303 /**//// <summary>
1304 /// 事务开始
1305 /// </summary>
1306 /// <returns>事务</returns>
1307 public IDbTransaction BeginTransaction()
1308 {
1309 // 写入调试信息
1310 #if (DEBUG)
1311 int milliStart = Environment.TickCount;
1312 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1313 #endif
1314 if (!this.InTransaction)
1315 {
1316 this.InTransaction = true;
1317 this.myOleDbTransaction = this.myOleDbConnection.BeginTransaction();
1318 this.myOleDbCommand.Transaction = this.myOleDbTransaction;
1319 this.myOleDbDataAdapter.SelectCommand.Transaction = this.myOleDbTransaction;
1320 }
1321 // 写入调试信息
1322 #if (DEBUG)
1323 int milliEnd = Environment.TickCount;
1324 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1325 #endif
1326 return this.myOleDbTransaction;
1327 }
1328 #endregion
1329
1330 public void CommitTransaction()#region public void CommitTransaction()
1331 /**//// <summary>
1332 /// 递交事务
1333 /// </summary>
1334 public void CommitTransaction()
1335 {
1336 // 写入调试信息
1337 #if (DEBUG)
1338 int milliStart = Environment.TickCount;
1339 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1340 #endif
1341 if (this.InTransaction)
1342 {
1343 // 事务已经完成了,一定要更新标志信息
1344 this.InTransaction = false;
1345 this.myOleDbTransaction.Commit();
1346 }
1347 // 写入调试信息
1348 #if (DEBUG)
1349 int milliEnd = Environment.TickCount;
1350 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1351 #endif
1352 }
1353 #endregion
1354
1355 public void RollbackTransaction()#region public void RollbackTransaction()
1356 /**//// <summary>
1357 /// 回滚事务
1358 /// </summary>
1359 public void RollbackTransaction()
1360 {
1361 // 写入调试信息
1362 #if (DEBUG)
1363 int milliStart = Environment.TickCount;
1364 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1365 #endif
1366 if (this.InTransaction)
1367 {
1368 this.InTransaction = false;
1369 this.myOleDbTransaction.Rollback();
1370 }
1371 // 写入调试信息
1372 #if (DEBUG)
1373 int milliEnd = Environment.TickCount;
1374 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1375 #endif
1376 }
1377 #endregion
1378
1379
1380 public delegate int Asyncdelegate();
1381
1382 private void CallbackMethod(IAsyncResult myIAsyncResult) 异步调用的挂接代理#region private void CallbackMethod(IAsyncResult myIAsyncResult) 异步调用的挂接代理
1383 /**//// <summary>
1384 /// 异步调用的挂接代理
1385 /// </summary>
1386 /// <param name="myIAsyncResult">回调</param>
1387 private void CallbackMethod(IAsyncResult myIAsyncResult)
1388 {
1389 Asyncdelegate myAsyncdelegate = (Asyncdelegate)myIAsyncResult.AsyncState;
1390 myAsyncdelegate.EndInvoke(myIAsyncResult);
1391 }
1392 #endregion
1393
1394 // 定义与方法同签名的委托
1395 private delegate int DelegateExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values);
1396
1397 private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1398 /**//// <summary>
1399 /// 异步调用数据库查询
1400 /// </summary>
1401 /// <param name="myCommandType">命令分类</param>
1402 /// <param name="sqlQuery">sql查询</param>
1403 /// <param name="names">参数名</param>
1404 /// <param name="values">参数值</param>
1405 /// <returns>影响行数</returns>
1406 private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1407 {
1408 int returnValue = 0;
1409 this.Open();
1410 returnValue = this.ExecuteNonQuery(myCommandType, sqlQuery, names, values);
1411 this.Close();
1412 return returnValue;
1413 }
1414 #endregion
1415
1416 public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1417 /**//// <summary>
1418 /// 异步调用数据库查询
1419 /// </summary>
1420 /// <param name="myCommandType">命令分类</param>
1421 /// <param name="sqlQuery">sql查询</param>
1422 /// <param name="names">参数名</param>
1423 /// <param name="values">参数值</param>
1424 public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1425 {
1426 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1427
1428 DelegateExecuteNonQuery myDelegateExecuteNonQuery = new DelegateExecuteNonQuery(AsyncExecuteNonQuery);
1429 myDelegateExecuteNonQuery.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null);
1430 }
1431 #endregion
1432
1433 // 定义与方法同签名的委托
1434 private delegate Object DelegateExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values);
1435
1436 private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1437 /**//// <summary>
1438 /// 异步调用数据库查询
1439 /// </summary>
1440 /// <param name="myCommandType">命令分类</param>
1441 /// <param name="sqlQuery">sql查询</param>
1442 /// <param name="names">参数名</param>
1443 /// <param name="values">参数值</param>
1444 /// <returns>对象</returns>
1445 private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1446 {
1447 Object returnValue = null;
1448 this.Open();
1449 returnValue = this.ExecuteScalar(myCommandType, sqlQuery, names, values);
1450 this.Close();
1451 return returnValue;
1452 }
1453 #endregion
1454
1455 public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) 异步调用数据库查询
1456 /**//// <summary>
1457 /// 异步调用数据库查询
1458 /// </summary>
1459 /// <param name="myCommandType">命令分类</param>
1460 /// <param name="sqlQuery">sql查询</param>
1461 /// <param name="names">参数名</param>
1462 /// <param name="values">参数值</param>
1463 public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)
1464 {
1465 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1466
1467 DelegateExecuteScalar myDelegateExecuteScalar = new DelegateExecuteScalar(AsyncExecuteScalar);
1468 myDelegateExecuteScalar.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null);
1469 }
1470 #endregion
1471
1472 // 定义与方法同签名的委托
1473 private delegate int DelegateExecuteProcedure(String procedureName, String[] names, Object[] values);
1474
1475 private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values) 异步调用数据库查询#region private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values) 异步调用数据库查询
1476 /**//// <summary>
1477 /// 异步调用数据库查询
1478 /// </summary>
1479 /// <param name="procedureName">存储过程</param>
1480 /// <param name="names">参数名</param>
1481 /// <param name="values">参数值</param>
1482 /// <returns>影响行数</returns>
1483 private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values)
1484 {
1485 int returnValue = 0;
1486 this.Open();
1487 returnValue = this.ExecuteProcedure(procedureName, names, values);
1488 this.Close();
1489 return returnValue;
1490 }
1491 #endregion
1492
1493 public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values) 异步调用数据库查询#region public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values) 异步调用数据库查询
1494 /**//// <summary>
1495 /// 异步调用数据库查询
1496 /// </summary>
1497 /// <param name="procedureName">存储过程</param>
1498 /// <param name="names">参数名</param>
1499 /// <param name="values">参数值</param>
1500 public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values)
1501 {
1502 AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod);
1503
1504 DelegateExecuteProcedure myDelegateExecuteProcedure = new DelegateExecuteProcedure(AsyncExecuteProcedure);
1505 myDelegateExecuteProcedure.BeginInvoke(procedureName, names, values, myAsyncCallback, null);
1506 }
1507 #endregion
1508
1509
1510 public void WriteLog(String sqlQuery) 写入SQL查询语句日志#region public void WriteLog(String sqlQuery) 写入SQL查询语句日志
1511 /**//// <summary>
1512 /// 写入SQL查询语日志
1513 /// </summary>
1514 /// <param name="sqlQuery">SQL查询语</param>
1515 public void WriteLog(String sqlQuery)
1516 {
1517 this.WriteLog(DateTime.Now.ToString(BaseSystemInfo.DateFormat) + "_" + this.FileName, sqlQuery);
1518 // 将调试信息输出到屏幕上
1519 #if DEBUG
1520 System.Console.WriteLine(sqlQuery);
1521 #endif
1522 }
1523 #endregion
1524
1525 public void WriteLog(String fileName, String sqlQuery) 写入SQL查询语句日志#region public void WriteLog(String fileName, String sqlQuery) 写入SQL查询语句日志
1526 /**//// <summary>
1527 /// 写入SQL查询语句
1528 /// </summary>
1529 /// <param name="fileName">文件名</param>
1530 /// <param name="sqlQuery">异常</param>
1531 public void WriteLog(String fileName, String sqlQuery)
1532 {
1533 String returnValue = String.Empty;
1534 // 系统里应该可以配置是否记录异常现象
1535 if (!BaseSystemInfo.LogSQL)
1536 {
1537 return;
1538 }
1539 // 将异常信息写入本地文件中
1540 String logDirectory = BaseSystemInfo.StartupPath + @"\\Log\\Query";
1541 if (!System.IO.Directory.Exists(logDirectory))
1542 {
1543 System.IO.Directory.CreateDirectory(logDirectory);
1544 }
1545 String writerFileName = logDirectory + "\\" + fileName;
1546 if (!File.Exists(writerFileName))
1547 {
1548 FileStream myFileStream = new FileStream(writerFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
1549 myFileStream.Close();
1550 }
1551 StreamWriter myStreamWriter = new StreamWriter(writerFileName, true, Encoding.Default);
1552 myStreamWriter.WriteLine(DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " " + sqlQuery);
1553 myStreamWriter.Close();
1554 }
1555 #endregion
1556
1557
1558 public void Close()#region public void Close()
1559 /**//// <summary>
1560 /// 关闭数据库连接
1561 /// </summary>
1562 public void Close()
1563 {
1564 // 写入调试信息
1565 #if (DEBUG)
1566 int milliStart = Environment.TickCount;
1567 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1568 #endif
1569 if (this.myOleDbConnection != null)
1570 {
1571 this.myOleDbConnection.Close();
1572 this.myOleDbConnection.Dispose();
1573 }
1574 // 写入调试信息
1575 #if (DEBUG)
1576 int milliEnd = Environment.TickCount;
1577 Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
1578 #endif
1579 }
1580 #endregion
1581
1582 private void Dispose(bool disposing)#region private void Dispose(bool disposing)
1583 /**//// <summary>
1584 /// 卸载
1585 /// </summary>
1586 /// <param name="disposing">卸载</param>
1587 private void Dispose(bool disposing)
1588 {
1589 if (disposing)
1590 {
1591 this.myOleDbCommand.Dispose();
1592 this.myOleDbDataAdapter.Dispose();
1593 this.myOleDbTransaction.Dispose();
1594 this.myOleDbConnection.Dispose();
1595 }
1596 }
1597 #endregion
1598
1599 public void Dispose()#region public void Dispose()
1600 /**//// <summary>
1601 /// 卸载
1602 /// </summary>
1603 public void Dispose()
1604 {
1605 Dispose(true);
1606 GC.SuppressFinalize(this);
1607 }
1608 #endregion
1609 }
1610}
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。