⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employee.cls

📁 完整的三层数据库应用程序
💻 CLS
📖 第 1 页 / 共 3 页
字号:
VERSION 1.0 CLASS
Begin      
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
End    

Attribute VB_Name = Employee
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Implements COMEXDataSourceSingle      
Private m_Fields() 
Public Event OnRecordSaved(byRef aEmployee As Employee)
Public Event OnRecordMarkForDelete(byRef aEmployee As Employee)
Public Event OnDirty(byVal IsDirty As Boolean)
Public Event OnRecordLoad(byRef aEmployee As Employee)

Private WithEvents mobjValid As BrokenRules
Event Valid(ByVal IsValid As Boolean)
Private m_Address As String
Private m_BillingRate As Currency
Private m_City As String
Private m_Country As String
Private m_EmployeeID As Long
Private m_Extension As String
Private m_FirstName As String
Private m_LastName As String
Private m_PostalCode As String
Private m_StateOrProvince As String
Private m_Title As String
Private m_WorkPhone As String
Private m_OldEmployeeID As Long
Private m_IsNew As Boolean
Private m_IsDirty As Boolean
Private m_IsDeleted As Boolean

Private m_TimeCards As TimeCards
	      

Friend Property Let IsNew(Byval vData As boolean)
  m_IsNew = vData
End Property

Public Property Get IsNew() As Boolean
  IsNew = m_IsNew
End Property

Friend Property Let IsDirty(Byval vData As boolean)
  m_IsDirty = vData
  RaiseEvent OnDirty(vData)
End Property

Public Property Get IsDirty() As Boolean
  IsDirty = m_IsDirty
End Property

Friend Property Let IsDeleted(Byval vData As boolean)
  m_IsDeleted = vData
  RaiseEvent OnRecordMarkForDelete(Me) 
End Property

Public Property Get IsDeleted() As Boolean
  IsDeleted = m_IsDeleted
End Property    

Public Property Get IsValid() As Boolean
  IsValid = (mobjValid.Count = 0)
End Property

Private Sub mobjValid_BrokenRule()
  RaiseEvent Valid(False)
End Sub

Private Sub mobjValid_NoBrokenRules()
  RaiseEvent Valid(True)
End Sub
'******************************************************************************
'Begin property get/let/set                                                   *
'******************************************************************************

Friend Property Let OldEmployeeID(vData As Long)
  m_OldEmployeeID = vData
End Property

Public Property Let Address (vData As String)
  m_Address = vData 	
  IsDirty = True
End Property

Public Property Get Address() As String
  Address = m_Address
End Property


Public Property Let BillingRate (vData As Currency)
  m_BillingRate = vData 	
  IsDirty = True
End Property

Public Property Get BillingRate() As Currency
  BillingRate = m_BillingRate
End Property


Public Property Let City (vData As String)
  m_City = vData 	
  IsDirty = True
End Property

Public Property Get City() As String
  City = m_City
End Property


Public Property Let Country (vData As String)
  m_Country = vData 	
  IsDirty = True
End Property

Public Property Get Country() As String
  Country = m_Country
End Property


Public Property Let EmployeeID (vData As Long)
  m_EmployeeID = vData 	
  IsDirty = True
End Property

Public Property Get EmployeeID() As Long
  EmployeeID = m_EmployeeID
End Property


Public Property Let Extension (vData As String)
  m_Extension = vData 	
  IsDirty = True
End Property

Public Property Get Extension() As String
  Extension = m_Extension
End Property


Public Property Let FirstName (vData As String)
  m_FirstName = vData 	
  IsDirty = True
End Property

Public Property Get FirstName() As String
  FirstName = m_FirstName
End Property


Public Property Let LastName (vData As String)
  m_LastName = vData 	
  IsDirty = True
End Property

Public Property Get LastName() As String
  LastName = m_LastName
End Property


Public Property Let PostalCode (vData As String)
  m_PostalCode = vData 	
  IsDirty = True
End Property

Public Property Get PostalCode() As String
  PostalCode = m_PostalCode
End Property


Public Property Let StateOrProvince (vData As String)
  m_StateOrProvince = vData 	
  IsDirty = True
End Property

Public Property Get StateOrProvince() As String
  StateOrProvince = m_StateOrProvince
End Property


Public Property Let Title (vData As String)
  m_Title = vData 	
  IsDirty = True
End Property

Public Property Get Title() As String
  Title = m_Title
End Property


Public Property Let WorkPhone (vData As String)
  m_WorkPhone = vData 	
  IsDirty = True
End Property

Public Property Get WorkPhone() As String
  WorkPhone = m_WorkPhone
End Property


Public Property Set TimeCards(vData As TimeCards)
  Set m_TimeCards = vData
End Property

Public Property Get TimeCards() As TimeCards
  Set TimeCards  = m_TimeCards
End Property
'******************************************************************************
'End property get/let/set                                                     *
'******************************************************************************	

'******************************************************************************
'*                                                                            *
'* Name:    Clear                                                             *
'*                                                                            *
'* Purpose: Reset this object and initialize data to default.                 *
'*                                                                            *
'******************************************************************************
Public Sub Clear() 
  m_IsNew = True
  m_IsDirty = False
  m_IsDeleted = False 

  m_Address = vbnullstring
  m_BillingRate = 0
  m_City = vbnullstring
  m_Country = vbnullstring
  m_EmployeeID = 0
  m_Extension = vbnullstring
  m_FirstName = vbnullstring
  m_LastName = vbnullstring
  m_PostalCode = vbnullstring
  m_StateOrProvince = vbnullstring
  m_Title = vbnullstring
  m_WorkPhone = vbnullstring
  Set m_TimeCards = Nothing
  Set m_TimeCards =  New TimeCards


  Set mobjValid = New BrokenRules
  ReSetBrokenRule True 
End Sub	


Public Sub ReSetBrokenRule(byval BrokenAll As boolean)  
  Dim vTimeCard As TimeCard
  For Each vTimeCard In m_TimeCards
  	vTimeCard.ReSetBrokenRule BrokenAll
  Next
End Sub


Private Sub Class_Initialize()
  Clear
  m_Fields = Array("Address", "BillingRate", "City", "Country", "EmployeeID", "Extension", "FirstName", "LastName", "PostalCode", "StateOrProvince", "Title", "WorkPhone")  
End Sub
Private Sub Class_Terminate()
  Clear
End Sub

'******************************************************************************
'*                                                                            *
'* Name:    Save                                                              *
'*                                                                            *
'* Purpose: Save a changed object or a new record into database.              *
'*                                                                            *
'* Returns: True when successfully saved, false when failed to save.          *
'*                                                                            *
'******************************************************************************
Public Function Save(optional Byval bolStartTran As boolean = True) As Boolean   
  Dim adoRS As ADODB.Recordset
  Dim strSQL As String
  Dim Count As Long, i As Long, bolInTran As boolean 
  
  On Error GoTo Err_Save
  
  If Not IsDirty Then GoTo Skip_Save
  
                 
  If Not IsValid Then 
    InvalidHandler(mobjValid.BrokenRules)
    GoTo Done_Save
  End If
  
  If bolStartTran Then 
    Conn.BeginTrans  
    bolInTran = True
  End If
  
  Set adoRS = New ADODB.Recordset  

  strSQL ="Select * FROM Employees a WHERE  a.EmployeeID=" & m_OldEmployeeID & ""
  adoRS.Open strSQL , Conn, adOpenKeyset, adLockOptimistic
  With adoRS
  If Not .EOF Then
    If m_IsDeleted Then
      .Delete

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -