コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: romson25/ScannerPC
void MainWindow::messageHandling        (MessageType type, QString what, QString who)
{
    if(logFile.isWritable())
    {
        QString time = date.currentDateTime().toString("HH:mm:ss");
        QString log = time + "\t" + (char)type + "\t" + who + "\t" + what + "\n";

        stream<<log;
    }
    else
    {
        showMessageOnStatusBar("Nie można otworzyć dziennika zdarzeń");
        return;
    }

    if(type == MessageType::criticalError || type == MessageType::warning)
        showMessageOnStatusBar(what);

}
コード例 #2
0
ファイル: app.cpp プロジェクト: rovan/qbalance
bool TApplication::open() {
    bool lResult = false;   // По умолчанию будем считать, что приложение открыть не удалось
    endDate = QDate::currentDate();
    beginDate = endDate.addDays(-31);
    if (gui->open())
    {  // Попытаемся открыть графический интерфейс
//        formLoader = new QUiLoader(gui);
//        formLoader->addPluginPath(applicationDirPath() + "/plugins");
//        formLoader->setWorkingDirectory(getFormsPath());

        messagesWindow = new MessageWindow();
        tcpServer = new TcpServer(config.localPort, this);
        driverFR = new DriverFR(this);

        if (driverFR->open(config.frDriverPort, config.frDriverBaudRate, config.frDriverTimeOut, config.frDriverPassword, config.remoteHost, config.remotePort))
        {
            driverFRisValid = true;
        }

        forever         // Будем бесконечно пытаться открыть базу, пока пользователь не откажется
        {
            int result = gui->openDB(); // Попытаемся открыть базу данных
            if (result == 0)
            {   // БД открыть удалось
                dictionaryList = new Dictionaries();
                topersList = new Topers();
                if (dictionaryList->open() && topersList->open())
                {
                    // Удалось открыть спосок справочников и типовых операций
                    db->getPeriod(beginDate, endDate);
                    gui->getMainWindow()->showPeriod();

                    // Загрузим константы
                    Dictionary* constDict = dictionaryList->getDictionary(db->getObjectName("константы"), true);
                    if (constDict != 0)
                    {
                        constDict->setPhotoEnabled(false);
                        constDict->query();
                    }

                    // Загрузим счета
                    Dictionary* accDict = dictionaryList->getDictionary(db->getObjectName("счета"), true);
                    if (accDict != 0)
                    {
                        accDict->setPhotoEnabled(false);
                    }

                    secDiff = QDateTime::currentDateTime().secsTo(db->getValue("SELECT now();", 0, 0).toDateTime());

                    if (driverFRisValid)
                        showMessageOnStatusBar("Найден фискальный регистратор.");
                    else
                        showMessageOnStatusBar("Фискальный регистратор не найден.");

                    lResult = true;     // Приложение удалось открыть
                    break;  // Выйдем из бесконечного цикла открытия БД
                }
            }
            else if (result == -2)
                {   // Произошла ошибка соединения с сервером
                if (gui->showMessage(QObject::trUtf8("Не удалось соединиться с базой данных (БД). Возможно БД отсутствует."),
                                     QObject::trUtf8("Попытаться создать новую БД?")) == QMessageBox::Yes)
                    // Попытаемся создать новую БД
                    db->createNewDBs(gui->getLastHostName(), gui->getLastDbName(), gui->getLastPort());
            }
            else if (result == -1)      // Пользователь нажал кнопку Отмена
                break;  // Выйдем из бесконечного цикла открытия БД
        }
    }