-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnt_ProtocoloIni.pas
More file actions
459 lines (425 loc) · 16.6 KB
/
Copy pathUnt_ProtocoloIni.pas
File metadata and controls
459 lines (425 loc) · 16.6 KB
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
unit Unt_ProtocoloIni;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unt_BaseIni, Unit_DM, ToolWin, ActnMan, ActnCtrls, ActnMenus,
ActnList, Menus, Unt_CadAnDocumentos, dxSkinsCore, dxSkinOffice2010Blue,
dxSkinscxPCPainter, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, dxSkinsForm, StdCtrls, cxButtons, ExtCtrls, cxPC, cxPCGoDialog,
Unt_CadAnUsuarios, Unt_CadAnSetores, Unt_CadAnClientes, dxSkinBlack,
dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
dxGDIPlusClasses, ImgList, Unt_CadAnEmpresas, dxScreenTip, dxCustomHint,
cxHint, Unt_CadAnProtocolos, Unt_CadAnArquivo, Unt_CadAnAgendaCompromisso, Unt_Util,
DB, DBClient, DateUtils, dxAlertWindow, ComObj, jpeg;
type
TF_ProtocoloIni = class(TF_BaseIni)
Agendadecompromissos3: TMenuItem;
tm_Compromissos: TTimer;
procedure act_CadDocumentosExecute(Sender: TObject);
procedure ac_CadUsuariosExecute(Sender: TObject);
procedure ac_CadSetoresExecute(Sender: TObject);
procedure act_CadClientesExecute(Sender: TObject);
procedure act_CadEmpresaExecute(Sender: TObject);
procedure act_EmiProtocolosExecute(Sender: TObject);
procedure act_ArquivoClienteExecute(Sender: TObject);
procedure act_AgendaCompCadExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure tm_CompromissosTimer(Sender: TObject);
procedure alerta_baseButtonClick(Sender: TObject;
AAlertWindow: TdxAlertWindow; AButtonIndex: Integer);
private
{ Private declarations }
procedure AtualizaResgistros(var Msg: TMessage); message WM_SALVO;
function Intervalo(AHora, AMinuto: Word): Integer;
procedure CriaAtertaCompromisso(ADados: OleVariant);
procedure SetRegistroArquivo(AStream: TMemoryStream; AExtens, ANomeArquivo: string);
public
{ Public declarations }
end;
var
F_ProtocoloIni: TF_ProtocoloIni;
implementation
{$R *.dfm}
procedure TF_ProtocoloIni.act_AgendaCompCadExecute(Sender: TObject);
begin
inherited;
with TF_CadAnAgendaCompromisso.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.act_ArquivoClienteExecute(Sender: TObject);
begin
inherited;
with TF_CadAnArquivo.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.act_CadClientesExecute(Sender: TObject);
begin
inherited;
with TF_CadAnClientes.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.act_CadDocumentosExecute(Sender: TObject);
begin
inherited;
with TF_CadAnDocumentos.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.act_CadEmpresaExecute(Sender: TObject);
begin
inherited;
with TF_CadAnEmpresas.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.act_EmiProtocolosExecute(Sender: TObject);
begin
inherited;
with TF_CadAnProtocolos.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.ac_CadSetoresExecute(Sender: TObject);
begin
inherited;
with TF_CadAnSetores.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.ac_CadUsuariosExecute(Sender: TObject);
begin
inherited;
with TF_CadAnUsuarios.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
end;
procedure TF_ProtocoloIni.alerta_baseButtonClick(Sender: TObject;
AAlertWindow: TdxAlertWindow; AButtonIndex: Integer);
begin
inherited;
case AButtonIndex of
0:
begin
if DM.cds_AgendaCompromisso.Locate('AGC_Cod', AAlertWindow.Tag, []) then
begin
DM.cds_AgendaCompromisso.Edit;
DM.cds_AgendaCompromisso.FieldByName('AGC_Status').AsBoolean:= True;
DM.cds_AgendaCompromisso.Post;
if not DM.cds_AgendaCompromisso.FieldByName('AGC_ArqExec').AsBoolean then
begin
DM.cds_acoesAgComp.Filtered:= False;
DM.cds_acoesAgComp.Filter:= 'AAC_AGC_Cod = '+IntToStr(AAlertWindow.Tag);
DM.cds_acoesAgComp.Filtered:= True;
if not DM.cds_acoesAgComp.IsEmpty then
begin
DM.cds_acoesAgComp.First;
while not DM.cds_acoesAgComp.Eof do
begin
case DM.cds_acoesAgComp.FieldByName('AAC_Tipo').AsInteger of
cs_AAC_Tipo_ExecArq:
begin
if DM.cds_arquivo.Locate('ARQ_Cod', DM.cds_acoesAgComp.FieldByName('AAC_ARQ_Cod').AsInteger, []) then
ExecFileArq(DM.cds_arquivo.FieldByName('ARQ_Path').AsString, Self.Handle);
end;
cs_AAC_Tipo_FuncPre:
begin
case DM.cds_acoesAgComp.FieldByName('AAC_ARQ_Cod').AsInteger of
cs_CapturaTela:
begin
//teste
CapituraTela.SaveToFile(ExtractFileDir(Application.ExeName)+'/'+FormatDateTime('yyyymmddhhnnsszzz', Now)+'.screeen');
end;
end;
end;
end;
DM.cds_acoesAgComp.Next;
end;
end;
end;
SendMessage(Handle, WM_SALVO, 0, 0);
AAlertWindow.Close;
DM.cds_acoesAgComp.Filtered:= False;
end;
end;
end;
end;
procedure TF_ProtocoloIni.AtualizaResgistros(var Msg: TMessage);
var
book: string;
begin
tm_Compromissos.Enabled:= False;
if cds_Compromissos.Active then
cds_Compromissos.Filtered:= False;
cds_Compromissos.Data:= DM.cds_AgendaCompromisso.Data;
cds_Compromissos.IndexFieldNames:= 'AGC_Hora; AGC_Minuto';
if Not cds_Compromissos.IsEmpty then
begin
cds_Compromissos.First;
cds_Compromissos.Filtered:= False;
cds_Compromissos.Filter:= 'AGC_Data = '+FormatDateTime('yyyy-mm-dd',Date) +' and AGC_Hora >=' +FormatDateTime('hh', Now)+ ' and AGC_Minuto > '+ FormatDateTime('nn', Now) + ' and AGC_Alerta = 0';
cds_Compromissos.Filtered:= True;
cds_Compromissos.First;
tm_Compromissos.Enabled:= (not cds_Compromissos.IsEmpty);
end;
end;
procedure TF_ProtocoloIni.CriaAtertaCompromisso(ADados: OleVariant);
begin
with alerta_base do
begin
with TClientDataSet.Create(Self) do
begin
try
Data:= ADados;
First;
while Not eof do
begin
with Show(FieldByName('ACaption').AsString, FieldByName('ADescricao').AsString, FieldByName('AIndexImagem').AsInteger) do
begin
Tag:= FieldByName('ATag').AsInteger;
end;
Next;
end;
finally
Free;
end;
end;
end;
end;
procedure TF_ProtocoloIni.FormShow(Sender: TObject);
begin
inherited;
SendMessage(Handle, WM_SALVO, 0, 0);
end;
function TF_ProtocoloIni.Intervalo(AHora, AMinuto: Word): Integer;
var
DataInicial: TDateTime;
begin
Result:= -1;
try
DataInicial:= EncodeDateTime(YearOf(Now), MonthOf(Now), DayOf(Now), AHora, AMinuto + 1, 0, 0);
if (DataInicial >= now) then
Result:= MinutesBetween(DataInicial, Now);
except
Result:= -1;
end;
end;
procedure TF_ProtocoloIni.SetRegistroArquivo(AStream: TMemoryStream; AExtens, ANomeArquivo: string);
var
dirBase, CodCliente, dirArq: string;
dataAux: TClientDataSet;
begin
//Teste
CodCliente:= '1';
dirBase:= Trim(ExtractFileDir(Application.ExeName)+'\CLIENTES\'+Trim(CodCliente));
if not DirectoryExists(dirBase) then
begin
ForceDirectories(dirBase);
end;
if not DirectoryExists(dirBase+'\'+Trim(UpperCase(AExtens))) then
ForceDirectories(dirBase+'\'+Trim(UpperCase(AExtens)));
if DirectoryExists(dirBase+'\'+Trim(UpperCase(AExtens))) then
begin
if not DM.cds_pasta.Locate('PST_Nome;PST_CLI_Cod', VarArrayOf([Trim(UpperCase(AExtens)), CodCliente]) , []) then
begin
DM.cds_pasta.Insert;
DM.cds_pasta.FieldByName('PST_CLI_Cod').AsInteger:= StrToInt(CodCliente);
DM.cds_pasta.FieldByName('PST_Nome').AsString:= AExtens;
DM.cds_pasta.FieldByName('PST_Path').AsString:= dirBase+'\'+DM.cds_pasta.FieldByName('PST_Nome').AsString;
DM.cds_pasta.Post;
end;
end;
dirArq:= dirBase+'\'+Trim(UpperCase(AExtens))+'\';
if DirectoryExists(dirArq) then
begin
dataAux:= TClientDataSet.Create(Self);
dataAux.Data:= DM.cds_arquivo.Data;
with TBitmap.Create do
begin
try
AStream.Position:= 0;
LoadFromStream(AStream);
SaveToFile(dirBase+'\'+Trim(UpperCase(AExtens))+'\'+ANomeArquivo+'.'+AExtens);
finally
Free;
end;
end;
if FileExists(dirBase+'\'+Trim(UpperCase(AExtens))+'\'+ANomeArquivo+'.'+AExtens) then
begin
DM.cds_arquivo.Insert;
DM.cds_arquivo.FieldByName('ARQ_PST_Cod').AsInteger:= DM.cds_pasta.FieldByName('PST_Cod').AsInteger;
DM.cds_arquivo.FieldByName('ARQ_Nome').AsString:= ANomeArquivo+'.'+AExtens;
dataAux.Free;
DM.cds_arquivo.FieldByName('ARQ_NomeGuid').AsString:= NovoGuid+'.'+AExtens;
DM.cds_arquivo.FieldByName('ARQ_Path').AsString:= dirBase+'\'+Trim(UpperCase(AExtens))+'\'+DM.cds_arquivo.FieldByName('ARQ_NomeGuid').AsString;
DM.cds_arquivo.FieldByName('Data').AsDateTime:= Now;
DM.cds_arquivo.Post;
RenameFile(dirBase+'\'+Trim(UpperCase(AExtens))+'\'+DM.cds_arquivo.FieldByName('ARQ_Nome').AsString, DM.cds_arquivo.FieldByName('ARQ_Path').AsString)
end;
end;
end;
procedure TF_ProtocoloIni.tm_CompromissosTimer(Sender: TObject);
var
IntervaloTmp: Integer;
voz : OleVariant;
ClientAux, ClientAux2: TClientDataSet;
Stream: TMemoryStream;
jpeg: TBitmap;
begin
inherited;
tm_Compromissos.Enabled:= (not cds_Compromissos.IsEmpty);
IntervaloTmp:= Intervalo(cds_Compromissos.FieldByName('AGC_Hora').AsInteger, cds_Compromissos.FieldByName('AGC_Minuto').AsInteger);
if IntervaloTmp = 0 then
begin
ClientAux:= TClientDataSet.Create(Self);
try
ClientAux.FieldDefs:= cds_Compromissos.FieldDefs;
ClientAux.CreateDataSet;
ClientAux.CloneCursor(cds_Compromissos, False);
ClientAux.Filtered:= False;
ClientAux.Filter:= 'AGC_Hora = '+ClientAux.FieldByName('AGC_Hora').AsString+ ' and AGC_Minuto = '+ ClientAux.FieldByName('AGC_Minuto').AsString;
ClientAux.Filtered:= True;
ClientAux2:= TClientDataSet.Create(Self);
with ClientAux2 do
begin
try
with ClientAux2.FieldDefs do
begin
Add('ADescricao', ftMemo);
Add('ACaption', ftString, 100);
Add('ATag', ftInteger);
Add('AIndexImagem', ftInteger);
Add('AArqExecuta', ftBoolean);
end;
ClientAux2.CreateDataSet;
ClientAux.First;
while not ClientAux.Eof do
begin
if DM.cds_AgendaCompromisso.Locate('AGC_Cod', ClientAux.FieldByName('AGC_Cod').AsInteger, []) then
begin
DM.cds_AgendaCompromisso.Edit;
DM.cds_AgendaCompromisso.FieldByName('AGC_Alerta').AsBoolean:= True;
DM.cds_AgendaCompromisso.Post;
ClientAux2.AppendRecord([ClientAux.FieldByName('AGC_Observacao').AsString,
ClientAux.FieldByName('AGC_Hora').AsString+':'+ClientAux.FieldByName('AGC_Minuto').AsString +' - '+ClientAux.FieldByName('AGC_Descricao').AsString,
ClientAux.FieldByName('AGC_Cod').AsInteger,
0,
ClientAux.FieldByName('AGC_ArqExec').AsBoolean]);
voz:= CreateOleObject('SAPI.SpVoice');
try
voz.Speak(ClientAux.FieldByName('AGC_Descricao').AsString);
except
//
end;
if ClientAux.FieldByName('AGC_ArqExec').AsBoolean then
begin
if DM.cds_AgendaCompromisso.Locate('AGC_Cod', ClientAux.FieldByName('AGC_Cod').AsInteger, []) then
begin
DM.cds_acoesAgComp.Filtered:= False;
DM.cds_acoesAgComp.Filter:= 'AAC_AGC_Cod = '+IntToStr(ClientAux.FieldByName('AGC_Cod').AsInteger);
DM.cds_acoesAgComp.Filtered:= True;
if not DM.cds_acoesAgComp.IsEmpty then
begin
DM.cds_acoesAgComp.First;
while not DM.cds_acoesAgComp.Eof do
begin
case DM.cds_acoesAgComp.FieldByName('AAC_Tipo').AsInteger of
cs_AAC_Tipo_ExecArq:
begin
if DM.cds_arquivo.Locate('ARQ_Cod', DM.cds_acoesAgComp.FieldByName('AAC_ARQ_Cod').AsInteger, []) then
ExecFileArq(DM.cds_arquivo.FieldByName('ARQ_Path').AsString, Self.Handle);
end;
cs_AAC_Tipo_FuncPre:
begin
case DM.cds_acoesAgComp.FieldByName('AAC_ARQ_Cod').AsInteger of
cs_CapturaTela:
begin
//teste
Stream:= TMemoryStream.Create;
try
jpeg:= CapituraTela;
jpeg.SaveToStream(Stream);
try
SetRegistroArquivo(Stream, cs_SCREEN, 'USUARIOTESTE');
finally
jpeg.Free;
end;
finally
Stream.Free;
end;
end;
end;
end;
end;
DM.cds_acoesAgComp.Next;
end;
end;
DM.cds_acoesAgComp.Filtered:= False;
end;
end;
end;
ClientAux.Next;
end;
CriaAtertaCompromisso(ClientAux2.Data);
finally
ClientAux2.Free;
end;
end;
finally
ClientAux.Free;
end;
SendMessage(Handle, WM_SALVO, 0, 0);
end;
end;
end.