예제 #1
0
double CurrDisplay::convert(const int from, const int to, const double amount, const QDate& date)
{
    if (from == to)
        return amount;

    XSqlQuery convq;
    convq.prepare("SELECT currToCurr(:from, :to, :amount, :date) AS result;");
    convq.bindValue(":from",   from);
    convq.bindValue(":to",     to);
    convq.bindValue(":amount", amount);
    convq.bindValue(":date",   date);
    convq.exec();
    if (convq.first())
        return convq.value("result").toDouble();
    else if (convq.lastError().type() != QSqlError::NoError)
    {
        if (convq.lastError().databaseText().contains("No exchange rate"))
            sNoConversionRate(0, from, date, "convert");
        else
            QMessageBox::critical(0, tr("A System Error occurred at %1::%2.")
                                  .arg(__FILE__)
                                  .arg(__LINE__),
                                  convq.lastError().databaseText());
    }
    return 0.0;
}
예제 #2
0
void CurrDisplay::sValueLocalChanged(double newValue)
{
    if (_mapper->model() &&
            _mapper->model()->data(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this))).toDouble() != newValue)
        _mapper->model()->setData(_mapper->model()->index(_mapper->currentIndex(),_mapper->mappedSection(this)), newValue);

    double oldBase = _valueBase;
    if (ABS(newValue) < EPSILON(_localScale) || _effective.isNull())
    {
        if (ABS(_valueBase) >= EPSILON(_baseScale))
        {
            _valueBase = 0;
            _baseKnown = true;
        }
    }
    else
    {
        XSqlQuery convertVal;
        convertVal.prepare("SELECT currToBase(:curr_id, :value, :date) "
                           " AS baseValue;");
        convertVal.bindValue(":curr_id", id());
        convertVal.bindValue(":value", newValue);
        convertVal.bindValue(":date", _effective);
        convertVal.exec();
        if (convertVal.first())
        {
            _valueBase = convertVal.value("baseValue").toDouble();
            sZeroErrorCount(id(), effective());
            _baseKnown = true;
        }
        else if (convertVal.lastError().type() != QSqlError::NoError)
        {
            if (convertVal.lastError().databaseText().contains("No exchange rate"))
            {
                emit noConversionRate();
                sNoConversionRate(this, id(), effective(), "sValueLocalChanged");
            }
            else
                QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                                      .arg(__FILE__)
                                      .arg(__LINE__),
                                      convertVal.lastError().databaseText());
            _baseKnown = false;
        }
    }

    if (ABS(oldBase - _valueBase) > EPSILON(_baseScale))
        emit valueBaseChanged(_valueBase);
}
예제 #3
0
void CurrDisplay::sValueBaseChanged(double newValue)
{
    double oldLocal = _valueLocal;
    if (ABS(newValue) < EPSILON(_baseScale) || _effective.isNull())
    {
        if (ABS(_valueLocal) >= EPSILON(_localScale))
        {
            _valueLocal = 0;
            _valueLocalWidget->clear();
        }
    }
    else
    {
        XSqlQuery convertVal;
        convertVal.prepare("SELECT currToLocal(:curr_id, :value, :date) "
                           " AS localValue;");
        convertVal.bindValue(":curr_id", id());
        convertVal.bindValue(":value", newValue);
        convertVal.bindValue(":date", _effective);
        convertVal.exec();
        if (convertVal.first())
        {
            _valueLocal = convertVal.value("localValue").toDouble();
            sZeroErrorCount(id(), effective());
            _localKnown = true;
        }
        else if (convertVal.lastError().type() != QSqlError::NoError)
        {
            if (convertVal.lastError().databaseText().contains("No exchange rate"))
            {
                emit noConversionRate();
                sNoConversionRate(this, id(), effective(), "sValueBaseChanged");
            }
            else
                QMessageBox::critical(this, tr("A System Error occurred at %1::%2.")
                                      .arg(__FILE__)
                                      .arg(__LINE__),
                                      convertVal.lastError().databaseText());
            _localKnown = false;
        }
    }
    if (ABS(oldLocal - _valueLocal) > EPSILON(_localScale))
        emit valueLocalChanged(_valueLocal);
}
예제 #4
0
static void sNoBase(QWidget* parent, const char* caller)
{
    sNoConversionRate(parent, -1, nullDate, caller);
}
예제 #5
0
static void sNoBase(QWidget* parent)
{
    sNoConversionRate(parent, -1, nullDate);
}