-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit1.pas
272 lines (234 loc) · 7.6 KB
/
Unit1.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
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL,
FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
FireDAC.Comp.Client, Data.DB, FireDAC.Comp.DataSet, Vcl.StdCtrls,
FireDAC.VCLUI.Login, Vcl.Grids, Vcl.DBGrids, FireDAC.Comp.UI,
FireDAC.VCLUI.Wait, Data.Bind.EngExt, Vcl.Bind.DBEngExt, Vcl.Bind.Grid,
System.Rtti, System.Bindings.Outputs, Vcl.Bind.Editors, Vcl.DBCtrls,
Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope, Vcl.ComCtrls,
Vcl.DBCGrids, Data.Bind.Controls, Vcl.ExtCtrls, Vcl.Buttons,
Vcl.Bind.Navigator, Vcl.ButtonGroup, Vcl.ImgList, Vcl.Tabs, Vcl.DockTabSet,
Vcl.CustomizeDlg, Vcl.ShellAnimations, Vcl.MPlayer, Vcl.CategoryButtons,
VCLTee.TeCanvas, VCLTee.TeePenDlg;
type
TForm1 = class(TForm)
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
Button1: TButton;
Label1: TLabel;
FDPhysMySQLDriverLink1: TFDPhysMySQLDriverLink;
FDUpdateSQL1: TFDUpdateSQL;
DataSource1: TDataSource;
BindSourceDB1: TBindSourceDB;
BindingsList1: TBindingsList;
LinkFillControlToField: TLinkFillControlToField;
LinkFillControlToField2: TLinkFillControlToField;
ListView1: TListView;
FDQuery2: TFDQuery;
BindSourceDB2: TBindSourceDB;
LinkListControlToField2: TLinkListControlToField;
LinkPropertyToFieldCaption2: TLinkPropertyToField;
StringGrid1: TStringGrid;
BindNavigator1: TBindNavigator;
Timer1: TTimer;
Label2: TLabel;
FDQuery2pta: TStringField;
FDQuery2nombre: TStringField;
FDQuery2telefono1: TIntegerField;
FDQuery2telefono2: TIntegerField;
FDQuery2telefono3: TIntegerField;
FDQuery2mail: TStringField;
FDQuery2id_cliente: TIntegerField;
DBGrid1: TDBGrid;
DataSource2: TDataSource;
LinkGridToDataSourceBindSourceDB2: TLinkGridToDataSource;
SpeedButton1: TSpeedButton;
Label3: TLabel;
ComboBox1: TComboBox;
LinkFillControlToField3: TLinkFillControlToField;
FDQuery3: TFDQuery;
ButtonGroup1: TButtonGroup;
ImageList1: TImageList;
HotKey1: THotKey;
HeaderControl1: THeaderControl;
ShellResources1: TShellResources;
TrayIcon1: TTrayIcon;
CustomizeDlg1: TCustomizeDlg;
DockTabSet1: TDockTabSet;
PageControl1: TPageControl;
LabeledEdit1: TLabeledEdit;
ButtonPen1: TButtonPen;
ButtonColor1: TButtonColor;
ComboFlat1: TComboFlat;
CategoryButtons1: TCategoryButtons;
procedure Button1Click(Sender: TObject);
procedure FDConnection1AfterConnect(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure StringGrid1FixedCellClick(Sender: TObject; ACol, ARow: Integer);
procedure ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
ultcambio:TDateTime;
procedure RefrescarDataSet(Modo:integer);
function EstadoInsertEdit:boolean;
procedure haycambios(var cambios:boolean; ultfecha:TDateTime);
{ Public declarations }
end;
var
Form1:TForm1;
implementation
{$R *.dfm}
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
FDConnection1.Connected:=true;
end;
procedure TForm1.FDConnection1AfterConnect(Sender: TObject);
begin
label1.caption:='conectado';
end;
procedure TForm1.FormCreate(Sender: TObject);
var qry: TFDQuery;
begin
qry:=TFDQuery.Create(Application);
qry.Connection:=FDConnection1;
qry.SQL.Clear;
qry.SQL.Add('Select Max(fechahora) from cambios');
qry.Open;
//qry.ExecSQL;
ultcambio:=qry.Fields[0].AsDateTime;
qry.Close;
qry.Destroy;
label2.Caption:=DateToStr(ultcambio);
end;
procedure TForm1.haycambios(var cambios:boolean;ultfecha:TDateTime);
var qry: TFDQuery;
begin
ultfecha:=ultcambio;
qry:=TFDQuery.Create(Application);
qry.Connection:=FDConnection1;
qry.SQL.Clear;
qry.SQL.Add('Select tabla,fechahora from cambios where fechahora > :ultcambio');
qry.Params.ParamByName('ultcambio').AsDateTime:=ultcambio;
qry.Params.ParamByName('ultcambio').ParamType:=ptInput;
qry.Params.ParamByName('ultcambio').DataType:=ftDateTime;
qry.Params.ParamByName('ultcambio').asDateTime:=ultcambio;
qry.Open;
cambios:=(qry.RecordCount > 0);
if cambios then ultfecha:= qry.Fields[1].AsDateTime;
qry.Close;
qry.destroy;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var cambios:boolean;
begin
haycambios(cambios,ultcambio);
if cambios then
begin
timer1.enabled:=false;
RefrescarDataSet(1);
end;
end;
procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var empiezo,longitud:integer;
begin
empiezo:=ComboBox1.Selstart;
longitud:=ComboBox1.SelLength;
if (ord(key)=27) or (ord(key)=9) or (ord(key)=13) then (Sender as TCombobox).DroppedDown:=false
else
begin
linkGridToDataSourceBindSourceDB2.Active:=false;
linkFillControlToField3.Active:=false;
if length((Sender as TComboBox).Text) > 0 then
begin
FDQuery2.Filter:='nombre like '+quotedStr((Sender as TComboBox).Text+'%');
FDQuery2.Filtered:=true;
Combobox1.DroppedDown:=true;
end
else
FDQuery2.Filtered:=false;
if (ord(key)=08) then FDQuery2.First;
linkGridToDataSourceBindSourceDB2.Active:=true;
linkFillControlToField3.Active:=true;
ComboBox1.SelStart:=empiezo ;
ComboBox1.SelLength:=longitud;
end;
end;
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
linkGridToDataSourceBindSourceDB2.Active:=false;
if length((Sender as TEdit).Text) > 0 then
begin
FDQuery2.Filter:='nombre like '+quotedStr((Sender as TEdit).Text+'%');
FDQuery2.Filtered:=true;
end
else
FDQuery2.Filtered:=false;
linkGridToDataSourceBindSourceDB2.Active:=true;
end;
function TForm1.EstadoInsertEdit:boolean;
var i:integer; enestado:boolean;
begin
i:=0;
enestado:=false;
while (i < FDConnection1.DataSetCount) and (not enestado) do
begin
if (FDConnection1.DataSets[i].State in [dsInsert,dsEdit]) then
enestado:=true;
i:=i+1;
end;
Result:=enestado;
end;
procedure TForm1.RefrescarDataSet(Modo:integer);
var i: integer; cambios:boolean;
begin
try
i:=0;
case Modo of
0: begin
while (i < FDConnection1.DataSetCount) do
begin
FDConnection1.DataSets[i].Refresh;
i:=i+1;
end;
haycambios(cambios,ultcambio)
end;
1: begin
if not EstadoInsertEdit then
while (i < FDConnection1.DataSetCount) do
begin
FDConnection1.DataSets[i].Refresh;
i:=i+1;
end;
end;
end;
finally
timer1.Enabled:=true;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Tform2.Create(Application).Show;
end;
procedure TForm1.StringGrid1FixedCellClick(Sender: TObject; ACol,
ARow: Integer);
var i:integer ;
begin
FDQuery2.IndexFieldNames:=FDQuery2.Fields[Acol].FieldName;
for i := 0 to ((Sender as TStringGrid).ColCount-1) do
(Sender as TStringGrid).Cols[i].Clear;
linkgridtodatasourcebindsourcedb2.Active:=false;
linkgridtodatasourcebindsourcedb2.Active:=true; // actualizar GRID
end;
end.