Kbase 15011: How to insert a row into an empty browser ( insert-row )
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
How to insert a row into an empty browser ( insert-row )
How to insert into an empty browse widget? (Version 8 browser)
---------------------------------------------------------------
The ability to insert into a empty browse widget
is an enhancement request for future versions of
Progress. Currently, you can insert into an empty
browse widget programmatically.
For example:
What the user sees is an empty browser and a button to insert.
The trigger code behind the insert button could be something like:
CREATE < record>.
<save-variable> = <record.keyfield>.
OPEN QUERY <query-name> FOR EACH <record> WHERE
<record.keyfield> = <save-variable>.
DISPLAY <record browse fields> WITH BROWSE <browse-name>.
This creates the record and then inserts the default values into the
browse so the user can then update the record.
The following .w demonstrates the use of an insert trigger to add a
record into an empty browser. It requires the sports database when
run. Note the use of the CHOOSE trigger for adding a new record and
the ROW-LEAVE trigger on the browser.
This example is based on an example from the Version 8 Programming
Handbook, page 9-32 and 9-33 "Creating Browse Rows in an Empty
Browse". When run without any modifications, the example program in
the documentation gives the following error:
DISPLAY WITH BROWSE stmt failed because there is no selected row
in the specified browser (427).
The code below has been modified to stop the error from occuring and
make inserting into an empty browse function the same as inserting
into a browse that contains records.
&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r2 GUI
&ANALYZE-RESUME
/* Connected Databases
sports PROGRESS
*/
&Scoped-define WINDOW-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS C-Win
/*--------------------------------------------------------------------
File:
Description:
Input Parameters:
<none>
Output Parameters:
<none>
Author:
Created:
--------------------------------------------------------------------*/
/* This .W file was created with the Progress UIB. */
/*------------------------------------------------------------------*/
/* Create an unnamed pool to store all the widgets created
by this procedure. This is a good default which assures
that this procedure's triggers and internal procedures
will execute in this procedure's storage, and that proper
cleanup will occur on deletion of the procedure. */
CREATE WIDGET-POOL.
/* *************************** Definitions ********************** */
/* Parameters Definitions --- */
/* Local Variable Definitions --- */
def var log as logical.
def var new-cust as int.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions **************** */
&Scoped-define PROCEDURE-TYPE Window
/* Name of first Frame and/or Browse and/or first Query */
&Scoped-define FRAME-NAME DEFAULT-FRAME
&Scoped-define BROWSE-NAME BROWSE-1
/* Internal Tables (found by Frame, Query & Browse Queries) */
&Scoped-define INTERNAL-TABLES sports.Customer
/* Definitions for BROWSE BROWSE-1 */
&Scoped-define FIELDS-IN-QUERY-BROWSE-1 sports.Customer.Cust-Num sports.Customer.Name sports.Customer.Phone sports.Customer.Sales-Rep
&Scoped-define ENABLED-FIELDS-IN-QUERY-BROWSE-1 sports.Customer.Name sports.Customer.Phone sports.Customer.Sales-Rep
&Scoped-define FIELD-PAIRS-IN-QUERY-BROWSE-1 ~{&FP1}Name ~{&FP2}Name ~{&FP3} ~{&FP1}Phone ~{&FP2}Phone ~{&FP3} ~{&FP1}Sales-Rep ~{&FP2}Sales-Rep ~{&FP3}
&Scoped-define ENABLED-TABLES-IN-QUERY-BROWSE-1 sports.Customer
&Scoped-define OPEN-QUERY-BROWSE-1 OPEN QUERY BROWSE-1 FOR EACH sports.Customer WHERE cust-num > 1100 NO-LOCK.
&Scoped-define FIRST-TABLE-IN-QUERY-BROWSE-1 sports.Customer
&Scoped-define TABLES-IN-QUERY-BROWSE-1 sports.Customer
/* Definitions for FRAME DEFAULT-FRAME */
&Scoped-define OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME ~{&OPEN-QUERY-BROWSE-1}
/* Standard List Definitions */
&Scoped-Define ENABLED-OBJECTS BROWSE-1 BUTTON-3 EDITOR-2
&Scoped-Define DISPLAYED-OBJECTS EDITOR-2
/* Custom List Definitions */
/* List-1,List-2,List-3,List-4,List-5,List-6 */
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME
/* *********************** Control Definitions ****************** */
/* Define the widget handle for the window */
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
DEFINE BUTTON BUTTON-3
LABEL "Add"
SIZE 9.72 BY 1.08.
DEFINE VARIABLE EDITOR-2 AS CHARACTER INITIAL
"This code demonstrates how to insert into an empty browser.
Notice the add trigger code, if not available(customer) then
create the customer. When leaving the row, the row-leave
trigger is checking browse-1:new-row. At that point, this
will no longer be a new row."
VIEW-AS EDITOR SCROLLBAR-VERTICAL
SIZE 62 BY 4 NO-UNDO.
/* Query definitions */
&ANALYZE-SUSPEND
DEFINE QUERY BROWSE-1 FOR
sports.Customer SCROLLING.
&ANALYZE-RESUME
/* Browse definitions */
DEFINE BROWSE BROWSE-1
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS BROWSE-1 C-Win _STRUCTURED
QUERY BROWSE-1 NO-LOCK DISPLAY
sports.Customer.Cust-Num
sports.Customer.Name
sports.Customer.Phone
sports.Customer.Sales-Rep
ENABLE
sports.Customer.Name
sports.Customer.Phone
sports.Customer.Sales-Rep
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
WITH NO-COLUMN-SCROLLING SEPARATORS SIZE 60 BY 7.
/* ************************ Frame Definitions ******************* */
DEFINE FRAME DEFAULT-FRAME
BROWSE-1 AT ROW 1.5 COL 10
BUTTON-3 AT ROW 9 COL 32
EDITOR-2 AT ROW 11.5 COL 8 NO-LABEL
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 80 BY 16.
/* *********************** Procedure Settings ********************* */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Window
Allow: Basic,Browse,DB-Fields,Window,Query
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* ************************* Create Window ********************** */
&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
CREATE WINDOW C-Win ASSIGN
HIDDEN = YES
TITLE = "<insert window title>"
HEIGHT = 16
WIDTH = 80
MAX-HEIGHT = 16
MAX-WIDTH = 80
VIRTUAL-HEIGHT = 16
VIRTUAL-WIDTH = 80
RESIZE = yes
SCROLL-BARS = no
STATUS-AREA = yes
BGCOLOR = ?
FGCOLOR = ?
KEEP-FRAME-Z-ORDER = yes
THREE-D = yes
MESSAGE-AREA = yes
SENSITIVE = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
&ANALYZE-RESUME
/* *************** Runtime Attributes and UIB Settings ********** */
&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW C-Win
VISIBLE,,RUN-PERSISTENT */
/* SETTINGS FOR EDITOR EDITOR-2 IN FRAME DEFAULT-FRAME
SHARED */
ASSIGN
EDITOR-2:READ-ONLY IN FRAME DEFAULT-FRAME = TRUE.
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN C-Win:HIDDEN = no.
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME
/* Setting information for Queries and Browse Widgets fields */
&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE BROWSE-1
/* Query rebuild information for BROWSE BROWSE-1
_TblList = "sports.Customer"
_Options = "NO-LOCK"
_Where[1] = "cust-num > 1100"
_FldNameList[1] = sports.Customer.Cust-Num
_FldNameList[2] > sports.Customer.Name
"Name" ? ? "character" ? ? ? ? ? ? yes ?
_FldNameList[3] > sports.Customer.Phone
"Phone" ? ? "character" ? ? ? ? ? ? yes ?
_FldNameList[4] > sports.Customer.Sales-Rep
"Sales-Rep" ? ? "character" ? ? ? ? ? ? yes ?
_Query is OPENED
*/ /* BROWSE BROWSE-1 */
&ANALYZE-RESUME
/* ************************ Control Triggers ******************* */
&Scoped-define SELF-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON END-ERROR OF C-Win /* <insert window title> */
OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
/* This case occurs when the user presses the "Esc" key.
In a persistently run window, just ignore this. If we did not, the
application would exit. */
IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON WINDOW-CLOSE OF C-Win /* <insert window title> */
DO:
/* These events will close the window and terminate the procedure. */
/* (NOTE: this will override any user-defined triggers previously */
/* defined on the window.) */
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define BROWSE-NAME BROWSE-1
&Scoped-define SELF-NAME BROWSE-1
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BROWSE-1 C-Win
ON ROW-LEAVE OF BROWSE-1 IN FRAME DEFAULT-FRAME
DO:
if browse-1:new-row then
do:
message "new row" view-as alert-box.
create customer.
assign input browse browse-1 name phone sales-rep.
display cust-num with browse browse-1.
log = browse-1:create-result-list-entry().
end.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME BUTTON-3
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BUTTON-3 C-Win
ON CHOOSE OF BUTTON-3 IN FRAME DEFAULT-FRAME /* Add */
DO:
/* If there is a row in the browser, then this will insert a new row.
If there is NOT an available customer (i.e., the browse is empty),
then a customer is created and the cust-num from the database
sequence is assigned to a temporary variable so that we can open
the query and display this new customer in the browser.
When we create the customer in this choose trigger, the row-leave
trigger will fire but it will NOT create the customer again because
the row-leave trigger for the browser first checks if this is a
new row and if it is NOT a new row, then we do NOT execute the code
in the row-leave trigger.
Notice that in this trigger code, there is no need to add an entry
into the result list because the query is re-opened.
*/
if available(customer) then
log = browse-1:insert-row().
else
do:
create customer.
new-cust = customer.cust-num.
open query browse-1 for each customer where
customer.cust-num = new-cust.
display customer.cust-num with browse browse-1.
apply "entry" to browse browse-1.
end.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&UNDEFINE SELF-NAME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK C-Win
/* *************************** Main Block *********************** */
/* Set CURRENT-WINDOW: this will parent dialog-boxes and frames. */
ASSIGN CURRENT-WINDOW = {&WINDOW-NAME}
THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}.
/*The CLOSE event can be used from inside or outside the procedure to
terminate it. */
ON CLOSE OF THIS-PROCEDURE
RUN disable_UI.
/* Best default for GUI applications is... */
PAUSE 0 BEFORE-HIDE.
/* Now enable the interface and wait for the exit condition. */
/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire.*/
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
RUN enable_UI.
IF NOT THIS-PROCEDURE:PERSISTENT THEN
WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ********************** Internal Procedures ******************* */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI C-Win _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
Purpose: DISABLE the User Interface
Parameters: <none>
Notes: Here we clean-up the user-interface by deleting
dynamic widgets we have created and/or hide
frames. This procedure is usually called when
we are ready to "clean-up" after running.
------------------------------------------------------------------- */
/* Delete the WINDOW we created */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN DELETE WIDGET C-Win.
IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI C-Win _DEFAULT-ENABLE
PROCEDURE enable_UI :
/*------------------------------------------------------------------------------
Purpose: ENABLE the User Interface
Parameters: <none>
Notes: Here we display/view/enable the widgets in the
user-interface. In addition, OPEN all queries
associated with each FRAME and BROWSE.
These statements here are based on the "Other
Settings" section of the widget Property Sheets.
------------------------------------------------------------------ */
DISPLAY EDITOR-2
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
ENABLE BROWSE-1 BUTTON-3 EDITOR-2
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
{&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
VIEW C-Win.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
Progress Software Technical Support Note # 15011