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

301 рядки
10KB

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

Powered by TurnKey Linux.