-
Notifications
You must be signed in to change notification settings - Fork 0
/
lu_equip.4gl
224 lines (177 loc) · 7.14 KB
/
lu_equip.4gl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# lu_equip.4gl - 4GL source for equipment lookups
# Copyright (C) 1995 David A. Snyder All Rights Reserved
DATABASE stores
DEFINE lu_arrcount SMALLINT
DEFINE lu_arrcurr SMALLINT
DEFINE lu_scrline SMALLINT
DEFINE p_record ARRAY[64] OF RECORD
eq_id LIKE equipment.eq_id,
eqp_name LIKE equipment.eqp_name
END RECORD
{*******************************************************************************
* This function searches through the equipment table. *
*******************************************************************************}
FUNCTION lu_equip(eq_id, eqp_name)
DEFINE eq_id LIKE equipment.eq_id
DEFINE eqp_name LIKE equipment.eqp_name
DEFINE keyhit INTEGER
DEFINE scratch CHAR(512)
OPEN WINDOW ringout_equipment AT 1,1 WITH 2 ROWS, 79 COLUMNS
DISPLAY "LU-QUERY: ESCAPE queries. INTERRUPT aborts. ARROW keys move cursor.", "" AT 1,1 ATTRIBUTE(WHITE)
DISPLAY "Searches through the equipment table.", "" AT 2,1 ATTRIBUTE(WHITE)
OPEN WINDOW lu_equip AT 6, 30 WITH FORM "lu_equip"
ATTRIBUTE(BORDER, WHITE, FORM LINE FIRST + 1)
LABEL retry:
LET int_flag = FALSE
CONSTRUCT BY NAME scratch ON eq_id, eqp_name ATTRIBUTE(BOLD)
IF int_flag THEN
CLOSE WINDOW lu_equip
CLOSE WINDOW ringout_equipment
RETURN eq_id, eqp_name
END IF
LET scratch = "SELECT eq_id, eqp_name FROM equipment WHERE ", scratch CLIPPED, " ORDER BY eq_id"
PREPARE lu_stmt FROM scratch
DECLARE lu_curs CURSOR FOR lu_stmt
LET lu_arrcount = 1
FOREACH lu_curs INTO p_record[lu_arrcount].*
LET lu_arrcount = lu_arrcount + 1
END FOREACH
LET lu_arrcount = lu_arrcount - 1
IF lu_arrcount = 0 THEN
ERROR " There are no rows satisfying the conditions "
GOTO retry
END IF
LET lu_arrcurr = 1
LET lu_scrline = 1
CURRENT WINDOW IS ringout_equipment
DISPLAY "LOOKUP: ESCAPE selects. INTERRUPT aborts. ARROW keys move cursor.", "" AT 1,1 ATTRIBUTE(WHITE)
CURRENT WINDOW IS lu_equip
CALL lu_dsppage_equipment()
WHILE (TRUE)
LET keyhit = fgl_getkey()
CASE
WHEN keyhit = fgl_keyval("ACCEPT") OR keyhit = fgl_keyval("INTERRUPT")
EXIT WHILE
WHEN keyhit = fgl_keyval("DOWN") OR keyhit = fgl_keyval("RIGHT")
CALL lu_down_equipment()
WHEN keyhit = fgl_keyval("UP") OR keyhit = fgl_keyval("LEFT")
CALL lu_up_equipment()
WHEN keyhit = fgl_keyval("CONTROL-F") # NEXT KEY
CALL lu_nextpage_equipment()
WHEN keyhit = fgl_keyval("CONTROL-B") # PREVIOUS KEY
CALL lu_prevpage_equipment()
WHEN keyhit = fgl_keyval("CONTROL-G")
CALL fgl_prtscr()
OTHERWISE
ERROR ""
END CASE
END WHILE
IF int_flag THEN
LET p_record[lu_arrcurr].eq_id = eq_id
LET p_record[lu_arrcurr].eqp_name = eqp_name
LET int_flag = FALSE
END IF
CLOSE WINDOW lu_equip
CLOSE WINDOW ringout_equipment
RETURN p_record[lu_arrcurr].*
END FUNCTION
{*******************************************************************************
* This function moves the cursor in the lookup window down one line. *
*******************************************************************************}
FUNCTION lu_down_equipment()
IF lu_arrcurr + 1 > lu_arrcount THEN
ERROR " There are no more rows in the direction you are going "
RETURN
END IF
CALL lu_dspline_equipment("NORMAL")
LET lu_arrcurr = lu_arrcurr + 1
IF lu_scrline + 1 > 5 THEN
SCROLL s_record.* UP
ELSE
LET lu_scrline = lu_scrline + 1
END IF
CALL lu_dspline_equipment("REVERSE")
END FUNCTION
{*******************************************************************************
* This function moves the cursor in the lookup window up one line. *
*******************************************************************************}
FUNCTION lu_up_equipment()
IF lu_arrcurr - 1 < 1 THEN
ERROR " There are no more rows in the direction you are going "
RETURN
END IF
CALL lu_dspline_equipment("NORMAL")
LET lu_arrcurr = lu_arrcurr - 1
IF lu_scrline - 1 < 1 THEN
SCROLL s_record.* DOWN
ELSE
LET lu_scrline = lu_scrline - 1
END IF
CALL lu_dspline_equipment("REVERSE")
END FUNCTION
{*******************************************************************************
* This function moves the cursor in the lookup window down one page. *
*******************************************************************************}
FUNCTION lu_nextpage_equipment()
IF (lu_arrcurr - lu_scrline + 1) + 5 > lu_arrcount THEN
ERROR " There are no more rows in the direction you are going "
RETURN
ELSE
LET lu_arrcurr = (lu_arrcurr - lu_scrline + 1) + 5
END IF
CALL lu_dsppage_equipment()
END FUNCTION
{*******************************************************************************
* This function moves the cursor in the lookup window up one page. *
*******************************************************************************}
FUNCTION lu_prevpage_equipment()
DEFINE retval SMALLINT
IF lu_arrcurr = 1 THEN
ERROR " There are no more rows in the direction you are going "
RETURN
ELSE
IF (lu_arrcurr - lu_scrline + 1) - 5 < 1 THEN
LET lu_arrcurr = 1
ELSE
LET lu_arrcurr = (lu_arrcurr - lu_scrline + 1) - 5
END IF
END IF
CALL lu_dsppage_equipment()
END FUNCTION
{*******************************************************************************
* This function displays a page of data in the lookup window. *
*******************************************************************************}
FUNCTION lu_dsppage_equipment()
FOR lu_scrline = 1 TO 5
IF lu_arrcurr <= lu_arrcount THEN
CALL lu_dspline_equipment("NORMAL")
ELSE
CALL lu_dspline_equipment("")
END IF
LET lu_arrcurr = lu_arrcurr + 1
END FOR
LET lu_arrcurr = lu_arrcurr - 5
LET lu_scrline = 1
CALL lu_dspline_equipment("REVERSE")
END FUNCTION
{*******************************************************************************
* This function displays a line of data in the lookup window. *
*******************************************************************************}
FUNCTION lu_dspline_equipment(style)
DEFINE style CHAR(7)
DEFINE lu_offset SMALLINT
CASE
WHEN style IS NULL
DISPLAY "", ""
TO s_record[lu_scrline].eq_id, s_record[lu_scrline].eqp_name
WHEN style = "NORMAL"
DISPLAY p_record[lu_arrcurr].eq_id, p_record[lu_arrcurr].eqp_name
TO s_record[lu_scrline].eq_id, s_record[lu_scrline].eqp_name
WHEN style = "REVERSE"
DISPLAY p_record[lu_arrcurr].eq_id, p_record[lu_arrcurr].eqp_name
TO s_record[lu_scrline].eq_id, s_record[lu_scrline].eqp_name
ATTRIBUTE(REVERSE)
END CASE
LET lu_offset = lu_scrline + 3
DISPLAY " " AT lu_offset,1
END FUNCTION