Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

634 Zeilen
30KB

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

Powered by TurnKey Linux.