Repository navigation
Expand file tree
/
Copy pathUCnpjBase.pas
More file actions
139 lines (113 loc) · 3.78 KB
/
Copy pathUCnpjBase.pas
File metadata and controls
139 lines (113 loc) · 3.78 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
unit UCnpjBase;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, StdCtrls, ExtCtrls, Mask, DBCtrls, Buttons;
type
TFCnpjBase = class(TForm)
Label1: TLabel;
CDSCNPJ: TClientDataSet;
DSCNPJ: TDataSource;
CDSCNPJCNPJ: TStringField;
CDSCNPJCNPJ_Base: TStringField;
CDSCNPJCNPJ_Filial: TStringField;
CDSCNPJCNPJ_DV: TStringField;
DBEdit1: TDBEdit;
BitBtn1: TBitBtn;
Panel2: TPanel;
Label2: TLabel;
DBEdit2: TDBEdit;
Label3: TLabel;
DBEdit3: TDBEdit;
Label4: TLabel;
DBEdit4: TDBEdit;
BtnGeraChaveNFe: TBitBtn;
procedure FormShow(Sender: TObject);
function CalculoDvCNPJ(CNPJ_Base,CNPJ_Filial: String) : String;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(Sender: TObject);
procedure BtnGeraChaveNFeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FCnpjBase: TFCnpjBase;
implementation
uses UFunctions, UPrincipal;
{$R *.dfm}
procedure TFCnpjBase.FormShow(Sender: TObject);
begin
if not (CDSCNPJ.Active and (CDSCNPJ.State in [dsinsert,dsedit])) then
CDSCNPJ.Append;
end;
function TFCnpjBase.CalculoDvCNPJ(CNPJ_Base, CNPJ_Filial: String): String;
var DV : String;
begin
DV := CalcMod11(CNPJ_Base+CNPJ_Filial);
DV := DV+CalcMod11(CNPJ_Base+CNPJ_Filial+DV);
Result := DV;
end;
procedure TFCnpjBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TFPrincipal(owner).FCNPJBase := nil;
TFPrincipal(owner).FCNPJBase.Free;
self.Release;
end;
procedure TFCnpjBase.BitBtn1Click(Sender: TObject);
var DVCalc: String;
begin
if Length(CDSCNPJCNPJ.AsString) <> 14 then
begin
ShowMessage('Digite um CNPJ com 14 DIgitos');
exit;
end;
CDSCNPJCNPJ_Base.AsString := Copy(CDSCNPJCNPJ .AsString,0,8);
CDSCNPJCNPJ_Filial.AsString := Copy(CDSCNPJCNPJ .AsString,9,4);
DVCalc := CalculoDvCNPJ(CDSCNPJCNPJ_Base.AsString, CDSCNPJCNPJ_Filial.AsString);
CDSCNPJCNPJ_DV.AsString := Copy(CDSCNPJCNPJ .AsString,13,2);
if DvCalc <> CDSCNPJCNPJ_DV.AsString then
begin
if messagedlg('DV Informado invalido, deseja recalcular ?',mtCustom,[mbYes,mbNo], 0) = mrYes then
CDSCNPJCNPJ_DV.AsString := DVCalc;
end;
end;
procedure TFCnpjBase.BtnGeraChaveNFeClick(Sender: TObject);
var DVCalc,CamposLengthErrado: String;
begin
if (CDSCNPJCNPJ_Base.AsString = '') or
(CDSCNPJCNPJ_Filial.AsString = '') then
begin
ShowMessage('Informe todos os campos do CNPJ, o unico que pode ficar em branco é DV');
exit;
end;
if Length(CDSCNPJCNPJ_Base.AsString) <> 8 then
CamposLengthErrado := 'CNPJ Base deve possuir 8 digitos';
if Length(CDSCNPJCNPJ_Filial.AsString) <> 4 then
if CamposLengthErrado <> '' then
CamposLengthErrado := CamposLengthErrado +#13+'Filial deve possuir 4 digitos'
else
CamposLengthErrado := 'Filial deve possuir 4 digitos';
if CamposLengthErrado <> '' then
begin
ShowMessage(CamposLengthErrado);
exit;
end;
DVCalc := CalculoDvCNPJ(CDSCNPJCNPJ_Base.AsString, CDSCNPJCNPJ_Filial.AsString);
if DvCalc <> CDSCNPJCNPJ_DV.AsString then
begin
if messagedlg('DV Informado invalido, deseja recalcular ?',mtCustom,[mbYes,mbNo], 0) = mrYes then
CDSCNPJCNPJ_DV.AsString := DVCalc;
end;
CDSCNPJCNPJ.AsString := CDSCNPJCNPJ_Base.AsString+CDSCNPJCNPJ_Filial.AsString+CDSCNPJCNPJ_DV.AsString;
end;
procedure TFCnpjBase.FormCreate(Sender: TObject);
begin
SetEditNumbers(DBEdit1.Handle);
SetEditNumbers(DBEdit2.Handle);
SetEditNumbers(DBEdit3.Handle);
SetEditNumbers(DBEdit4.Handle);
end;
end.