Consultor Eletrônico



Kbase P90547: How to increment fillin date fields with '+' or '-'
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   24/09/2004
Status: Unverified

GOAL:

How to add functionality to increment dates with '+' or '-'

GOAL:

How to increment date fillin fields with '+' and '-' keys.

GOAL:

In dynamics you can add functionality to the framework so that date fillin fields on dynamic viewers can be incremented and decremented by one day, with the '+' plus and '-' minus keys.

FACT(s) (Environment):

Dynamics

FIX:

1. In the procedure widgetWalk in af/app/afsesmngrp.i, modify the procedure so that it looks like the following. The additional code is between comments
/* DATE CHANGE */ and /* DATE CHANGE END */:

/* Only Date, Decimal or Integer Fill-ins will ever have popups. */
IF pcAction = "setup":U
AND LOOKUP(hWidget:TYPE, "FILL-IN":U) NE 0
AND CAN-QUERY(hWidget, "DATA-TYPE":U)
AND LOOKUP(hWidget:DATA-TYPE, "DATE,DECIMAL,INTEGER":U) NE 0 THEN
DO:
/* DATE CHANGE */
/* For date-fields add the '+' and '-' trigger to add/subtract 1 day
to/from the current day */

IF hWidget:DATA-TYPE = "DATE" THEN
DO:
ON '+':U OF hWidget PERSISTENT RUN plusOneDay IN phObject (INPUT hWidget).
ON '-':U OF hWidget PERSISTENT RUN minusOneDay IN phObject (INPUT hWidget).
END.
/* DATE CHANGE END */
/* Check whether the ShowPopup property has been explicitly set.
If so, use this value. If not, act according to the defaults. */

ASSIGN cShowPopup = "":U.
IF CAN-QUERY(hWidget, "PRIVATE-DATA":U)


2. For dynamic viewers make the following changes to ry/prc/rydynvcroi.i

/* Add F4 trigger to widget */
ON F4 OF hField PERSISTENT RUN runLookup IN gshSessionManager (INPUT hField).
ASSIGN cFieldPopupMapping =
cFieldPopupMapping +
STRING(hField) + ",":U + STRING(hPopup) + ",":U
hPopup:HIDDEN = FALSE.
END. /* show a popup */

/* DATE CHANGE */
/* For date-fields add the '+' and '-' trigger to add/subtract 1 day
to/from the current day */
IF hField:DATA-TYPE = "DATE" THEN
DO:
ON '+':U OF hField PERSISTENT RUN plusOneDay IN TARGET-PROCEDURE (INPUT hField).
ON '-':U OF hField PERSISTENT RUN minusOneDay IN TARGET-PROCEDURE (INPUT hField).
END.
/* DATE CHANGE END */

/* MODIFIED is set to true by the 4GL after setting visible to true
up above. MODIFIED is set to false for datafields when they are displayed. When certain widgets that are not dataobject-based are enabled, MODIFIED is set to false by the 4GL, for others it is not so we need to set it to false here. */

IF CAN-SET(hField, "MODIFIED":U) AND ttWidget.tVisible AND
ttWidget.tTableName EQ "":U THEN
ASSIGN hField:MODIFIED = NO.


3. Create two new procedures in viewer.p (or implement in viewrcustom.p) to implement the functionality:
PROCEDURE plusOneDay:
DEFINE INPUT PARAMETER iphWidget AS HANDLE NO-UNDO.

IF VALID-HANDLE(iphWidget) AND
CAN-QUERY(iphWidget,"data-type":u) AND
iphWidget:DATA-TYPE = "DATE":u THEN
&nb.sp; ASSIGN iphWidget:SCREEN-VALUE = iphWidget:INPUT-VALUE + 1.
RETURN NO-APPLY.
END PROCEDURE.

PROCEDURE minusOneDay:
DEFINE INPUT PARAMETER iphWidget AS HANDLE NO-UNDO.

IF VALID-HANDLE(iphWidget) AND
CAN-QUERY(iphWidget,"data-type":u) AND
iphWidget:DATA-TYPE = "DATE":u THEN
ASSIGN iphWidget:SCREEN-VALUE = iphWidget:INPUT-VALUE - 1.
RETURN NO-APPLY.
END PROCEDURE.

4. Compile:
- adm2\viewer.p
- icf\af\app\afsessrvrp.p
- icf\af\sup2\afsesclntp.p
- icf\ry\prc\rydynviewp.p.