#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Parser As SaxParser
Dim PD_ProductID, PD_CartonContent, PD_Name, PD_Unit, PD_Tax, PD_Barcode, PD_Price, PD_inStock As String
'Table
Private ScrollView1 As ScrollView
Dim Header As Panel
Dim Table As Panel
Dim NumberOfColumns, RowHeight, ColumnWidth As Int
Dim HeaderColor, TableColor, FontColor, HeaderFontColor As Int
Dim FontSize As Float
' Type RowCol (Row As Int, Col As Int)
Dim Alignment As Int
Dim SelectedRow As Int
Dim SelectedRowColor As Int
'Table Settings
HeaderColor = Colors.Gray
NumberOfColumns = 8
RowHeight = 30dip
TableColor = Colors.White
FontColor = Colors.Black
HeaderFontColor = Colors.White
FontSize = 14
Alignment = Gravity.CENTER 'change to Gravity.LEFT or Gravity.RIGHT for other alignments.
SelectedRowColor = Colors.Blue
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Parser.Initialize
Activity.LoadLayout("ProductManagement")
ScrollView1.Initialize(0)
Table = ScrollView1.Panel
Table.Color = TableColor
Activity.AddView(ScrollView1, 0%x, 25%y, 100%x, 70%y)
ColumnWidth = ScrollView1.Width / NumberOfColumns
SelectedRow = -1
'add header
SetHeader(Array As String("Product ID", "Carton Content", "Name", "Unit", "Tax", "Barcode", "Price", "in Stock"))
ServiceLoad
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ServiceLoad
Dim job1 As HttpJob
job1.Initialize("Job1", Me)
job1.Download2("XXX", _
Array As String("KeyCode", "XXX", "whereSql", "Customer_ID=1"))
End Sub
'################################################################################## ScrollView Start ##########################################################################################################
Sub Cell_Click
Dim rc As RowCol
Dim l As Label
l = Sender
rc = l.Tag
SelectRow(rc.Row)
Activity.Title = "Cell clicked: (" & rc.Row & ", " & rc.Col & ")"
End Sub
Sub Header_Click
Dim l As Label
Dim col As Int
l = Sender
col = l.Tag
Activity.Title = "Header clicked: " & col
End Sub
Sub SelectRow(Row As Int)
'remove the color of previously selected row
If SelectedRow > -1 Then
For col = 0 To NumberOfColumns - 1
GetView(SelectedRow, col).Color = Colors.Transparent
Next
End If
SelectedRow = Row
For col = 0 To NumberOfColumns - 1
GetView(Row, col).Color = SelectedRowColor
Next
End Sub
Sub GetView(Row As Int, Col As Int) As Label
Dim l As Label
l.Initialize("")
ScrollView1.Initialize(100%x)
l = Table.GetView(Row * NumberOfColumns + Col)
Return l
End Sub
Sub AddRow(Values() As String)
If Values.Length <> NumberOfColumns Then
Log("Wrong number of values.")
Return
End If
Dim lastRow As Int
lastRow = NumberOfRows
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("cell")
l.Text = Values(i)
l.Gravity = Alignment
l.TextSize = FontSize
l.TextColor = FontColor
Dim rc As RowCol
rc.Initialize
rc.Col = i
rc.Row = lastRow
l.Tag = rc
Table.AddView(l, ColumnWidth * i, RowHeight * lastRow, ColumnWidth, RowHeight)
Next
Table.Height = NumberOfRows * RowHeight
End Sub
Sub SetHeader(Values() As String)
If Header.IsInitialized Then Return 'should only be called once
Header.Initialize("")
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("header")
l.Text = Values(i)
l.Gravity = Gravity.CENTER
l.TextSize = FontSize
l.Color = HeaderColor
l.TextColor = HeaderFontColor
l.Tag = i
Header.AddView(l, ColumnWidth * i, 0, ColumnWidth, RowHeight)
Next
Activity.AddView(Header, ScrollView1.Left, ScrollView1.Top - RowHeight, ScrollView1.Width, RowHeight)
End Sub
Sub NumberOfRows As Int
Return Table.NumberOfViews / NumberOfColumns
End Sub
Sub SetCell(Row As Int, Col As Int, Value As String)
GetView(Row, Col).Text = Value
End Sub
Sub GetCell(Row As Int, Col As Int) As String
Return GetView(Row, Col).Text
End Sub
Sub ClearAll
For i = Table.NumberOfViews -1 To 0 Step -1
Table.RemoveViewAt(i)
Next
Table.Height = 0
SelectedRow = -1
End Sub
Sub TableFilling
'add rows Auslagern in ein Modul nach XML Parser
' For i = 1 To 100
AddRow(Array As String(PD_ProductID, PD_CartonContent, PD_Name, PD_Unit, PD_Tax, PD_Barcode, PD_Price, PD_inStock))
' Next
'set the value of a specific cell
' SetCell(0, 3, "New value")
'get the value
Log("Cell (1, 2) value = " & GetCell(1, 2))
End Sub
'################################################################################## ScrollView END ##########################################################################################################
'################################################################################## XMLParser START ##########################################################################################################
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If Name = "ProductID" Then
PD_ProductID = Text.ToString
End If
If Name = "CartonContent" Then
PD_CartonContent = Text.ToString
End If
If Name = "ProductName" Then
PD_Name = Text.ToString
End If
If Name = "Unit" Then
PD_Unit = Text.ToString
End If
If Name = "TaxRate" Then
PD_Tax = Text.ToString
End If
If Name = "PD_Barcode" Then
PD_Barcode = Text.ToString
End If
If Name = "PD_Price" Then
PD_Price = Text.ToString
End If
If Name = "inStock" Then
PD_inStock = Text.ToString
TableFilling
End If
End Sub
Sub JobDone (Job As HttpJob )
''Msgbox ("job","qq")
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Parser.Parse(StringToInputStream(Job.GetString), "Parser") ' PArser'e gonderiyorsun
'' Msgbox ("jobsucces","qq")
Log(Job.GetString)
'\|%&
'StartActivity("HomeScreen")
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub StringToInputStream (s As String) As InputStream
Try
Dim In As InputStream
Dim data() As Byte = s.GetBytes("UTF8")
In.InitializeFromBytesArray(data, 0, data.Length)
Return In
Catch
Log(LastException.Message )
End Try
End Sub
'################################################################################## XMLParser END ##########################################################################################################
'################################################################################## ADD NEW Account ##########################################################################################################
Sub Button1_Click
StartActivity("AccountsInsert")
End Sub