using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
//using System.Data.OleDb;
using Oracle.DataAccess.Client;
//using System.Data.OracleClient;
namespace GNUNIX
{
    public class DBConn
    {
        //public static OleDbConnection conn;
        //public static OleDbDataAdapter adap;
        //public static OleDbCommand comm = new OleDbCommand();
        //public static OleDbDataReader read;
        public static OracleConnection conn;
        public static OracleDataAdapter adap;
        public static OracleCommand comm = new OracleCommand();
        public static OracleDataReader read;
        public static DataSet ds;
        public static bool Open(String SID, String ID, String PW)
        {
            try
            {
                //conn = new OleDbConnection("Provider=MSDAORA;Data Source=" + SID + ";User ID=" + ID + ";Password=" + PW);
                conn = new OracleConnection(@"Data Source=" + SID + ";User ID=" + ID + ";Password=" + PW);
                //conn = new OleDbConnection("Provider=OraOLEDB.Oracle.1;Data Source=" + SID + ";User ID=" + ID + ";Password=" + PW);
                conn.Open();
                
                comm.Connection = conn;
                return true;
            }
            catch
            {
                throw;
            }
        }
        public static void ExecuteSelectQueryRead(string query)
        {
            comm.CommandText = query;
            try
            {
                if (read!=null)
                {
                    read.Close();
                }
                read = comm.ExecuteReader();
            }
            catch//(Exception ex)
            {
                throw;
            }
        }
        public static void ExecuteSelectQueryAdapter(string query)
        {
            comm.CommandText = query;
            //ds = null;
            ds = new DataSet();
            try
            {
                if (read != null)
                {
                    read.Close();
                }
                //adap = new OleDbDataAdapter(comm);
                adap = new OracleDataAdapter(comm);
            }
            catch//(Exception ex)
            {
                //String test = ex.ToString();
                throw;
            }
        }
        //UDI = Update Delete Insert
        public static bool ExecuteUDIQuery(String query)
        {
            comm.CommandText = query;
            try
            {
                if (read != null)
                {
                    read.Close();
                }
                comm.ExecuteNonQuery();
                return true;
            }
            catch
            {
                throw;
            }
        }
        
        public static bool ExecuteSP(string sp, string[] parms)
        {
            comm.CommandText = "Call "+sp;
            for (int i=0; i<parms.Length; i++){
                comm.Parameters.Add(parms[i]);
            }
            try
            {
                if (read != null)
                {
                    read.Close();
                }
                comm.ExecuteNonQuery();
                return true;
            }
            catch
            {
                throw;
            }
        }
        public static void ExecuteSPReturnValue(string sp, string[] parms)
        {
            comm.CommandText = "Call " + sp;
            for (int i = 0; i < parms.Length; i++)
            {
                comm.Parameters.Add(parms[i]);
            }
            try
            {
                if (read != null)
                {
                    read.Close();
                }
                read = comm.ExecuteReader();
            }
            catch
            {
                throw;
            }
        }
    }
}