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.

313 lines
9.5KB

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

Powered by TurnKey Linux.