您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

928 行
86KB

  1. Option Explicit
  2. Dim dev:dev = "local"
  3. Dim outFile
  4. Dim WaitTime:WaitTime = 15000
  5. Dim DataDirectory
  6. Dim ExportDirectory
  7. Dim PurpleEnvelopeProofReport,OfficeCopiesProofReport,CustomOfficeCopiesProof
  8. Dim WshShell:Set WshShell = WScript.CreateObject("Wscript.Shell")
  9. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  10. Dim ConnectionString
  11. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  12. Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global")
  13. Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e")
  14. If (success <> 1) Then
  15. WriteLine(glob.LastErrorText)
  16. WScript.Quit
  17. End If
  18. Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv")
  19. Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
  20. Select Case dev
  21. Case "local"
  22. DataDirectory = "C:\Share\TrackingDataImport\"
  23. ExportDirectory = "C:\Share\TrackingDataExport\"
  24. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;"
  25. PurpleEnvelopeProofReport = "F:\Development\Tracking_Kits\Data\Proofs.rep"
  26. OfficeCopiesProofReport="F:\Development\Tracking_Kits\Data\Office-Copy-Proof.rep"
  27. CustomOfficeCopiesProof="F:\Development\Tracking_Kits\Data\Custom Office Copies Proof.rep"
  28. set outFile = objFSO.CreateTextFile("C:\Share\TrackingDataExport\temp.csv",True)
  29. Case true
  30. DataDirectory = "C:\Share\TrackingDataImport\"
  31. ExportDirectory = "C:\Share\TrackingDataExport\"
  32. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\Git Repos\tracking_kits\Data\webdata - Copy.mdb;"
  33. PurpleEnvelopeProofReport = "C:\Git Repos\tracking_kits\Data\Proofs.rep"
  34. OfficeCopiesProofReport = "C:\Git Repos\tracking_kits\Data\Office-Copy-Proof.rep"
  35. CustomOfficeCopiesProof="F:\Development\Tracking_Kits\Data\Custom Office Copies Proof.rep"
  36. set outFile = objFSO.CreateTextFile("C:\Git Repos\tracking_kits\Data\TrackingDataExport\temp.csv",True)
  37. Case Else
  38. DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport"
  39. ExportDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataExport\"
  40. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;"
  41. PurpleEnvelopeProofReport ="C:\inetpub\tracking\Data\Proofs.rep"
  42. OfficeCopiesProofReport = "C:\inetpub\tracking\Data\Office-Copy-Proof.rep"
  43. CustomOfficeCopiesProof="C:\inetpub\tracking\Data\Custom Office Copies Proof.rep"
  44. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  45. End Select
  46. 'ToDo create a checkstatus function so I dont need four functions of create a case switch that responds to the status of jobs
  47. CreateCustomOfficeCopyJobsProofFiles
  48. If ThereAreCustomOfficeCopyJobsReady() Then
  49. CreateCustomOfficeCopyJobsInKjetFiles
  50. CreateCustomOfficeCopyJobsProofFiles
  51. End If
  52. Dim KitID:CheckForFiles:KitID = CheckForJobsToCass()
  53. If KitID > 0 Then
  54. ExportMMCsv(KitID)
  55. RunMailManager
  56. ImportCass
  57. End If
  58. KitID = CheckStatusFor("Ready to Assign Labels"):If KitID > 0 Then:createTrackingInfoForKit(KitID):End If
  59. KitID = CheckStatusFor("Ready For Export"):If KitID > 0 Then:CreateExportForSnailWorks(KitID):End If
  60. KitID = CheckStatusFor("Ready to Proof"):If KitID > 0 Then:CreateProofForJurisdiction(KitID):End If
  61. KitID = CheckStatusFor("Ready For Inkjet Export"):If KitID > 0 Then:ExportInkjetFile(KitID):End If
  62. if dev = False then
  63. CheckSnailWorksPurpleEnvelopeExport
  64. CheckSnailWorksTrakingKitExport
  65. End if
  66. WScript.Quit
  67. Sub CreateCustomOfficeCopyJobsInKjetFiles
  68. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  69. Dim JurisdictionRs,JobsRs,ContactRs,objInkjetCSV:set JobsRs = oConn.Execute("Select * From [CustomOfficeCopyJob] Where [Status] ='Ready';")
  70. Do While Not JobsRs.Eof
  71. Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & JobsRs("Jcode").Value & "';")
  72. Set ContactRs = oConn.Execute("SELECT * FROM Contacts WHERE [JURISCODE] ='" & JobsRs("Jcode").Value & "';")
  73. Set objInkJetCSV = CreateObject("Chilkat_9_5_0.Csv")
  74. objInkjetCSV.HasColumnNames = 1
  75. objInkjetCSV.EnableQuotes = 1
  76. objInkjetCSV.SetColumnName 0,"Full Name"
  77. objInkjetCSV.SetColumnName 1,"Address 1"
  78. objInkjetCSV.SetColumnName 2,"Address 2"
  79. objInkjetCSV.SetColumnName 3,"Address 3"
  80. objInkjetCSV.SetColumnName 4,"Address 4"
  81. objInkjetCSV.SetColumnName 5,"IM barcode Characters"
  82. objInkjetCSV.SetColumnName 6,"Precinct"
  83. objInkjetCSV.SetColumnName 7,"Ballot ID"
  84. objInkjetCSV.SetColumnName 8,"Ballot Number"
  85. objInkjetCSV.SetColumnName 9,"Jurisdiction code"
  86. objInkjetCSV.SetColumnName 10,"Election Date"
  87. objInkJetCSV.SetColumnName 11,"Combined Pct_Ballot Num"
  88. objInkJetCSV.SetColumnName 12,"Title"
  89. objInkJetCSV.SetColumnName 13,"G2 Full Name"
  90. objInkJetCSV.SetColumnName 14,"G2 Company"
  91. objInkJetCSV.SetColumnName 15,"G2 Alternate 1 Address"
  92. objInkJetCSV.SetColumnName 16,"G2 Delivery Address"
  93. objInkJetCSV.SetColumnName 17,"G2 City St ZIP+4"
  94. objInkJetCSV.SetColumnName 18,"G2 IM barcode Characters"
  95. objInkJetCSV.SetColumnName 19,"Matching Code"
  96. Dim Record
  97. For Record = 0 To JobsRs("Amount").Value -1
  98. objInkJetCSV.SetCellByName Record,"Precinct",JobsRs("Precinct").Value
  99. objInkJetCSV.SetCellByName Record,"Ballot Number",JobsRs("StartingBallotNumber").Value + Record
  100. objInkjetCSV.SetCellByName Record,"Title",CleanNull(ContactRs("Title").Value)
  101. objInkJetCSV.SetCellByName Record,"G2 Full Name",JurisdictionRs("Name").Value
  102. objInkJetCSV.SetCellByName Record,"G2 Company",JurisdictionRs("Mailing_Address").Value
  103. objInkJetCSV.SetCellByName Record,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  104. objInkJetCSV.SetCellByName Record,"G2 Delivery Address",""
  105. objInkJetCSV.SetCellByName Record,"G2 City St ZIP+4",""
  106. objInkJetCSV.SetCellByName Record,"G2 IM barcode Characters",JurisdictionRs("IMB_Digits").Value
  107. Next
  108. objInkjetCSV.SaveFile(ExportDirectory & JurisdictionRs("Name").Value & "-" & JobsRs("Precinct").Value & ".csv" )
  109. Set objInkjetCSV = Nothing
  110. Set JurisdictionRs = Nothing
  111. set ContactRs = Nothing
  112. oConn.Execute("Update [CustomOfficeCopyJob] Set [Status] ='Ready To Proof' where [ID] = " & JobsRs("ID").Value & ";")
  113. JobsRs.MoveNext
  114. Loop
  115. If JobsRs.State = 1 Then:JobsRs.Close
  116. If oConn.State = 1 Then:oConn.Close
  117. End Sub
  118. Sub CreateCustomOfficeCopyJobsProofFiles
  119. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  120. Dim JobsRs:Set JobsRs = oConn.Execute("Select * From [CustomOfficeCopyJob] Where [Status] ='Ready To Proof';")
  121. If Not JobsRs.EOF Then
  122. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & JobsRs("Jcode").Value & "';")
  123. Dim reportManager:set reportManager = CreateObject("ReportMan.ReportManX")
  124. With reportManager
  125. .Preview = False
  126. .ShowProgress = False
  127. .ShowPrintDialog = False
  128. .filename = CustomOfficeCopiesProof
  129. .SetDatabaseConnectionString "MORE_DATA",ConnectionString
  130. .SetParamValue "PBJCODE",JobsRs("Jcode")
  131. .SetParamValue "PBCSV",JurisdictionRs("Name").Value & "-" & JobsRs("Precinct").Value & ".csv"
  132. .SaveToPDF ExportDirectory & JurisdictionRs("Name").Value & "-" & JobsRs("Precinct").Value & ".pdf",1
  133. End With
  134. oConn.Execute("Update [CustomOfficeCopyJob] Set [Status] ='Done' where [ID] = " & JobsRs("ID").Value & ";")
  135. End If
  136. If JobsRs.State = 1 Then:JobsRs.Close
  137. If oConn.State = 1 Then:oConn.Close
  138. End Sub
  139. Function ThereAreCustomOfficeCopyJobsReady
  140. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  141. Dim JobsRs:set JobsRs = oConn.Execute("Select [ID] From [CustomOfficeCopyJob] Where [Status] ='Ready';")
  142. If Not JobsRs.EOF Then:ThereAreCustomOfficeCopyJobsReady = True:Else ThereAreCustomOfficeCopyJobsReady = False
  143. If JobsRs.State = 1 Then:JobsRs.Close
  144. If oConn.State = 1 Then:oConn.Close
  145. End Function
  146. Sub CheckSnailWorksPurpleEnvelopeExport
  147. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  148. Dim objFolder
  149. Dim success
  150. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Purple Envelopes")
  151. If objFolder.Files.Count > 0 Then
  152. success = Sftp.Connect("sftp.snailworks.com",22)
  153. success = Sftp.AuthenticatePw("KCIHotFolder2024FTPUser","Z!4WXLSQMM#f")
  154. success = Sftp.InitializeSftp()
  155. Dim file
  156. For Each file In objFolder.Files
  157. debug.WriteLine file.Path
  158. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  159. Sftp.UploadFile handle,file.Path
  160. Sftp.CloseHandle handle
  161. file.Delete
  162. Next
  163. End If
  164. End Sub
  165. Sub CheckSnailWorksTrakingKitExport
  166. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  167. Dim objFolder
  168. Dim success
  169. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Tracking Kits")
  170. If objFolder.Files.Count > 0 Then
  171. success = Sftp.Connect("sftp.snailworks.com",22)
  172. success = Sftp.AuthenticatePw("KCI2024Type2FTPUser","Z!NXVRV5SH#f")
  173. success = Sftp.InitializeSftp()
  174. Dim file
  175. For Each file In objFolder.Files
  176. debug.WriteLine file.Path
  177. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  178. Sftp.UploadFile handle,file.Path
  179. Sftp.CloseHandle handle
  180. file.Delete
  181. Next
  182. End If
  183. End Sub
  184. Function ExportInkjetFile(KitID)
  185. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  186. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  187. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("SELECT * FROM ( " & _
  188. "SELECT IIf(Len([PRECINCT]) = 1, '0' & [PRECINCT] & Right([BALLOT_NUMBER],4), [PRECINCT] & Right([BALLOT_NUMBER],4)) AS SORT_ORDER, " & _
  189. "InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME, " & _
  190. "InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT, " & _
  191. "InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4, " & _
  192. "InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT, " & _
  193. "InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS, " & _
  194. "InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2, " & _
  195. "InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID, " & _
  196. "KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB, " & _
  197. "KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG, " & _
  198. "KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber " & _
  199. "FROM InkjetRecords " & _
  200. "LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID " & _
  201. "WHERE InkjetRecords.KitID = " & KitID & ") AS [Data] " & _
  202. "ORDER BY Val(PRECINCT) DESC, PRECINCT DESC, " & _
  203. "Val(Right(BALLOT_NUMBER, 4)) DESC, Right(BALLOT_NUMBER, 4) DESC;")
  204. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  205. Dim ContactRs:Set ContactRs = oConn.Execute("SELECT * FROM Contacts WHERE [JURISCODE] ='" & KitRs("Jcode").Value & "';")
  206. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & ".csv"
  207. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  208. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  209. Dim ElectionDate:ElectionDate=GetSetting("ElectionDate")
  210. Dim objInkjetCSV:Set objInkJetCSV = CreateObject("Chilkat_9_5_0.Csv")
  211. objInkjetCSV.HasColumnNames = 1
  212. objInkjetCSV.EnableQuotes = 1
  213. objInkjetCSV.SetColumnName 0,"Full Name"
  214. objInkjetCSV.SetColumnName 1,"Address 1"
  215. objInkjetCSV.SetColumnName 2,"Address 2"
  216. objInkjetCSV.SetColumnName 3,"Address 3"
  217. objInkjetCSV.SetColumnName 4,"Address 4"
  218. objInkjetCSV.SetColumnName 5,"IM barcode Characters"
  219. objInkjetCSV.SetColumnName 6,"Precinct"
  220. objInkjetCSV.SetColumnName 7,"Ballot ID"
  221. objInkjetCSV.SetColumnName 8,"Ballot Number"
  222. objInkjetCSV.SetColumnName 9,"Jurisdiction code"
  223. objInkjetCSV.SetColumnName 10,"Election Date"
  224. objInkJetCSV.SetColumnName 11,"Combined Pct_Ballot Num"
  225. objInkJetCSV.SetColumnName 12,"Title"
  226. objInkJetCSV.SetColumnName 13,"G2 Full Name"
  227. objInkJetCSV.SetColumnName 14,"G2 Company"
  228. objInkJetCSV.SetColumnName 15,"G2 Alternate 1 Address"
  229. objInkJetCSV.SetColumnName 16,"G2 Delivery Address"
  230. objInkJetCSV.SetColumnName 17,"G2 City St ZIP+4"
  231. objInkJetCSV.SetColumnName 18,"G2 IM barcode Characters"
  232. objInkJetCSV.SetColumnName 19,"Matching Code"
  233. Dim AddressArray
  234. Dim row:row = 0
  235. While Not KitLabelsRs.EOF
  236. AddressArray = CompressArray(Array(KitLabelsRs("CassADDRESS1").Value,KitLabelsRs("CassADDRESS2").Value,KitLabelsRs("CassADDRESS3").Value,KitLabelsRs("CassADDRESS4").Value,KitLabelsRs("CassADDRESS5").Value))
  237. objInkjetCSV.SetCellByName row,"Full Name",AddressArray(0)
  238. objInkjetCSV.SetCellByName row,"Address 1",AddressArray(1)
  239. objInkjetCSV.SetCellByName row,"Address 2",AddressArray(2)
  240. objInkjetCSV.SetCellByName row,"Address 3",AddressArray(3)
  241. objInkjetCSV.SetCellByName row,"Address 4",AddressArray(4)
  242. If KitRs("OutboundSTID") <> "0" Then
  243. objInkJetCSV.SetCellByName row,"IM barcode Characters",KitLabelsRs("OutboundIMBDigits").Value
  244. End If
  245. objInkJetCSV.SetCellByName row,"Precinct",KitLabelsRs("PRECINCT").Value
  246. objInkJetCSV.SetCellByName row,"Ballot ID","*" & KitLabelsRs("VOTERID").Value & "*"
  247. objInkJetCSV.SetCellByName row,"Ballot Number",TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  248. objInkJetCSV.SetCellByName row,"Jurisdiction code",KitRs("Jcode").Value
  249. objInkJetCSV.SetCellByName row,"Election Date",ElectionDate
  250. objInkJetCSV.SetCellByName row,"Combined Pct_Ballot Num",KitLabelsRs("PRECINCT").Value & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  251. objInkjetCSV.SetCellByName row,"Title",CleanNull(ContactRs("Title").Value)
  252. objInkJetCSV.SetCellByName row,"G2 Full Name",JurisdictionRs("Name").Value
  253. objInkJetCSV.SetCellByName row,"G2 Company",JurisdictionRs("Mailing_Address").Value
  254. objInkJetCSV.SetCellByName row,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  255. objInkJetCSV.SetCellByName row,"G2 Delivery Address",""
  256. objInkJetCSV.SetCellByName row,"G2 City St ZIP+4",""
  257. objInkJetCSV.SetCellByName row,"G2 IM barcode Characters",Choice(IsNull(KitRs("InboundSTID")),JurisdictionRs("IMB_Digits").Value,KitLabelsRs("InBoundIMBDigits").Value)
  258. objInkJetCSV.SetCellByName row,"Matching Code",KitRs("Jcode").Value & TrimLeadingZeros(KitLabelsRs("PRECINCT").Value) & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  259. 'Where do we put the roundtrip IMB
  260. row = row + 1
  261. KitLabelsRs.MoveNext
  262. Wend
  263. If KitRs("OfficeCopiesAmount").Value > 0 Then
  264. dim s
  265. For s = 0 to KitRs("OfficeCopiesAmount").Value -1
  266. objInkjetCSV.SetCellByName row + s,"Title",CleanNull(ContactRs("Title").Value)
  267. objInkJetCSV.SetCellByName row + s,"G2 Full Name",JurisdictionRs("Name").Value
  268. objInkJetCSV.SetCellByName row + s,"G2 Company",JurisdictionRs("Mailing_Address").Value
  269. objInkJetCSV.SetCellByName row + s,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  270. objInkJetCSV.SetCellByName row + s,"G2 Delivery Address",""
  271. objInkJetCSV.SetCellByName row + s,"G2 City St ZIP+4",""
  272. objInkJetCSV.SetCellByName row + s,"G2 IM barcode Characters",JurisdictionRs("IMB_Digits").Value
  273. Next
  274. End If
  275. objInkjetCSV.SaveFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName)
  276. oConn.Execute("UPDATE KIT SET [Status] ='Done',[InkJetJob]=1 WHERE [ID] =" & KitID & ";")
  277. If KitRs.State = 1 Then:KitRs.Close:End If
  278. If ContactRs.State =1 Then:ContactRs.Close:End If
  279. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  280. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  281. If oConn.State = 1 Then:oConn.Close:End If
  282. End Function
  283. Function CheckStatusFor(StatusString)
  284. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  285. Dim rs:Set rs = oConn.Execute("Select TOP 1 [ID] FROM [Kit] Where Status ='" & StatusString & "' and JobType='Purple Envelopes';")
  286. If Not rs.EOF Then
  287. CheckStatusFor = rs("ID").value
  288. Else
  289. CheckStatusFor = 0
  290. End If
  291. If rs.State = 1 Then:rs.Close:End If
  292. If oConn.State = 1 Then:oConn.Close:End If
  293. End Function
  294. Function CreateProofForJurisdiction(KitID)
  295. Dim Qpdf:Set Qpdf = WScript.CreateObject("DebenuPDFLibraryAX1013.PDFLibrary")
  296. Dim Result:Result = Qpdf.UnlockKey("j564z3wi9i66k93cp3r798b3y")
  297. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  298. Dim Rs:set Rs = oConn.Execute("SELECT MIN(ID) as [MIN],MAX(ID) as [MAX] FROM InkjetRecords WHERE KitID = " & KitID &";")
  299. Dim MIN:MIN = Rs("MIN").Value
  300. Dim MAX:MAX = Rs("MAX").Value
  301. Dim RecordCount:RecordCount = (MAX - MIN) + 1
  302. Rs.Close
  303. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  304. Dim JurisdictionRs:set JurisdictionRs = oConn.Execute("SELECt * FROM [Jurisdiction] WHERE JCode='" & KitRs("Jcode").Value & "';")
  305. Dim ProofFileName:ProofFileName = objFSO.GetBaseName(KitRs("Filename")) & "-PROOF.PDF"
  306. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  307. Dim reportManager:set reportManager = CreateObject("ReportMan.ReportManX")
  308. With reportManager
  309. .Preview = False
  310. .ShowProgress = False
  311. .ShowPrintDialog = False
  312. .filename = PurpleEnvelopeProofReport
  313. .SetDatabaseConnectionString "WEBDATA",ConnectionString
  314. .SetParamValue "PBKITID",KitID
  315. .SetParamValue "PBJCODE",KitRs("Jcode").Value
  316. Dim MAXRECORDS:MAXRECORDS = 50000
  317. If RecordCount > MAXRECORDS Then
  318. Dim i
  319. For i = 0 To RecordCount / MAXRECORDS
  320. Dim newMin:If MIN + (i * MAXRECORDS) > MIN Then:newMin = MIN + (i * MAXRECORDS) + 1:Else newMin = MIN:End If
  321. Dim newMax:If MIN + (i * MAXRECORDS) + MAXRECORDS > MAX Then:newMax = MAX:Else newMax = MIN + (i * MAXRECORDS) + MAXRECORDS:End If
  322. .SetParamValue "PBMIN",newMin
  323. .SetParamValue "PBMAX",newMax
  324. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName,1
  325. Result = Qpdf.AddToFileList("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName)
  326. Next
  327. Result = Qpdf.MergeFileListFast("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName)
  328. Dim test
  329. For test = 1 To Qpdf.FileListCount("Proofs")
  330. WshShell.Run "cmd.exe /c DEL /F /Q """ & Qpdf.FileListItem("Proofs",test) & """" ,0,True
  331. Next
  332. Else
  333. .SetParamValue "PBMIN",MIN
  334. .SetParamValue "PBMAX",MAX
  335. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName,1
  336. End If
  337. End With
  338. oConn.Execute("UPDATE KIT SET [Status] ='Ready For Inkjet Export' WHERE [ID] =" & KitID & ";")
  339. If KitRs.State = 1 Then:KitRs.Close:End If
  340. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  341. If oConn.State = 1 Then:oConn.Close:End If
  342. End Function
  343. Function CreateExportForSnailWorks(KitID)
  344. Dim State
  345. Dim AddressArray
  346. Dim ForeignTest
  347. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  348. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  349. If KitRs("OutboundSTID") <> "0" Then
  350. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("SELECT InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME," &_
  351. " InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT," &_
  352. " InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4," &_
  353. " InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT," &_
  354. " InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS," &_
  355. " InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2," &_
  356. " InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID," &_
  357. " KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB," &_
  358. " KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG," &_
  359. " KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber" &_
  360. " FROM InkjetRecords" &_
  361. " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _
  362. " WHERE InkjetRecords.KitID =" & KitID & " ;")
  363. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  364. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & "_SW_EXPORT.csv"
  365. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  366. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  367. Dim objExportFile:set objExportFile = objFSO.CreateTextFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName,2)
  368. With objExportFile
  369. .Write("""H"",") 'Record Type Required value must be = "H" (Header)
  370. .Write(Truncate("5.2",5)) 'Version Required value must be ="5.2" for current release
  371. .Write(Truncate("KCIHotFolder2024FTPUser",50)) 'UserId Required
  372. .Write(Truncate(KitRs("Jcode").Value,50)) 'Client Name Required (will create new subaccount if not already defined) - We decideded to make this the juriscode
  373. .Write(Truncate("",50)) 'Parent Client Name Optional (use if 3-tier account structure)
  374. .Write(Truncate("Purple envelope - " & KitRs("JobNumber").Value,50)) 'Job Name Required
  375. .Write(Truncate("",50)) 'Job Description Optional
  376. .Write(Truncate("",50)) 'Split Name Optional � will default to �Default�
  377. .Write(Truncate("",80)) 'Split Description Optional
  378. .Write(Truncate("L",1)) 'Piece Type Required L-Letters, C-Cards, F-Flats
  379. .Write(Truncate(Year(Now()) & "/" &_
  380. Right("0" & Month(Now()), 2) & "/" & Right("0" & Day(Now()), 2),10)) 'MailDate Required (YYYY/MM/DD)
  381. .Write(Truncate("N",1)) 'UploadType Required N = New job, new split A = Append new split to existing job R = Replace existing split
  382. .Write(Truncate("",8)) 'TrackedQuantity Optional
  383. .Write(Truncate("",8)) 'PiecesMailed Optional � shown as Estimated Quantity
  384. .Write(Truncate("",10)) 'Target InHomeDateStart Optional (YYYY/MM/DD)
  385. .Write(Truncate("",10)) 'Target InHomeDateEnd Optional (YYYY/MM/DD)
  386. .Write(Truncate("danielc@kentcommunications.com",100)) 'ConfirmationEmail Optional
  387. .Write(Truncate("",9)) 'JobId (SW) Optional for previously created jobs SWJobId
  388. .Write(Truncate("",4)) 'SplitId (SW) Optional for previously created jobs SWJobId
  389. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"O","R"),1)) 'TypeofTracking Required Values: O- Outbound Only I-Inbound Only R-Round Trip
  390. .Write(Truncate("",11)) 'ReturnedPostalRoutingCode
  391. .Write(Truncate("",2)) 'ReportId1
  392. .Write(Truncate("",255)) 'Report1Email
  393. .Write(Truncate("",2)) 'ReportId2
  394. .Write(Truncate("",255)) 'Report2Email
  395. .Write("""N""") 'INFOONLY
  396. .Write(vbCrLf)
  397. While Not KitLabelsRs.EOF
  398. AddressArray = Array(KitLabelsRs("CassADDRESS2").Value,KitLabelsRs("CassADDRESS3").Value,KitLabelsRs("CassADDRESS4").Value,KitLabelsRs("CassADDRESS5").Value)
  399. PushNonEmptyToBottom AddressArray
  400. ForeignTest = AddressArray(3) & " " & AddressArray(2)
  401. State = GetState(AddressArray(3))
  402. State = Replace(State," ","")
  403. If CheckStringDoesNotHaveForiegnCountries(ForeignTest) And State <> """""," then
  404. 'If InStr(ForeignTest,"CANADA") = 0 And InStr(ForeignTest,"AUSTRALIA") = 0 And State <> "" Then " ",
  405. .Write("""D"",") 'RecordType Required value must be = �D� (Detail)
  406. .Write(Truncate("",20)) 'CustomerUniqueIdentifier Optional- any identifier you designate
  407. .Write(Truncate(KitLabelsRs("OutboundIMBDigits"),31)) 'IMB Required � Unencoded, numeric IMB
  408. .Write(Truncate("",10)) 'Greeting Optional
  409. .Write(Truncate("",50)) 'First Name Optional
  410. .Write(Truncate("",2)) 'MI Optional
  411. .Write(Truncate("",50)) 'Last Name Optional
  412. .Write(Truncate("",10)) 'Suffix Optional
  413. .Write(Truncate((KitLabelsRs("CassADDRESS1").Value),100)) 'Full Name Optional
  414. .Write(Truncate("",50)) 'Company Optional
  415. .Write(Truncate("",50)) 'Title Optional
  416. .Write(Truncate(AddressArray(1),128)) 'Address1 Optional
  417. .Write(Truncate(AddressArray(2),128)) 'Address2 Optional
  418. .Write(Truncate(Left(AddressArray(3), _
  419. InStr(AddressArray(3), ",") - 1),50)) 'City Optional
  420. .Write(Truncate(State,2)) 'State Optional
  421. .Write Choice(InStr(AddressArray(3),"-"),Truncate(Right(AddressArray(3),11),11),Truncate(Right(AddressArray(3),5),5)) 'Zip Optional
  422. .Write(Truncate(KitRs("Jcode"),100)) 'UserDefined1 Optional - Summary fields only
  423. .Write(Truncate("",100)) 'UserDefined2 Optional - Summary fields only
  424. .Write(Truncate("",100)) 'UserDefined3 Optional - Summary fields only
  425. .Write(Truncate(KitLabelsRs("PRECINCT").Value &_
  426. KitLabelsRs("BALLOT_NUMBER"),80)) 'UserDefinedIdentifier4 Optional � Allows for unique identifiers
  427. .Write(Truncate(KitLabelsRs("VOTERID").Value,80)) 'UserDefinedIdentifier5 Optional � Allows for unique identifiers
  428. .Write(Truncate("",1)) 'SeedIndicator Optional - if true provide �Y�
  429. .Write(Truncate("",80)) 'InductionPoint Optional
  430. .Write(Truncate("",10)) 'InductionDate Optional � Valid date format, ex. MM/DD/YYYY
  431. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"", _
  432. KitLabelsRs("InBoundIMBDigits").Value),31)) 'InboundIMB Optional � numeric IMB for Round trip jobs only
  433. .Write(Truncate("",24)) 'IMCB Optional � Container Barcode
  434. .Write("""""") 'IMTB Optional � Tray Barcode
  435. .Write(vbCrLf)
  436. End If
  437. KitLabelsRs.MoveNext
  438. Wend
  439. .Close
  440. End With
  441. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  442. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  443. End If
  444. oConn.Execute("UPDATE KIT SET [Status] ='Ready to Proof',[ExportedToSnailWorks] =#" & Now() & "# WHERE [ID] =" & KitID & ";")
  445. If oConn.State = 1 Then:oConn.Close:End If
  446. If KitRs.State = 1 Then:KitRs.Close:End If
  447. End Function
  448. Function createTrackingInfoForKit(KitID)
  449. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  450. oConn.Execute("UPDATE Kit SET Status ='Applying Serial Numbers' WHERE ID =" & KitID & ";")
  451. Dim KitRs:set KitRs = oConn.Execute("Select * from Kit Where ID =" & KitID & ";")
  452. If KitRs("OutBoundSTID") = 0 Then
  453. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  454. Else
  455. Dim InkjetRs:Set InkjetRs = oConn.Execute("Select * from InkjetRecords Where KitID =" & KitID & ";")
  456. Dim JurisRs:set JurisRs = oConn.Execute("Select Right(IMB_Digits,9) as IMBZip FROM Jurisdiction Where JCode ='" & KitRs("Jcode") & "';"):Dim Jcode:Jcode = JurisRs("IMBZip"):JurisRs.Close
  457. Dim SerialNumberStart:SerialNumberStart = GetSetting("SerialNumberStart")
  458. Dim serialOffset:serialOffset = GetSetting("SerialOffset")
  459. Dim serialStart:serialStart = CLng(GetSetting("SerialNumberStart")) + CLng(GetSetting("SerialOffset"))
  460. Dim Counter:Counter=0
  461. Dim KitLabelID
  462. Dim KitLabelRs
  463. Dim Mid:Mid = GetSetting("MailingID")
  464. Dim Step : If KitRs("InboundSTID") <> "" Then : Step = 2 : Else Step = 1
  465. serialStart = PadLeft(serialStart + CLng(Counter),9,"0")
  466. Dim oRsKitLabels : Set oRsKitLabels = CreateObject("ADODB.Recordset"):oRsKitLabels.Open "Select * FROM [KitLabels] Where KitID =" & KitID & ";",oConn,3,3
  467. While Not InkjetRs.EOF
  468. oRsKitLabels.AddNew
  469. KitLabelID = oRsKitLabels("ID").value
  470. If Step = 1 Then
  471. oRsKitLabels("KitID") = KitID
  472. oRsKitLabels("OutboundSerial") = serialStart
  473. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  474. Else
  475. oRsKitLabels("KitID") = KitID
  476. oRsKitLabels("OutboundSerial") = serialStart
  477. oRsKitLabels("InBoundSerial") = serialStart + 1
  478. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  479. oRsKitLabels("InBoundIMBDigits") = KitRs("InboundSTID").Value & Mid & serialStart + 1 & Jcode
  480. End If
  481. oRsKitLabels.Update
  482. oConn.Execute("UPDATE InkjetRecords Set [KitLabelID]=" & KitLabelID & " WHERE ID=" & InkjetRs("ID") & ";")
  483. Counter = Counter + Step
  484. serialStart = serialStart + Step
  485. InkjetRs.MoveNext
  486. Wend
  487. oRsKitLabels.Update
  488. oRsKitLabels.Close
  489. oConn.Execute("UPDATE Settings Set [Value]='" & serialOffset + Counter & "' WHERE [Name] = 'SerialOffset';")
  490. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  491. oConn.Close
  492. End If
  493. End Function
  494. Function GetSetting(settingName)
  495. Dim rs:Set rs = oConn.Execute("Select Value From [Settings] Where [Name] = '" & settingName & "';")
  496. If Not rs.EOF Then
  497. GetSetting = rs(0).value
  498. rs.Close
  499. Else
  500. SetSetting = 0
  501. rs.Close
  502. End If
  503. End Function
  504. Function CheckForFiles()
  505. If objFSO.FolderExists(DataDirectory) Then
  506. Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory)
  507. If objFolder.Files.Count > 0 Then
  508. 'WScript.Echo "Files found in directory: " & DataDirectory
  509. Dim objFile
  510. For Each objFile In objFolder.Files
  511. Dim CsvString:CsvString = ConvertCsvToString(objFile.Path)
  512. If ValidImportCSV(CsvString) Then
  513. SetupKit CsvString,objFile.Name
  514. objFSO.MoveFile objFile.Path, DataDirectory & "\import\" & objFile.Name
  515. End If
  516. Next
  517. Else
  518. 'WScript.Echo "No files found in directory: " & DataDirectory
  519. End If
  520. End If
  521. End Function
  522. Function ValidJcode(jcode)
  523. Dim oConn
  524. Set oConn = WScript.CreateObject("ADODB.Connection")
  525. oConn.ConnectionString = ConnectionString
  526. oConn.Open
  527. Dim oRs
  528. set oRs = oConn.Execute("Select * from Jurisdiction Where [JCode] = '" & jcode & "';")
  529. If oRs.EOF Then
  530. ValidJcode = 0
  531. Else
  532. ValidJcode = 1
  533. End If
  534. oRs.Close
  535. oConn.Close
  536. End Function
  537. Function CheckStringDoesNotHaveForiegnCountries(StringToCheck)
  538. Dim Countries
  539. Countries = Array("SPAIN","LAGOS","PORTUGL","ON N4K 5-Y1","ITALY","CANADA","PHILIPPINES","GWYNEDD PENYGROES","NEW SOUTH WALES","UNITED KINGDOM","CHINA","SCOTLAND UK","ISRAEL","AUSTRIA","NORWAY","BUDAPEST","JAPAN","NEW ZEALAND","AUSTRALIA","FRANCE","UK LL","KENT ENGLAND","CANADA","NETHERLANDS","GERMANY","TAIWAN","NICARAGUA","IREL")
  540. Dim Country
  541. For Each Country In Countries
  542. If InStr(StringToCheck,Country) Then
  543. CheckStringDoesNotHaveForiegnCountries = False
  544. Exit For
  545. End If
  546. CheckStringDoesNotHaveForiegnCountries = True
  547. Next
  548. End Function
  549. Function SetupKit(CsvString,FileName)
  550. Dim JobNumber:JobNumber = Mid(FileName,9,6)
  551. Dim JCode:JCode = Left(Filename,5)
  552. If IsNumeric(JobNumber) Then
  553. If ValidJcode(JCode) Then
  554. WScript.Echo FileName & " Is a Valid CSV for Importing"
  555. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  556. oConn.ConnectionString = ConnectionString
  557. oConn.Open
  558. oConn.Execute("Insert Into Kit ([JobNumber], [Jcode], [CreatedOn], [JobType],[Filename],[Status]) VALUES ('" & JobNumber & "','" & JCode & "',#" & Now() & "#,'Purple Envelopes','" & FileName & "','Importing');")
  559. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit ORDER BY ID DESC")
  560. Dim kitId : kitId = rs("ID").value
  561. rs.close
  562. Dim i
  563. For i = 1 To objCSV.NumRows -1
  564. Dim AddressArray:AddressArray = Array(Replace(objCSV.GetCell(i,6),"'","''"),Replace(objCSV.GetCell(i,7),"'","''"),Replace(objCSV.GetCell(i,8),"'","''"),Replace(objCSV.GetCell(i,9),"'","''"),Replace(objCSV.GetCell(i,10),"'","''"))
  565. PushNonEmptyToBottom AddressArray
  566. oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _
  567. ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _
  568. ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _
  569. ",'" & Replace(objCSV.GetCell(i,0),"'","''") & _
  570. "','" & Replace(objCsv.GetCell(i,1),"'","''") & _
  571. "','" & Replace(objCSV.GetCell(i,2),"'","''") & _
  572. "','" & Replace(objCSV.GetCell(i,3),"'","''") & _
  573. "','" & Replace(objCSV.GetCell(i,4),"'","''") & _
  574. "','" & Replace(objCSV.GetCell(i,5),"'","''") & _
  575. "','" & AddressArray(0) & _
  576. "','" & AddressArray(1) & _
  577. "','" & AddressArray(2) & _
  578. "','" & AddressArray(3) & _
  579. "','" & AddressArray(4) & _
  580. "','" & Replace(objCSV.GetCell(i,11),"'","''") & _
  581. "','" & Replace(objCSV.GetCell(i,12),"'","''") & _
  582. "','" & Replace(objCsv.GetCell(i,13),"'","''") & _
  583. "','" & objCsv.GetCell(i,14) & _
  584. "','" & objCsv.GetCell(i,15) & _
  585. "','" & objCsv.GetCell(i,16) & _
  586. "','" & objCsv.GetCell(i,17) & _
  587. "','" & objCsv.GetCell(i,18) & _
  588. "','" & objCsv.GetCell(i,19) & _
  589. "')")
  590. Next
  591. oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";")
  592. 'oConn.Close
  593. End If
  594. End If
  595. End Function
  596. Function ConvertCsvToString(FilePath)
  597. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  598. Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath)
  599. Dim strContent:strContent = ""
  600. Dim intLineCount:intLineCount = 0
  601. Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3
  602. objCsvFile.SkipLine
  603. intLineCount = intLineCount + 1
  604. Loop
  605. ' Read the remaining content into a string
  606. Do Until objCsvFile.AtEndOfStream
  607. Dim strLine:strLine = objCsvFile.ReadLine
  608. strContent = strContent & strLine & vbCrLf
  609. Loop
  610. ConvertCsvToString = strContent
  611. End Function
  612. Function ValidImportCSV(CsvFileAsString)
  613. objCSV.LoadFromString(CsvFileAsString)
  614. If objCSV.NumColumns = 20 Then
  615. ValidImportCSV = True
  616. Else
  617. ValidImportCSV = False
  618. End If
  619. End Function
  620. Sub ImportCass
  621. Dim currentRow
  622. Select Case dev
  623. Case "local"
  624. objCsv.LoadFile("C:\Share\TrackingDataExport\FROM_MM.CSV")
  625. Case True
  626. objCsv.LoadFile("C:\Share\TrackingDataExport\FROM_MM.CSV")
  627. Case Else
  628. objCsv.LoadFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\FROM_MM.CSV")
  629. End Select
  630. For currentRow = 0 To objCsv.NumRows -1
  631. Dim AddressArray:AddressArray = CompressArray(Array(Replace(objCsv.GetCell(currentRow,1),"'","''"),Replace(objCsv.GetCell(currentRow,2),"'","''"),Replace(objCsv.GetCell(currentRow,3),"'","''"),Replace(objCsv.GetCell(currentRow,4),"'","''"),Replace(objCsv.GetCell(currentRow,5),"'","''"),Replace(objCsv.GetCell(currentRow,6) & ", " & objCsv.GetCell(currentRow,7) & " " & objCsv.GetCell(currentRow,8),"'","''")))
  632. oConn.Execute("UPDATE InkJetRecords SET CassADDRESS1 = '" & AddressArray(0) & "', " &_
  633. "CassADDRESS2 = '" & AddressArray(1) & "', " &_
  634. "CassADDRESS3 = '" & AddressArray(2) & "', " &_
  635. "CassADDRESS4 = '" & AddressArray(3) & "', " &_
  636. "CassADDRESS5 = '" & AddressArray(4) & "'" &_
  637. " WHERE ID = " & objCSV.GetCell(currentRow,0) & ";")
  638. Next
  639. oConn.Execute("UPDATE Kit SET Status ='Ready To Assign STIDS' WHERE ID =" & KitID & ";")
  640. oConn.Execute("UPDATE Kit SET [Cass] = 1 WHERE ID =" & KitID & ";")
  641. End Sub
  642. Sub RunMailManager
  643. Select Case dev
  644. Case "local"
  645. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB-LOCAL.mjb -u DAN",1,True
  646. Case True
  647. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB-DEV.mjb -u DAN",1,True
  648. Case Else
  649. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB.mjb -u DAN",1,True
  650. End Select
  651. End Sub
  652. Sub ExportMMCsv(KitId)
  653. Dim success
  654. objCsv.HasColumnNames = 1
  655. objCSV.EnableQuotes = 1
  656. success = objCsv.SetColumnName(0,"ID")
  657. success = objCsv.SetColumnName(1,"NAME")
  658. success = objCsv.SetColumnName(2,"ADDRESS1")
  659. success = objCsv.SetColumnName(3,"ADDRESS2")
  660. success = objCsv.SetColumnName(4,"ADDRESS3")
  661. success = objCsv.SetColumnName(5,"ADDRESS4")
  662. success = objCsv.SetColumnName(6,"ADDRESS5")
  663. Dim rs : Set rs = oConn.Execute("Select ID," & _
  664. "IIF(FIRSTNAME IS NULL,'',FIRSTNAME & ' ') & " & _
  665. "IIF(MIDDLENAME IS NULL,'',MIDDLENAME & ' ') & " & _
  666. "IIF(LASTNAME IS NULL,'',LASTNAME & ' ') & " & _
  667. "IIF(SUFFIX IS NULL,'',SUFFIX & ' ') " & _
  668. "AS NAME, ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5 FROM InkjetRecords WHERE KitID =" & KitID & " ORDER By ID;")
  669. Dim CurrentRow:CurrentRow = 0
  670. While Not rs.EOF
  671. objCSV.SetCell CurrentRow,0,rs("ID").value
  672. objCSV.SetCell CurrentRow,1,rs("NAME").value
  673. objCSV.SetCell CurrentRow,2,rs("ADDRESS1").value
  674. objCSV.SetCell CurrentRow,3,rs("ADDRESS2").value
  675. objCSV.SetCell CurrentRow,4,rs("ADDRESS3").value
  676. objCSV.SetCell CurrentRow,5,rs("ADDRESS4").value
  677. objCSV.SetCell CurrentRow,6,rs("ADDRESS5").value
  678. rs.MoveNext
  679. CurrentRow = CurrentRow +1
  680. Wend
  681. Dim CsvString:CsvString = objCSV.SaveToString()
  682. outFile.WriteLine CsvString
  683. outFile.Close
  684. End Sub
  685. Function CheckForJobsToCass()
  686. oConn.ConnectionString = ConnectionString
  687. oConn.Open
  688. 'oConn.Open
  689. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Cass' ORDER BY ID DESC;")
  690. If Not rs.EOF Then
  691. Dim kitId : kitId = rs("ID").value
  692. rs.Close
  693. CheckForJobsToCass = KitID
  694. oConn.Execute("UPDATE Kit SET Status ='Cassing' WHERE ID =" & KitID & ";")
  695. Else
  696. CheckForJobsToCass = 0
  697. End If
  698. 'oConn.Close
  699. End Function
  700. Public Function PadLeft(originalString,desiredLength,Char)
  701. Dim padLength
  702. padLength = desiredLength - Len(originalString)
  703. If padLength > 0 Then
  704. ' Left pad the string with zeros
  705. PadLeft = String(padLength, Char) & originalString
  706. Else
  707. ' If the original string is already longer or equal to the desired length, no padding is needed
  708. PadLeft = originalString
  709. End If
  710. End Function
  711. Function Truncate(inputString, size)
  712. If Len(inputString) > size Then:Truncate = """" & Left(inputString,size) & """,":Else Truncate = """" & inputString & """,":End If
  713. End Function
  714. Function PadString(inputString, size)
  715. Dim paddedString
  716. Dim inputLength
  717. Dim i
  718. If IsNull(inputString) Then:inputString = ""
  719. ' Get the length of the input string
  720. inputLength = Len(inputString)
  721. ' If the input string is already equal to or longer than the specified size, return it as is
  722. If inputLength >= size Then
  723. PadString = inputString
  724. Exit Function
  725. End If
  726. ' Initialize the padded string with the input string
  727. paddedString = inputString
  728. ' Pad spaces to the right of the input string until it reaches the specified size
  729. For i = 1 To (size - inputLength)
  730. paddedString = paddedString & " "
  731. Next
  732. ' Return the padded string
  733. PadString = paddedString
  734. End Function
  735. Function CleanNull(StringToClean)
  736. If IsNull(StringToClean) Then:CleanNull = "":Else CleanNull = StringToClean:End If
  737. End Function
  738. Public Sub Assign(ByRef var, ByVal val)
  739. If IsObject(val) Then
  740. Set var = val
  741. Else
  742. var = val
  743. End If
  744. End Sub
  745. Public Function Choice(ByVal cond, ByVal if_true, ByVal if_false)
  746. If cond Then
  747. Assign Choice, if_true
  748. Else
  749. Assign Choice, if_false
  750. End If
  751. End Function
  752. Function CompressArray(arr)
  753. Dim temp,i,j
  754. For i = LBound(arr) To UBound(arr) - 1
  755. For j = i + 1 To UBound(arr)
  756. If arr(i) = "" Then
  757. temp = arr(i)
  758. arr(i) = arr(j)
  759. arr(j) = temp
  760. End If
  761. Next
  762. Next
  763. CompressArray = arr
  764. End Function
  765. Function TrimLeadingZeros(inputStr)
  766. Dim i
  767. For i = 1 To Len(inputStr)
  768. If Mid(inputStr, i, 1) <> "0" Then
  769. TrimLeadingZeros = Mid(inputStr, i)
  770. Exit Function
  771. End If
  772. Next
  773. ' If the input string is all zeros, return "0"
  774. TrimLeadingZeros = "0"
  775. End Function
  776. Sub PushNonEmptyToBottom(ByRef myArray)
  777. Dim tempArray(), i, count
  778. count = UBound(myArray)
  779. ' Create a temporary array to store the rearranged elements
  780. ReDim tempArray(UBound(myArray))
  781. ' Fill the temporary array with empty strings initially
  782. For i = 0 To UBound(myArray)
  783. tempArray(i) = ""
  784. Next
  785. ' Add non-empty elements to the highest-numbered positions
  786. For i = UBound(myArray) To 0 Step -1
  787. If myArray(i) <> "" Then
  788. tempArray(count) = myArray(i)
  789. count = count - 1
  790. End If
  791. Next
  792. ' Copy the temporary array back to the original array
  793. For i = 0 To UBound(myArray)
  794. myArray(i) = tempArray(i)
  795. Next
  796. End Sub
  797. Copy code
  798. Function GetState(ByVal addressLine)
  799. Dim statePattern, matches, state
  800. statePattern = ",\s([A-Z]{2})\s\d{5}" ' Pattern to match ", STATE ZIP"
  801. Dim regEx
  802. Set regEx = New RegExp
  803. regEx.Pattern = statePattern
  804. regEx.IgnoreCase = False
  805. regEx.Global = False
  806. Set matches = regEx.Execute(addressLine)
  807. If matches.Count > 0 Then
  808. ' Extract the state abbreviation (the first captured group)
  809. state = Trim(matches(0).SubMatches(0))
  810. Else
  811. state = ""
  812. End If
  813. GetState = state
  814. End Function

Powered by TurnKey Linux.