Страница: 1 |
|
Вопрос: ПОМОГИТЕ найти класс
|
Добавлено: 05.02.05 19:24
|
|
Автор вопроса: re_alexis
|
Народ как то давно я с этого сайта скачивал класс clsBODT.cls, и вот я принес проект домой и забыл этот самый класс а теперь не могу его найти если кто знает где он лежит кинте плз урлу
За ранее благодарен!
Ответить
|
Номер ответа: 2 Автор ответа: AlexF
Вопросов: 20 Ответов: 113
|
Профиль | | #2
|
Добавлено: 06.02.05 10:59
|
Ne znayu, tot li eto, chto tebe nado, no ispol'zuyu takoj klass. Vrode est' vse dlya raboty s BD :
Option Explicit
Private m_strFileName As String
'Private m_strConnect As String
' Win32api function which retrieves data from INI FILE
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
' Win32api function which updates data in INI FILE
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function ExecuteSQL(ByVal strSQL As String, Optional strConnect As String = "" As Long
'*****************************************************
' Purpose: This Function updates data in DB
' Inputs: strSQL As String - string SQL
' strConnect(optional) - connection string
' Returns: 0 if succeeded, error number if failed
' Subject: Added error logging functionality
'*****************************************************
On Error GoTo err_hndl
 im conn As Object
' Open connection
If Len(strConnect) = 0 Then strConnect = GetConnectionString(m_strFileName)
Set conn = ConnectDB(strConnect)
If Not (conn Is Nothing) Then
'Execute SQL in the data store
conn.BeginTrans
conn.Execute strSQL
'If succeeded then commit changes
conn.CommitTrans
ExecuteSQL = 0
'Close connection to data store
 isconnectDB conn
Else
ExecuteSQL = -1
End If
Exit Function
err_hndl:
ExecuteSQL = Abs(Err.Number) * -1
LogEvent strSQL, Err.Source & ": Error " & Err.Number & ": " & Err.Description
conn.RollbackTrans
If Not (conn Is Nothing) Then DisconnectDB conn
End Function
Public Function ExecuteSQLReturnIdentity(ByVal strSQL As String, Optional strConnect As String = "" As Long
'*****************************************************
' Purpose: This Function updates data in DB
' Inputs: strSQL As String - string SQL
' strConnect(optional) - connection string
' Returns: identity if succeeded, error number if failed
' Subject: Added error logging functionality
'*****************************************************
On Error GoTo err_hndl
 im conn As Object
 im rs As Object
' Open connection
If Len(strConnect) = 0 Then strConnect = GetConnectionString(m_strFileName)
Set conn = ConnectDB(strConnect)
If Not (conn Is Nothing) Then
'Execute SQL in the data store
conn.BeginTrans
conn.Execute strSQL
'If succeeded then get identity
Set rs = conn.Execute("SELECT @@IDENTITY"
ExecuteSQLReturnIdentity = Val(rs.Fields(0).Value & ""
'commit changes
conn.CommitTrans
'Close connection to data store
Set rs = Nothing
 isconnectDB conn
Else
ExecuteSQLReturnIdentity = -1
End If
Exit Function
err_hndl:
ExecuteSQLReturnIdentity = Abs(Err.Number) * -1
LogEvent strSQL, Err.Source & ": Error " & Err.Number & ": " & Err.Description
conn.RollbackTrans
Set rs = Nothing
If Not (conn Is Nothing) Then DisconnectDB conn
End Function
Private Function ConnectDB(ByVal strConnect As String) As Object
'*****************************************************
' Purpose: This sub creates connection to DB
' Returns:
' Subject: parameter m_strConnect removed from function call
'*****************************************************
On Error GoTo err_hndl
 im conn As Object
Set conn = CreateObject("ADODB.Connection"
conn.Provider = "MSDataShape"
conn.Open strConnect
Set ConnectDB = conn
Exit Function
err_hndl:
LogEvent "Conn.open " & strConnect, Err.Source & ": Error " & Err.Number & ": " & Err.Description
Set conn = Nothing
End Function
Private Sub DisconnectDB(conn)
'*****************************************************
' Purpose: This Procedure closes connection to DB
' Inputs: Connection
' Returns:
' Subject: Code tuning and optimization
'*****************************************************
'If object of connection exists then destroy its instance
On Error Resume Next
If Not (conn Is Nothing) Then
conn.Close
Set conn = Nothing
End If
Exit Sub
End Sub
Public Function ExecuteSQLReturnRS(ByVal strSQL As String, Optional strConnect As String = "" As Object
'*****************************************************
' Purpose: This function returns recordset containing
' fields from provided SQL
' Receives: strSQL - query to be executed
' strConnect(optional) - connection string
' Returns: Disconnected ADO recordset
' Subject: Added error logging functionality
'*****************************************************
On Local Error GoTo err_hndl
 im conn As Object
 im rsResult As Object
'Connect to database and create recordset with result data
If Len(strConnect) = 0 Then strConnect = GetConnectionString(m_strFileName)
Set conn = ConnectDB(strConnect)
If Not (conn Is Nothing) Then
Set rsResult = CreateObject("ADODB.Recordset"
rsResult.StayInSync = True 'In case of shaped RS
rsResult.CursorLocation = 3 'adUseClient
rsResult.LockType = 4 'adLockBatchOptimistic
rsResult.Open strSQL, conn
'Make rsResult disconnected and return as function value
Set rsResult.ActiveConnection = Nothing
Set ExecuteSQLReturnRS = rsResult
'Close connection to DB
 isconnectDB conn
End If
Exit Function
err_hndl:
LogEvent strSQL, Err.Source & ": Error " & Err.Number & ": " & Err.Description
Set ExecuteSQLReturnRS = Nothing
If Not (conn Is Nothing) Then DisconnectDB conn
End Function
Private Sub Class_Initialize()
m_strFileName = App.Path & "\System.ini"
'm_strConnect = GetConnectionString(m_strFileName)
End Sub
Public Function GetConnectionString(strIniFileName As String) As String
'****************************************************************************
' Purpose: Reads data from ini file and builds connection string
' Inputs: FileName - Name of INI FILE to be searched.
' Returns: Connection string
' Subject:
'****************************************************************************
On Error GoTo err_hndl
GetConnectionString = GetIniString(m_strFileName, "CONNECT", "CONNECTSTRING"
Exit Function
err_hndl:
GetConnectionString = Err.Number
End Function
Private Function GetLogFileName(strIniFileName As String) As String
'****************************************************************************
' Purpose: Reads data from ini file and builds connection string
' Inputs: FileName - Name of INI FILE to be searched.
' Returns: Connection string
' Subject:
'****************************************************************************
On Error GoTo err_hndl
 im strTemp As String
'Get data provider
GetLogFileName = GetIniString(m_strFileName, "LOG", "LOGFILE"
Exit Function
err_hndl:
GetLogFileName = ""
End Function
Public Function SaveIniString(FileName As String, ByVal Section As String, ByVal SectionPart As String, ByVal Value As Variant) As Long
'****************************************************************************
' Purpose: saves data to INI FILE
' Inputs: FileName - Name of INI FILE to be searched.
' Section - Name of Section in INI FILE to be searched.
' SectionPart - which Part in Section of INI FILE to be searched.
' Value - Value of SectionPart to be updated.
' Returns: True if update succeeded, False if failed
' Subject: Code optimization
'****************************************************************************
On Error GoTo err_hndl
If Len(FileName) = 0 Then FileName = m_strFileName
SaveIniString = WritePrivateProfileString(Section, SectionPart, CStr(Value), FileName)
Exit Function
err_hndl:
SaveIniString = Err.Number
End Function
Public Function GetIniString(FileName As String, ByVal Section As String, ByVal SectionPart As String) As String
'****************************************************************************
' Purpose: retrieves data from INI FILE
' Inputs: FileName - Name of INI FILE to be searched.
' Section - Name of Section in INI FILE to be searched.
' SectionPart - which Part in Section of INI FILE to be searched.
' Returns: Returns Value of searched SectionPart.
' Subject: Code optimization
'****************************************************************************
Dim lngResult As Long
Dim strTemp1 As String
On Error GoTo err_hndl
strTemp1 = Space$(500)
If Len(FileName) = 0 Then FileName = m_strFileName
lngResult = GetPrivateProfileString(Section, SectionPart, "", strTemp1, 500, FileName)
strTemp1 = Trim$(strTemp1 & ""
GetIniString = CStr(LCase$(Left$(strTemp1, lngResult)))
Exit Function
err_hndl:
GetIniString = Err.Number
End Function
Private Sub LogEvent(strSQL As String, strResult As String)
'****************************************************************************
' Purpose: Logs result of operation into text file
' Inputs: strSQL - sqlThat attempted to be executed
' strResult - string with result of the execution
' Returns: Returns Value of searched SectionPart.
' Subject: Code optimization
'****************************************************************************
On Error GoTo err_hndl
 im ff As Long
 im strLogFile As String
ff = FreeFile
'Get the name of log file
strLogFile = GetLogFileName(m_strFileName)
Open strLogFile For Append As #ff
Print #ff, Now
Print #ff, strSQL & vbCrLf
Print #ff, strResult
Close #ff
Exit Sub
err_hndl:
Err.Number = 0
End Sub
Public Function GetData(ByVal strFields As String, _
ByVal strTables As String, ByVal strScope As String, _
Optional blnTestMode As Boolean, Optional strConnect As String = "" As Object
'*****************************************************
' Purpose: This function returns recordset containing
' fields from provided list
' Receives: strFields - list of fields to return
' strTables - from which tables to retrieve
' strScope - selection condition
' Returns: Disconnected ADO recordset
' Subject: Added error logging functionality
'*****************************************************
'IMPORTANT!!! This function has been replaced by
'ExecuteSQLReturnRS and is present for compatibility
'purposes only! Avoid using it!!!
'*****************************************************
On Local Error GoTo err_hndl
 im strSQL As String
 im rsResult As Object
 im conn As Object
'Build primary sql string
strSQL = "SELECT " & strFields & " FROM " & strTables
'If scope is set then add it to sql
If Not IsMissing(strScope) And Len(strScope) > 0 Then
strSQL = strSQL & " WHERE " & strScope
End If
'Connect to database and create recordset with result data
Set conn = ConnectDB(strConnect)
If Not (conn Is Nothing) Then
Set rsResult = CreateObject("ADODB.Recordset"
rsResult.CursorLocation = 3 'adUseClient
rsResult.LockType = 4 'adLockBatchOptimistic
rsResult.Open strSQL, conn
'Make rsResult disconnected and return as function value
Set rsResult.ActiveConnection = Nothing
Set GetData = rsResult
'Close connection to DB
 isconnectDB conn
'If test mode is requested then create log file for this operation
If Not IsMissing(blnTestMode) And blnTestMode = True Then
LogEvent strSQL, "OK"
End If
End If
Exit Function
err_hndl:
LogEvent strSQL, Err.Source & ": Error " & Err.Number & ": " & Err.Description
If Not (conn Is Nothing) Then DisconnectDB conn
End Function
Ответить
|
Страница: 1 |
Поиск по форуму