Project

General

Profile

r-brows2.p

Igor Skornyakov, 10/23/2015 06:47 PM

Download (1.61 KB)

 
1
DEFINE VARIABLE method-return AS LOGICAL NO-UNDO.
2
DEFINE QUERY q1 FOR Customer SCROLLING.
3

    
4
DEFINE BROWSE b1 QUERY q1 NO-LOCK DISPLAY Customer.CustNum Customer.Name 
5
  Customer.Phone Customer.Discount ENABLE Customer.Name Customer.Phone Customer.Discount 
6
  WITH 15 DOWN NO-ASSIGN SEPARATORS.
7

    
8
DEFINE BUTTON button1 LABEL "New Row".
9
DEFINE FRAME f1 
10
  SKIP(1) SPACE(8) b1 SKIP(1) SPACE(8) button1
11
  WITH NO-BOX NO-HELP NO-VALIDATE NO-AUTO-VALIDATE.
12

    
13

    
14
ON ROW-LEAVE OF b1 IN FRAME f1 DO: /* No-Assign Browser */
15
  /* If new row, create record and assign values in browse. */
16
  IF b1:NEW-ROW THEN DO:
17
    CREATE Customer.
18
    ASSIGN INPUT BROWSE b1 Customer.Name Customer.Phone.
19
    DISPLAY Customer.CustNum WITH BROWSE b1.
20
    method-return = b1:CREATE-RESULT-LIST-ENTRY().
21
    RETURN.
22
  END.
23
  /* If record exists and was changed in browse, update it. */
24
  IF BROWSE b1:CURRENT-ROW-MODIFIED THEN DO:
25
    GET CURRENT q1 EXCLUSIVE-LOCK.
26
    IF CURRENT-CHANGED Customer THEN DO:
27
      MESSAGE "This record has been changed by another user." SKIP
28
        "Please re-enter your changes.".
29
      DISPLAY Customer.CustNum Customer.Name Customer.Phone WITH BROWSE b1.
30
      RETURN NO-APPLY.
31
    END.
32
    ELSE /* Record is the same, so update it with exclusive-lock */
33
      ASSIGN INPUT BROWSE b1 Customer.Name Customer.Phone.
34
      /* Downgrade the lock to a no-lock. */
35
      GET CURRENT q1 NO-LOCK.
36
  END.
37
END.
38

    
39
ON CHOOSE OF button1 IN FRAME f1 DO: /* Insert */
40
  method-return = b1:INSERT-ROW("AFTER").
41
END.
42

    
43
OPEN QUERY q1 FOR EACH Customer.
44
ENABLE ALL WITH FRAME f1.
45
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.