📄 dabasis.cs
字号:
using System;
using System.Threading;
using System.Configuration;
using System.Reflection;
using System.Diagnostics;
using System.Resources;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using BEC;
namespace DAT
{
/// <summary>
/// This is the super class of all data access objects
/// </summary>
public class DABasis
{
// connection string for the local Sqlserver
protected static string strLocalServer;
//Sqlparameter Factory
protected static PMFactory_In pmFactory_In;
protected static PMFactory_Out pmFactory_Out;
// Objects for the local database access
protected SqlConnection dbConnection_L;
protected SqlCommand dbCommand_L;
protected SqlDataAdapter dbAdapter_L;
protected SqlTransaction dbTransaction_L;
public DABasis()
{
this.bSkipInitialization_L=false;
}
/// <summary>
/// This flag is used to prevent to establish new connection and creating an another instance
/// of Sqlcommand class,
/// </summary>
bool bSkipInitialization_L;
/// <summary>
/// Set the bSkipInitialization flag
/// </summary>
public void SetSkipInitialization_L()
{
this.bSkipInitialization_L=true;
}
/// <summary>
/// Sets the bSkipInitialization flag and take connection and command from a peer data access tier class
/// </summary>
public void SetSkipInitialization_L(DABasis oBasis)
{
this.bSkipInitialization_L=true;
this.dbConnection_L=oBasis.dbConnection_L;
this.dbCommand_L=oBasis.dbCommand_L;
this.dbTransaction_L=oBasis.dbTransaction_L;
}
/// <summary>
/// Set the bSkipInitialization flag
/// </summary>
public void ResetSkipInitialization_L()
{
this.bSkipInitialization_L=false;
}
/// <summary>
/// retrives values from web.config
/// </summary>
static DABasis()
{
// Intit Parameter factory
pmFactory_In = new PMFactory_In();
pmFactory_Out = new PMFactory_Out();
// read the config file
AppSettingsReader appReader=new AppSettingsReader();
strLocalServer= (string)appReader.GetValue("localConnection",Type.GetType("System.String"));
}
/// <summary>
/// Timeout for the local SqlCommand
/// </summary>
/// <param name="nTimeOut"></param>
protected void SetCommandTimeOut_L(int nTimeOut)
{
try
{
this.dbCommand_L.CommandTimeout=nTimeOut;
}
catch(Exception oException)
{
throw oException;
}
}
/// <summary>
/// Sets backs the default timeout
/// </summary>
/// <param name="nTimeOut"></param>
protected void ResetCommandTimeOut_L(int nTimeOut)
{
try
{
this.dbCommand_L.ResetCommandTimeout();
}
catch(Exception oException)
{
throw oException;
}
}
/// <summary>
/// Marks the transactin begin for the local server with isolation level
/// </summary>
protected void BeginTransaction_L(System.Data.IsolationLevel oIsolationLevel)
{
try
{
if(this.bSkipInitialization_L==false)
{
dbTransaction_L = dbConnection_L.BeginTransaction(oIsolationLevel);
dbCommand_L.Transaction = this.dbTransaction_L;
}
}
catch(Exception oException)
{
string strMessage = " BeginTransaction_L(System.Data.IsolationLevel)";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// Marks the transaction begin for the local server with isolation level
/// </summary>
protected void BeginTransaction_L(System.Data.IsolationLevel oIsolationLevel,string strTransactionName)
{
try
{
if(this.bSkipInitialization_L==false)
{
dbTransaction_L = dbConnection_L.BeginTransaction(oIsolationLevel,strTransactionName);
dbCommand_L.Transaction = this.dbTransaction_L;
}
}
catch(Exception oException)
{
string strMessage = " BeginTransaction_L(System.Data.IsolationLevel oIsolationLevel,string strTransactionName)";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// Marks the transactin begin for the local server
/// </summary>
protected void BeginTransaction_L()
{
try
{
if(this.bSkipInitialization_L==false)
{
dbTransaction_L = dbConnection_L.BeginTransaction();
dbCommand_L.Transaction = this.dbTransaction_L;
}
}
catch(Exception oException)
{
string strMessage = " BeginTransaction_L()";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// Commit the transaction against the local server
/// </summary>
protected void Commit_L()
{
try
{
if(this.bSkipInitialization_L==false)
{
dbTransaction_L.Commit();
}
}
catch(Exception oException)
{
string strMessage = "Error occurred in BeginTransaction_L()";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// Rollbacks the transaction of the local server
/// </summary>
protected void Rollback_L()
{
try
{
this.dbTransaction_L.Rollback();
}
catch(Exception oException)
{
string strMessage = "Error occurred in Rollback_L";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// Rollbacks the transaction of the local server
/// </summary>
protected void Rollback_L(string strTransactionName)
{
try
{
this.dbTransaction_L.Rollback(strTransactionName);
}
catch(Exception oException)
{
string strMessage = "Error occurred in Rollback_L";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// This method initialize data access utilities for the local Sqlserver
/// If the bSkipInitialization flag is true
/// then the instance of the SqlCommand class will be recycled not created
/// </summary>
/// <param name="strSP">name of the stored procedure</param>
protected virtual void Prepair_L(string strSP)
{
try
{
if(this.bSkipInitialization_L==false)
{
dbConnection_L = new SqlConnection(strLocalServer);
dbCommand_L = new SqlCommand(strSP,dbConnection_L);
dbCommand_L.CommandType = CommandType.StoredProcedure;
}
else
{
this.ReuseCommand_L(strSP);
}
}
catch(Exception oException)
{
string strMessage = "Occurred in Prepail_L() ";
throw new Exception(strMessage,oException);
}
}
/// <summary>
/// This method initialize data access utilities for the local Sqlserver
/// Note:This method doesn抰 initialize the instance of the SqlCommand class
/// with the store procedure and it is used to execute 揹ata access methods
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -