-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUAbcCliente.~pas
118 lines (84 loc) · 2.68 KB
/
UAbcCliente.~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
unit UAbcCliente;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, DBClient, Grids, DBGrids, ComCtrls;
type
TFABCCliente = class(TForm)
Button1: TButton;
TB_Pedido: TADOQuery;
TB_ABC: TClientDataSet;
TB_ABCCodCliente: TIntegerField;
TB_ABCTotal: TCurrencyField;
TB_Pedidoid_cliente: TIntegerField;
TB_Pedidopreco: TBCDField;
TB_PedidoSituacao: TIntegerField;
TB_Pedidocodigo: TAutoIncField;
TB_Pedidobaixaestoque: TBooleanField;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
CheckBox1: TCheckBox;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
TB_Pedidodata_hora: TDateTimeField;
TB_ABCUltimaCompra: TDateField;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FABCCliente: TFABCCliente;
implementation
uses UDados;
{$R *.dfm}
procedure TFABCCliente.Button1Click(Sender: TObject);
begin
TB_Pedido.Active := false;
TB_Pedido.SQL.Clear;
TB_Pedido.SQL.Add('Select A.id_cliente, A.preco, A.data_hora, A.Situacao, B.codigo, B.baixaestoque from');
TB_Pedido.SQL.Add('Venda_info A left join situacao_pedido B on');
TB_Pedido.SQL.Add('A.situacao = b.codigo');
tb_pedido.SQL.Add('Where b.baixaestoque = true');
if CheckBox1.Checked then
TB_Pedido.SQL.Add('and A.data_hora between #'+FormatDateTime('mm/dd/yyyy',DateTimePicker1.Date)+'# and #'+FormatDateTime('mm/dd/yyyy',DateTimePicker2.Date)+'#');
tb_pedido.open;
// selecionada função acima para listar os clientes
// criando tb
TB_ABC.Active := false;
TB_ABC.IndexFieldNames := '';
TB_ABC.IndexDefs.Clear;
TB_ABC.CreateDataSet;
TB_pedido.First;
WHile not TB_Pedido.Eof do
begin
if not TB_ABC.Locate(TB_ABCCodCliente.FieldName,TB_Pedidoid_cliente.Value,[]) then
begin
TB_ABC.Insert;
TB_ABCCodCliente.Value := TB_Pedidoid_cliente.Value;
TB_ABCUltimaCompra.Value := TB_Pedidodata_hora.Value;
TB_ABCTotal.Value := TB_Pedidopreco.Value;
end
else
begin
// cliente ja adicionado, atualizar dados
TB_ABC.Edit;
TB_ABCTotal.Value :=TB_ABCTotal.Value + TB_Pedidopreco.Value;
if TB_Pedidodata_hora.Value > TB_ABCUltimaCompra.Value then
TB_ABCUltimaCompra.Value := TB_Pedidodata_hora.Value;
tb_abc.Post;
end;
TB_Pedido.Next;
end;
with TB_ABC.IndexDefs.AddIndexDef do
begin
Name := 'comprou';
Fields := TB_ABCTotal.FieldName;
Options := [ixDescending];//ixAscending
end;
TB_ABC.IndexName := 'comprou';
Banco.ListaQuery(TB_ABC,'',0);
TB_ABC.Active := false;
end;
end.