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

7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
7 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
7 місяці тому
6 місяці тому
6 місяці тому
7 місяці тому
6 місяці тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. Option Explicit
  2. Dim dev:dev = True
  3. Dim outFile
  4. Dim WaitTime:WaitTime = 15000
  5. Dim DataDirectory
  6. Dim WshShell:Set WshShell = WScript.CreateObject("Wscript.Shell")
  7. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  8. Dim ConnectionString
  9. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  10. Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global")
  11. Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e")
  12. If (success <> 1) Then
  13. WriteLine(glob.LastErrorText)
  14. WScript.Quit
  15. End If
  16. Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv")
  17. Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
  18. If dev Then
  19. DataDirectory = WorkingDirectory & "test"
  20. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;"
  21. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  22. Else
  23. DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport"
  24. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;"
  25. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  26. End If
  27. Dim KitID
  28. CheckForFiles
  29. KitID = CheckForJobsToCass()
  30. If KitID > 0 Then
  31. ExportMMCsv(KitID)
  32. RunMailManager
  33. ImportCass
  34. End If
  35. 'oConn.Open(ConnectionString)
  36. KitID = CheckForReadyToLabel()
  37. If KitID > 0 Then
  38. createTrackingInfoForKit(KitID)
  39. End If
  40. WScript.Quit
  41. Function createTrackingInfoForKit(KitID)
  42. Dim KitRs:set KitRs = oConn.Execute("Select * from Kit Where ID =" & KitID & ";")
  43. Dim InkjetRs:Set InkjetRs = oConn.Execute("Select * from InkjetRecords Where KitID =" & KitID & ";")
  44. 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
  45. Dim SerialNumberStart:SerialNumberStart = GetSetting("SerialNumberStart")
  46. Dim serialOffset:serialOffset = GetSetting("SerialOffset")
  47. Dim serialStart:serialStart = CLng(GetSetting("SerialNumberStart")) + CLng(GetSetting("SerialOffset"))
  48. Dim Counter:Counter=0
  49. Dim KitLabelID
  50. Dim KitLabelRs
  51. Dim Step : If KitRs("InboundSTID") <> "" Then : Step = 2 : Else Step = 1
  52. serialStart = PadLeft(serialStart + CLng(Counter),9,"0")
  53. While Not InkjetRs.EOF
  54. If Step = 1 Then
  55. oConn.Execute("INSERT INTO KitLabels (KitID,OutboundSerial,OutboundIMBDigits) " &_
  56. "VALUES(" & KitID & ",'" & serialStart & "','" & KitRs("OutBoundSTID").Value & serialStart & "000000000" & "');")
  57. Else
  58. oConn.Execute "INSERT INTO KitLabels (KitID,OutboundSerial,InBoundSerial,OutboundIMBDigits,InBoundIMBDigits) " &_
  59. "VALUES(" & KitID & ",'" & serialStart & "','" & serialStart + 1 & "','" & KitRs("OutBoundSTID").Value & serialStart & "000000000" & "','" & KitRs("InboundSTID").Value & serialStart + 1 & Jcode & "');"
  60. End If
  61. Set KitLabelRs = oConn.Execute("SELECT TOP 1 [ID] FROM KitLabels ORDER BY ID DESC"):KitLabelID = KitLabelRs("ID").Value
  62. oConn.Execute("UPDATE InkjetRecords Set [KitLabelID]=" & KitLabelID & " WHERE ID=" & InkjetRs("ID") & ";")
  63. Counter = Counter + Step
  64. serialStart = serialStart + Step
  65. InkjetRs.MoveNext
  66. Wend
  67. oConn.Execute("UPDATE Settings Set [Value]='" & serialOffset + Counter & "' WHERE [Name] = 'SerialOffset';")
  68. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  69. End Function
  70. Function GetSetting(settingName)
  71. Dim rs:Set rs = oConn.Execute("Select Value From [Settings] Where [Name] = '" & settingName & "';")
  72. If Not rs.EOF Then
  73. GetSetting = rs(0).value
  74. rs.Close
  75. Else
  76. SetSetting = 0
  77. rs.Close
  78. End If
  79. End Function
  80. Function CheckForReadyToLabel()
  81. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Assign Labels' ORDER BY ID DESC;")
  82. If Not rs.EOF Then
  83. Dim kitId : kitId = rs("ID").value
  84. rs.Close
  85. CheckForReadyToLabel = KitID
  86. oConn.Execute("UPDATE Kit SET Status ='Applying Serial Numbers' WHERE ID =" & KitID & ";")
  87. Else
  88. CheckForReadyToLabel = 0
  89. End If
  90. End Function
  91. Function CheckForFiles()
  92. If objFSO.FolderExists(DataDirectory) Then
  93. Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory)
  94. If objFolder.Files.Count > 0 Then
  95. 'WScript.Echo "Files found in directory: " & DataDirectory
  96. Dim objFile
  97. For Each objFile In objFolder.Files
  98. Dim CsvString:CsvString = ConvertCsvToString(objFile.Path)
  99. If ValidImportCSV(CsvString) Then
  100. SetupKit CsvString,objFile.Name
  101. objFSO.MoveFile objFile.Path, DataDirectory & "\import\" & objFile.Name
  102. End If
  103. Next
  104. Else
  105. 'WScript.Echo "No files found in directory: " & DataDirectory
  106. End If
  107. End If
  108. End Function
  109. Function ValidJcode(jcode)
  110. Dim oConn
  111. Set oConn = WScript.CreateObject("ADODB.Connection")
  112. oConn.ConnectionString = ConnectionString
  113. oConn.Open
  114. Dim oRs
  115. set oRs = oConn.Execute("Select * from Jurisdiction Where [JCode] = '" & jcode & "';")
  116. If oRs.EOF Then
  117. ValidJcode = 0
  118. Else
  119. ValidJcode = 1
  120. End If
  121. oRs.Close
  122. oConn.Close
  123. End Function
  124. Function SetupKit(CsvString,FileName)
  125. Dim JobNumber:JobNumber = Mid(FileName,9,6)
  126. Dim JCode:JCode = Left(Filename,5)
  127. If IsNumeric(JobNumber) Then
  128. If ValidJcode(JCode) Then
  129. WScript.Echo FileName & " Is a Valid CSV for Importing"
  130. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  131. oConn.ConnectionString = ConnectionString
  132. oConn.Open
  133. oConn.Execute("Insert Into Kit ([JobNumber], [Jcode], [CreatedOn], [JobType],[Filename],[Status]) VALUES ('" & JobNumber & "','" & JCode & "',#" & Now() & "#,'Purple Envelopes','" & FileName & "','Importing');")
  134. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit ORDER BY ID DESC")
  135. Dim kitId : kitId = rs("ID").value
  136. rs.close
  137. Dim i
  138. For i = 1 To objCSV.NumRows -1
  139. oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _
  140. ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _
  141. ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _
  142. ",'" & Replace(objCSV.GetCell(i,0),"'","''") & _
  143. "','" & objCsv.GetCell(i,1) & _
  144. "','" & Replace(objCSV.GetCell(i,2),"'","''") & _
  145. "','" & Replace(objCSV.GetCell(i,3),"'","''") & _
  146. "','" & Replace(objCSV.GetCell(i,4),"'","''") & _
  147. "','" & Replace(objCSV.GetCell(i,5),"'","''") & _
  148. "','" & Replace(objCSV.GetCell(i,6),"'","''") & _
  149. "','" & Replace(objCSV.GetCell(i,7),"'","''") & _
  150. "','" & Replace(objCSV.GetCell(i,8),"'","''") & _
  151. "','" & Replace(objCSV.GetCell(i,9),"'","''") & _
  152. "','" & Replace(objCSV.GetCell(i,10),"'","''") & _
  153. "','" & Replace(objCSV.GetCell(i,11),"'","''") & _
  154. "','" & Replace(objCSV.GetCell(i,12),"'","''") & _
  155. "','" & Replace(objCsv.GetCell(i,13),"'","''") & _
  156. "','" & objCsv.GetCell(i,14) & _
  157. "','" & objCsv.GetCell(i,15) & _
  158. "','" & objCsv.GetCell(i,16) & _
  159. "','" & objCsv.GetCell(i,17) & _
  160. "','" & objCsv.GetCell(i,18) & _
  161. "','" & objCsv.GetCell(i,19) & _
  162. "')")
  163. Next
  164. oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";")
  165. 'oConn.Close
  166. End If
  167. End If
  168. End Function
  169. Function ConvertCsvToString(FilePath)
  170. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  171. Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath)
  172. Dim strContent:strContent = ""
  173. Dim intLineCount:intLineCount = 0
  174. Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3
  175. objCsvFile.SkipLine
  176. intLineCount = intLineCount + 1
  177. Loop
  178. ' Read the remaining content into a string
  179. Do Until objCsvFile.AtEndOfStream
  180. Dim strLine:strLine = objCsvFile.ReadLine
  181. strContent = strContent & strLine & vbCrLf
  182. Loop
  183. ConvertCsvToString = strContent
  184. End Function
  185. Function ValidImportCSV(CsvFileAsString)
  186. objCSV.LoadFromString(CsvFileAsString)
  187. If objCSV.NumColumns = 20 Then
  188. debug.WriteLine objCsv.GetCell(1,1)
  189. ValidImportCSV = True
  190. Else
  191. ValidImportCSV = False
  192. End If
  193. End Function
  194. Sub ImportCass
  195. Dim currentRow
  196. objCsv.LoadFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\FROM_MM.CSV")
  197. For currentRow = 0 To objCsv.NumRows -1
  198. oConn.Execute("UPDATE InkJetRecords SET CassADDRESS1 = '" & Replace(objCsv.GetCell(currentRow,1),"'","''") & "', " &_
  199. "CassADDRESS2 = '" & Replace(objCSV.GetCell(currentRow,3),"'","''") & "', " &_
  200. "CassADDRESS3 = '" & Replace(objCSV.GetCell(currentRow,4),"'","''") & "', " &_
  201. "CassADDRESS4 = '" & Replace(objCSV.GetCell(currentRow,5),"'","''") & "', " &_
  202. "CassADDRESS5 = '" & Replace(objCsv.GetCell(currentRow,6) & ", " & objCsv.GetCell(currentRow,7) & " " & objCsv.GetCell(currentRow,8),"'","''") & "'" &_
  203. " WHERE ID = " & objCSV.GetCell(currentRow,0) & ";")
  204. Next
  205. oConn.Execute("UPDATE Kit SET Status ='Ready To Assign STIDS' WHERE ID =" & KitID & ";")
  206. oConn.Execute("UPDATE Kit SET [Cass] = 1 WHERE ID =" & KitID & ";")
  207. End Sub
  208. Sub RunMailManager
  209. 'WshShell.Run "\\MM2012\APPS\BCC\MM2010\mailman.exe -p -j MMJOB.mjb -u DAN",1,True
  210. 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
  211. End Sub
  212. Sub ExportMMCsv(KitId)
  213. Dim success
  214. objCsv.HasColumnNames = 1
  215. objCSV.EnableQuotes = 1
  216. success = objCsv.SetColumnName(0,"ID")
  217. success = objCsv.SetColumnName(1,"NAME")
  218. success = objCsv.SetColumnName(2,"ADDRESS1")
  219. success = objCsv.SetColumnName(3,"ADDRESS2")
  220. success = objCsv.SetColumnName(4,"ADDRESS3")
  221. success = objCsv.SetColumnName(5,"ADDRESS4")
  222. success = objCsv.SetColumnName(6,"ADDRESS5")
  223. Dim rs : Set rs = oConn.Execute("Select ID," & _
  224. "IIF(FIRSTNAME IS NULL,'',FIRSTNAME & ' ') & " & _
  225. "IIF(MIDDLENAME IS NULL,'',MIDDLENAME & ' ') & " & _
  226. "IIF(LASTNAME IS NULL,'',LASTNAME & ' ') & " & _
  227. "IIF(SUFFIX IS NULL,'',SUFFIX & ' ') " & _
  228. "AS NAME, ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5 FROM InkjetRecords WHERE KitID =" & KitID & " ORDER By ID;")
  229. Dim CurrentRow:CurrentRow = 0
  230. While Not rs.EOF
  231. objCSV.SetCell CurrentRow,0,rs("ID").value
  232. objCSV.SetCell CurrentRow,1,rs("NAME").value
  233. objCSV.SetCell CurrentRow,2,rs("ADDRESS1").value
  234. objCSV.SetCell CurrentRow,3,rs("ADDRESS2").value
  235. objCSV.SetCell CurrentRow,4,rs("ADDRESS3").value
  236. objCSV.SetCell CurrentRow,5,rs("ADDRESS4").value
  237. objCSV.SetCell CurrentRow,6,rs("ADDRESS5").value
  238. rs.MoveNext
  239. CurrentRow = CurrentRow +1
  240. Wend
  241. Dim CsvString:CsvString = objCSV.SaveToString()
  242. outFile.WriteLine CsvString
  243. outFile.Close
  244. End Sub
  245. Function CheckForJobsToCass()
  246. oConn.ConnectionString = ConnectionString
  247. oConn.Open
  248. 'oConn.Open
  249. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Cass' ORDER BY ID DESC;")
  250. If Not rs.EOF Then
  251. Dim kitId : kitId = rs("ID").value
  252. rs.Close
  253. CheckForJobsToCass = KitID
  254. oConn.Execute("UPDATE Kit SET Status ='Cassing' WHERE ID =" & KitID & ";")
  255. Else
  256. CheckForJobsToCass = 0
  257. End If
  258. 'oConn.Close
  259. End Function
  260. Public Function PadLeft(originalString,desiredLength,Char)
  261. Dim padLength
  262. padLength = desiredLength - Len(originalString)
  263. If padLength > 0 Then
  264. ' Left pad the string with zeros
  265. PadLeft = String(padLength, Char) & originalString
  266. Else
  267. ' If the original string is already longer or equal to the desired length, no padding is needed
  268. PadLeft = originalString
  269. End If
  270. End Function

Powered by TurnKey Linux.