-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelCascataTesteUnidadeEditar.pas
412 lines (390 loc) · 11.4 KB
/
ModelCascataTesteUnidadeEditar.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
unit ModelCascataTesteUnidadeEditar;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset,
ComCtrls, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids;
type
TFormModeloCascataTesteUnidadeEditar = class(TForm)
PanelLista: TPanel;
lblTestes: TLabel;
gridtabelas: TDBGrid;
edtProcurar: TLabeledEdit;
btnVoltar: TBitBtn;
btnLimpar1: TBitBtn;
labelCriarTesteUnidade: TPanel;
lblTitulo: TLabel;
lblDescricao: TLabel;
lblTipo: TLabel;
lblSituacao: TLabel;
edtIdentificador: TLabeledEdit;
edtNome: TLabeledEdit;
memoDescricao: TMemo;
cboxTipo: TComboBox;
cboxSituacao: TComboBox;
edtDataTeste: TLabeledEdit;
btnSalvar: TBitBtn;
btncancelar: TBitBtn;
Query: TZQuery;
Source: TDataSource;
MainMenu1: TMainMenu;
Ajuda1: TMenuItem;
Logoff1: TMenuItem;
btnExcluir: TBitBtn;
btnEditar: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Logoff1Click(Sender: TObject);
procedure btncancelarClick(Sender: TObject);
procedure edtIdentificadorChange(Sender: TObject);
procedure edtProcurarChange(Sender: TObject);
procedure btnEditarClick(Sender: TObject);
procedure btnLimpar1Click(Sender: TObject);
procedure btnVoltarClick(Sender: TObject);
procedure btnExcluirClick(Sender: TObject);
procedure btnSalvarClick(Sender: TObject);
procedure Ajuda1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormModeloCascataTesteUnidadeEditar: TFormModeloCascataTesteUnidadeEditar;
implementation
uses ModeloCascata, ModelCascataTesteUnidadeEditarAjuda;
{$R *.dfm}
procedure TFormModeloCascataTesteUnidadeEditar.FormCreate(Sender: TObject);
begin
//Centraliza form
Left := (GetSystemMetrics(SM_CXSCREEN) - Width) div 2;
Top := (GetSystemMetrics(SM_CYSCREEN) - Height) div 2;
//Atualiza grid testeunidade
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select identificador as ID, nome as Nome from tbtesteunidade where codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1) order by nome asc');
query.open;
end;
end;
procedure TFormModeloCascataTesteUnidadeEditar.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//Fecha e libera memória
FormModeloCascataTesteUnidadeEditar.Release;
FormModeloCascataTesteUnidadeEditar:=Nil;
end;
procedure TFormModeloCascataTesteUnidadeEditar.Logoff1Click(
Sender: TObject);
begin
//Faz logoff
FormModeloCascata.Close;
FormModeloCascataTesteUnidadeEditar.Close;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btncancelarClick(
Sender: TObject);
begin
//Limpa os campos
edtIdentificador.Clear;
edtNome.Clear;
memoDescricao.Lines.clear;
cboxTipo.ItemIndex:=-1;
cboxSituacao.ItemIndex:=-1;
edtDataTeste.clear;
end;
procedure TFormModeloCascataTesteUnidadeEditar.edtIdentificadorChange(
Sender: TObject);
begin
//Se estiver vazio
if (edtIdentificador.text='') then
begin
edtIdentificador.Enabled:=False;
edtNome.Enabled:=False;
lblDescricao.Enabled:=False;
memoDescricao.Enabled:=False;
lblTipo.Enabled:=False;
cboxTipo.Enabled:=False;
lblSituacao.Enabled:=false;
cboxSituacao.Enabled:=False;
edtDataTeste.Enabled:=False;
btnSalvar.Enabled:=False;
btnCancelar.Enabled:=False;
edtProcurar.Enabled:=True;
btnEditar.Enabled:=True;
btnExcluir.Enabled:=True;
btnLimpar1.Enabled:=True;
btnVoltar.Enabled:=True;
end
else
begin
edtIdentificador.Enabled:=True;
edtNome.Enabled:=True;
lblDescricao.Enabled:=True;
memoDescricao.Enabled:=True;
lblTipo.Enabled:=True;
cboxTipo.Enabled:=True;
lblSituacao.Enabled:=True;
cboxSituacao.Enabled:=True;
edtDataTeste.Enabled:=True;
btnSalvar.Enabled:=True;
btnCancelar.Enabled:=True;
edtProcurar.Enabled:=False;
btnEditar.Enabled:=False;
btnExcluir.Enabled:=False;
btnLimpar1.Enabled:=False;
btnVoltar.Enabled:=False;
end;
end;
procedure TFormModeloCascataTesteUnidadeEditar.edtProcurarChange(
Sender: TObject);
begin
//Seleciona dados de acordo com o nome no edt procurar
with query do
begin
query.close;
query.sql.Clear;
query.sql.text:=('select identificador as ID, nome as Nome from tbtesteunidade where nome like "'+edtProcurar.Text+'%" and codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1)');
query.open;
end;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btnEditarClick(
Sender: TObject);
var
id,nome,tipo,situacao:string;
begin
//seleciona pelo id
id:=(gridtabelas.Columns.Items[0].Field).AsString;
//Seleciona teste unidade pelo nome
nome:=(gridtabelas.Columns.Items[1].Field).AsString;
//Se vazio
if (id='') or (nome='') then
begin
showmessage('Selecione um teste de unidade da lista!');
gridtabelas.SetFocus;
Abort;
end;
//Seleciona e insere nos campos
with query do
begin
query.close;
query.sql.Clear;
query.sql.text:=('select * from tbtesteunidade where identificador="'+id+'" and nome="'+nome+'" and codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1)');
query.open;
edtIdentificador.text:=Query.FieldByName('identificador').AsString;
edtNome.text:=Query.FieldByName('nome').AsString;
memoDescricao.Lines.Text:=Query.FieldByName('descricao').AsString;
tipo:=Query.FieldByName('tipo').AsString;
situacao:=Query.FieldByName('situacao').AsString;
edtDataTeste.text:=Query.FieldByName('datateste').AsString;
end;
//Seta cboxTipo
if (tipo='DATA') then
begin
cboxTipo.ItemIndex:=0;
end;
if (tipo='NÚMEROS') then
begin
cboxTipo.ItemIndex:=1;
end;
if (tipo='SENHA') then
begin
cboxTipo.ItemIndex:=2;
end;
if (tipo='DOMÍNIO') then
begin
cboxTipo.ItemIndex:=3;
end;
if (tipo='CPF/CNPJ, ETC') then
begin
cboxTipo.ItemIndex:=4;
end;
if (tipo='OUTROS') then
begin
cboxTipo.ItemIndex:=5;
end;
//Seta situação
if (situacao='APROVADO') then
begin
cboxSituacao.ItemIndex:=0;
end;
if (situacao='PENDENTE') then
begin
cboxSituacao.ItemIndex:=1;
end;
if (situacao='REPROVADO') then
begin
cboxSituacao.ItemIndex:=2;
end;
//Atua liza lista testeunidade
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select identificador as ID, nome as Nome from tbtesteunidade where codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1)');
query.open;
end;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btnLimpar1Click(
Sender: TObject);
begin
//Limpa edtProcurar
edtProcurar.Clear;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btnVoltarClick(
Sender: TObject);
begin
//Fecha form
FormModeloCascataTesteUnidadeEditar.Close;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btnExcluirClick(
Sender: TObject);
var
resposta:integer;
id,nome,codigo_projeto:string;
begin
//seleciona pelo id
id:=(gridtabelas.Columns.Items[0].Field).AsString;
//Seleciona teste unidade pelo nome
nome:=(gridtabelas.Columns.Items[1].Field).AsString;
//Se estiver vazio
if (id='') or (nome='') then
begin
showmessage('Selecione um teste de unidade da lista!');
gridtabelas.SetFocus;
Abort;
end;
//Seleciona codigo projeto
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select codigo_projeto from tbprojetoacesso order by codigo desc limit 1');
query.open;
codigo_projeto:=Query.FieldByName('codigo_projeto').AsString;
end;
//Faz questionamento
resposta:=messagedlg('Você deseja excluir o teste de unidade ID="'+id+'" e Nome="'+nome+'"?',mtinformation,mbokcancel,0);
//Se sim
if (resposta=1) then
begin
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('delete from tbtesteunidade where identificador="'+id+'" and nome="'+nome+'" and codigo_projeto="'+codigo_projeto+'"');
query.ExecSql;
end;
showmessage('Teste de unidade excluido com sucesso!');
end;
//atualiza teste de unidade
with query do
begin
query.Close;
query.sql.clear;
query.sql.text:=('select identificador as ID, nome as Nome from tbtesteunidade where codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1)');
query.open;
end;
end;
procedure TFormModeloCascataTesteUnidadeEditar.btnSalvarClick(
Sender: TObject);
var
codigo_projeto,tamanho,i,cont:integer;
palavra,letra:string;
begin
//Se estiver vazio
if (memoDescricao.Lines.text='') then
begin
showmessage('O campo descrição é obrigatório!');
memoDescricao.SetFocus;
Abort;
end;
if (cboxTipo.Text='') then
begin
showmessage('O campo tipo é obrigatório!');
cboxTipo.SetFocus;
Abort;
end;
if (cboxSituacao.text='') then
begin
showmessage('O campo situação é obrigatório!');
cboxSituacao.SetFocus;
Abort;
end;
//Se existir mais espaços do que letras
cont:=0;
palavra:=memoDescricao.Lines.Text;
tamanho:=length(palavra);
for i:=1 to tamanho do
begin
letra:=copy(palavra,i,1);
if (letra=' ') then
begin
cont:=cont-1;
end
else
begin
cont:=cont+2;
end;
end;
if (cont<0) then
begin
showmessage('O campo descrição contém mais espaços do que letras!');
memoDescricao.SetFocus;
Abort;
end;
//seleciona codigo_projeto
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select codigo_projeto from tbprojetoacesso order by codigo desc limit 1');
query.open;
codigo_projeto:=Query.FieldByName('codigo_projeto').AsInteger;
end;
//Atualiza tabela
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('update tbtesteunidade set descricao="'+memoDescricao.Lines.Text+'" where identificador="'+edtIdentificador.Text+'" and nome="'+edtNome.text+'" and codigo_projeto="'+IntToStr(codigo_projeto)+'"');
query.ExecSQL;
end;
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('update tbtesteunidade set tipo="'+cboxTipo.Text+'" where identificador="'+edtIdentificador.Text+'" and nome="'+edtNome.text+'" and codigo_projeto="'+IntToStr(codigo_projeto)+'"');
query.ExecSQL;
end;
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('update tbtesteunidade set situacao="'+cboxSituacao.text+'" where identificador="'+edtIdentificador.Text+'" and nome="'+edtNome.text+'" and codigo_projeto="'+IntToStr(codigo_projeto)+'"');
query.ExecSQL;
end;
//Atualiza lista de testes de unidade
with query do
begin
query.close;
query.sql.clear;
query.sql.text:=('select identificador as ID, nome as Nome from tbtesteunidade where codigo_projeto=(select codigo_projeto from tbprojetoacesso order by codigo desc limit 1)');
query.open;
end;
showmessage('Teste de unidade salvo!');
//Limpa os campos
edtIdentificador.Clear;
edtNome.Clear;
memoDescricao.Lines.Clear;
cboxTipo.ItemIndex:=-1;
cboxSituacao.ItemIndex:=-1;
edtDataTeste.Clear;
end;
procedure TFormModeloCascataTesteUnidadeEditar.Ajuda1Click(
Sender: TObject);
begin
//Cria e exibe
Application.CreateForm(TFormModeloCascataTesteUnidadeEditarAjuda, FormModeloCascataTesteUnidadeEditarAjuda);
FormModeloCascataTesteUnidadeEditarAjuda.ShowModal;
end;
end.