This text is a continuation of Database: Showing registry.
Continuing our previous learning, we will view the table data created in JDialogQuery window in another window and allow the user to change the registry data.
Open the window JDialogQuery and add a button titled View.
Perform double-click on the onclick event of the button View and add the following functions:
verifyValue with the parameters:
jTableProduct
SelectedRow
>
0
There is no record!
openWindow with the parameters:
JDialogAlter
"+jTableProduct.getSelectedValue("id")+"
closeWindow without parameters.
In the first function, we verify if there are records in jTableProduct. If not , displays the message "There is the record !" and stops the process of the event. In the second , we opened the JDialogAlter window (which we will create now) through the id parameter of the selected record in the table. In the third, we closed the JDialogQuery window.
Create a window, clicking with the right mouse button on Window Explorer and selecting New, with the name JDialogAlter and change the Title to Alter and Window to Dialog (Object Inspector). Add two Labels, with Text Description and Price, two TextFields, with names jTextFieldDescription and jTextFieldPrice, and a Button with Text Alter. Change the HorizontalTextAlignment of jTextFieldPrice to RIGHT and Mask to Decimal.
Perform double-click in the OnShow event of the window and add a function selectRecord with the parameters:
product
description, price
where id="+getReturn()+"
This function will select the record of the table product with the id equals to the value passed through the parameter, when we opened the window JDialogAlter from JDialogQuery.
Change the property Column of jTextFieldDescription and jTextFieldPrice to description and price. This will make when selecionarRegistro function is executed , the jTextFields receive the query values.
Select the Alter button and perform double-click on the OnClick event in the Object Inspector.
Add the function alterRecord with the parameters:
product
description='"+jTextFieldDescription.getText()+"', price='"+jTextFieldPrice.getText()+"'
where id="+getReturn()+"
Add the function closeWindow too, without parameters.
Save and Run your application, clicking on the buttons int the Toolbar or typing CTRL + S and F9.