1: using Oracle.ManagedDataAccess.Client;
2: using System;
3: using System.Configuration;
4: using System.Data;
5:
6: namespace Ia.Cl.Model.Db
7: {
8: ////////////////////////////////////////////////////////////////////////////
9:
10: /// <summary publish="true">
11: /// Oracle support class.
12: /// </summary>
13: /// <remarks>
14: /// Copyright © 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
15: ///
16: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
17: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
18: ///
19: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21: ///
22: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
23: ///
24: /// Copyright notice: This notice may not be removed or altered from any source distribution.
25: /// </remarks>
26: public class Oracle
27: {
28: private static OracleConnection oracleConnection;
29:
30: ////////////////////////////////////////////////////////////////////////////
31:
32: /// <summary>
33: ///
34: /// </summary>
35: public Oracle()
36: {
37: oracleConnection = new OracleConnection();
38:
39: oracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
40: oracleConnection.Open();
41: }
42:
43: ////////////////////////////////////////////////////////////////////////////
44:
45: /// <summary>
46: ///
47: /// </summary>
48: public Oracle(string connectionString)
49: {
50: oracleConnection = new OracleConnection();
51:
52: oracleConnection.ConnectionString = connectionString;
53: oracleConnection.Open();
54: }
55:
56: ////////////////////////////////////////////////////////////////////////////
57:
58: /// <summary>
59: ///
60: /// </summary>
61: public bool Sql(string sql)
62: {
63: //
64: bool b;
65: OracleCommand oco;
66:
67: oco = null;
68:
69: try
70: {
71: oco = new OracleCommand();
72:
73: oco.Connection = oracleConnection;
74: oco.CommandText = sql;
75: oco.CommandType = CommandType.Text;
76:
77: oco.ExecuteNonQuery();
78:
79: b = true;
80: }
81: catch (OracleException)
82: {
83: b = false;
84: }
85: catch (Exception)
86: {
87: b = false;
88: }
89: finally
90: {
91: oco.Dispose();
92: }
93:
94: return b;
95: }
96:
97: ////////////////////////////////////////////////////////////////////////////
98:
99: /// <summary>
100: ///
101: /// </summary>
102: public DataTable Select(string sql)
103: {
104: DataSet ds = new DataSet();
105: DataTable dt = new DataTable();
106: OracleCommand oco;
107: OracleDataReader dr;
108:
109: dt = null;
110: oco = null;
111: dr = null;
112:
113: try
114: {
115: dt = new DataTable();
116: oco = new OracleCommand();
117:
118: oco.Connection = oracleConnection;
119: oco.CommandText = sql;
120: oco.CommandType = CommandType.Text;
121:
122: dr = oco.ExecuteReader();
123: dt.Load(dr);
124: }
125: catch (OracleException)
126: {
127: }
128: catch (Exception)
129: {
130: }
131: finally
132: {
133: dr.Dispose();
134: oco.Dispose();
135: }
136:
137: return dt;
138: }
139:
140: ////////////////////////////////////////////////////////////////////////////
141: ////////////////////////////////////////////////////////////////////////////
142: }
143: }