Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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

Powered by TurnKey Linux.