62,046
社区成员
发帖
与我相关
我的任务
分享
public void Dispose()
{
if (this.DBConnection.State != ConnectionState.Closed)
{
this.DBConnection.Dispose();
}
GC.Collect();
}
internal int ExecuteNonQuery(string commandText)
{
int num;
try
{
num = this.CreateCommand(commandText).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQuery(string commandText, MySqlParameter[] parameters)
{
int num;
try
{
num = this.CreateCommand(commandText, parameters).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryProcedure(string commandText)
{
int num;
try
{
num = this.CreateCommand(commandText, CommandType.StoredProcedure).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryProcedure(string commandText, MySqlParameter[] parameters)
{
int num;
try
{
num = this.CreateCommand(commandText, CommandType.StoredProcedure, parameters).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryProcedureTransaction(string commandText)
{
int num;
try
{
num = this.CreateCommandTransaction(commandText, CommandType.StoredProcedure).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryProcedureTransaction(string commandText, MySqlParameter[] parameters)
{
int num;
try
{
num = this.CreateCommandTransaction(commandText, CommandType.StoredProcedure, parameters).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryTransaction(string commandText)
{
int num;
try
{
num = this.CreateCommandTransaction(commandText).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
internal int ExecuteNonQueryTransaction(string commandText, MySqlParameter[] parameters)
{
int num;
try
{
num = this.CreateCommandTransaction(commandText, parameters).ExecuteNonQuery();
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return num;
}
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using ESWS;
internal class MySqlHelper : IDisposable
{
private MySqlCommand mySqlCommand;
private MySqlConnection mySqlConnection;
private MySqlDataAdapter mySqlDataAdapter;
private MySqlTransaction myTransaction;
protected virtual void AddParameters(MySqlCommand command, MySqlParameter[] parameters)
{
foreach (MySqlParameter parameter in parameters)
{
command.Parameters.AddWithValue(parameter.ParameterName, parameter.Value);
}
}
internal void BegionTransaction()
{
if (this.DBConnection.State != ConnectionState.Open)
{
this.DBConnection.Open();
}
this.myTransaction = this.DBConnection.BeginTransaction();
}
internal void Commit()
{
this.DBTransaction.Commit();
}
protected MySqlCommand CreateCommand(string commandText)
{
return this.CreateCommand(commandText, CommandType.Text);
}
protected MySqlCommand CreateCommand(string commandText, CommandType commandType)
{
return this.CreateCommand(commandText, commandType, null);
}
protected MySqlCommand CreateCommand(string commandText, MySqlParameter[] parameters)
{
return this.CreateCommand(commandText, CommandType.Text, parameters);
}
protected MySqlCommand CreateCommand(string commandText, CommandType commandType, MySqlParameter[] parameters)
{
return this.CreateCommand(this.DBConnection, commandType, commandText, 30, parameters);
}
protected MySqlCommand CreateCommand(MySqlConnection connection, CommandType commandType, string commandText, int commandTimeout, MySqlParameter[] parameters)
{
MySqlCommand mySqlCommand;
try
{
using (this.mySqlCommand = new MySqlCommand())
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
this.mySqlCommand.Connection = connection;
this.mySqlCommand.CommandType = commandType;
this.mySqlCommand.CommandText = commandText;
if ((parameters != null) && (parameters.Length > 0))
{
this.AddParameters(this.mySqlCommand, parameters);
}
this.mySqlCommand.CommandTimeout = commandTimeout;
mySqlCommand = this.mySqlCommand;
}
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return mySqlCommand;
}
protected MySqlCommand CreateCommand(MySqlTransaction transaction, CommandType commandType, string commandText, int commandTimeout, MySqlParameter[] parameters)
{
MySqlCommand mySqlCommand;
try
{
using (this.mySqlCommand = new MySqlCommand())
{
if (transaction.Connection.State != ConnectionState.Open)
{
transaction.Connection.Open();
}
this.mySqlCommand.Connection = transaction.Connection;
this.mySqlCommand.CommandType = commandType;
this.mySqlCommand.CommandText = commandText;
if ((parameters != null) && (parameters.Length > 0))
{
this.AddParameters(this.mySqlCommand, parameters);
}
this.mySqlCommand.CommandTimeout = commandTimeout;
mySqlCommand = this.mySqlCommand;
}
}
catch (MySqlException exception)
{
throw new CustomException(exception.Message, exception);
}
return mySqlCommand;
}
protected MySqlCommand CreateCommandTransaction(string commandText)
{
return this.CreateCommandTransaction(commandText, CommandType.Text);
}
protected MySqlCommand CreateCommandTransaction(string commandText, MySqlParameter[] parameters)
{
return this.CreateCommandTransaction(commandText, CommandType.Text, parameters);
}
protected MySqlCommand CreateCommandTransaction(string commandText, CommandType commandType)
{
return this.CreateCommandTransaction(commandText, commandType, null);
}
protected MySqlCommand CreateCommandTransaction(string commandText, CommandType commandType, MySqlParameter[] parameters)
{
return this.CreateCommand(this.DBTransaction, commandType, commandText, 30, parameters);
}