Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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

Powered by TurnKey Linux.