C#连接Oracle的帮助类代码

wuman 贡献于2013-09-25

作者 吴宝军  创建于2011-12-14 07:04:00   修改者吴宝军  修改于2011-12-14 08:56:00字数48703

文档摘要:C#连接Oracle的帮助类代码
关键词:

 //------------------------------------------------------------ // All Rights Reserved , Copyright (C) 2008 , Jirisoft , Ltd. //------------------------------------------------------------ using System; using System.IO; using System.Text; using System.Globalization; using System.Data; using System.Data.Common; using System.Data.OracleClient; using System.Reflection; using System.Diagnostics; namespace Jirisoft.Common.DbUtilities { using Jirisoft.Common; using Jirisoft.Common.Utilities; /**//// /// OracleHelper /// 有关数据库连接的方法。 /// /// 修改纪录 /// /// 2008.06.01 版本:1.2 JiRiGaLa 数据库连接获得方式进行改进,构造函数获得调通。 /// 2008.05.08 版本:1.1 JiRiGaLa 调试通过,修改一些 有关参数的 Bug。 /// 2008.05.07 版本:1.0 JiRiGaLa 创建。 /// /// 版本:1.1 /// /// /// JiRiGaLa /// 2008.05.08 /// /// public class OracleHelper : IDbHelper, IDisposable { public OracleConnection myOracleConnection = new OracleConnection(); public OracleCommand myOracleCommand = new OracleCommand(); public OracleDataAdapter myOracleDataAdapter = new OracleDataAdapter(); public OracleTransaction myOracleTransaction; private bool inTransaction; // 是否已在事务之中 public String FileName = "OracleHelper.txt"; // SQL查询语句日志 public OracleHelper()#region public OracleHelper() /**//// /// 构造方法 /// public OracleHelper() { } #endregion public OracleHelper(String connectionString)#region public OracleHelper(String connectionString) /**//// /// 设定软件名称 /// /// 数据连接 public OracleHelper(String connectionString) : this() { this.myOracleConnection.ConnectionString = connectionString; } #endregion public String GetDBNow()#region public String GetDBNow() /**//// /// 获得数据库日期时间 /// /// 日期时间 public String GetDBNow() { String returnValue = " Getdate() "; switch (BaseConfiguration.Instance.DataBaseType) { case DataBaseType.Access: returnValue = "'" + DateTime.Now.ToString() + "'"; break; case DataBaseType.Sqlserver: returnValue = " GetDate() "; break; case DataBaseType.Oracle: returnValue = " SYSDATE "; break; } return returnValue; } #endregion public DateTime GetDBDateTime() 获得数据库日期时间#region public DateTime GetDBDateTime() 获得数据库日期时间 /**//// /// 获得数据库日期时间 /// /// 日期时间 public DateTime GetDBDateTime() { String sqlQuery = this.GetDBNow(); Object myObject = this.ExecuteScalar(sqlQuery); return DateTime.Parse(myObject.ToString()); } #endregion public bool InTransaction 是否已采用事务#region public bool InTransaction 是否已采用事务 /**//// /// 是否已采用事务 /// /// 采用事务 public bool InTransaction { get { return this.inTransaction; } set { this.inTransaction = value; } } #endregion public IDbConnection GetDbConnection() 获取数据库连接#region public IDbConnection GetDbConnection() 获取数据库连接 /**//// /// 获取数据库连接 /// /// 数据库连接 public IDbConnection GetDbConnection() { return this.myOracleConnection; } #endregion public IDbTransaction GetDbTransaction() 获取数据源上执行的事务#region public IDbTransaction GetDbTransaction() 获取数据源上执行的事务 /**//// /// 获取数据源上执行的事务 /// /// 数据源上执行的事务 public IDbTransaction GetDbTransaction() { return this.myOracleTransaction; } #endregion public IDbCommand GetDbCommand() 获取数据源上命令#region public IDbCommand GetDbCommand() 获取数据源上命令 /**//// /// 获取数据源上命令 /// /// 数据源上命令 public IDbCommand GetDbCommand() { return this.myOracleCommand; } #endregion public IDbConnection Open()#region public IDbConnection Open() /**//// /// 这时主要的获取数据库连接的方法 /// /// 数据库连接 public IDbConnection Open() { #if (DEBUG) int milliStart = Environment.TickCount; #endif if (String.IsNullOrEmpty(this.myOracleConnection.ConnectionString)) { // 这里是获取一个连接的详细方法 if (this.myOracleConnection.ConnectionString.Length == 0) { BaseConfiguration.Instance.GetSetting(); } this.Open(BaseConfiguration.Instance.OracleConnection); } // 写入调试信息 #if (DEBUG) Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif return this.myOracleConnection; } #endregion public IDbConnection Open(String connectionString)#region public IDbConnection Open(String connectionString) /**//// /// 获得新的数据库连接 /// /// 数据库连接字符串 /// 数据库连接 public IDbConnection Open(String connectionString) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 这里数据库连接打开的时候,就判断注册属性的有效性 if (!BaseCodeChange.Instance.CheckRegister()) { // 若没有进行注册,让程序无法打开数据库比较好。 this.myOracleConnection.ConnectionString = String.Empty; // 抛出异常信息显示给客户 throw new Exception(BaseConfiguration.Instance.ExceptionInfo); } if (this.myOracleConnection.State == ConnectionState.Closed) { this.myOracleConnection.ConnectionString = connectionString; this.myOracleConnection.Open(); // 创建对象 this.myOracleCommand = new OracleCommand(String.Empty, this.myOracleConnection); this.myOracleDataAdapter = new OracleDataAdapter(String.Empty, this.myOracleConnection); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif } return this.myOracleConnection; } #endregion 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) /**//// /// 测试数据库连接是否成功,这里抛出异常进行加强,充分使用系统的异常功能。 /// /// 数据库类别 /// 数据库名称 /// 用户名 /// 密码 /// 服务器名称 /// 是否信任的连接 /// 是否连接成功 public bool TestConn(DataBaseType dataBaseType, String dataBase, String userName, String password, String workstation, bool trustLink) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif bool returnValue = false; // 连接是否成功 String connectionString = String.Empty; // 连接字符传 OracleConnection DbConnection = null; // 数据库连接 connectionString = BaseConfiguration.Instance.GetOleDbConnection(dataBaseType, dataBase, userName, password, workstation, trustLink); DbConnection = (OracleConnection)this.Open(connectionString); try { if (DbConnection.State == ConnectionState.Closed) { DbConnection.Open(); } DbConnection.Close(); returnValue = true; } catch (OracleException myOracleException) { DbConnection = null; throw myOracleException; } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif return returnValue; } #endregion public String SqlSafe(String value) 检查参数的安全性#region public String SqlSafe(String value) 检查参数的安全性 /**//// /// 检查参数的安全性 /// /// 参数 /// 安全的参数 public String SqlSafe(String value) { value = value.Replace("'", "''"); // value = value.Replace("%", "'%"); return value; } #endregion public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues)#region public DbParameter[] GetParameters(String[] targetFileds, Object[] targetValues) /**//// /// 获取参数 /// /// 目标字段 /// 值 /// 参数集 public DbParameter[] GetParameters(String[] targetFileds, Object[] myTargetValues) { DbParameter[] myDbParameters = new DbParameter[0]; if (targetFileds != null && myTargetValues != null) { myDbParameters = new DbParameter[targetFileds.Length]; for (int i = 0; i < targetFileds.Length; i++) { myDbParameters[i] = this.GetParameter(targetFileds[i], myTargetValues[i]); } } return myDbParameters; } #endregion public DbParameter GetParameter(String targetFiled, Object targetValue)#region public DbParameter GetParameter(String targetFiled, Object targetValue) /**//// /// 获取参数 /// /// 目标字段 /// 值 /// 参数 public DbParameter GetParameter(String targetFiled, Object myTargetValue) { OracleParameter myDbParameter = null; if (myTargetValue is String) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.VarChar); } else { if (myTargetValue is Boolean) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.Byte); } else { if (myTargetValue is DateTime) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.DateTime); } else { if (myTargetValue is int) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.Int32); } else { if (myTargetValue is Int64) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.Number); } else { if (myTargetValue is Double) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.Double); } else { if (myTargetValue is Byte[]) { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.Blob); } else { myDbParameter = new OracleParameter(":" + targetFiled, OracleType.VarChar); } } } } } } } myDbParameter.Value = myTargetValue; return myDbParameter; } #endregion public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue)#region public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object targetValue) /**//// /// 添加参数 /// /// 数据库命令 /// 目标字段 /// 值 public void AddParameter(IDbCommand myTargetDbCommand, String targetFiled, Object myTargetValue) { ((OracleCommand)myTargetDbCommand).Parameters.Add(this.GetParameter(targetFiled, myTargetValue)); } #endregion public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句#region public String GetWhereString(String[] names, ref Object[] values, String relation) 获得条件语句 /**//// /// 获得条件语句 /// /// 字段名 /// 字段值 /// 逻辑关系 /// 字符串 public String GetWhereString(String[] names, ref Object[] values, String relation) { String returnValue = String.Empty; String subSqlQuery = String.Empty; for (int i = 0; i < names.Length; i++) { if ((names[i] != null) && (names[i].Length > 0)) { if (values[i] == null || String.IsNullOrEmpty(values[i].ToString())) { subSqlQuery = " (" + names[i] + " IS NULL) "; } else { // 这里操作,就会有些重复了,不应该进行处理 // values[i] = this.SqlSafe(values[i].ToString()); subSqlQuery = " (" + names[i] + " = " + this.GetParameter(names[i]) + ") "; } returnValue += subSqlQuery + relation; } } if (returnValue.Length > 0) { returnValue = returnValue.Substring(0, returnValue.Length - relation.Length - 1); } return returnValue; } #endregion String GetParameter(String parameter) 获得参数Sql表达式#region String GetParameter(String parameter) 获得参数Sql表达式 /**//// /// 获得参数Sql表达式 /// /// 参数名称 /// 字符串 public String GetParameter(String parameter) { return " :" + parameter + " "; } #endregion public String PlusSign() 字符串相加符号#region public String PlusSign() 字符串相加符号 /**//// /// 字符串相加符号 /// /// 字符加 public String PlusSign() { return " || "; } #endregion public IDataReader ExecuteReader(String sqlQuery)#region public IDataReader ExecuteReader(String sqlQuery) /**//// /// 执行查询 /// /// sql查询 /// 结果集流 public IDataReader ExecuteReader(String sqlQuery) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleCommand.CommandType = CommandType.Text; this.myOracleCommand.CommandText = sqlQuery; if (this.InTransaction) { this.myOracleCommand.Transaction = this.myOracleTransaction; } OracleDataReader myOracleDataReader = this.myOracleCommand.ExecuteReader(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return myOracleDataReader; } #endregion public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters);#region public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters); /**//// /// 执行查询 /// /// sql查询 /// 参数集 /// 结果集流 public IDataReader ExecuteReader(String sqlQuery, DbParameter[] myDbParameters) { return this.ExecuteReader(CommandType.Text, sqlQuery, myDbParameters); } #endregion public IDataReader ExecuteReader(String sqlQuery, String name, Object value)#region public IDataReader ExecuteReader(String sqlQuery, String name, Object value) /**//// /// 执行查询 /// /// 数据集 /// sql查询 /// 参数名 /// 参数值 /// 结果集流 public IDataReader ExecuteReader(String sqlQuery, String name, Object value) { String[] names = new String[1] { name }; Object[] values = new Object[1] { value }; return this.ExecuteReader(CommandType.Text, sqlQuery, names, values); } #endregion public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// sql查询 /// 参数名 /// 参数值 /// 结果集流 public IDataReader ExecuteReader(String sqlQuery, String[] names, Object[] values) { return this.ExecuteReader(CommandType.Text, sqlQuery, names, values); } #endregion public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数集 /// 结果集流 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleCommand = new OracleCommand(sqlQuery, this.myOracleConnection); this.myOracleCommand.CommandType = myCommandType; if (this.myOracleTransaction != null) { this.myOracleCommand.Transaction = this.myOracleTransaction; } if (myDbParameters != null) { this.myOracleCommand.Parameters.Clear(); for (int i = 0; i < myDbParameters.Length; i++) { this.myOracleCommand.Parameters.Add(myDbParameters[i]); } } OracleDataReader myOracleDataReader = this.myOracleCommand.ExecuteReader(); this.myOracleCommand.Parameters.Clear(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return myOracleDataReader; } #endregion public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 结果集流 public IDataReader ExecuteReader(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { return this.ExecuteReader(myCommandType, sqlQuery, this.GetParameters(names, values)); } #endregion public int ExecuteNonQuery(String sqlQuery)#region public int ExecuteNonQuery(String sqlQuery) /**//// /// 执行查询, SQL BUILDER 用了这个东西?参数需要保存, 不能丢失. /// /// sql查询 /// 影响行数 public int ExecuteNonQuery(String sqlQuery) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleCommand.CommandType = CommandType.Text; this.myOracleCommand.CommandText = sqlQuery; if (this.InTransaction) { this.myOracleCommand.Transaction = this.myOracleTransaction; } int returnValue = this.myOracleCommand.ExecuteNonQuery(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return returnValue; } #endregion public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters);#region public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters); /**//// /// 执行查询 /// /// sql查询 /// 参数集 /// 影响行数 public int ExecuteNonQuery(String sqlQuery, DbParameter[] myDbParameters) { return this.ExecuteNonQuery(CommandType.Text, sqlQuery, myDbParameters); } #endregion public int ExecuteNonQuery(String sqlQuery, String name, Object value)#region public int ExecuteNonQuery(String sqlQuery, String name, Object value) /**//// /// 执行查询 /// /// 数据集 /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteNonQuery(String sqlQuery, String name, Object value) { String[] names = new String[1] { name }; Object[] values = new Object[1] { value }; return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values); } #endregion public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteNonQuery(String sqlQuery, String[] names, Object[] values) { return this.ExecuteNonQuery(CommandType.Text, sqlQuery, names, values); } #endregion public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数集 /// 影响行数 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { OracleTransaction myOracleTransaction = null; if (this.InTransaction) { myOracleTransaction = this.myOracleTransaction; } return this.ExecuteNonQuery(myOracleTransaction, myCommandType, sqlQuery, myDbParameters); } #endregion public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { OracleTransaction myOracleTransaction = null; if (this.InTransaction) { myOracleTransaction = this.myOracleTransaction; } return this.ExecuteNonQuery(myOracleTransaction, myCommandType, sqlQuery, names, values); } #endregion public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// 数据库事务 /// 命令分类 /// sql查询 /// 参数集 /// 影响行数 public int ExecuteNonQuery(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleCommand = new OracleCommand(sqlQuery, this.myOracleConnection); this.myOracleCommand.CommandType = myCommandType; if (myOleDbTransaction != null) { this.myOracleCommand.Transaction = (OracleTransaction)myOleDbTransaction; } if (myDbParameters != null) { this.myOracleCommand.Parameters.Clear(); for (int i = 0; i < myDbParameters.Length; i++) { this.myOracleCommand.Parameters.Add(myDbParameters[i]); } } int returnValue = this.myOracleCommand.ExecuteNonQuery(); this.myOracleCommand.Parameters.Clear(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return returnValue; } #endregion 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) /**//// /// 执行查询 /// /// 数据库事务 /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteNonQuery(IDbTransaction myOracleTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { return this.ExecuteNonQuery(myOracleTransaction, myCommandType, sqlQuery, this.GetParameters(names, values)); } #endregion public Object ExecuteScalar(String sqlQuery)#region public Object ExecuteScalar(String sqlQuery) /**//// /// 执行查询 /// /// sql查询 /// object public Object ExecuteScalar(String sqlQuery) { return this.ExecuteScalar(CommandType.Text, sqlQuery, null, null); } #endregion public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// sql查询 /// 参数集 /// Object public Object ExecuteScalar(String sqlQuery, DbParameter[] myDbParameters) { return this.ExecuteScalar(CommandType.Text, sqlQuery, myDbParameters); } #endregion public Object ExecuteScalar(String sqlQuery, String name, Object value)#region public Object ExecuteScalar(String sqlQuery, String name, Object value) /**//// /// 执行查询 /// /// sql查询 /// 参数名 /// 参数值 /// Object public Object ExecuteScalar(DataSet myDataSet, String sqlQuery, String name, Object value) { String[] names = new String[1] { name }; Object[] values = new Object[1] { value }; return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values); } #endregion public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public Object ExecuteScalar(String sqlQuery, String[] names, Object[] values) { return this.ExecuteScalar(CommandType.Text, sqlQuery, names, values); } #endregion public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数集 /// Object public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { OracleTransaction myOracleTransaction = null; if (this.InTransaction) { myOracleTransaction = this.myOracleTransaction; } return this.ExecuteScalar(myOracleTransaction, myCommandType, sqlQuery, myDbParameters); } #endregion public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values)#region public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) /**//// /// 执行查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 影响行数 public Object ExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { OracleTransaction myOracleTransaction = null; if (this.InTransaction) { myOracleTransaction = this.myOracleTransaction; } return this.ExecuteScalar(myOracleTransaction, myCommandType, sqlQuery, names, values); } #endregion public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 执行查询 /// /// 数据库事务 /// 命令分类 /// sql查询 /// 参数集 /// Object public Object ExecuteScalar(IDbTransaction myOleDbTransaction, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleCommand = new OracleCommand(sqlQuery, this.myOracleConnection); this.myOracleCommand.CommandType = myCommandType; if (myOleDbTransaction != null) { this.myOracleCommand.Transaction = (OracleTransaction)myOleDbTransaction; } if (myDbParameters != null) { this.myOracleCommand.Parameters.Clear(); for (int i = 0; i < myDbParameters.Length; i++) { this.myOracleCommand.Parameters.Add(myDbParameters[i]); } } Object returnValue = this.myOracleCommand.ExecuteScalar(); this.myOracleCommand.Parameters.Clear(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return returnValue; } #endregion 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) /**//// /// 执行查询 /// /// 数据库事务 /// 命令分类 /// sql查询 /// /// /// 影响行数 public Object ExecuteScalar(IDbTransaction myOracleTransaction, CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { return this.ExecuteScalar(myOracleTransaction, myCommandType, sqlQuery, this.GetParameters(names, values)); } #endregion public DataTable Fill(DataTable myDataTable, String sqlQuery)#region public DataTable Fill(DataTable myDataTable, String sqlQuery) /**//// /// 填充数据表 /// /// 目标数据表 /// 查询 /// 数据表 public DataTable Fill(DataTable myDataTable, String sqlQuery) { return this.Fill(myDataTable, CommandType.Text, sqlQuery, null, null); } #endregion public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 填充数据表 /// /// 目标数据表 /// sql查询 /// 参数集 /// 数据表 public DataTable Fill(DataTable myDataTable, String sqlQuery, DbParameter[] myDbParameters) { return this.Fill(myDataTable, CommandType.Text, sqlQuery, myDbParameters); } #endregion public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value) /**//// /// 填充数据表 /// /// 目标数据表 /// sql查询 /// 参数名 /// 参数值 /// 数据表 public DataTable Fill(DataTable myDataTable, String sqlQuery, String name, Object value) { String[] names = new String[1] { name }; Object[] values = new Object[1] { value }; return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values); } #endregion public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values)#region public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values) /**//// /// 填充数据表 /// /// 目标数据表 /// sql查询 /// 参数名 /// 参数值 /// 数据表 public DataTable Fill(DataTable myDataTable, String sqlQuery, String[] names, Object[] values) { return this.Fill(myDataTable, CommandType.Text, sqlQuery, names, values); } #endregion public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters)#region public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) /**//// /// 填充数据表 /// /// 目标数据表 /// 命令分类 /// sql查询 /// 参数集 /// 数据表 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, DbParameter[] myDbParameters) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleDataAdapter = new OracleDataAdapter(sqlQuery, this.myOracleConnection); this.myOracleDataAdapter.SelectCommand.CommandType = myCommandType; if (this.InTransaction) { this.myOracleDataAdapter.SelectCommand.Transaction = this.myOracleTransaction; } if (myDbParameters != null) { this.myOracleCommand.Parameters.Clear(); for (int i = 0; i < myDbParameters.Length; i++) { this.myOracleDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]); } } this.myOracleDataAdapter.Fill(myDataTable); this.myOracleDataAdapter.SelectCommand.Parameters.Clear(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return myDataTable; } #endregion 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) /**//// /// 填充数据表 /// /// 目标数据表 /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 数据表 public DataTable Fill(DataTable myDataTable, CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { return this.Fill(myDataTable, myCommandType, sqlQuery, this.GetParameters(names, values)); } #endregion public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName) /**//// /// 填充数据集 /// /// 目标数据集 /// 查询 /// 填充表 /// 数据集 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName) { return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, null, null); } #endregion public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters)#region public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters) /**//// /// 填充数据集 /// /// 数据集 /// sql查询 /// 填充表 /// 参数集 /// 数据集 public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, DbParameter[] myDbParameters) { return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, myDbParameters); } #endregion 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) /**//// /// 填充数据集 /// /// 数据集 /// sql查询 /// 填充表 /// 参数名 /// 参数值 /// DataSet public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String name, Object value) { String[] names = new String[1] { name }; Object[] values = new Object[1] { value }; return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values); } #endregion 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) /**//// /// 填充数据集 /// /// 数据集 /// sql查询 /// 填充表 /// 参数名 /// 参数值 /// DataSet public DataSet Fill(DataSet myDataSet, String sqlQuery, String tableName, String[] names, Object[] values) { return this.Fill(myDataSet, CommandType.Text, sqlQuery, tableName, names, values); } #endregion 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) /**//// /// 填充数据集 /// /// 数据集 /// 命令分类 /// sql查询 /// 填充表 /// 参数集 /// 数据集 public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, DbParameter[] myDbParameters) { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif this.myOracleDataAdapter = new OracleDataAdapter(sqlQuery, this.myOracleConnection); this.myOracleDataAdapter.SelectCommand.CommandType = myCommandType; if (this.InTransaction) { this.myOracleDataAdapter.SelectCommand.Transaction = this.myOracleTransaction; } if (myDbParameters != null) { this.myOracleCommand.Parameters.Clear(); for (int i = 0; i < myDbParameters.Length; i++) { this.myOracleDataAdapter.SelectCommand.Parameters.Add(myDbParameters[i]); } } this.myOracleDataAdapter.Fill(myDataSet, tableName); this.myOracleDataAdapter.SelectCommand.Parameters.Clear(); // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif // 写入日志 this.WriteLog(sqlQuery); return myDataSet; } #endregion 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) /**//// /// 填充数据集 /// /// 数据集 /// 命令分类 /// sql查询 /// 填充表 /// 参数名 /// 参数值 /// DataSet public DataSet Fill(DataSet myDataSet, CommandType myCommandType, String sqlQuery, String tableName, String[] names, Object[] values) { return this.Fill(myDataSet, myCommandType, sqlQuery, tableName, this.GetParameters(names, values)); } #endregion public int ExecuteProcedure(String procedureName)#region public int ExecuteProcedure(String procedureName) /**//// /// 执行数据库查询 /// /// 存储过程 /// int public int ExecuteProcedure(String procedureName) { return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, null, null); } #endregion public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters)#region public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters) /**//// /// 执行存储过程 /// /// 存储过程名 /// 参数集 /// 影响行数 public int ExecuteProcedure(String procedureName, DbParameter[] myDbParameters) { return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, myDbParameters); } #endregion public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程#region public int ExecuteProcedure(String procedureName, String name, String value) 执行存储过程 /**//// /// 执行存储过程 /// /// 存储过程名 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteProcedure(String procedureName, String name, String value) { String[] names = new String[1]; Object[] values = new Object[1]; int returnValue = 0; names[0] = name; values[0] = value; returnValue = this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values); return returnValue; } #endregion public int ExecuteProcedure(String procedureName, String[] names, Object[] values)#region public int ExecuteProcedure(String procedureName, String[] names, Object[] values) /**//// /// 执行数据库脚本 /// /// 存储过程 /// 参数名 /// 参数值 /// 影响行数 public int ExecuteProcedure(String procedureName, String[] names, Object[] values) { return this.ExecuteNonQuery(CommandType.StoredProcedure, procedureName, names, values); } #endregion public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters)#region public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters) /**//// /// 执行数据库脚本 /// /// 数据集 /// 存储过程 /// 填充表 /// 参数集 /// 数据集 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, DbParameter[] myDbParameters) { return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, myDbParameters); } #endregion 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) /**//// /// 执行数据库脚本 /// /// 数据集 /// 存储过程 /// 填充表 /// 参数名 /// 参数值 /// 影响行数 public DataSet ExecuteProcedureForDataSet(DataSet myDataSet, String procedureName, String tableName, String[] names, Object[] values) { return this.Fill(myDataSet, CommandType.StoredProcedure, procedureName, tableName, names, values); } #endregion public IDbTransaction BeginTransaction()#region public IDbTransaction BeginTransaction() /**//// /// 事务开始 /// /// 事务 public IDbTransaction BeginTransaction() { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif if (!this.InTransaction) { this.InTransaction = true; this.myOracleTransaction = this.myOracleConnection.BeginTransaction(); this.myOracleCommand.Transaction = this.myOracleTransaction; this.myOracleDataAdapter.SelectCommand.Transaction = this.myOracleTransaction; } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif return this.myOracleTransaction; } #endregion public void CommitTransaction()#region public void CommitTransaction() /**//// /// 递交事务 /// public void CommitTransaction() { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif if (this.InTransaction) { // 事务已经完成了,一定要更新标志信息 this.InTransaction = false; this.myOracleTransaction.Commit(); } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif } #endregion public void RollbackTransaction()#region public void RollbackTransaction() /**//// /// 回滚事务 /// public void RollbackTransaction() { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif if (this.InTransaction) { this.InTransaction = false; this.myOracleTransaction.Rollback(); } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif } #endregion public delegate int Asyncdelegate(); /**//// /// 异步调用的挂接代理 /// /// 回调 private void CallbackMethod(IAsyncResult myIAsyncResult) { Asyncdelegate myAsyncdelegate = (Asyncdelegate)myIAsyncResult.AsyncState; myAsyncdelegate.EndInvoke(myIAsyncResult); } #endregion // 定义与方法同签名的委托 private delegate int DelegateExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values); /**//// /// 异步调用数据库查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 影响行数 private int AsyncExecuteNonQuery(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { int returnValue = 0; this.Open(); returnValue = this.ExecuteNonQuery(myCommandType, sqlQuery, names, values); this.Close(); return returnValue; } #endregion /**//// /// 异步调用数据库查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 public void ExecuteNonQueryAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod); DelegateExecuteNonQuery myDelegateExecuteNonQuery = new DelegateExecuteNonQuery(AsyncExecuteNonQuery); myDelegateExecuteNonQuery.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null); } #endregion // 定义与方法同签名的委托 private delegate Object DelegateExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values); /**//// /// 异步调用数据库查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 /// 对象 private Object AsyncExecuteScalar(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { Object returnValue = null; this.Open(); returnValue = this.ExecuteScalar(myCommandType, sqlQuery, names, values); this.Close(); return returnValue; } #endregion /**//// /// 异步调用数据库查询 /// /// 命令分类 /// sql查询 /// 参数名 /// 参数值 public void ExecuteScalarAsync(CommandType myCommandType, String sqlQuery, String[] names, Object[] values) { AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod); DelegateExecuteScalar myDelegateExecuteScalar = new DelegateExecuteScalar(AsyncExecuteScalar); myDelegateExecuteScalar.BeginInvoke(myCommandType, sqlQuery, names, values, myAsyncCallback, null); } #endregion // 定义与方法同签名的委托 private delegate int DelegateExecuteProcedure(String procedureName, String[] names, Object[] values); /**//// /// 异步调用数据库查询 /// /// 存储过程 /// 参数名 /// 参数值 /// 影响行数 private int AsyncExecuteProcedure(String procedureName, String[] names, Object[] values) { int returnValue = 0; this.Open(); returnValue = this.ExecuteProcedure(procedureName, names, values); this.Close(); return returnValue; } #endregion /**//// /// 异步调用数据库查询 /// /// 存储过程 /// 参数名 /// 参数值 public void ExecuteProcedureAsync(String procedureName, String[] names, Object[] values) { AsyncCallback myAsyncCallback = new AsyncCallback(CallbackMethod); DelegateExecuteProcedure myDelegateExecuteProcedure = new DelegateExecuteProcedure(AsyncExecuteProcedure); myDelegateExecuteProcedure.BeginInvoke(procedureName, names, values, myAsyncCallback, null); } #endregion /**//// /// 写入SQL查询语日志 /// /// SQL查询语 public void WriteLog(String sqlQuery) { this.WriteLog(DateTime.Now.ToString(BaseSystemInfo.DateFormat) + "_" + this.FileName, sqlQuery); // 将调试信息输出到屏幕上 #if DEBUG System.Console.WriteLine(sqlQuery); #endif } #endregion /**//// /// 写入SQL查询语句 /// /// 文件名 /// 异常 public void WriteLog(String fileName, String sqlQuery) { String returnValue = String.Empty; // 系统里应该可以配置是否记录异常现象 if (!BaseSystemInfo.LogSQL) { return; } // 将异常信息写入本地文件中 String logDirectory = BaseSystemInfo.StartupPath + @"\\Log\\Query"; if (!System.IO.Directory.Exists(logDirectory)) { System.IO.Directory.CreateDirectory(logDirectory); } String writerFileName = logDirectory + "\\" + fileName; if (!File.Exists(fileName)) { FileStream myFileStream = new FileStream(writerFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); myFileStream.Close(); } StreamWriter myStreamWriter = new StreamWriter(writerFileName, true, Encoding.Default); myStreamWriter.WriteLine(DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " " + sqlQuery); myStreamWriter.Close(); } #endregion public void Close()#region public void Close() /**//// /// 关闭数据库连接 /// public void Close() { // 写入调试信息 #if (DEBUG) int milliStart = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif if (this.myOracleConnection != null) { this.myOracleConnection.Close(); this.myOracleConnection.Dispose(); } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name); #endif } #endregion private void Dispose(bool disposing)#region private void Dispose(bool disposing) /**//// /// 卸载 /// /// 卸载 private void Dispose(bool disposing) { if (disposing) { this.myOracleCommand.Dispose(); this.myOracleDataAdapter.Dispose(); this.myOracleTransaction.Dispose(); this.myOracleConnection.Dispose(); } } #endregion public void Dispose()#region public void Dispose() /**//// /// 卸载 /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion } }

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 5 金币 [ 分享文档获得金币 ] 0 人已下载

下载文档