//using System; //using System.Collections; //using System.Configuration; //using System.Data; //using System.Globalization; //using System.Text; //using System.Web; //using Oracle.DataAccess.Client; //namespace ETD.Data //{ // /// // /// SQL Server 数据库处理类 // /// // public class ORACLEDBHandler : IDBHandlerble, IDisposable // { // private Hashtable links; // /// // /// SqlCommand对象实例 // /// // private OracleCommand oracleCommand; // /// // /// 声明sql 的数据库连接对象 // /// // private OracleConnection oracleConnection; // /// // /// 取得整个系统的数据库都存放在一台服务器的数据库连接字符串 // /// // private static string sqlDefaultConnectionString = ConfigurationManager.AppSettings["DefaultConnectionString"].Trim(); // /// // /// 模块使用的字符串变量 // /// // private static string sqlModuleConnectionString = string.Empty; // /// // /// 声明事务对象 // /// // protected OracleTransaction oracleTransaction; // /// // /// 整个系统使用同一个数据库连接,通过web.config中DefultConnectionString中的连接字符串来连接数据库 // /// // /// 取得web.config或者app.config中AppSetting中sql_default中的连接字符串 // public ORACLEDBHandler() // { // this.links = null; // this.GetLinkObject(); // string ConnectionString = this.GetDataLink(""); // if (ConfigurationManager.AppSettings["IsEncryptString"].Trim() == "1") // { // ConnectionString = new Security().Uncrypt(ConnectionString, ""); // } // this.oracleConnection = new OracleConnection(ConnectionString); // this.oracleCommand = this.oracleConnection.CreateCommand(); // } // /// // /// 不同模块使用不同的数据库连接,通过web.config中DefultConnectionString中的连接字符串来连接数据库 // /// // /// 模块关键字 // public ORACLEDBHandler(string module) // { // string ConnectionString; // Security security; // this.links = null; // this.GetLinkObject(); // string isSame = "0"; // if (this.links != null) // { // isSame = this.links["isSame"].ToString(); // } // else // { // isSame = ConfigurationManager.AppSettings["IsSameDB"]; // } // if (isSame.Trim() == "1") // { // ConnectionString = this.GetDataLink(""); // if (ConfigurationManager.AppSettings["IsEncryptString"].Trim() == "1") // { // security = new Security(); // ConnectionString = security.Uncrypt(ConnectionString, ""); // } // this.oracleConnection = new OracleConnection(ConnectionString); // } // else if (module == string.Empty) // { // ConnectionString = this.GetDataLink(""); // if (ConfigurationManager.AppSettings["IsEncryptString"].Trim() == "1") // { // security = new Security(); // ConnectionString = security.Uncrypt(ConnectionString, ""); // } // this.oracleConnection = new OracleConnection(ConnectionString); // } // else // { // sqlModuleConnectionString = this.GetDataLink(module); // if (ConfigurationManager.AppSettings["IsEncryptString"].Trim() == "1") // { // sqlModuleConnectionString = new Security().Uncrypt(sqlModuleConnectionString, ""); // } // this.oracleConnection = new OracleConnection(sqlModuleConnectionString); // } // this.oracleCommand = this.oracleConnection.CreateCommand(); // } // /// // /// 添加参数 // /// // /// 参数名称 // /// 参数类型 // /// 参数方向 // public void AddParameter(string paramName, DbType paramType, ParameterDirection direction) // { // OracleParameter splParameter = new OracleParameter(); // splParameter.ParameterName = paramName; // splParameter.DbType = paramType; // splParameter.Direction = direction; // this.oracleCommand.Parameters.Add(splParameter); // } // /// // /// 重载-添加参数 // /// // /// 参数名称 // /// 参数类型 // /// 参数方向 // /// 参数值 // public void AddParameter(string paramName, DbType paramType, ParameterDirection direction, object pValue) // { // this.AddParameter(paramName, paramType, direction); // this.ModifyParameter(paramName, pValue); // } // /// // /// 添加有长度的参数 // /// // /// 参数名称 // /// 参数类型 // /// 参数长度 // /// 参数方向 // public void AddParameter(string paramName, DbType paramType, int paramSize, ParameterDirection direction) // { // OracleParameter oracleParameter = new OracleParameter(); // oracleParameter.ParameterName = paramName; // oracleParameter.DbType = paramType; // oracleParameter.Size = paramSize; // oracleParameter.Direction = direction; // this.oracleCommand.Parameters.Add(oracleParameter); // } // /// // /// 重载-添加有长度的参数 // /// // /// 参数名称 // /// 参数类型 // /// 参数长度 // /// 参数方向 // /// 参数值 // public void AddParameter(string paramName, DbType paramType, int paramSize, ParameterDirection direction, object pValue) // { // this.AddParameter(paramName, paramType, paramSize, direction); // this.ModifyParameter(paramName, pValue); // } // /// // /// 启动事务处理 // /// // /// 返回执行结果状态码 // public void BeginTransaction() // { // this.ConnectionOpen(); // if (null == this.oracleTransaction) // { // this.oracleTransaction = this.oracleConnection.BeginTransaction(IsolationLevel.ReadCommitted); // } // //this.oracleCommand.Transaction= this.oracleTransaction; // } // /// // /// 提交事务处理 // /// // /// 返回执行结果状态码 // public void CommitTransaction() // { // try // { // this.oracleTransaction.Commit(); // } // finally // { // this.ConnectionClose(); // } // } // /// // /// 关闭数据库连接 // /// // public void ConnectionClose() // { // if (ConnectionState.Closed != this.oracleConnection.State) // { // this.oracleConnection.Close(); // this.oracleConnection.Dispose(); // } // } // /// // /// 打开数据库连接 // /// // public void ConnectionOpen() // { // if (ConnectionState.Closed == this.oracleConnection.State) // { // this.oracleConnection.Open(); // } // } // /// // /// 释放资源 // /// // public void Dispose() // { // if (this.oracleConnection != null) // { // this.oracleConnection.Dispose(); // } // if (this.oracleCommand != null) // { // this.oracleCommand.Dispose(); // } // if (this.oracleTransaction != null) // { // this.oracleTransaction.Dispose(); // } // } // /// // /// 返回数据适配器 // /// // /// 查询命令 // /// 返回执行结果 // public IDbDataAdapter ExecuteAdapter(string commandText) // { // return this.ExecuteAdapter(commandText, CommandType.Text); // } // /// // /// 重载-返回数据适配器(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 返回执行结果 // public IDbDataAdapter ExecuteAdapter(string commandText, CommandType commandType) // { // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // this.ConnectionOpen(); // return new OracleDataAdapter(this.oracleCommand); // } // /// // /// 返回数据集 // /// // /// 查询命令 // /// 返回执行结果 // public DataSet ExecuteDataSet(string commandText) // { // return this.ExecuteDataSet(commandText, CommandType.Text); // } // /// // /// 重载-返回数据集(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 返回执行结果 // public DataSet ExecuteDataSet(string commandText, CommandType commandType) // { // return this.ExecuteDataSet(commandText, commandType, ""); // } // /// // /// 重载-返回数据集(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 表名 // /// 返回执行结果 // public DataSet ExecuteDataSet(string commandText, CommandType commandType, string tableName) // { // return this.ExecuteDataSet("", commandText, commandType, ""); // } // /// // /// 重载-返回数据集(适应存储过程调用需求) // /// // /// DataSet 名称 // /// 查询命令 // /// 查询命令类型 // /// 表名 // /// 返回执行结果 // public DataSet ExecuteDataSet(string dataSetName, string commandText, CommandType commandType, string tableName) // { // DataSet dstResult = new DataSet(); // dstResult.Locale = CultureInfo.InvariantCulture; // if (dataSetName != string.Empty) // { // dstResult.DataSetName = dataSetName; // } // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // this.ConnectionOpen(); // if (tableName != string.Empty) // { // OracleDataAdapter oracleAdapter = new OracleDataAdapter(this.oracleCommand); // oracleAdapter.Fill(dstResult, tableName); // } // else // { // new OracleDataAdapter(this.oracleCommand).Fill(dstResult); // } // this.ConnectionClose(); // return dstResult; // } // /// // /// 返回数据表 // /// // /// 查询命令 // /// 返回执行结果 // public DataTable ExecuteDataTable(string commandText) // { // return this.ExecuteDataTable(commandText, CommandType.Text); // } // /// // /// 返回数据表 // /// // /// // /// // /// 返回执行结果 // public DataTable ExecuteDataTable(string commandText, bool isCloseConnection) // { // return this.ExecuteDataTable(commandText, CommandType.Text, "", isCloseConnection); // } // /// // /// 重载-返回数据表 // /// // /// 查询命令 // /// 查询命令类型 // /// 返回执行结果 // public DataTable ExecuteDataTable(string commandText, CommandType commandType) // { // return this.ExecuteDataTable(commandText, commandType, ""); // } // /// // /// 重载-返回数据表 // /// // /// 查询命令 // /// 查询命令类型 // /// 表名 // /// 返回执行结果 // public DataTable ExecuteDataTable(string commandText, CommandType commandType, string tableName) // { // return this.ExecuteDataTable(commandText, commandType, tableName, false); // } // /// // /// 重载-返回数据表 // /// // /// 查询命令 // /// 查询命令类型 // /// 表名 // /// 是否关闭数据库 // /// 返回执行结果 // public DataTable ExecuteDataTable(string commandText, CommandType commandType, string tableName, bool isCloseConnection) // { // DataTable dtblResult = new DataTable(); // dtblResult.Locale = CultureInfo.InvariantCulture; // if (tableName != string.Empty) // { // dtblResult.TableName = tableName; // } // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // this.ConnectionOpen(); // new OracleDataAdapter(this.oracleCommand).Fill(dtblResult); // if (isCloseConnection) // { // this.ConnectionClose(); // } // return dtblResult; // } // /// // /// 返回数据表(分页) // /// // /// 当前页 // /// 每页显示数 // /// 总记录数 // /// 需要查询的字段 // /// 排序字段,例如: id asc,name desc 不带order by // /// 查询表名称 // /// // public DataTable ExecuteDataTable(int page, int pageSize, ref int recordCount, string strFields, string strOrderBy, string strTableName) // { // recordCount = Convert.ToInt32(this.ExecuteScalar("select count(1) from " + strTableName + " as t")); // StringBuilder sb = new StringBuilder("select " + strFields + " from ("); // sb.Append(string.Concat(new object[] { " select row_number() over( order by ", strOrderBy, " ) as rowrumber,* from ", strTableName, " as a) as t where t.rowrumber between ", (page - 1) * pageSize, 1, " and ", page * pageSize, " order by t.rowrumber " })); // return this.ExecuteDataTable(sb.ToString()); // } // /// // /// 执行无返回类型数据查询(返回影响行数) // /// // /// 查询命令(SQL语句) // /// 返回执行结果影响行数 // public int ExecuteNonQuery(string commandText) // { // return this.ExecuteNonQuery(commandText, CommandType.Text); // } // /// // /// 执行无返回类型数据查询(返回影响行数) // /// // /// 查询命令(SQL语句) // /// 是否关闭数据连结,true: 关闭,false: 不关闭 // /// 返回执行结果影响行数 // public int ExecuteNonQuery(string commandText, bool isCloseConnection) // { // return this.ExecuteNonQuery(commandText, CommandType.Text, isCloseConnection); // } // /// // /// 重载-无返回类型数据查询(适应存储过程调用需求且返回影响行数) // /// // /// 查询命令 // /// 查询命令类型 // /// 返回执行结果影响行数 // public int ExecuteNonQuery(string commandText, CommandType commandType) // { // return this.ExecuteNonQuery(commandText, commandType, false); // } // /// // /// 重载-无返回类型数据查询(适应存储过程调用需求且返回影响行数) // /// // /// 查询命令 // /// 查询命令类型 // /// 是否关闭数据连结,true: 关闭,false: 不关闭 // /// 返回执行结果影响行数 // public int ExecuteNonQuery(string commandText, CommandType commandType, bool isCloseConnection) // { // int row; // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // try // { // this.ConnectionOpen(); // row = this.oracleCommand.ExecuteNonQuery(); // } // finally // { // if (isCloseConnection) // { // this.ConnectionClose(); // } // } // return row; // } // /// // /// 返回向前只读数据集查询 // /// // /// 查询命令 // /// 返回执行结果 // public IDataReader ExecuteReader(string commandText) // { // return this.ExecuteReader(commandText, CommandType.Text); // } // /// // /// 重载-返回向前只读数据集查询(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 返回执行结果 // public IDataReader ExecuteReader(string commandText, CommandType commandType) // { // return this.ExecuteReader(commandText, commandType, CommandBehavior.CloseConnection); // } // /// // /// 重载-返回向前只读数据集查询(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 提供对查询结果和查询对数据库的影响的说明 // /// 返回执行结果 // public IDataReader ExecuteReader(string commandText, CommandType commandType, CommandBehavior commandBehavior) // { // IDataReader row; // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // this.ConnectionOpen(); // try // { // row = this.oracleCommand.ExecuteReader(commandBehavior); // } // catch (OracleException ex) // { // this.ConnectionClose(); // throw ex; // } // return row; // } // public object ExecuteScalar(string commandText) // { // return this.ExecuteScalar(commandText, false); // } // /// // /// 返回第一行第一列结果的数据查询 // /// // /// 查询命令 // /// 是否关闭数据连结,true: 关闭,false: 不关闭 // /// 返回查询结果 // public object ExecuteScalar(string commandText, bool isCloseConnection) // { // return this.ExecuteScalar(commandText, CommandType.Text, isCloseConnection); // } // /// // /// 重载-返回第一行第一列结果的数据查询(适应存储过程调用需求) // /// // /// 查询命令 // /// 查询命令类型 // /// 是否关闭数据连结,true: 关闭,false: 不关闭 // /// 返回查询结果 // public object ExecuteScalar(string commandText, CommandType commandType, bool isCloseConnection) // { // object row; // this.oracleCommand.CommandText = commandText; // this.oracleCommand.CommandType = commandType; // this.ConnectionOpen(); // try // { // row = this.oracleCommand.ExecuteScalar(); // } // finally // { // if (isCloseConnection) // { // this.ConnectionClose(); // } // } // return row; // } // /// // /// 获得数据库连接字符串 // /// // /// 模块名称 // /// // public string GetDataLink(string ModuleName) // { // if (this.links != null) // { // if (ModuleName == string.Empty) // { // ModuleName = "default"; // } // return this.links[ModuleName].ToString(); // } // if (ModuleName == string.Empty) // { // return sqlDefaultConnectionString; // } // return ConfigurationManager.AppSettings[ModuleName + "ConnectionString"].Trim(); // } // /// // /// // /// // private void GetLinkObject() // { // try // { // if (HttpContext.Current.Session["uLinks"] != null) // { // this.links = HttpContext.Current.Session["uLinks"] as Hashtable; // if (this.links.Count == 0) // { // this.links = null; // } // } // } // catch // { // } // } // /// // /// 提取参数值 // /// // /// 参数名称 // /// 返回执行结果状态码 // public object GetParameter(string paramName) // { // if (this.oracleCommand.Parameters.Contains(paramName)) // { // return this.oracleCommand.Parameters[paramName].Value; // } // return null; // } // /// // /// 将DataTable添加到DataSet中 // /// // /// DataSet对象 // /// 表名数组 // public void LoadDataSet(DataSet dataSet, string[] tableNames) // { // for (int i = 0; i < tableNames.Length; i++) // { // this.LoadDataSet(dataSet, tableNames[i]); // } // } // /// // /// 将DataTable添加到DataSet中 // /// // /// DataSet对象 // /// 表名 // public void LoadDataSet(DataSet dataSet, string tableName) // { // dataSet.Tables.Add(tableName); // } // /// // /// 修改参数值 // /// // /// 参数名称 // /// 参数值 // public void ModifyParameter(string paramName, object pValue) // { // if ((this.oracleCommand.Parameters[paramName].OracleDbType == OracleDbType.Varchar2) && (pValue.GetType() == typeof(sbyte))) // { // pValue = new Guid(pValue.ToString()); // } // if (-1 != this.oracleCommand.Parameters.IndexOf(paramName)) // { // this.oracleCommand.Parameters[paramName].Value = pValue; // } // } // /// // /// 移除所有的参数 // /// // public void RemoveAllParameters() // { // this.oracleCommand.Parameters.Clear(); // } // /// // /// 移除参数 // /// // /// 参数名称 // public void RemoveParameter(string paramName) // { // this.oracleCommand.Parameters.RemoveAt(paramName); // } // /// // /// 回滚事务处理 // /// // /// 返回执行结果状态码 // public void RollbackTransaction() // { // try // { // this.oracleTransaction.Rollback(); // } // finally // { // this.ConnectionClose(); // } // } // } //}