-
Notifications
You must be signed in to change notification settings - Fork 24
/
wConnections.w
1320 lines (1009 loc) · 41.4 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
Desc: Maintain connections for DataDigger
----------------------------------------------------------------------*/
/* This .W file was created with the Progress AppBuilder. */
/*----------------------------------------------------------------------*/
&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 540 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 425 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 425 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 825
btnDelete AT Y 5 X 560
btnTest AT Y 325 X 790
btnConnect AT Y 5 X 310
fiLogicalName AT Y 40 X 390 COLON-ALIGNED
btnDisconnect AT Y 5 X 335
cbSection AT Y 40 X 655 COLON-ALIGNED
btnAdd AT Y 5 X 385
fiDescription AT Y 65 X 390 COLON-ALIGNED
fiDatabaseName AT Y 92 X 390 COLON-ALIGNED
brConnections AT Y 1 X 1
btnClone AT Y 5 X 410
edParameters AT Y 145 X 310 NO-LABEL
btnEdit AT Y 5 X 435
btnSave AT Y 5 X 485
btnUndo AT Y 5 X 510
"Parameters:" VIEW-AS TEXT
SIZE-PIXELS 120 BY 13 AT Y 130 X 310
WITH VIEW-AS DIALOG-BOX KEEP-TAB-ORDER
SIDE-LABELS NO-UNDERLINE THREE-D
SIZE-PIXELS 873 BY 382
TITLE "Database Connections" DROP-TARGET.
/* *********************** 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 :
/* Add dropped files as connections
*/
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
#AddFile:
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 #AddFile.
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 = SUBSTRING(cContents,1,20000).
END.
/* Save to registry */
RUN saveConnection(buffer ttConnection).
IF rReposition = ? THEN rReposition = ROWID(ttConnection).
END. /* not can-find */
END. /* #AddFile */
IF rReposition <> ? THEN
DO:
RUN openConnectionQuery(?,?).
brConnections:query:reposition-to-rowid(rReposition) NO-ERROR.
APPLY "VALUE-CHANGED" TO brConnections.
END.
END. /* do with frame */
END PROCEDURE. /* addConnections */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnAddChoose Dialog-Frame
PROCEDURE btnAddChoose :
/* Set screen to add-mode
*/
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 :
/* Duplicate a connection and go to update-mode
*/
DEFINE BUFFER bfOriginalConnection FOR ttConnection.
gcRecordState = 'new'.
FIND bfOriginalConnection WHERE ROWID(bfOriginalConnection) = ROWID(ttConnection) NO-ERROR.
IF NOT AVAILABLE bfOriginalConnection THEN RETURN.
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 :
/* Try to connect to the current connection
*/
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 INFORMATION 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 INFORMATION 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 :
/* Delete a connection
*/
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 INFORMATION 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')), ? ).
setRegistry('Connections', SUBSTITUTE('&1-section' , 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 :
/* Disconnect db
*/
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 INFORMATION 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 :
/* Set screen to edit-mode
*/
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 :
/* Save the current connection
*/
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 :
/* Test the current connection
*/
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 INFORMATION 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 INFORMATION BUTTONS OK.
END.
END.
END PROCEDURE. /* btnTestConnection */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE btnUndoChoose Dialog-Frame
PROCEDURE btnUndoChoose :
/* Undo changes and go back to display-mode
*/
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 :
/* Try to connect to a given database.
*/
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.
END.
/* Try to establish a connection */
SESSION:SET-WAIT-STATE('general').
IF bConnection.cDatabaseName MATCHES "*~.pf" THEN
CONNECT value("-pf " + bConnection.cDatabaseName) NO-ERROR.
ELSE
DO:
CONNECT value(bConnection.cDatabaseName)
VALUE(bConnection.cParameters)
VALUE(SUBSTITUTE(' -ld &1', bConnection.cLogicalName)) NO-ERROR.
IF NOT ERROR-STATUS:ERROR THEN
addConnection(bConnection.cLogicalName, bConnection.cSection).
END.
SESSION:SET-WAIT-STATE('').
/* If no success, show why */
IF ERROR-STATUS:ERROR THEN
DO:
pcError = 'Error connecting database:'.
DO iError = 1 TO ERROR-STATUS:NUM-MESSAGES:
pcError = SUBSTITUTE('&1~n&2 (&3)'
, pcError
, ERROR-STATUS:GET-MESSAGE(iError)
, ERROR-STATUS:GET-NUMBER(iError)
).
END.
RETURN.
END.
END PROCEDURE. /* connectDatabase */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI Dialog-Frame _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
Purpose: DISABLE the User Interface
Parameters: <none>
Notes: Here we clean-up the user-interface by deleting
dynamic widgets we have created and/or hide
frames. This procedure is usually called when
we are ready to "clean-up" after running.
------------------------------------------------------------------------------*/
/* Hide all frames. */
HIDE FRAME Dialog-Frame.
END PROCEDURE.