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.

223 line
6.3KB

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

Powered by TurnKey Linux.