-
Notifications
You must be signed in to change notification settings - Fork 0
/
UPadrao.pas
205 lines (188 loc) · 5.47 KB
/
UPadrao.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
unit UPadrao;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, pngimage, Buttons, PngBitBtn, FMTBcd, DB,
SqlExpr, DBClient, Provider, DBXCommon, DBCtrls;
type
TfrmPadrao = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
GroupBox1: TGroupBox;
btNovo: TPngBitBtn;
btCancelar: TPngBitBtn;
btGravar: TPngBitBtn;
btEditar: TPngBitBtn;
btExcluir: TPngBitBtn;
dspTab: TDataSetProvider;
dsTab: TDataSource;
cdsTab: TClientDataSet;
sqlTab: TSQLQuery;
procedure dsTabStateChange(Sender: TObject);
procedure btNovoClick(Sender: TObject);
procedure btCancelarClick(Sender: TObject);
procedure btGravarClick(Sender: TObject);
procedure btExcluirClick(Sender: TObject);
procedure btEditarClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure AbreDados;
procedure AbreTabela(Cp:String;Valor:Integer);
private
{ Private declarations }
public
{ Public declarations }
Cod_Padrao : integer;
Campo : String;
end;
var
frmPadrao: TfrmPadrao;
Tr : TDBXTransaction;
implementation
uses UDados, Uerro;
{$R *.dfm}
procedure TfrmPadrao.AbreDados;
begin
cdsTab.Close;
sqlTab.Close;
sqlTab.ParamByName(Campo).AsInteger := Cod_Padrao;
cdsTab.Open;
end;
procedure TfrmPadrao.AbreTabela(Cp:String; Valor: Integer);
begin
cdsTab.Close;
sqlTab.Close;
sqlTab.ParamByName(Cp).AsInteger := Valor;
Campo := Cp;
cdsTab.Open;
end;
procedure TfrmPadrao.btCancelarClick(Sender: TObject);
begin
try
if cdsTab.Active then begin
cdsTab.CancelUpdates;
Dados.DB.CommitFreeAndNil(Tr);
end;
except on E : Exception do begin
application.CreateForm(TfrmErro, frmErro);
frmErro.lblClasse.Caption := E.ClassName;
frmErro.lblErro.Lines.Add(PChar(E.Message));
frmErro.ShowModal;
Dados.DB.RollbackFreeAndNil(tr);
end;
end;
end;
procedure TfrmPadrao.btEditarClick(Sender: TObject);
begin
try
Tr := Dados.DB.BeginTransaction(TDBXIsolations.ReadCommitted);
if cdsTab.Active then begin
Cod_Padrao := cdsTab.FieldByName(Campo).AsInteger;
cdsTab.Edit;
end;
except on E : Exception do begin
application.CreateForm(TfrmErro, frmErro);
frmErro.lblClasse.Caption := E.ClassName;
frmErro.lblErro.Lines.Add(PChar(E.Message));
dados.DB.RollbackIncompleteFreeAndNil(tr);
frmErro.ShowModal;
end;
end;
end;
procedure TfrmPadrao.btExcluirClick(Sender: TObject);
begin
if application.MessageBox('Deseja Excluir o Registro?', 'Confirmação', MB_YesNo + MB_IconQuestion) = idYes then begin
try
Tr := Dados.DB.BeginTransaction(TDBXIsolations.ReadCommitted);
if cdsTab.Active then begin
cdsTab.Delete;
cdsTab.ApplyUpdates(-1);
Dados.DB.CommitFreeAndNil(Tr);
end;
except on E : Exception do begin
application.CreateForm(TfrmErro, frmErro);
frmErro.lblClasse.Caption := E.ClassName;
frmErro.lblErro.Lines.Add(PChar(E.Message));
frmErro.ShowModal;
Dados.DB.RollbackFreeAndNil(tr);
end;
end;
end;
end;
procedure TfrmPadrao.btGravarClick(Sender: TObject);
begin
if application.MessageBox('Deseja Realmente Gravar as Alterações o Registro?', 'Confirmação', MB_YesNo + MB_IconQuestion) = idYes then begin
try
if cdsTab.Active then begin
Cod_Padrao := cdsTab.FieldByName(Campo).AsInteger;
cdsTab.Post;
cdsTab.ApplyUpdates(-1);
Dados.DB.CommitFreeAndNil(Tr);
end;
AbreDados;
except on E : Exception do begin
application.CreateForm(TfrmErro, frmErro);
frmErro.lblClasse.Caption := E.ClassName;
frmErro.lblErro.Lines.Add(PChar(E.Message));
frmErro.ShowModal;
Dados.DB.RollbackFreeAndNil(tr);
end;
end;
end;
end;
procedure TfrmPadrao.btNovoClick(Sender: TObject);
begin
try
Tr := Dados.DB.BeginTransaction(TDBXIsolations.ReadCommitted);
if cdsTab.Active then begin
cdsTab.Append;
end;
except on E : Exception do begin
application.CreateForm(TfrmErro, frmErro);
frmErro.lblClasse.Caption := E.ClassName;
frmErro.lblErro.Lines.Add(PChar(E.Message));
dados.DB.RollbackIncompleteFreeAndNil(tr);
frmErro.ShowModal;
end;
end;
end;
procedure TfrmPadrao.dsTabStateChange(Sender: TObject);
begin
//procedimento para habilitar e desabilitar os botões
if dsTab.State in [dsBrowse] then begin
btNovo.Enabled := True;
btEditar.Enabled := True;
btExcluir.Enabled := true;
btCancelar.Enabled := false;
btGravar.Enabled := false;
end else if dsTab.State in [dsEdit, dsInsert] then begin
btNovo.Enabled := false;
btEditar.Enabled := false;
btExcluir.Enabled := false;
btCancelar.Enabled := true;
btGravar.Enabled := true;
end;
end;
procedure TfrmPadrao.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if dsTab.State in [dsEdit, dsInsert] then begin
Application.MessageBox('Registro Em Modo de Edição / Inclusão Cancele ou Grave as Alterações', 'Atenção', MB_ICONEXCLAMATION);
Action := caNone;
end else begin
release;
end;
end;
procedure TfrmPadrao.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
Key := #0;
Perform(WM_NEXTDLGCTL, 0, 0)
end;
end;
end.