home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / vbof / demoprsn.cls < prev    next >
Encoding:
Text File  |  1996-11-20  |  15.7 KB  |  593 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Person"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. ' the following pertain to being supported by
  11. '   VBOFCollection, VBOFObjectManager and
  12. '   VBOFEventManager
  13. Public ObjectID As Long
  14. Public ObjectChanged As Long
  15. Public ObjectAdded As Long
  16. Public ObjectDeleted As Long
  17. Public ObjectParentCount As Long
  18. Public ObjectManager As VBOFObjectManager
  19.  
  20. ' the following code pertains to the business
  21. '   of the Person object
  22. Private pvtCustomerNumber As Long
  23. Private pvtFirstName As String
  24. Private pvtLastName As String
  25. Private pvtMaidenName As String
  26. Private pvtSSN As Long
  27. Private pvtSex As String
  28. Private pvtDateOfBirth As Variant
  29. Private pvtDateOfDeath As Variant
  30. Private pvtMaritalStatus As String
  31. Private pvtAddressesCollection As VBOFCollection
  32. Private pvtPhonesCollection As VBOFCollection
  33. Private pvtMother As Person
  34. Private pvtFather As Person
  35. Private pvtSpouse As Person
  36.  
  37. Public Property Set Father(aPerson As Variant)
  38.     Set pvtFather = aPerson
  39. End Property
  40.  
  41. Public Property Set Spouse(aPerson As Variant)
  42.     Set pvtSpouse = aPerson
  43. End Property
  44.  
  45.  
  46. Public Property Get Father() As Variant
  47.     Set Father = pvtFather
  48. End Property
  49.  
  50. Public Property Get Spouse() As Variant
  51.     Set Spouse = pvtSpouse
  52. End Property
  53.  
  54.  
  55. Public Property Set Mother(aPerson As Variant)
  56.     Set pvtMother = aPerson
  57. End Property
  58.  
  59. Public Property Get Mother() As Variant
  60.     Set Mother = pvtMother
  61. End Property
  62.  
  63.  
  64. Public Function ObjectDBGridUnboundReadData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional RowNumber As Variant) As Boolean
  65. ' Populate the DBGrid RowBuf with values from
  66. '   variables within this object
  67. '   (in support of VBOFCollection)
  68. ' Parameter Description:
  69. '   DBGrid:= the DBGrid which is being
  70. '       populated
  71. '   RowBuf:= the current DBGrid RowBuf object
  72. '   RowNumber:= the row number being processed
  73.  
  74.     Dim I As Long
  75.     
  76.     For I = 0 To RowBuf.ColumnCount - 1
  77.         Select Case RowBuf.ColumnName(I)
  78.             Case "CustomerNumber"
  79.                 RowBuf.Value(RowNumber, I) = CustomerNumber
  80.             Case "FirstName"
  81.                 RowBuf.Value(RowNumber, I) = FirstName
  82.             Case "LastName"
  83.                 RowBuf.Value(RowNumber, I) = LastName
  84.             Case "MaidenName"
  85.                 RowBuf.Value(RowNumber, I) = MaidenName
  86.             Case "SSN"
  87.                 RowBuf.Value(RowNumber, I) = SSN
  88.             Case "Sex"
  89.                 RowBuf.Value(RowNumber, I) = Sex
  90.             Case "DateOfBirth"
  91.                 RowBuf.Value(RowNumber, I) = DateOfBirth
  92.             Case "DateOfDeath"
  93.                 RowBuf.Value(RowNumber, I) = DateOfDeath
  94.             Case "MaritalStatus"
  95.                 RowBuf.Value(RowNumber, I) = MaritalStatus
  96.             Case "ObjectID"
  97.                 RowBuf.Value(RowNumber, I) = ObjectID
  98.         End Select
  99.     Next I
  100.  
  101. End Function
  102. Public Function ObjectDBGridUnboundAddData(Optional DBGrid As Variant, Optional RowBuf As Variant, Optional NewRowBookmark As Variant) As Boolean
  103. ' Populate the object variables with the values
  104. '   provided by the user in the new row of the
  105. '   DBGrid
  106. '   (in support of VBOFCollection)
  107. '
  108. ' Parameter Description:
  109. '   DBGrid:= the DBGrid which is being
  110. '       populated
  111. '   RowBuf:= the current DBGrid RowBuf object
  112. '   NewRowBookmark:= the row number being processed
  113.  
  114.     Dim I As Long
  115.     
  116.     For I = 0 To RowBuf.ColumnCount - 1
  117.         If Not IsNull(RowBuf.Value(0, I)) Then
  118.             Select Case RowBuf.ColumnName(I)
  119.                 Case "CustomerNumber"
  120.                     CustomerNumber = RowBuf.Value(0, I)
  121.                 Case "FirstName"
  122.                     FirstName = RowBuf.Value(0, I)
  123.                 Case "LastName"
  124.                     LastName = RowBuf.Value(0, I)
  125.                 Case "MaidenName"
  126.                     MaidenName = RowBuf.Value(0, I)
  127.                 Case "SSN"
  128.                     SSN = RowBuf.Value(0, I)
  129.                 Case "Sex"
  130.                     Sex = RowBuf.Value(0, I)
  131.                 Case "DateOfBirth"
  132.                     DateOfBirth = RowBuf.Value(0, I)
  133.                 Case "DateOfDeath"
  134.                     DateOfDeath = RowBuf.Value(0, I)
  135.                 Case "MaritalStatus"
  136.                     MaritalStatus = RowBuf.Value(0, I)
  137.     
  138. ' Note:  Do not initialize the ObjectID.
  139.         
  140.             End Select
  141.         End If
  142.     Next I
  143.     
  144. ' return "OK" status
  145.     ObjectDBGridUnboundAddData = True
  146. End Function
  147.  
  148.  
  149. Public Function ObjectListBoxValue() As String
  150. ' Return a String will represent this object
  151. '   in a ListBox
  152. '   (in support of VBOFCollection)
  153.  
  154.     ObjectListBoxValue = _
  155.         FormattedName
  156.  
  157. End Function
  158.  
  159. Public Function PersonalInformation() As String
  160. ' Returns a string containing the formatted names
  161. '   of this person's parents or spouse
  162.  
  163.     Dim ReturnString As String
  164.     
  165.     If pvtMother Is Nothing _
  166.     And pvtFather Is Nothing _
  167.     And pvtSpouse Is Nothing _
  168.     Then
  169.         PersonalInformation = "There is no known lineage for this person"
  170.         Exit Function
  171.     End If
  172.     
  173.     ReturnString = "Personal Info: "
  174.     
  175.     If Not pvtMother Is Nothing Then
  176.         ReturnString = ReturnString & _
  177.             " Mother: " & _
  178.             pvtMother.FormattedName
  179.     End If
  180.  
  181.     If Not pvtFather Is Nothing Then
  182.         ReturnString = ReturnString & _
  183.             " Father: " & _
  184.             pvtFather.FormattedName
  185.     End If
  186.  
  187.     If Not pvtSpouse Is Nothing Then
  188.         ReturnString = ReturnString & _
  189.             " Spouse: " & _
  190.             pvtSpouse.FormattedName
  191.     End If
  192.  
  193.     PersonalInformation = ReturnString
  194. End Function
  195.  
  196. Private Sub Class_Terminate()
  197.     If Not ObjectManager Is Nothing Then
  198.         ObjectManager.TerminateObject _
  199.             Object:=Me
  200.     End If
  201. End Sub
  202.  
  203.  
  204. Public Function ObjectHasChanged()
  205. ' Mark this object as "Changed" and trigger the
  206. '   "Changed" event
  207. ' Note: if processing in SynchronousCommit mode,
  208. '   it might be advisable to execute this method
  209. '   after any of the application's properties have
  210. '   changed.  Otherwise, it might be best to have
  211. '   the application GUI execute this method after
  212. '   posting a series of property changes.
  213.  
  214.     ObjectChanged = True
  215.     
  216. #If NoEventMgr = False Then
  217.     If Not ObjectManager Is Nothing Then
  218.         ObjectManager. _
  219.             TriggerObjectEvent _
  220.                 Event:="Changed", _
  221.                 Object:=Me
  222.     End If
  223. #End If
  224.  
  225. End Function
  226.  
  227. Public Function AddPhone(Optional Item As Variant, Optional Parent As Variant) As Phone
  228. ' Return a Phone, added to my pvtPhonesCollection
  229. '   (just a wrapper method for Phones.Add)
  230.  
  231.     Set AddPhone = Me.Phones.Add( _
  232.         Item:=Item, _
  233.         Parent:=Me)
  234.  
  235.     ObjectHasChanged
  236. End Function
  237.  
  238. Public Function ObjectInitializeFromRecordSet(Optional RecordSet As Variant) As Person
  239. ' Populate my variables from the RecordSet
  240. '   (in support of VBOFCollection)
  241.  
  242.     Dim NewPerson As New Person
  243.  
  244.     On Local Error Resume Next
  245.     
  246.     CustomerNumber = RecordSet("CustomerNumber")
  247.     FirstName = RecordSet("FirstName")
  248.     LastName = RecordSet("LastName")
  249.     SSN = RecordSet("SSN")
  250.     Sex = RecordSet("Sex")
  251.     If IsNull(RecordSet("DateOfBirth")) Then
  252.         DateOfBirth = #1/1/01#
  253.     Else
  254.         DateOfBirth = RecordSet("DateOfBirth")
  255.     End If
  256.     If IsNull(RecordSet("DateOfDeath")) Then
  257.         DateOfDeath = #1/1/01#
  258.     Else
  259.         DateOfDeath = RecordSet("DateOfDeath")
  260.     End If
  261.     MaritalStatus = RecordSet("MaritalStatus")
  262.     MaidenName = RecordSet("MaidenName")
  263.     
  264.     ObjectID = RecordSet("ObjectID")
  265.     
  266. ' pick-up the Mother object
  267.     If Not IsNull(RecordSet("MotherObjectID")) Then
  268.         Set pvtMother = _
  269.             ObjectManager. _
  270.                 NewObject( _
  271.                     Sample:=NewPerson, _
  272.                     ObjectID:=CStr(RecordSet("MotherObjectID")))
  273.     End If
  274.     
  275. ' pick-up the Father object
  276.     If Not IsNull(RecordSet("FatherObjectID")) Then
  277.         Set pvtFather = _
  278.             ObjectManager. _
  279.                 NewObject( _
  280.                     Sample:=NewPerson, _
  281.                     ObjectID:=CStr(RecordSet("FatherObjectID")))
  282.     End If
  283.     
  284. ' pick-up the Spouse object
  285.     If Not IsNull(RecordSet("SpouseObjectID")) Then
  286.         Set pvtSpouse = _
  287.             ObjectManager. _
  288.                 NewObject( _
  289.                     Sample:=NewPerson, _
  290.                     ObjectID:=CStr(RecordSet("SpouseObjectID")))
  291.     End If
  292.  
  293.     Set ObjectInitializeFromRecordSet = Me
  294. End Function
  295.  
  296.  
  297. Public Function ObjectInitializeRecordSet(Optional RecordSet As Variant) As Long
  298. ' Populate the RecordSet with my variables.
  299. '   Do not initialize the ObjectID column.
  300. '   Return any error code encountered.
  301. '   (in support of VBOFCollection)
  302.  
  303.     On Local Error GoTo InitializeRecordSet_SetError
  304.     Err = 0
  305.     
  306.     RecordSet("CustomerNumber") = CustomerNumber
  307.     RecordSet("FirstName") = FirstName
  308.     RecordSet("LastName") = LastName
  309.     RecordSet("SSN") = SSN
  310.     RecordSet("Sex") = Sex
  311.     If DateOfBirth = #1/1/01# Then
  312.         RecordSet("DateOfBirth") = Null
  313.     Else
  314.         RecordSet("DateOfBirth") = Format$(DateOfBirth, "mm/dd/yyyy")
  315.     End If
  316.     If DateOfDeath = #1/1/01# Then
  317.         RecordSet("DateOfDeath") = Null
  318.     Else
  319.         RecordSet("DateOfDeath") = Format$(DateOfDeath, "mm/dd/yyyy")
  320.     End If
  321.     RecordSet("MaritalStatus") = MaritalStatus
  322.     RecordSet("MaidenName") = MaidenName
  323.     
  324. ' set the Mother object
  325.     If Not pvtMother Is Nothing Then
  326.         RecordSet("MotherObjectID") = _
  327.             pvtMother.ObjectID
  328.     Else
  329.         RecordSet("MotherObjectID") = Null
  330.     End If
  331.     
  332. ' set the Father object
  333.     If Not pvtFather Is Nothing Then
  334.         RecordSet("FatherObjectID") = _
  335.             pvtFather.ObjectID
  336.     Else
  337.         RecordSet("FatherObjectID") = Null
  338.     End If
  339.     
  340. ' set the Spouse object
  341.     If Not pvtSpouse Is Nothing Then
  342.         RecordSet("SpouseObjectID") = _
  343.             pvtSpouse.ObjectID
  344.     Else
  345.         RecordSet("SpouseObjectID") = Null
  346.     End If
  347.         
  348. ' Note:  Do not initialize the ObjectID column.
  349.  
  350.     GoTo InitializeRecordSet_SetError
  351.  
  352. InitializeRecordSet_SetError:
  353.     ObjectInitializeRecordSet = Err
  354.     Exit Function
  355. End Function
  356.  
  357. Public Function ObjectDataSource() As String
  358. ' Return the Data Source with which this Class is associated
  359. '   (in support of VBOFCollection)
  360.     
  361.     ObjectDataSource = "Persons"
  362. End Function
  363. Public Function ObjectNewInstanceOfMyClass() As Person
  364. ' Return a new instance of this class
  365. '   (in support of VBOFCollection)
  366.  
  367.     Set ObjectNewInstanceOfMyClass = New Person
  368. End Function
  369.  
  370.  
  371. Public Function ObjectEventCallBack(Optional Event As Variant, Optional Object As Variant) As Long
  372. ' Receive the Trigger notification and process
  373. '   accordingly
  374. '
  375. ' Parameters:
  376. '   Event
  377. '       a string which identifies the Event
  378. '       Example: "Changed", "Created", "Deleted"
  379. '   Object
  380. '       the object originating the Event.
  381. '       responds to:
  382. '           TypeName(TriggerObject)
  383. '           TriggerObject.ObjectID
  384. ' (supported by VBOFEventManager)
  385.  
  386. End Function
  387.  
  388.  
  389.  
  390.  
  391. Public Function AddAddress(Optional Item As Variant, Optional Parent As Variant) As Address
  392. ' Return an Address, added to my pvtAddressesCollection
  393. '   (just a wrapper method for Addresses.Add)
  394.  
  395.     Set AddAddress = Me.Addresses.Add( _
  396.         Item:=Item, _
  397.         Parent:=Me)
  398.  
  399.     ObjectHasChanged
  400. End Function
  401.  
  402.  
  403. Public Function Addresses(Optional ObjectID As Variant) As Variant
  404. ' Returns a VBOFCollection of Address objects which are
  405. '   contained by this Person object,
  406. ' or
  407. ' Returns an Address object whose ObjectID matches the ObjectID
  408. '   parameter.
  409.  
  410.     Dim tempNewAddress As New Address
  411.  
  412.     Set Addresses = _
  413.         ObjectManager. _
  414.             ManageCollection( _
  415.                 ObjectID:=ObjectID, _
  416.                 Collection:=pvtAddressesCollection, _
  417.                 Parent:=Me, _
  418.                 Sample:=tempNewAddress)
  419.  
  420. End Function
  421.  
  422. Public Function Phones(Optional ObjectID As Variant) As Variant
  423. ' Returns a VBOFCollection of Phone objects which are
  424. '   contained by this Person object,
  425. ' or
  426. ' Returns a Phone object whose ObjectID matches the ObjectID
  427. '   parameter.
  428.  
  429.     Dim tempNewPhone As New Phone
  430.     
  431.     Set Phones = _
  432.         ObjectManager. _
  433.             ManageCollection( _
  434.                 ObjectID:=ObjectID, _
  435.                 Collection:=pvtPhonesCollection, _
  436.                 Parent:=Me, _
  437.                 Sample:=tempNewPhone)
  438.  
  439. End Function
  440.  
  441.  
  442. Public Function FormattedName() As String
  443.  
  444.     Dim ReturnString As String
  445.     
  446.     If UCase$(Left$(Sex, 1)) = "M" Then
  447.         ReturnString = "Mr. "
  448.     ElseIf UCase$(Left$(Sex, 1)) = "F" Then
  449.         ReturnString = "Ms. "
  450.     End If
  451.     
  452.     If UCase$(Left$(Sex, 1)) = "F" _
  453.     And UCase$(Left$(MaritalStatus, 1)) = "M" _
  454.     Then
  455.         ReturnString = "Mrs. "
  456.     End If
  457.     
  458.     ReturnString = ReturnString & FirstName
  459.     
  460.     If MaidenName <> "" Then
  461.         ReturnString = ReturnString & " (" & MaidenName & ")"
  462.     End If
  463.     
  464.     FormattedName = ReturnString & " " & LastName
  465. End Function
  466.  
  467.  
  468. Private Sub Class_Initialize()
  469.  
  470.     CustomerNumber = -1
  471.     FirstName = ""
  472.     LastName = ""
  473.     SSN = -1
  474.     DateOfBirth = #1/1/01#
  475.     DateOfDeath = #1/1/01#
  476.     ObjectID = -1
  477.     
  478.     Set ObjectManager = Nothing
  479.     Set pvtMother = Nothing
  480.     Set pvtFather = Nothing
  481.     Set pvtSpouse = Nothing
  482. End Sub
  483.  
  484.  
  485.  
  486. Public Function Age() As Integer
  487.     
  488.     Dim tempDateOfDeath As Variant
  489.     
  490.     If DateOfBirth = "" _
  491.     Or DateOfBirth = #1/1/01# _
  492.     Then
  493.         Age = 0
  494.         Exit Function
  495.     End If
  496.     
  497.     If DateOfDeath = "" _
  498.     Or DateOfDeath = #1/1/01# _
  499.     Then
  500.         tempDateOfDeath = Now
  501.     Else
  502.         tempDateOfDeath = DateOfDeath
  503.     End If
  504.     
  505.     Age = DateDiff("yyyy", DateOfBirth, tempDateOfDeath)
  506. End Function
  507.  
  508.  
  509. Public Property Get CustomerNumber() As Long
  510.     CustomerNumber = pvtCustomerNumber
  511. End Property
  512.  
  513. Public Property Let CustomerNumber(aLong As Long)
  514.     pvtCustomerNumber = aLong
  515. '    ObjectHasChanged
  516. End Property
  517.  
  518. Public Property Get FirstName() As String
  519.     FirstName = pvtFirstName
  520. End Property
  521.  
  522. Public Property Let FirstName(aString As String)
  523.     pvtFirstName = aString
  524. '    ObjectHasChanged
  525. End Property
  526.  
  527. Public Property Get LastName() As String
  528.     LastName = pvtLastName
  529. End Property
  530.  
  531. Public Property Get MaidenName() As String
  532.     MaidenName = pvtMaidenName
  533. End Property
  534.  
  535.  
  536. Public Property Let LastName(aString As String)
  537.     pvtLastName = aString
  538. '    ObjectHasChanged
  539. End Property
  540.  
  541. Public Property Let MaidenName(aString As String)
  542.     pvtMaidenName = aString
  543. '    ObjectHasChanged
  544. End Property
  545.  
  546.  
  547. Public Property Get SSN() As Long
  548.     SSN = pvtSSN
  549. End Property
  550.  
  551. Public Property Let SSN(aLong As Long)
  552.     pvtSSN = aLong
  553. '    ObjectHasChanged
  554. End Property
  555.  
  556. Public Property Get Sex() As String
  557.     Sex = pvtSex
  558. End Property
  559.  
  560. Public Property Let Sex(aString As String)
  561.     pvtSex = aString
  562. '    ObjectHasChanged
  563. End Property
  564.  
  565. Public Property Get DateOfBirth() As Variant
  566.     DateOfBirth = pvtDateOfBirth
  567. End Property
  568.  
  569. Public Property Get DateOfDeath() As Variant
  570.     DateOfDeath = pvtDateOfDeath
  571. End Property
  572.  
  573.  
  574. Public Property Let DateOfBirth(aDate As Variant)
  575.     pvtDateOfBirth = aDate
  576. '    ObjectHasChanged
  577. End Property
  578.  
  579. Public Property Let DateOfDeath(aDate As Variant)
  580.     pvtDateOfDeath = aDate
  581. '    ObjectHasChanged
  582. End Property
  583.  
  584.  
  585. Public Property Get MaritalStatus() As String
  586.     MaritalStatus = pvtMaritalStatus
  587. End Property
  588.  
  589. Public Property Let MaritalStatus(aString As String)
  590.     pvtMaritalStatus = aString
  591. '    ObjectHasChanged
  592. End Property
  593.