202 lines
2.9 KiB
C#
202 lines
2.9 KiB
C#
using ADODB;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
|
||
namespace NX.ERP.U8
|
||
{
|
||
public class U8DbHelper:IDisposable
|
||
{
|
||
public string _connstring;
|
||
|
||
private string string_0;
|
||
|
||
public bool _DbErr;
|
||
|
||
public Connection Conn;
|
||
|
||
public string ConnectionString
|
||
{
|
||
get
|
||
{
|
||
return _connstring;
|
||
}
|
||
set
|
||
{
|
||
_connstring = value;
|
||
}
|
||
}
|
||
|
||
public string ErrMsg
|
||
{
|
||
get
|
||
{
|
||
return string_0;
|
||
}
|
||
}
|
||
|
||
public U8DbHelper(string connstr)
|
||
{
|
||
|
||
_connstring = connstr;
|
||
if (_connstring != null && !(_connstring == string.Empty))
|
||
{
|
||
Conn = new ConnectionClass();
|
||
Conn.ConnectionString = _connstring;
|
||
try
|
||
{
|
||
Conn.Open();
|
||
_DbErr = false;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
_DbErr = true;
|
||
string_0 = "数据连接配置错误,无法从指定的数据连接字符串打开数据库,请检查WEB.CONFIG文件";
|
||
throw new Exception(ErrMsg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_DbErr = true;
|
||
string_0 = "数据连接配置错误,没有配置数据连接";
|
||
}
|
||
}
|
||
|
||
public U8DbHelper(Connection cnt)
|
||
{
|
||
|
||
_connstring = cnt.ConnectionString;
|
||
Conn = cnt;
|
||
try
|
||
{
|
||
if (Conn.State != 1)
|
||
{
|
||
Conn.Open();
|
||
_DbErr = false;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
_DbErr = true;
|
||
string_0 = "数据连接配置错误,无法从指定的数据连接字符串打开数据库,请检查WEB.CONFIG文件";
|
||
throw new Exception(ErrMsg);
|
||
}
|
||
}
|
||
|
||
public static bool IsConn(string connectionString)
|
||
{
|
||
Connection connection = new ConnectionClass();
|
||
try
|
||
{
|
||
connection.ConnectionString = connectionString;
|
||
connection.Open();
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
finally
|
||
{
|
||
if (connection.State == 1)
|
||
{
|
||
connection.Close();
|
||
}
|
||
connection = null;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public Recordset U8ExcuteRecord(string strSQL)
|
||
{
|
||
try
|
||
{
|
||
object RecordsAffected;
|
||
return Conn.Execute(strSQL, out RecordsAffected);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public int U8ExcuteNoneQuery(string strSQL)
|
||
{
|
||
try
|
||
{
|
||
object RecordsAffected;
|
||
Conn.Execute(strSQL, out RecordsAffected);
|
||
return (int)RecordsAffected;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public void BeginTrans()
|
||
{
|
||
try
|
||
{
|
||
if (Conn != null)
|
||
{
|
||
Conn.BeginTrans();
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public void RollbackTrans()
|
||
{
|
||
try
|
||
{
|
||
if (Conn != null)
|
||
{
|
||
Conn.RollbackTrans();
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public void CommitTrans()
|
||
{
|
||
try
|
||
{
|
||
if (Conn != null)
|
||
{
|
||
Conn.CommitTrans();
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
try
|
||
{
|
||
if (Conn != null)
|
||
{
|
||
if (Conn.State == 1)
|
||
{
|
||
Conn.Close();
|
||
}
|
||
Conn = null;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
}
|