-
Notifications
You must be signed in to change notification settings - Fork 6
/
upadrao.pas
173 lines (147 loc) · 4.37 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
unit uPadrao;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, FileUtil, Forms, Controls, Graphics, Dialogs,
ExtCtrls, DbCtrls, StdCtrls, uDm;
type
{ TfPadrao }
TfPadrao = class(TForm)
btnClose: TImage;
ds: TDataSource;
btnINC: TImage;
btnEDT: TImage;
btnEXC: TImage;
btnPROC: TImage;
btnCANC: TImage;
btnSALV: TImage;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure btnCANC1Click(Sender: TObject);
procedure btnCANCClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnEDTClick(Sender: TObject);
procedure btnEXCClick(Sender: TObject);
procedure btnINCClick(Sender: TObject);
procedure btnPROCClick(Sender: TObject);
procedure btnSALVClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure ControlaBotoes;
procedure HabilitaEdicao(Status:Boolean);
public
end;
var
fPadrao: TfPadrao;
implementation
{$R *.lfm}
{ TfPadrao }
procedure TfPadrao.FormCreate(Sender: TObject);
begin
btnINC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnEDT.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnEXC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnPROC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnSALV.Visible := (ds.DataSet.State in [DsInsert,DsEdit]);
btnCANC.Visible := (ds.DataSet.State in [DsInsert,DsEdit]);
end;
procedure TfPadrao.FormShow(Sender: TObject);
begin
HabilitaEdicao(false);
ds.DataSet.Active:=True;
end;
procedure TfPadrao.btnINCClick(Sender: TObject);
begin
if (ds.DataSet.State in [dsBrowse, dsInactive]) then
ds.DataSet.Active:=True;
ds.DataSet.Insert;
ControlaBotoes;
HabilitaEdicao(true);
end;
procedure TfPadrao.btnPROCClick(Sender: TObject);
begin
ControlaBotoes;
HabilitaEdicao(false);
end;
procedure TfPadrao.btnSALVClick(Sender: TObject);
begin
if (ds.DataSet.State in [dsEdit, dsInsert]) then
ds.DataSet.Post;
ControlaBotoes;
HabilitaEdicao(false);
end;
procedure TfPadrao.btnEDTClick(Sender: TObject);
begin
ds.DataSet.Edit;
ControlaBotoes;
HabilitaEdicao(true);
end;
procedure TfPadrao.btnCANCClick(Sender: TObject);
begin
ds.DataSet.Cancel;
ControlaBotoes;
HabilitaEdicao(false);
end;
procedure TfPadrao.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfPadrao.btnCANC1Click(Sender: TObject);
begin
end;
procedure TfPadrao.btnEXCClick(Sender: TObject);
begin
ds.DataSet.Delete;
ControlaBotoes;
HabilitaEdicao(false);
end;
procedure TfPadrao.ControlaBotoes;
begin
btnINC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnEDT.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnEXC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnPROC.Visible := not(ds.DataSet.State in [DsInsert,DsEdit]);
btnSALV.Visible := (ds.DataSet.State in [DsInsert,DsEdit]);
btnCANC.Visible := (ds.DataSet.State in [DsInsert,DsEdit]);
end;
procedure TfPadrao.HabilitaEdicao(Status: Boolean);
var
n : integer;
begin
for n := 0 to ComponentCount - 1 do
begin
if components[n] is TDBEdit then
begin
TDBEdit(components[n]).Enabled := Status;
TDBEdit(components[n]).Color := clwhite;
TDBEdit(components[n]).Font.Color := clBlack;
end
else if components[n] is TEdit then
begin
TEdit(components[n]).Enabled := Status;
TEdit(components[n]).Color := clwhite;
TEdit(components[n]).Font.Color := clBlack;
end
else if components[n] is TComboBox then
begin
TComboBox(components[n]).Enabled := Status;
TComboBox(components[n]).Color := clwhite;
TComboBox(components[n]).Font.Color := clBlack;
end
else if components[n] is TDBLookupComboBox then
begin
TDBComboBox(components[n]).Enabled := Status;
TDBComboBox(components[n]).Color := clwhite;
TDBComboBOx(components[n]).Font.Color := clBlack;
end
else if components[n] is TDBLookupComboBox then
begin
TDBlookupComboBox(components[n]).Enabled := Status;
TDBlookupComboBox(components[n]).Color := clwhite;
TDBlookupComboBOx(components[n]).Font.Color := clBlack;
end;
end;
end;
end.