Platforms to show: All Mac Windows Linux Cross-Platform
/Main/Web Edition Examples/Little database sample Web1
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Web Edition Examples/Little database sample Web1
This example is the version from Mon, 18th Mar 2012.
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Web Edition Examples/Little database sample Web1
This example is the version from Mon, 18th Mar 2012.
Project "Little database sample Web1.xojo_binary_project"
Class App Inherits WebApplication
EventHandler Sub Open()
db = new REALSQLDatabase
db.DatabaseFile = SpecialFolder.desktop.Child("registrations.db")
if db.DatabaseFile.Exists then
if db.Connect then
print "Connected to database."
// ok
else
System.DebugLog "Failed to connect to database."
quit
end if
else
if db.CreateDatabaseFile then
print "Created database."
db.SQLExecute "CREATE TABLE Users (Firstname varchar, Lastname varchar, Email varchar)"
db.Commit
else
System.DebugLog "Failed to create database."
quit
end if
end if
End EventHandler
Property db As REALSQLDatabase
End Class
Class Session Inherits WebSession
End Class
Class AdminPage Inherits WebPage
Control Liste Inherits WebListBox
ControlInstance Liste Inherits WebListBox
EventHandler Sub SelectionChanged()
if Liste.ListIndex >= 0 then
DeleteButton.Enabled = true
EditButton.Enabled = true
else
DeleteButton.Enabled = false
EditButton.Enabled = false
end if
End EventHandler
End Control
Control AddButton Inherits WebButton
ControlInstance AddButton Inherits WebButton
EventHandler Sub Action()
dim d as integer = 0
dim c as integer = Runtime.ObjectCount
for i as integer = 0 to c
if instr(Runtime.ObjectClass(i), "AdminPage")>0 then
d = d + 1
end if
next
EditPage.Add
EditPage.show
End EventHandler
End Control
Control EditButton Inherits WebButton
ControlInstance EditButton Inherits WebButton
EventHandler Sub Action()
dim index as integer = liste.ListIndex
if index>=0 then
dim RowID as string = liste.RowTag(index)
EditPage.Edit RowID
EditPage.show
end if
End EventHandler
End Control
Control DeleteButton Inherits WebButton
ControlInstance DeleteButton Inherits WebButton
EventHandler Sub Action()
dim index as integer = liste.ListIndex
if index>=0 then
dim RowID as string = liste.RowTag(index)
app.db.SQLExecute "DELETE FROM Users WHERE RowID="+RowID
app.db.Commit
EditButton.Enabled = false
DeleteButton.Enabled = false
end if
End EventHandler
End Control
Control RefreshButton Inherits WebButton
ControlInstance RefreshButton Inherits WebButton
EventHandler Sub Action()
update
End EventHandler
End Control
EventHandler Sub Open()
update
End EventHandler
Sub Update()
EditButton.Enabled = false
DeleteButton.Enabled = false
liste.DeleteAllRows
dim r as RecordSet = app.db.SQLSelect("select RowID,Firstname,Lastname,Email from Users")
dim RowID, Firstname, Lastname, Email as string
while not r.EOF
RowID = r.IdxField(1).StringValue
Firstname = r.IdxField(2).StringValue
Lastname = r.IdxField(3).StringValue
Email = r.IdxField(4).StringValue
liste.AddRow Firstname, Lastname, Email
liste.RowTag(liste.LastIndex)=RowID
r.MoveNext
wend
End Sub
End Class
Class LoginPage Inherits WebPage
Control Label1 Inherits WebLabel
ControlInstance Label1 Inherits WebLabel
End Control
Control Label2 Inherits WebLabel
ControlInstance Label2 Inherits WebLabel
End Control
Control LoginField Inherits WebTextField
ControlInstance LoginField Inherits WebTextField
End Control
Control PasswordField Inherits WebTextField
ControlInstance PasswordField Inherits WebTextField
End Control
Control LoginButton Inherits WebButton
ControlInstance LoginButton Inherits WebButton
EventHandler Sub Action()
if LoginField.text = "admin" and PasswordField.text = "test" then
AdminPage.show
else
MsgBox "Invalid login."
end if
End EventHandler
End Control
Control Label3 Inherits WebLabel
ControlInstance Label3 Inherits WebLabel
End Control
End Class
Class EditPage Inherits WebPage
Control Label1 Inherits WebLabel
ControlInstance Label1 Inherits WebLabel
End Control
Control Firstname Inherits WebTextField
ControlInstance Firstname Inherits WebTextField
EventHandler Sub TextChanged()
update
End EventHandler
End Control
Control Label2 Inherits WebLabel
ControlInstance Label2 Inherits WebLabel
End Control
Control Lastname Inherits WebTextField
ControlInstance Lastname Inherits WebTextField
EventHandler Sub TextChanged()
update
End EventHandler
End Control
Control Email Inherits WebTextField
ControlInstance Email Inherits WebTextField
EventHandler Sub TextChanged()
update
End EventHandler
End Control
Control Label3 Inherits WebLabel
ControlInstance Label3 Inherits WebLabel
End Control
Control OKButton Inherits WebButton
ControlInstance OKButton Inherits WebButton
EventHandler Sub Action()
dim Firstname as string = self.Firstname.text
dim Lastname as string = self.Lastname.text
dim Email as string = self.Email.text
if RowID = "" then
// add
dim r as new DatabaseRecord
r.Column("Firstname") = Firstname
r.Column("Lastname") = Lastname
r.Column("Email") = Email
app.db.InsertRecord("Users",r)
app.db.Commit
AdminPage.Update
AdminPage.show
else
// edit
dim r as RecordSet = app.db.SQLSelect("SELECT Firstname, Lastname, Email FROM Users WHERE RowID="+RowID)
r.Edit
r.IdxField(1).StringValue = Firstname
r.IdxField(2).StringValue = Lastname
r.IdxField(3).StringValue = Email
r.Update
app.db.Commit
AdminPage.Update
AdminPage.show
end if
End EventHandler
End Control
Control CancelButton Inherits WebButton
ControlInstance CancelButton Inherits WebButton
EventHandler Sub Action()
AdminPage.Update
AdminPage.show
End EventHandler
End Control
EventHandler Sub Close()
System.DebugLog "Editpage close"
End EventHandler
EventHandler Sub Open()
System.DebugLog "Editpage open"
End EventHandler
Sub Add()
self.RowID = ""
Firstname.text = ""
Lastname.text = ""
Email.text = ""
OKButton.Enabled = false
End Sub
Sub Edit(RowID as string)
self.RowID = RowID
dim r as RecordSet = app.db.SQLSelect("SELECT Firstname,Lastname,Email FROM Users WHERE RowID = "+RowID)
Firstname.text = r.IdxField(1).StringValue
Lastname.text = r.IdxField(2).StringValue
Email.text = r.IdxField(3).StringValue
End Sub
Sub update()
if len(Firstname.text)>0 and len(Lastname.text)>0 and len(email.text)>0 then
OKButton.Enabled = true
else
OKButton.Enabled = false
end if
End Sub
Property RowID As string
End Class
End Project
See also:
- /Main/Web Edition Examples/Infos Web1
- /Main/Web Edition Examples/Infos Web2
- /Main/Web Edition Examples/Invisible FileUploader with Button Web1
- /Main/Web Edition Examples/Music in Web App Web1
- /Main/Web Edition Examples/TicTacToe game/TicTacToe game Web1
- /Main/Web Edition Examples/TicTacToe game/TicTacToe game Web2
- /Main/Web Edition Examples/WebApp with missing pictures Web1
- /Main/Web Loadbalancer Example/MyApp
The items on this page are in the following plugins: MBS Main Plugin.
Feedback: Report problem or ask question.