25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsRepository.asp 6.9KB

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

Powered by TurnKey Linux.