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