Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

294 рядки
10.0KB

  1. <%
  2. '=======================================================================================================================
  3. ' KitLabels Model
  4. '=======================================================================================================================
  5. Class KitLabelsModel_Class
  6. Public Validator
  7. Public Class_Get_Properties
  8. Public ID '90
  9. Public KitId '122
  10. Public OutboundSerial '106
  11. Public InBoundSerial '106
  12. Public OutboundIMB '106
  13. Public InBoundIMB '106
  14. Public OutboundIMBDigits '106
  15. Public InBoundIMBDigits '106
  16. Public OutboundIMBPNG
  17. Public INBOUNDIMBPNG
  18. Private Sub Class_Initialize
  19. 'ValidateExitsts Me, "",""
  20. Class_Get_Properties = Array("ID, KitId, OutboundSerial, InBoundSerial, OutboundIMB, InBoundIMB, OutboundIMBDigits, InBoundIMBDigits,OutboundIMBPNG,INBOUNDIMBPNG")
  21. End Sub
  22. End CLass
  23. '=======================================================================================================================
  24. ' KitLabels Repository
  25. '=======================================================================================================================
  26. Class KitLabelsRepository_Class
  27. Public Function FindByID(ID)
  28. dim sql : sql = "Select [ID], [KitId], [OutboundSerial], [InBoundSerial], [OutboundIMB], [InBoundIMB], [OutboundIMBDigits], [InBoundIMBDigits],OutboundIMBPNG,INBOUNDIMBPNG FROM [KitLabels] WHERE ID = ?"
  29. dim rs : set rs = DAL.Query(sql,ID)
  30. If rs.EOF then
  31. Err.Raise 1, "KitLabelsRepository_Class", KitLabelsNotFoundException("ID", ID)
  32. Else
  33. set FindByID = Automapper.AutoMap(rs,"KitLabelsModel_Class")
  34. End If
  35. End Function
  36. Public Function GetAll(orderBy)
  37. set GetAll = Find(empty,orderBy)
  38. End Function
  39. Public Function Find(where_kvarray, order_string_or_array)
  40. dim sql : sql = "Select [ID], [KitId], [OutboundSerial], [InBoundSerial], [OutboundIMB], [InBoundIMB], [OutboundIMBDigits], [InBoundIMBDigits],OutboundIMBPNG,INBOUNDIMBPNG FROM [KitLabels]"
  41. If Not IsEmpty(where_kvarray) then
  42. sql = sql & " WHERE "
  43. dim where_keys, where_values
  44. KVUnzip where_kvarray, where_keys, where_values
  45. dim i
  46. For i = 0 to UBound(where_keys)
  47. If i > 0 then sql = sql & " AND "
  48. sql = sql & " " & where_keys(i) & " "
  49. Next
  50. End If
  51. If Not IsEmpty(order_string_or_array) then
  52. sql = sql & "ORDER BY "
  53. If IsArray(order_string_or_array) then
  54. dim order_array : order_array = order_string_or_array
  55. For i = 0 to UBound(order_array)
  56. If i > 0 then sql = sql & ", "
  57. sql = sql & " " & order_array(i)
  58. Next
  59. Else
  60. sql = sql & order_string_or_array & " "
  61. End If
  62. End If
  63. dim rs : set rs = DAL.Query(sql, where_values)
  64. set Find = KitLabelsList(rs)
  65. Destroy rs
  66. End Function
  67. Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  68. dim sql : sql = "Select [ID], [KitId], [OutboundSerial], [InBoundSerial], [OutboundIMB], [InBoundIMB], [OutboundIMBDigits], [InBoundIMBDigits],OutboundIMBPNG,INBOUNDIMBPNG FROM [KitLabels]"
  69. If Not IsEmpty(where_kvarray) then
  70. sql = sql & " WHERE "
  71. dim where_keys, where_values
  72. KVUnzip where_kvarray, where_keys, where_values
  73. dim i
  74. For i = 0 to UBound(where_keys)
  75. If i > 0 then sql = sql & " AND "
  76. sql = sql & " " & where_keys(i) & " "
  77. Next
  78. End If
  79. If Not IsEmpty(order_string_or_array) then
  80. sql = sql & "ORDER BY "
  81. If IsArray(order_string_or_array) then
  82. dim order_array : order_array = order_string_or_array
  83. For i = 0 to UBound(order_array)
  84. If i > 0 then sql = sql & ", "
  85. sql = sql & " " & order_array(i)
  86. Next
  87. Else
  88. sql = sql & order_string_or_array & " "
  89. End If
  90. End If
  91. dim list : set list = new LinkedList_Class
  92. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  93. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  94. rs.PageSize = per_page
  95. rs.AbsolutePage = page_num
  96. page_count = rs.PageCount
  97. record_count = rs.RecordCount
  98. End If
  99. set FindPaged = PagedKitLabelsList(rs, per_page)
  100. Destroy rs
  101. End Function
  102. Public Function SearchTablePaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count)
  103. dim sql : sql = "Select [ID], [KitId], [OutboundSerial], [InBoundSerial], [OutboundIMB], [InBoundIMB], [OutboundIMBDigits], [InBoundIMBDigits],OutboundIMBPNG,INBOUNDIMBPNG FROM [KitLabels]"
  104. If Not IsEmpty(where_kvarray) then
  105. sql = sql & " WHERE "
  106. dim where_keys, where_values
  107. KVUnzip where_kvarray, where_keys, where_values
  108. dim i
  109. For i = 0 to UBound(where_keys)
  110. If i > 0 then sql = sql & " OR"
  111. sql = sql & " " & where_keys(i) & " LIKE ?"
  112. Next
  113. End If
  114. If Not IsEmpty(order_string_or_array) then
  115. sql = sql & " ORDER BY "
  116. If IsArray(order_string_or_array) then
  117. dim order_array : order_array = order_string_or_array
  118. For i = 0 to UBound(order_array)
  119. If i > 0 then sql = sql & ", "
  120. sql = sql & " " & order_array(i)
  121. Next
  122. Else
  123. sql = sql & order_string_or_array & " "
  124. End If
  125. End If
  126. dim list : set list = new LinkedList_Class
  127. dim rs : set rs = DAL.PagedQuery(sql, where_values, per_page, page_num)
  128. If Not rs.EOF and Not (IsEmpty(per_page) and IsEmpty(page_num) and IsEmpty(page_count) and IsEmpty(record_count)) then
  129. rs.PageSize = per_page
  130. rs.AbsolutePage = page_num
  131. page_count = rs.PageCount
  132. record_count = rs.RecordCount
  133. End If
  134. set SearchTablePaged = PagedKitLabelsList(rs, per_page)
  135. Destroy rs
  136. End Function
  137. Private Function PagedKitLabelsList(rs, per_page)
  138. dim list : set list = new LinkedList_Class
  139. dim x : x =0
  140. Do While x < per_page and Not rs.EOF
  141. list.Push Automapper.AutoMap(rs, new KitLabelsModel_Class)
  142. x = x +1
  143. rs.MoveNext
  144. Loop
  145. set PagedKitLabelsList = list
  146. End Function
  147. Private Function KitLabelsNotFoundException(ByVal field_name, ByVal field_val)
  148. KitLabelsNotFoundException = "KitLabels was not found with " & field_name & " of '" & field_val & "'."
  149. End Function
  150. Private Function KitLabelsList(rs)
  151. dim list : set list = new LinkedList_Class
  152. dim model
  153. Do until rs.EOF
  154. set model = new KitLabelsModel_Class
  155. list.Push Automapper.AutoMap(rs, model)
  156. rs.MoveNext
  157. Loop
  158. set KitLabelsList = list
  159. End Function
  160. Public Sub BulkAdd(KitId,Amount)
  161. Dim rest : Set rest = Server.CreateObject("Chilkat_9_5_0.Rest")
  162. Dim responseJson : responseJson = rest.Connect("https://postalpro.usps.com",443,1,1)
  163. Dim Kit : Set Kit = KitRepository.Find(Array("ID = ?",KitId),empty).pop()
  164. Dim Jurisdiction:Set Jurisdiction = JurisdictionRepository.Find(Array("JCode =?",Kit.Jcode),empty).pop
  165. Dim MailingID:MailingID = SettingsRepository.Find(Array("Name =?","MailingID"),empty).pop().Value
  166. Dim SerialNumberStart:SerialNumberStart = SettingsRepository.Find(Array("Name =?","SerialNumberStart"),empty).pop().Value
  167. Dim serialOffset:serialOffset = SettingsRepository.Find(Array("Name =?","SerialOffset"),empty).pop().Value
  168. Dim SerialStart:SerialStart = CLng(SerialNumberStart) + CLng(serialOffset)
  169. dim i
  170. for i = 0 to (Amount * 2) - 2 Step 2
  171. dim NewKitLabel : set NewKitLabel = new KitLabelsModel_Class
  172. NewKitLabel.KitId = KitId
  173. NewKitLabel.OutboundSerial = PadLeft(SerialStart + i,9,"0")
  174. NewKitLabel.InBoundSerial = PadLeft(SerialStart + i + 1,9,"0")
  175. NewKitLabel.OutboundIMBDigits ="00716" & MailingID & NewKitLabel.OutboundSerial & "000000000"
  176. NewKitLabel.InBoundIMBDigits = "00778" & MailingID & NewKitLabel.InBoundSerial & right(Jurisdiction.IMB_Digits,9)
  177. dim imbJson : imbJson = rest.FullRequestNoBody("get","/ppro-tools-api/imb/encode?imb=" & NewKitLabel.OutboundIMBDigits)
  178. json.loadJSON(imbJson)
  179. NewKitLabel.OutboundIMB = json.Data("imb")
  180. NewKitLabel.OutboundIMBPNG = json.Data("imbImage")
  181. imbJson = rest.FullRequestNoBody("get","/ppro-tools-api/imb/encode?imb=" & NewKitLabel.InBoundIMBDigits )
  182. json.loadJSON(imbJson)
  183. NewKitLabel.InBoundIMB = json.Data("imb")
  184. NewKitLabel.INBOUNDIMBPNG = json.Data("imbImage")
  185. me.AddNew NewKitLabel
  186. Next
  187. DAL.Execute "UPDATE Settings SET [Value] ='" & (Amount * 2) + serialOffset & "' Where [Name] ='SerialOffset'",empty
  188. End Sub
  189. Public Sub AddNew(ByRef model)
  190. dim sql : sql = "INSERT INTO [KitLabels] (" &_
  191. "[KitId]," &_
  192. "[OutboundSerial]," &_
  193. "[InBoundSerial]," &_
  194. "[OutboundIMB]," &_
  195. "[InBoundIMB]," &_
  196. "[OutboundIMBDigits]," &_
  197. "[InBoundIMBDigits]," &_
  198. "[OutboundIMBPNG]," &_
  199. "[INBOUNDIMBPNG])" &_
  200. "VALUES (?,?,?,?,?,?,?,?,?)"
  201. DAL.Execute sql, Array(model.KitId, _
  202. model.OutboundSerial, _
  203. model.InBoundSerial, _
  204. model.OutboundIMB, _
  205. model.InBoundIMB, _
  206. model.OutboundIMBDigits, _
  207. model.InBoundIMBDigits, _
  208. model.OutboundIMBPNG, _
  209. model.INBOUNDIMBPNG)
  210. sql = "SELECT TOP 1 ID FROM [KitLabels] ORDER BY ID DESC"
  211. dim rs : set rs = DAL.Query(sql, empty)
  212. model.ID = rs("ID")
  213. Destroy rs
  214. End Sub
  215. Public Sub Update(model)
  216. dim sql : sql = "UPDATE [KitLabels] SET [KitId] = ?," &_
  217. "[OutboundSerial] = ?," &_
  218. "[InBoundSerial] = ?," &_
  219. "[OutboundIMB] = ?," &_
  220. "[InBoundIMB] = ?," &_
  221. "[OutboundIMBDigits] = ?," &_
  222. "[InBoundIMBDigits] = ?," &_
  223. "OutboundIMBPNG,INBOUNDIMBPNG)" &_
  224. " WHERE [ID] = ?"
  225. DAL.Execute sql, Array(model.KitId, _
  226. model.OutboundSerial, _
  227. model.InBoundSerial, _
  228. model.OutboundIMB, _
  229. model.InBoundIMB, _
  230. model.OutboundIMBDigits, _
  231. model.InBoundIMBDigits, _
  232. model.OutboundIMBPNG, _
  233. model.INBOUNDIMBPNG, _
  234. model.ID)
  235. End Sub
  236. Public Sub Delete(id)
  237. dim sql : sql = "DELETE FROM [KitLabels] WHERE [ID] = ?"
  238. DAL.Execute sql, id
  239. End Sub
  240. End Class
  241. dim KitLabelsRepository__Singleton
  242. Function KitLabelsRepository()
  243. If IsEmpty(KitLabelsRepository__Singleton) then
  244. set KitLabelsRepository__Singleton = new KitLabelsRepository_Class
  245. End If
  246. set KitLabelsRepository = KitLabelsRepository__Singleton
  247. End Function
  248. %>

Powered by TurnKey Linux.