1Imports#Region "Imports"
2Imports System.Data.OracleClient
3#End Region
4
5Public Class DbManagerClass DbManager
6
7Private Fields#Region "Private Fields"
8 Private isInTransaction As Boolean = False
9 Private oraConn As OracleConnection
10 Private oraCommand As OracleCommand
11 Private oraTransaction As OracleTransaction
12 Private strConnectString As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectString")
13#End Region
14
15Public Functions#Region "Public Functions"
16
17 Public Function openOracleDB()Function openOracleDB()
18 If oraConn Is Nothing Then
19 If strConnectString Is Nothing Or strConnectString = "" Then
20 strConnectString = "data source=TEST;user id=aaa;password=TEST"
21 End If
22
23 oraConn = New OracleConnection(strConnectString)
24 oraConn.Open()
25 oraCommand = New OracleCommand
26 oraCommand.Connection = oraConn
27 End If
28 End Function
29
30 Public Function closeOracleDB()Function closeOracleDB()
31 If isInTransaction Then
32 Return Nothing
33 End If
34 If Not oraConn Is Nothing Then
35 If oraConn.State = ConnectionState.Open Then
36 oraConn.Close()
37 End If
38 End If
39 If Not oraCommand Is Nothing Then
40 oraCommand.Dispose()
41 End If
42 End Function
43
44 Public Function beginTransaction()Function beginTransaction()
45 openOracleDB()
46
47 oraTransaction = oraConn.BeginTransaction
48 oraCommand.Transaction = oraTransaction
49 isInTransaction = True
50 End Function
51
52 Public Function commitTransaction()Function commitTransaction()
53
54 oraTransaction.Commit()
55 isInTransaction = False
56 closeOracleDB()
57
58 End Function
59
60 Public Function rollbackTransaction()Function rollbackTransaction()
61
62 oraTransaction.Rollback()
63 isInTransaction = False
64 closeOracleDB()
65
66 End Function
67
68 Public Function Db_ExecuteNonquery()Function Db_ExecuteNonquery(ByVal strSQL As String)
69
70 openOracleDB()
71 oraCommand.CommandText = strSQL
72 oraCommand.ExecuteNonQuery()
73 closeOracleDB()
74
75 End Function
76
77 Public Function Db_ExecuteNonquery()Function Db_ExecuteNonquery(ByVal strSQL As String, ByVal argParameters As OracleParameter())
78 openOracleDB()
79 oraCommand.CommandText = strSQL
80 For i As Integer = 0 To argParameters.Length - 1
81 oraCommand.Parameters.Add(argParameters(i))
82 Next
83 oraCommand.ExecuteNonQuery()
84 closeOracleDB()
85 End Function
86
87 Public Function Db_CreateReader()Function Db_CreateReader(ByVal strSQL As String) As OracleDataReader
88 openOracleDB()
89 oraCommand.CommandText = strSQL
90 Dim oraReader As OracleDataReader = oraCommand.ExecuteReader()
91
92 Return oraReader
93 End Function
94
95 Public Function Db_CreateReader()Function Db_CreateReader(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As OracleDataReader
96 openOracleDB()
97 oraCommand.CommandText = strSQL
98 For i As Integer = 0 To argParameters.Length - 1
99 oraCommand.Parameters.Add(argParameters(i))
100 Next
101 Dim oraReader As OracleDataReader = oraCommand.ExecuteReader()
102
103 Return oraReader
104 End Function
105
106 Public Function Db_CreateDataSet()Function Db_CreateDataSet(ByVal strSQL As String) As DataSet
107 openOracleDB()
108 oraCommand.CommandText = strSQL
109 Dim oraDap As New OracleDataAdapter(oraCommand)
110 Dim oraDst As New DataSet
111 oraDap.Fill(oraDst)
112 closeOracleDB()
113 Return oraDst
114 End Function
115
116 Public Function Db_CreateDataSet()Function Db_CreateDataSet(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As DataSet
117 openOracleDB()
118 oraCommand.CommandText = strSQL
119 For i As Integer = 0 To argParameters.Length - 1
120 oraCommand.Parameters.Add(argParameters(i))
121 Next
122 Dim oraDap As New OracleDataAdapter(oraCommand)
123 Dim oraDst As New DataSet
124 oraDap.Fill(oraDst)
125 closeOracleDB()
126 Return oraDst
127 End Function
128
129 Public Function Db_CreateDataTable()Function Db_CreateDataTable(ByVal strSQL As String) As DataTable
130 Dim oraDst As DataSet = Db_CreateDataSet(strSQL)
131 Dim oraDt As DataTable = oraDst.Tables(0)
132 Return oraDt
133 End Function
134
135 Public Function Db_CreateDataTable()Function Db_CreateDataTable(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As DataTable
136 Dim oraDst As DataSet = Db_CreateDataSet(strSQL, argParameters)
137 Dim oraDt As DataTable = oraDst.Tables(0)
138 Return oraDt
139 End Function
140#End Region
141
142End Class
143
2Imports System.Data.OracleClient
3#End Region
4
5Public Class DbManagerClass DbManager
6
7Private Fields#Region "Private Fields"
8 Private isInTransaction As Boolean = False
9 Private oraConn As OracleConnection
10 Private oraCommand As OracleCommand
11 Private oraTransaction As OracleTransaction
12 Private strConnectString As String = System.Configuration.ConfigurationSettings.AppSettings("ConnectString")
13#End Region
14
15Public Functions#Region "Public Functions"
16
17 Public Function openOracleDB()Function openOracleDB()
18 If oraConn Is Nothing Then
19 If strConnectString Is Nothing Or strConnectString = "" Then
20 strConnectString = "data source=TEST;user id=aaa;password=TEST"
21 End If
22
23 oraConn = New OracleConnection(strConnectString)
24 oraConn.Open()
25 oraCommand = New OracleCommand
26 oraCommand.Connection = oraConn
27 End If
28 End Function
29
30 Public Function closeOracleDB()Function closeOracleDB()
31 If isInTransaction Then
32 Return Nothing
33 End If
34 If Not oraConn Is Nothing Then
35 If oraConn.State = ConnectionState.Open Then
36 oraConn.Close()
37 End If
38 End If
39 If Not oraCommand Is Nothing Then
40 oraCommand.Dispose()
41 End If
42 End Function
43
44 Public Function beginTransaction()Function beginTransaction()
45 openOracleDB()
46
47 oraTransaction = oraConn.BeginTransaction
48 oraCommand.Transaction = oraTransaction
49 isInTransaction = True
50 End Function
51
52 Public Function commitTransaction()Function commitTransaction()
53
54 oraTransaction.Commit()
55 isInTransaction = False
56 closeOracleDB()
57
58 End Function
59
60 Public Function rollbackTransaction()Function rollbackTransaction()
61
62 oraTransaction.Rollback()
63 isInTransaction = False
64 closeOracleDB()
65
66 End Function
67
68 Public Function Db_ExecuteNonquery()Function Db_ExecuteNonquery(ByVal strSQL As String)
69
70 openOracleDB()
71 oraCommand.CommandText = strSQL
72 oraCommand.ExecuteNonQuery()
73 closeOracleDB()
74
75 End Function
76
77 Public Function Db_ExecuteNonquery()Function Db_ExecuteNonquery(ByVal strSQL As String, ByVal argParameters As OracleParameter())
78 openOracleDB()
79 oraCommand.CommandText = strSQL
80 For i As Integer = 0 To argParameters.Length - 1
81 oraCommand.Parameters.Add(argParameters(i))
82 Next
83 oraCommand.ExecuteNonQuery()
84 closeOracleDB()
85 End Function
86
87 Public Function Db_CreateReader()Function Db_CreateReader(ByVal strSQL As String) As OracleDataReader
88 openOracleDB()
89 oraCommand.CommandText = strSQL
90 Dim oraReader As OracleDataReader = oraCommand.ExecuteReader()
91
92 Return oraReader
93 End Function
94
95 Public Function Db_CreateReader()Function Db_CreateReader(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As OracleDataReader
96 openOracleDB()
97 oraCommand.CommandText = strSQL
98 For i As Integer = 0 To argParameters.Length - 1
99 oraCommand.Parameters.Add(argParameters(i))
100 Next
101 Dim oraReader As OracleDataReader = oraCommand.ExecuteReader()
102
103 Return oraReader
104 End Function
105
106 Public Function Db_CreateDataSet()Function Db_CreateDataSet(ByVal strSQL As String) As DataSet
107 openOracleDB()
108 oraCommand.CommandText = strSQL
109 Dim oraDap As New OracleDataAdapter(oraCommand)
110 Dim oraDst As New DataSet
111 oraDap.Fill(oraDst)
112 closeOracleDB()
113 Return oraDst
114 End Function
115
116 Public Function Db_CreateDataSet()Function Db_CreateDataSet(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As DataSet
117 openOracleDB()
118 oraCommand.CommandText = strSQL
119 For i As Integer = 0 To argParameters.Length - 1
120 oraCommand.Parameters.Add(argParameters(i))
121 Next
122 Dim oraDap As New OracleDataAdapter(oraCommand)
123 Dim oraDst As New DataSet
124 oraDap.Fill(oraDst)
125 closeOracleDB()
126 Return oraDst
127 End Function
128
129 Public Function Db_CreateDataTable()Function Db_CreateDataTable(ByVal strSQL As String) As DataTable
130 Dim oraDst As DataSet = Db_CreateDataSet(strSQL)
131 Dim oraDt As DataTable = oraDst.Tables(0)
132 Return oraDt
133 End Function
134
135 Public Function Db_CreateDataTable()Function Db_CreateDataTable(ByVal strSQL As String, ByVal argParameters As OracleParameter()) As DataTable
136 Dim oraDst As DataSet = Db_CreateDataSet(strSQL, argParameters)
137 Dim oraDt As DataTable = oraDst.Tables(0)
138 Return oraDt
139 End Function
140#End Region
141
142End Class
143