using System; using System.Data; using System.Data.OracleClient; using System.Collections; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Threading; namespace STMes { /// /// DBManager 的摘要说明。 /// public class DBManager : IDisposable { /// /// 初始化 /// public DBManager() { InitDBManager("MesDB", "A"); } /// /// 初始化 /// /// 数据库名称 public DBManager(string dbName) { InitDBManager(dbName, "A"); } /// /// 初始化 /// /// 数据库名称 /// 优先级 public DBManager(string dbName, string priority) { InitDBManager(dbName, priority); } public void Dispose() { } /// /// 获取上次执行时最后一个错误信息,无错误则返回空字符串 /// /// 错误信息 public string GetLastError() { return _errMsg; } /// /// 判断DBManager是否有效 /// /// 是否有效 public bool IsValid() { return _valid; } /// /// 获取数据库类型,用字符串"SQLServer","Oracle", "OleDb"分别表示不同类型的数据库 /// /// 数据库类型 public string GetDbType() { string dbType = ""; try { dbType = _dbProxy.GetDbType(_dbName, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return dbType; } //获取数据库类型,用字符串"SQLServer","Oracle", "OleDb"分别表示不同类型的数据库 public string GetDbType(out string err) { string dbType = ""; err = ""; try { dbType = _dbProxy.GetDbType(_dbName, out err); _errMsg = err; } catch (Exception ex) { _valid = false; _errMsg = err = ex.Message; } return dbType; } #region add 马亮 2011-10-21 /// /// 分页返回查询数据[只支持Oracle数据库] /// /// /// /// /// /// /// /// public DataSet ExecuteDataPageQuery(string sql, int pageIndex, int pageSize, out int recordCount, out int pageCount, out string err) { DataPage dpage = new DataPage(_dbProxy, _dbName, _priority); dpage.InitDataPage(sql, pageIndex, pageSize); _valid = dpage._valid; _errMsg = dpage._errMsg; err = _errMsg; recordCount = dpage.RecordCount; pageCount = dpage.PageCount; return dpage.Result; } /// /// 分页返回查询数据[只支持Oracle数据库] /// /// /// /// /// /// /// /// /// /// public DataSet ExecuteDataPageQuery(string sql, int pageIndex, int pageSize, IDataParameter[] Params, object[] Values, out int recordCount, out int pageCount, out string err) { DataPage dpage = new DataPage(_dbProxy, _dbName, _priority); dpage.InitDataPage(sql, pageIndex, pageSize, Params, Values); _valid = dpage._valid; _errMsg = dpage._errMsg; err = _errMsg; recordCount = dpage.RecordCount; pageCount = dpage.PageCount; return dpage.Result; } #endregion //执行SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, Guid guid) { DataSet ds = null; try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql) { DataSet ds = null; try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, out string err) { err = ""; DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, out string err, bool ifDBLink) { err = ""; DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err, ifDBLink); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, Guid guid) { DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType) { DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType, out string err) { err = ""; DataSet ds = new DataSet(); try { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, Guid guid) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ArrayList OutputValues = null; ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ArrayList OutputValues = null; ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ArrayList OutputValues = null; ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ArrayList OutputValues = null; ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, Guid guid) { DataSet ds = new DataSet(); ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values) { DataSet ds = new DataSet(); ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues) { DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, out string err) { err = ""; DataSet ds = new DataSet(); ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行带参数的SQL语句,返回DataSet public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } public DataSet ExecuteQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, out string err) { err = ""; DataSet ds = new DataSet(); try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { ds = _dbProxy.ExecuteQuery(_dbName, _priority, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return ds; } //执行SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, Guid guid) { int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql) { int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, Guid guid, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //执行SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, Guid guid) { int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType) { int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, Guid guid, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, Guid guid) { int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values) { int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid) { int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues) { int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, Guid guid, out string err) { err = ""; int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, out string err) { err = ""; int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid, out string err) { err = ""; int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, out string err) { err = ""; int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, CommandType.Text, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, Guid guid) { int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values) { int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid) { int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues) { int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out _errMsg); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, Guid guid, out string err) { err = ""; int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, out string err) { err = ""; int lines = -1; ArrayList OutputValues = null; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; } lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //执行带参数的SQL语句,返回受影响的行数 public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, Guid guid, out string err) { err = ""; int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; int[] Sizes = new int[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; if (this.GetDbType().ToUpper() == "ORACLE") DbTypes[i] = (DbType)(((OracleParameter)Params[i]).OracleType); else DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; if (this.GetDbType().ToUpper() == "ORACLE") Sizes[i] = ((OracleParameter)Params[i]).Size; } if (this.GetDbType().ToUpper() == "ORACLE") lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Sizes, Values, ref OutputValues, out err); else lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, guid, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery(string Sql, CommandType cmdType, IDataParameter[] Params, object[] Values, ref ArrayList OutputValues, out string err) { err = ""; int lines = -1; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; ParameterDirection[] Directions = new ParameterDirection[Params.Length]; bool[] IsNullables = new bool[Params.Length]; string[] SourceColumns = new string[Params.Length]; DataRowVersion[] SourceVersions = new DataRowVersion[Params.Length]; int[] Sizes = new int[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; if (this.GetDbType().ToUpper() == "ORACLE") DbTypes[i] = (DbType)(((OracleParameter)Params[i]).OracleType); else DbTypes[i] = Params[i].DbType; Directions[i] = Params[i].Direction; IsNullables[i] = Params[i].IsNullable; SourceColumns[i] = Params[i].SourceColumn; SourceVersions[i] = Params[i].SourceVersion; if (this.GetDbType().ToUpper() == "ORACLE") Sizes[i] = ((OracleParameter)Params[i]).Size; } if (this.GetDbType().ToUpper() == "ORACLE") lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Sizes, Values, ref OutputValues, out err); else lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, ParameterNames, DbTypes, Directions, IsNullables, SourceColumns, SourceVersions, Values, ref OutputValues, out err); } else { lines = _dbProxy.ExecuteNonQuery(_dbName, _priority, Sql, cmdType, null, null, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //不通过DBServer时使用 public int ExecuteNonQuery_NoDBSever(string Sql, CommandType cmdType, IDataParameter[] Params, Guid guid, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery_NoDBSever(_dbName, _priority, guid, Sql, cmdType, Params, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } public int ExecuteNonQuery_NoDBSever(string Sql, CommandType cmdType, IDataParameter[] Params, out string err) { err = ""; int lines = -1; try { lines = _dbProxy.ExecuteNonQuery_NoDBSever(_dbName, _priority, Sql, cmdType, Params, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return lines; } //更新 public bool UpdateTable(DataTable dt, string Sql, Guid guid) { bool result = false; try { result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, null, null, dt, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql) { bool result = false; try { result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, null, null, dt, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, Guid guid, out string err) { err = ""; bool result = false; try { result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, null, null, dt, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, out string err) { err = ""; bool result = false; try { result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, null, null, dt, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, IDataParameter[] Params, object[] Values, Guid guid) { bool result = false; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; } result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Values, dt, out _errMsg); } else { result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, null, null, null, dt, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, IDataParameter[] Params, object[] Values) { bool result = false; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; } result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Values, dt, out _errMsg); } else { result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, null, null, null, dt, out _errMsg); } } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, IDataParameter[] Params, object[] Values, Guid guid, out string err) { bool result = false; err = ""; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; } result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, ParameterNames, DbTypes, Values, dt, out err); } else { result = _dbProxy.UpdateTable(_dbName, _priority, guid, Sql, CommandType.Text, null, null, null, dt, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; _errMsg = err = ex.Message; } return result; } public bool UpdateTable(DataTable dt, string Sql, IDataParameter[] Params, object[] Values, out string err) { bool result = false; err = ""; try { //给所有的参数赋值 if (Params != null && Values != null) { string[] ParameterNames = new string[Params.Length]; DbType[] DbTypes = new DbType[Params.Length]; for (int i = 0; i < Params.Length; i++) { ParameterNames[i] = Params[i].ParameterName; DbTypes[i] = Params[i].DbType; } result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, ParameterNames, DbTypes, Values, dt, out err); } else { result = _dbProxy.UpdateTable(_dbName, _priority, Sql, CommandType.Text, null, null, null, dt, out err); } _errMsg = err; } catch (Exception ex) { _valid = false; _errMsg = err = ex.Message; } return result; } public Guid BeginTransaction(out string err) { return BeginTransaction("", out err); } //开始处理事物,返回结果表示是否成功 public Guid BeginTransaction(string methodName, out string err) { err = ""; Guid guid = Guid.NewGuid(); try { guid = _dbProxy.BeginTransaction(methodName, _dbName, _priority, _dbManagerID, 20.00, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return guid; } public Guid BeginTransaction(double minutes, out string err) { return BeginTransaction("", minutes, out err); } //开始处理事物,指定事务最长执行时间, 返回结果表示是否成功 public Guid BeginTransaction(string methodName, double minutes, out string err) { err = ""; Guid guid = Guid.NewGuid(); try { guid = _dbProxy.BeginTransaction(methodName, _dbName, _priority, _dbManagerID, minutes, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return guid; } //提交当前事物,返回结果表示是否成功 public bool Commit(Guid guid) { bool bSuccess = false; try { bSuccess = _dbProxy.Commit(_dbName, _priority, guid, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return bSuccess; } //提交当前事物,返回结果表示是否成功 public bool Commit(Guid guid, out string err) { err = ""; bool bSuccess = false; try { bSuccess = _dbProxy.Commit(_dbName, _priority, guid, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return bSuccess; } //回滚当前事务 public bool Rollback(Guid guid) { bool bSuccess = false; try { bSuccess = _dbProxy.Rollback(_dbName, _priority, guid, out _errMsg); } catch (Exception ex) { _valid = false; _errMsg = ex.Message; } return bSuccess; } //回滚当前事务 public bool Rollback(Guid guid, out string err) { err = ""; bool bSuccess = false; try { bSuccess = _dbProxy.Rollback(_dbName, _priority, guid, out err); _errMsg = err; } catch (Exception ex) { _valid = false; err = _errMsg = ex.Message; } return bSuccess; } //////////////////////////////////////////////////////////////////////////////////// ///私有函数 /////////////////////////////////////////////////////////////////////////////////// //初始化DBManager private void InitDBManager(string name, string priority) { //保存数据库信息 _dbName = name; _priority = priority; _errMsg = ""; _valid = true; //如果是第一次创建DBManager对象,则需先读取远程处理配置文件 if (_firstCreate) { try { //读取远程处理配置文件clientConfig.cfg //RemotingConfiguration.Configure("clientConfig.cfg"); //生成DBProxy对象 _dbProxy = new DBProxy(); _firstCreate = false; } catch (Exception ex) { _errMsg = ex.Message; _valid = false; throw ex; } } try { //获取由DBProxy为DBManager对象分配的ID _dbManagerID = _dbProxy.GetDBManagerID(); //设置数据库信息 _dbProxy.SetDbInfo(_dbManagerID, _dbName, _priority); } catch (Exception ex) { _errMsg = ex.Message; _valid = false; } } ////////////////////////////////////////////////////////////////////////////////// ///私有数据成员 ////////////////////////////////////////////////////////////////////////////////// public static DBProxy _dbProxy; private long _dbManagerID;//DBProxy为DBManager对象分配的ID private string _dbName;//数据库名称 private string _priority;//数据库访问优先级 private string _errMsg;//最后一个错误信息 private bool _valid;//DBManager有效标志,每次调用DBProxy函数时设置 private static bool _firstCreate = true; ////////////////////////////////////////////////////////////////////////////////// ///公共属性 ////////////////////////////////////////////////////////////////////////////////// //数据库名称 public string DBName { get { return _dbName; } set { _dbName = value; } } //数据库访问优先级 public string Priority { get { return _priority; } set { _priority = value; } } } }