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

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

Powered by TurnKey Linux.