No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

871 líneas
82KB

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

Powered by TurnKey Linux.