-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathweb1dot0.rpgle
235 lines (209 loc) · 6.82 KB
/
web1dot0.rpgle
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
223
224
225
226
227
228
229
230
231
232
233
234
235
<%@ free="*YES"%>
<%
/* -------------------------------------------------------------------------------- *\
Super simple web 1.0 CURD application...
Public test:
http://sandbox.icebreak.org:60060/web1dot0
http://my_ibm_i:60060/web1dot0
\* -------------------------------------------------------------------------------- */
ctl-opt decEdit(*jobrun) datEdit(*YMD) main(main);
ctl-opt bndDir('ICEBREAK');
dcl-f updFile
extdesc('ICPRODUCT')
extfile(*extdesc)
usage(*input : *update: *output : *delete)
rename(PRODUCTR:updRec);
dcl-f listFile
disk(*ext)
extdesc('ICPRODUCT')
keyed
infds(InfoDS)
usage(*input)
extfile(*extdesc)
rename(PRODUCTR:listRec);
dcl-ds infoDS;
rrn int(10) pos(397);
end-ds;
// --------------------------------------------------------------------------------
// The Main logic controling the state from previous incarnations
// --------------------------------------------------------------------------------
dcl-proc Main;
// Previous function parses update or add parameter
// ------------------------------------------------
select;
// The "New" button is clicked in the inputForm form
when reqStr('Option') = 'New' ;
rrn = 0;
clear updRec;
inputForm ();
// The "Update" button is clicked in the inputForm form. Update or write new record
when reqStr('Option') = 'Update';
rrn = reqNum('sys.rrn');
if (rrn = 0) ;
form2db();
write updRec;
else;
chain rrn updRec;
Form2db();
update updRec;
endif;
loadList();
// The "Delete" button is clicked - and a rrn exists; now delete that record
when reqStr('Option') = 'Delete';
rrn = reqNum('sys.rrn');
if rrn > 0;
chain rrn updRec;
delete updrec;
endif;
loadList();
// Return without update - just reload the list
when reqStr('Option') = 'Return' ;
loadList();
// When Clicking on a row in the table the " href .." returns the "rrn" allong in the "QryStr"
when reqNum('rrn') > 0;
rrn = QryStrNum('rrn');
chain rrn updRec;
setll *hival updRec;
inputForm();
other;
loadList();
endsl;
End-proc;
// ------------------------------------------------------------------ *
// Form to database for product
// ------------------------------------------------------------------ *
dcl-proc Form2db;
PRODKEY = reqNum('PRODKEY'); // Product Key
PRODID = reqStr('PRODID'); // Product ID
DESC = reqStr('DESC'); // Description
MANUID = reqStr('MANUID'); // Manufacturer ID
PRICE = reqNum('PRICE'); // Price
STOCKCNT = reqNum('STOCKCNT'); // Stock Count
STOCKDATE = %date(reqStr('STOCKDATE')); // Stock Date
end-proc;
// --------------------------------------------------------------------------------
// Setup the HTML header and stylesheet / (evt. the script links)
// --------------------------------------------------------------------------------
dcl-proc head;
%><html>
<Head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/System/Styles/portfolio.css"/>
</head>
<body>
<h1>Product master</h1>
<%
end-proc;
// --------------------------------------------------------------------------------
// Finish up the final html
// --------------------------------------------------------------------------------
dcl-proc tail;
%></body>
</html>
<%
end-Proc;
// --------------------------------------------------------------------------------
// loadList; is much like a "load subfile". All records are placed into a html table
// --------------------------------------------------------------------------------
dcl-proc loadList;
dcl-s i int(10);
dcl-s urlManuId varchar(32);
head();
%><form method="POST" >
<input type="submit" value="New" name="Option">
</form>
<style>
tr:nth-child(even){
background-color: #fafafa;
}
</style>
<table id="tab1" >
<thead>
<tr>
<th>Product Key</th>
<th>Product ID</th>
<th>Description</th>
<th>Manufacturer ID</th>
<th>Price</th>
<th>Stock Count</th>
<th>Stock Date</th>
</tr>
</thead>
<%
// Now reload the list, e.g. Set lower limit with *loval is the first record
// then repeat reading until end-of-file or counter exhausted
// -------------------------------------------------------------------------
i = 0;
urlManuId = qryStr ('MANUID');
setll *loval listRec;
read listRec;
dow (not %eof(listFile) and i < 2000) ;
i += 1;
if manuid = urlManuId or urlManuId <= '';
// Put the table row
// -----------------
%><tr onclick="location.href='?rrn=<% = %char(rrn)%>'">
<td align="right"><% = %char(PRODKEY) %></td>
<td><% = PRODID %></td>
<td><% = DESC %></td>
<td><% = MANUID %></td>
<td align="right"><% = %char(PRICE) %></td>
<td align="right"><% = %char(STOCKCNT) %></td>
<td align="right"><% = %char(STOCKDATE) %></td>
</tr><%
endif;
// ready for the next row
// ----------------------
read listrec;
EndDo;
%></table>
<script>
var r = document.getElementById('tab1');
var l = r.rows[1].cells.length;
for (var i = 0; i<l; i++) {
var v1 = r.rows[0].cells[i].clientWidth;
var v2 = r.rows[1].cells[i].clientWidth;
var v = v1 > v2 ? v1 : v2;
r.rows[0].cells[i].style.width = v;
r.rows[1].cells[i].style.width = v;
}
</script>
<%
tail();
end-proc;
// ------------------------------------------------------------------ *
// Input Form for product
// ------------------------------------------------------------------ *
dcl-proc inputForm;
head();
%>
<style>
label {
width: 180px;
}
</style>
<form method="POST">
<input type="hidden" name="sys.rrn" value="<% = %char(rrn) %>"/>
<label>Product Key</label>
<input type="text" name="PRODKEY" value ="<% = %char(PRODKEY) %>"/>
<br/>
<label>Product ID</label>
<input type="text" name="PRODID" size="<%= %char(%size(PRODID))%>" maxlength="<%= %char(%size(PRODID))%>" value ="<% = PRODID %>"><br/>
<label>Description</label>
<textarea name="DESC" rows="4" cols="64" maxlength="<%= %char(%size(DESC))%>"><% = DESC %></textarea><br/>
<label>Manufacturer ID</label>
<input type="text" name="MANUID" size="<%= %char(%size(MANUID))%>" maxlength="<%= %char(%size(MANUID))%>" value ="<% = MANUID %>"><br/>
<label>Price</label>
<input type="text" name="PRICE" value ="<% = %char(PRICE) %>"><br/>
<label>Stock Count</label>
<input type="text" name="STOCKCNT" value ="<% = %char(STOCKCNT) %>"><br/>
<label>Stock Date</label>
<input type="text" name="STOCKDATE" size="<%= %char(%size(STOCKDATE))%>" maxlength="<%= %char(%size(STOCKDATE))%>" value ="<% = %char(STOCKDATE) %>"><br/>
<br/><br/>
<input type="submit" value="Update" name="Option">
<input type="submit" value="Delete" name="Option">
<input type="submit" value="Return" name="Option">
</form>
<%
tail();
end-Proc;