-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportSimple.pas
708 lines (675 loc) · 22.2 KB
/
ReportSimple.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
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
unit ReportSimple;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, sButton, sCheckBox, sGroupBox, NxColumns,
NxColumnClasses, NxScrollControl, NxCustomGridControl, NxCustomGrid,
NxGrid, sEdit, sComboBox, ExtCtrls, sPanel, IniFiles, IBC, sLabel,
Mask, sMaskEdit, sCustomComboEdit, sTooledit, sRichEdit, StrUtils, ComObj,
sGauge, DateUtils;
type
TFormReportSimple = class(TForm)
panelSelectData: TsPanel;
groupLocation: TsGroupBox;
cbLocGeneral: TsCheckBox;
cbLocWord: TsCheckBox;
groupSelectData: TsGroupBox;
editFilter: TsComboBox;
btnOK: TsButton;
btnCancel: TsButton;
panelDates: TsPanel;
editDate1: TsDateEdit;
editDate2: TsDateEdit;
lblDate: TsLabel;
panelFilters: TsPanel;
editFilterData: TsComboBox;
ProgressBar: TsGauge;
lblStatus: TsLabel;
procedure FormCreate(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure ClearEdits;
procedure IniLoadReportSimple;
procedure cbLocGeneralClick(Sender: TObject);
procedure GenerateReport;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure editFilterSelect(Sender: TObject);
private
{ Private declarations }
public
procedure CreateParams(var Params: TCreateParams); override;
{ Public declarations }
end;
var
FormReportSimple: TFormReportSimple;
Q_GEN_SIMPLE_BREAK: Boolean = False;
implementation
uses Main, Editor, Report, Helpers;
{$R *.dfm}
procedure TFormReportSimple.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_Ex_AppWindow;
end;
procedure TFormReportSimple.FormCreate(Sender: TObject);
begin
IniLoadReportSimple;
end;
procedure TFormReportSimple.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Q_GEN_SIMPLE_BREAK := True;
end;
procedure TFormReportSimple.btnOKClick(Sender: TObject);
begin
GenerateReport;
end;
procedure TFormReportSimple.btnCancelClick(Sender: TObject);
begin
Q_GEN_SIMPLE_BREAK := True;
FormReportSimple.Close;
end;
procedure TFormReportSimple.ClearEdits;
begin
editFilter.ItemIndex := -1;
editFilterData.Clear;
panelFilters.Visible := True;
panelDates.Visible := False;
end;
procedure TFormReportSimple.IniLoadReportSimple;
begin
IniMain := TIniFile.Create(AppPath + 'office.ini');
cbLocGeneral.Checked := IniMain.ReadBool('reportsimple', 'cbLocGeneral', False);
cbLocWord.Checked := IniMain.ReadBool('reportsimple', 'cbLocWord', False);
if (not cbLocGeneral.Checked) and (not cbLocWord.Checked) then
cbLocWord.Checked := True;
IniMain.Free;
end;
procedure TFormReportSimple.cbLocGeneralClick(Sender: TObject);
begin
if not cbLocGeneral.Checked and not cbLocWord.Checked then
cbLocGeneral.Checked := True;
end;
procedure TFormReportSimple.editFilterSelect(Sender: TObject);
var
Q: TIBCQuery;
i, n: integer;
memo: TStringList;
Phones, Email, Web, tmp: string;
begin
editFilterData.Items.BeginUpdate;
editFilterData.Clear;
editDate1.Date := Now;
editDate2.Date := Now;
case editFilter.ItemIndex of
0 .. 10:
begin
panelFilters.Visible := True;
panelDates.Visible := False;
end;
11 .. 12:
begin
panelFilters.Visible := False;
panelDates.Visible := True;
end;
end;
Q := QueryCreate;
if editFilter.ItemIndex = 0 then
begin // ÐÓÁÐÈÊÈ
for i := 0 to Main.sgRubr_tmp.RowCount - 1 do
begin
editFilterData.AddItem(Main.sgRubr_tmp.Cells[0, i], Pointer(StrToInt(Main.sgRubr_tmp.Cells[1, i])));
end;
end
else if editFilter.ItemIndex = 1 then
begin // ÎÁËÀÑÒÈ
Q.Close;
Q.SQL.Text := 'select * from REGION';
Q.Open;
Q.FetchAll := True;
for i := 1 to Q.RecordCount do
begin
editFilterData.AddItem(Q.FieldValues['NAME'], Pointer(integer(Q.FieldValues['ID'])));
Q.Next;
end;
end
else if editFilter.ItemIndex = 2 then
begin // ÃÎÐÎÄÀ
Q.Close;
Q.SQL.Text := 'select * from CITY';
Q.Open;
Q.FetchAll := True;
for i := 1 to Q.RecordCount do
begin
editFilterData.AddItem(Q.FieldValues['NAME'], Pointer(integer(Q.FieldValues['ID'])));
Q.Next;
end;
end
else if editFilter.ItemIndex = 3 then
begin // ÑÒÐÀÍÛ
Q.Close;
Q.SQL.Text := 'select * from COUNTRY';
Q.Open;
Q.FetchAll := True;
for i := 1 to Q.RecordCount do
begin
editFilterData.AddItem(Q.FieldValues['NAME'], Pointer(integer(Q.FieldValues['ID'])));
Q.Next;
end;
end
else if editFilter.ItemIndex = 4 then
begin // ÊÓÐÀÒÎÐÛ
for i := 0 to Main.sgCurator_tmp.RowCount - 1 do
begin
editFilterData.AddItem(Main.sgCurator_tmp.Cells[0, i], Pointer(StrToInt(Main.sgCurator_tmp.Cells[1, i])));
end;
end
else if editFilter.ItemIndex = 5 then
begin // ÒÈÏÛ
for i := 0 to Main.sgFirmType_tmp.RowCount - 1 do
begin
editFilterData.AddItem(Main.sgFirmType_tmp.Cells[0, i], Pointer(StrToInt(Main.sgFirmType_tmp.Cells[1, i])));
end;
end
else if editFilter.ItemIndex = 6 then
begin // ÀÊÒÈÂÍÎÑÒÜ
editFilterData.AddItem('Íåò', Pointer(0));
editFilterData.AddItem('Äà', Pointer(1));
end
else if editFilter.ItemIndex = 7 then
begin // ÀÊÒÓÀËÜÍÎÑÒÜ
editFilterData.AddItem('Íåò', Pointer(0));
editFilterData.AddItem('Äà', Pointer(1));
end
else if editFilter.ItemIndex = 8 then
begin // ÒÅËÅÔÎÍÛ
Q.Close;
Q.SQL.Text := 'select PHONES from BASE';
Q.Open;
Q.FetchAll := True;
memo := TStringList.Create;
for i := 1 to Q.RecordCount do
begin
Phones := Q.Fields[0].AsString;
while pos('$', Phones) > 0 do
begin
memo.Clear;
tmp := copy(Phones, 0, pos('$', Phones));
delete(Phones, 1, length(tmp));
tmp := copy(Phones, 0, pos('$', Phones));
delete(Phones, 1, length(tmp));
delete(tmp, 1, 1);
delete(tmp, length(tmp), 1);
if trim(tmp) = '' then
Continue;
memo.Text := tmp;
for n := 0 to memo.Count - 1 do
begin
tmp := memo[n];
if pos(')', tmp) > 0 then
delete(tmp, 1, pos(')', tmp));
tmp := trim(tmp);
editFilterData.AddItem(tmp, Pointer(0));
end;
end;
Q.Next;
end;
memo.Free;
end
else if editFilter.ItemIndex = 9 then
begin // ÌÅÉË
Q.Close;
Q.SQL.Text := 'select EMAIL from BASE';
Q.Open;
Q.FetchAll := True;
for i := 1 to Q.RecordCount do
begin
Email := Q.Fields[0].AsString;
if length(trim(Email)) > 0 then
begin
if Email[length(Email)] <> ',' then
Email := Email + ',';
while pos(',', Email) > 0 do
begin
tmp := copy(Email, 0, pos(',', Email));
delete(Email, 1, length(tmp));
tmp := trim(tmp);
delete(tmp, length(tmp), 1);
editFilterData.AddItem(tmp, Pointer(0));
end;
end;
Q.Next;
end;
end
else if editFilter.ItemIndex = 10 then
begin // ÑÀÉÒ
Q.Close;
Q.SQL.Text := 'select WEB from BASE';
Q.Open;
Q.FetchAll := True;
for i := 1 to Q.RecordCount do
begin
Web := Q.Fields[0].AsString;
if length(trim(Web)) > 0 then
begin
if Web[length(Web)] <> ',' then
Web := Web + ',';
while pos(',', Web) > 0 do
begin
tmp := copy(Web, 0, pos(',', Web));
delete(Web, 1, length(tmp));
tmp := trim(tmp);
delete(tmp, length(tmp), 1);
editFilterData.AddItem(tmp, Pointer(0));
end;
end;
Q.Next;
end;
end
else if editFilter.ItemIndex = 11 then
begin
lblDate.Caption := 'Äàòà äîáàâëåíèÿ (ïåðèîä):'
end
else if editFilter.ItemIndex = 12 then
begin
lblDate.Caption := 'Äàòà èçìåíåíèÿ (ïåðèîä):'
end;
Q.Close;
Q.Free;
FormMain.IBDatabase1.Close;
editFilterData.Items.EndUpdate;
if editFilterData.Items.Count > 0 then
editFilterData.ItemIndex := 0;
if editFilter.ItemIndex in [0 .. 10] then
begin
editFilterData.SetFocus;
editFilterData.DroppedDown := True;
end;
end;
procedure TFormReportSimple.GenerateReport;
var
i, RE_TextLength, index: integer;
Q_GEN: TIBCQuery;
REQ, param, d1, d2, ID_tmp, str1, str2, finalStr: string;
RE: TsRichEdit;
WordApp: OleVariant;
t1, t2: TDateTime;
TmpFilesCount: integer;
procedure AddLine(AText: string; AColor: TColor; AFontSize: integer; AFontName: TFontName; AFontStyle: TFontStyles);
begin
RE_TextLength := RE_TextLength + length(AText) + 2;
RE.SelStart := RE_TextLength - length(AText) - 2;
RE.SelAttributes.Color := AColor;
RE.SelAttributes.Size := AFontSize;
RE.SelAttributes.Name := AFontName;
RE.SelAttributes.Style := AFontStyle;
RE.Lines.Add(AText);
end;
procedure FormatAdres(AAdres, APhones: string; ID_Lang: integer = 0);
var
list, list2: TStringList;
Phones, tmp, adres, country_str, region_str, city_str, ofType: string;
x: integer;
begin
list := TStringList.Create;
list.Text := AAdres;
Phones := APhones;
for x := 0 to list.Count - 1 do
begin
// list2[0] = CBAdres; list2[1] = NO; list2[2] = OfficeType; list2[3] = ZIP;
// list2[4] = Street; list2[5] = Country; list2[6] = Region; list2[7] = City;
list2 := FormEditor.ParseAdresFieldToEntriesList(list[x]);
tmp := copy(Phones, 0, pos('$', Phones));
delete(Phones, 1, length(tmp));
tmp := copy(Phones, 0, pos('$', Phones));
delete(Phones, 1, length(tmp));
delete(tmp, 1, 1);
delete(tmp, length(tmp), 1);
tmp := StringReplace(tmp, '(', '', [rfReplaceAll]);
tmp := StringReplace(tmp, ')', '', [rfReplaceAll]);
// â TMP ñåé÷àñ õðàíÿòñÿ âñå òåëåôîíû äëÿ àäðåñà list[x] â ôîðìàòå Ìåìî
if list2[0] = '1' then
begin
ofType := list2[2];
country_str := list2[5];
region_str := list2[6];
city_str := list2[7];
adres := EmptyStr;
if list2[3] <> EmptyStr then
adres := list2[3] + ', '; // ZIP
if region_str <> EmptyStr then
adres := adres + GetNameByID('REGION', region_str, ID_Lang) + ', '; // REGION
if city_str <> EmptyStr then
adres := adres + GetNameByID('CITY', city_str, ID_Lang) + ','; // CITY
if Trim(adres) <> EmptyStr then
AddLine(adres, clWindowText, 10, 'Times New Roman', []);
if list2[4] <> EmptyStr then
AddLine(list2[4], clWindowText, 10, 'Times New Roman', []);
if Trim(tmp) <> EmptyStr then
AddLine(tmp, clWindowText, 10, 'Times New Roman', [fsItalic]);
end;
list2.Free;
end; // for x := 0 to list.Count - 1 do
list.Free;
end;
function FormatNapr(Field, Value: string): string;
var
str, tmp: string;
begin
Result := '';
if length(Value) = 0 then
exit;
str := Value;
while pos('$', str) > 0 do
begin
tmp := copy(str, 0, pos('$', str));
delete(str, 1, length(tmp));
delete(tmp, 1, 1);
delete(tmp, length(tmp), 1);
if AnsiLowerCase(Field) = 'napr' then
if Main.sgNapr_tmp.FindText(1, tmp, [soCaseInsensitive, soExactMatch]) then
Result := Result + #13 + Main.sgNapr_tmp.Cells[0, Main.sgNapr_tmp.SelectedRow];
if length(Result) > 0 then
if Result[1] = #13 then
delete(Result, 1, 1);
end;
end;
function FormatEMailWeb(Value: string): string;
var
str, tmp: string;
begin
Result := '';
if length(Value) = 0 then
exit;
str := Value;
if str[length(str)] <> ',' then
str := str + ',';
while pos(',', str) > 0 do
begin
tmp := copy(str, 0, pos(',', str));
delete(str, 1, length(tmp));
tmp := trim(tmp);
delete(tmp, length(tmp), 1);
Result := Result + #13 + tmp;
if length(Result) > 0 then
if Result[1] = #13 then
delete(Result, 1, 1);
end;
end;
procedure GetRequest(var REQ, param: string);
var
ID: string;
index: integer;
begin
REQ := '';
param := '';
index := editFilterData.Items.IndexOf(trim(editFilterData.Text));
if index <> -1 then
ID := IntToStr(integer(editFilterData.Items.Objects[index]))
else
ID := '-1';
if editFilter.ItemIndex = 0 then
begin // ÐÓÁÐÈÊÀ
REQ := 'select * from BASE where RUBR like :param and ACTIVITY = 1 order by lower(NAME)';
param := '%#' + ID + '$%';
end
else if editFilter.ItemIndex = 1 then
begin // ÎÁËÀÑÒÜ
REQ := 'select * from BASE where ADRES like :param order by lower(NAME)';
param := '%#*' + ID + '$%';
end
else if editFilter.ItemIndex = 2 then
begin // ÃÎÐÎÄ
REQ := 'select * from BASE where ADRES like :param order by lower(NAME)';
param := '%#^' + ID + '$%';
end
else if editFilter.ItemIndex = 3 then
begin // ÑÒÐÀÍÀ
REQ := 'select * from BASE where ADRES like :param order by lower(NAME)';
param := '%#&' + ID + '$%';
end
else if editFilter.ItemIndex = 4 then
begin // ÊÓÐÀÒÎÐ
REQ := 'select * from BASE where CURATOR like :param order by lower(NAME)';
param := '%#' + ID + '$%';
end
else if editFilter.ItemIndex = 5 then
begin // ÒÈÏ
REQ := 'select * from BASE where FIRMTYPE like :param order by lower(NAME)';
param := '%#' + ID + '$%';
end
else if editFilter.ItemIndex = 6 then
begin // ÀÊÒÈÂÍÎÑÒÜ
REQ := 'select * from BASE where ACTIVITY like :param order by lower(NAME)';
if AnsiLowerCase(trim(editFilterData.Text)) = 'äà' then
ID := '1'
else if AnsiLowerCase(trim(editFilterData.Text)) = 'íåò' then
ID := '0'
else
ID := '-2';
param := ID;
end
else if editFilter.ItemIndex = 7 then
begin // ÀÊÒÓÀËÜÍÎÑÒÜ
REQ := 'select * from BASE where RELEVANCE like :param order by lower(NAME)';
if AnsiLowerCase(trim(editFilterData.Text)) = 'äà' then
ID := '1'
else if AnsiLowerCase(trim(editFilterData.Text)) = 'íåò' then
ID := '0'
else
ID := '-2';
param := ID;
end
else if editFilter.ItemIndex = 8 then
begin // ÒÅËÅÔÎÍ
REQ := 'select * from BASE where PHONES like :param order by lower(NAME)';
param := '%' + AnsiLowerCase(trim(editFilterData.Text)) + '%';
end
else if editFilter.ItemIndex = 9 then
begin // ÌÅÉË
REQ := 'select * from BASE where lower(EMAIL) like :param order by lower(NAME)';
param := '%' + AnsiLowerCase(trim(editFilterData.Text)) + '%';
end
else if editFilter.ItemIndex = 10 then
begin // ÑÀÉÒ
REQ := 'select * from BASE where lower(WEB) like :param order by lower(NAME)';
param := '%' + AnsiLowerCase(trim(editFilterData.Text)) + '%';
end
else if editFilter.ItemIndex = 11 then
begin // ÄÀÒÀ ÄÎÁÀÂËÅÍÈß
d1 := '''' + editDate1.Text + '''';
d2 := '''' + editDate2.Text + '''';
REQ := 'select * from BASE where (DATE_ADDED BETWEEN DATE ' + d1 + ' AND DATE ' + d2 + ') order by lower(NAME)';
end
else if editFilter.ItemIndex = 12 then
begin // ÄÀÒÀ ÈÇÌÅÍÅÍÈß
d1 := '''' + editDate1.Text + '''';
d2 := '''' + editDate2.Text + '''';
REQ := 'select * from BASE where (DATE_EDITED BETWEEN DATE ' + d1 + ' AND DATE ' + d2 + ') order by lower(NAME)';
end;
end;
begin
if (editFilter.ItemIndex = -1) or ((editFilter.ItemIndex in [0 .. 10]) and (trim(editFilterData.Text) = '')) then
begin
MessageBox(handle, 'Óêàæèòå äàííûå äëÿ ãåíåðàöèè îò÷åòà', 'Ïðåäóïðåæäåíèå', MB_OK or MB_ICONWARNING);
exit;
end;
index := editFilterData.Items.IndexOf(trim(editFilterData.Text));
Q_GEN := QueryCreate;
RE := TsRichEdit.Create(FormReportSimple);
RE.Visible := False;
RE.Parent := FormReportSimple;
RE.Clear;
try
Q_GEN.Close;
Q_GEN.SQL.Text := ':param'; // tmp
GetRequest(REQ, param);
if length(REQ) > 0 then
begin
Q_GEN.ParamByName('param').AsString := param;
end;
if REQ = '' then
begin
MessageBox(handle, 'Ïî Âàøåìó çàïðîñó íå áûëî íàéäåíî íè îäíîé çàïèñè', 'Èíôîðìàöèÿ', MB_OK or MB_ICONINFORMATION);
RE.Free;
Q_GEN.Close;
Q_GEN.Free;
exit;
end;
WriteLog('TFormReportSimple.GenerateReport: ñîçäàíèå ïðîñòîãî îò÷åòà');
Q_GEN.SQL.Text := REQ;
Q_GEN.Open;
Q_GEN.FetchAll := True;
if Q_GEN.RecordCount = 0 then
begin
MessageBox(handle, 'Ïî Âàøåìó çàïðîñó íå áûëî íàéäåíî íè îäíîé çàïèñè', 'Èíôîðìàöèÿ', MB_OK or MB_ICONINFORMATION);
RE.Free;
Q_GEN.Close;
Q_GEN.Free;
exit;
end;
btnOK.Enabled := False;
editFilter.Enabled := False;
panelFilters.Enabled := False;
panelDates.Enabled := False;
cbLocGeneral.Enabled := False;
cbLocWord.Enabled := False;
FormMain.DisableAllForms('FormReportSimple');
RE.Lines.BeginUpdate;
FormMain.SGGeneral.BeginUpdate;
if cbLocGeneral.Checked then
FormMain.SGGeneral.ClearRows;
lblStatus.Caption := 'Ïîñòðîåíèå îò÷åòà...';
lblStatus.Visible := True;
ProgressBar.MinValue := 0;
ProgressBar.MaxValue := Q_GEN.RecordCount;
ProgressBar.Visible := True;
t1 := Now;
if cbLocWord.Checked then
begin
AddLine('Íàéäåíî çàïèñåé: ' + IntToStr(Q_GEN.RecordCount), clWindowText, 10, 'Times New Roman', []);
AddLine('Óñëîâèÿ âûáîðà:', clWindowText, 10, 'Times New Roman', []);
case editFilter.ItemIndex of
0 .. 10:
AddLine(editFilter.Text + ' = ' + trim(editFilterData.Text), clWindowText, 10, 'Times New Roman', []);
11 .. 12:
AddLine(editFilter.Text + ' = ' + editDate1.Text + ' - ' + editDate2.Text, clWindowText, 10, 'Times New Roman', []);
end;
AddLine('', clWindowText, 10, 'Times New Roman', []);
end;
TmpFilesCount := 0;
for i := 1 to Q_GEN.RecordCount do
begin
if Q_GEN_SIMPLE_BREAK then
Break;
ProgressBar.Progress := i;
if RE.Lines.Count >= 10000 then
begin
Inc(TmpFilesCount, 1);
RE.Lines.SaveToFile(AppPath + '\report_' + IntToStr(TmpFilesCount) + '.tmp');
RE.Clear;
end;
if cbLocGeneral.Checked then
begin
FormMain.SGAddRow(FormMain.SGGeneral, Q_GEN.FieldByName('ACTIVITY').AsInteger, Q_GEN.FieldByName('RELEVANCE').AsInteger,
Q_GEN.FieldValues['NAME'], Q_GEN.FieldValues['CURATOR'], Q_GEN.FieldValues['DATE_ADDED'], Q_GEN.FieldValues['DATE_EDITED'],
Q_GEN.FieldValues['WEB'], Q_GEN.FieldValues['EMAIL'], Q_GEN.FieldValues['FIRMTYPE'], Q_GEN.FieldValues['ID'],
Q_GEN.FieldValues['FIO'], Q_GEN.FieldValues['RUBR']);
end;
if cbLocWord.Checked then
begin
AddLine(Q_GEN.FieldValues['NAME'], clWindowText, 12, 'Times New Roman', [fsBold]);
FormatAdres(Q_GEN.FieldValues['ADRES'], Q_GEN.FieldValues['PHONES'], Q_GEN.FieldValues['ID_LANG']);
if trim(Q_GEN.FieldValues['EMAIL']) <> '' then
begin
AddLine(FormatEMailWeb(Q_GEN.FieldValues['EMAIL']), clWindowText, 10, 'Times New Roman', [fsUnderline]);
end;
if trim(Q_GEN.FieldValues['WEB']) <> '' then
begin
AddLine(FormatEMailWeb(Q_GEN.FieldValues['WEB']), clWindowText, 10, 'Times New Roman', []);
end;
if editFilter.ItemIndex = 0 then
begin
// Îòîáðàæàåì íàïðàâëåíèÿ òîëüêî çàêðåïëåííûå çà ýòîé ðóáðèêîé (RELATIONS)
if index <> -1 then
ID_tmp := IntToStr(integer(editFilterData.Items.Objects[index]))
else
ID_tmp := '-1';
str1 := Q_GEN.FieldValues['RELATIONS'];
if pos('#' + ID_tmp + '=', str1) > 0 then
begin
delete(str1, 1, pos('#' + ID_tmp + '=', str1));
delete(str1, 1, pos('=', str1));
delete(str1, pos('$', str1), length(str1));
finalStr := '';
while pos(')', str1) > 0 do
begin
str2 := copy(str1, 0, pos(')', str1));
delete(str1, 1, length(str2));
delete(str2, 1, 1);
delete(str2, length(str2), 1);
finalStr := finalStr + '#' + str2 + '$';
end;
AddLine(FormatNapr('NAPR', finalStr), clWindowText, 10, 'Times New Roman', [fsItalic]);
end;
end
else { // Îòîáðàæàåì âñå íàïðàâëåíèÿ }
if trim(Q_GEN.FieldValues['NAPRAVLENIE']) <> '' then
begin
AddLine(FormatNapr('NAPR', Q_GEN.FieldValues['NAPRAVLENIE']), clWindowText, 10, 'Times New Roman', [fsItalic]);
end;
AddLine('', clWindowText, 10, 'Times New Roman', []);
end;
Q_GEN.Next;
Application.ProcessMessages;
end; // for i := 1 to Q_GEN.RecordCount
t2 := Now;
FormMain.sStatusBar1.Panels[2].Text := 'Îò÷åò ñîçäàí çà ' + IntToStr(SecondsBetween(t1, t2)) + ' ñåê';
RE.Lines.EndUpdate;
FormMain.SGGeneral.EndUpdate;
if (length(RE.Text) > 0) and (not Q_GEN_SIMPLE_BREAK) then
begin
try
WordApp := GetActiveOleObject('Word.Application');
WordApp.Documents.Close(0);
WordApp.Quit;
except
end;
if TmpFilesCount > 0 then
begin
// ñîõðàíÿåì ïîñë ÷àñòü îò÷åòà ïîòîìó-÷òî áûëî ðàçäåëåíèå è ôîðìàòèðóåì
Inc(TmpFilesCount, 1);
RE.Lines.SaveToFile(AppPath + '\report_' + IntToStr(TmpFilesCount) + '.tmp');
FormReport.FormatReport(TmpFilesCount, RE, ProgressBar, lblStatus);
end;
RE.Lines.SaveToFile(AppPath + '\tmp.rtf');
WordApp := CreateOLEObject('Word.Application');
WordApp.Documents.Add(AppPath + '\tmp.rtf');
WordApp.Visible := True;
end;
if cbLocGeneral.Checked then
FormMain.sPageControl1.ActivePageIndex := 0;
except
on E: Exception do
begin
WriteLog('TFormReportSimple.GenerateReport' + #13 + 'Ïðîèçîøåë ñáîé ïðè ãåíåðàöèè îò÷åòà' + #13 + E.Message);
MessageBox(handle, PChar('Ïðîèçîøåë ñáîé ïðè ãåíåðàöèè îò÷åòà' + #13 + E.Message), 'Îøèáêà', MB_OK or MB_ICONERROR);
end;
end;
FormReport.DeleteTempReports;
lblStatus.Visible := False;
ProgressBar.Visible := False;
btnOK.Enabled := True;
editFilter.Enabled := True;
panelFilters.Enabled := True;
panelDates.Enabled := True;
cbLocGeneral.Enabled := True;
cbLocWord.Enabled := True;
FormMain.EnableAllForms('');
RE.Free;
Q_GEN.Close;
Q_GEN.Free;
FormMain.IBDatabase1.Close;
FormReportSimple.Close;
WriteLog('TFormReportSimple.GenerateReport: îò÷åò ñîçäàí óñïåøíî');
end;
end.