home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / mts4.cab / Account.VB_Step8_MoveMoney.cls < prev    next >
Text File  |  1997-11-14  |  4KB  |  118 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "MoveMoney"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. ' Filename: Account.vbp
  11. '
  12. ' Description:  MoveMoney Class
  13. '
  14. ' This file is provided as part of the Microsoft Transaction Server Samples
  15. '
  16. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  17. ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  18. ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  19. ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  20. ' PURPOSE.
  21. '
  22. ' Copyright (C) 1997 Microsoft Corporation, All rights reserved
  23.  
  24. Option Explicit
  25.  
  26. Public PrimeAccount As Long
  27. Public SecondAccount As Long
  28.  
  29. Private Const ERROR_NUMBER = vbObjectError + 0
  30. Private Const APP_ERROR = -2147467008
  31.  
  32. Public Function Perform(ByVal lngPrimeAccount As Long, ByVal lngSecondAccount As Long, ByVal lngAmount As Long, ByVal lngTranType As Long) As String
  33.  
  34.     Dim strResult As String
  35.     
  36.     On Error GoTo ErrorHandler
  37.     
  38.     ' check for security
  39.     If (lngAmount > 500 Or lngAmount < -500) Then
  40.         If Not GetObjectContext.IsCallerInRole("Managers") Then
  41.             Err.Raise Number:=APP_ERROR, Description:="Need 'Managers' role for amounts over $500"
  42.         End If
  43.     End If
  44.     
  45.     ' create the account object using our context
  46.     Dim objAccount As Bank.Account
  47.     Set objAccount = GetObjectContext.CreateInstance("Bank.Account")
  48.     
  49.     If objAccount Is Nothing Then
  50.         Err.Raise ERROR_NUMBER, Description:="Could not create account object"
  51.     End If
  52.  
  53.     ' call the post function based on the transaction type
  54.     Select Case lngTranType
  55.         
  56.         Case 1
  57.             strResult = objAccount.Post(lngPrimeAccount, 0 - lngAmount)
  58.             If strResult = "" Then
  59.                 Err.Raise ERROR_NUMBER, Description:=strResult
  60.             End If
  61.     
  62.         Case 2
  63.             strResult = objAccount.Post(lngPrimeAccount, lngAmount)
  64.                 If strResult = "" Then
  65.                     Err.Raise ERROR_NUMBER, Description:=strResult
  66.             End If
  67.             
  68.         Case 3
  69.             Dim strResult1 As String, strResult2 As String
  70.             ' do the credit
  71.             strResult1 = objAccount.Post(lngSecondAccount, lngAmount)
  72.             If strResult1 = "" Then
  73.                 Err.Raise ERROR_NUMBER, Description:=strResult1
  74.             Else
  75.                 ' then do the debit
  76.                 strResult2 = objAccount.Post(lngPrimeAccount, 0 - lngAmount)
  77.                 If strResult2 = "" Then
  78.                     Err.Raise ERROR_NUMBER, Description:=strResult2    ' debit failed
  79.                 Else
  80.                     strResult = strResult1 + "  " + strResult2
  81.                 End If
  82.             End If
  83.             
  84.         Case Else
  85.             Err.Raise ERROR_NUMBER, Description:="Invalid Transaction Type"
  86.     
  87.     End Select
  88.     
  89.     ' Get Receipt Number for the transaction
  90.     Dim objReceiptNo As Bank.GetReceipt
  91.     Dim lngReceiptNo As Long
  92.   
  93.     Set objReceiptNo = GetObjectContext.CreateInstance("Bank.GetReceipt")
  94.     lngReceiptNo = objReceiptNo.GetNextReceipt
  95.     If lngReceiptNo > 0 Then
  96.         strResult = strResult & "; Receipt No: " & Str$(lngReceiptNo)
  97.     End If
  98.     
  99.     GetObjectContext.SetComplete                  ' we are finished and happy
  100.     
  101.     Perform = strResult
  102.      
  103.     Exit Function
  104.  
  105. ErrorHandler:
  106.  
  107.     GetObjectContext.SetAbort                      ' we are unhappy
  108.     
  109.     Perform = ""                            ' indicate that an error occured
  110.     
  111.     Err.Raise Err.Number, "Bank.MoveMoney.Perform", Err.Description
  112.     
  113. End Function
  114. Public Function StatefulPerform(ByVal lngAmount As Long, ByVal lngTranType As Long) As String
  115.    StatefulPerform = Perform(PrimeAccount, SecondAccount, lngAmount, lngTranType)
  116. End Function
  117.  
  118.