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.

148 Zeilen
4.6KB

  1. Option Explicit
  2. Dim dev:dev = True
  3. Dim WaitTime:WaitTime = 15000
  4. Dim DataDirectory
  5. Dim ConnectionString
  6. Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global")
  7. Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e")
  8. If (success <> 1) Then
  9. WriteLine(glob.LastErrorText)
  10. WScript.Quit
  11. End If
  12. Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv")
  13. Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
  14. If dev Then
  15. DataDirectory = WorkingDirectory & "test"
  16. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;"
  17. Else
  18. DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport\"
  19. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;"
  20. End If
  21. Do
  22. CheckForFiles
  23. WScript.Sleep WaitTime
  24. Loop
  25. Function CheckForFiles()
  26. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  27. If objFSO.FolderExists(DataDirectory) Then
  28. Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory)
  29. If objFolder.Files.Count > 0 Then
  30. WScript.Echo "Files found in directory: " & DataDirectory
  31. Dim objFile
  32. For Each objFile In objFolder.Files
  33. Dim CsvString:CsvString = ConvertCsvToString(objFile.Path)
  34. If ValidImportCSV(CsvString) Then
  35. SetupKit CsvString,objFile.Name
  36. End If
  37. Next
  38. Else
  39. WScript.Echo "No files found in directory: " & DataDirectory
  40. End If
  41. End If
  42. End Function
  43. Function ValidJcode(jcode)
  44. Dim oConn
  45. Set oConn = WScript.CreateObject("ADODB.Connection")
  46. oConn.ConnectionString = ConnectionString
  47. oConn.Open
  48. Dim oRs
  49. set oRs = oConn.Execute("Select * from Jurisdiction Where [JCode] = '" & jcode & "';")
  50. If oRs.EOF Then
  51. ValidJcode = 0
  52. Else
  53. ValidJcode = 1
  54. End If
  55. oRs.Close
  56. oConn.Close
  57. End Function
  58. Function SetupKit(CsvString,FileName)
  59. Dim JobNumber:JobNumber = Mid(FileName,9,6)
  60. Dim JCode:JCode = Left(Filename,5)
  61. If IsNumeric(JobNumber) Then
  62. If ValidJcode(JCode) Then
  63. WScript.Echo FileName & " Is a Valid CSV for Importing"
  64. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  65. oConn.ConnectionString = ConnectionString
  66. oConn.Open
  67. oConn.Execute("Insert Into Kit ([JobNumber], [Jcode], [CreatedOn], [JobType],[Filename],[Status]) VALUES ('" & JobNumber & "','" & JCode & "',#" & Now() & "#,'Purple Envelopes','" & FileName & "','Importing');")
  68. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit ORDER BY ID DESC")
  69. Dim kitId : kitId = rs("ID").value
  70. rs.close
  71. Dim i
  72. For i = 1 To objCSV.NumRows -1
  73. oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _
  74. ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _
  75. ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _
  76. ",'" & objCsv.GetCell(i,0) & _
  77. "','" & objCsv.GetCell(i,1) & _
  78. "','" & objCsv.GetCell(i,2) & _
  79. "','" & objCsv.GetCell(i,3) & _
  80. "','" & objCsv.GetCell(i,4) & _
  81. "','" & objCsv.GetCell(i,5) & _
  82. "','" & objCsv.GetCell(i,6) & _
  83. "','" & objCsv.GetCell(i,7) & _
  84. "','" & objCsv.GetCell(i,8) & _
  85. "','" & objCsv.GetCell(i,9) & _
  86. "','" & objCsv.GetCell(i,10) & _
  87. "','" & objCsv.GetCell(i,11) & _
  88. "','" & objCsv.GetCell(i,12) & _
  89. "','" & objCsv.GetCell(i,13) & _
  90. "','" & objCsv.GetCell(i,14) & _
  91. "','" & objCsv.GetCell(i,15) & _
  92. "','" & objCsv.GetCell(i,16) & _
  93. "','" & objCsv.GetCell(i,17) & _
  94. "','" & objCsv.GetCell(i,18) & _
  95. "','" & objCsv.GetCell(i,19) & _
  96. "')")
  97. Next
  98. oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";")
  99. oConn.Close
  100. End If
  101. End If
  102. End Function
  103. Function ConvertCsvToString(FilePath)
  104. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  105. Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath)
  106. Dim strContent:strContent = ""
  107. Dim intLineCount:intLineCount = 0
  108. Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3
  109. objCsvFile.SkipLine
  110. intLineCount = intLineCount + 1
  111. Loop
  112. ' Read the remaining content into a string
  113. Do Until objCsvFile.AtEndOfStream
  114. Dim strLine:strLine = objCsvFile.ReadLine
  115. strContent = strContent & strLine & vbCrLf
  116. Loop
  117. ConvertCsvToString = strContent
  118. End Function
  119. Function ValidImportCSV(CsvFileAsString)
  120. objCSV.LoadFromString(CsvFileAsString)
  121. If objCSV.NumColumns = 20 Then
  122. debug.WriteLine objCsv.GetCell(1,1)
  123. ValidImportCSV = True
  124. Else
  125. ValidImportCSV = False
  126. End If
  127. End Function

Powered by TurnKey Linux.