/*********************************************************************************************
 * Copyright 2002 - Volian Enterprises, Inc. All rights reserved.
 * Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
 * ------------------------------------------------------------------------------
 * $Workfile: DBEncap.cs $     $Revision: 5 $
 * $Author: Kathy $   $Date: 12/10/02 2:24p $
 *
 * $History: DBEncap.cs $
 * 
 * *****************  Version 5  *****************
 * User: Kathy        Date: 12/10/02   Time: 2:24p
 * Updated in $/LibSource/DBEncapsulation
 * handle dbnull for sql server
 * 
 * *****************  Version 4  *****************
 * User: Kathy        Date: 10/09/02   Time: 12:36p
 * Updated in $/LibSource/DBEncapsulation
 * handle null in data
 * 
 * *****************  Version 3  *****************
 * User: Jsj          Date: 9/05/02    Time: 1:03p
 * Updated in $/LibSource/DBEncapsulation
 * added ExecuteNonQuery calls
 * 
 * *****************  Version 2  *****************
 * User: Jsj          Date: 9/05/02    Time: 11:31a
 * Updated in $/LibSource/DBEncapsulation
 * added Close functions
 * 
 * *****************  Version 1  *****************
 * User: Jsj          Date: 8/23/02    Time: 3:07p
 * Created in $/LibSource/DBEncapsulation
 *********************************************************************************************/

using System;
using System.Data;
using System.Data.OleDb;
using Microsoft.Data.Odbc;

namespace DBEncapsulation
{
	/// <summary>
	/// Summary description for DBEncapsulate: Encapsulate database interface methods &
	/// classes. Will encapsulate OLE DB & ODBC connections, commands, readers & other
	/// features as required.
	/// </summary>
	public class DBEncapsulate
	{
		public virtual void Connection(string strconnect)
		{
		}
		public virtual void OpenConnection()
		{
		}
		public virtual void CloseConnection()
		{
		}
		public virtual void Command(string strCommand)
		{
		}
		public virtual void CommandDispose()
		{
		}
		public virtual bool Reader()
		{
			return false;
		}
		public virtual void ReaderClose()
		{
		}
		public virtual bool Read()
		{
			return false;
		}
		public virtual string GetString(int num)
		{
			string tmp = "tmp";
			return (tmp);
		}
		public virtual int GetInt32(int num)
		{
			return (0);
		}
		public virtual void NonQuery()
		{
		}
	}
	public class OLEDB_DBEncap: DBEncapsulate
	{
		OleDbConnection myDatabaseConn;
		OleDbCommand myCommand;
		OleDbDataReader myReader;
		public override void Connection(string strconnect)
		{
			myDatabaseConn = new OleDbConnection(strconnect);
		}
		public override void OpenConnection()
		{
			myDatabaseConn.Open();
		}
		public override void CloseConnection()
		{
			myDatabaseConn.Close();
		}
		public override void Command(string strCommand)
		{
			myCommand = new OleDbCommand(strCommand,myDatabaseConn);
		}
		public override void CommandDispose()
		{
			myCommand.Dispose();
		}
		public override bool Reader()
		{
			myReader = myCommand.ExecuteReader();
			if (myReader == null)
				return false;
			else
				return true;
		}
		public override void ReaderClose()
		{
			myReader.Close();
		}
		public override bool Read()
		{
			return(myReader.Read());
		}
		public override string GetString(int num)
		{
			if (myReader.IsDBNull(num) == false)
				return(myReader.GetString(num));
			else
				 return null;
			//if (myReader.GetString(num) == null) return null;
			//return(myReader.GetString(num));
		}
		public override int GetInt32(int num)
		{
			return(myReader.GetInt32(num));
		}
		public override void NonQuery()
		{
			myCommand.ExecuteNonQuery();
		}
	}

	public class ODBC_DBEncap: DBEncapsulate
	{
		OdbcConnection myDatabaseConn;
		OdbcCommand myCommand;
		OdbcDataReader myReader;
		public override void Connection(string strconnect)
		{
			myDatabaseConn = new OdbcConnection(strconnect);
		}
		public override void OpenConnection()
		{
			myDatabaseConn.Open();
		}
		public override void CloseConnection()
		{
			myDatabaseConn.Close();
		}
		public override void Command(string strCommand)
		{
			myCommand = new OdbcCommand(strCommand,myDatabaseConn);
		}
		public override void CommandDispose()
		{
			myCommand.Dispose();
		}
		public override bool Reader()
		{
			myReader = myCommand.ExecuteReader();
			if (myReader == null) 
				return false;
			else
				return true;
		}
		public override void ReaderClose()
		{
			myReader.Close();
		}
		public override bool Read()
		{
			return(myReader.Read());
		}
		public override string GetString(int num)
		{
			if (myReader.IsDBNull(num) == false)
				return(myReader.GetString(num));
			else
				return null;
		}
		public override int GetInt32(int num)
		{
			return(myReader.GetInt32(num));
		}
		public override void NonQuery()
		{
			myCommand.ExecuteNonQuery();
		}
	}
}
