www.pudn.com > whpower2007-8-24.rar > AbstractDataManager.cs, change:2007-05-18,size:2259b


using System; 
using System.Data; 
using System.Data.SqlClient; 
using System.Web; 
using System.Web.UI; 
using com.etong.SqlDataConnect; 
 
namespace com.etong.BusinessRule.Zwf 
{ 
	/// <summary> 
	/// AbstractDataManager 的摘要说明。 
	/// </summary> 
	public abstract class AbstractDataManager 
	{ 
		public AbstractDataManager() 
		{ 
			// 
			// TODO: 在此处添加构造函数逻辑 
			// 
		} 
		MSSqlDataAccess MSDA = new MSSqlDataAccess(0); 
 
		public virtual bool insert(string InsSQL,QueryParameterCollection insParams,CommandType commandtype) 
		{ 
 
			MSDA.Open(); 
 
			SqlTransaction tran = MSDA.BeginTransaction(); 
			try 
			{ 
				MSDA.ExecuteNonQuery(commandtype,InsSQL,insParams); 
				tran.Commit(); 
				return true; 
			} 
			catch 
			{ 
				tran.Rollback(); 
				throw; 
//				return false; 
			} 
			finally 
			{ 
				MSDA.Close(); 
			} 
		} 
 
		public  virtual DataSet Search(string searchSQL,QueryParameterCollection searchParams ,CommandType commandtype) 
		{ 
			DataSet ds = new DataSet(); 
			MSDA.Open(); 
			SqlTransaction tran = MSDA.BeginTransaction(); 
			try 
			{ 
				MSDA.ExecuteDataset(commandtype,searchSQL,searchParams,ds,""); 
				tran.Commit(); 
				return ds; 
			} 
			catch 
			{ 
				tran.Rollback(); 
				return null; 
			} 
			finally 
			{ 
				MSDA.Close(); 
			} 
			 
		} 
 
		public  virtual bool Update(string updSQL,QueryParameterCollection updParams,CommandType commandtype)  
		{ 
			MSDA.Open(); 
//			MSDA.ExecuteNonQuery(commandtype,updSQL,updParams); 
//			MSDA.Close(); 
//			return true; 
			SqlTransaction tran = MSDA.BeginTransaction(); 
			try 
			{ 
				MSDA.ExecuteNonQuery(commandtype,updSQL,updParams); 
				tran.Commit(); 
				return true; 
			} 
			catch 
			{ 
				tran.Rollback(); 
				throw; 
//				return false; 
			} 
			finally 
			{ 
				MSDA.Close(); 
			} 
		} 
 
		public virtual bool Delete(string delSQL ,QueryParameterCollection delParams,CommandType commandtype) 
		{ 
			MSDA.Open(); 
			SqlTransaction tran = MSDA.BeginTransaction(); 
			try 
			{ 
				MSDA.ExecuteNonQuery(commandtype,delSQL,delParams); 
				tran.Commit(); 
				return true; 
			} 
			catch 
			{ 
				tran.Rollback(); 
				return false; 
			} 
			finally 
			{ 
				MSDA.Close(); 
			} 
		} 
	} 
}