using System;
using System.Data;
using System.Windows.Forms;
namespace JXC_MIS.DataTier
{
	/// <summary>
	/// 连接小型桌面数据库 Access 的摘要说明。
	/// </summary>
	public class ClsAccess
	{
		private ClsAdoNet ado;

			//其它数据库
			private System.Data.OleDb.OleDbConnection _sysConn;
			private System.Data.OleDb.OleDbCommand _sysCmd;
			private System.Data.OleDb.OleDbParameter _sysPar;
			public ClsAccess()
			{
				//其它数据库

				ado = new ClsAdoNet(false);			
//				_sysConn = ado.GetOleDbConn(AdoNet.DataBaseType.ACCESS97,"c;\testdb97.mdb","","","");
//				_sysConn = ado.GetOleDbConnection(ClsAdoNet.DataBaseType.ACCESS2KX ,"..\\..\\TempFile.ljs","","","");
				_sysConn = ado.GetOleDbConnection(ClsAdoNet.DataBaseType.ACCESS2KX ,Application.StartupPath +"\\TempFile.ljs","","","");

				_sysCmd =(System.Data.OleDb.OleDbCommand)ado.DbCmd;
				_sysPar =(System.Data.OleDb.OleDbParameter)ado.DbPar;
				_sysCmd.Connection = _sysConn;           
			
			}

			public bool IsSql
			{	
				get
				{				
					return true;
				}		
			}


			public System.Data.OleDb.OleDbConnection sysConn
			{	
				get
				{
					return _sysConn;
				}		
			}

			public System.Data.OleDb.OleDbCommand sysCmd
			{	
				get
				{
					return _sysCmd;
				}		
			}

			public System.Data.OleDb.OleDbParameter sysPar
			{	
				get
				{
					return _sysPar;
				}		
			}

			//以下与数据库类型无关

			/// <summary>
			/// 开始事务
			/// </summary>
			public void BeginTrans()
			{
				ado.BeginTrans();
			}
			/// <summary>
			/// 提交事务
			/// </summary>
			public void Commit()
			{
				ado.Commit();
			}

			/// <summary>
			/// 事务回滚
			/// </summary>
			public void Rollback()
			{
				ado.Rollback();			
			}

			/// <summary>
			/// 获取事务执行是否成功状态
			/// </summary>
			public bool IsSuccessTrans
			{
				get
				{
					return ado.IsSuccessTrans;
				}
			}


			/// <summary>
			/// 执行SQL
			/// </summary>
			public int ExeSql(string strSQL)
			{	
				int intEffected;
				intEffected=ado.ExeSql(strSQL,this._sysConn);
				return intEffected;
			}

			/// <summary>
			/// 关闭数据库连接
			/// </summary>
			public void Close()
			{			
				try
				{
					if (_sysConn.State==ConnectionState.Open)
						_sysConn.Close();
					_sysConn=null;
					ado.CloseDbConn();
				}
				catch{}				
			}

			/// <summary>
			/// 得到指定SQL或存储过程的数据集
			/// </summary>
			/// <param name="strSQL">指定选择查询或存储过程</param>
			/// <returns></returns>
			public System.Data.DataSet GetDataSet(string strSQL)
			{
				if (strSQL=="")  {return null;}
				return ado.GetDataSet(strSQL,_sysConn);	
			}

			/// <summary>
			/// 得到默认Command的数据集
			/// </summary>
			/// <returns></returns>
			public System.Data.DataSet GetDataSet()
			{
				return ado.GetDataSet(sysCmd);
			}

			public System.Data.DataSet GetDataSet(object Command)
			{
				return ado.GetDataSet(Command);
			}
		}
	}





