Sub HandleFile(job As HttpJob)
If job.Success = False Then
ToastMessageShow("Error Downloading CSV File.", True)
ProgressDialogHide
Return
End If
Dim out As OutputStream
out = File.OpenOutput(File.DirDefaultExternal,strTableName , False)
File.Copy2(job.GetInputStream,out)
out.close
Log("finished writing csv file to external default directory")
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim existemap As Map
existemap.Initialize
Dim start, finish As Int
start = 0
finish = 9
Dim readcsv As List
Dim csv As StringUtils
readcsv.Initialize
'Read the saved csv file into a list
readcsv = csv.LoadCSV(File.DirDefaultExternal, strTableName, ",")
Dim columnlist As List
Dim cols() As String
columnlist.Initialize
'read the first line of the list which contains the column names into cols variable
cols = readcsv.Get(0)
'place the column names into another list to be able to build a map with column names and field values
For l = 0 To cols.Length - 1
columnlist.Add(cols(l))
Next
Dim cnt As Int
'build a map with column names and field values
For i = 1 To readcsv.Size - 1
Dim m As Map
m.Initialize
Dim reading() As String
'read each field value into an array of strings
reading = readcsv.Get(i)
For j = 0 To reading.Length - 1
'place the each column name and each field value in a map
m.Put(columnlist.Get(j), reading(j))
Next
'check if records exist, so we won't insert them again.
'Dim existe As Int
'existe = DBUtils.RecordExists(SQL1, "wcJobLog", m)
'If existe > 0 Then
'Log("Record already exists, skipping...")
'Else
'add the map into a list
ListOfMaps.Add(m)
cnt= cnt + 1
Log(cnt)
'End If
Next
If ListOfMaps.Size > 0 Then
DBUtils.InsertMaps(SQL1, strTable, ListOfMaps)
ProgressDialogHide
Else
ProgressDialogHide
End If
End Sub