تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كلاس Data Access Layer
#1
كاتب الموضوع : أبو عابد

السلام عليكم ورحمة الله وبركاته

هذا كلاس للتعامل مع البيانات بغض النظر عن نوع مخزن البيانات (Oracle, SQL Server )

وجدته بالإنترنت ، آمل أن يكون ممفيداً


كود :
[COLOR=#000000][COLOR=#0000bb]Imports System
Imports System[/COLOR][color=#007700].[/color][color=#0000bb]Collections[/color][color=#007700].[/color][COLOR=#0000bb]Generic
Imports System[/COLOR][color=#007700].[/color][COLOR=#0000bb]Data
Imports System[/COLOR][color=#007700].[/color][color=#0000bb]Data[/color][color=#007700].[/color][COLOR=#0000bb]SqlClient
Imports System[/COLOR][color=#007700].[/color][color=#0000bb]Data[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
Imports System[/COLOR][color=#007700].[/color][color=#0000bb]Data[/color][color=#007700].[/color][COLOR=#0000bb]OleDb
Imports System[/COLOR][color=#007700].[/color][color=#0000bb]Data[/color][color=#007700].[/color][COLOR=#0000bb]OracleClient
Imports System[/COLOR][color=#007700].[/color][COLOR=#0000bb]Text

Namespace DataAccessLayer
    [/COLOR][color=#007700]Public [/color][COLOR=#0000bb]Enum DataProvider
        Oracle
        SqlServer
        Oledb
        Odbc

    End Enum
    [/COLOR][color=#007700]Public Interface [/color][COLOR=#0000bb]IDBManager
        Property ProviderType[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]DataProvider
        Property ConnectionString[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]String
        ReadOnly Property Connection[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]IDbConnection
        ReadOnly Property Transaction[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]IDbTransaction
        Property DataReader[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]IDataReader

        ReadOnly Property Command[/COLOR][color=#007700]() As [/color][COLOR=#0000bb]IDbCommand
        ReadOnly Property Parameters[/COLOR][color=#007700]() As [/color][color=#0000bb]IDbDataParameter[/color][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub Open[/color][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub BeginTransaction[/color][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub CommitTransaction[/color][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub CreateParameters[/color][color=#007700]([/color][color=#0000bb]ByVal ParamsCount [/color][color=#007700]As [/color][color=#0000bb]Integer[/color][COLOR=#007700])
        [/COLOR][color=#0000bb]Sub AddParameters[/color][color=#007700]([/color][color=#0000bb]ByVal index [/color][color=#007700]As [/color][color=#0000bb]Integer[/color][color=#007700], [/color][color=#0000bb]ByVal ParamName [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700], [/color][color=#0000bb]ByVal objvalue [/color][color=#007700]As [/color][color=#0000bb]Object[/color][COLOR=#007700])
        Function [/COLOR][color=#0000bb]ExecuteReader[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][COLOR=#0000bb]IDataReader
        [/COLOR][color=#007700]Function [/color][color=#0000bb]ExecuteDataset[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][COLOR=#0000bb]DataSet
        [/COLOR][color=#007700]Function [/color][color=#0000bb]ExecuteScalar[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][COLOR=#0000bb]Object
        [/COLOR][color=#007700]Function [/color][color=#0000bb]ExecuteNonQuery[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal CommandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][COLOR=#0000bb]Integer
        Sub CloseReader[/COLOR][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub close[/color][COLOR=#007700]()
        [/COLOR][color=#0000bb]Sub Dispose[/color][COLOR=#007700]()
    [/COLOR][color=#0000bb]End [/color][COLOR=#007700]Interface
    Public [/COLOR][color=#0000bb]NotInheritable [/color][color=#007700]Class [/color][COLOR=#0000bb]DBManagerFactory
        [/COLOR][color=#007700]Private [/color][color=#0000bb]Sub [/color][COLOR=#007700]New()
        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetConnection[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700]) As [/color][COLOR=#0000bb]IDbConnection
            Dim iDbConnection [/COLOR][color=#007700]As [/color][color=#0000bb]IDbConnection [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
            Select [/COLOR][color=#007700]Case [/color][COLOR=#0000bb]providerType
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]SqlServer
                    iDbConnection [/COLOR][color=#007700]= New [/color][color=#0000bb]SqlConnection[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oledb
                    iDbConnection [/COLOR][color=#007700]= New [/color][color=#0000bb]OleDbConnection[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
                    iDbConnection [/COLOR][color=#007700]= New [/color][color=#0000bb]OdbcConnection[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oracle
                    iDbConnection [/COLOR][color=#007700]= New [/color][color=#0000bb]OracleConnection[/color][COLOR=#007700]()
                Case Else
                    Return [/COLOR][COLOR=#0000bb]Nothing
            End Select
            [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]iDbConnection
        End [/COLOR][COLOR=#007700]Function
        Public [/COLOR][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700]) As [/color][COLOR=#0000bb]IDbCommand
            Select [/COLOR][color=#007700]Case [/color][COLOR=#0000bb]providerType
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]SqlServer
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]SqlCommand[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oledb
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OleDbCommand[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OdbcCommand[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oracle
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OracleCommand[/color][COLOR=#007700]()
                Case Else
                    Return [/COLOR][COLOR=#0000bb]Nothing
            End Select
        End [/COLOR][COLOR=#007700]Function

        Public [/COLOR][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetDataAdapter[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700]) As [/color][COLOR=#0000bb]IDbDataAdapter
            Select [/COLOR][color=#007700]Case [/color][COLOR=#0000bb]providerType
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]SqlServer
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]SqlDataAdapter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oledb
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OleDbDataAdapter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OdbcDataAdapter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oracle
                    [/COLOR][color=#007700]Return New [/color][color=#0000bb]OracleDataAdapter[/color][COLOR=#007700]()
                Case Else
                    Return [/COLOR][COLOR=#0000bb]Nothing
            End Select
        End [/COLOR][COLOR=#007700]Function
        Public [/COLOR][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetTransaction[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700]) As [/color][COLOR=#0000bb]IDbTransaction
            Dim iDbConnection [/COLOR][color=#007700]As [/color][color=#0000bb]IDbConnection [/color][color=#007700]= [/color][color=#0000bb]GetConnection[/color][color=#007700]([/color][color=#0000bb]providerType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Dim iDbTransaction [/color][color=#007700]As [/color][color=#0000bb]IDbTransaction [/color][color=#007700]= [/color][color=#0000bb]iDbConnection[/color][color=#007700].[/color][color=#0000bb]BeginTransaction[/color][COLOR=#007700]()
            Return [/COLOR][COLOR=#0000bb]iDbTransaction

        End [/COLOR][COLOR=#007700]Function
        Public [/COLOR][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetParameter[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700]) As [/color][COLOR=#0000bb]IDataParameter
            Dim iDataParameter [/COLOR][color=#007700]As [/color][color=#0000bb]IDataParameter [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
            Select [/COLOR][color=#007700]Case [/color][COLOR=#0000bb]providerType
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]SqlServer
                    iDataParameter [/COLOR][color=#007700]= New [/color][color=#0000bb]SqlParameter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oledb
                    iDataParameter [/COLOR][color=#007700]= New [/color][color=#0000bb]OleDbParameter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
                    iDataParameter [/COLOR][color=#007700]= New [/color][color=#0000bb]OdbcParameter[/color][COLOR=#007700]()
                Case [/COLOR][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oracle
                    iDataParameter [/COLOR][color=#007700]= New [/color][color=#0000bb]OracleParameter[/color][COLOR=#007700]()
            [/COLOR][COLOR=#0000bb]End Select
            [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]iDataParameter
        End [/COLOR][COLOR=#007700]Function
        Public [/COLOR][color=#0000bb]Shared [/color][color=#007700]Function [/color][color=#0000bb]GetParameters[/color][color=#007700]([/color][color=#0000bb]ByVal providerType [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700], [/color][color=#0000bb]ByVal paramsCount [/color][color=#007700]As [/color][color=#0000bb]Integer[/color][color=#007700]) As [/color][color=#0000bb]IDbDataParameter[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]Dim iDbParams [/color][color=#007700]As [/color][color=#0000bb]IDbDataParameter[/color][color=#007700]() = New [/color][color=#0000bb]IDbDataParameter[/color][color=#007700]([/color][color=#0000bb]paramsCount [/color][color=#007700]- [/color][color=#0000bb]1[/color][COLOR=#007700]) {}
            [/COLOR][color=#0000bb]Select [/color][color=#007700]Case [/color][COLOR=#0000bb]providerType
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]SqlServer
                    [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][color=#0000bb]0 To paramsCount [/color][color=#007700]- [/color][COLOR=#0000bb]1
                        iDbParams[/COLOR][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]) = New [/color][color=#0000bb]SqlParameter[/color][COLOR=#007700]()
                    [/COLOR][COLOR=#0000bb]Next i
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oledb
                    [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][color=#0000bb]0 To paramsCount [/color][color=#007700]- [/color][COLOR=#0000bb]1
                        iDbParams[/COLOR][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]) = New [/color][color=#0000bb]OleDbParameter[/color][COLOR=#007700]()
                    [/COLOR][COLOR=#0000bb]Next i
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Odbc
                    [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][color=#0000bb]0 To paramsCount [/color][color=#007700]- [/color][COLOR=#0000bb]1
                        iDbParams[/COLOR][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]) = New [/color][color=#0000bb]OdbcParameter[/color][COLOR=#007700]()
                    [/COLOR][COLOR=#0000bb]Next i
                [/COLOR][color=#007700]Case [/color][color=#0000bb]DataProvider[/color][color=#007700].[/color][COLOR=#0000bb]Oracle
                    [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][color=#0000bb]0 To paramsCount [/color][color=#007700]- [/color][COLOR=#0000bb]1
                        iDbParams[/COLOR][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]) = New [/color][color=#0000bb]OracleParameter[/color][COLOR=#007700]()
                    [/COLOR][COLOR=#0000bb]Next i

            End Select
            [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]iDbParams
        End [/COLOR][COLOR=#007700]Function
    [/COLOR][color=#0000bb]End [/color][COLOR=#007700]Class
    Public [/COLOR][color=#0000bb]NotInheritable [/color][color=#007700]Class [/color][color=#0000bb]DBManager [/color][color=#007700]: Implements [/color][color=#0000bb]IDBManager[/color][color=#007700], [/color][COLOR=#0000bb]IDisposable
        [/COLOR][COLOR=#dd0000]'Inherits IDBManager
        '[/COLOR][color=#007700]Implements [/color][COLOR=#0000bb]IDisposable
        [/COLOR][color=#007700]Private [/color][color=#0000bb]idbConnection [/color][color=#007700]As [/color][COLOR=#0000bb]IDbConnection
        [/COLOR][color=#007700]Private [/color][color=#0000bb]idataReader [/color][color=#007700]As [/color][COLOR=#0000bb]IDataReader
        [/COLOR][color=#007700]Private [/color][color=#0000bb]iDbCommand [/color][color=#007700]As [/color][COLOR=#0000bb]IDbCommand
        [/COLOR][color=#007700]Private [/color][color=#0000bb]providerType_Renamed [/color][color=#007700]As [/color][COLOR=#0000bb]DataProvider
        [/COLOR][color=#007700]Private [/color][color=#0000bb]idbTransaction [/color][color=#007700]As [/color][color=#0000bb]IDbTransaction [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
        [/COLOR][color=#007700]Private [/color][color=#0000bb]idbParameters [/color][color=#007700]As [/color][color=#0000bb]IDbDataParameter[/color][color=#007700]() = [/color][COLOR=#0000bb]Nothing
        [/COLOR][color=#007700]Private [/color][color=#0000bb]strConnection [/color][color=#007700]As [/color][COLOR=#0000bb]String

        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub [/color][COLOR=#007700]New()

        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub [/color][color=#007700]New([/color][color=#0000bb]ByVal providerType_Renamed [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]providerType_Renamed [/color][color=#007700]= [/color][COLOR=#0000bb]providerType_Renamed
        End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub [/color][color=#007700]New([/color][color=#0000bb]ByVal providerType_Renamed [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][color=#007700], [/color][color=#0000bb]ByVal ConnectionString [/color][color=#007700]As [/color][color=#0000bb]String[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]providerType_Renamed [/color][color=#007700]= [/color][COLOR=#0000bb]providerType_Renamed
            Me[/COLOR][color=#007700].[/color][color=#0000bb]strConnection [/color][color=#007700]= [/color][COLOR=#0000bb]ConnectionString
        End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]ReadOnly Property Connection[/color][color=#007700]() As [/color][color=#0000bb]IDbConnection [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]Connection
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]idbConnection

            End Get
        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Property DataReader[/color][color=#007700]() As [/color][color=#0000bb]IDataReader [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]DataReader
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]idataReader

            End Get
            Set[/COLOR][color=#007700]([/color][color=#0000bb]ByVal value [/color][color=#007700]As [/color][color=#0000bb]IDataReader[/color][COLOR=#007700])
                [/COLOR][color=#0000bb]idataReader [/color][color=#007700]= [/color][COLOR=#0000bb]value
            End Set
        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Property ProviderType[/color][color=#007700]() As [/color][color=#0000bb]DataProvider [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ProviderType
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]providerType_Renamed
            End Get
            Set[/COLOR][color=#007700]([/color][color=#0000bb]ByVal value [/color][color=#007700]As [/color][color=#0000bb]DataProvider[/color][COLOR=#007700])
                [/COLOR][color=#0000bb]providerType_Renamed [/color][color=#007700]= [/color][COLOR=#0000bb]value
            End Set

        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Property ConnectionString[/color][color=#007700]() As [/color][color=#0000bb]String [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ConnectionString
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]strConnection
            End Get
            Set[/COLOR][color=#007700]([/color][color=#0000bb]ByVal value [/color][color=#007700]As [/color][color=#0000bb]String[/color][COLOR=#007700])
                [/COLOR][color=#0000bb]strConnection [/color][color=#007700]= [/color][COLOR=#0000bb]value
            End Set

        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]ReadOnly Property Command[/color][color=#007700]() As [/color][color=#0000bb]IDbCommand [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]Command
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]iDbCommand
            End Get
        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]ReadOnly Property Transaction[/color][color=#007700]() As [/color][color=#0000bb]IDbTransaction [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]Transaction
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]idbTransaction
            End Get
        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]ReadOnly Property Parameters[/color][color=#007700]() As [/color][color=#0000bb]IDbDataParameter[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]Parameters
            Get
                [/COLOR][color=#007700]Return [/color][COLOR=#0000bb]idbParameters
            End Get
        End Property
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub Open[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]Open
            idbConnection [/COLOR][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetConnection[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]idbConnection[/color][color=#007700].[/color][color=#0000bb]ConnectionString [/color][color=#007700]= [/color][color=#0000bb]Me[/color][color=#007700].[/color][COLOR=#0000bb]ConnectionString
            [/COLOR][color=#007700]If [/color][color=#0000bb]idbConnection[/color][color=#007700].[/color][color=#0000bb]State [/color][color=#007700]<> [/color][color=#0000bb]ConnectionState[/color][color=#007700].[/color][COLOR=#0000bb]Open Then
                idbConnection[/COLOR][color=#007700].[/color][color=#0000bb]Open[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])

        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub Close[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]close
            [/COLOR][color=#007700]If [/color][color=#0000bb]idbConnection[/color][color=#007700].[/color][color=#0000bb]State [/color][color=#007700]<> [/color][color=#0000bb]ConnectionState[/color][color=#007700].[/color][COLOR=#0000bb]Closed Then
                idbConnection[/COLOR][color=#007700].[/color][color=#0000bb]Close[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If

        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub Dispose[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][color=#0000bb]Dispose[/color][color=#007700], [/color][color=#0000bb]IDisposable[/color][color=#007700].[/color][COLOR=#0000bb]Dispose
            GC[/COLOR][color=#007700].[/color][color=#0000bb]SuppressFinalize[/color][color=#007700]([/color][color=#0000bb]Me[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Close[/color][COLOR=#007700]()
             [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Command [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
            Me[/COLOR][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
            Me[/COLOR][color=#007700].[/color][color=#0000bb]idbTransaction [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
            Me[/COLOR][color=#007700].[/color][color=#0000bb]idbConnection [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
        End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub CreateParameters[/color][color=#007700]([/color][color=#0000bb]ByVal paramsCount [/color][color=#007700]As [/color][color=#0000bb]Integer[/color][color=#007700]) Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]CreateParameters
            idbParameters [/COLOR][color=#007700]= New [/color][color=#0000bb]IDbDataParameter[/color][color=#007700]([/color][color=#0000bb]paramsCount [/color][color=#007700]- [/color][color=#0000bb]1[/color][COLOR=#007700]) {}
            [/COLOR][color=#0000bb]idbParameters [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetParameters[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][color=#007700], [/color][color=#0000bb]paramsCount[/color][COLOR=#007700])

        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub AddParameters[/color][color=#007700]([/color][color=#0000bb]ByVal index [/color][color=#007700]As [/color][color=#0000bb]Integer[/color][color=#007700], [/color][color=#0000bb]ByVal paramName [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700], [/color][color=#0000bb]ByVal objValue [/color][color=#007700]As [/color][color=#0000bb]Object[/color][color=#007700]) Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]AddParameters
            [/COLOR][color=#007700]If [/color][color=#0000bb]index [/color][color=#007700]< [/color][color=#0000bb]idbParameters[/color][color=#007700].[/color][COLOR=#0000bb]Length Then
                idbParameters[/COLOR][color=#007700]([/color][color=#0000bb]index[/color][color=#007700]).[/color][color=#0000bb]ParameterName [/color][color=#007700]= [/color][COLOR=#0000bb]paramName
                idbParameters[/COLOR][color=#007700]([/color][color=#0000bb]index[/color][color=#007700]).[/color][color=#0000bb]Value [/color][color=#007700]= [/color][COLOR=#0000bb]objValue
            End [/COLOR][COLOR=#007700]If
        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub BeginTransaction[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]BeginTransaction
            [/COLOR][color=#007700]If [/color][color=#0000bb]Me[/color][color=#007700].[/color][COLOR=#0000bb]idbTransaction Is Nothing Then
                idbTransaction [/COLOR][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetTransaction[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Transaction [/color][color=#007700]= [/color][COLOR=#0000bb]idbTransaction
        End Sub
        [/COLOR][color=#007700]Public [/color][color=#0000bb]Sub CommitTransaction[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]CommitTransaction
            [/COLOR][color=#007700]If [/color][color=#0000bb]Not Me[/color][color=#007700].[/color][COLOR=#0000bb]idbTransaction Is Nothing Then
                Me[/COLOR][color=#007700].[/color][color=#0000bb]idbTransaction[/color][color=#007700].[/color][color=#0000bb]Commit[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If
            [/COLOR][color=#0000bb]idbTransaction [/color][color=#007700]= [/color][COLOR=#0000bb]Nothing
        End Sub

        [/COLOR][color=#007700]Public Function [/color][color=#0000bb]ExecuteReader[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][color=#0000bb]IDataReader [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ExecuteReader
            Me[/COLOR][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Connection [/color][color=#007700]= [/color][color=#0000bb]Me[/color][color=#007700].[/color][COLOR=#0000bb]Connection
            PrepareCommand[/COLOR][color=#007700]([/color][color=#0000bb]iDbCommand[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Connection[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Transaction[/color][color=#007700], [/color][color=#0000bb]commandType[/color][color=#007700], [/color][color=#0000bb]commandText[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]DataReader [/color][color=#007700]= [/color][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]ExecuteReader[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][color=#007700].[/color][color=#0000bb]Clear[/color][COLOR=#007700]()
            Return [/COLOR][color=#0000bb]Me[/color][color=#007700].[/color][COLOR=#0000bb]DataReader
        End [/COLOR][COLOR=#007700]Function
        Public [/COLOR][color=#0000bb]Sub CloseReader[/color][color=#007700]() Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]CloseReader
            [/COLOR][color=#007700]If [/color][color=#0000bb]Not Me[/color][color=#007700].[/color][COLOR=#0000bb]DataReader Is Nothing Then
                Me[/COLOR][color=#007700].[/color][color=#0000bb]DataReader[/color][color=#007700].[/color][color=#0000bb]Close[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If
        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Private [/color][color=#0000bb]Sub AttachParameters[/color][color=#007700]([/color][color=#0000bb]ByVal command [/color][color=#007700]As [/color][color=#0000bb]IDbCommand[/color][color=#007700], [/color][color=#0000bb]ByVal commandParameters [/color][color=#007700]As [/color][color=#0000bb]IDbDataAdapter[/color][COLOR=#007700]())
            For [/COLOR][color=#0000bb]Each idbParameter [/color][color=#007700]As [/color][COLOR=#0000bb]IDbDataParameter In commandParameters
                [/COLOR][color=#007700]If ([/color][color=#0000bb]idbParameter[/color][color=#007700].[/color][color=#0000bb]Direction [/color][color=#007700]= [/color][color=#0000bb]ParameterDirection[/color][color=#007700].[/color][color=#0000bb]InputOutput[/color][color=#007700]) [/color][color=#0000bb]AndAlso [/color][color=#007700]([/color][color=#0000bb]idbParameter[/color][color=#007700].[/color][color=#0000bb]Value Is Nothing[/color][color=#007700]) [/color][COLOR=#0000bb]Then
                    idbParameter[/COLOR][color=#007700].[/color][color=#0000bb]Value [/color][color=#007700]= [/color][color=#0000bb]DBNull[/color][color=#007700].[/color][COLOR=#0000bb]Value
                End [/COLOR][COLOR=#007700]If
                [/COLOR][color=#0000bb]command[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][color=#007700].[/color][color=#0000bb]Add[/color][color=#007700]([/color][color=#0000bb]idbParameter[/color][COLOR=#007700])
            [/COLOR][COLOR=#0000bb]Next idbParameter
        End Sub
        [/COLOR][color=#007700]Private [/color][color=#0000bb]Sub PrepareCommand[/color][color=#007700]([/color][color=#0000bb]ByVal command [/color][color=#007700]As [/color][color=#0000bb]IDbCommand[/color][color=#007700], [/color][color=#0000bb]ByVal connection [/color][color=#007700]As [/color][color=#0000bb]IDbConnection[/color][color=#007700], [/color][color=#0000bb]ByVal transaction [/color][color=#007700]As [/color][color=#0000bb]IDbTransaction[/color][color=#007700], [/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700], [/color][color=#0000bb]ByVal commandParameters [/color][color=#007700]As [/color][color=#0000bb]IDbDataParameter[/color][COLOR=#007700]())
            [/COLOR][color=#0000bb]command[/color][color=#007700].[/color][color=#0000bb]Connection [/color][color=#007700]= [/color][COLOR=#0000bb]connection
            command[/COLOR][color=#007700].[/color][color=#0000bb]CommandText [/color][color=#007700]= [/color][COLOR=#0000bb]commandText
            command[/COLOR][color=#007700].[/color][color=#0000bb]CommandType [/color][color=#007700]= [/color][COLOR=#0000bb]commandType

            [/COLOR][color=#007700]If [/color][COLOR=#0000bb]Not transaction Is Nothing Then
                command[/COLOR][color=#007700].[/color][color=#0000bb]Transaction [/color][color=#007700]= [/color][COLOR=#0000bb]transaction
            End [/COLOR][COLOR=#007700]If
            If [/COLOR][COLOR=#0000bb]Not commandParameters Is Nothing Then
                AttachParameters[/COLOR][color=#007700]([/color][color=#0000bb]command[/color][color=#007700], [/color][color=#0000bb]commandParameters[/color][COLOR=#007700])

            [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If
        [/COLOR][COLOR=#0000bb]End Sub
        [/COLOR][color=#007700]Public Function [/color][color=#0000bb]ExecuteNonQuery[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][color=#0000bb]Integer [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ExecuteNonQuery
            Me[/COLOR][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]PrepareCommand[/color][color=#007700]([/color][color=#0000bb]iDbCommand[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Connection[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Transaction[/color][color=#007700], [/color][color=#0000bb]commandType[/color][color=#007700], [/color][color=#0000bb]commandText[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]parameters[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Dim returnvalue [/color][color=#007700]As [/color][color=#0000bb]Object [/color][color=#007700]= [/color][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]ExecuteScalar[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][color=#007700].[/color][color=#0000bb]Clear[/color][COLOR=#007700]()
            Return [/COLOR][COLOR=#0000bb]returnvalue

        End [/COLOR][COLOR=#007700]Function
        Public Function [/COLOR][color=#0000bb]ExecuteScalar[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][color=#0000bb]Object [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ExecuteScalar
            Me[/COLOR][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]PrepareCommand[/color][color=#007700]([/color][color=#0000bb]iDbCommand[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Connection[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]Transaction[/color][color=#007700], [/color][color=#0000bb]commandType[/color][color=#007700], [/color][color=#0000bb]commandText[/color][color=#007700], [/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]parameters[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Dim returnvalue [/color][color=#007700]As [/color][color=#0000bb]Object [/color][color=#007700]= [/color][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]ExecuteScalar[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][color=#007700].[/color][color=#0000bb]Clear[/color][COLOR=#007700]()
            Return [/COLOR][COLOR=#0000bb]returnvalue

        End [/COLOR][COLOR=#007700]Function
        Public Function [/COLOR][color=#0000bb]ExecuteDataSet[/color][color=#007700]([/color][color=#0000bb]ByVal commandType [/color][color=#007700]As [/color][color=#0000bb]CommandType[/color][color=#007700], [/color][color=#0000bb]ByVal commandText [/color][color=#007700]As [/color][color=#0000bb]String[/color][color=#007700]) As [/color][color=#0000bb]DataSet [/color][color=#007700]Implements [/color][color=#0000bb]IDBManager[/color][color=#007700].[/color][COLOR=#0000bb]ExecuteDataset

            Me[/COLOR][color=#007700].[/color][color=#0000bb]iDbCommand [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetCommand[/color][color=#007700]([/color][color=#0000bb]Me[/color][color=#007700].[/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]PrepareCommand[/color][color=#007700]([/color][color=#0000bb]iDbCommand[/color][color=#007700], [/color][color=#0000bb]Connection[/color][color=#007700], [/color][color=#0000bb]Transaction[/color][color=#007700], [/color][color=#0000bb]commandType[/color][color=#007700], [/color][color=#0000bb]commandText[/color][color=#007700], [/color][color=#0000bb]parameters[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]Dim dataAdapter [/color][color=#007700]As [/color][color=#0000bb]IDbDataAdapter [/color][color=#007700]= [/color][color=#0000bb]DBManagerFactory[/color][color=#007700].[/color][color=#0000bb]GetDataAdapter[/color][color=#007700]([/color][color=#0000bb]ProviderType[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]dataAdapter[/color][color=#007700].[/color][color=#0000bb]SelectCommand [/color][color=#007700]= [/color][COLOR=#0000bb]iDbCommand
            Dim dataset [/COLOR][color=#007700]As [/color][color=#0000bb]DataSet [/color][color=#007700]= New [/color][color=#0000bb]DataSet[/color][COLOR=#007700]()
            [/COLOR][color=#0000bb]dataAdapter[/color][color=#007700].[/color][color=#0000bb]Fill[/color][color=#007700]([/color][color=#0000bb]dataset[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]iDbCommand[/color][color=#007700].[/color][color=#0000bb]Parameters[/color][color=#007700].[/color][color=#0000bb]Clear[/color][COLOR=#007700]()
            Return [/COLOR][COLOR=#0000bb]dataset
        End [/COLOR][COLOR=#007700]Function

    [/COLOR][color=#0000bb]End [/color][COLOR=#007700]Class



[/COLOR][COLOR=#0000bb]End Namespace  
[/COLOR][/COLOR]
}}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كلاس تصوير الويبكام RaggiTech 0 404 17-10-12, 08:58 PM
آخر رد: RaggiTech
  كود خاص لمعرفة كلمة السر لملفات Access 97 RaggiTech 0 356 17-10-12, 05:14 PM
آخر رد: RaggiTech
  عمل Microsft Data Access وقت التنفيذ RaggiTech 0 232 17-10-12, 05:11 PM
آخر رد: RaggiTech
  كلاس لعدة تعاملات مع الداتا بيز(فتح و غلق الأتصال..سيليكت...و انسيرت ...) RaggiTech 0 506 09-10-12, 05:50 PM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم