B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=9.8
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	
	Private Suppliers As SuppliersPage
	
	Private edtName, edtAddress, edtCity As B4XView
	Private ResultSet1 As ResultSet
	Private btnAdd, btnUpdate As B4XView
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
	Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	Root.LoadLayout("EditSupplier")

	Suppliers = B4XPages.MainPage.Suppliers
	
	B4XPages.SetTitle(Me, "SLQiteLight4   Edit Supplier")

	Select B4XPages.MainPage.SupplierEditMode
		Case "Add"
			InitNewItem
			btnUpdate.Visible = False
		Case "Edit"
			InitEditItem
	End Select
End Sub

Public Sub Show
	
End Sub

'Public Sub frmEditSupplier_Closed
''	ResultSet1.Close
'	Suppliers.Show
'End Sub

Sub btnAdd_Click
	Private Query As String
	
	Query = "INSERT INTO Suppliers VALUES ('" & edtName.Text & "', '" & edtAddress.Text & "', '" & edtCity.Text & "')"
	B4XPages.MainPage.SQL1.ExecNonQuery(Query)
	btnUpdate.Visible = True
	B4XPages.MainPage.Suppliers.Show
End Sub

Private Sub btnUpdate_Click
	Private Query As String
	
	Query = "UPDATE Suppliers SET Name = '" & edtName.Text & "', Address = '" & edtAddress.Text & "', City = '" & edtCity.Text & "'"
	Query = Query & " WHERE rowid = " & Suppliers.SelectedRowID
	
	B4XPages.MainPage.SQL1.ExecNonQuery(Query)
	B4XPages.MainPage.Suppliers.Show
End Sub

Private Sub InitNewItem
	edtName.Text = ""
	edtAddress.Text = ""
	edtCity.Text = ""
End Sub

Private Sub InitEditItem
	Private Query As String
	
	Query = "SELECT Name, Address, City FROM Suppliers WHERE Suppliers.rowid = " & Suppliers.SelectedRowID
	ResultSet1 = B4XPages.MainPage.SQL1.ExecQuery(Query)
	ResultSet1.NextRow
	edtName.Text = ResultSet1.GetString2(0)
	edtAddress.Text = ResultSet1.GetString2(1)
	edtCity.Text = ResultSet1.GetString2(2)
End Sub
