home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / Schedule.cls < prev    next >
Text File  |  1997-11-01  |  5KB  |  151 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Schedule"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Function Destinations(ByVal strFileDSN As String)
  13.     Dim objContext As ObjectContext
  14.     Set objContext = GetObjectContext
  15.     
  16.     On Error GoTo ErrorHandler
  17.     
  18.     Dim strSQL As String
  19.     Dim rst As New ADODB.Recordset
  20.     
  21.     strSQL = "SELECT CityName from Destination ORDER BY CityName"
  22.     rst.CursorLocation = adUseServer
  23.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly
  24.     Set Destinations = rst
  25.     Exit Function
  26.  
  27. ErrorHandler:
  28.     If Not rst Is Nothing Then Set rst = Nothing
  29.     Set Destinations = Nothing
  30.     objContext.SetAbort
  31.     Err.Raise Err.Number, "Flight.Schedule()", Err.Description
  32. End Function
  33.  
  34. Function CostOfFlightInMiles(ByVal strFileDSN As String, ByVal strFrom As String, ByVal strTo As String, ByVal strClass As String)
  35.     Dim objContext As ObjectContext
  36.     Set objContext = GetObjectContext
  37.     
  38.     On Error GoTo ErrorHandler
  39.     
  40.     Dim strSQL As String
  41.     Dim rst As New ADODB.Recordset
  42.     
  43.     strSQL = "SELECT distinct MilesCostFirst, MilesCostBusiness, MilesCostCoach " & _
  44.              "FROM FlightSchedule " & _
  45.              "WHERE Origin = '" & strFrom & "' " & _
  46.              "AND Destination = '" & strTo & "'"
  47.     rst.CursorLocation = adUseServer
  48.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly
  49.     
  50.     If strClass = "Coach" Then CostOfFlightInMiles = rst.Fields("MilesCostCoach")
  51.     If strClass = "Business" Then CostOfFlightInMiles = rst.Fields("MilesCostBusiness")
  52.     If strClass = "First" Then CostOfFlightInMiles = rst.Fields("MilesCostFirst")
  53.     
  54.     objContext.SetComplete
  55.     
  56.     Exit Function
  57.  
  58. ErrorHandler:
  59.     If Not rst Is Nothing Then Set rst = Nothing
  60.     CostOfFlightInMiles = -1
  61.     objContext.SetAbort
  62.     Err.Raise Err.Number, "Flight.CostOfFlightInMiles()", Err.Description
  63. End Function
  64.  
  65. Function FlightNumber(ByVal strFileDSN As String, ByVal strFrom As String, _
  66.     ByVal strTo As String)
  67.     Dim objContext As ObjectContext
  68.     Set objContext = GetObjectContext
  69.     
  70.     On Error GoTo ErrorHandler
  71.     
  72.     Dim strSQL As String
  73.     Dim rst As New ADODB.Recordset
  74.     
  75.     strSQL = "SELECT distinct FlightNo " & _
  76.              "FROM FlightSchedule " & _
  77.              "WHERE Origin = '" & strFrom & "' " & _
  78.              "AND Destination = '" & strTo & "'"
  79.     rst.CursorLocation = adUseServer
  80.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly
  81.     
  82.     FlightNumber = rst.Fields("FlightNo")
  83.     
  84.     objContext.SetComplete
  85.     
  86.     Exit Function
  87.  
  88. ErrorHandler:
  89.     If Not rst Is Nothing Then Set rst = Nothing
  90.     FlightNumber = -1
  91.     objContext.SetAbort
  92.     Err.Raise Err.Number, "Flight.FlightNumber()", Err.Description
  93. End Function
  94.  
  95. Function BookFlight(ByVal strFileDSN As String, ByVal lngMemberID As Long, _
  96.     ByVal lngFlightNo As Long, ByVal datFlightDate As Date, _
  97.     ByVal lngMiles As Long, ByVal lngMilesLeft As Long, _
  98.     ByVal strClass As String)
  99.     
  100.     Dim objContext As ObjectContext
  101.     Set objContext = GetObjectContext
  102.     
  103.     On Error GoTo ErrorHandler
  104.     
  105.     BookFlight = True
  106.     
  107.     Dim strSQL As String
  108.     Dim cnn As New ADODB.Connection
  109.     cnn.Open "FILEDSN=" & strFileDSN
  110.         
  111.     strSQL = "UPDATE Member " & _
  112.              "SET Mileage=" & lngMilesLeft & _
  113.              "WHERE AccountID=" & lngMemberID
  114.     cnn.Execute strSQL
  115.     
  116.     Dim strTranType As String, lngCompanyId As Long, lngMilesSubtract As Long, _
  117.         lngSpecialId As Long, strComment As String
  118.     strTranType = "USE"
  119.     lngCompanyId = 1
  120.     lngMilesSubtract = (lngMiles * -1)
  121.     lngSpecialId = 1
  122.     strComment = "Free Flight!"
  123.  
  124.     strSQL = "INSERT INTO Transactions " & _
  125.                           "(AccountID, TranType, " & _
  126.                           "FlightNo, FlightDate, " & _
  127.                           "CompanyId, Miles, " & _
  128.                           "SpecialId, Comment) " & _
  129.                           "VALUES (" & _
  130.                           lngMemberID & ", " & _
  131.                           "'" & strTranType & "', " & _
  132.                           lngFlightNo & ", " & _
  133.                           "'" & datFlightDate & "', " & _
  134.                           lngCompanyId & ", " & _
  135.                           lngMilesSubtract & ", " & _
  136.                           lngSpecialId & ", " & _
  137.                           "'" & strComment & "'" & _
  138.                           ")"
  139.     cnn.Execute strSQL
  140.     
  141.     objContext.SetComplete
  142.     
  143.     Exit Function
  144.  
  145. ErrorHandler:
  146.     If Not cnn Is Nothing Then Set cnn = Nothing
  147.     BookFlight = False
  148.     objContext.SetAbort
  149.     Err.Raise Err.Number, "Flight.BookFlight()", Err.Description
  150. End Function
  151.