-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathabdev.PRG
More file actions
8108 lines (6585 loc) · 246 KB
/
abdev.PRG
File metadata and controls
8108 lines (6585 loc) · 246 KB
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
* {fr} abDev.prg
* =====================================================
* (c) Abaque SARL, 66 rue Michel Ange - 75016 Paris - France
* contact@FoxInCloud.com - http://foxincloud.com/ - +33 9 53 41 90 90
* {fr} -----------------------------------------------------
* {fr} Ce logiciel est distribué sous GNU General Public License, tel quel, sans aucune garantie
* {fr} Il peut être utilisé et/ou redistribué sans restriction
* {fr} Toute modification doit être reversée à la communauté
* {fr} La présente mention doit être intégralement reproduite dans toute copie même partielle
* {en} -----------------------------------------------------
* {en} This software is distributed under the terms of GNU General Public License, AS IS, without any warranty
* {en} It can be used and/or distributed without restriction
* {en} Any modification or improvement must be given for free to the community
* {en} This permission notice shall be entirely included in all copies or substantial portions of the Software
* =====================================================
#INCLUDE AB.H
AB()
return abUnitTests()
* =================================================
define class cusBatchLog as custom && {fr} Trace un processus répétitif dans un tableau à l'écran
* =================================================
&& {fr} Valeurs initiales
alConsole = .f.
alFooter = .f.
acScreenFont = .null.
anScreenFontSize = .null.
* -------------------------------
&& {fr} Contenu des lignes du tableau de compte rendu
#define L_cHEADER 1 && Texte de l'en-tête de la colonne
#define L_uVALUE 2 && {fr} Ligne courante : contenu original de la cellule
#define L_cTYPE 3 && {fr} Ligne courante : type du contenu original
#define L_cDISPLAY 4 && {fr} Ligne courante : contenu affiché (en caractères bien sûr)
#define L_lBORDER 5 && {fr} La colonne est délimitée par des barres verticales
#define L_nWIDTH 6 && {fr} Largeur utilisable pour affichage dans la colonne (foxels)
#define L_cID 7 && {fr} Identifiant de la colonne
#define L_nSUM 8 && {fr} Cumul de la donnée si elle est numérique
#define L_lSUM 9 && {fr} Sommer / moyenner la donnée en fin d'état si elle est numérique
#define L_cFORMAT 10 && {fr} Format pour Transform()
#define L_COUNT L_cFORMAT
* -------------------------------
dimension aaLog[;
L_COUNT; && {fr} une ligne par caractéristique
, 1] && {fr} une colonne par colonne de log
anCols = 0
acLine = '' && {fr} Contenu de la ligne courante
anLine = 0 && {fr} N° de la ligne courante
anDataLines = 0 && {fr} Nombre de lignes contenant des données
acWarnings = '' && {fr} Avertissements déjà émis
anWarnings = 0 && {fr} Avertissements déjà émis
* {fr} Adresses des fichiers
acTxtLogAddr = ''
acWarnTxtLogAddr = ''
acDBFlogAddr = ''
acDBFlogAlias = ''
alParentPjFiles = .f. && {fr} Parent object has a reference to project files collection
alDocumentView = .f.
alDataSession = .f.
alProjectManager = .f.
* -------------------------------------------------
procedure Init && {fr} Ouvre les fichiers de compte-rendu et vide la fenêtre VFP
lparameters ;
tuTxtLog; && [.T.] {fr} Nom, dossier ou adresse du fichier de compte-rendu texte, .T. : automatique
, tuDBFlog; && [.T.] {fr} Nom, dossier ou adresse du fichier de la table de compte-rendu, .T. : automatique
, tlFooter; && [.T.] {fr} Produire une ligne de totaux / moyennes en fin de CR
, tlConsole; && [.T.] {fr} Afficher le compte rendu à l'écran s'il est visible
local lnParms, luTxtLog, luDBFlog, llResult
lnParms = pcount()
* {en} Determine if Parent object holds a reference to a project files collection
this.alParentPjFiles = type('this.parent.aoPjFiles') == 'O' and not isNull(this.parent.aoPjFiles)
* {en} Init/Open log files
luTxtLog = iif(m.lnParms>=1 and vartype(m.tuTxtLog) $ 'CL', m.tuTxtLog, .t.)
luDBFlog = iif(m.lnParms>=2 and vartype(m.tuDBFlog) $ 'CL', m.tuDBFlog, .t.)
llResult = this.init_Logs(m.luTxtLog, m.luDBFlog)
assert m.llResult message cAssertMsg(textmerge([Échec de la création des fichiers de compte-rendu]))
* {fr} Déterminer si une ligne de totaux / moyennes doit être produite en fin de log
this.alFooter = m.lnParms < 3 or lTrue(m.tlFooter)
* {fr} Déterminer si les sorties doivent être envoyées à l'écran
this.alConsole = (m.lnParms < 4 or lTrue(m.tlConsole));
and inlist(_vfp.startmode, 0, 1, 4);
and vartype(_screen) == 'O' ;
and _screen.visible
if m.this.alConsole
this.acScreenFont = _screen.fontname
this.anScreenFontSize = _screen.fontsize
_screen.fontname = "Courier New"
_screen.fontsize = 10
hide window all
activate screen
clear
endif
return m.llResult
* -------------------------------------------------
procedure init_Logs && {fr} Ouvre les fichiers de compte-rendu
lparameters ;
tuTxtLog; && [.T.] {fr} Nom ou adresse du fichier de compte-rendu texte, .T. pour automatique
, tuDBFlog; && [.T.] {fr} Nom ou adresse du fichier de la table de compte-rendu, .T. pour automatique
local lcLogAddr, lcResult, llResultTXT, llResultDBF
* {fr} Si une adresse de log peut être bâtie
lcLogAddr = this.cLogPathStem(m.tuTxtLog)
llResultTXT = !empty(m.lcLogAddr)
if m.llResultTXT
* {fr} Ouvrir ou créer les fichiers de log
this.acTxtLogAddr = lower(forceext(m.lcLogAddr, EXT_LOG))
this.acWarnTxtLogAddr = lower(forceext(m.lcLogAddr , EXT_LOG_WARN))
this.LogCheck(m.this.acTxtLogAddr)
this.LogCheck(m.this.acWarnTxtLogAddr)
lcResult = 'Starting log on '+ transform(datetime())
lcResult = CRLF2 + m.lcResult + CRLF + replicate('=', len(m.lcResult))
llResultTXT = strtofile(m.lcResult, this.acTxtLogAddr, .t.) > 0
llResultTXT = strtofile(m.lcResult, this.acWarnTxtLogAddr, .t.) > 0 and m.llResultTXT
endif
* {fr} Open/Init table log
lcLogAddr = this.cLogPathStem(m.tuDBFlog)
llResultDBF = !empty(m.lcLogAddr)
if m.llResultDBF
this.acDBFlogAlias = cVFPname(juststem(m.lcLogAddr))
this.acDBFlogAddr = forceext(m.lcLogAddr, 'dbf')
use in select(this.acDBFlogAlias)
this.LogCheck(this.acDBFlogAddr)
llResultDBF = file(this.acDBFlogAddr)
if m.llResultDBF
use (this.acDBFlogAddr) in 0 shared alias (this.acDBFlogAlias)
endif
endif
return m.llResultTXT or m.llResultDBF
* -------------------------------------------------
procedure destroy && {fr} Ferme les fichiers de log et rétablit la fenêtre VFP
* {fr} Faire le pied du tableau
this.FooterCreate()
* {en} Close log table
use in select(this.acDBFlogAlias)
* {en} Show windows hidden AT init()
show window all
show window all && {fr} parfois il reste des fenêtres invisibles
if m.this.alConsole
* {en} Restore screen font
_screen.fontname = this.acScreenFont
_screen.fontsize = this.anScreenFontSize
* {fr} Si l'utilisateur souhaite voir les avertissements
local lcS, lcBe
lcS = Iif(m.this.anWarnings > 1, 's', '')
if not empty(m.this.acWarnings);
and 6 = messagebox(;
Textmerge([<<m.this.anWarnings>> ] + ICase(;
cLangUser() = 'fr', [avertissement<<m.lcS>> <<Iif(m.this.anWarnings > 1, 'ont', 'a')>> été enregistré<<m.lcS>>] + CRLF2 + "Voulez-vous le<<m.lcS>> voir ?",; && copy-paste this line to add another language support
[warning<<m.lcS>> <<Iif(m.this.anWarnings > 1, 'were', 'was')>> recorded] + CRLF2 + "Do you want to see <<Iif(m.this.anWarnings > 1, 'them', 'it')>>?"; && default: English
));
, 4+32;
, icase(;
cLangUser() = 'fr', "Fin de traitement",; && copy-paste this line to add another language support
"End of processing"; && default: English
);
, 5000;
)
* {fr} Copier les avertissements dans un fichier texte temporaire
local lcFile, loSafety
lcFile = forcepath(m.this.acWarnTxtLogAddr, sys(2023))
loSafety = abSet('SAFETY', 'OFF')
strtofile(m.this.acWarnings, m.lcFile)
release loSafety
* {fr} Afficher dans une fenêtre d'édition
modify file (m.lcFile) nowait
activate window (justfname(m.lcFile))
endif
endif
* -------------------------------------------------
procedure LogCheck && {fr} Vérifie qu'un fichier de compte-rendu est accessible en écriture
lparameters tcLogAddr && {fr} Adresse du fichier de compte-rendu
if file(m.tcLogAddr)
* {fr} Ajouter le fichier au projet
if this.alParentPjFiles
ProjectFileAdd(m.tcLogAddr, this.parent.aoPjFiles)
endif
local lnHandle, lcWindow
lnHandle = 0
lcWindow = justfname(m.tcLogAddr)
do while .t.
lnHandle = fopen(m.tcLogAddr, 1) && 1 : write buffered
if m.lnHandle = -1
if wexist(m.lcWindow)
release windows (m.lcWindow)
exit
else
if 2 = messagebox('';
+ "Le fichier de log " + m.tcLogAddr + " est actuellement ouvert." + CRLF;
+ "Veuillez le refermer et cliquer sur Réessayer." + CRLF;
+ "Cliquez sur 'Annuler' pour continuer sans écrire dans le log";
, 5+16)
exit
endif
endif
else
exit
endif
enddo
fclose(m.lnHandle)
endif
* -------------------------------------------------
protected procedure cLogPathStem && {fr} Adresse d'un fichier de compte-rendu sans l'extension
lparameters tuLog; && [.T.] {fr} Nom ou adresse du fichier de compte-rendu, .T. pour automatique
local lcResult, lcSys16;
, lcLogPath, lcLogPathAuto;
, lcLogStem, lcLogStemAuto
lcResult = ''
lcSys16 = sys(16,1)
if !empty(m.lcSys16)
lcLogPathAuto = addbs(cModuleInfo(m.lcSys16, 'Path'))
lcLogStemAuto = cModuleInfo(m.lcSys16, 'Name')
store '' to m.lcLogPath, m.lcLogStem
do case
case ga_Type_IsChar(m.tuLog, .T.)
lcLogPath = addbs(justpath(m.tuLog))
lcLogPath = iif(directory(m.lcLogPath), m.lcLogPath, m.lcLogPathAuto)
lcLogStem = cFileName(juststem(m.tuLog))
lcLogStem = iif(lFileName(m.lcLogStem), m.lcLogStem, m.lcLogStemAuto)
case lTrue(m.tuLog)
lcLogPath = lcLogPathAuto
lcLogStem = lcLogStemAuto
endcase
lcResult = addbs(m.lcLogPath) + m.lcLogStem
endif
return m.lcResult
* -------------------------------------------------
procedure ColAdd && {fr} Ajoute une colonne à la fin de la table de compte-rendu
lparameters ;
tcHeader; && [''] {fr} Contenu de l'en-tête de la colonne
, tnColWidth; && [Header width || 10] {fr} Largeur de la colonne en foxels
, tlNoLeftBar; && [.F.] {fr} Ne pas délimiter les colonnes par une barre verticale
, tcID; && [tcHeader] {fr} Identifiant de la colonne
, tlSum; && [.F.] {fr} Si la donnée est numérique, en fin d'état : .T.: Sommer, .F.: Moyenner, .NULL.: ne rien faire
, tcFormat; && [''] {fr} Format pour Transform()
local lnResult && {fr} Numéro de la colonne ajoutée
lnResult = 0
if m.this.anLine = 0 && {fr} possible only if no line was displayed yet
lnResult = this.aColAdd()
local lcHeader, lnColWidth
lcHeader = uDefault(m.tcHeader, '')
lnColWidth = uDefault(m.tnColWidth, max(10, len(m.lcHeader)))
this.aaLog[L_cHEADER, m.lnResult] = m.lcHeader
this.aaLog[L_uVALUE, m.lnResult] = .null.
this.aaLog[L_cTYPE, m.lnResult] = ''
this.aaLog[L_nWIDTH, m.lnResult] = m.lnColWidth
this.aaLog[L_cDISPLAY, m.lnResult] = space(m.lnColWidth)
this.aaLog[L_lBORDER, m.lnResult] = not uDefault(m.tlNoLeftBar, .f.)
this.aaLog[L_cID, m.lnResult] = uDefault(m.tcID, m.lcHeader)
this.aaLog[L_nSUM, m.lnResult] = 0
this.aaLog[L_lSUM, m.lnResult] = iif(vartype(m.tlSum) $ 'LX', m.tlSum, .f.)
this.aaLog[L_cFORMAT, m.lnResult] = evl(m.tcFormat, '')
* {fr} Si affichage à l'écran (console)
if m.this.alConsole
* {fr} Calculer la largeur totale du tableau en caractères
local lnCol, lnTableWidth
lnTableWidth = 0
for m.lnCol = 1 to m.lnResult
lnTableWidth = m.lnTableWidth + this.aaLog[L_nWIDTH, m.lnCol] + iif(this.aaLog[L_lBORDER, m.lnCol], 1, 0)
endfor
lnTableWidth = m.lnTableWidth + 1 && {fr} right border
* {fr} Tant que le tableau est plus large que l'écran, réduire la police de l'écran
do while m.lnTableWidth * fontmetric(6, _screen.fontname, _screen.fontsize) > _screen.viewportwidth ;
and _screen.fontsize > 5
_screen.fontsize = _screen.fontsize - 1
enddo
endif
endif
this.anCols = m.lnResult
return m.lnResult
* -------------------------------------------------
procedure aColAdd && {fr} Ajoute une colonne au tableau de compte-rendu
local lnResult && {fr} Numéro de la colonne ajoutée
lnResult = alen(this.aaLog, 2)
if not vartype(this.aaLog[1]) = 'L' && {fr} La première colonne n'est plus disponible
local array laCopy[L_COUNT, m.lnResult]
acopy(this.aaLog, m.laCopy)
aColsIns(@m.laCopy)
lnResult = m.lnResult + 1
dimension this.aaLog[L_COUNT, m.lnResult]
acopy(m.laCopy, this.aaLog)
endif
return m.lnResult
* -------------------------------------------------
procedure nCol && {fr} Numéro de colonne d'après son identifiant
lparameters ;
tcColID && {fr} Identifiant de la colonne
local lnResult && {fr} Numéro de la colonne
lnResult = 0
if vartype(m.tcColID) == 'C' and not empty(m.tcColID)
lnResult = ascan(this.aaLog, m.tcColID, 1, -1, -1, 1+2+4)
lnResult = asubscript(this.aaLog, m.lnResult, 2)
endif
return m.lnResult
* -------------------------------------------------
procedure nColWidthTotal && {fr} Largeur totale d'un colonne du compte-rendu (avec gouttières)
lparameters tnCol && {fr} Numéro de colonne
local lnColWidth, lnResult
lnResult = 0
if vartype(m.tnCol) = 'N' ;
and between(m.tnCol, 1, alen(this.aaLog, 2))
lnColWidth = this.aaLog [L_nWIDTH, m.tnCol]
lnResult = iif(vartype(m.lnColWidth) == 'N' and m.lnColWidth > 0;
, 1 + m.lnColWidth; && {fr} gouttière avant
, 0;
)
endif
return m.lnResult
* -------------------------------------------------
procedure CellFill && {fr} Remplit une cellule du compte-rendu
lparameters ;
tuCol; && {fr} Numéro ou ID de la colonne
, tuContent; && [''] {fr} Contenu à placer dans la colonne
, tlExpand; && [.F.] {fr} Si le contenu est plus large que la colonne, déborder sur les colonnes de droite
, tlNoDisplay; && [.F.] {fr} Différer l'affichage de la ligne (pour gagner du temps lorsque plusieurs modifications successives de la ligne)
, tcFormat; && [''] {fr} Format d'affichage
local lnCols, lcType, lnCol, llResult
* {fr} Si la définition de colonne est valide
lnCols = alen(this.aaLog, 2)
lcType = vartype(m.tuCol)
do case
case m.lcType == 'N'
lnCol = m.tuCol
llResult = m.tuCol <= m.lnCols
case m.lcType == 'C'
lnCol = this.nCol(m.tuCol)
llResult = m.lnCol > 0
endcase
assert m.llResult message cAssertMsg(textmerge([Spécification de colonne invalide <<cLitteral(m.tuCol)>>]))
if m.llResult
local luContent, llExpand, llNoDisplay, lcFormat, lcContent, lnColWidth
* {fr} Donner leur valeur par défaut aux paramètres optionnels
luContent = iif(pcount() >= 2, m.tuContent, '')
llExpand = lTrue(m.tlExpand)
llNoDisplay = lTrue(m.tlNoDisplay)
lcFormat = iif(pcount() >= 5 and vartype(m.tcFormat) == 'C', m.tcFormat, '')
lcFormat = evl(m.lcFormat, this.aaLog[L_cFORMAT, m.lnCol])
* {fr} Si la colonne a une largeur positive
lnColWidth = this.aaLog[L_nWIDTH, m.lnCol]
llResult = m.lnColWidth > 0
if m.llResult
* {fr} Charger la données originale dans la cellule
this.aaLog[L_uVALUE, m.lnCol] = m.luContent
this.aaLog[L_cTYPE, m.lnCol] = vartype(m.luContent)
* {fr} Si la donnée est numérique, cumuler
if this.aaLog[L_cTYPE, m.lnCol] == 'N'
this.aaLog[L_nSUM, m.lnCol] = this.aaLog[L_nSUM, m.lnCol] + m.luContent
endif
* {fr} Si la colonne peut déborder
lcContent = transform(m.luContent, m.lcFormat)
if m.llExpand and m.lnCol < m.lnCols
local lnColX, lnColWidthX
lnColWidthX = m.lnColWidth
for m.lnColX = m.lnCol + 1 to alen(this.aaLog, 2)
lnColWidthX = m.lnColWidthX + this.nColWidthTotal(m.lnColX)
endfor
lnColWidth = min(len(m.lcContent), m.lnColWidthX)
endif
* {fr} Charger l'affichage dans la cellule
this.aaLog[L_cDISPLAY, m.lnCol] = ;
this.cCellContent(m.tuContent, m.lnColWidth, m.llExpand, m.lcFormat)
llResult = m.llNoDisplay or this.LineDisplay()
endif
endif
return m.llResult
* -------------------------------------------------
procedure cCellContent && {fr} Contenu d'une cellule du tableau de compte-rendu, ajusté à la taille de la cellule
lparameters ;
tuContent; && {fr} Contenu à placer dans la colonne
, tnColWidth; && {fr} Largeur de la colonne en foxels
, tlExpand; && [.F.] {fr} Si le contenu est plus large que la colonne, déborder sur les colonnes de droite
, tcFormat; && [''] {fr} Format de présentation
tlExpand = lTrue(m.tlExpand)
tcFormat = evl(m.tcFormat, '')
local lcType, lcResult
lcType = vartype(m.tuContent)
if m.lcType $ 'CNYLDT'
lcResult = transform(m.tuContent, m.tcFormat)
* {fr} Manage position in column, trim if necessary
do case
case m.lcType $ 'NY'
lcResult = iif(m.tlExpand;
, this.cColJustified(m.lcResult, m.tnColWidth); && {fr} gauche
, padl(m.lcResult, m.tnColWidth, space(1)); && {fr} Aligner à droite avec un Space(1)
)
case m.lcType = 'L'
lcResult = iif(m.tlExpand;
, this.cColJustified(m.lcResult, m.tnColWidth); && {fr} à gauche
, padl(m.lcResult, m.tnColWidth/2+2, space(1)); && {fr} centrer
)
otherwise
* {fr} Aligner à gauche en tentant de préserver les espaces en tête
lcResult = this.cColJustified(m.lcResult, m.tnColWidth)
endcase
lcResult = padr(m.lcResult, m.tnColWidth, space(1))
else
lcResult = ''
endif
return m.lcResult
* -------------------------------------------------
function cColJustified && {fr} Justifie le contenu d'une cellule dans la largeur de la colonne
lparameters ;
tcContent ; && {fr} Contenu à placer dans la colonne
, tnColWidth && {fr} Largeur de la colonne en foxels
local lcResult
lcResult = m.tcContent
if lenc(m.lcResult) > m.tnColWidth
lcResult = rtrim(m.lcResult)
if lenc(m.lcResult) > m.tnColWidth
lcResult = ltrim(m.lcResult)
if lenc(m.lcResult) > m.tnColWidth
lcResult = leftc(m.lcResult, m.tnColWidth-1) + POINTSUSP
endif
endif
endif
return m.lcResult
* -------------------------------------------------
procedure LineFill && {fr} Écrit une nouvelle ligne à l'écran
lparameters tuContent
local lnResult && {fr} Position de la fin de ligne
lnResult = 0
if this.LineFeed()
this.acLine = transform(m.tuContent)
if m.this.alConsole
activate screen
?? m.this.acLine at 0
endif
lnResult = len(m.this.acLine)
endif
return m.lnResult
* -------------------------------------------------
procedure LineAppend && {fr} Ajoute un contenu à la ligne courante et affiche le résultat
lparameters ;
tuContent ; && {fr} Contenu à placer dans la colonne
, tnPosition && [fin de ligne] {fr} Position où le contenu est ajouté
local lnLine, lnResult && {fr} Position où le contenu a été ajouté
this.acLine = alltrim(this.acLine)
lnLine = len(this.acLine)
lnResult = iif(vartype(m.tnPosition)=='N', m.tnPosition, m.lnLine)
this.acLine = left(this.acLine, m.lnResult) + ;
space(iif(empty(m.this.acLine), 0, 1)) + ;
transform(m.tuContent)
* {fr} Compléter avec des espaces pour superposer la ligne précédente
if m.lnLine > len(this.acLine)
this.acLine = padr(this.acLine, m.lnLine, space(1))
endif
if m.this.alConsole
activate screen
?? m.this.acLine at 0
endif
return m.lnResult
* -------------------------------------------------
procedure LineDisplay && {fr} Affiche le contenu de l'en-tête ou de la ligne courante
lparameters tlHeader && [.F.] {fr} Afficher l'en-tête du tableau
tlHeader = lTrue(m.tlHeader)
local lcLineOut, lnDisplayWidth;
, lnCol, lnColsWidth, lnColWidth;
, lcCellDisplay, llLeftBar, llResult
* {fr} Pour chaque colonne
lcLineOut = ''
store 0 to m.lnDisplayWidth, m.lnColsWidth
for m.lnCol = 1 to alen(this.aaLog, 2)
lcCellDisplay = iif(m.tlHeader;
, this.cCellContent(this.aaLog[L_cHEADER, m.lnCol], this.aaLog[L_nWIDTH, m.lnCol]);
, this.aaLog[L_cDISPLAY, m.lnCol];
)
llLeftBar = this.aaLog[L_lBORDER, m.lnCol]
lnColWidth = 1 + this.aaLog[L_nWIDTH, m.lnCol]
llResult = ;
vartype(m.lcCellDisplay) == 'C' ;
and vartype(m.llLeftBar) == 'L' ;
and vartype(m.lnColWidth) == 'N'
assert m.llResult message cAssertMsg(textmerge([La table de log est mal remplie.]))
if m.llResult
do case
case m.lnDisplayWidth = m.lnColsWidth && {fr} start current column
lcLineOut = m.lcLineOut + iif(m.llLeftBar, '|', space(1)) + m.lcCellDisplay
case m.lnDisplayWidth >= m.lnColsWidth + m.lnColWidth && {fr} Beyond current column
otherwise && {fr} inside current column
lcLineOut = padr(m.lcLineOut, m.lnColsWidth + m.lnColWidth, space(1))
endcase
lnColsWidth = m.lnColsWidth + m.lnColWidth
lnDisplayWidth = len(m.lcLineOut)
else
exit
endif
endfor
if m.llResult
this.acLine = m.lcLineOut + iif(m.llLeftBar, '|', '')
this.lineShow(m.tlHeader)
endif
return m.llResult
* -------------------------------------------------
procedure lineShow && {fr} Affiche la ligne courante à l'écran
lparameters tlHeader && [.F.] {fr} Afficher l'en-tête
if m.this.alConsole
activate screen
*!* ?? '' AT 0 && {fr} bug de TEXT TO m.lcResult TEXTMERGE NOSHOW
?? space(1) at 0 && {fr} bug de TEXT TO m.lcResult TEXTMERGE NOSHOW
if lTrue(m.tlHeader)
?
endif
?? m.this.acLine at 0
endif
* -------------------------------------------------
procedure LineFeed && {fr} Vide la ligne courante pour en commencer une nouvelle
lparameters ;
tlSepLine ; && [.F.] {fr} Tracer une ligne séparatrice après la nouvelle ligne
, tlDataLine && [.F.] {fr} La nouvelle ligne contient des données vivantes
local lcLine, llResult
* {fr} Update line count
if this.anCols > 0
this.anLine = this.anLine + 1
this.anDataLines = this.anDataLines + iif(lTrue(m.tlDataLine), 1, 0)
endif
* {fr} Flush and clear current line
llResult = this.LineFlush()
llResult = this.LineClear() and m.llResult
* {fr} Move to ENDFOR line, with separation line if required
if lTrue(m.tlSepLine)
lcLine = this.cSepLine()
strtofile(CRLF + m.lcLine, this.acTxtLogAddr, .t.)
else
lcLine = space(1)
endif
if m.this.alConsole
activate screen
? m.lcLine
endif
return m.llResult
* -------------------------------------------------
procedure LineFlush && {fr} Sauve la ligne courante dans les fichiers de compte-rendu
local llResult
llResult = .t.
* {fr} Ajouter au log texte
if not empty(this.acTxtLogAddr) and not empty(this.acLine)
llResult = strtofile(CRLF + this.acLine, this.acTxtLogAddr, .t.) > 0
endif
* {fr} Ajouter au log table
if not empty(this.acDBFlogAddr)
llResult = used(this.acDBFlogAlias) or this.DBFlogCreate()
if m.llResult
llResult = this.DBFlogAppend()
endif
endif
return m.llResult
* -------------------------------------------------
procedure LineClear && {fr} Efface la ligne courante
local lnCol, lnWidth
for m.lnCol = 1 to alen(this.aaLog, 2)
lnWidth = this.aaLog[L_nWIDTH, m.lnCol]
lnWidth = iif(vartype(m.lnWidth)=='N', m.lnWidth, 0)
this.aaLog[L_cDISPLAY, m.lnCol] = space(m.lnWidth)
this.aaLog[L_uVALUE, m.lnCol] = .null.
endfor
this.acLine = ''
* -------------------------------------------------
procedure Warning && {fr} Affiche un avertissement dans une fenêtre "WAIT WINDOW", ajoute au compte-rendu des avertissements si nouveau
lparameters ;
tcWarning as String; && {en} warning, empty for a new line {fr} Avertissement, vide pour nouvelle ligne
, lAppendNot as Boolean; && [.F.] {en} do not log warning {fr} Ne pas ajouter l'avertissement au compte-rendu
, lCallingAddNot as Boolean; && [.F.] {en} do not add calling program name as header {fr} ne pas ajouter le nom du programme appelant en-tête
local llResult as Boolean;
, llWarnNew;
, lcWarning;
, lcCallingModule;
* {fr} Si avertissement non vide
if .t.;
and vartype(m.tcWarning) == 'C';
and not empty(m.tcWarning)
tcWarning = alltrim(m.tcWarning)
* {fr} Si nouvel avertissement
lcCallingModule = cTronc(lower(cCallingModule()), 20)
lcWarning = Iif(lTrue(m.lCallingAddNot), '', padr(m.lcCallingModule, 20) ) + m.tcWarning
llWarnNew = not upper(Chrtran(m.lcWarning, '0123456789', '')) $ upper(Chrtran(m.this.acWarnings, '0123456789', '')) && {fr} comparer en ignorant les chiffres
if m.llWarnNew
* {fr} Display warning
wait window cTronc('Module ' + m.lcCallingModule + ' : ' + m.tcWarning, 254) nowait
* ?? Chr(7)
endif
else && {fr} blank line
* {fr} Clear warning
wait clear
llWarnNew = .t.
lcWarning = ''
endif
* {fr} If requested, Append Warning to Log
if m.llWarnNew and not (lTrue(m.lAppendNot))
lcWarning = CRLF + m.lcWarning
this.acWarnings = m.this.acWarnings + m.lcWarning
this.anWarnings = m.this.anWarnings + 1
llResult = strtofile(m.lcWarning, m.this.acWarnTxtLogAddr, .t.) > 0
else
llResult = .t.
endif
return m.llResult
* -------------------------------------------------
function cSepLine && {fr} Ligne séparatrice horizontale
lparameters tlLeftBars && [.F.] {fr} Tracer une barre verticale au début de la nouvelle ligne
local lnCol, lnColWidth, llLeftBar, lcResult
lcResult = ''
for m.lnCol = 1 to alen(this.aaLog, 2)
llLeftBar = m.tlLeftBars and this.aaLog[L_lBORDER, m.lnCol]
lnColWidth = this.nColWidthTotal(m.lnCol)
llResult = vartype(m.lnColWidth) = 'N' and m.lnColWidth > 0
if m.llResult
lcResult = m.lcResult + ;
iif(m.llLeftBar, '|', '-') + ;
replicate('-', m.lnColWidth - 1)
else
exit
endif
endfor
return iif(m.llResult, m.lcResult + iif(m.llLeftBar, '|', '-'), '')
* -------------------------------------------------
procedure DBFlogCreate && {fr} Crée la table de compte-rendu
local lcFields, lnCol;
, lcFieldName, lcFieldType, lnFieldLength, lcFieldExp;
, lnSelect, llResult
if m.this.anCols > 0
lcFields = ''
for m.lnCol = 1 to this.anCols
lcFieldName = cVFPname (this.aaLog[L_cHEADER, m.lnCol], 10)
lcFieldType = uDefault(alltrim(this.aaLog[L_cTYPE, m.lnCol]), 'C')
lcFieldType = evl(m.lcFieldType, 'C')
lnFieldLength = this.aaLog[L_nWIDTH, m.lnCol]
lcFieldExp = cFieldExp(m.lcFieldName, m.lcFieldType, m.lnFieldLength,,.t.)
llResult = not empty(m.lcFieldExp)
if m.llResult
lcFields = c2Words(m.lcFields, ',', m.lcFieldExp)
else
exit
endif
endfor
if m.llResult
lcFields = '(' + m.lcFields + ')'
lnSelect = select(0)
create table (this.acDBFlogAddr) free &lcFields
use
this.LogCheck(this.acDBFlogAddr)
use (this.acDBFlogAddr) alias (this.acDBFlogAlias) exclusive
select (m.lnSelect)
endif
endif
return m.llResult
* -------------------------------------------------
procedure DBFlogAppend && {fr} Sauve la ligne courante du tableau dans la table de compte-rendu
local lnCols, llResult
lnCols = alen(this.aaLog, 2)
llResult = m.lnCols > 0 and used(this.acDBFlogAlias)
if m.llResult
* {fr} Tabuler les champs de la table de log
local array laFields[1]
afields(laFields, this.acDBFlogAlias)
* {fr} Pour chaque colonne
local llAllEmpty, lnCol, lcFieldName, luFieldValue, lcFieldType, lnFieldLength, lcFieldExp, lnField, lcAlter
llAllEmpty = .t.
lcAlter = ''
for lnCol = 1 to m.lnCols
* {fr} Déterminer les caractéristiques du champ pouvant contenir la donnée
lcFieldName = cVFPname(this.aaLog[L_cID, m.lnCol], 10)
luFieldValue = this.aaLog[L_uVALUE, m.lnCol]
lcFieldType = this.aaLog[L_cTYPE, m.lnCol]
lnFieldLength = this.aaLog[L_nWIDTH, m.lnCol]
if vartype(m.lcFieldType) = 'C' ;
and not empty(m.lcFieldType) ;
and vartype(m.lnFieldLength) = 'N' ;
and not empty(m.lnFieldLength)
lcFieldExp = cFieldExp(m.lcFieldName, m.lcFieldType, m.lnFieldLength,,.t.)
lnField = ascan(laFields, m.lcFieldName, 1, -1, 1, 1+2+4+8)
* {fr} Si le champ n'existe pas
if m.lnField = 0
lcAlter = lcAlter + ' ADD COLUMN ' + m.lcFieldExp
* {fr} Sinon (le champ existe)
else
* {fr} Si le champ n'est pas de le bonne taille ou type
if not m.lcFieldType $ VFP7_FIELD_TYPES_FIXED_LEN ;
and laFields[m.lnField, 3] < m.lnFieldLength ;
or not laFields[m.lnField, 2] == m.lcFieldType
lcAlter = lcAlter + ' ALTER COLUMN ' + m.lcFieldExp
endif
endif
llAllEmpty = m.llAllEmpty and (empty(m.luFieldValue) or isNull(m.luFieldValue))
endif
local (m.lcFieldName)
store m.luFieldValue to (m.lcFieldName) && {fr} pour GATHER MEMVAR plus loin
endfor
* {fr} S'il faut changer la structure de la table
if not empty(m.lcAlter)
llResult = used(ExclusiveForce(this.acDBFlogAlias))
if m.llResult
lcAlter = 'ALTER TABLE ' + cLitteral(this.acDBFlogAlias) + m.lcAlter
&lcAlter
use in (this.acDBFlogAlias)
use (this.acDBFlogAddr) in 0 shared alias (this.acDBFlogAlias)
endif
endif
if m.llResult and not m.llAllEmpty
local loSelect
loSelect = createobject('abSelect', this.acDBFlogAlias)
append blank
gather memvar
endif
endif
return m.llResult
* -------------------------------------------------
procedure FooterCreate && {fr} Crée un pied de tableau avec totaux ou moyennes
* {fr} En cas d'interruption anormale, vider la ligne en cours
if not empty(m.this.acLine)
this.LineFeed
endif
* {fr} Si au moins une ligne de données
if m.this.anCols * m.this.anDataLines > 0
* {fr} Tracer une ligne pour fermer le tableau
this.acLine = this.cSepLine()
this.lineShow()
* {fr} Si un pied de tableau a été demandé
if m.this.alFooter
this.LineFeed()
local lnCol, lnSum, luSum, llFooter, llTitle
* {fr} Pour chaque colonne
for m.lnCol = 1 to this.anCols
lnSum = this.aaLog[L_nSUM, m.lnCol]
luSum = this.aaLog[L_lSUM, m.lnCol]
* {fr} Si la colonne contient un total et qu'un bilan est demandé
if m.lnSum > 0 and not isNull(m.luSum) && .NULL.: ne rien faire, ni total ni moyenne
this.CellFill(m.lnCol, m.lnSum / iif(m.luSum, 1, m.this.anDataLines))
llFooter = .t.
else
if not m.llTitle
llTitle = this.CellFill(;
m.lnCol;
, textmerge(icase(;
cLangUser() = 'fr', [Totaux / moyennes des <<m.this.anDataLines>> lignes],; && copy-paste this line to add another language support
[Total / averages of <<m.this.anDataLines>> lines]; && default: English
));
, .t.;
)
endif
endif
endfor
* {fr} Si le pied d'état a été créé, le sortir
if m.llFooter
this.LineFeed(.t.)
endif
endif
endif
* -------------------
enddefine && {fr} CLASS cusBatchLog as Custom
* -----------------------------------------------------
procedure cusBatchLog_Test
local lcSys16
lcSys16 = sys(16,1)
? m.lcSys16
local loBatchLog, lnPos
loBatchLog = createobject('cusBatchLog', addbs(sys(2023)) + 'test')
with m.loBatchLog
.LineFill('Ceci va commencer le test ...')
lnPos = .LineAppend('Première étape')
wait 'Test de cusBatchLog en cours ...' window timeout 3
.LineAppend('OK', m.lnPos)
.ColAdd('First column', 18)
.ColAdd('Second column', 25)
.ColAdd('Third column', 15, .t.)
.ColAdd('Fourth column', 15)
.LineFeed(.t.)
.LineDisplay(.t.)
.LineFeed(.t.)
.CellFill(1, datetime())
.CellFill(2, 'Thierry Nivelet')
.CellFill(3, 524.25)
.CellFill(4, .f.)
.LineFeed(.t.)
.CellFill(1, datetime())
.CellFill(2, 'Thierry Nivelet is a poor developper', .t.)
.CellFill(3, 524.25)
.CellFill(4, .f.)
.LineFeed(.t.)
.Warning('Warning test OK')
endwith
* ========================================
function cModuleInfo && {fr} Nom, Chemin ou Adresse d'un module d'après Sys(16)
lparameters ;
tcSys16; && {fr} Chaîne obtenue par Sys(16)
, tcInfo; && ['N'] {N}ame, {A}ddress, {P}ath, {O}bject, {S}ys16, {L}ignée, {F}ull lignée
, tlCase && [.F.] {fr} Respecter la casse sur disque
tcInfo = iif(vartype(m.tcInfo) = 'C' and not empty(m.tcInfo), upper(left(ltrim(m.tcInfo), 1)), 'N')
tcInfo = iif(m.tcInfo $ 'NAPSOLF', m.tcInfo, 'N')
tlCase = lTrue(m.tlCase)
local llProc, lcAddr, lcProc, laMembers[1], lnMembers, llMethod;
, llResult, lcResult
lcResult = ''
* {fr} Si le paramètre requis est valide
llResult = vartype(m.tcSys16) = 'C'
assert m.llResult message cAssertMsg(textmerge([Invalid Sys(16) Information : <<cLitteral(m.tcSys16)>>]))
if m.llResult and not upper(left(m.tcSys16, 2)) == 'ON' && {fr} ON ...
* {fr} Repérer le nom de la procédure et l'adresse du fichier dans la chaine sys(16)
llProc = left(upper(m.tcSys16), lenc('PROCEDURE ')) == 'PROCEDURE '
lcAddr = iif(m.llProc;