Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

540 linhas
24KB

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

Powered by TurnKey Linux.