-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentesDPR.pas
1552 lines (1376 loc) · 51.3 KB
/
ComponentesDPR.pas
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
unit ComponentesDPR;
interface
uses Classes, DB, Forms, ExtCtrls, Mask, Controls, SysUtils, Windows, StdCtrls,
MaskUtils, DBGrids, Graphics, ShellApi, ComCtrls, Menus, Messages, DBClient,
Math, Types, UITypes, JvGradient, JvPanel;
type
TTipoCaracter = (tcNormal, tcMaiusculo, tcMinusculo);
PonteiroMeuRegistro = ^TMeuRegistro;
TMeuRegistro = record
FMenu: TMenuItem;
FTabSheet: TTabSheet;
end;
TPesquisa = class(TComponent)
private
FAutor, FTitulo, FCampo: String;
FEsquerda, FTopo: Integer;
FMascara: TEditMask;
FDataSet: TDataSet;
FTipoCaracter: TTipoCaracter;
FPosicao: TPosition;
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure MaskEditChange(Sender: TObject);
procedure SetAutor(const C: String);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Pesquisar: Boolean;
published
property Autor: String read FAutor write SetAutor;
property Campo: String read FCampo write FCampo;
property DataSet: TDataSet read FDataSet write FDataSet;
property Esquerda: Integer read FEsquerda write FEsquerda;
property Mascara: TEditMask read FMascara write FMascara;
property Posicao: TPosition read FPosicao write FPosicao;
property TipoCaracter: TTipoCaracter read FTipoCaracter write FTipoCaracter;
property Titulo: String read FTitulo write FTitulo;
property Topo: Integer read FTopo write FTopo;
end;
TGridParaHTML = class(TComponent)
private
FAutor, FTitulo, FArquivo, FRodape: String;
FDBGrid: TDBGrid;
FVisualizar, FCorpoFontePadrao, FCabecalhoFontePadrao: Boolean;
procedure SetAutor(const C: String);
procedure SetArquivo(const C: String);
function DBGridToHtmlTable(mDBGrid: TDBGrid; mStrings: TStrings; mCaption: TCaption = ''; mRodape: TCaption = ''): Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Executar: Boolean;
published
property Autor: String read FAutor write SetAutor;
property Arquivo: String read FArquivo write SetArquivo;
property DBGrid: TDBGrid read FDBGrid write FDBGrid;
property Rodape: String read FRodape write FRodape;
property Titulo: String read FTitulo write FTitulo;
property Visualizar: Boolean read FVisualizar write FVisualizar;
property CorpoFontePadrao: Boolean read FCorpoFontePadrao write FCorpoFontePadrao;
property CabecalhoFontePadrao: Boolean read FCabecalhoFontePadrao write FCabecalhoFontePadrao;
end;
TDataSetParaCSV = class(TComponent)
private
FAutor, FArquivoBase, FSeparador, FDelimitador, FExtensao: String;
FDataSet: TDataSet;
FDoInicio: Boolean;
FMaximoRegistrosPorArquivo: Integer;
procedure SetAutor(const C: String);
procedure SetArquivoBase(const C: String);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Executar: Boolean;
published
property Autor: String read FAutor write SetAutor;
property ArquivoBase: String read FArquivoBase write SetArquivoBase;
property DataSet: TDataSet read FDataSet write FDataSet;
property Delimitador: String read FDelimitador write FDelimitador;
property DoInicio: Boolean read FDoInicio write FDoInicio;
property Extensao: String read FExtensao write FExtensao;
property Separador: String read FSeparador write FSeparador;
property MaximoRegistrosPorArquivo: Integer read FMaximoRegistrosPorArquivo write FMaximoRegistrosPorArquivo;
end;
TTreeViewDPR = class(TTreeView)
private
FAutor: String;
FMenuPrincipal: TMainMenu;
FPageControl: TPageControl;
FExpandir1, FRecolherAntesPosicionar, FUsarImagensDoMenu, FOrdenar,
FPosicionarPageControlChange: Boolean;
FIndexImagemPasta, FIndexImagemArquivo, FIndexImagemPastaSelec, FIndexImagemArquivoSelec: Integer;
FEventoAoPosicionar: TNotifyEvent;
procedure SetAutor(const C: String);
procedure SetMenuPrincipal(M: TMainMenu);
procedure SetPageControl(P: TPageControl);
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
procedure LimparPonteirosUsados;
protected
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure Change(Node: TTreeNode); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Preenche;
function Posicionar(Sender: TObject; ExecutarChange: Boolean = True): Boolean;
procedure MoverTreeNodePeloTabSheet(TabSheetAMover, NovaTabSheePai: TTabSheet);
function MenuItemPeloNo: TMenuItem;
procedure LimparItems;
published
property Autor: String read FAutor write SetAutor;
property ExpandirPrimeiroNivel: Boolean read FExpandir1 write FExpandir1 default True;
property MenuPrincipal: TMainMenu read FMenuPrincipal write SetMenuPrincipal;
property PageControl: TPageControl read FPageControl write SetPageControl;
property RecolherAntesPosicionar: Boolean read FRecolherAntesPosicionar write FRecolherAntesPosicionar default False;
property IndexImagemPasta: Integer read FIndexImagemPasta write FIndexImagemPasta default 0;
property IndexImagemArquivo: Integer read FIndexImagemArquivo write FIndexImagemArquivo default 1;
property IndexImagemPastaSelec: Integer read FIndexImagemPastaSelec write FIndexImagemPastaSelec default 2;
property IndexImagemArquivoSelec: Integer read FIndexImagemArquivoSelec write FIndexImagemArquivoSelec default 3;
property Ordenar: Boolean read FOrdenar write FOrdenar default False;
property UsarImagensDoMenu: Boolean read FUsarImagensDoMenu write FUsarImagensDoMenu default False;
property AoPosicionar: TNotifyEvent read FEventoAoPosicionar write FEventoAoPosicionar;
end;
TIndicadorDPR = class(TCustomPanel)
private
JvGradientEsquerdo: TJvGradient;
JvGradientCentro: TJvGradient;
JvGradientDireito: TJvGradient;
ShapeMarcador: TShape;
JvPanelTransparente: TJvPanel;
JvPanelTransparente2: TJvPanel;
PanelDescricao: TPanel;
FAutor: string;
FDescricao: string;
FValorMaximo: Currency;
FValorAtual: Currency;
FValorMinimo: Currency;
FCorEsquerda: TColor;
FCorMeio: TColor;
FCorDireita: TColor;
FValorLimiteSuperiorMeio: Currency;
FValorLimiteInferiorMeio: Currency;
FExibirValorAtual: Boolean;
FGradient: Boolean;
procedure AjustarCores;
procedure AjustarMeio;
procedure AjustarPosicionamento;
procedure AtualizarHeightPanelTransparente;
procedure AtualizarHeightPanelTransparente2;
procedure AtualizarExibicaoValorAtual;
procedure RefreshCorrecao;
procedure SetAutor(const Value: string);
procedure SetDescricao(const Value: string);
procedure SetValorAtual(const Value: Currency);
procedure SetValorMaximo(const Value: Currency);
procedure SetValorMinimo(const Value: Currency);
procedure SetValorLimiteInferiorMeio(const Value: Currency);
procedure SetValorLimiteSuperiorMeio(const Value: Currency);
procedure SetAlturaPainelDescricao(const Value: Integer);
procedure SetFontPainelDescricao(const Value: TFont);
procedure SetFontPainelValorAtual(const Value: TFont);
procedure SetCorDireita(const Value: TColor);
procedure SetCorMeio(const Value: TColor);
procedure SetCorEsquerda(const Value: TColor);
procedure SetExibirValorAtual(const Value: Boolean);
procedure SetGradient(const Value: Boolean);
procedure SetLarguraMarcador(const Value: Integer);
procedure SetEspessuraLinhaMarcador(const Value: Integer);
function GetAlturaPainelDescricao: Integer;
function GetFontPainelDescricao: TFont;
function GetFontPainelValorAtual: TFont;
function GetLarguraMarcador: Integer;
function GetEspessuraLinhaMarcador: Integer;
protected
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Imagem(out BMP: TBitMap);
published
property Autor: string read FAutor write SetAutor;
property Descricao: string read FDescricao write SetDescricao;
property ValorMinimo: Currency read FValorMinimo write SetValorMinimo;
property ValorMaximo: Currency read FValorMaximo write SetValorMaximo;
property ValorAtual: Currency read FValorAtual write SetValorAtual;
property ValorLimiteInferiorMeio: Currency read FValorLimiteInferiorMeio write SetValorLimiteInferiorMeio;
property ValorLimiteSuperiorMeio: Currency read FValorLimiteSuperiorMeio write SetValorLimiteSuperiorMeio;
property CorDireita: TColor read FCorDireita write SetCorDireita default clLime;
property CorMeio: TColor read FCorMeio write SetCorMeio default clYellow;
property CorEsquerda: TColor read FCorEsquerda write SetCorEsquerda default clRed;
property FontPainelDescricao: TFont read GetFontPainelDescricao write SetFontPainelDescricao;
property FontPainelValorAtual: TFont read GetFontPainelValorAtual write SetFontPainelValorAtual;
property AlturaPainelDescricao: Integer read GetAlturaPainelDescricao write SetAlturaPainelDescricao;
property LarguraMarcador: Integer read GetLarguraMarcador write SetLarguraMarcador;
property EspessuraLinhaMarcador: Integer read GetEspessuraLinhaMarcador write SetEspessuraLinhaMarcador;
property ExibirValorAtual: Boolean read FExibirValorAtual write SetExibirValorAtual;
property Gradient: Boolean read FGradient write SetGradient;
// publicando algumas propriedades de TPanel
property Align;
property Anchors;
{ // Essas propriedades não foram liberadas, pois davam problema ao desenhar os componentes,
// Se quiser mais detalhes no indicador, coloque um panel por baixo dele e ajuste essas propriedades do panel
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BorderStyle;
property BorderWidth;
}
property Color;
property Constraints;
property PopupMenu;
property ShowHint;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
end;
procedure Register;
function ColorToHtml(mColor: TColor): string;
function StrToHtml(mStr: string; mFont: TFont = nil): string;
function RetiraEComercial(S: String): String;
function iif(Condicao: Boolean; ResultadoVerdadeiro, ResultadoFalso: Variant): Variant;
const
C_Autor = 'Denis Pereira Raymundo';
var
Contato: String;
implementation
{$region 'Funções Genéricas'}
procedure Register;
begin
RegisterComponents('DenisPR',[TPesquisa, TGridParaHTML, TTreeViewDPR, TDataSetParaCSV, TIndicadorDPR]);
end;
function iif(Condicao: Boolean; ResultadoVerdadeiro, ResultadoFalso: Variant): Variant;
begin
if Condicao then
Result := ResultadoVerdadeiro
else
Result := ResultadoFalso;
end;
function RetiraEComercial(S: String): String;
begin
Result := StringReplace(S, '&', '', [rfReplaceAll]);
end;
function ColorToHtml(mColor: TColor): string;
begin
mColor := ColorToRGB(mColor);
Result := Format('#%.2x%.2x%.2x', [GetRValue(mColor), GetGValue(mColor), GetBValue(mColor)]);
end;
function StrToHtml(mStr: string; mFont: TFont = nil): string;
var vLeft, vRight: string;
begin
Result := mStr;
Result := StringReplace(Result, '&', '&', [rfReplaceAll]);
Result := StringReplace(Result, '<', '<', [rfReplaceAll]);
Result := StringReplace(Result, '>', '>', [rfReplaceAll]);
Result := StringReplace(Result, ' ', ' ', [rfReplaceAll]);
if Trim(Result) = '' then Result := ' ';
if not Assigned(mFont) then Exit;
vLeft := Format('<FONT SIZE=1 FACE="%s" COLOR="%s">', [mFont.Name, ColorToHtml(mFont.Color)]);
vRight := '</FONT>';
if fsBold in mFont.Style then
begin
vLeft := vLeft + '<B>';
vRight := '</B>' + vRight;
end;
if fsItalic in mFont.Style then
begin
vLeft := vLeft + '<I>';
vRight := '</I>' + vRight;
end;
if fsUnderline in mFont.Style then
begin
vLeft := vLeft + '<U>';
vRight := '</U>' + vRight;
end;
if fsStrikeOut in mFont.Style then
begin
vLeft := vLeft + '<S>';
vRight := '</S>' + vRight;
end;
Result := vLeft + Result + vRight;
end;
{$endregion}
{$region 'Implementação do Componente TPesquisa'}
constructor TPesquisa.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutor := C_Autor;
FPosicao := poScreenCenter;
end;
destructor TPesquisa.Destroy;
begin
inherited Destroy;
end;
procedure TPesquisa.SetAutor(const C: String);
begin
if C <> FAutor then
Application.MessageBox(PChar(Contato), 'Contato', mb_Ok);
end;
function TPesquisa.Pesquisar: Boolean;
var
F: TForm;
P: TPanel;
M: TMaskEdit;
FocoAnterior: TWinControl;
ASTemp, BSTemp: TDataSetNotifyEvent;
RegistroAtual: Integer;
begin
Result := False;
if (FDataSet = nil) or (not FDataSet.Active) then Exit;
Application.CreateForm(TForm, F);
// Desativando eventos de rolagem
with FDataSet do
begin
ASTemp := AfterScroll;
BSTemp := BeforeScroll;
AfterScroll := nil;
BeforeScroll := nil;
RegistroAtual := RecNo;
end;
with F do
try
if fTitulo = '' then
Caption := 'Pesquisa'
else
Caption := 'Pesquisar por ' + FTitulo;
BorderStyle := bsSingle;
Position := FPosicao;
BorderIcons := [biSystemMenu];
Height := 81;
Left := FEsquerda;
KeyPreview := True;
Top := FTopo;
Width := 364;
OnKeyDown := FormKeyDown;
OnShow := FormShow;
P := TPanel.Create(F);
with P do
begin
Align := alClient;
Caption := '';
BevelInner := bvLowered;
BevelOuter := bvLowered;
Parent := F;
end;
M := TMaskEdit.Create(F);
with M do
begin
Name := 'MaskEditPesquisaIncremental';
CharCase := TEditCharCase(FTipoCaracter);
EditMask := FMascara;
Parent := P;
Top := 18;
Left := 57;
Width := 250;
MaxLength := 50;
Clear;
OnChange := MaskEditChange;
end;
FocoAnterior := Screen.ActiveForm.ActiveControl;
Result := (ShowModal = mrOk);
Screen.ActiveForm.ActiveControl := FocoAnterior;
finally
Free;
// retornando eventos e executando apenas uma vez caso necessário
with FDataSet do
begin
AfterScroll := ASTemp;
BeforeScroll := BSTemp;
if (RegistroAtual <> RecNo) then
begin
if Assigned(BeforeScroll) then
BeforeScroll(FDataSet);
if Assigned(AfterScroll) then
AfterScroll(FDataSet);
end;
end;
end;
end;
procedure TPesquisa.MaskEditChange(Sender: TObject);
var
S: String;
Conteudo: Variant;
ComLocate, Descendente: Boolean;
begin
S := TrimRight(TMaskEdit(Sender).Text);
with FDataSet do
if (S <> '') and
(( (FieldByName(FCampo).DataType in [ftDate, ftTimeStamp]) and (Length(S) = 10) and (S <> '/ /') ) or
( (FieldByName(FCampo).DataType in [ftDateTime, ftTimeStamp]) and (Length(Trim(Copy(S, 1, 10))) = 10) ) or
( (FieldByName(FCampo).DataType in [ftTime, ftTimeStamp]) and (Length(S) = 8) and (S <> ': :') ) or
(not (FieldByName(FCampo).DataType in [ftDate, ftTime, ftTimeStamp]))) then
try
DisableControls;
ComLocate := True;
Conteudo := TMaskEdit(Sender).Text;
try
case FieldByName(FCampo).DataType of
ftInteger: StrToInt(TMaskEdit(Sender).Text);
ftFMTBCD:
begin
if (FieldByName(FCampo).Size = 0) then
StrToInt64(TMaskEdit(Sender).Text)
else
Conteudo := StrToFloat(TMaskEdit(Sender).Text);
end;
ftDate, ftDateTime, ftTime, ftTimeStamp:
begin
if (Pos('99/99/9999 99:99:99', FieldByName(FCampo).EditMask) = 1) and (Length(Trim(Copy(S, 1, 10))) = 10) then
Conteudo := StrToDateTime(Trim(Copy(S, 1, 10)))
else
Conteudo := StrToDateTime(TMaskEdit(Sender).Text);
end;
end;
except
on E: EConvertError do
begin
Application.MessageBox('Conteúdo a pesquisar é inválido para o tipo de campo', 'Informação', mb_Ok);
//TMaskEdit(Sender).Clear;
//TMaskEdit(Sender).SelectAll;
Abort;
end;
end;
if (FDataSet is TClientDataSet) and
(TClientDataSet(FDataSet).IndexName = FCampo) then
begin
try
// Se o Indice não existir vai dar erro
TClientDataSet(FDataSet).IndexDefs.Update;
Descendente := (ixDescending in TClientDataSet(FDataSet).IndexDefs.Find(FCampo).Options);
if (not Descendente) then
begin
TClientDataSet(FDataSet).FindNearest([Conteudo]);
ComLocate := False;
end;
except
end;
end;
if ComLocate then
try
Locate(FCampo, Conteudo, [loPartialKey, loCaseInsensitive]);
except
on E: Exception do
begin
if (Pos('field', LowerCase(E.Message)) = 1) and
(Pos('cannot be used in a filter expression', LowerCase(E.Message)) > 0) then
Application.MessageBox('Não é possível pesquisar por este campo neste local. Ele deve ser originário de outra tabela.', 'Informação', mb_Ok)
else
raise;
end;
end;
finally
EnableControls;
end;
end;
procedure TPesquisa.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and (Key = vk_Return) then TForm(Sender).ModalResult := mrOk;
if (Shift = []) and (Key = vk_Escape) then TForm(Sender).ModalResult := mrCancel;
end;
procedure TPesquisa.FormShow(Sender: TObject);
begin
// Gambiarra para apresentar o cursor piscando, mas muda o componente ativo
// Screen.ActiveForm.Perform(WM_NEXTDLGCTL, 0, 0);
end;
{$endregion}
{$region 'Implementação do Componente TGridParaHTML'}
constructor TGridParaHTML.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutor := C_Autor;
FCorpoFontePadrao := False;
FCabecalhoFontePadrao := False;
end;
destructor TGridParaHTML.Destroy;
begin
inherited Destroy;
end;
procedure TGridParaHTML.SetAutor(const C: String);
begin
if C <> FAutor then
Application.MessageBox(PChar(Contato), 'Contato', mb_Ok);
end;
procedure TGridParaHTML.SetArquivo(const C: String);
begin
FArquivo := ChangeFileExt(C, '.HTM');
end;
function TGridParaHTML.Executar: Boolean;
var S: TStrings; C: TCursor;
begin
C := Screen.Cursor;
Screen.Cursor := crHourGlass;
S := TStringList.Create;
try
DBGridToHtmlTable(FDBGrid, S, FTitulo, FRodape);
S.SaveToFile(FArquivo);
if FVisualizar then
ShellExecute(0, nil, PChar(FArquivo), nil, nil, SW_SHOW)
else
Application.MessageBox(PChar(AnsiUpperCase(FArquivo) + ' gerado com sucesso'), 'Término de Processo', mb_Ok);
Result := True;
finally
S.Free;
Screen.Cursor := C;
end;
end;
function TGridParaHTML.DBGridToHtmlTable(mDBGrid: TDBGrid; mStrings: TStrings; mCaption: TCaption = ''; mRodape: TCaption = ''): Boolean;
const
cAlignText: array[TAlignment] of string = ('LEFT', 'RIGHT', 'CENTER');
var
vColFormat, vColText: string;
vAllWidth, I, J, Reg: Integer;
vWidths: array of Integer;
GridAtiva: Boolean;
SLTemp: TStrings;
vBookmark: TBookmark;
begin
Result := False;
if not Assigned(mStrings) then Exit;
if not Assigned(mDBGrid) then Exit;
if not Assigned(mDBGrid.DataSource) then Exit;
if not Assigned(mDBGrid.DataSource.DataSet) then Exit;
if not mDBGrid.DataSource.DataSet.Active then Exit;
vBookmark := mDBGrid.DataSource.DataSet.Bookmark;
mDBGrid.DataSource.DataSet.DisableControls;
GridAtiva := mDBGrid.Enabled;
mDBGrid.Enabled := False;
SLTemp := TStringList.Create;
try
J := 0;
vAllWidth := 0;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then
begin
Inc(J);
SetLength(vWidths, J);
vWidths[J - 1] := mDBGrid.Columns[I].Width;
Inc(vAllWidth, mDBGrid.Columns[I].Width);
end;
if J <= 0 then Exit;
mStrings.Clear;
mStrings.Add(Format('<HTML><HEADER><TITLE>%s</TITLE>', [StrToHtml(mCaption)]));
mStrings.Add('<style type="text/css"><!--');
mStrings.Add(' .t{border-top: 1px solid #000000; border-right: 1px solid #000000;');
mStrings.Add(' border-bottom: 1px solid #000000; border-left: 1px solid #000000;}');
mStrings.Add(' .d{border-top: 1px none; border-right: 1px solid #C0C0C0;');
mStrings.Add(' border-bottom: 1px solid #C0C0C0; border-left: 1px none;');
mStrings.Add(' font-family: "MS Sans Serif", Times, serif; font-size: 8px; color: #000000; background-color: #FFFFFF;}');
mStrings.Add(' .c{border-top: 1px none; border-right: 1px solid #000000;');
mStrings.Add(' border-bottom: 1px solid #000000; border-left: 1px none;');
mStrings.Add(' font-family: Tahoma, Times, serif; font-size: 11px; color: #000000; background-color: #9CC99C; font-weight: bold; text-align: center;}');
mStrings.Add('--> </style></HEADER><BODY>');
mStrings.Add(Format('<TABLE CLASS="t" BGCOLOR="%s" WIDTH="100%%" CELLSPACING=0 BORDERCOLOR="#C0C0C0">', [ColorToHtml(mDBGrid.Color)]));
if mCaption <> '' then
mStrings.Add(Format('<CAPTION><FONT FACE="Tahoma" COLOR="%S"><B>%s</FONT></B></CAPTION>', [ColorToHtml(clBlack), StrToHtml(mCaption)]));
vColFormat := '<TR>'#13#10;
vColText := '<TR>'#13#10;
J := 0;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then
begin
if FCorpoFontePadrao then
vColFormat := vColFormat + Format(
' <TD CLASS="d" ALIGN=%s>DisplayText%d</TD>'#13#10,
[cAlignText[mDBGrid.Columns[I].Alignment], J])
else
vColFormat := vColFormat + Format(
' <TD CLASS="d" BGCOLOR="%s" ALIGN=%s WIDTH="%d%%">DisplayText%d</TD>'#13#10,
[ColorToHtml(mDBGrid.Columns[I].Color),
cAlignText[mDBGrid.Columns[I].Alignment],
Round(vWidths[J] / vAllWidth * 100), J]);
if FCabecalhoFontePadrao then
vColText := vColText + Format(
' <TD CLASS="c" WIDTH="%d%%">%s</TD>'#13#10,
[Round(vWidths[J] / vAllWidth * 100),
StrToHtml(mDBGrid.Columns[I].Title.Caption)])
else
vColText := vColText + Format(
' <TD CLASS="c" BGCOLOR="%s" ALIGN=%s WIDTH="%d%%">%s</TD>'#13#10,
[ColorToHtml(mDBGrid.Columns[I].Title.Color),
cAlignText[mDBGrid.Columns[I].Title.Alignment],
Round(vWidths[J] / vAllWidth * 100),
StrToHtml(mDBGrid.Columns[I].Title.Caption,
mDBGrid.Columns[I].Title.Font)]);
Inc(J);
end;
vColFormat := vColFormat + '</TR>'#13#10;
vColText := vColText + '</TR>'#13#10;
mStrings.Text := mStrings.Text + vColText;
mDBGrid.DataSource.DataSet.First;
Reg := 0;
while not mDBGrid.DataSource.DataSet.Eof do
begin
Inc(Reg);
if (Reg mod 1000) = 0 then
begin
Reg := 0;
// mDBGrid.DataSource.DataSet.EnableControls;
// mDBGrid.DataSource.DataSet.DisableControls;
Application.ProcessMessages;
end;
J := 0;
vColText := vColFormat;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then
begin
if FCorpoFontePadrao then
vColText := StringReplace(vColText, Format('>DisplayText%d<', [J]),
Format('>%s<', [StrToHtml(mDBGrid.Columns[I].Field.DisplayText)]), [rfReplaceAll])
else
vColText := StringReplace(vColText, Format('>DisplayText%d<', [J]),
Format('>%s<', [StrToHtml(mDBGrid.Columns[I].Field.DisplayText, mDBGrid.Columns[I].Font)]), [rfReplaceAll]);
Inc(J);
end;
// mStrings.Text := mStrings.Text + vColText;
mStrings.Add(vColText);
mDBGrid.DataSource.DataSet.Next;
end;
mStrings.Add('</TABLE>');
mStrings.Add(Format('<CENTER><FONT FACE="Arial" SIZE=0 COLOR="%s"><B><I>%s</B></I></FONT>', [ColorToHtml(clNavy), mRodape]));
mStrings.Add('</BODY></HTML>');
finally
mDBGrid.DataSource.DataSet.Bookmark := vBookmark;
mDBGrid.DataSource.DataSet.EnableControls;
mDBGrid.Enabled := GridAtiva;
vWidths := nil;
SLTemp.Free;
end;
Result := True;
end;
{$endregion}
{$region 'Implementação do Componente TTreeViewDPR'}
constructor TTreeViewDPR.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutor := C_Autor;
FOrdenar := False;
FExpandir1 := True;
FIndexImagemPasta := 0;
FIndexImagemArquivo := 1;
FIndexImagemPastaSelec := 2;
FIndexImagemArquivoSelec := 3;
FRecolherAntesPosicionar := False;
FPosicionarPageControlChange := True;
FMenuPrincipal := nil;
FPageControl := nil;
ReadOnly := True;
HotTrack := True;
Align := alLeft;
end;
destructor TTreeViewDPR.Destroy;
begin
LimparPonteirosUsados;
inherited Destroy;
end;
procedure TTreeViewDPR.SetAutor(const C: String);
begin
if C <> FAutor then
Application.MessageBox(PChar(Contato), 'Contato', mb_Ok);
end;
procedure TTreeViewDPR.SetPageControl(P: TPageControl);
begin
FPageControl := P;
FMenuPrincipal := nil;
Self.Items.Clear;
end;
procedure TTreeViewDPR.SetMenuPrincipal(M: TMainMenu);
begin
FMenuPrincipal := M;
FPageControl := nil;
Self.Items.Clear;
end;
procedure TTreeViewDPR.Preenche;
var
x1, x2, x3, x4: integer;
T1, T2, T3, T4: TTreeNode;
MeuRegistro: PonteiroMeuRegistro;
begin
LimparPonteirosUsados;
if Assigned(FMenuPrincipal) then
with FMenuPrincipal do
begin
Self.Invalidate;
Self.Items.Clear;
// Primeiro nivel
for x1 := 0 to Items.Count - 1 do
if (Items[x1].Visible) and
(Items[x1].Enabled) and
(Items[x1].Caption <> '-') then
begin
New(MeuRegistro);
MeuRegistro^.FMenu := Items[x1];
T1 := Self.Items.AddObject(nil, RetiraEComercial(MeuRegistro^.FMenu.Caption), MeuRegistro);
if FUsarImagensDoMenu then
begin
T1.ImageIndex := MeuRegistro^.FMenu.ImageIndex;
T1.SelectedIndex := MeuRegistro^.FMenu.ImageIndex;
end
else
begin
if Items[x1].Count = 0 then
begin
T1.ImageIndex := FIndexImagemArquivo;
T1.SelectedIndex := FIndexImagemArquivoSelec;
end
else
begin
T1.ImageIndex := FIndexImagemPasta;
T1.SelectedIndex := FIndexImagemPastaSelec;
end;
end;
// Segundo nivel
for x2 := 0 to Items[x1].Count - 1 do
if (Items[x1].Items[x2].Visible) and
(Items[x1].Items[x2].Enabled) and
(Items[x1].Items[x2].Caption <> '-') then
begin
New(MeuRegistro);
MeuRegistro^.FMenu := Items[x1].Items[x2];
T2 := Self.Items.AddChildObject(T1, RetiraEComercial(MeuRegistro^.FMenu.Caption), MeuRegistro);
if FUsarImagensDoMenu then
begin
T2.ImageIndex := MeuRegistro^.FMenu.ImageIndex;
T2.SelectedIndex := MeuRegistro^.FMenu.ImageIndex;
end
else
begin
if Items[x1].Items[x2].Count = 0 then
begin
T2.ImageIndex := FIndexImagemArquivo;
T2.SelectedIndex := FIndexImagemArquivoSelec;
end
else
begin
T2.ImageIndex := FIndexImagemPasta;
T2.SelectedIndex := FIndexImagemPastaSelec;
end;
end;
// Terceiro nível
for x3 := 0 to Items[x1].Items[x2].Count - 1 do
if (Items[x1].Items[x2].Items[x3].Visible) and
(Items[x1].Items[x2].Items[x3].Enabled) and
(Items[x1].Items[x2].Items[x3].Caption <> '-') then
begin
New(MeuRegistro);
MeuRegistro^.FMenu := Items[x1].Items[x2].Items[x3];
T3 := Self.Items.AddChildObject(T2, RetiraEComercial(MeuRegistro^.FMenu.Caption), MeuRegistro);
if FUsarImagensDoMenu then
begin
T3.ImageIndex := MeuRegistro^.FMenu.ImageIndex;
T3.SelectedIndex := MeuRegistro^.FMenu.ImageIndex;
end
else
begin
if Items[x1].Items[x2].Items[x3].Count = 0 then
begin
T3.ImageIndex := FIndexImagemArquivo;
T3.SelectedIndex := FIndexImagemArquivoSelec;
end
else
begin
T3.ImageIndex := FIndexImagemPasta;
T3.SelectedIndex := FIndexImagemPastaSelec;
end;
end;
// Quarto nível
for x4 := 0 to Items[x1].Items[x2].Items[x3].Count - 1 do
if (Items[x1].Items[x2].Items[x3].Items[x4].Visible) and
(Items[x1].Items[x2].Items[x3].Items[x4].Enabled) and
(Items[x1].Items[x2].Items[x3].Items[x4].Caption <> '-') then
begin
New(MeuRegistro);
MeuRegistro^.FMenu := Items[x1].Items[x2].Items[x3].Items[x4];
T4 := Self.Items.AddChildObject(T3, RetiraEComercial(MeuRegistro^.FMenu.Caption), MeuRegistro);
if FUsarImagensDoMenu then
begin
T4.ImageIndex := MeuRegistro^.FMenu.ImageIndex;
T4.SelectedIndex := MeuRegistro^.FMenu.ImageIndex;
end
else
begin
if Items[x1].Items[x2].Items[x3].Items[x4].Count = 0 then
begin
T4.ImageIndex := FIndexImagemArquivo;
T4.SelectedIndex := FIndexImagemArquivoSelec;
end
else
begin
T4.ImageIndex := FIndexImagemPasta;
T4.SelectedIndex := FIndexImagemPastaSelec;
end;
end;
end;
end;
end;
end;
Self.Repaint;
end
else if Assigned(FPageControl) then
with FPageControl do
try
FPosicionarPageControlChange := False;
Self.Invalidate;
Self.Items.Clear;
for x1 := 0 to PageCount - 1 do
if (Pages[x1].Enabled) then
begin
New(MeuRegistro);
MeuRegistro^.FTabSheet := Pages[x1];
T1 := Self.Items.AddObject(nil, MeuRegistro^.FTabSheet.Caption, MeuRegistro);
T1.ImageIndex := FIndexImagemArquivo;
T1.SelectedIndex := FIndexImagemArquivoSelec;
end;
Self.Repaint;
finally
FPosicionarPageControlChange := True;
end;
try
FPosicionarPageControlChange := False;
if FOrdenar then
Self.Items.AlphaSort(True);
// Expandindo 1 nivel
if FExpandir1 then
with Self do
for x1 := 0 to Items.Count - 1 do
if Items[x1].Level = 0 then Items[x1].Expand(False);
finally
FPosicionarPageControlChange := True;
end;
end;
function TTreeViewDPR.Posicionar(Sender: TObject; ExecutarChange: Boolean = True): Boolean;
var x: Integer;
begin
Result := False;
if FRecolherAntesPosicionar then Self.FullCollapse;
if Assigned(FMenuPrincipal) and (Sender is TMenuItem) then
with Self do
for x := 0 to Items.Count -1 do
if (PonteiroMeuRegistro(Items[x].Data)^.FMenu = (Sender as TMenuItem)) then
begin
Select(Items[x], []);
Result := True;
Break;
end;
if Assigned(FPageControl) and (Sender is TTabSheet) then
with Self do
try
FPosicionarPageControlChange := False;
for x := 0 to Items.Count -1 do
if (PonteiroMeuRegistro(Items[x].Data)^.FTabSheet = (Sender as TTabSheet)) then
begin
Select(Items[x], []);
Result := True;
Break;
end;
finally
FPosicionarPageControlChange := True;
if ExecutarChange then Change(Self.Selected);
end;
if Assigned(FEventoAoPosicionar) then
FEventoAoPosicionar(Sender);
end;
procedure TTreeViewDPR.WMLButtonUp(var Message: TWMLButtonUp);
var MousePos: TPoint; ANode: TTreeNode;
begin
// Interceptando o botão ESQUERDO do mouse
inherited;
if GetCursorPos(MousePos) then
begin
MousePos := Self.ScreenToClient(MousePos);
ANode := Self.GetNodeAt(MousePos.x, MousePos.y);
if (ANode <> nil) and (Self.Selected <> nil) then
if (ANode.Text = Self.Selected.Text) then
begin
if Assigned(FMenuPrincipal) then
PonteiroMeuRegistro(Selected.Data)^.FMenu.Click;
end
end
end;
procedure TTreeViewDPR.WMRButtonUp(var Message: TWMRButtonUp);
var MousePos: TPoint; ANode: TTreeNode;
begin
// Interceptando o botão DIREITO do mouse
inherited;
if GetCursorPos(MousePos) then
begin
MousePos := Self.ScreenToClient(MousePos);
ANode := Self.GetNodeAt(MousePos.x, MousePos.y);
if (ANode <> nil) and (Self.Selected <> nil) then
Self.Selected := ANode;
end
end;
procedure TTreeViewDPR.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited;
if Key = vk_return then
begin
if Assigned(FMenuPrincipal) and
(Self.Selected <> nil) then
PonteiroMeuRegistro(Selected.Data)^.FMenu.Click;