forked from joseafilho/cine-tapioca
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uCadastroBase.pas
196 lines (166 loc) · 3.87 KB
/
uCadastroBase.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
unit uCadastroBase;
interface
{$REGION 'uses'}
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Data.DB, Vcl.Grids, Vcl.DBGrids, Vcl.ExtCtrls, Vcl.ComCtrls,
Vcl.DBCtrls, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param,
FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf,
FireDAC.Stan.Async, FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Client;
{$ENDREGION}
type
TfmCadastroBase = class(TForm)
pcPrincipal: TPageControl;
tsDados: TTabSheet;
tsEdit: TTabSheet;
pnDadosButtons: TPanel;
pnDadosNavigator: TPanel;
grDados: TDBGrid;
btInserir: TButton;
btEditar: TButton;
btDeletar: TButton;
nvDados: TDBNavigator;
pnEdits: TPanel;
pnEditButtons: TPanel;
btSalvar: TButton;
btCancelar: TButton;
qrDados: TFDQuery;
dsDados: TDataSource;
procedure btInserirClick(Sender: TObject);
procedure btEditarClick(Sender: TObject);
procedure btSalvarClick(Sender: TObject);
procedure btCancelarClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btDeletarClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
procedure Insert;
procedure Edit;
procedure Save;
procedure Cancel;
procedure Delete;
procedure GotoPageDados;
procedure GotoPageEdit;
procedure HiddenTabs;
{ Private declarations }
protected
function ValidarDados: boolean; virtual;
public
{ Public declarations }
end;
var
fmCadastroBase: TfmCadastroBase;
implementation
{$R *.dfm}
{$REGION 'uses'}
uses uDmConn, uSystemUtils;
{$ENDREGION}
procedure TfmCadastroBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfmCadastroBase.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not(Shift = []) then
Exit;
if dsDados.State = dsBrowse then
case Key of
VK_F2:
Insert;
VK_F3:
Edit;
VK_F4:
Delete;
end;
if dsDados.State in [dsInsert, dsEdit] then
case Key of
VK_F9:
Save;
VK_ESCAPE:
Cancel;
end;
end;
procedure TfmCadastroBase.FormShow(Sender: TObject);
begin
HiddenTabs;
GotoPageDados;
qrDados.Open;
end;
procedure TfmCadastroBase.HiddenTabs;
var
I: Integer;
begin
for I := 0 to pcPrincipal.PageCount - 1 do
pcPrincipal.Pages[I].TabVisible := false;
end;
procedure TfmCadastroBase.btSalvarClick(Sender: TObject);
begin
Save;
end;
procedure TfmCadastroBase.Save;
begin
btSalvar.SetFocus; { TODO -oUECE -cBug : Forçar atribuição do valor ao Field }
if ValidarDados then
begin
qrDados.Post;
GotoPageDados;
end;
end;
procedure TfmCadastroBase.Cancel;
begin
qrDados.Cancel;
GotoPageDados;
end;
procedure TfmCadastroBase.Delete;
begin
if not(qrDados.IsEmpty) then
if ShowQuestion('Deseja excluir o registro atual?') then
begin
qrDados.Delete;
end;
end;
procedure TfmCadastroBase.Edit;
begin
if not(qrDados.IsEmpty) then
begin
GotoPageEdit;
qrDados.Edit;
end;
end;
function TfmCadastroBase.ValidarDados: boolean;
begin
Result := false;
end;
procedure TfmCadastroBase.btCancelarClick(Sender: TObject);
begin
Cancel;
end;
procedure TfmCadastroBase.GotoPageDados;
begin
pcPrincipal.ActivePage := tsDados;
end;
procedure TfmCadastroBase.btInserirClick(Sender: TObject);
begin
Insert;
end;
procedure TfmCadastroBase.Insert;
begin
GotoPageEdit;
qrDados.Insert;
end;
procedure TfmCadastroBase.btDeletarClick(Sender: TObject);
begin
Delete;
end;
procedure TfmCadastroBase.btEditarClick(Sender: TObject);
begin
Edit;
end;
procedure TfmCadastroBase.GotoPageEdit;
begin
pcPrincipal.ActivePage := tsEdit;
end;
end.