Sub Process_Globals
Dim SQL As SQL
End Sub
Sub Globals
Dim btnImport As Button
Dim WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout ("main.bal")
If FirstTime Then
SQL.Initialize(File.DirRootExternal, "Test1.db", True)
End If
DBUtils.DropTable(SQL, "Test1")
WebView1.Visible = False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnImport_Click
Dim i, j As Int
Dim FileDialog1 As FileDialog
ProgressDialogShow("This process can take several minutes. Please wait!")
FileDialog1.FilePath = File.DirRootExternal
If FileDialog1.Show("Choose csv file", "Ok", "Cancel", "", Null) = DialogResponse.POSITIVE Then
SQL.Initialize(File.DirRootExternal, "test1.db", True)
SQL.ExecNonQuery("DROP TABLE IF EXISTS Table1")
SQL.ExecNonQuery("CREATE TABLE Table1 (col1 Text, col2 Text, col3 Text, col4 Text, col5 Text, col6 Text, col7 Text, col8 Text, col9 Text, col10 Text, col11 Text, col12 Text, col13 Text, col14 Text)")
SQL.BeginTransaction
Dim Reader As TextReader
Reader.Initialize(File.OpenInput(FileDialog1.FilePath, FileDialog1.ChosenName))
Try
Dim line As String
Reader.ReadLine
line = Reader.ReadLine
Do While line <> Null
j = j + 1
line = Reader.ReadLine
If line.Contains("Result") OR line.Contains("#") Then
Else
Dim ColumnContent() As String
ColumnContent = Regex.Split(";", line)
For i = 0 To 13
ColumnContent(i) = ColumnContent(i).Replace(QUOTE, "")
Next
SQL.ExecNonQuery2("INSERT INTO Table1 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (ColumnContent(0), ColumnContent(1), ColumnContent(2), ColumnContent(3), ColumnContent(4), ColumnContent(5), ColumnContent(6), ColumnContent(7), ColumnContent(8), ColumnContent(9), ColumnContent(10), ColumnContent(11), ColumnContent(12), ColumnContent(13)))
DoEvents
End If
Loop
Catch
Log(LastException.Message)
End Try
Reader.Close
SQL.TransactionSuccessful
SQL.EndTransaction
ProgressDialogHide
Msgbox("csv file imported!", "Message")
Else
Return True
End If
WebView1.Visible = True
Dim m As Map
m.Initialize
m.Put("TA-Nummer", DBUtils.DB_TEXT)
m.Put("Material", DBUtils.DB_TEXT)
m.Put("Vonplatz", DBUtils.DB_TEXT)
DBUtils.CreateTable(SQL, "Test1", m, "")
FillTest1Table
End Sub
Sub FillTest1Table
Dim ListOfMaps As List
ListOfMaps.Initialize
Dim id As Int
For i = 1 To 40
Dim m As Map
m.Initialize
m.Put("TA-Nummer", "12345")
m.Put("Material", "654321")
m.Put("Vonplatz", "A001-01-01" & i)
ListOfMaps.Add(m)
Next
DBUtils.InsertMaps(SQL, "Test1", ListOfMaps)
End Sub
Sub ShowTable1InWebView
WebView1.Visible = True
WebView1.LoadHtml(DBUtils.ExecuteHtml(SQL, _
"SELECT Material, [Material] As Name FROM Test1" _
, Null, 0, True))
End Sub