Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JurisdictionRepository.asp 7.1KB

8 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <%
  2. '=======================================================================================================================
  3. ' Jurisdiction Model
  4. '=======================================================================================================================
  5. Class JurisdictionModel_Class
  6. Public Validator
  7. Public Class_Get_Properties
  8. Public JCode '106
  9. Public Name '106
  10. Public Mailing_Address '106
  11. Public CSZ '106
  12. Public IMB '106
  13. Public IMB_Digits '106
  14. Private Sub Class_Initialize
  15. 'ValidateExitsts Me, "",""
  16. Class_Get_Properties = Array("JCode, Name, Mailing_Address, CSZ, IMB, IMB_Digits")
  17. End Sub
  18. End CLass
  19. '=======================================================================================================================
  20. ' Jurisdiction Repository
  21. '=======================================================================================================================
  22. Class JurisdictionRepository_Class
  23. Public Function FindByJCode(JCode)
  24. dim sql : sql = "Select [JCode], [Name], [Mailing_Address], [CSZ], [IMB], [IMB_Digits] FROM [Jurisdiction] WHERE JCode = ?"
  25. dim rs : set rs = DAL.Query(sql,JCode)
  26. If rs.EOF then
  27. Err.Raise 1, "JurisdictionRepository_Class", JurisdictionNotFoundException("JCode", JCode)
  28. Else
  29. set FindByJCode = Automapper.AutoMap(rs,"JurisdictionModel_Class")
  30. End If
  31. End Function
  32. Public Function GetAll(orderBy)
  33. set GetAll = Find(empty,orderBy)
  34. End Function
  35. Public Function Find(where_kvarray, order_string_or_array)
  36. dim sql : sql = "Select [JCode], [Name], [Mailing_Address], [CSZ], [IMB], [IMB_Digits] FROM [Jurisdiction]"
  37. If Not IsEmpty(where_kvarray) then
  38. sql = sql & " WHERE "
  39. dim where_keys, where_values
  40. KVUnzip where_kvarray, where_keys, where_values
  41. dim i
  42. For i = 0 to UBound(where_keys)
  43. If i > 0 then sql = sql & " AND "
  44. sql = sql & " " & where_keys(i) & " "
  45. Next
  46. End If
  47. If Not IsEmpty(order_string_or_array) then
  48. sql = sql & "ORDER BY "
  49. If IsArray(order_string_or_array) then
  50. dim order_array : order_array = order_string_or_array
  51. For i = 0 to UBound(order_array)
  52. If i > 0 then sql = sql & ", "
  53. sql = sql & " " & order_array(i)
  54. Next
  55. Else
  56. sql = sql & order_string_or_array & " "
  57. End If
  58. End If
  59. dim rs : set rs = DAL.Query(sql, where_values)
  60. set Find = JurisdictionList(rs)
  61. Destroy rs
  62. End Function
  63. Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  64. dim sql : sql = "Select [JCode], [Name], [Mailing_Address], [CSZ], [IMB], [IMB_Digits] FROM [Jurisdiction]"
  65. If Not IsEmpty(where_kvarray) then
  66. sql = sql & " WHERE "
  67. dim where_keys, where_values
  68. KVUnzip where_kvarray, where_keys, where_values
  69. dim i
  70. For i = 0 to UBound(where_keys)
  71. If i > 0 then sql = sql & " AND "
  72. sql = sql & " " & where_keys(i) & " "
  73. Next
  74. End If
  75. If Not IsEmpty(order_string_or_array) then
  76. sql = sql & "ORDER BY "
  77. If IsArray(order_string_or_array) then
  78. dim order_array : order_array = order_string_or_array
  79. For i = 0 to UBound(order_array)
  80. If i > 0 then sql = sql & ", "
  81. sql = sql & " " & order_array(i)
  82. Next
  83. Else
  84. sql = sql & order_string_or_array & " "
  85. End If
  86. End If
  87. dim list : set list = new LinkedList_Class
  88. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  89. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  90. rs.PageSize = per_page
  91. rs.AbsolutePage = page_num
  92. page_count = rs.PageCount
  93. record_count = rs.RecordCount
  94. End If
  95. set FindPaged = PagedJurisdictionList(rs, per_page)
  96. Destroy rs
  97. End Function
  98. Public Function SearchTablePaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  99. dim sql : sql = "Select [JCode], [Name], [Mailing_Address], [CSZ], [IMB], [IMB_Digits] FROM [Jurisdiction]"
  100. If Not IsEmpty(where_kvarray) then
  101. sql = sql & " WHERE "
  102. dim where_keys, where_values
  103. KVUnzip where_kvarray, where_keys, where_values
  104. dim i
  105. For i = 0 to UBound(where_keys)
  106. If i > 0 then sql = sql & " OR"
  107. sql = sql & " " & where_keys(i) & " LIKE ?"
  108. Next
  109. End If
  110. If Not IsEmpty(order_string_or_array) then
  111. sql = sql & " ORDER BY "
  112. If IsArray(order_string_or_array) then
  113. dim order_array : order_array = order_string_or_array
  114. For i = 0 to UBound(order_array)
  115. If i > 0 then sql = sql & ", "
  116. sql = sql & " " & order_array(i)
  117. Next
  118. Else
  119. sql = sql & order_string_or_array & " "
  120. End If
  121. End If
  122. dim list : set list = new LinkedList_Class
  123. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  124. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  125. rs.PageSize = per_page
  126. rs.AbsolutePage = page_num
  127. page_count = rs.PageCount
  128. record_count = rs.RecordCount
  129. End If
  130. set SearchTablePaged = PagedJurisdictionList(rs, per_page)
  131. Destroy rs
  132. End Function
  133. Private Function PagedJurisdictionList(rs, per_page)
  134. dim list : set list = new LinkedList_Class
  135. dim x : x =0
  136. Do While x < per_page and Not rs.EOF
  137. list.Push Automapper.AutoMap(rs, new JurisdictionModel_Class)
  138. x = x +1
  139. rs.MoveNext
  140. Loop
  141. set PagedJurisdictionList = list
  142. End Function
  143. Private Function JurisdictionNotFoundException(ByVal field_name, ByVal field_val)
  144. JurisdictionNotFoundException = "Jurisdiction was not found with " & field_name & " of '" & field_val & "'."
  145. End Function
  146. Private Function JurisdictionList(rs)
  147. dim list : set list = new LinkedList_Class
  148. dim model
  149. Do until rs.EOF
  150. set model = new JurisdictionModel_Class
  151. list.Push Automapper.AutoMap(rs, model)
  152. rs.MoveNext
  153. Loop
  154. set JurisdictionList = list
  155. End Function
  156. Public Sub AddNew(ByRef model)
  157. dim sql : sql = "INSERT INTO [Jurisdiction] (" &_
  158. "[Name]," &_
  159. "[Mailing_Address]," &_
  160. "[CSZ]," &_
  161. "[IMB]," &_
  162. "[IMB_Digits])" &_
  163. "VALUES (?,?,?,?,?)"
  164. DAL.Execute sql, Array(model.Name, _
  165. model.Mailing_Address, _
  166. model.CSZ, _
  167. model.IMB, _
  168. model.IMB_Digits)
  169. sql = "SELECT TOP 1 JCode FROM [Jurisdiction] ORDER BY JCode DESC"
  170. dim rs : set rs = DAL.Query(sql, empty)
  171. model.JCode = rs("JCode")
  172. Destroy rs
  173. End Sub
  174. Public Sub Update(model)
  175. dim sql : sql = "UPDATE [Jurisdiction] SET [Name] = ?," &_
  176. "[Mailing_Address] = ?," &_
  177. "[CSZ] = ?," &_
  178. "[IMB] = ?," &_
  179. "[IMB_Digits] = ?" &_
  180. " WHERE [JCode] = ?"
  181. DAL.Execute sql, Array(model.Name, _
  182. model.Mailing_Address, _
  183. model.CSZ, _
  184. model.IMB, _
  185. model.IMB_Digits, _
  186. model.JCode)
  187. End Sub
  188. Public Sub Delete(id)
  189. dim sql : sql = "DELETE FROM [Jurisdiction] WHERE [JCode] = ?"
  190. DAL.Execute sql, id
  191. End Sub
  192. End Class
  193. dim JurisdictionRepository__Singleton
  194. Function JurisdictionRepository()
  195. If IsEmpty(JurisdictionRepository__Singleton) then
  196. set JurisdictionRepository__Singleton = new JurisdictionRepository_Class
  197. End If
  198. set JurisdictionRepository = JurisdictionRepository__Singleton
  199. End Function
  200. %>

Powered by TurnKey Linux.