VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CAuthor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'download by http://www.codefans.net
Private m_lngAuID As Long
Private m_strAuthorName As String
Private m_intYearBorn As Integer
Private m_dcnDB As ADODB.Connection
Public Event ValidData()
Public Event InvalidData(strReason As String)
Public Property Let YearBorn(ByVal vData As Integer)
    m_intYearBorn = vData
End Property


Public Property Get YearBorn() As Integer
    YearBorn = m_intYearBorn
End Property



Public Property Let AuthorName(ByVal vData As String)
    m_strAuthorName = vData
End Property


Public Property Get AuthorName() As String
    AuthorName = m_strAuthorName
End Property



Public Property Let AuID(ByVal vData As Long)
    m_lngAuID = vData
End Property


Public Property Get AuID() As Long
    AuID = m_lngAuID
End Property

Public Sub Init(dcnDB As ADODB.Connection, Optional lngID As Long = -1)
    Dim strSQL As String
    Dim rsData As ADODB.Recordset
    
    Set m_dcnDB = dcnDB
    If lngID = -1 Then Exit Sub
    
    strSQL = "select * from Authors where Au_ID=" & lngID
    Set rsData = m_dcnDB.Execute(strSQL)
    If Not rsData.EOF Then
        m_lngAuID = rsData("Au_ID")
        m_strAuthorName = rsData("Author") & ""
        If Not IsNull(rsData("Year Born")) Then
            m_intYearBorn = CInt(rsData("Year Born"))
        End If
    End If
    rsData.Close
    Set rsData = Nothing
End Sub



Public Sub Save()
    Dim strSQL As String
    Dim rsData As ADODB.Recordset
    
    If m_strAuthorName = "" Then
        RaiseEvent InvalidData("Author name is missing.")
        Exit Sub
    End If
    
    strSQL = "select *from Authors"
    If m_lngAuID <> 0 Then
        strSQL = strSQL & " where Au_ID=" & m_lngAuID
    End If
    
    Set rsData = New ADODB.Recordset
    rsData.Open strSQL, m_dcnDB, 3, 3
    
    If m_lngAuID = 0 Then
        rsData.AddNew
    End If
    rsData("Author") = m_strAuthorName
    rsData("Year Born") = m_intYearBorn
    rsData.Update
    m_lngAuID = rsData("Au_ID")
    rsData.Close
    RaiseEvent ValidData
    
    Set rsData = Nothing
End Sub
