17 setAttribute ( Qt::WA_DeleteOnClose );
18 setWindowTitle( tr(
"Synchronize Reports with Database" ) );
20 setMinimumSize( 300, 160 );
24 QVBoxLayout*
main =
new QVBoxLayout(
this );
25 main->setContentsMargins( 2, 2, 2, 2 );
26 main->setSpacing ( 2 );
29 QGridLayout* top =
new QGridLayout;
41 QString name = ( invlev > 0 )
53 "<b>Note:</b> Proceeding may result in local reports<br/>"
54 "being replaced from the database.<ul>"
55 "<li><b>Cancel</b> to abort synchronizing from the DB.</li>"
56 "<li><b>Download</b> to proceed with DB synchronization.</li>"
57 "<li><b>New Only</b> to only download new DB records.</li></ul>" );
59 top->addWidget(
te_desc, row, 0, 4, 2 );
61 main->addLayout( top );
64 QHBoxLayout* buttons =
new QHBoxLayout;
69 connect( pb_cancel, SIGNAL( clicked() ), SLOT(
cancelled() ) );
70 connect( pb_accept, SIGNAL( clicked() ), SLOT(
accepted() ) );
71 connect( pb_newonly, SIGNAL( clicked() ), SLOT(
downnew() ) );
73 buttons->addWidget( pb_cancel );
74 buttons->addWidget( pb_accept );
75 buttons->addWidget( pb_newonly );
77 main->addLayout( buttons );
93 qDebug() <<
"CANCELED";
101 qDebug() <<
"DOWNLOAD";
112 qDebug() <<
"NEWONLY";
129 QMessageBox::information(
this,
130 tr(
"DB Connection Problem" ),
131 tr(
"There was an error connecting to the database:\n" )
137 "<b>Note:</b> Proceeding may result in local reports<br/>"
138 "being replaced from the database.<ul>"
139 "<li><b>Cancel</b> to abort synchronizing from the DB.</li>"
140 "<li><b>Download</b> to proceed with DB synchronization.</li>"
141 "<li><b>New Only</b> to only download new DB records.</li></ul>"
142 "<b>Downloading report records from the database...</b>" );
144 qApp->processEvents();
145 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
150 setWindowTitle( tr(
"Download Report Data from the Database" ) );
153 query <<
"count_reports" << invID;
154 int nreports = db.functionQuery( query );
155 qDebug() <<
"Reports count" << nreports;
156 desc = desc +
"<br/> ";
157 int nbdchr = desc.length();
158 desc = desc.left( nbdchr )
159 + tr(
"Total DB run reports is %1" ).arg( nreports );
161 qApp->processEvents();
165 QDir dirres( resdir );
166 QStringList resruns = dirres.entryList(
167 QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );
170 query <<
"get_report_desc" << invID;
177 QDir dirrpt( rptdir );
181 QString runid = db.value( 4 ).toString();
183 if ( resruns.contains( runid ) )
186 qDebug() <<
" report id" << db.value(0).toString() <<
"runID" << runid;
190 qDebug() <<
"Report descs count" << kreports;
192 desc = desc.left( nbdchr )
193 + tr(
"DB reports for local runIDs is %1" ).arg( kreports );
195 qApp->processEvents();
197 for (
int ii = 0; ii < kreports; ii++ )
199 QString runid = runids[ ii ];
200 QString rundir = rptdir + runid;
201 QString runresd = resdir + runid;
204 freport.
readDB( runid, &db );
206 int ntriples = freport.
triples.count();
207 qDebug() <<
" Report" << ii <<
"triples count" << ntriples <<
"runID" << runid;
211 if ( QDir( rundir ).exists() )
220 dirrpt.mkdir( runid );
226 for (
int jj = 0; jj < ntriples; jj++ )
229 int ndocs = tripl->
docs.count();
230 qDebug() <<
" Triple" << jj <<
"docs count" << ndocs;
232 desc = desc.left( nbdchr )
233 + tr(
"Run %1, Triple %2: comparing %3 documents...")
234 .arg( ii + 1 ).arg( jj + 1 ).arg( ndocs );
236 qApp->processEvents();
238 for (
int kk = 0; kk < ndocs; kk++ )
242 qDebug() <<
" Doc" << kk <<
"filename" << fname <<
"ID" << doc->
documentID;
243 QString fpath = rundir +
"/" + fname;
244 if ( fname.endsWith(
".csv" ) )
245 fpath = runresd +
"/" + fname;
247 QFile dfile( fpath );
249 if ( dfile.exists() )
260 int st = doc->
readDB( rundir, &db );
264 qDebug() <<
"ReportDoc read ERROR: status" << st << fpath;
273 QApplication::restoreOverrideCursor();
275 QMessageBox::information(
this,
276 tr(
"DB Reports Downloaded" ),
277 tr(
"Run IDs: %1 updated, %2 added.\n"
278 "Documents: %3 replaced, %4 added." )
280 qDebug() <<
"nrunrpl nrunadd ndocrpl ndocadd" <<
nrunrpl <<
nrunadd