B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=6.47
@EndOfDesignText@
'Static code module
Sub Process_Globals
	Private fx As JFX
	
	Private frmEditSupplier As Form
	Private edtName, edtAddress, edtCity As B4XView
	Private ResultSet1 As ResultSet
	Private btnAdd, btnUpdate As B4XView
End Sub

Public Sub Show
	If frmEditSupplier.IsInitialized = False Then
		frmEditSupplier.Initialize("frmEditSupplier", 600, 600)
		frmEditSupplier.RootPane.LoadLayout("EditSupplier")
		frmEditSupplier.Title = "SLQiteLight4  Edit Supplier"
	End If

	Select B4XPages.MainPage.SupplierEditMode
		Case "Add"
			InitNewItem
			btnUpdate.Visible = False
		Case "Edit"
			InitEditItem
	End Select
	
	frmEditSupplier.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
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)
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
