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.

848 line
79KB

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

Powered by TurnKey Linux.