应该完成了

This commit is contained in:
Mike Solar
2023-08-15 11:17:09 +08:00
parent 979595c8d8
commit a7c74a20a6
18 changed files with 587 additions and 140 deletions

View File

@ -9,6 +9,7 @@
#include <PropKey.h>
#include <ShlObj.h>
#include <QtXml/QtXml>
#include <QtNetwork/QtNetwork>
#include <QtSvg/QtSvg>
#include "navbar.h"
#include "config.h"
@ -26,15 +27,10 @@
#pragma comment (lib,"Qt5Xml.lib")
#endif
#pragma comment (lib,"Shell32.lib")
#if _MSC_VER >=1936
#include <filesystem>
namespace fs = std::filesystem;
#else
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
namespace fs= std::experimental::filesystem;
bool getMenu(std::wstring &path_str,QHash<QString,QString> *paths)
{
fs::directory_iterator* it = new fs::directory_iterator(path_str);
@ -141,7 +137,7 @@ SQLiteHelper::~SQLiteHelper()
bool SQLiteHelper::update_software()
{
HKEY hKeyUninstall = nullptr;
QHash<QString,QString>* paths = new QHash<QString, QString>;
QHash<QString, QString>* paths = new QHash<QString, QString>;
/*QSqlQuery query;
QString sql = "select * from kmd_menu;";
query.exec(sql);
@ -180,15 +176,15 @@ bool SQLiteHelper::update_software()
HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//<2F><>ȡProgramData<74>п<EFBFBD>ʼ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>·<EFBFBD><C2B7>
std::wstring path_str(path);
getMenu(path_str, paths);
for(int i=0;i<sizeof(path)/sizeof(wchar_t);i++)
for (int i = 0; i < sizeof(path) / sizeof(wchar_t); i++)
{
path[i] = 0;
}
hr = SHGetFolderPathW(nullptr, CSIDL_PROGRAMS, nullptr, 0, path);//<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>п<EFBFBD>ʼ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>·<EFBFBD><C2B7>
path_str.clear();
path_str = std::wstring(path);
getMenu(path_str, paths);
getMenu(path_str, paths);
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>Ѱ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
QHash<QString, Record> reg_records;
HKEY hKey;
@ -230,7 +226,7 @@ bool SQLiteHelper::update_software()
&ftLastWriteTime); // last write time
// ö<>ٸ<EFBFBD><D9B8>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD>
for (DWORD i = 0; i<cSubKeys; i++)
for (DWORD i = 0; i < cSubKeys; i++)
{
WCHAR szSubKey[MAX_PATH] = { 0 };
DWORD dwSize = MAX_PATH;
@ -239,7 +235,7 @@ bool SQLiteHelper::update_software()
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
HKEY hSubKey;
if (RegOpenKeyExW(hKey, szSubKey, 0, KEY_READ| KEY_WOW64_64KEY, &hSubKey) == ERROR_SUCCESS)
if (RegOpenKeyExW(hKey, szSubKey, 0, KEY_READ | KEY_WOW64_64KEY, &hSubKey) == ERROR_SUCCESS)
{
Record record;
WCHAR szProductPath[MAX_PATH] = { 0 };
@ -287,11 +283,11 @@ bool SQLiteHelper::update_software()
record.op = "soft";
record.locked = false;
RegCloseKey(hSubKey);
if(!path.isEmpty())
if (!path.isEmpty())
{
reg_records.insert(path, record);
}
}
}
else
@ -340,7 +336,7 @@ bool SQLiteHelper::update_software()
&ftLastWriteTime); // last write time
// ö<>ٸ<EFBFBD><D9B8>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD>
for (DWORD i = 0;i<cSubKeys ; i++)
for (DWORD i = 0; i < cSubKeys; i++)
{
WCHAR szSubKey[MAX_PATH] = { 0 };
DWORD dwSize = MAX_PATH;
@ -408,12 +404,12 @@ bool SQLiteHelper::update_software()
RegCloseKey(hkey2);
}
BOOL isWow64;
if(IsWow64Process(GetCurrentProcess(),&isWow64))
if (IsWow64Process(GetCurrentProcess(), &isWow64))
{
HKEY hkey3;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
0, KEY_READ|KEY_WOW64_64KEY, &hkey3) == ERROR_SUCCESS)
0, KEY_READ | KEY_WOW64_64KEY, &hkey3) == ERROR_SUCCESS)
{
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
@ -449,7 +445,7 @@ bool SQLiteHelper::update_software()
&ftLastWriteTime); // last write time
// ö<>ٸ<EFBFBD><D9B8>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD>
for (DWORD i = 0;i<cSubKeys ; i++)
for (DWORD i = 0; i < cSubKeys; i++)
{
WCHAR szSubKey[MAX_PATH] = { 0 };
DWORD dwSize = MAX_PATH;
@ -650,13 +646,41 @@ bool SQLiteHelper::update_software()
}
}
delete paths;*/
for(auto key :reg_records.keys())
for (auto key : reg_records.keys())
{
public_programs_list.insert(reg_records[key].orig_name, reg_records[key]);
}
QSqlQuery find2(db);
QJsonArray array;
if (find2.exec("select * from kmd_menu where status=1;")) {
while (find2.next()) {
QJsonObject obj;
obj.insert("sort", find2.value("sort").toInt());
obj.insert("app_id", find2.value("app_id").toString());
obj.insert("locked", find2.value("locked").toBool());
obj.insert("type", find2.value("type").toString());
obj.insert("category_id", find2.value("category_id").toString());
obj.insert("name", find2.value("name").toString());
obj.insert("orig_name", find2.value("orig_name").toString());
obj.insert("version", find2.value("version").toString());
obj.insert("dev", find2.value("dev").toString());
obj.insert("create_time", find2.value("create_time").toInt());
obj.insert("use_time", find2.value("use_time").toInt());
obj.insert("op", find2.value("op").toString());
obj.insert("func", find2.value("func").toString());
obj.insert("path", find2.value("path").toString());
obj.insert("url", find2.value("url").toString());
obj.insert("initial_position", find2.value("initial_position").toString());
obj.insert("logo", find2.value("logo").toString());
obj.insert("status", find2.value("status").toBool());
obj.insert("is_delete", find2.value("is_delete").toBool());
array.append(obj);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬲<EFBFBD>ȫ<EFBFBD>ֶ<EFBFBD>
SoftwareRequest software_request;
bool ok=software_request.sendRequest(*paths,&public_programs_list);
bool ok=software_request.sendRequest(*paths,&public_programs_list,array);
if(!ok)
{
return false;
@ -697,6 +721,7 @@ bool SQLiteHelper::update_software()
sql += "' where orig_name='";
sql += key;
sql += "';";
}
else
{
@ -709,6 +734,10 @@ bool SQLiteHelper::update_software()
sql += ",'";
sql += public_programs_list[key].type;
sql += "','";
sql += QString::number(ALL, 10);
sql += ",";
sql += QString::number(SOFT, 10);
sql += ",";
sql += QString::number(OTHERS, 10);
sql += "','";
sql += public_programs_list[key].name;
@ -733,6 +762,37 @@ bool SQLiteHelper::update_software()
sql += "','";
sql += public_programs_list[key].status;
sql += "');";
bool categories[8] = { false };
categories[ALL - 1] = true;
categories[SOFT - 1] = true;
for (int i = 0; i < 8; i++)
{
QSqlQuery query2(db);
if (categories[i])
{
query2.prepare("select total from kmd_category where id=:id;");
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
if (query2.next())
{
int total = query2.value("total").toInt();
query2.prepare("update kmd_category set total=:total where id=:id;");
query2.bindValue(":total", total + 1);
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
}
}
}
}
QSqlQuery query(db);
if(!query.exec(sql))
@ -741,6 +801,7 @@ bool SQLiteHelper::update_software()
rollback.exec();
return false;
}
}
QSqlQuery find(db);
@ -755,6 +816,37 @@ bool SQLiteHelper::update_software()
del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;");
del.bindValue(":orig_value", find.value("orig_name"));
del.exec();
bool categories[8] = { false };
categories[ALL - 1] = true;
categories[SOFT - 1] = true;
for (int i = 0; i < 8; i++)
{
QSqlQuery query2(db);
if (categories[i])
{
query2.prepare("select total from kmd_category where id=:id;");
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
if (query2.next())
{
int total = query2.value("total").toInt();
query2.prepare("update kmd_category set total=:total where id=:id;");
query2.bindValue(":total", total - 1);
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
}
}
}
}
}
}
@ -786,7 +878,7 @@ void SetSVGBackColor(QDomElement& elem, QString strtagname, QString strattr, QSt
SetSVGBackColor(elem.childNodes().at(i).toElement(), strtagname, strattr, strattrval);
}
}
bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response)
bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigResponse* config_response)
{
QSqlQuery query(db);
QString sql = "select * from kmd_menu where type='navbar' order by sort,orig_name asc ;";
@ -797,7 +889,8 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
QString background_color;
QString title_color;
QString title_cover_color;
if(config_response->succeed)
QList<Button> buttons = config_response->buttons;
if (config_response->succeed)
{
background_color = config_response->basic.backgroud_color;
title_color = config_response->basic.title_color;
@ -805,19 +898,138 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
}
else
{
background_color = DEFAULT_BACKGROUND_COLOR;
title_color = DEFAULT_TEXT_COLOR;
title_cover_color = DEFAULT_COVER_COLOR;
QFile file(QApplication::applicationDirPath() + DEFAULT_NAVBAR_FILLE);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray buffer;
buffer = file.readAll();
QJsonDocument result;
result = QJsonDocument::fromJson(buffer);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (result.isObject()) {
QJsonObject obj_root = result.object();
QJsonArray array;
array = obj_root.value("data").toObject().value("menu").toArray();
qDebug() << array;
QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject();
background_color = obj_basic.value("backgroud_color").toString();
title_color = obj_basic.value("title_color").toString();
title_cover_color = obj_basic.value("title_cover_color").toString();
auto i = 0;
for (auto value : array) {
QJsonObject object = value.toObject();
Button button;
button.img = object.value("img").toString();
// button.img_cover=object.value("img_cover").toString();
button.title = object.value("title").toString();
button.categroy_id = object.value("category_id").toString();
button.orig_name = object.value("orig_name").toString();
button.op = object.value("op").toString();
button.func = object.value("func").toString();
button.url = object.value("url").toString();
buttons << button;
i++;
}
}
else {
background_color = DEFAULT_BACKGROUND_COLOR;
title_color = DEFAULT_TEXT_COLOR;
title_cover_color = DEFAULT_COVER_COLOR;
}
}
}
QByteArray* buffer = new QByteArray;
QHash<QString, ButtonStruct> button_map;
for(auto menu : config_response->buttons)
QNetworkAccessManager* manager;
for (auto menu : buttons)
{
ButtonStruct button_struct;
button_struct.text = menu.title;
button_struct.orig_name = menu.orig_name;
button_struct.op = menu.op;
button_struct.func = menu.func;
button_struct.url = menu.url;
QImage* image = new QImage(200, 200, QImage::Format_ARGB32);
QImage* image_cover = new QImage(200, 200, QImage::Format_ARGB32);
downloadSuccess = true;
QUrl url_logo(menu.img);
QNetworkRequest* request_logo = new QNetworkRequest(url_logo);
manager = new QNetworkAccessManager;
reply = manager->get(*request_logo);
QTimer timer;
timer.setInterval(5000);
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, this, &SQLiteHelper::cancelDownload);
eventLoop.exec();
timer.stop();
buffer = new QByteArray;
*buffer = reply->readAll();
delete request_logo;
reply->close();
if ((reply->error() == QNetworkReply::NoError)&&(downloadSuccess == true)) {
QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg");
if (file.open(QIODevice::Text | QIODevice::WriteOnly))
{
file.write(*buffer);
file.close();
}
}
else
{
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg";
QFile file(icon);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
//QByteArray* buffer = new QByteArray;
*buffer = file.readAll();
file.close();
}
else
{
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
//QByteArray* buffer = new QByteArray;
*buffer = file.readAll();
file.close();
}
}
}
delete manager;
manager = nullptr;
QSvgRenderer* render_image = new QSvgRenderer(*buffer);
QPainter painter_image(image);
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
painter_image.fillRect(image->rect(), Qt::transparent); // <20><><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>ɫ
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // <20>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
render_image->render(&painter_image);
//<2F>޸<EFBFBD><DEB8><EFBFBD>ɫ
QDomDocument doc;
doc.setContent(*buffer);
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
QPainter painter_image_cover(image_cover);
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // <20><><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>ɫ
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // <20>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
render_image_cover->render(&painter_image_cover);
delete render_image;
delete render_image_cover;
button_struct.image = image;
button_struct.image_cover = image_cover;
button_struct.background_color = background_color;
button_struct.text_color = QColor(title_color);
button_struct.text_cover_color = QColor(title_cover_color);
*button_structs << button_struct;
}
while (query.next())
{
QString icon = QApplication::applicationDirPath() + "/images/software/" + query.value("orig_name").toString() + ".svg";
QString icon = QApplication::applicationDirPath() + "/images/svg/" + query.value("orig_name").toString() + ".svg";
ButtonStruct button_struct;
button_struct.path = query.value("path").toString();
button_struct.text = query.value("name").toString();
@ -842,7 +1054,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
//<2F>޸<EFBFBD><DEB8><EFBFBD>ɫ
QDomDocument doc;
doc.setContent(svg_buffer);
SetSVGBackColor(doc.documentElement(), "path", "fill",title_cover_color);
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
QPainter painter_image_cover(image_cover);
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@ -852,7 +1064,8 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
delete render_image;
delete render_image_cover;
}else
}
else
{
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
QFile file(icon);
@ -886,9 +1099,10 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
button_struct.background_color = background_color;
button_struct.text_color = QColor(title_color);
button_struct.text_cover_color = QColor(title_cover_color);
*buttons << button_struct;
*button_structs << button_struct;
}
return true;
}
@ -900,7 +1114,9 @@ void SQLiteHelper::cancelDownload() {
}
bool SQLiteHelper::update_app()
{
QString app_path = QApplication::applicationDirPath()+"/app";
QSqlQuery work(db);
work.exec("begin;");
QString app_path = QApplication::applicationDirPath() + "/app";
for(auto dir: fs::directory_iterator(fs::path(app_path.toStdString())))
{
if(fs::is_directory(dir))
@ -953,11 +1169,43 @@ bool SQLiteHelper::update_app()
query.addBindValue(obj_root.value("initial_position").toString());
query.addBindValue(obj_root.value("status").toBool());
query.exec();
bool categories[8]={false};
categories[ALL - 1] = true;
categories[INNER - 1] = true;
for (int i = 0; i < 8; i++)
{
QSqlQuery query2(db);
if (categories[i])
{
query2.prepare("select total from kmd_category where id=:id;");
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
if (query2.next())
{
int total = query2.value("total").toInt();
query2.prepare("update kmd_category set total=:total where id=:id;");
query2.bindValue(":total", total + 1);
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
}
}
}
}
}
}
work.exec("commit;");
return true;
}
@ -1045,25 +1293,48 @@ bool SQLiteHelper::set_category(QList<Categrory>& categrories)
qDebug() << work.lastError();
return true;
}
bool SQLiteHelper::get_category(QList<Categrory>& categrories)
bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
{
QSqlQuery query(db);
if(!query.exec("select id,name,status,sort from kmd_category"))
if(is_edit)
{
return false;
}
while(query.next())
{
if(query.value("name")==QString::fromLocal8Bit("ȫ<EFBFBD><EFBFBD>"))
if (!query.exec("select id,name,status,sort from kmd_category where is_edit=1;"))
{
continue;
return false;
}
while (query.next())
{
if (query.value("name") == QString::fromLocal8Bit("ȫ<EFBFBD><EFBFBD>"))
{
continue;
}
Categrory categrory;
categrory.name = query.value("name").toString();
categrory.id = query.value("id").toInt();
categrory.sort = query.value("sort").toInt();
categrory.display = query.value("status").toBool();
categrories << categrory;
}
}
else
{
if (!query.exec("select id,name,status,sort from kmd_category;"))
{
return false;
}
while (query.next())
{
if (query.value("name") == QString::fromLocal8Bit("ȫ<EFBFBD><EFBFBD>"))
{
continue;
}
Categrory categrory;
categrory.name = query.value("name").toString();
categrory.id = query.value("id").toInt();
categrory.sort = query.value("sort").toInt();
categrory.display = query.value("status").toBool();
categrories << categrory;
}
Categrory categrory;
categrory.name = query.value("name").toString();
categrory.id = query.value("id").toInt();
categrory.sort = query.value("sort").toInt();
categrory.display = query.value("status").toBool();
categrories << categrory;
}
return true;
}
@ -1113,6 +1384,8 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString type)
{
QSqlQuery begin(db);
begin.exec("begin;");
if (type.isEmpty())
{
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories where orig_name=:orig_name;";
@ -1133,8 +1406,47 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
query.bindValue(":orig_name", orig_name);
if (!query.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
qDebug() << query.lastError();
QSqlQuery categories_sql(db);
for(int i=0;i<8;i++)
{
QSqlQuery query2(db);
if(categories[i])
{
query2.prepare("select total from kmd_category where id=:id;");
query2.bindValue(":id", i + 1);
if(!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
if(query2.next())
{
QSqlQuery total(db);
QSqlQuery query3(db);
QString total_sql = "select id from kmd_menu where category_id like '%";
total_sql += QString::number(i + 1);
total_sql += "%';";
total.exec(total_sql);
query3.prepare("update kmd_category set total=:total where id=:id;");
query3.bindValue(":total", total.size());;
query3.bindValue(":id", i + 1);
if (!query3.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
}
}
}
QSqlQuery commit(db);
commit.exec("commit;");
return true;
}else
{
@ -1160,6 +1472,43 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
{
return false;
}
qDebug() << query.lastError();
for (int i = 0; i < 8; i++)
{
QSqlQuery query2(db);
if (categories[i])
{
query2.prepare("select total from kmd_category where id=:id;");
query2.bindValue(":id", i + 1);
if (!query2.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
if (query2.next())
{
QSqlQuery total(db);
QSqlQuery query3(db);
QString total_sql = "select id from kmd_menu where category_id like '%";
total_sql += QString::number(i + 1);
total_sql += "%';";
total.exec(total_sql);
query3.prepare("update kmd_category set total=:total where id=:id;");
query3.bindValue(":total", total.size());;
query3.bindValue(":id", i + 1);
if (!query3.exec())
{
QSqlQuery rollback(db);
rollback.exec("rollback;");
return false;
}
}
}
}
QSqlQuery commit(db);
commit.exec("commit;");
return true;
}
}