改了几个bug,提交
parent
409443e311
commit
46f48b8440
|
@ -3,7 +3,7 @@
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <sqlitehelper.h>
|
#include <sqlitehelper.h>
|
||||||
|
#include "config.h"
|
||||||
#include "applicationmanager.h"
|
#include "applicationmanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,27 +16,34 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
this->row=row;
|
||||||
SQLiteHelper sqlite_helper;
|
SQLiteHelper sqlite_helper;
|
||||||
setFixedSize(450, 450);
|
setFixedSize(450, 450);
|
||||||
|
Record2 record;
|
||||||
|
sqlite_helper.get_a_software(row->orig_name, &record);
|
||||||
setWindowFlags(Qt::WindowCloseButtonHint);
|
setWindowFlags(Qt::WindowCloseButtonHint);
|
||||||
form = new QFormLayout;
|
form = new QFormLayout;
|
||||||
name = new QLineEdit;
|
name = new QLineEdit;
|
||||||
form->addRow(QString::fromLocal8Bit("名称"), name);
|
form->addRow(QString::fromLocal8Bit("名称"), name);
|
||||||
if(isEdit)
|
|
||||||
|
if (isEdit)
|
||||||
{
|
{
|
||||||
name_label = new QLabel(orig_name_str);
|
name_label = new QLabel(orig_name_str);
|
||||||
form->addRow(QString::fromLocal8Bit("全名"), name_label);
|
form->addRow(QString::fromLocal8Bit("全名"), name_label);
|
||||||
if(row!=nullptr)
|
|
||||||
|
if (!record.orig_name.isEmpty())
|
||||||
{
|
{
|
||||||
name_label->setText(row->orig_name);
|
name_label->setText(record.orig_name);
|
||||||
}
|
}
|
||||||
|
orig_name_str = record.orig_name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
orig_name = new QLineEdit;
|
orig_name = new QLineEdit;
|
||||||
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
|
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
|
||||||
}
|
}
|
||||||
if(row==nullptr)
|
|
||||||
|
if (record.orig_name.isEmpty())
|
||||||
{
|
{
|
||||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||||
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
||||||
|
@ -46,11 +53,12 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
||||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||||
QList<Categrory> categrories;
|
QList<Categrory> categrories;
|
||||||
layout_inner = new QVBoxLayout;
|
layout_inner = new QVBoxLayout;
|
||||||
sqlite_helper.get_category(categrories,true);
|
sqlite_helper.get_category(categrories, true);
|
||||||
|
|
||||||
for (auto category : categrories)
|
for (auto category : categrories)
|
||||||
{
|
{
|
||||||
QCheckBox* check_box = new QCheckBox(category.name);
|
QCheckBox* check_box = new QCheckBox(category.name);
|
||||||
|
|
||||||
layout_inner->addWidget(check_box);
|
layout_inner->addWidget(check_box);
|
||||||
categories_list.insert(category.id, check_box);
|
categories_list.insert(category.id, check_box);
|
||||||
}
|
}
|
||||||
|
@ -61,28 +69,29 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
||||||
connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
|
connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
|
||||||
connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit);
|
connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit);
|
||||||
this->isEdit = isEdit;
|
this->isEdit = isEdit;
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
name->setText(row->name);
|
name->setText(record.name);
|
||||||
name_str=row->name;
|
name_str = record.name;
|
||||||
sort_str=QString::number(row->sort);
|
sort_str = QString::number(record.sort);
|
||||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||||
path_str = row->exe_file;
|
path_str = record.exe_file;
|
||||||
path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str()));
|
path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str()));
|
||||||
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
||||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||||
sort = new QLineEdit;
|
sort = new QLineEdit;
|
||||||
sort->setText(QString::number(row->sort));
|
sort->setText(QString::number(record.sort));
|
||||||
sort->setValidator(new QIntValidator(10, 100));
|
sort->setValidator(new QIntValidator(10, 100));
|
||||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||||
QList<Categrory> categrories;
|
QList<Categrory> categrories;
|
||||||
layout_inner = new QVBoxLayout;
|
layout_inner = new QVBoxLayout;
|
||||||
sqlite_helper.get_category(categrories,true);
|
sqlite_helper.get_category(categrories, true);
|
||||||
categories = row->categories;
|
this->categories = record.categories;
|
||||||
for (auto category : categrories)
|
for (auto category : categrories)
|
||||||
{
|
{
|
||||||
QCheckBox* check_box = new QCheckBox(category.name);
|
QCheckBox* check_box = new QCheckBox(category.name);
|
||||||
if(row->categories[category.id-1])
|
if (record.categories[category.id - 1])
|
||||||
{
|
{
|
||||||
check_box->setCheckState(Qt::Checked);
|
check_box->setCheckState(Qt::Checked);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +121,7 @@ AddApp::~AddApp()
|
||||||
delete orig_name;
|
delete orig_name;
|
||||||
}
|
}
|
||||||
delete path;
|
delete path;
|
||||||
delete sort;
|
//delete sort;
|
||||||
delete submit_btn;
|
delete submit_btn;
|
||||||
delete form;
|
delete form;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +155,6 @@ void AddApp::submit() {
|
||||||
QString sort_str_old = sort_str;
|
QString sort_str_old = sort_str;
|
||||||
name_str = name->text();
|
name_str = name->text();
|
||||||
sort_str = sort->text();
|
sort_str = sort->text();
|
||||||
|
|
||||||
if (name_str.isEmpty()) {
|
if (name_str.isEmpty()) {
|
||||||
name_str = name_str_old;
|
name_str = name_str_old;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +167,8 @@ void AddApp::submit() {
|
||||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写路径"));
|
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写路径"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if ((!orig_name->text().isEmpty()) && (!path->text().isEmpty()))
|
if ((!orig_name->text().isEmpty()) && (!path->text().isEmpty()))
|
||||||
{
|
{
|
||||||
|
@ -167,7 +176,10 @@ void AddApp::submit() {
|
||||||
if (name->text().isEmpty()) {
|
if (name->text().isEmpty()) {
|
||||||
name_str = orig_name_str;
|
name_str = orig_name_str;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
name_str = name->text();
|
name_str = name->text();
|
||||||
|
}
|
||||||
|
|
||||||
sort_str = sort->text();
|
sort_str = sort->text();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -176,10 +188,22 @@ void AddApp::submit() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
categories = new bool[8];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
categories[i] = false;
|
||||||
|
}
|
||||||
|
categories[ALL-1] = true;
|
||||||
|
if (row->op == "soft") {
|
||||||
|
categories[SOFT-1] = true;
|
||||||
|
}
|
||||||
|
else if (row->op == "app") {
|
||||||
|
categories[INNER-1] = true;
|
||||||
|
}
|
||||||
for(auto key:categories_list.keys())
|
for(auto key:categories_list.keys())
|
||||||
{
|
{
|
||||||
categories[key - 1] = categories_list[key]->checkState();
|
categories[key - 1] = categories_list[key]->checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
qDebug() << categories[i];
|
qDebug() << categories[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ private:
|
||||||
QString orig_name_str;
|
QString orig_name_str;
|
||||||
QString path_str;
|
QString path_str;
|
||||||
QVBoxLayout* layout_inner;
|
QVBoxLayout* layout_inner;
|
||||||
|
Record2 *row;
|
||||||
bool isEdit;
|
bool isEdit;
|
||||||
private slots:
|
private slots:
|
||||||
void broswer_exe();
|
void broswer_exe();
|
||||||
|
|
|
@ -24,7 +24,7 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
||||||
layout_top->setMargin(5);
|
layout_top->setMargin(5);
|
||||||
layout_bottom = new QHBoxLayout(this);
|
layout_bottom = new QHBoxLayout(this);
|
||||||
QList<Categrory> categrories;
|
QList<Categrory> categrories;
|
||||||
sqlite_helper.get_category(categrories,false);
|
sqlite_helper.get_category(categrories,false,true);
|
||||||
sqlite_helper.get_buttons(button_structs);
|
sqlite_helper.get_buttons(button_structs);
|
||||||
for (auto button_struct : button_structs)
|
for (auto button_struct : button_structs)
|
||||||
{
|
{
|
||||||
|
@ -45,13 +45,13 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
||||||
//ui.tabWidget->setMovable(false);
|
//ui.tabWidget->setMovable(false);
|
||||||
//ui.tabWidget->setDocumentMode(false);
|
//ui.tabWidget->setDocumentMode(false);
|
||||||
//ui.tabWidget->setCurrentIndex(0);
|
//ui.tabWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
tab_bar = new QTabBar(this);
|
tab_bar = new QTabBar(this);
|
||||||
tab_bar->addTab(QString::fromLocal8Bit("È«²¿"));
|
|
||||||
layout_bottom_top = new QVBoxLayout;
|
layout_bottom_top = new QVBoxLayout;
|
||||||
|
|
||||||
for(int i=2;i<=8;i++)
|
for(int i=1;i<=8;i++)
|
||||||
{
|
{
|
||||||
tab_bar->addTab(categrories[i - 2].name);
|
tab_bar->addTab(categrories[i - 1].name + "(" + QString::number(categrories[i - 1].total) + ")");
|
||||||
}
|
}
|
||||||
layout_bottom_top->addWidget(tab_bar, 1);
|
layout_bottom_top->addWidget(tab_bar, 1);
|
||||||
application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
|
application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
|
||||||
|
@ -66,6 +66,7 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
||||||
application_manager_page->setHidden(true);
|
application_manager_page->setHidden(true);
|
||||||
map.insert(i, application_manager_page);
|
map.insert(i, application_manager_page);
|
||||||
}
|
}
|
||||||
|
connect(this,&ApplicationManager::refresh,this,&ApplicationManager::onNumChange);
|
||||||
tab_bar->setCurrentIndex(0);
|
tab_bar->setCurrentIndex(0);
|
||||||
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
|
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
|
||||||
QString style = "QTabBar::tab{height:80;width:150; border:2px} QTabBar::tab:hover{ border:2px;height:80;width:150;color:";
|
QString style = "QTabBar::tab{height:80;width:150; border:2px} QTabBar::tab:hover{ border:2px;height:80;width:150;color:";
|
||||||
|
@ -210,6 +211,7 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||||
}
|
}
|
||||||
|
emit refresh();
|
||||||
}else if(func=="app_category")
|
}else if(func=="app_category")
|
||||||
{
|
{
|
||||||
AddCategory add_category;
|
AddCategory add_category;
|
||||||
|
@ -225,6 +227,8 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败"));
|
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败"));
|
||||||
}
|
}
|
||||||
|
emit refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(op=="soft")
|
}else if(op=="soft")
|
||||||
|
@ -251,7 +255,7 @@ void ApplicationManager::onclick2(QString orig_name, QString op)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit changeUrl(application_manager_page_all->rows[orig_name].url);
|
emit changeUrl(application_manager_page_all->rows[orig_name].url);
|
||||||
WinExec(application_manager_page_all->rows[orig_name].exe_file.toStdString().c_str(), SW_SHOW);
|
WinExec((QApplication::applicationDirPath()+application_manager_page_all->rows[orig_name].exe_file).toStdString().c_str(), SW_SHOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (op == "settings")
|
else if (op == "settings")
|
||||||
|
@ -265,10 +269,16 @@ void ApplicationManager::onclick2(QString orig_name, QString op)
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
|
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
|
||||||
}
|
}
|
||||||
|
emit refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func,application_manager_page_all->rows[orig_name].exe_file,application_manager_page_all->rows[orig_name].url);
|
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op,
|
||||||
|
application_manager_page_all->rows[orig_name].func,
|
||||||
|
application_manager_page_all->rows[orig_name].url,
|
||||||
|
application_manager_page_all->rows[orig_name].exe_file
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,3 +291,11 @@ void ApplicationManager::tabChange(int index)
|
||||||
}
|
}
|
||||||
map[index + 1]->setHidden(false);
|
map[index + 1]->setHidden(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplicationManager::onNumChange() {
|
||||||
|
QList<Categrory> categrories;
|
||||||
|
sqlite_helper.get_category(categrories, false, true);
|
||||||
|
for (int i = 0; i < categrories.size(); i++) {
|
||||||
|
tab_bar->setTabText(i, categrories[i].name + "(" + QString::number(categrories[i].total) + ")");
|
||||||
|
}
|
||||||
|
}
|
|
@ -77,4 +77,5 @@ public slots:
|
||||||
void onclick1(QString op, QString func, QString path, QString url);
|
void onclick1(QString op, QString func, QString path, QString url);
|
||||||
void onclick2(QString orig_name, QString op);
|
void onclick2(QString orig_name, QString op);
|
||||||
void tabChange(int index);
|
void tabChange(int index);
|
||||||
|
void onNumChange();
|
||||||
};
|
};
|
||||||
|
|
|
@ -174,14 +174,7 @@ void ApplicationManagerPage::refresh()
|
||||||
{
|
{
|
||||||
table->removeRow(0);
|
table->removeRow(0);
|
||||||
}
|
}
|
||||||
for(auto row:rows)
|
|
||||||
{
|
|
||||||
disconnect(row.settings, &MiniButton::click0, row.settings, &MiniButton::onclick2);
|
|
||||||
disconnect(row.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
|
||||||
disconnect(row.open, &MiniButton::click0, row.open, &MiniButton::onclick2);
|
|
||||||
disconnect(row.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
|
||||||
disconnect(row.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked);
|
|
||||||
}
|
|
||||||
softwares.clear();
|
softwares.clear();
|
||||||
sqlite_helper.get_all_software(softwares, category);
|
sqlite_helper.get_all_software(softwares, category);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -241,6 +234,9 @@ void ApplicationManagerPage::refresh()
|
||||||
record2.categories[i] = true;
|
record2.categories[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
record2.op = software.op;
|
||||||
|
record2.func = software.func;
|
||||||
|
connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
|
||||||
record2.sort = software.sort;
|
record2.sort = software.sort;
|
||||||
record2.check_box = new QCheckBox;
|
record2.check_box = new QCheckBox;
|
||||||
if (software.type == "navbar")
|
if (software.type == "navbar")
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include "applicationmanager.h"
|
||||||
#define MAX_KEY_LENGTH 255
|
#define MAX_KEY_LENGTH 255
|
||||||
#define MAX_VALUE_NAME 16383
|
#define MAX_VALUE_NAME 16383
|
||||||
|
|
||||||
|
@ -782,7 +783,7 @@ bool SQLiteHelper::update_software()
|
||||||
{
|
{
|
||||||
int total = query2.value("total").toInt();
|
int total = query2.value("total").toInt();
|
||||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||||
query2.bindValue(":total", total + 1);
|
query2.bindValue(":total", total);
|
||||||
query2.bindValue(":id", i + 1);
|
query2.bindValue(":id", i + 1);
|
||||||
if (!query2.exec())
|
if (!query2.exec())
|
||||||
{
|
{
|
||||||
|
@ -1177,24 +1178,18 @@ bool SQLiteHelper::update_app()
|
||||||
QSqlQuery query2(db);
|
QSqlQuery query2(db);
|
||||||
if (categories[i])
|
if (categories[i])
|
||||||
{
|
{
|
||||||
query2.prepare("select total from kmd_category where id=:id;");
|
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||||
query2.bindValue(":id", i + 1);
|
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||||
if (!query2.exec())
|
if (query2.exec() && query2.first())
|
||||||
{
|
|
||||||
QSqlQuery rollback(db);
|
|
||||||
rollback.exec("rollback;");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (query2.next())
|
|
||||||
{
|
{
|
||||||
int total = query2.value("total").toInt();
|
int total = query2.value("total").toInt();
|
||||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||||
query2.bindValue(":total", total + 1);
|
query2.bindValue(":total", total);
|
||||||
query2.bindValue(":id", i + 1);
|
query2.bindValue(":id", i + 1);
|
||||||
if (!query2.exec())
|
if (!query2.exec())
|
||||||
{
|
{
|
||||||
QSqlQuery rollback(db);
|
QSqlQuery rollback(db);
|
||||||
rollback.exec("rollback;");
|
rollback.exec("ROLLBACK;");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1246,7 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||||
query.addBindValue("app");
|
query.addBindValue("app");
|
||||||
query.addBindValue(categories_str);
|
query.addBindValue(categories_str);
|
||||||
query.addBindValue(name);
|
query.addBindValue(name);
|
||||||
query.addBindValue(name);
|
query.addBindValue(orig_name);
|
||||||
time_t create_time;
|
time_t create_time;
|
||||||
time(&create_time);
|
time(&create_time);
|
||||||
query.addBindValue(create_time);
|
query.addBindValue(create_time);
|
||||||
|
@ -1266,6 +1261,31 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("´íÎó"), QString::fromLocal8Bit("дÈëÊý¾Ý¿âʧ°Ü"));
|
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("´íÎó"), QString::fromLocal8Bit("дÈëÊý¾Ý¿âʧ°Ü"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (categories[i])
|
||||||
|
{
|
||||||
|
QSqlQuery query2(db);
|
||||||
|
|
||||||
|
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||||
|
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||||
|
if (query2.exec() && query2.first())
|
||||||
|
{
|
||||||
|
int total = query2.value("total").toInt();
|
||||||
|
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||||
|
query2.bindValue(":total", total);
|
||||||
|
query2.bindValue(":id", i + 1);
|
||||||
|
qDebug()<< query2.lastError();
|
||||||
|
if (!query2.exec())
|
||||||
|
{
|
||||||
|
query.exec("ROLLBACK;");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1293,12 +1313,12 @@ bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||||
qDebug() << work.lastError();
|
qDebug() << work.lastError();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit,bool all)
|
||||||
{
|
{
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
if(is_edit)
|
if(is_edit)
|
||||||
{
|
{
|
||||||
if (!query.exec("select id,name,status,sort from kmd_category where is_edit=1;"))
|
if (!query.exec("select id,name,status,sort,total from kmd_category where is_edit=1;"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1313,12 +1333,29 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
||||||
categrory.id = query.value("id").toInt();
|
categrory.id = query.value("id").toInt();
|
||||||
categrory.sort = query.value("sort").toInt();
|
categrory.sort = query.value("sort").toInt();
|
||||||
categrory.display = query.value("status").toBool();
|
categrory.display = query.value("status").toBool();
|
||||||
|
categrory.total = query.value("total").toInt();
|
||||||
|
categrories << categrory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (all&&(!is_edit)) {
|
||||||
|
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (query.next())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
categrory.total = query.value("total").toInt();
|
||||||
categrories << categrory;
|
categrories << categrory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!query.exec("select id,name,status,sort from kmd_category;"))
|
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1333,6 +1370,7 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
||||||
categrory.id = query.value("id").toInt();
|
categrory.id = query.value("id").toInt();
|
||||||
categrory.sort = query.value("sort").toInt();
|
categrory.sort = query.value("sort").toInt();
|
||||||
categrory.display = query.value("status").toBool();
|
categrory.display = query.value("status").toBool();
|
||||||
|
categrory.total = query.value("total").toInt();
|
||||||
categrories << categrory;
|
categrories << categrory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1431,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||||
query.prepare(sql);
|
query.prepare(sql);
|
||||||
query.bindValue(":name", name);
|
query.bindValue(":name", name);
|
||||||
query.bindValue(":path", path);
|
query.bindValue(":path", path);
|
||||||
query.bindValue(":sort", sort.toInt());
|
query.bindValue(":sort", sort);
|
||||||
QString categories_str = "";
|
QString categories_str = "";
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
|
@ -1415,34 +1453,21 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||||
for(int i=0;i<8;i++)
|
for(int i=0;i<8;i++)
|
||||||
{
|
{
|
||||||
QSqlQuery query2(db);
|
QSqlQuery query2(db);
|
||||||
if(categories[i])
|
|
||||||
|
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||||
|
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||||
|
if (query2.exec() && query2.first())
|
||||||
{
|
{
|
||||||
query2.prepare("select total from kmd_category where id=:id;");
|
int total = query2.value("total").toInt();
|
||||||
|
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||||
|
query2.bindValue(":total", total);
|
||||||
query2.bindValue(":id", i + 1);
|
query2.bindValue(":id", i + 1);
|
||||||
if(!query2.exec())
|
qDebug() << query2.lastError();
|
||||||
|
if (!query2.exec())
|
||||||
{
|
{
|
||||||
QSqlQuery rollback(db);
|
query.exec("ROLLBACK;");
|
||||||
rollback.exec("rollback;");
|
|
||||||
return false;
|
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);
|
QSqlQuery commit(db);
|
||||||
|
@ -1456,7 +1481,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||||
query.prepare(sql);
|
query.prepare(sql);
|
||||||
query.bindValue(":name", name);
|
query.bindValue(":name", name);
|
||||||
query.bindValue(":path", path);
|
query.bindValue(":path", path);
|
||||||
query.bindValue(":sort", sort.toInt());
|
query.bindValue(":sort", sort);
|
||||||
QString categories_str = "";
|
QString categories_str = "";
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
|
@ -1496,7 +1521,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||||
total_sql += "%';";
|
total_sql += "%';";
|
||||||
total.exec(total_sql);
|
total.exec(total_sql);
|
||||||
query3.prepare("update kmd_category set total=:total where id=:id;");
|
query3.prepare("update kmd_category set total=:total where id=:id;");
|
||||||
query3.bindValue(":total", total.size());;
|
query3.bindValue(":total", total.size()+1);
|
||||||
query3.bindValue(":id", i + 1);
|
query3.bindValue(":id", i + 1);
|
||||||
if (!query3.exec())
|
if (!query3.exec())
|
||||||
{
|
{
|
||||||
|
@ -1512,3 +1537,33 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
||||||
|
QString sql = "select * from kmd_menu where orig_name=:orig_name;";
|
||||||
|
QSqlQuery query(db);
|
||||||
|
query.prepare(sql);
|
||||||
|
query.bindValue(":orig_name", orig_name);
|
||||||
|
if (!query.exec())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (query.next())
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (query.value("category_id").toString().contains(QString::number(i + 1))) {
|
||||||
|
record->categories[i] = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
record->categories[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
record->sort = query.value("sort").toInt();
|
||||||
|
record->name = query.value("name").toString();
|
||||||
|
record->orig_name = query.value("orig_name").toString();
|
||||||
|
record->op = query.value("op").toString();
|
||||||
|
record->func = query.value("func").toString();
|
||||||
|
record->exe_file = query.value("path").toString();
|
||||||
|
record->url = query.value("url").toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "buttonstruct.h"
|
#include "buttonstruct.h"
|
||||||
struct ConfigResponse;
|
struct ConfigResponse;
|
||||||
class ConfigRequest;
|
class ConfigRequest;
|
||||||
|
struct Record2;
|
||||||
class SoftwareRequest;
|
class SoftwareRequest;
|
||||||
typedef struct tagRecord{
|
typedef struct tagRecord{
|
||||||
int id;
|
int id;
|
||||||
|
@ -34,6 +35,7 @@ typedef struct tagRecord{
|
||||||
struct Categrory
|
struct Categrory
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
int total;
|
||||||
QString name;
|
QString name;
|
||||||
bool display;
|
bool display;
|
||||||
int sort;
|
int sort;
|
||||||
|
@ -50,9 +52,10 @@ public:
|
||||||
bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response);
|
bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response);
|
||||||
bool update_app();
|
bool update_app();
|
||||||
bool get_buttons(QList<ButtonStruct> &buttons);
|
bool get_buttons(QList<ButtonStruct> &buttons);
|
||||||
bool get_category(QList<Categrory>& categrories, bool is_edit);
|
bool get_category(QList<Categrory>& categrories, bool is_edit,bool all=false);
|
||||||
bool set_category(QList<Categrory>& categrories);
|
bool set_category(QList<Categrory>& categrories);
|
||||||
bool get_all_software(QList<Record> &softwares,int category);
|
bool get_all_software(QList<Record> &softwares,int category);
|
||||||
|
bool get_a_software(QString orig_name, Record2 *record);
|
||||||
QSqlDatabase db;
|
QSqlDatabase db;
|
||||||
|
|
||||||
~SQLiteHelper();
|
~SQLiteHelper();
|
||||||
|
|
Loading…
Reference in New Issue