Consolidated ASP Classic MVC framework from best components
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

244 lignes
11KB

  1. <%
  2. ' Auto-generated Repository for table [Households]
  3. ' Generator: GenerateRepo.vbs v1.0
  4. '
  5. ' Dependencies:
  6. ' - core/lib.DAL.asp (DAL singleton for database access)
  7. ' - core/lib.AutoMapper.asp (Automapper for object mapping)
  8. ' - core/lib.Collections.asp (LinkedList_Class)
  9. ' - core/lib.helpers.asp (KVUnzip, BuildOrderBy, QI, Destroy)
  10. Class HouseholdsRepository_Class
  11. Public Function FindByID(id)
  12. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [Id] = ?"
  13. Dim rs : Set rs = DAL.Query(sql, Array(id))
  14. If rs.EOF Then
  15. Err.Raise 1, "HouseholdsRepository_Class", RecordNotFoundException("Id", id)
  16. Else
  17. Set FindByID = Automapper.AutoMap(rs, "POBO_Households")
  18. End If
  19. Destroy rs
  20. End Function
  21. Public Function GetAll(orderBy)
  22. Set GetAll = Find(Empty, orderBy)
  23. End Function
  24. Public Function Find(where_kvarray, order_string_or_array)
  25. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]"
  26. Dim where_keys, where_values, i
  27. If Not IsEmpty(where_kvarray) Then
  28. KVUnzip where_kvarray, where_keys, where_values
  29. If Not IsEmpty(where_keys) Then
  30. sql = sql & " WHERE "
  31. For i = 0 To UBound(where_keys)
  32. If i > 0 Then sql = sql & " AND "
  33. sql = sql & " " & QI(where_keys(i)) & " = ?"
  34. Next
  35. End If
  36. End If
  37. sql = sql & BuildOrderBy(order_string_or_array, "[Id]")
  38. Dim rs : Set rs = DAL.Query(sql, where_values)
  39. Dim list : Set list = new LinkedList_Class
  40. Do Until rs.EOF
  41. list.Push Automapper.AutoMap(rs, "POBO_Households")
  42. rs.MoveNext
  43. Loop
  44. Set Find = list
  45. Destroy rs
  46. End Function
  47. Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  48. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]"
  49. Dim where_keys, where_values, i
  50. If Not IsEmpty(where_kvarray) Then
  51. KVUnzip where_kvarray, where_keys, where_values
  52. If Not IsEmpty(where_keys) Then
  53. sql = sql & " WHERE "
  54. For i = 0 To UBound(where_keys)
  55. If i > 0 Then sql = sql & " AND "
  56. sql = sql & " " & QI(where_keys(i)) & " = ?"
  57. Next
  58. End If
  59. End If
  60. sql = sql & BuildOrderBy(order_string_or_array, "[Id]")
  61. Dim rs : Set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  62. If Not rs.EOF Then
  63. rs.PageSize = per_page
  64. rs.AbsolutePage = page_num
  65. page_count = rs.PageCount
  66. record_count = rs.RecordCount
  67. End If
  68. Set FindPaged = PagedList(rs, per_page)
  69. Destroy rs
  70. End Function
  71. Public Function SearchTablePaged(columns_array, search_value, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  72. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]"
  73. Dim i, params()
  74. If IsArray(columns_array) And UBound(columns_array) >= 0 Then
  75. sql = sql & " WHERE "
  76. ReDim params(UBound(columns_array))
  77. For i = 0 To UBound(columns_array)
  78. If i > 0 Then sql = sql & " OR "
  79. sql = sql & " " & QI(columns_array(i)) & " LIKE ?"
  80. params(i) = "%" & search_value & "%"
  81. Next
  82. End If
  83. sql = sql & BuildOrderBy(order_string_or_array, "[Id]")
  84. Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num)
  85. If Not rs.EOF Then
  86. rs.PageSize = per_page
  87. rs.AbsolutePage = page_num
  88. page_count = rs.PageCount
  89. record_count = rs.RecordCount
  90. End If
  91. Set SearchTablePaged = PagedList(rs, per_page)
  92. Destroy rs
  93. End Function
  94. Public Function SearchTablePagedByDoNotCall(columns_array, search_value, doNotCallValue, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  95. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [DoNotCall] = ?"
  96. Dim i, params()
  97. If IsArray(columns_array) And UBound(columns_array) >= 0 Then
  98. ReDim params(UBound(columns_array) + 1)
  99. params(0) = doNotCallValue
  100. sql = sql & " AND ("
  101. For i = 0 To UBound(columns_array)
  102. If i > 0 Then sql = sql & " OR "
  103. sql = sql & " " & QI(columns_array(i)) & " LIKE ?"
  104. params(i + 1) = "%" & search_value & "%"
  105. Next
  106. sql = sql & ")"
  107. Else
  108. ReDim params(0)
  109. params(0) = doNotCallValue
  110. End If
  111. sql = sql & BuildOrderBy(order_string_or_array, "[Id]")
  112. Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num)
  113. If Not rs.EOF Then
  114. rs.PageSize = per_page
  115. rs.AbsolutePage = page_num
  116. page_count = rs.PageCount
  117. record_count = rs.RecordCount
  118. End If
  119. Set SearchTablePagedByDoNotCall = PagedList(rs, per_page)
  120. Destroy rs
  121. End Function
  122. Public Function FindPagedByTerritoryAndDoNotCall(territoryId, doNotCallValue, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  123. Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [TerritoryId] = ? AND [DoNotCall] = ?"
  124. Dim rs : Set rs = DAL.PagedQuery(sql & BuildOrderBy(order_string_or_array, "[Id]"), Array(territoryId, doNotCallValue), per_page, page_num)
  125. If Not rs.EOF Then
  126. rs.PageSize = per_page
  127. rs.AbsolutePage = page_num
  128. page_count = rs.PageCount
  129. record_count = rs.RecordCount
  130. End If
  131. Set FindPagedByTerritoryAndDoNotCall = PagedList(rs, per_page)
  132. Destroy rs
  133. End Function
  134. Private Function PagedList(rs, per_page)
  135. Dim list : Set list = new LinkedList_Class
  136. Dim x : x = 0
  137. Do While (per_page <= 0 Or x < per_page) And Not rs.EOF
  138. list.Push Automapper.AutoMap(rs, "POBO_Households")
  139. x = x + 1
  140. rs.MoveNext
  141. Loop
  142. Set PagedList = list
  143. End Function
  144. Public Function GetCountsByTerritory()
  145. Dim sql : sql = "SELECT [TerritoryId], COUNT(*) AS [HouseholdCount] FROM [Households] GROUP BY [TerritoryId]"
  146. Dim rs : Set rs = DAL.Query(sql, Empty)
  147. Dim dict : Set dict = Server.CreateObject("Scripting.Dictionary")
  148. Do Until rs.EOF
  149. If Not IsNull(rs("TerritoryId")) Then
  150. dict(CLng(rs("TerritoryId"))) = CLng(rs("HouseholdCount"))
  151. End If
  152. rs.MoveNext
  153. Loop
  154. Set GetCountsByTerritory = dict
  155. Destroy rs
  156. End Function
  157. Public Function GetDistinctStreetsByTerritory(territoryId)
  158. Dim sql : sql = "SELECT DISTINCT [StreetName] FROM [Households] WHERE [TerritoryId] = ? AND [StreetName] IS NOT NULL AND [StreetName] <> '' ORDER BY [StreetName]"
  159. Dim rs : Set rs = DAL.Query(sql, Array(territoryId))
  160. Dim list : Set list = new LinkedList_Class
  161. Do Until rs.EOF
  162. list.Push rs("StreetName") & ""
  163. rs.MoveNext
  164. Loop
  165. Set GetDistinctStreetsByTerritory = list
  166. Destroy rs
  167. End Function
  168. Public Sub AddNew(ByRef model)
  169. Dim sql : sql = "INSERT INTO [Households] ([Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
  170. DAL.[Execute] sql, Array(model.Address, model.DoNotCall, model.DoNotCallDate, model.DoNotCallNotes, model.DoNotCallPrivateNotes, model.IsBusiness, model.Latitude, model.Longitude, model.StreetName, model.StreetNumber, model.TerritoryId)
  171. ' Retrieve the newly inserted ID
  172. On Error Resume Next
  173. Dim rsId : Set rsId = DAL.Query("SELECT @@IDENTITY AS NewID", Empty)
  174. If Err.Number <> 0 Then
  175. ' Fallback for Access databases
  176. Err.Clear
  177. Set rsId = DAL.Query("SELECT TOP 1 [Id] FROM [Households] ORDER BY [Id] DESC", Empty)
  178. End If
  179. On Error GoTo 0
  180. If Not rsId.EOF Then
  181. If Not IsNull(rsId(0)) Then model.Id = rsId(0)
  182. End If
  183. Destroy rsId
  184. End Sub
  185. Public Sub Update(model)
  186. Dim sql : sql = "UPDATE [Households] SET [Address] = ?, [DoNotCall] = ?, [DoNotCallDate] = ?, [DoNotCallNotes] = ?, [DoNotCallPrivateNotes] = ?, [IsBusiness] = ?, [Latitude] = ?, [Longitude] = ?, [StreetName] = ?, [StreetNumber] = ?, [TerritoryId] = ? WHERE [Id] = ?"
  187. DAL.[Execute] sql, Array(model.Address, model.DoNotCall, model.DoNotCallDate, model.DoNotCallNotes, model.DoNotCallPrivateNotes, model.IsBusiness, model.Latitude, model.Longitude, model.StreetName, model.StreetNumber, model.TerritoryId, model.Id)
  188. End Sub
  189. Public Sub Delete(id)
  190. Dim sql : sql = "DELETE FROM [Households] WHERE [Id] = ?"
  191. DAL.[Execute] sql, Array(id)
  192. End Sub
  193. Private Function RecordNotFoundException(ByVal field_name, ByVal field_val)
  194. RecordNotFoundException = "Households record was not found with " & field_name & " = '" & field_val & "'."
  195. End Function
  196. Private Function QI(name)
  197. QI = "[" & Replace(CStr(name), "]", "]]") & "]"
  198. End Function
  199. Private Function BuildOrderBy(orderArg, defaultCol)
  200. Dim s : s = ""
  201. If IsEmpty(orderArg) Or IsNull(orderArg) Or orderArg = "" Then
  202. s = " ORDER BY " & defaultCol & " ASC"
  203. ElseIf IsArray(orderArg) Then
  204. Dim i : s = " ORDER BY "
  205. For i = 0 To UBound(orderArg)
  206. If i > 0 Then s = s & ", "
  207. s = s & QI(orderArg(i))
  208. Next
  209. Else
  210. s = " ORDER BY " & QI(orderArg)
  211. End If
  212. BuildOrderBy = s
  213. End Function
  214. End Class
  215. Dim HouseholdsRepository__Singleton
  216. Function HouseholdsRepository()
  217. If IsEmpty(HouseholdsRepository__Singleton) Then
  218. Set HouseholdsRepository__Singleton = new HouseholdsRepository_Class
  219. End If
  220. Set HouseholdsRepository = HouseholdsRepository__Singleton
  221. End Function
  222. %>

Powered by TurnKey Linux.