Esempio n. 1
0
SchedRulesList::SchedRulesList(QString clockname)
{
  QString sql;
  RDSqlQuery *q;
  RDSqlQuery *q1;

  sql=QString().sprintf("create table if not exists `%s_RULES` (\
      CODE varchar(10) not null primary key,\
      MAX_ROW int unsigned,\
      MIN_WAIT int unsigned,\
      NOT_AFTER varchar(10),\
      OR_AFTER varchar(10),\
      OR_AFTER_II varchar(10))",(const char*)clockname.replace(" ","_")); 

  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    printf("SQL: %s\n",(const char *)sql);
    printf("SQL Error: %s\n",(const char *)q->lastError().databaseText());
  }
  delete q;

  sql=QString().sprintf("select CODE,DESCRIPTION from SCHED_CODES order by `CODE` asc"); 

  q=new RDSqlQuery(sql);

  itemcounter=q->size();  
  sched_code = new QString[itemcounter];
  max_row = new int[itemcounter];
  min_wait = new int[itemcounter];
  not_after = new QString[itemcounter];
  or_after = new QString[itemcounter];
  or_after_II = new QString[itemcounter];
  description = new QString[itemcounter];
    
  for (int i=0; i<itemcounter; i++){
    q->next();
    sched_code[i] = q->value(0).toString();
    description[i] = q->value(1).toString();
    sql=QString().sprintf("select MAX_ROW,MIN_WAIT,NOT_AFTER,OR_AFTER,OR_AFTER_II from %s_RULES where CODE=\"%s\"",
	(const char *)clockname.replace(" ","_"),(const char *)sched_code[i]);
    q1=new RDSqlQuery(sql);
    if(q1->first())
      {
      max_row[i] = q1->value(0).toInt();
      min_wait[i] = q1->value(1).toInt();
      not_after[i] = q1->value(2).toString();
      or_after[i] = q1->value(3).toString();
      or_after_II[i] = q1->value(3).toString();
      }
    else
      {
      max_row[i] = 1;
      min_wait[i] = 0;
      not_after[i] = "";
      or_after[i] = "";
      or_after_II[i] = "";
      }
    delete q1;
    }
  delete q;
}
int RunLogOperation(int argc,char *argv[],const QString &svcname,
                    int start_offset,bool protect_existing,bool gen_log,
                    bool merge_mus,bool merge_tfc)
{
    QString sql;
    RDSqlQuery *q;
    QString report;
    QString unused_report;
    QString svcname_table=svcname;
    svcname_table.replace(" ","_");

    //
    // Some Basic Structures
    //
#ifndef WIN32
    rda->setUser(rda->station()->defaultName());
#endif  // WIN32
    RDSvc *svc=new RDSvc(svcname);
    if(!svc->exists()) {
        fprintf(stderr,"rdlogmanager: no such service\n");
        return 256;
    }
    QDate start_date=QDate::currentDate().addDays(1+start_offset);
    QString logname=RDDateDecode(svc->nameTemplate(),start_date);
    RDLog *log=new RDLog(logname);

    //
    // Generate Log
    //
    if(gen_log) {
        if(protect_existing&&log->exists()) {
            fprintf(stderr,"log \"%s\" already exists\n",
                    (const char *)log->name().utf8());
            exit(256);
        }
        log->removeTracks(rda->station(),rda->user(),rda->config());
        srand(QTime::currentTime().msec());
        sql=RDCreateStackTableSql(svcname_table);
        q=new RDSqlQuery(sql);
        if(!q->isActive()) {
            fprintf(stderr,"SQL: %s\n",(const char *)sql);
            fprintf(stderr,"SQL Error: %s\n",
                    (const char *)q->lastError().databaseText());
        }
        delete q;
        if(!svc->generateLog(start_date,
                             RDDateDecode(svc->nameTemplate(),start_date),
                             RDDateDecode(svc->nameTemplate(),start_date.addDays(1)),
                             &unused_report)) {
            fprintf(stderr,"rdlogmanager: unable to generate log\n");
            return 256;
        }
        log->updateTracks();

        //
        // Generate Exception Report
        //
        RDLogEvent *event=
            new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
        event->load();
        if((event->validate(&report,start_date)!=0)||
                (!unused_report.isEmpty())) {
            printf("%s\n\n%s",(const char*)report,(const char*)unused_report);
        }
        delete event;
    }

    //
    // Merge Music
    //
    if(merge_mus) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceMusic)==RDLog::LinkDone)) {
            fprintf(stderr,"rdlogmanager: music for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        log->removeTracks(rda->station(),rda->user(),rda->config());
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        svc->clearLogLinks(RDSvc::Music,start_date,logname);
        if(svc->linkLog(RDSvc::Music,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open music schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Music,start_date));
            exit(256);
        }
    }

    //
    // Merge Traffic
    //
    if(merge_tfc) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceTraffic)==RDLog::LinkDone)) {
            fprintf(stderr,
                    "rdlogmanager: traffic for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        if(svc->linkLog(RDSvc::Traffic,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open traffic schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Traffic,start_date));
        }
    }

    //
    // Clean Up
    //
    delete log;
    delete svc;
    return 0;
}
Esempio n. 3
0
void GenerateLog::createData()
{
  QString report;
  QString unused_report;
  QString str1;
  QString str2;
  unsigned tracks=0;

  //
  // Generate Log
  //
  RDSvc *svc=new RDSvc(gen_service_box->currentText(),this);
  QString logname=RDDateDecode(svc->nameTemplate(),gen_date_edit->date());
  RDLog *log=new RDLog(logname);
  if(log->exists()) {
    str1=QString(tr("The log for"));
    str2=QString(tr("already exists.  Recreating it\nwill remove any merged Music or Traffic events.\n\nRecreate?"));
    if(QMessageBox::question(this,tr("Log Exists"),
			     QString().sprintf("%s %s %s",(const char *)str1,
		 (const char *)gen_date_edit->date().toString("MM/dd/yyyy"),
					       (const char *)str2),
			     QMessageBox::Yes,QMessageBox::No)!=
       QMessageBox::Yes) {
      delete log;
      delete svc;
      return;
    }
    if((tracks=log->completedTracks())>0) {
      str1=QString(tr("This will also delete the"));
      str2=QString(tr("voice tracks associated with this log.\nContinue?"));
      if(QMessageBox::warning(this,tr("Tracks Exist"),
			      QString().sprintf("%s %u %s",
						(const char *)str1,
						tracks,
						(const char *)str2),
			      QMessageBox::Yes,QMessageBox::No)!=
	 QMessageBox::Yes) {
	delete log;
	delete svc;
	return;
      }
    }
  }
  log->removeTracks(rda->station(),rda->user(),rda->config());

  //
  // Scheduler
  //
  QString sql;
  RDSqlQuery *q;

  srand(QTime::currentTime().msec());
  sql=RDCreateStackTableSql(gen_service_box->currentText().replace(" ","_")); 

  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    fprintf(stderr,"SQL: %s\n",(const char *)sql);
    fprintf(stderr,"SQL Error: %s\n",
	    (const char *)q->lastError().databaseText());
    delete q;
  }
  delete q;

  connect(svc,SIGNAL(generationProgress(int)),
	  gen_progress_dialog,SLOT(setProgress(int)));
  svc->generateLog(gen_date_edit->date(),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date()),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date().
				addDays(1)),&unused_report);
  log->updateTracks();
  delete log;
  delete svc;

  //
  // Generate Exception Report
  //
  RDLogEvent *event=
    new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
  event->load();
  if((event->validate(&report,gen_date_edit->date())==0)&&
     unused_report.isEmpty()) {
    QMessageBox::information(this,tr("No Errors"),tr("No exceptions found."));
  }
  else {
    RDTextFile(report+"\n\n"+unused_report);
  }
  delete event;

  UpdateControls();
}