In this section: How to: |
Your next step is to create the code that will update the fan information for the fan shown in Update_Form. Generating this code using the Language Wizard is fairly straightforward.
You must select individual fields that you want to update in a data source Unlike when you generated the ADD command using the Language Wizard. This gives you the flexibility to update just the fields that you want.
You cannot update SSN because it is a key field.
Notice that you can also select the CUSTOMER segment and move it over. The Language Wizard knows to move only updatable fields, as shown in the following image.
Select the Stack radio button and select GetFanStack from the list of data source stacks in your procedure.
The Language Wizard generates the following code:
Update fannames.CUSTOMER.LASTNAME fannames.CUSTOMER.FIRSTNAME fannames.CUSTOMER.COMPANY fannames.CUSTOMER.ADDRESS fannames.CUSTOMER.CITY fannames.CUSTOMER.STATE fannames.CUSTOMER.ZIP fannames.CUSTOMER.PHONE fannames.CUSTOMER.EMAIL fannames.CUSTOMER.TITLE fannames.CUSTOMER.ENROLLMENT_DATE from GetFanStack(GetFanStack.FocIndex);
For more information on the UPDATE command, see the Command Reference in the Maintain Language Reference manual.
How to: |
Your next step is to create the code that will delete the fan shown in the Update/Delete form from the fannames data source. Generating this code using the Language Wizard is fairly straightforward.
However, think about the flow of forms in your application. After you delete the fan from the data source, you do not want to display the information about the fan in the Update_Form, so you should close the Update_Form.
Instead of closing using the Close form button in the Event Handler editor, you will use the Winform command to close the form. The Winform command enables you to manipulate forms at run time, including opening forms, closing forms, determining properties of forms and their controls, and setting properties of forms and controls.
Select the Stack radio button and select GetFanStack from the list of data source stacks in your procedure.
The Language Wizard generates the code
Delete fannames.CUSTOMER.SSN from GetFanStack(GetFanStack.FocIndex) ;
which means, Delete the record that corresponds to the current row of GetFanStack from the fannames data source. For more information on the DELETE command, see the Command Reference in the Maintain Language Reference manual.
The Language Wizard generates the following syntax:
Winform Close Update_Form;
For more information on the Winform command, see the Command Reference in the Maintain Language Reference manual.
How to: |
After you close Update_Form, you return to the ShowFan form, which contains an HTML Table that displays the contents of GetFanStack. Unless you do something, the fan that you just deleted from the fannames data source will still be in GetFanStack and visible to the end user.
So, in addition to deleting the fan from fannames, you also have to delete the fan from GetFanStack.
Your first inclination might be to reload the data from fannames into GetFanStack. However, data source operations such as this one are often the bottlenecks in application design. Your application will run much more quickly if you simply delete the row from the stack, especially if your data source has a lot of records or resides on another computer).
Take a look at how to delete a row from a stack. In the following figure, you can see a diagram of what a stack looks like. The current row, the one you want to delete, is numbered FocIndex, and the number of rows in GetFanStack is FocCount.
You can leave the rows from 1 to FocIndex–1 alone, as shown in the following image.
The rows from FocIndex+1 to FocCount each need to move up one. To do this, you will copy the contents of the FocIndex+1 row into the FocIndex row. This discards the data in the FocIndex row, but that is fine because you wanted to delete it. You also have two copies of the data in the FocIndex+1 row.
Next, copy the contents of the FocIndex+2 row into the FocIndex+1 row, thus overwriting the original copy of the data in the FocIndex+1 row (but you now have the copy in the FocIndex row). You also have two copies of the data in the FocIndex+2 row.
You continue copying rows until you reach the end of the stack and have two copies of the data in the FocCount, or last row. At this point, you redefine the FocCount of the stack to be FocCount–1, thus discarding the extra copy of the data in the FocCount row.
There is a special case when FocIndex is the last row of the stack. In this case, all you need to do is redefine both FocIndex and FocCount to be FocIndex–1 and FocCount–1, respectively, as shown in the following image.
Notice at the bottom of the dialog box, that the Type Wizard uses an abbreviation of I2 to represent your data type choice.
Notice that the Type Wizard has transferred the I2 to the Type box. If you know the WebFOCUS abbreviation for your data type, you can type it directly here, as shown in the following image. You will also notice, as you continue to work in a project, that WebFOCUS Maintain saves the data types you have applied and lists them.
Note: If you double-click the CNT variable, you will see your new CNT variable listed under the $$Declarations line at the top of the Start procedure under the MAINTAIN command line.
IF GetFanStack.FocCount=GetFanStack.FocIndex THEN BEGIN COMPUTE GetFanStack.FocCount = GetFanStack.FocCount-1; COMPUTE GetFanStack.FocIndex = GetFanStack.FocIndex-1; ENDBEGIN ELSE BEGIN COMPUTE CNT = GetFanStack.FocIndex; Stack copy from GetFanStack(CNT+1) into GetFanStack(CNT) ; COMPUTE GetFanStack.FocCount = GetFanStack.FocCount-1; ENDBEGIN
Note: You can use the Language Wizard to generate the STACK COPY line of code. You can also generate the syntax for any variables by dragging them from the Project Explorer. For example, to generate the syntax for GetFanStack.FocCount, expand GetFanStack in the Project Explorer and move to the bottom of the list of columns. You will see FocCount and FocIndex at the bottom. You can now drag them into the Procedure Editor.
For the complete COPY command syntax, see the Command Reference chapter in the Maintain Language Reference manual.
WebFOCUS |