Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
5.2 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "StopSigns"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"No"
  16. Option Explicit
  17. Public Sub GetAllStopSignsRs( _
  18. ByVal o_rs As ADODB.Recordset _
  19. )
  20. Dim strQuery As String
  21. CheckDatabaseVersion
  22. CloseRecordSet o_rs
  23. strQuery = "" & _
  24. "SELECT * " & _
  25. "FROM StopSigns " & _
  26. "ORDER BY StopSign;"
  27. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  28. End Sub
  29. Public Sub GetAllStopSignsDict( _
  30. ByVal o_dictStopSigns As Scripting.Dictionary _
  31. )
  32. Dim rs As ADODB.Recordset
  33. Dim strQuery As String
  34. CheckDatabaseVersion
  35. Set rs = New ADODB.Recordset
  36. strQuery = "" & _
  37. "SELECT * " & _
  38. "FROM StopSigns"
  39. rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockReadOnly
  40. Do While (Not rs.EOF)
  41. o_dictStopSigns.Add rs("SSID").Value, Array(rs("StopSign").Value, rs("Context").Value)
  42. DoEvents
  43. rs.MoveNext
  44. Loop
  45. End Sub
  46. Public Function ContainsStopSign( _
  47. ByVal i_str As String _
  48. ) As Boolean
  49. Dim rs As ADODB.Recordset
  50. Dim arrStr() As String
  51. Dim strStopSign As String
  52. Dim strLastChar As String
  53. Dim strWord As String
  54. Dim intIndex As Long
  55. Dim intLength As Long
  56. CheckDatabaseVersion
  57. ContainsStopSign = False
  58. Set rs = New ADODB.Recordset
  59. GetAllStopSignsRs rs
  60. If (rs.EOF) Then
  61. Exit Function
  62. End If
  63. arrStr = Split(i_str)
  64. Do While (Not rs.EOF)
  65. strStopSign = rs("StopSign")
  66. Select Case rs("Context")
  67. Case CONTEXT_ANYWHERE_E
  68. If (InStr(i_str, strStopSign) <> 0) Then
  69. ContainsStopSign = True
  70. Exit Function
  71. End If
  72. Case CONTEXT_AT_END_OF_WORD_E
  73. ' If a stop sign exists by itself, and not right after a word,
  74. ' then it doesn't qualify.
  75. ' So "abc." qualifies, but "abc ." and "a.bc" don't.
  76. For intIndex = LBound(arrStr) To UBound(arrStr)
  77. strWord = arrStr(intIndex)
  78. intLength = Len(strWord)
  79. strLastChar = Mid(strWord, intLength)
  80. If ((strLastChar = strStopSign) And _
  81. (intLength > 1)) Then
  82. ContainsStopSign = True
  83. Exit Function
  84. End If
  85. Next
  86. Case Else
  87. End Select
  88. rs.MoveNext
  89. Loop
  90. End Function
  91. Public Sub Create( _
  92. ByVal i_strStopSign As String, _
  93. ByVal i_intContext As Long _
  94. )
  95. Dim rsLock As ADODB.Recordset
  96. Dim rs As ADODB.Recordset
  97. Dim strQuery As String
  98. CheckDatabaseVersion
  99. LockTable LOCK_TABLE_STOP_SIGNS, rsLock
  100. CheckAuthoringGroupAccess
  101. ' Do some validation to see if the StopSign is acceptable.
  102. p_ValidateStopSign i_strStopSign, i_intContext
  103. ' Does an active StopSign exist?
  104. Set rs = New ADODB.Recordset
  105. p_GetStopSign i_strStopSign, rs
  106. If (Not rs.EOF) Then
  107. Err.Raise errAlreadyExists
  108. Exit Sub
  109. End If
  110. rs.Close
  111. ' Create a new record in the database
  112. strQuery = "" & _
  113. "SELECT * " & _
  114. "FROM StopSigns "
  115. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  116. If (rs.RecordCount > 0) Then
  117. rs.MoveLast
  118. End If
  119. rs.AddNew
  120. rs("StopSign") = i_strStopSign
  121. rs("Context") = i_intContext
  122. rs.Update
  123. End Sub
  124. Public Sub Delete( _
  125. ByVal i_intSSID As Long _
  126. )
  127. Dim rsLock As ADODB.Recordset
  128. Dim rs As ADODB.Recordset
  129. Dim strQuery As String
  130. Dim strStopSign As String
  131. Dim intContext As Long
  132. CheckDatabaseVersion
  133. LockTable LOCK_TABLE_STOP_SIGNS, rsLock
  134. CheckAuthoringGroupAccess
  135. Set rs = New ADODB.Recordset
  136. strQuery = "" & _
  137. "DELETE * " & _
  138. "FROM StopSigns " & _
  139. "WHERE (SSID = " & i_intSSID & " );"
  140. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  141. End Sub
  142. Private Sub p_GetStopSign( _
  143. ByVal i_strStopSign As String, _
  144. ByVal o_rs As ADODB.Recordset _
  145. )
  146. Dim strQuery As String
  147. CloseRecordSet o_rs
  148. strQuery = "" & _
  149. "SELECT * " & _
  150. "FROM StopSigns " & _
  151. "WHERE (StopSign = """ & i_strStopSign & """)"
  152. o_rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockReadOnly
  153. End Sub
  154. Private Sub p_ValidateStopSign( _
  155. ByVal i_strStopSign As String, _
  156. ByVal i_intContext As Long _
  157. )
  158. If (Len(i_strStopSign) <> 1) Then
  159. Err.Raise errTooLong
  160. ElseIf (ContainsOperatorShortcut(i_strStopSign) And _
  161. (i_intContext <> CONTEXT_AT_END_OF_WORD_E)) Then
  162. Err.Raise errContainsOperatorShortcut
  163. End If
  164. End Sub