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.

289 lines
8.4KB

  1. <%
  2. '=======================================================================================================================
  3. ' Kit Model
  4. '=======================================================================================================================
  5. Class KitModel_Class
  6. Public Validator
  7. Public Class_Get_Properties
  8. Public ID '90
  9. Public JobNumber '106
  10. Public Jcode '106
  11. Private Sub Class_Initialize
  12. 'ValidateExitsts Me, "",""
  13. Class_Get_Properties = Array("ID, JobNumber, Jcode")
  14. End Sub
  15. End CLass
  16. Class IndexKitModel_Class
  17. Public Validator
  18. Public Class_Get_Properties
  19. Public ID
  20. Public JobNumber '90
  21. Public Jurisdiction '106
  22. Public LabelCount '106
  23. Public CreatedOn
  24. Public LabelsPrinted
  25. Public ExportedToSnailWorks
  26. Private Sub Class_Initialize
  27. 'ValidateExitsts Me, "",""
  28. Class_Get_Properties = Array("ID, JobNumber, Jurisdiction,LabelCount,CreatedOn,LabelsPrinted,ExportedToSnailWorks")
  29. End Sub
  30. End Class
  31. '=======================================================================================================================
  32. ' Kit Repository
  33. '=======================================================================================================================
  34. Class KitRepository_Class
  35. Public Function PagedIndexView(per_page, page_num, ByRef page_count, ByRef record_count)
  36. dim sql : sql = "SELECT Kit.ID,Kit.JobNumber as [JobNumber], " &_
  37. "Jurisdiction.Name As Jurisdiction," &_
  38. "(SELECT COUNT(*) From KitLabels Where KitId = Kit.ID)" &_
  39. " As [LabelCount],[CreatedOn],[LabelsPrinted],[ExportedToSnailWorks] FROM Kit INNER JOIN Jurisdiction ON Kit.Jcode = Jurisdiction.JCode;"
  40. dim list : set list = new LinkedList_Class
  41. dim rs : set rs = DAL.PagedQuery(sql, empty, per_page, page_num)
  42. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  43. rs.PageSize = per_page
  44. rs.AbsolutePage = page_num
  45. page_count = rs.PageCount
  46. record_count = rs.RecordCount
  47. End If
  48. set PagedIndexView = PagedIndexViewKitList(rs, per_page)
  49. Destroy rs
  50. End Function
  51. Private Function PagedIndexViewKitList(rs, per_page)
  52. dim list : set list = new LinkedList_Class
  53. dim x : x =0
  54. Do While x < per_page and Not rs.EOF
  55. list.Push Automapper.AutoMap(rs, new IndexKitModel_Class)
  56. x = x +1
  57. rs.MoveNext
  58. Loop
  59. set PagedIndexViewKitList = list
  60. End Function
  61. Public Function SwitchBoardEditFindById(ID)
  62. dim sql : sql = "SELECT Kit.ID,Kit.JobNumber as [JobNumber], " &_
  63. "Jurisdiction.Name As Jurisdiction," &_
  64. "(SELECT COUNT(*) From KitLabels Where KitId = Kit.ID)" &_
  65. " As [LabelCount],[CreatedOn],[LabelsPrinted],[ExportedToSnailWorks] FROM Kit INNER JOIN Jurisdiction ON Kit.Jcode = Jurisdiction.JCode " &_
  66. "WHERE ID = ?"
  67. dim rs : set rs = DAL.Query(sql,ID)
  68. If rs.EOF then
  69. Err.Raise 1, "KitRepository_Class", KitNotFoundException("ID", ID)
  70. Else
  71. set SwitchBoardEditFindByID = Automapper.AutoMap(rs,"IndexKitModel_Class")
  72. End If
  73. End Function
  74. Public Function FindByID(ID)
  75. dim sql : sql = "Select [ID], [JobNumber], [Jcode] FROM [Kit] WHERE ID = ?"
  76. dim rs : set rs = DAL.Query(sql,ID)
  77. If rs.EOF then
  78. Err.Raise 1, "KitRepository_Class", KitNotFoundException("ID", ID)
  79. Else
  80. set FindByID = Automapper.AutoMap(rs,"KitModel_Class")
  81. End If
  82. End Function
  83. Public Function GetAll(orderBy)
  84. set GetAll = Find(empty,orderBy)
  85. End Function
  86. Public Function Find(where_kvarray, order_string_or_array)
  87. dim sql : sql = "Select [ID], [JobNumber], [Jcode] FROM [Kit]"
  88. If Not IsEmpty(where_kvarray) then
  89. sql = sql & " WHERE "
  90. dim where_keys, where_values
  91. KVUnzip where_kvarray, where_keys, where_values
  92. dim i
  93. For i = 0 to UBound(where_keys)
  94. If i > 0 then sql = sql & " AND "
  95. sql = sql & " " & where_keys(i) & " "
  96. Next
  97. End If
  98. If Not IsEmpty(order_string_or_array) then
  99. sql = sql & "ORDER BY "
  100. If IsArray(order_string_or_array) then
  101. dim order_array : order_array = order_string_or_array
  102. For i = 0 to UBound(order_array)
  103. If i > 0 then sql = sql & ", "
  104. sql = sql & " " & order_array(i)
  105. Next
  106. Else
  107. sql = sql & order_string_or_array & " "
  108. End If
  109. End If
  110. dim rs : set rs = DAL.Query(sql, where_values)
  111. set Find = KitList(rs)
  112. Destroy rs
  113. End Function
  114. Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  115. dim sql : sql = "Select [ID], [JobNumber], [Jcode] FROM [Kit]"
  116. If Not IsEmpty(where_kvarray) then
  117. sql = sql & " WHERE "
  118. dim where_keys, where_values
  119. KVUnzip where_kvarray, where_keys, where_values
  120. dim i
  121. For i = 0 to UBound(where_keys)
  122. If i > 0 then sql = sql & " AND "
  123. sql = sql & " " & where_keys(i) & " "
  124. Next
  125. End If
  126. If Not IsEmpty(order_string_or_array) then
  127. sql = sql & "ORDER BY "
  128. If IsArray(order_string_or_array) then
  129. dim order_array : order_array = order_string_or_array
  130. For i = 0 to UBound(order_array)
  131. If i > 0 then sql = sql & ", "
  132. sql = sql & " " & order_array(i)
  133. Next
  134. Else
  135. sql = sql & order_string_or_array & " "
  136. End If
  137. End If
  138. dim list : set list = new LinkedList_Class
  139. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  140. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  141. rs.PageSize = per_page
  142. rs.AbsolutePage = page_num
  143. page_count = rs.PageCount
  144. record_count = rs.RecordCount
  145. End If
  146. set FindPaged = PagedKitList(rs, per_page)
  147. Destroy rs
  148. End Function
  149. Public Function SearchTablePaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  150. dim sql : sql = "Select [ID], [JobNumber], [Jcode] FROM [Kit]"
  151. If Not IsEmpty(where_kvarray) then
  152. sql = sql & " WHERE "
  153. dim where_keys, where_values
  154. KVUnzip where_kvarray, where_keys, where_values
  155. dim i
  156. For i = 0 to UBound(where_keys)
  157. If i > 0 then sql = sql & " OR"
  158. sql = sql & " " & where_keys(i) & " LIKE ?"
  159. Next
  160. End If
  161. If Not IsEmpty(order_string_or_array) then
  162. sql = sql & " ORDER BY "
  163. If IsArray(order_string_or_array) then
  164. dim order_array : order_array = order_string_or_array
  165. For i = 0 to UBound(order_array)
  166. If i > 0 then sql = sql & ", "
  167. sql = sql & " " & order_array(i)
  168. Next
  169. Else
  170. sql = sql & order_string_or_array & " "
  171. End If
  172. End If
  173. dim list : set list = new LinkedList_Class
  174. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  175. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  176. rs.PageSize = per_page
  177. rs.AbsolutePage = page_num
  178. page_count = rs.PageCount
  179. record_count = rs.RecordCount
  180. End If
  181. set SearchTablePaged = PagedKitList(rs, per_page)
  182. Destroy rs
  183. End Function
  184. Private Function PagedKitList(rs, per_page)
  185. dim list : set list = new LinkedList_Class
  186. dim x : x =0
  187. Do While x < per_page and Not rs.EOF
  188. list.Push Automapper.AutoMap(rs, new KitModel_Class)
  189. x = x +1
  190. rs.MoveNext
  191. Loop
  192. set PagedKitList = list
  193. End Function
  194. Private Function KitNotFoundException(ByVal field_name, ByVal field_val)
  195. KitNotFoundException = "Kit was not found with " & field_name & " of '" & field_val & "'."
  196. End Function
  197. Private Function KitList(rs)
  198. dim list : set list = new LinkedList_Class
  199. dim model
  200. Do until rs.EOF
  201. set model = new KitModel_Class
  202. list.Push Automapper.AutoMap(rs, model)
  203. rs.MoveNext
  204. Loop
  205. set KitList = list
  206. End Function
  207. Public Sub AddNew(ByRef model)
  208. dim sql : sql = "INSERT INTO [Kit] (" &_
  209. "[JobNumber]," &_
  210. "[Jcode])" &_
  211. "VALUES (?,?)"
  212. DAL.Execute sql, Array(model.JobNumber, _
  213. model.Jcode)
  214. sql = "SELECT TOP 1 ID FROM [Kit] ORDER BY ID DESC"
  215. dim rs : set rs = DAL.Query(sql, empty)
  216. model.ID = rs("ID")
  217. Destroy rs
  218. End Sub
  219. Public Sub Update(model)
  220. dim sql : sql = "UPDATE [Kit] SET [JobNumber] = ?," &_
  221. "[Jcode] = ?" &_
  222. " WHERE [ID] = ?"
  223. DAL.Execute sql, Array(model.JobNumber, _
  224. model.Jcode, _
  225. model.ID)
  226. End Sub
  227. Public Sub Delete(id)
  228. dim sql : sql = "DELETE FROM [Kit] WHERE [ID] = ?"
  229. DAL.Execute sql, id
  230. End Sub
  231. End Class
  232. dim KitRepository__Singleton
  233. Function KitRepository()
  234. If IsEmpty(KitRepository__Singleton) then
  235. set KitRepository__Singleton = new KitRepository_Class
  236. End If
  237. set KitRepository = KitRepository__Singleton
  238. End Function
  239. %>

Powered by TurnKey Linux.