-
Notifications
You must be signed in to change notification settings - Fork 1
/
formaPagamentoListaU.pas
134 lines (116 loc) · 4.18 KB
/
formaPagamentoListaU.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
unit formaPagamentoListaU;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ModeloListaU, Data.DB, Vcl.ExtCtrls,
Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls, Vcl.Buttons, uADStanIntf, uADStanOption,
uADStanParam, uADStanError, uADDatSManager, uADPhysIntf, uADDAptIntf,
uADStanAsync, uADDAptManager, uADCompDataSet, uADCompClient;
type
TfrmFormaPagamentoLista = class(TfrmModeloLista)
adqFormPgto: TADQuery;
procedure FormShow(Sender: TObject);
procedure btnExcluirClick(Sender: TObject);
procedure btnAdicionarClick(Sender: TObject);
procedure dbgDadosDblClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure btnFiltroClick(Sender: TObject);
procedure dbgDadosTitleClick(Column: TColumn);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmFormaPagamentoLista: TfrmFormaPagamentoLista;
campoFiltro: string;
implementation
{$R *.dfm}
uses DataModLivraria, FormaPagamento;
procedure TfrmFormaPagamentoLista.btnAdicionarClick(Sender: TObject);
begin
inherited;
frmFormPagto := TfrmFormPagto.Create(Application);
//idRef := 0;
end;
procedure TfrmFormaPagamentoLista.btnExcluirClick(Sender: TObject);
var iCod : integer;
begin
inherited;
//verifica se há registros na tabela
if dsModelo.DataSet.RecordCount = 0 then begin
MessageBox(application.Handle, Pchar('Não existem registros!'), Pchar('Falha ao excluir registro!'), MB_OK+MB_ICONERROR);
exit;
end;
//confirmação de exclusão
if MessageBox(application.Handle, Pchar('Deseja excluir este registro?'), Pchar('Confirmar Exclusão'), MB_YESNO+MB_ICONQUESTION ) = ID_YES then begin
iCod := dsModelo.DataSet.FieldByName('ID').AsInteger;
adqFormPgto.Filtered := false;
adqFormPgto.Close;
adqFormPgto.SQL.Clear;
adqFormPgto.SQL.Add('SELECT ID FROM TBFORM_PAGAMENTO WHERE ID = :ID');
adqFormPgto.ParamByName('ID').AsInteger := iCod;
adqFormPgto.Open;
if not adqFormPgto.IsEmpty then begin
try
DataModuleLivraria.adConnectionLivro.StartTransaction;
adqFormPgto.Close;
adqFormPgto.SQL.Clear;
adqFormPgto.SQL.Add('DELETE FROM TBFORM_PAGAMENTO WHERE ID = :ID');
adqFormPgto.ParamByName('ID').AsInteger := iCod;
adqFormPgto.ExecSQL;
DataModuleLivraria.adConnectionLivro.Commit;
finally
if DataModuleLivraria.adConnectionLivro.InTransaction then
DataModuleLivraria.adConnectionLivro.Rollback
else begin
FormShow(Sender);
ShowMessage('Deletado com sucesso!');
end;
end;
end;
end;
end;
procedure TfrmFormaPagamentoLista.btnFiltroClick(Sender: TObject);
var debug : string;
begin
inherited;
adqFormPgto.FilterOptions := [foCaseInsensitive];
adqFormPgto.Filter := campoFiltro+' like '+QuotedStr('%'+editFiltro.Text+'%');
debug := adqFormPgto.Filter;
//ativa o filtro
adqFormPgto.Filtered := true;
end;
procedure TfrmFormaPagamentoLista.dbgDadosDblClick(Sender: TObject);
begin
inherited;
idRef := dbgDados.DataSource.DataSet.FieldByName('ID').AsInteger; //usando dados do DataSource
frmFormPagto := TfrmFormPagto.Create(Application);
end;
procedure TfrmFormaPagamentoLista.dbgDadosTitleClick(Column: TColumn);
begin
inherited;
lbFiltro.Caption := Column.Title.Caption+': ';
editFiltro.Clear;
campoFiltro := Column.FieldName;
adqFormPgto.Filtered := false;
editFiltro.SetFocus; //apresentar o cursor no campo de pesquisa após clicar no título da coluna
end;
procedure TfrmFormaPagamentoLista.FormActivate(Sender: TObject);
begin
inherited;
dsModelo.DataSet.Refresh;
end;
procedure TfrmFormaPagamentoLista.FormShow(Sender: TObject);
begin
inherited;
adqFormPgto.Close;
adqFormPgto.SQL.Clear;
adqFormPgto.SQL.Add('SELECT ID, DESCRICAO FROM TBFORM_PAGAMENTO ORDER BY ID');
adqFormPgto.Open;
lbFiltro.Caption := dbgDados.Columns[0].Title.caption+': ';
editFiltro.Clear;
campoFiltro := dbgDados.Columns[0].FieldName;
adqFormPgto.Filtered := false;
end;
end.