-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcclreport.pas
115 lines (92 loc) · 3.39 KB
/
cclreport.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
unit CCLReport;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, EditBtn, StdCtrls,
ExtCtrls, lconvencoding;
type
{ TCCLReportForm }
TCCLReportForm = class(TForm)
ButExport: TButton;
ButCanc: TButton;
CCLDateStart: TDateEdit;
CCLDateEnd: TDateEdit;
LabRepEnd: TLabel;
LabRepStart: TLabel;
RadSummary: TRadioButton;
RadDetail: TRadioButton;
RadioGroup1: TRadioGroup;
procedure ButCancClick(Sender: TObject);
procedure ButExportClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
public
end;
var
CCLReportForm: TCCLReportForm;
implementation
uses
Control;
{$R *.lfm}
{ TCCLReportForm }
procedure TCCLReportForm.FormShow(Sender: TObject);
begin
CCLReportForm.Top := ControlForm.Top + 10;
CCLReportForm.Left := ControlForm.Left + 10;
end;
procedure TCCLReportForm.ButCancClick(Sender: TObject);
begin
CCLReportForm.Close;
end;
procedure TCCLReportForm.ButExportClick(Sender: TObject);
var
ReportFile: TextFile;
line : string;
begin
if CCLDateStart.Text = '' then
begin
ShowMessage('Please fill in the Report From date');
exit;
end;
if CCLDateEnd.Text = '' then
begin
ShowMessage('Please fill in the Report To date');
exit;
end;
ControlForm.SaveDialog1.Title := 'CCL Report Export';
ControlForm.SaveDialog1.DefaultExt:='.csv';
ControlForm.SaveDialog1.Filter := 'CSV Files|*.csv';
if ControlForm.SaveDialog1.Execute then
begin
AssignFile(ReportFile, ControlForm.SaveDialog1.FileName);
Rewrite(ReportFile);
if RadSummary.Checked then
begin
ControlForm.SQLMainQuery.SQL.Text:='SELECT cclname, cclcopy, COUNT(DISTINCT cclevent) AS usage FROM cclrecord WHERE ccldate >= julianday(:STARTDATE) AND ccldate <= julianday(:ENDDATE) GROUP BY songId';
writeln(ReportFile, '"First Line / Chorus","Copyright","Used Count"');
end
else
begin
ControlForm.SQLMainQuery.SQL.Text:='SELECT cclname, cclcopy, strftime("%d-%m-%Y",ccldate) AS eventdate, cclevent FROM cclrecord WHERE ccldate >= julianday(:STARTDATE) AND ccldate <= julianday(:ENDDATE) GROUP BY songId, date(ccldate), cclevent';
writeln(ReportFile, '"First Line / Chorus","Copyright","Date","Event"');
end;
ControlForm.SQLMainQuery.Params.ParamByName('STARTDATE').AsString := COPY(CCLDateStart.Text, 7,4) + '-' + COPY(CCLDateStart.Text, 4, 2) + '-' + COPY(CCLDateStart.Text, 1, 2);
ControlForm.SQLMainQuery.Params.ParamByName('ENDDATE').AsString := COPY(CCLDateEnd.Text, 7,4) + '-' + COPY(CCLDateEnd.Text, 4, 2) + '-' + COPY(CCLDateEnd.Text, 1, 2);
ControlForm.SQLMainQuery.Open;
while NOT ControlForm.SQLMainQuery.EOF do
begin
Line := '"' + ControlForm.SQLMainQuery.FieldByName('cclname').AsString + '","' + ControlForm.SQLMainQuery.FieldByName('cclcopy').AsString + '",';
if RadSummary.Checked then
Line := Line + ControlForm.SQLMainQuery.FieldByName('usage').AsString
else
Line := Line + '"' + ControlForm.SQLMainQuery.FieldByName('eventdate').AsString + '","' + ControlForm.SQLMainQuery.FieldByName('cclevent').AsString + '"';
Line := ConvertEncoding(Line, GuessEncoding(Line), EncodingUTF8);
writeln(ReportFile,Line);
ControlForm.SQLMainQuery.Next;
end;
ControlForm.SQLMainQuery.Close;
CloseFile(ReportFile);
CCLReportForm.Close;
end;
end;
end.