VB开发安卓程序_例程3类DBUtils1操作SQLite数据库

工程源码已上传。


类DBUtils


布局文件

运行截图

运行截图 

main模块源码

#Region Module Attributes
	#FullScreen: False
	#IncludeTitle: True
	#ApplicationLabel: DBUtils
	#VersionCode: 2
	#VersionName: 1.01
	#SupportedOrientations: portrait
#End Region

Sub Process_Globals
	
End Sub

Sub Globals
	Private lblStudentName As Label
	Private spnrStudentId As Spinner
	Private spnrTests As Spinner
	Private lblBirthday As Label
	Private lstFailedTest As ListView
	Private txtGrade As EditText
	Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("1")
	'Fill the students id spinner.
	DBUtils.ExecuteSpinner(Starter.SQL, "SELECT Id FROM Students", Null, 0, spnrStudentId)
	spnrStudentId_ItemClick(0, spnrStudentId.GetItem(0))
End Sub

Sub ShowTableInWebView 'ignore
	WebView1.Visible = True
	'[First Name] || ' ' || [Last Name] As Name => 
	'Creates a column named Name which is made of the First Name AND Last Name fields (with a space between them).
	
	'date(birthday / 1000, 'unixepoch', 'localtime') =>
	'Create a column named Birthday. This method converts the stored B4A time (milliseconds since 1/1/1970) to a string.
	WebView1.LoadHtml(DBUtils.ExecuteHtml(Starter.SQL, _
		"SELECT Id, [First Name] || ' ' || [Last Name] As Name, date(birthday / 1000, 'unixepoch', 'localtime') As Birthday FROM Students" _
			, Null, 0, True))
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
	'parse the row and column numbers from the URL
	Dim values() As String
	values = Regex.Split("[.]", Url.SubString(7))
	Dim col, row As Int
	col = values(0)
	row = values(1)
	ToastMessageShow("User pressed on column: " & col & " and row: " & row, False)
	Return True 'Don't try to navigate to this URL
End Sub

Sub ExportToJSON 'ignore
	Dim gen As JSONGenerator
	gen.Initialize(DBUtils.ExecuteJSON(Starter.SQL, "SELECT Id, [Last Name], Birthday FROM Students", Null, _
		0, Array As String(DBUtils.DB_TEXT, DBUtils.DB_TEXT, DBUtils.DB_INTEGER)))
	Dim JSONString As String
	JSONString = gen.ToPrettyString(4)
	Msgbox(JSONString, "")
End Sub

Sub spnrStudentId_ItemClick (Position As Int, Value As Object)
	Dim m As Map
	m = DBUtils.ExecuteMap(Starter.SQL, "SELECT Id, [First Name], [Last Name], Birthday FROM students WHERE id = ?", _
		Array As String(Value))
	If m = Null Or m.IsInitialized = False Then 'Null will return if there is no match
		lblStudentName.Text = "N/A"
		lblBirthday.Text = ""
	Else
		lblStudentName.Text = m.Get("first name") & " " & m.Get("last name") 'keys are lower cased!
		lblBirthday.Text = DateTime.Date(m.Get("birthday"))
	End If
	'Get the tests for this specific student (currently it is all tests).
	DBUtils.ExecuteSpinner(Starter.SQL, "SELECT test FROM Grades WHERE id = ?", _
		Array As String(Value), 0, spnrTests)
	spnrTests.SelectedIndex = 0
	spnrTests_ItemClick(0, spnrTests.GetItem(0))
	FindFailedTests(Value)
End Sub

Sub spnrTests_ItemClick (Position As Int, Value As Object)
	'Show the grade of this test
	Dim m As Map = DBUtils.ExecuteMap(Starter.SQL, "SELECT Grade FROM Grades WHERE id = ? AND test = ?"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值