diff --git a/Dependancies/ChilkatAx-9.5.0-x64.dll b/Dependancies/ChilkatAx-9.5.0-x64.dll new file mode 100644 index 0000000..a729951 Binary files /dev/null and b/Dependancies/ChilkatAx-9.5.0-x64.dll differ diff --git a/Dependancies/PsExec.exe b/Dependancies/PsExec.exe new file mode 100644 index 0000000..c7b348b Binary files /dev/null and b/Dependancies/PsExec.exe differ diff --git a/Dependancies/PsExec64.exe b/Dependancies/PsExec64.exe new file mode 100644 index 0000000..db94608 Binary files /dev/null and b/Dependancies/PsExec64.exe differ diff --git a/ImportService/PsExec.exe b/ImportService/PsExec.exe new file mode 100644 index 0000000..c7b348b Binary files /dev/null and b/ImportService/PsExec.exe differ diff --git a/ImportService/PsExec64.exe b/ImportService/PsExec64.exe new file mode 100644 index 0000000..db94608 Binary files /dev/null and b/ImportService/PsExec64.exe differ diff --git a/ImportService/TrackingDataImport.vbs b/ImportService/TrackingDataImport.vbs index bfd076b..9e13591 100644 --- a/ImportService/TrackingDataImport.vbs +++ b/ImportService/TrackingDataImport.vbs @@ -1,8 +1,12 @@ Option Explicit Dim dev:dev = True +Dim outFile Dim WaitTime:WaitTime = 15000 Dim DataDirectory +Dim WshShell:Set WshShell = WScript.CreateObject("Wscript.Shell") +Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection") Dim ConnectionString +Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject") Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global") Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e") @@ -16,38 +20,45 @@ Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.S If dev Then DataDirectory = WorkingDirectory & "test" ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;" + set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True) Else - DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport\" + DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport" ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;" + set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True) End If -Do + CheckForFiles - WScript.Sleep WaitTime + Dim KitID:KitID = CheckForJobsToCass() + If KitID > 0 Then + ExportMMCsv(KitID) + RunMailManager + ImportCass + End If + -Loop Function CheckForFiles() -Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject") + If objFSO.FolderExists(DataDirectory) Then Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory) If objFolder.Files.Count > 0 Then - WScript.Echo "Files found in directory: " & DataDirectory + 'WScript.Echo "Files found in directory: " & DataDirectory Dim objFile For Each objFile In objFolder.Files Dim CsvString:CsvString = ConvertCsvToString(objFile.Path) If ValidImportCSV(CsvString) Then SetupKit CsvString,objFile.Name - + objFSO.MoveFile objFile.Path, DataDirectory & "\import\" & objFile.Name End If Next Else - WScript.Echo "No files found in directory: " & DataDirectory + 'WScript.Echo "No files found in directory: " & DataDirectory End If End If @@ -88,20 +99,20 @@ Dim JCode:JCode = Left(Filename,5) oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _ ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _ ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _ - ",'" & objCsv.GetCell(i,0) & _ + ",'" & Replace(objCSV.GetCell(i,0),"'","''") & _ "','" & objCsv.GetCell(i,1) & _ - "','" & objCsv.GetCell(i,2) & _ - "','" & objCsv.GetCell(i,3) & _ - "','" & objCsv.GetCell(i,4) & _ - "','" & objCsv.GetCell(i,5) & _ - "','" & objCsv.GetCell(i,6) & _ - "','" & objCsv.GetCell(i,7) & _ - "','" & objCsv.GetCell(i,8) & _ - "','" & objCsv.GetCell(i,9) & _ - "','" & objCsv.GetCell(i,10) & _ - "','" & objCsv.GetCell(i,11) & _ - "','" & objCsv.GetCell(i,12) & _ - "','" & objCsv.GetCell(i,13) & _ + "','" & Replace(objCSV.GetCell(i,2),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,3),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,4),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,5),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,6),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,7),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,8),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,9),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,10),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,11),"'","''") & _ + "','" & Replace(objCSV.GetCell(i,12),"'","''") & _ + "','" & Replace(objCsv.GetCell(i,13),"'","''") & _ "','" & objCsv.GetCell(i,14) & _ "','" & objCsv.GetCell(i,15) & _ "','" & objCsv.GetCell(i,16) & _ @@ -111,7 +122,7 @@ Dim JCode:JCode = Left(Filename,5) "')") Next oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";") - oConn.Close + 'oConn.Close End If End If @@ -145,4 +156,77 @@ Function ValidImportCSV(CsvFileAsString) Else ValidImportCSV = False End If +End Function + +Sub ImportCass + Dim currentRow + objCsv.LoadFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\FROM_MM.CSV") + + For currentRow = 0 To objCsv.NumRows -1 + oConn.Execute("UPDATE InkJetRecords SET CassADDRESS1 = '" & Replace(objCsv.GetCell(currentRow,1),"'","''") & "', " &_ + "CassADDRESS2 = '" & Replace(objCSV.GetCell(currentRow,3),"'","''") & "', " &_ + "CassADDRESS3 = '" & Replace(objCSV.GetCell(currentRow,4),"'","''") & "', " &_ + "CassADDRESS4 = '" & Replace(objCSV.GetCell(currentRow,5),"'","''") & "', " &_ + "CassADDRESS5 = '" & Replace(objCsv.GetCell(currentRow,6) & ", " & objCsv.GetCell(currentRow,7) & " " & objCsv.GetCell(currentRow,8),"'","''") & "'" &_ + " WHERE ID = " & objCSV.GetCell(currentRow,0) & ";") + + Next + + oConn.Execute("UPDATE Kit SET Status ='Ready To Create Labels' WHERE ID =" & KitID & ";") +End Sub + +Sub RunMailManager + 'WshShell.Run "\\MM2012\APPS\BCC\MM2010\mailman.exe -p -j MMJOB.mjb -u DAN",1,True + 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 +End Sub +Sub ExportMMCsv(KitId) + + Dim success + objCsv.HasColumnNames = 1 + objCSV.EnableQuotes = 1 + success = objCsv.SetColumnName(0,"ID") + success = objCsv.SetColumnName(1,"NAME") + success = objCsv.SetColumnName(2,"ADDRESS1") + success = objCsv.SetColumnName(3,"ADDRESS2") + success = objCsv.SetColumnName(4,"ADDRESS3") + success = objCsv.SetColumnName(5,"ADDRESS4") + success = objCsv.SetColumnName(6,"ADDRESS5") + Dim rs : Set rs = oConn.Execute("Select ID," & _ + "IIF(FIRSTNAME IS NULL,'',FIRSTNAME & ' ') & " & _ + "IIF(MIDDLENAME IS NULL,'',MIDDLENAME & ' ') & " & _ + "IIF(LASTNAME IS NULL,'',LASTNAME & ' ') & " & _ + "IIF(SUFFIX IS NULL,'',SUFFIX & ' ') " & _ + "AS NAME, ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5 FROM InkjetRecords WHERE KitID =" & KitID & " ORDER By ID;") + Dim CurrentRow:CurrentRow = 0 + While Not rs.EOF + objCSV.SetCell CurrentRow,0,rs("ID").value + objCSV.SetCell CurrentRow,1,rs("NAME").value + objCSV.SetCell CurrentRow,2,rs("ADDRESS1").value + objCSV.SetCell CurrentRow,3,rs("ADDRESS2").value + objCSV.SetCell CurrentRow,4,rs("ADDRESS3").value + objCSV.SetCell CurrentRow,5,rs("ADDRESS4").value + objCSV.SetCell CurrentRow,6,rs("ADDRESS5").value + rs.MoveNext + CurrentRow = CurrentRow +1 + Wend + Dim CsvString:CsvString = objCSV.SaveToString() + outFile.WriteLine CsvString + outFile.Close + +End Sub +Function CheckForJobsToCass() +oConn.ConnectionString = ConnectionString +oConn.Open + + 'oConn.Open + Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Cass' ORDER BY ID DESC;") + If Not rs.EOF Then + Dim kitId : kitId = rs("ID").value + rs.Close + CheckForJobsToCass = KitID + oConn.Execute("UPDATE Kit SET Status ='Cassing' WHERE ID =" & KitID & ";") + Else + CheckForJobsToCass = 0 + End If + 'oConn.Close End Function \ No newline at end of file