forked from tryphon/rivendell2-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_deltaflex.cpp
185 lines (171 loc) · 4.98 KB
/
export_deltaflex.cpp
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
// export_deltaflex.cpp
//
// Export a Rivendell Report to CBSI DeltaFlex
//
// (C) Copyright 2002-2005 Fred Gleason <[email protected]>
//
// $Id: export_deltaflex.cpp,v 1.12.6.1 2013/02/08 21:41:44 cvs Exp $
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//
// CBSI Settings
//
#define CBSI_DELTAFLEX_VERSION 201
#define CBSI_STATION_ID 1
#define CBSI_SCHED_FLAG "C"
#include <stdio.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <rddb.h>
#include <rddatedecode.h>
#include <rdreport.h>
bool RDReport::ExportDeltaflex(const QDate &startdate,const QDate &enddate,
const QString &mixtable)
{
QString sql;
RDSqlQuery *q;
FILE *f;
QString air_fmt;
#ifdef WIN32
QString filename=RDDateDecode(exportPath(RDReport::Windows),startdate);
#else
QString filename=RDDateDecode(exportPath(RDReport::Linux),startdate);
#endif
QFile file(filename);
if((f=fopen((const char *)filename,"wb"))==NULL) {
report_error_code=RDReport::ErrorCantOpen;
return false;
}
if(useLeadingZeros()) {
air_fmt=QString().sprintf("%%0%uu",cartDigits());
}
else {
air_fmt="%u";
}
sql=QString().sprintf("select `%s_SRT`.LENGTH,`%s_SRT`.CART_NUMBER,\
`%s_SRT`.EVENT_DATETIME,`%s_SRT`.EVENT_TYPE,\
`%s_SRT`.EXT_START_TIME,`%s_SRT`.EXT_LENGTH,\
`%s_SRT`.EXT_DATA,`%s_SRT`.EXT_EVENT_ID,\
`%s_SRT`.EXT_ANNC_TYPE,`%s_SRT`.TITLE,\
`%s_SRT`.EXT_CART_NAME from `%s_SRT` \
left join CART on\
`%s_SRT`.CART_NUMBER=CART.NUMBER\
order by EVENT_DATETIME",
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable,
(const char *)mixtable);
q=new RDSqlQuery(sql);
//
// Write File Header
//
unsigned station_id=stationId().toUInt();
if(station_id>99) {
station_id=0;
}
fprintf(f,"Air Log for CBSI %03d|%s|%02u|%05d|%s|\x0d\x0a",
CBSI_DELTAFLEX_VERSION,
(const char *)startdate.toString("yy/MM/dd"),
station_id,
q->size(),
CBSI_SCHED_FLAG);
//
// Write Data Rows
//
QString cart_title;
QString play_length;
QString tfc_length;
QString tfc_time;
QString air_cartnum;
QString tfc_cartnum;
QString ext_data;
QString ext_annc_type;
while(q->next()) {
if(q->value(9).toString().length()>29) {
cart_title=q->value(9).toString().left(29);
}
else {
cart_title=q->value(9).toString();
}
if(q->value(8).toString().length()>3) {
ext_annc_type=q->value(8).toString().left(3);
}
else {
ext_annc_type=q->value(8).toString();
}
ext_data="";
if(q->value(6).toString().length()>0) {
if(q->value(6).toString().length()<=8) {
for(unsigned i=0;i<(8-q->value(6).toString().stripWhiteSpace().length());
i++) {
ext_data+="0";
}
ext_data+=q->value(6).toString().stripWhiteSpace();
}
else {
ext_data+=q->value(6).toString().stripWhiteSpace().left(8);
}
}
if(q->value(0).toUInt()<=999000) {
play_length=QString().sprintf("%03u",q->value(0).toUInt()/1000);
}
else {
play_length=QString("999");
}
if(q->value(5).toInt()<0) {
tfc_length="000";
}
else {
if(q->value(5).toInt()<=999000) {
tfc_length=QString().sprintf("%03d",q->value(5).toInt()/1000);
}
else {
tfc_length=QString("999");
}
}
if(!q->value(4).toTime().isNull()) {
tfc_time=q->value(4).toTime().toString("hhmm");
}
else {
tfc_time="";
}
air_cartnum=QString().sprintf(air_fmt,q->value(1).toUInt());
tfc_cartnum=q->value(10).toString();
fprintf(f,"%s|%4s|%-29s|%-12s|%-12s|%s|%s|%8s|%-3s| | |%4s|\x0d\x0a",
(const char *)q->value(2).toDateTime().toString("hhmm"),
(const char *)tfc_time,
(const char *)cart_title,
(const char *)air_cartnum,
(const char *)tfc_cartnum,
(const char *)play_length,
(const char *)tfc_length,
(const char *)ext_data,
(const char *)q->value(8).toString(),
(const char *)q->value(7).toString());
}
delete q;
fclose(f);
report_error_code=RDReport::ErrorOk;
return true;
}