示例#1
0
void LoginDialog::ok()
{
	DBConn* conn = DBService::getInstance()->getConnection();
	if (!conn->isConnected())
	{
		QMessageBox::critical(NULL, "Ошибка БД", "Нет подключения к БД");
		reject();
	}

	QString sql =
			QString("SELECT count(*) FROM users WHERE user_name = \'%1\' AND password = \'%2\'")
			.arg(name->text(), passwd->text());
	QSqlQuery q = conn->executeQuery(sql);
	bool res = false;
	if (q.isActive() && q.next())
	{
		res = q.value(0).toInt() > 0;
	}

	if (res == false)
	{
		QMessageBox::warning(NULL, "Предупреждение", "Неверный пароль");
	}
	else
	{
		accept();
	}
}
void StatisticEmailSender::initSlot() const
{
	bool res = true;

	DBConn* conn = DBService::getInstance()->getConnection();
	if (!conn->isConnected())
	{
		qCritical() << Q_FUNC_INFO << "Нет соединения с БД";
		res = false;
	}


	QStringList message;

	if (res == true)
	{
		QString sql = "SELECT relname,n_live_tup"
					  " FROM pg_stat_user_tables"
					  " ORDER BY n_live_tup DESC";

		conn->beginTransaction();

		bool check = checkSend(conn);
		if (check == true)
		{
			QSqlQuery q = conn->executeQuery(sql);
			if (!q.isActive())
			{
				res = false;
				qCritical() << Q_FUNC_INFO << "Ошибка выполнения запроса статистики";
			}
			else
			{
				bool first = true;
				while (q.next())
				{
					if (first == true)
					{
						message.append("Статистика по записям в таблицах: ");
						first = false;
					}
					message.append(q.value(0).toString() + ": " + q.value(1).toString());
				}
			}

			res = updateHistory(conn);
		}

		conn->commit();
	}

	if ( (res == true) && !message.isEmpty())
	{
		res = send(message.join("\n"));
	}

	if (res == false)
	{
		QTimer::singleShot(30 * 60 * 1000,
				const_cast<StatisticEmailSender*>(this), SLOT(initSlot()));
	}
}