Beispiel #1
0
void batchItem::sSave()
{
  if (_mode == cReschedule)
  {
    RecurrenceWidget::RecurrenceChangePolicy cp = _recur->getChangePolicy();
    if (cp == RecurrenceWidget::NoPolicy)
      return;

    if (_recur->isRecurring() && _recur->parentId() < 0)
      _recur->setParent(_batchid, _recur->parentType());

    XSqlQuery beginq("BEGIN;");
    XSqlQuery rollbackq;
    rollbackq.prepare("ROLLBACK;");

    XSqlQuery schedq(_db);
    schedq.prepare("UPDATE xtbatch.batch"
                   "   SET batch_scheduled=CAST(:date AS DATE) + CAST(:time AS TIME),"
                   "       batch_started=NULL, batch_completed=NULL,"
                   "       batch_recurring_batch_id=:parentid"
                   " WHERE (batch_id=:batchid);");
    schedq.bindValue(":date",     _scheduledDate->date());
    schedq.bindValue(":time",     _scheduledTime->time());
    if (_recur->isRecurring())
      schedq.bindValue(":parentid", _recur->parentId());
    schedq.bindValue(":batchid",  _batchid);
    schedq.exec();
    if (schedq.lastError().type() != QSqlError::NoError)
    {
      rollbackq.exec();
      QMessageBox::critical(this,
                            tr("Error rescheduling job at %1::%2")
                              .arg(__FILE__, __LINE__),
                              schedq.lastError().databaseText());
      return;
    }

    QString errmsg;
    if (! _recur->save(true, cp, &errmsg))
    {
      rollbackq.exec();
      QMessageBox::critical(this, "Error Saving Recurrence", errmsg);
      return;
    }

    XSqlQuery commitq("COMMIT;");
  }
  done(_batchid);
}
Beispiel #2
0
void batchItem::sSave()
{
  QString interval;

  if (_reschedule->isChecked())
  {
    switch (_interval->currentIndex())
    {
      case 0:
        interval = "D";
        break;

      case 1:
        interval = "W";
        break;

      case 2:
        interval = "M";
        break;
    }
  }

  if (interval.length() == 0)
    interval = "N";

  if (_mode == cReschedule)
  {
    XSqlQuery schedq(_db);
    schedq.prepare("SELECT rescheduleBatchItem(:batchid,"
                   "                           CAST(:date AS DATE) +"
                   "                           CAST(:time AS TIME),"
                   "                           :interval) AS result;");
    schedq.bindValue(":batchid",  _batchid);
    schedq.bindValue(":date",     _scheduledDate->date());
    schedq.bindValue(":time",     _scheduledTime->time());
    schedq.bindValue(":interval", interval); 
    schedq.exec();
    if (schedq.first())
    {
      int result = schedq.value("result").toInt();
      if (result < 0)
      {
        QMessageBox::critical(this,
                              tr("Error Rescheduling Batch Item at %1::%2")
                                .arg(__FILE__, __LINE__),
                              storedProcErrorLookup("rescheduleBatchItem",
                                                    result));
        return;
      }
    }
    else if (schedq.lastError().type() != QSqlError::NoError)
    {
      QMessageBox::critical(this,
                            tr("Error Rescheduling Batch Item at %1::%2")
                              .arg(__FILE__, __LINE__),
                              schedq.lastError().databaseText());
      return;
    }
  }
  done(_batchid);
}