forked from patrickTingen/DataDigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wConnections.w
1414 lines (1085 loc) · 47 KB
/
wConnections.w
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12 GUI
&ANALYZE-RESUME
/* Connected Databases
*/
&Scoped-define WINDOW-NAME CURRENT-WINDOW
&Scoped-define FRAME-NAME Dialog-Frame
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Dialog-Frame
/*------------------------------------------------------------------------
Name : wConnections.w
Description : Maintain connections for DataDigger
----------------------------------------------------------------------
15-10-2009 pti Created
----------------------------------------------------------------------*/
/* Parameters Definitions --- */
&IF DEFINED(UIB_is_running)=0 &THEN
define input parameter pcCommand as character no-undo.
define input parameter pcAttribute as character no-undo.
define output parameter pcResult as character no-undo.
&ELSE
define variable pcCommand as character no-undo initial "UI".
define variable pcAttribute as character no-undo initial "".
define variable pcResult as character no-undo initial "".
&ENDIF
{ datadigger.i }
define variable gcRecordState as character no-undo initial 'nodata'.
/* Allow testing */
&IF DEFINED(UIB_is_running) <> 0 &THEN
define variable hDiggerLib as handle no-undo.
run DataDiggerLib.p persistent set hDiggerLib.
session:add-super-procedure(hDiggerLib, search-target).
/* Load or create personalized ini files */
define variable cEnvironment as character no-undo.
define variable cProgDir as character no-undo.
cEnvironment = substitute('DataDigger-&1', getUserName()).
output to value(cProgDir + cEnvironment + '.ini') append.
output close.
load cEnvironment dir cProgDir base-key 'ini' no-error.
cEnvironment = 'DataDigger'.
output to value(cProgDir + cEnvironment + '.ini') append.
output close.
load cEnvironment dir cProgDir base-key 'ini' no-error.
&ENDIF
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions ******************** */
&Scoped-define PROCEDURE-TYPE Dialog-Box
&Scoped-define DB-AWARE no
/* Name of designated FRAME-NAME and/or first browse and/or first query */
&Scoped-define FRAME-NAME Dialog-Frame
&Scoped-define BROWSE-NAME brConnections
/* Internal Tables (found by Frame, Query & Browse Queries) */
&Scoped-define INTERNAL-TABLES ttConnection
/* Definitions for BROWSE brConnections */
&Scoped-define FIELDS-IN-QUERY-brConnections ttConnection.cLogicalName ttConnection.cDescription ttConnection.lConnected
&Scoped-define ENABLED-FIELDS-IN-QUERY-brConnections
&Scoped-define SELF-NAME brConnections
&Scoped-define QUERY-STRING-brConnections FOR EACH ttConnection
&Scoped-define OPEN-QUERY-brConnections OPEN QUERY {&SELF-NAME} FOR EACH ttConnection.
&Scoped-define TABLES-IN-QUERY-brConnections ttConnection
&Scoped-define FIRST-TABLE-IN-QUERY-brConnections ttConnection
/* Definitions for DIALOG-BOX Dialog-Frame */
&Scoped-define OPEN-BROWSERS-IN-QUERY-Dialog-Frame ~
~{&OPEN-QUERY-brConnections}
/* Standard List Definitions */
&Scoped-Define ENABLED-OBJECTS btnBrowse btnDelete btnTest btnConnect ~
btnDisconnect cbSection btnAdd brConnections btnClone btnEdit btnSave ~
btnUndo
&Scoped-Define DISPLAYED-OBJECTS fiLogicalName cbSection fiDescription ~
fiDatabaseName edParameters
/* Custom List Definitions */
/* List-1,List-2,List-3,List-4,List-5,List-6 */
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME
/* ************************ Function Prototypes ********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD getNewConnectionNr Dialog-Frame
FUNCTION getNewConnectionNr RETURNS INTEGER
( /* parameter-definitions */ ) FORWARD.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* *********************** Control Definitions ********************** */
/* Define a dialog box */
/* Definitions of the field level widgets */
DEFINE BUTTON btnAdd NO-FOCUS FLAT-BUTTON
LABEL "&Add"
SIZE-PIXELS 25 BY 24 TOOLTIP "add a connection".
DEFINE BUTTON btnBrowse
LABEL "..."
SIZE-PIXELS 25 BY 24 TOOLTIP "find database".
DEFINE BUTTON btnClone NO-FOCUS FLAT-BUTTON
LABEL "&Clone"
SIZE-PIXELS 25 BY 24 TOOLTIP "clone connection".
DEFINE BUTTON btnConnect DEFAULT NO-FOCUS FLAT-BUTTON
LABEL "&Con"
SIZE-PIXELS 25 BY 24 TOOLTIP "connect selected database"
BGCOLOR 8 .
DEFINE BUTTON btnDelete NO-FOCUS FLAT-BUTTON
LABEL "&Delete"
SIZE-PIXELS 25 BY 24 TOOLTIP "delete the currently selected connection".
DEFINE BUTTON btnDisconnect NO-FOCUS FLAT-BUTTON
LABEL "&Dis"
SIZE-PIXELS 25 BY 24 TOOLTIP "disconnect selected database".
DEFINE BUTTON btnEdit NO-FOCUS FLAT-BUTTON
LABEL "&Edit"
SIZE-PIXELS 25 BY 24 TOOLTIP "change settings of currently selected connection".
DEFINE BUTTON btnSave DEFAULT NO-FOCUS FLAT-BUTTON
LABEL "&Save"
SIZE-PIXELS 25 BY 24 TOOLTIP "save changes"
BGCOLOR 8 .
DEFINE BUTTON btnTest DEFAULT
LABEL "&Test"
SIZE-PIXELS 60 BY 24 TOOLTIP "test the currently selected connection"
BGCOLOR 8 .
DEFINE BUTTON btnUndo DEFAULT NO-FOCUS FLAT-BUTTON
LABEL "&Undo"
SIZE-PIXELS 25 BY 24 TOOLTIP "cancel changes"
BGCOLOR 8 .
DEFINE VARIABLE cbSection AS CHARACTER
LABEL "Section in INI"
VIEW-AS COMBO-BOX SORT INNER-LINES 10
LIST-ITEMS "Item 1"
DROP-DOWN
SIZE-PIXELS 160 BY 21 TOOLTIP "the section in the INI file to save the settings to"
FGCOLOR 1 NO-UNDO.
DEFINE VARIABLE edParameters AS CHARACTER
VIEW-AS EDITOR SCROLLBAR-VERTICAL
SIZE-PIXELS 470 BY 180 TOOLTIP "the connection parameters for this database"
FGCOLOR 1 FONT 2 NO-UNDO.
DEFINE VARIABLE fiDatabaseName AS CHARACTER FORMAT "X(256)":U
LABEL "DB/PF name"
VIEW-AS FILL-IN
SIZE-PIXELS 375 BY 21 TOOLTIP "the physical database name or PF file name to connect"
FGCOLOR 1 NO-UNDO.
DEFINE VARIABLE fiDescription AS CHARACTER FORMAT "X(256)":U
LABEL "Description"
VIEW-AS FILL-IN
SIZE-PIXELS 400 BY 21 TOOLTIP "the description of this connection"
FGCOLOR 1 NO-UNDO.
DEFINE VARIABLE fiLogicalName AS CHARACTER FORMAT "X(256)":U
LABEL "Logical Name"
VIEW-AS FILL-IN
SIZE-PIXELS 160 BY 21 TOOLTIP "the logical name for this connection (no spaces)"
FGCOLOR 1 NO-UNDO.
/* Query definitions */
&ANALYZE-SUSPEND
DEFINE QUERY brConnections FOR
ttConnection SCROLLING.
&ANALYZE-RESUME
/* Browse definitions */
DEFINE BROWSE brConnections
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS brConnections Dialog-Frame _FREEFORM
QUERY brConnections DISPLAY
ttConnection.cLogicalName
ttConnection.cDescription
ttConnection.lConnected
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
WITH NO-ROW-MARKERS SEPARATORS
&IF '{&WINDOW-SYSTEM}' = 'TTY':U &THEN SIZE 60 BY 15
&ELSE SIZE-PIXELS 299 BY 324 &ENDIF FIT-LAST-COLUMN.
/* ************************ Frame Definitions *********************** */
DEFINE FRAME Dialog-Frame
btnBrowse AT Y 90 X 760 WIDGET-ID 56
btnDelete AT Y 5 X 565 WIDGET-ID 14
btnTest AT Y 325 X 725 WIDGET-ID 42
btnConnect AT Y 5 X 315 WIDGET-ID 48
fiLogicalName AT Y 40 X 375 COLON-ALIGNED WIDGET-ID 4
btnDisconnect AT Y 5 X 340 WIDGET-ID 52
cbSection AT Y 40 X 615 COLON-ALIGNED WIDGET-ID 54
btnAdd AT Y 5 X 390 WIDGET-ID 2
fiDescription AT Y 65 X 375 COLON-ALIGNED WIDGET-ID 38
fiDatabaseName AT Y 92 X 375 COLON-ALIGNED WIDGET-ID 6
brConnections AT Y 1 X 1 WIDGET-ID 200
btnClone AT Y 5 X 415 WIDGET-ID 46
edParameters AT Y 145 X 315 NO-LABEL WIDGET-ID 10
btnEdit AT Y 5 X 440 WIDGET-ID 12
btnSave AT Y 5 X 490 WIDGET-ID 22
btnUndo AT Y 5 X 515 WIDGET-ID 24
"Parameters:" VIEW-AS TEXT
SIZE-PIXELS 120 BY 13 AT Y 130 X 315 WIDGET-ID 18
WITH VIEW-AS DIALOG-BOX KEEP-TAB-ORDER
SIDE-LABELS NO-UNDERLINE THREE-D
SIZE-PIXELS 798 BY 382
TITLE "Database Connections" DROP-TARGET WIDGET-ID 100.
/* *********************** Procedure Settings ************************ */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Dialog-Box
Allow: Basic,Browse,DB-Fields,Query
Other Settings: COMPILE
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* *********** Runtime Attributes and AppBuilder Settings *********** */
&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR DIALOG-BOX Dialog-Frame
FRAME-NAME Custom */
/* BROWSE-TAB brConnections fiDatabaseName Dialog-Frame */
ASSIGN
FRAME Dialog-Frame:SCROLLABLE = FALSE
FRAME Dialog-Frame:HIDDEN = TRUE.
ASSIGN
brConnections:ALLOW-COLUMN-SEARCHING IN FRAME Dialog-Frame = TRUE
brConnections:COLUMN-RESIZABLE IN FRAME Dialog-Frame = TRUE.
/* SETTINGS FOR EDITOR edParameters IN FRAME Dialog-Frame
NO-ENABLE */
/* SETTINGS FOR FILL-IN fiDatabaseName IN FRAME Dialog-Frame
NO-ENABLE */
/* SETTINGS FOR FILL-IN fiDescription IN FRAME Dialog-Frame
NO-ENABLE */
/* SETTINGS FOR FILL-IN fiLogicalName IN FRAME Dialog-Frame
NO-ENABLE */
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME
/* Setting information for Queries and Browse Widgets fields */
&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE brConnections
/* Query rebuild information for BROWSE brConnections
_START_FREEFORM
OPEN QUERY {&SELF-NAME} FOR EACH ttConnection.
_END_FREEFORM
_Query is OPENED
*/ /* BROWSE brConnections */
&ANALYZE-RESUME
/* ************************ Control Triggers ************************ */
&Scoped-define SELF-NAME Dialog-Frame
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL Dialog-Frame Dialog-Frame
ON DROP-FILE-NOTIFY OF FRAME Dialog-Frame /* Database Connections */
do:
run addConnections.
end.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL Dialog-Frame Dialog-Frame
ON MOUSE-SELECT-CLICK OF FRAME Dialog-Frame /* Database Connections */
DO:
define variable hWidget as handle no-undo.
hWidget = getWidgetUnderMouse(input frame dialog-frame:handle).
if not valid-handle(hWidget) then return.
if lookup(hWidget:name, "fiLogicalName,fiDescription,cbSection,fiDatabaseName,edParameters") > 0 then
run btnEditChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL Dialog-Frame Dialog-Frame
ON WINDOW-CLOSE OF FRAME Dialog-Frame /* Database Connections */
DO:
APPLY "END-ERROR":U TO SELF.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define BROWSE-NAME brConnections
&Scoped-define SELF-NAME brConnections
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL brConnections Dialog-Frame
ON START-SEARCH OF brConnections IN FRAME Dialog-Frame
DO:
run openConnectionQuery(input self:current-column:name,?).
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL brConnections Dialog-Frame
ON VALUE-CHANGED OF brConnections IN FRAME Dialog-Frame
DO:
run viewConnection.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnAdd
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnAdd Dialog-Frame
ON CHOOSE OF btnAdd IN FRAME Dialog-Frame /* Add */
or "insert-mode" of brConnections
DO:
run btnAddChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnBrowse
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnBrowse Dialog-Frame
ON CHOOSE OF btnBrowse IN FRAME Dialog-Frame /* ... */
do:
define variable lOkay as logical no-undo.
define variable cFileName as character no-undo.
cFileName = fiDatabaseName:screen-value.
system-dialog get-file cFilename
filters "Databases (*.db)" "*.db",
"All Files (*.*)" "*.*"
initial-filter 1
must-exist
use-filename
default-extension ".db"
update lOkay.
if not lOkay then
return.
do with frame {&frame-name}:
fiDatabaseName:screen-value = cFileName.
end.
end.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnClone
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnClone Dialog-Frame
ON CHOOSE OF btnClone IN FRAME Dialog-Frame /* Clone */
or "shift-ins" of brConnections
or "alt-o" of brConnections
DO:
run btnCloneChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnConnect
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnConnect Dialog-Frame
ON CHOOSE OF btnConnect IN FRAME Dialog-Frame /* Con */
do:
run btnConnectChoose.
end.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnDelete
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnDelete Dialog-Frame
ON CHOOSE OF btnDelete IN FRAME Dialog-Frame /* Delete */
or "delete-character" of brConnections
do:
run btnDeleteChoose.
end.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnDisconnect
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnDisconnect Dialog-Frame
ON CHOOSE OF btnDisconnect IN FRAME Dialog-Frame /* Dis */
DO:
run btnDisconnectChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnEdit
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnEdit Dialog-Frame
ON CHOOSE OF btnEdit IN FRAME Dialog-Frame /* Edit */
or "DEFAULT-ACTION" of brConnections
DO:
run btnEditChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnSave
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnSave Dialog-Frame
ON CHOOSE OF btnSave IN FRAME Dialog-Frame /* Save */
or "RETURN" of fiLogicalName, fiDescription, fiDatabaseName, cbSection
DO:
run btnSaveChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnTest
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnTest Dialog-Frame
ON CHOOSE OF btnTest IN FRAME Dialog-Frame /* Test */
DO:
run btnTestChoose.
end.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME btnUndo
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnUndo Dialog-Frame
ON CHOOSE OF btnUndo IN FRAME Dialog-Frame /* Undo */
DO:
run btnUndoChoose.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME fiLogicalName
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL fiLogicalName Dialog-Frame
ON ANY-PRINTABLE OF fiLogicalName IN FRAME Dialog-Frame /* Logical Name */
DO:
if lastkey = 32 then
do:
apply '_'.
return no-apply.
end.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&UNDEFINE SELF-NAME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Dialog-Frame
/* *************************** Main Block *************************** */
/* Parent the dialog-box to the ACTIVE-WINDOW, if there is no parent. */
IF VALID-HANDLE(ACTIVE-WINDOW) AND FRAME {&FRAME-NAME}:PARENT eq ?
THEN FRAME {&FRAME-NAME}:PARENT = ACTIVE-WINDOW.
ON END-ERROR OF frame Dialog-Frame
OR ENDKEY OF frame Dialog-Frame anywhere
do:
if fiLogicalName:sensitive then
do:
run btnUndoChoose.
return no-apply.
end.
END.
/* 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 initializeObject.
case pcCommand:
when 'connect' then run connectDatabase(input pcAttribute, output pcResult).
when 'getConnections' then run getConnections(output pcResult).
when 'UI' then do:
RUN enable_UI.
run openConnectionQuery(?,?).
apply "value-changed" to brConnections in frame {&frame-name}.
apply "ENTRY" to brConnections in frame {&frame-name}.
WAIT-FOR GO OF FRAME {&FRAME-NAME}.
end.
end case.
END.
RUN disable_UI.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ********************** Internal Procedures *********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE addConnections Dialog-Frame
PROCEDURE addConnections :
/*------------------------------------------------------------------------
Name : addConnections
Description : Add dropped files as connections
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
define variable iFile as integer no-undo.
define variable cFile as character no-undo.
define variable cName as character no-undo.
define variable rReposition as rowid no-undo.
define variable cContents as longchar no-undo.
DO WITH FRAME dialog-frame:
/* If we are in edit-mode, accept only the first dropped file */
if gcRecordState = "edit"
and self:get-dropped-file(1) matches "*~.pf" then
fiDatabaseName:screen-value = self:get-dropped-file(1).
/* Otherwise, add all files as new connections */
else
do iFile = 1 to self:num-dropped-files:
cFile = self:get-dropped-file(iFile).
if not cFile matches "*~.pf" and not cFile matches "*~.db" then next.
cName = entry(num-entries(cFile,"\"),cFile,"\").
if not can-find(first ttConnection where ttConnection.cDatabaseName = cName) then
do:
create ttConnection.
assign
ttConnection.iConnectionNr = getNewConnectionNr()
ttConnection.cLogicalName = entry(1,cName,".")
ttConnection.cLogicalName = replace(ttConnection.cLogicalName,' ','_')
ttConnection.cDescription = entry(1,cName,".")
ttConnection.cDatabaseName = cFile
ttConnection.cSection = ttConnection.cLogicalName
ttConnection.lConnected = false
.
/* Different settings for PF and DB files */
if cName matches "*~.db" then
ttConnection.cParameters = "-1".
else
do:
copy-lob from file cFile to cContents NO-CONVERT.
ttConnection.cParameters = string(cContents).
end.
/* Save to registry */
run saveConnection(buffer ttConnection).
if rReposition = ? then rReposition = rowid(ttConnection).
end.
end.
if rReposition <> ? then
do:
run openConnectionQuery(?,?).
brConnections:query:reposition-to-rowid(rReposition) no-error.
apply "VALUE-CHANGED" to brConnections.
end.
END.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnAddChoose Dialog-Frame
PROCEDURE btnAddChoose :
/*------------------------------------------------------------------------
Name : btnAddChoose
Description : Set screen to add-mode
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
gcRecordState = 'new'.
create ttConnection.
assign ttConnection.iConnectionNr = getNewConnectionNr().
run viewConnection.
run setToolbar.
apply "ENTRY" to fiLogicalName in frame dialog-frame.
END PROCEDURE. /* btnAddChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnCloneChoose Dialog-Frame
PROCEDURE btnCloneChoose :
/*------------------------------------------------------------------------
Name : btnCloneChoose
Description : Duplicate a connection and go to update-mode
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
define buffer bfOriginalConnection for ttConnection.
gcRecordState = 'new'.
find bfOriginalConnection
where rowid(bfOriginalConnection) = rowid(ttConnection).
create ttConnection.
buffer-copy bfOriginalConnection to ttConnection
assign ttConnection.iConnectionNr = getNewConnectionNr()
ttConnection.lConnected = false.
run viewConnection.
run setToolbar.
apply "ENTRY" to fiLogicalName in frame dialog-frame.
END PROCEDURE. /* btnCloneChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnConnectChoose Dialog-Frame
PROCEDURE btnConnectChoose :
/*------------------------------------------------------------------------
Name : btnConnectChoose
Description : Try to connect to the current connection
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
define variable iError as integer no-undo.
define variable cError as character no-undo initial 'Errors:'.
define variable lAlreadyConnected as logical no-undo.
DO WITH FRAME dialog-frame:
/* Warn if already connected */
lAlreadyConnected = (lookup( fiLogicalName:screen-value, getDatabaseList()) > 0).
/* Try to establish a connection */
session:set-wait-state('general').
run connectDatabase(input fiLogicalName:screen-value, output cError).
session:set-wait-state('').
/* Refresh connection status */
ttConnection.lConnected = (lookup( ttConnection.cLogicalName, getDatabaseList() ) > 0).
brConnections:refresh().
run viewConnection.
/* If no success, show why */
if error-status:error then
do:
do iError = 1 TO error-status:num-messages:
cError = substitute('&1~n&2 (&3)'
, cError
, error-status:get-message(iError)
, error-status:get-number(iError)
).
end.
message cError view-as alert-box info buttons ok.
apply "ENTRY" to brConnections.
return no-apply.
end.
else
/* Success, but report if db was already connected */
if lAlreadyConnected then
do:
message 'Database already connected' view-as alert-box info buttons ok.
apply "ENTRY" to brConnections.
return no-apply.
end.
apply "ENTRY" to brConnections.
END.
END PROCEDURE. /* btnConnectChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnDeleteChoose Dialog-Frame
PROCEDURE btnDeleteChoose :
/*------------------------------------------------------------------------
Name : btnDeleteChoose
Description : Delete a connection
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
define variable lOk as logical no-undo initial true.
define variable iConn as integer no-undo.
define variable rConnection as rowid no-undo.
define variable rDelete as rowid no-undo.
DO WITH FRAME dialog-frame:
message 'Delete this connection?' view-as alert-box info buttons yes-no-cancel update lOk.
if lOk = true then
do:
/* Delete from registry */
iConn = ttConnection.iConnectionNr.
setRegistry('Connections', substitute('&1-ldbname' , string(iConn,'999')), ? ).
setRegistry('Connections', substitute('&1-description', string(iConn,'999')), ? ).
setRegistry('Connections', substitute('&1-pdbname' , string(iConn,'999')), ? ).
setRegistry('Connections', substitute('&1-parameters' , string(iConn,'999')), ? ).
/* Remember record to delete */
rDelete = brConnections:query:get-buffer-handle(1):rowid.
/* And try to find the "next" connection, from the query's point of view */
if brConnections:query:get-next then
rConnection = brConnections:query:get-buffer-handle(1):rowid.
/* Find back record to delete */
brConnections:query:reposition-to-rowid(rDelete) no-error.
delete ttConnection.
/* Point browse to next connection */
brConnections:query:reposition-to-rowid(rConnection) no-error.
/* And reopen */
run openConnectionQuery(?,?).
run viewConnection.
end.
apply "ENTRY" to brConnections.
END.
END PROCEDURE. /* btnDeleteChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnDisconnectChoose Dialog-Frame
PROCEDURE btnDisconnectChoose :
/*------------------------------------------------------------------------
Name : btnDisconnectChoose
Description : Disconnect db
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
DEFINE VARIABLE cCurrentDb AS CHARACTER NO-UNDO.
DEFINE VARIABLE lDisconnect AS LOGICAL NO-UNDO.
cCurrentDb = fiLogicalName:screen-value in frame dialog-frame.
message substitute('Are you sure you want to disconnect database "&1"?', cCurrentDb)
view-as alert-box info buttons yes-no-cancel update lDisconnect.
if lDisconnect <> yes then return.
disconnect value(cCurrentDb).
removeConnection(cCurrentDb).
ttConnection.lConnected = (lookup( ttConnection.cLogicalName, getDatabaseList() ) > 0).
brConnections:refresh().
run viewConnection.
apply "ENTRY" to brConnections.
END PROCEDURE. /* btnDisconnectChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnEditChoose Dialog-Frame
PROCEDURE btnEditChoose :
/*------------------------------------------------------------------------
Name : btnEditChoose
Description : Set screen to edit-mode
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
DO WITH FRAME dialog-frame:
gcRecordState = 'edit'.
run setToolbar.
apply "ENTRY" to fiLogicalName in frame dialog-frame.
END.
END PROCEDURE. /* btnEditChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnSaveChoose Dialog-Frame
PROCEDURE btnSaveChoose :
/*------------------------------------------------------------------------
Name : btnSaveChoose
Description : Save the current connection
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
DO WITH FRAME dialog-frame:
/* No spaces in logical name */
fiLogicalName:screen-value = replace(fiLogicalName:screen-value,' ','_').
assign
ttConnection.cLogicalName = fiLogicalName:screen-value
ttConnection.cDescription = fiDescription:screen-value
ttConnection.cDatabaseName = fiDatabaseName:screen-value
ttConnection.cSection = cbSection:screen-value
ttConnection.cParameters = edParameters:screen-value
.
if ttConnection.cSection = ? then ttConnection.cSection = ttConnection.cLogicalName.
/* Save to registry */
run saveConnection(buffer ttConnection).
run openConnectionQuery(?,?).
run viewConnection.
apply "ENTRY" to brConnections.
END.
END PROCEDURE. /* btnSaveChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnTestChoose Dialog-Frame
PROCEDURE btnTestChoose :
/*------------------------------------------------------------------------
Name : btnTestChoose
Description : Test the current connection
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
define variable iError as integer no-undo.
define variable cError as character no-undo initial 'Errors:'.
define variable lAlreadyConnected as logical no-undo.
DO WITH FRAME dialog-frame:
lAlreadyConnected = (lookup( fiLogicalName:screen-value, getDatabaseList()) > 0).
/* Try to establish a connection */
session:set-wait-state('general').
connect value(fiDatabaseName:screen-value)
value(edParameters:screen-value)
value(substitute(' -ld &1', fiLogicalName:screen-value))
no-error.
session:set-wait-state('').
/* If no success, show why */
if error-status:error then
do:
do iError = 1 TO error-status:num-messages:
cError = substitute('&1~n&2 (&3)'
, cError
, error-status:get-message(iError)
, error-status:get-number(iError)
).
end.
message cError view-as alert-box info buttons ok.
end.
else
do:
/* Otherwise disconnect the db since it's only a test */
if not lAlreadyConnected then
disconnect value(ldbname(num-dbs)).
message 'Connection successful' view-as alert-box info buttons ok.
end.
END.
END PROCEDURE. /* btnTestConnection */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnUndoChoose Dialog-Frame
PROCEDURE btnUndoChoose :
/*------------------------------------------------------------------------
Name : btnUndoChoose
Description : Undo changes and go back to display-mode
----------------------------------------------------------------------
17-12-2012 pti Created
----------------------------------------------------------------------*/
DO WITH FRAME dialog-frame:
if gcRecordState = 'new' then delete ttConnection.
run openConnectionQuery(?,?).
run viewConnection.
if can-find(first ttConnection) then
gcRecordState = 'display'.
else
gcRecordState = 'nodata'.
run setToolbar.
apply "ENTRY" to brConnections.
end.
END PROCEDURE. /* btnUndoChoose */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE connectDatabase Dialog-Frame
PROCEDURE connectDatabase :
/*------------------------------------------------------------------------
Name : connectDatabase
Description : Try to connect to a given database.
----------------------------------------------------------------------
22-01-2009 pti Created
----------------------------------------------------------------------*/
define input parameter pcConnection as character no-undo.
define output parameter pcError as character no-undo.
define variable iError as integer no-undo.
define buffer bConnection for ttConnection.
/* Find the connection */
find bConnection where bConnection.cLogicalName = pcConnection no-lock no-error.
if not available bConnection then
do:
assign pcError = 'No such connection known'.
return.