支持导出 excel 表格
支持查看商品操作日志
支持高精度浮点运算
支持同一商品以不同价格入库
该软件已开源。
因预览版 可执行文件过大,所以上传到csdn
大家有问题,可以加我的QQ1653687969
源码目录结构:
源码目录结构:
部分代码:
ContentWidget::ContentWidget(QWidget *parent) :
QWidget(parent)
{
sql_x = -1;
sql_y = -1;
tab_page = true;
search_page = false;
if(!sqlInit(false)){
QMessageBox message(QMessageBox::NoIcon, "提示", "请先选中一件库存商品");
message.setIconPixmap(QPixmap(":/img/safe"));
message.exec();
return;
}
// configure = new Configure;
// configure->readconfigure();
excelengine = new ExcelEngine;
QThread* daemon_thread = new QThread;
excelengine->moveToThread(daemon_thread);
daemon_thread->start(QThread::IdlePriority);
// connect(this, SIGNAL(saveExecl(QMap)),excelengine, SIGNAL(signals_saveExecl(QMap)));
// saveExecl(product_table);
main_widget = new QWidget(this);
storage_table = new QTableWidget(this);
product_table = new QTableWidget(this);
gmpmath = new GmpMath;
setToolsWidget();
setProductTab();
setStorageTab();
setTabWidget();
tabShow();
QPalette palette;
tools_widget->setAutoFillBackground(true);
main_widget->setAutoFillBackground(true);
palette.setColor(QPalette::Background,QColor(155,225,123));
tools_widget->setPalette(palette);
tools_widget->setFixedHeight(75);
main_splitter = new QSplitter(this);
main_splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
main_splitter->setOrientation(Qt::Vertical);
main_splitter->setHandleWidth(0);
main_splitter->setStyleSheet("QSplitter::handle{background:lightgray;}");
main_splitter->addWidget(tools_widget);
// main_splitter->addWidget(left_widget);
main_splitter->addWidget(main_widget);
for(int i = 0; icount();i++)
{
QSplitterHandle *handle = main_splitter->handle(i);
handle->setEnabled(false);
}
qDebug() << "content_ widget ok";
QHBoxLayout *main_layout = new QHBoxLayout();
main_layout->addWidget(main_splitter);
main_layout->setSpacing(0);
main_layout->setContentsMargins(0, 0, 0, 0);
connect(btn_add, SIGNAL(clicked()),this, SLOT(addwidget()));
connect(btn_minus, SIGNAL(clicked()),this, SLOT(minuswidget()));
connect(btn_plus, SIGNAL(clicked()),this, SLOT(pluswidget()));
connect(btn_delete, SIGNAL(clicked()),this, SLOT(sqldelete()));
connect(btn_cancel, SIGNAL(clicked()),this, SLOT(sqlcancel()));
connect(btn_outinto, SIGNAL(clicked()),this, SLOT(saveas()));
setLayout(main_layout);
// slotStyleChange(0);
btnEnable(false);
}
现在跟大家介绍一下软件实现界面:
初始化数据库
主界面
#include "main_menu.h"
MainMenu::MainMenu(QWidget *widget)
: QMenu(widget)
{
this->createActions();
this->translateActions();
}
void MainMenu::createActions()
{
//创建菜单项
action_sqlinit = new QAction(this);
action_changepasswd = new QAction(this);
action_sqlinit->setIcon(QIcon("img/safe.png"));
//添加菜单项
this->addAction(action_sqlinit);
this->addAction(action_changepasswd);
//设置信号连接
QObject::connect(action_sqlinit, SIGNAL(triggered()), this, SIGNAL(sqlinit_signal()));
QObject::connect(action_changepasswd, SIGNAL(triggered()), this, SIGNAL(changepasswd_signal()));
}
void MainMenu::translateActions()
{
action_sqlinit->setText(tr("初始化数据库"));
action_changepasswd->setText(tr("修改管理员密码"));
}
入库
出库
搜索商品
商品操作详情
删除商品
导出excel 表格
#include "excelengine.h"
ExcelEngine::ExcelEngine(QObject *parent) :
QObject(parent)
{
pExcel = NULL;
pWorkbooks = NULL;
pWorkbook = NULL;
pWorksheet = NULL;
sXlsFile = "";
nRowCount = 0;
nColumnCount = 0;
nStartRow = 0;
nStartColumn = 0;
bIsOpen = false;
bIsValid = false;
bIsANewFile = false;
bIsSaveAlready = false;
HRESULT r = OleInitialize(0);
if (r != S_OK && r != S_FALSE)
{
qDebug("Qt: Could not initialize OLE (error %x)", (unsigned int)r);
}
// connect(this, SIGNAL(signals_saveExecl(QMap)),this, SLOT(saveExecl(QMap)));
}
ExcelEngine::ExcelEngine(QString xlsFile)
{
pExcel = NULL;
pWorkbooks = NULL;
pWorkbook = NULL;
pWorksheet = NULL;
sXlsFile = xlsFile;
nRowCount = 0;
nColumnCount = 0;
nStartRow = 0;
nStartColumn = 0;
bIsOpen = false;
bIsValid = false;
bIsANewFile = false;
bIsSaveAlready = false;
HRESULT r = OleInitialize(0);
if (r != S_OK && r != S_FALSE)
{
qDebug("Qt: Could not initialize OLE (error %x)", (unsigned int)r);
}
}
ExcelEngine::~ExcelEngine()
{
if ( bIsOpen )
{
//析构前,先保存数据,然后关闭workbook
Close();
}
OleUninitialize();
}
/**
*@brief 打开sXlsFile指定的excel报表
*@return true : 打开成功
* false: 打开失败
*/
bool ExcelEngine::Open(UINT nSheet, bool visible)
{
if ( bIsOpen )
{
//return bIsOpen;
Close();
}
nCurrSheet = nSheet;
bIsVisible = visible;
if ( NULL == pExcel )
{
pExcel = new QAxObject("Excel.Application");
if ( pExcel )
{
bIsValid = true;
}
else
{
bIsValid = false;
bIsOpen = false;
return bIsOpen;
}
pExcel->dynamicCall("SetVisible(bool)", bIsVisible);
}
if ( !bIsValid )
{
bIsOpen = false;
return bIsOpen;
}
if ( sXlsFile.isEmpty() )
{
bIsOpen = false;
return bIsOpen;
}
/*如果指向的文件不存在,则需要新建一个*/
QFile f(sXlsFile);
if (!f.exists())
{
bIsANewFile = true;
}
else
{
bIsANewFile = false;
}
if (!bIsANewFile)
{
pWorkbooks = pExcel->querySubObject("WorkBooks"); //获取工作簿
pWorkbook = pWorkbooks->querySubObject("Open(QString, QVariant)",sXlsFile,QVariant(0)); //打开xls对应的工作簿
}
else
{
pWorkbooks = pExcel->querySubObject("WorkBooks"); //获取工作簿
pWorkbooks->dynamicCall("Add"); //添加一个新的工作薄
pWorkbook = pExcel->querySubObject("ActiveWorkBook"); //新建一个xls
}
pWorksheet = pWorkbook->querySubObject("WorkSheets(int)", nCurrSheet);//打开第一个sheet
//至此已打开,开始获取相应属性
QAxObject *usedrange = pWorksheet->querySubObject("UsedRange");//获取该sheet的使用范围对象
QAxObject *rows = usedrange->querySubObject("Rows");
QAxObject *columns = usedrange->querySubObject("Columns");
//因为excel可以从任意行列填数据而不一定是从0,0开始,因此要获取首行列下标
nStartRow = usedrange->property("Row").toInt(); //第一行的起始位置
nStartColumn = usedrange->property("Column").toInt(); //第一列的起始位置
nRowCount = rows->property("Count").toInt(); //获取行数
nColumnCount = columns->property("Count").toInt(); //获取列数
bIsOpen = true;
return bIsOpen;
}
/**
*@brief Open()的重载函数
*/
bool ExcelEngine::Open(QString xlsFile, UINT nSheet, bool visible)
{
sXlsFile = xlsFile;
nCurrSheet = nSheet;
bIsVisible = visible;
return Open(nCurrSheet,bIsVisible);
}
void ExcelEngine::saveExecl(QMap tmp)
{
if(!Open("test.xls",1,false))
qDebug() << "open xls error";
qDebug() << "ExcelEngine::saveExecl";
if(!SaveDataFrTable(tmp[1])){
qDebug() << "output execl error";
}
this->Close();
// if(!excelengine->Open("test.xls",1,false))
// qDebug() << "open xls error";
}
/**
*@brief 保存表格数据,把数据写入文件
*/
void ExcelEngine::Save()
{
if ( pWorkbook )
{
if (bIsSaveAlready)
{
return ;
}
// qDebug() << "save as" << sXlsFile;
// pWorkbook->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",
// sXlsFile,56,QString(""),QString(""),false,false);
if (!bIsANewFile)
{
qDebug() << "Save is new file " << sXlsFile;
pWorkbook->dynamicCall("Save()");
}
else /*如果该文档是新建出来的,则使用另存为COM接口*/
{
qDebug() << "save as" << sXlsFile;
// pWorkbook->dynamicCall("SaveAs (const QString&)",
// "d:/code/svn/acanoe_brower/test.xls");
pWorkbook->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",
sXlsFile,56,QString(""),QString(""),false,false);
}
bIsSaveAlready = true;
}
}
/**
*@brief 关闭前先保存数据,然后关闭当前Excel COM对象,并释放内存
*/
void ExcelEngine::Close()
{
//关闭前先保存数据
Save();
if ( pExcel && pWorkbook )
{
pWorkbook->dynamicCall("Close(bool)", true);
pExcel->dynamicCall("Quit()");
delete pExcel;
pExcel = NULL;
bIsOpen = false;
bIsValid = false;
bIsANewFile = false;
bIsSaveAlready = true;
}
}
/**
*@brief 把tableWidget中的数据保存到excel中
*@param tableWidget : 指向GUI中的tablewidget指针
*@return 保存成功与否 true : 成功
* false: 失败
*/
bool ExcelEngine::SaveDataFrTable(QTableWidget *tableWidget)
{
if ( NULL == tableWidget )
{
return false;
}
if ( !bIsOpen )
{
return false;
}
int tableR = tableWidget->rowCount();
int tableC = tableWidget->columnCount();
//获取表头写做第一行
for (int i=0; ihorizontalHeaderItem(i) != NULL )
{
this->SetCellData(1,i+1,tableWidget->horizontalHeaderItem(i)->text());
}
}
//写数据
for (int i=0; iitem(i,j) != NULL )
{
this->SetCellData(i+2,j+1,tableWidget->item(i,j)->text());
}
}
}
qDebug() << " ExcelEngine::SaveDataFrTable " << sXlsFile;
//保存
Save();
return true;
}
/**
*@brief 从指定的xls文件中把数据导入到tableWidget中
*@param tableWidget : 执行要导入到的tablewidget指针
*@return 导入成功与否 true : 成功
* false: 失败
*/
bool ExcelEngine::ReadDataToTable(QTableWidget *tableWidget)
{
if ( NULL == tableWidget )
{
return false;
}
//先把table的内容清空
int tableColumn = tableWidget->columnCount();
tableWidget->clear();
for (int n=0; nremoveColumn(0);
}
int rowcnt = nStartRow + nRowCount;
int columncnt = nStartColumn + nColumnCount;
//获取excel中的第一行数据作为表头
QStringList headerList;
for (int n = nStartColumn; nquerySubObject("Cells(int,int)",nStartRow, n);
if ( cell )
{
headerList<dynamicCall("Value2()").toString();
}
}
//重新创建表头
tableWidget->setColumnCount(nColumnCount);
tableWidget->setHorizontalHeaderLabels(headerList);
//插入新数据
for (int i = nStartRow+1, r = 0; i < rowcnt; i++, r++ ) //行
{
tableWidget->insertRow(r); //插入新行
for (int j = nStartColumn, c = 0; j < columncnt; j++, c++ ) //列
{
QAxObject * cell = pWorksheet->querySubObject("Cells(int,int)", i, j );//获取单元格
//在r新行中添加子项数据
if ( cell )
{
tableWidget->setItem(r,c,new QTableWidgetItem(cell->dynamicCall("Value2()").toString()));
}
}
}
return true;
}
/**
*@brief 获取指定单元格的数据
*@param row : 单元格的行号
*@param column : 单元格的列号
*@return [row,column]单元格对应的数据
*/
QVariant ExcelEngine::GetCellData(UINT row, UINT column)
{
QVariant data;
QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
if ( cell )
{
data = cell->dynamicCall("Value2()");
}
return data;
}
/**
*@brief 修改指定单元格的数据
*@param row : 单元格的行号
*@param column : 单元格指定的列号
*@param data : 单元格要修改为的新数据
*@return 修改是否成功 true : 成功
* false: 失败
*/
bool ExcelEngine::SetCellData(UINT row, UINT column, QVariant data)
{
bool op = false;
QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
if ( cell )
{
QString strData = data.toString(); //excel 居然只能插入字符串和整型,浮点型无法插入
cell->dynamicCall("SetValue(const QVariant&)",strData); //修改单元格的数据
op = true;
}
else
{
op = false;
}
return op;
}
/**
*@brief 清空除报表之外的数据
*/
void ExcelEngine::Clear()
{
sXlsFile = "";
nRowCount = 0;
nColumnCount = 0;
nStartRow = 0;
nStartColumn = 0;
}
/**
*@brief 判断excel是否已被打开
*@return true : 已打开
* false: 未打开
*/
bool ExcelEngine::IsOpen()
{
return bIsOpen;
}
/**
*@brief 判断excel COM对象是否调用成功,excel是否可用
*@return true : 可用
* false: 不可用
*/
bool ExcelEngine::IsValid()
{
return bIsValid;
}
/**
*@brief 获取excel的行数
*/
UINT ExcelEngine::GetRowCount()const
{
return nRowCount;
}
/**
*@brief 获取excel的列数
*/
UINT ExcelEngine::GetColumnCount()const
{
return nColumnCount;
}
修改密码
#include
#include
#include
#include "about_us.h"
AboutUsDialog::AboutUsDialog(QWidget *parent,int index_tmp,QString name_tmp)
:QDialog(parent)
{
this->resize(520, 290);
index = index_tmp;
name = name_tmp;
qDebug() << index << name;
QPalette palette;
this->setAutoFillBackground(true);
palette.setColor(QPalette::Background,QColor(155,225,123));
this->setPalette(palette);
//初始化为未按下鼠标左键
mouse_press = false;
//设置标题栏隐藏
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
title_label = new QLabel();
title_icon_label = new QLabel();
title_info_label = new QLabel();
info_label = new QLabel();
version_label = new QLabel();
mummy_label = new QLabel();
copyright_label = new QLabel();
icon_label = new QLabel();
close_button = new PushButton();
ok_button = new QPushButton();
QPixmap title_pixmap(":/img/safe");
title_icon_label->setPixmap(title_pixmap);
title_icon_label->setFixedSize(16, 16);
title_icon_label->setScaledContents(true);
close_button->loadPixmap(":/sysButton/close");
title_label->setFixedHeight(30);
ok_button->setFixedSize(75, 25);
QPixmap pixmap(":/img/360safe");
icon_label->setPixmap(pixmap);
icon_label->setFixedSize(pixmap.size());
QFont title_info_font("微软雅黑", 20, QFont::Bold, false);
QHBoxLayout *input1 = new QHBoxLayout();
QHBoxLayout *input2 = new QHBoxLayout();
QHBoxLayout *input3 = new QHBoxLayout();
switch(index_tmp){
case 1:
{
QLabel *L_name = new QLabel(tr("商品名 "));
E_name = new QLineEdit;
QLabel *L_Price = new QLabel(tr("商品价格"));
E_Price = new QLineEdit;
QLabel *L_amount = new QLabel(tr("数量 "));
E_amount = new QLineEdit;
QLabel *L_person = new QLabel(tr("管理员 "));
E_person = new QLineEdit;
QLabel *L_sign = new QLabel(tr("签字人 "));
E_sign = new QLineEdit;
QLabel *L_remark = new QLabel(tr("备注 "));
E_remark = new QLineEdit;
input1->addWidget(L_name);
input1->addWidget(E_name);
input1->addWidget(L_Price);
input1->addWidget(E_Price);
input1->setSpacing(10);
input1->setContentsMargins(10, 0, 10, 0);
input2->addWidget(L_amount);
input2->addWidget(E_amount);
input2->addWidget(L_person);
input2->addWidget(E_person);
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
input3->addWidget(L_sign);
input3->addWidget(E_sign);
input3->addWidget(L_remark);
input3->addWidget(E_remark);
input3->setSpacing(10);
input3->setContentsMargins(10, 0, 10, 0);
break;
}
case 2:
{
QLabel *L_name = new QLabel(QString("商品 ") + name + " 出库");
L_name ->setFont(title_info_font);
E_name = new QLineEdit;
// QLabel *L_Price = new QLabel(tr("商品价格"));
// E_Price = new QLineEdit;
QLabel *L_amount = new QLabel(tr("数量 "));
E_amount = new QLineEdit;
QLabel *L_person = new QLabel(tr("管理员 "));
E_person = new QLineEdit;
QLabel *L_sign = new QLabel(tr("签字人 "));
E_sign = new QLineEdit;
QLabel *L_remark = new QLabel(tr("备注 "));
E_remark = new QLineEdit;
input1->addWidget(L_name);
// input1->addWidget(E_name);
// input1->addWidget(L_Price);
// input1->addWidget(E_Price);
input1->setSpacing(10);
input1->setContentsMargins(10, 0, 10, 0);
input2->addWidget(L_amount);
input2->addWidget(E_amount);
input2->addWidget(L_person);
input2->addWidget(E_person);
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
input3->addWidget(L_sign);
input3->addWidget(E_sign);
input3->addWidget(L_remark);
input3->addWidget(E_remark);
input3->setSpacing(10);
input3->setContentsMargins(10, 0, 10, 0);
break;
}
case 3:
{
QLabel *L_name = new QLabel(QString("商品 ") + name + " 入库");
L_name ->setFont(title_info_font);
E_name = new QLineEdit;
QSpacerItem *horizontalSpacer = new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum);
QLabel *L_Price = new QLabel(tr("入库价格"));
E_Price = new QLineEdit;
QLabel *L_amount = new QLabel(tr("数量 "));
E_amount = new QLineEdit;
QLabel *L_person = new QLabel(tr("管理员 "));
E_person = new QLineEdit;
QLabel *L_sign = new QLabel(tr("签字人 "));
E_sign = new QLineEdit;
QLabel *L_remark = new QLabel(tr("备注 "));
E_remark = new QLineEdit;
input1->addWidget(L_name);
// input1->addWidget(E_name);
input1->addItem(horizontalSpacer);
input1->addWidget(L_Price);
input1->addWidget(E_Price);
input1->setSpacing(10);
input1->setContentsMargins(10, 0, 10, 0);
input2->addWidget(L_amount);
input2->addWidget(E_amount);
input2->addWidget(L_person);
input2->addWidget(E_person);
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
input3->addWidget(L_sign);
input3->addWidget(E_sign);
input3->addWidget(L_remark);
input3->addWidget(E_remark);
input3->setSpacing(10);
input3->setContentsMargins(10, 0, 10, 0);
break;
}
case 4:
{
QLabel *L_name = new QLabel();
L_name->setText(name);
L_name ->setFont(title_info_font);
input2->addWidget(L_name);
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
break;
}
case 5:
{
QLabel *L_name = new QLabel();
L_name->setText("请输入管理员密码:");
L_name ->setFont(title_info_font);
E_Price = new QLineEdit;
input2->addWidget(L_name);
input2->addWidget(E_Price);
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
break;
}
case 6:
{
QLabel *L_name = new QLabel(tr("现在密码 "));
E_name = new QLineEdit;
QLabel *L_Price = new QLabel(tr("修改为 "));
E_Price = new QLineEdit;
QLabel *L_amount = new QLabel(tr("再次确认"));
E_amount = new QLineEdit;
input1->addWidget(L_name);
input1->addWidget(E_name);
input1->setSpacing(10);
input1->setContentsMargins(10, 0, 10, 0);
input2->addWidget(L_Price);
input2->addWidget(E_Price );
input2->setSpacing(10);
input2->setContentsMargins(10, 0, 10, 0);
input3->addWidget(L_amount);
input3->addWidget(E_amount);
input3->setSpacing(10);
input3->setContentsMargins(10, 0, 10, 0);
break;
}
default:
{
return;
}
}
QHBoxLayout *title_layout = new QHBoxLayout();
title_layout->addWidget(title_icon_label, 0, Qt::AlignVCenter);
title_layout->addWidget(title_label, 0, Qt::AlignVCenter);
title_layout->addStretch();
title_layout->addWidget(close_button, 0, Qt::AlignTop);
title_layout->setSpacing(5);
title_layout->setContentsMargins(10, 0, 5, 0);
QHBoxLayout *bottom_layout = new QHBoxLayout();
bottom_layout->addStretch();
bottom_layout->addWidget(ok_button);
bottom_layout->setSpacing(0);
bottom_layout->setContentsMargins(0, 0, 30, 20);
QVBoxLayout *main_layout = new QVBoxLayout();
main_layout->addLayout(title_layout);
main_layout->addStretch(); /// 添加格挡
main_layout->addLayout(input1);
main_layout->addStretch();
main_layout->addLayout(input2);
main_layout->addStretch();
main_layout->addLayout(input3);
main_layout->addStretch();
main_layout->addLayout(bottom_layout);
main_layout->setSpacing(0);
main_layout->setContentsMargins(0, 0, 0, 0);
setLayout(main_layout);
title_label->setStyleSheet("color:white;");
copyright_label->setStyleSheet("color:gray;");
title_info_label->setStyleSheet("color:rgb(30,170,60);");
info_label->setStyleSheet("color:rgb(30,170,60);");
ok_button->setStyleSheet("QPushButton{border:1px solid lightgray;background:rgb(230,230,230);}" "QPushButton:hover{border-color:green; background:transparent;}");
QFont info_font = info_label->font();
info_font.setBold(true);
info_label->setFont(info_font);
ok_button->setText(tr("OK"));
connect(ok_button, SIGNAL(clicked()), this, SLOT(getinput()));
connect(close_button, SIGNAL(clicked()), this, SLOT(hide()));
}
void AboutUsDialog::getinput()
{
QStringList tmp;
switch(index){
case 1:
{
if(E_amount->text().toInt() == 0 ){
E_amount->setText("数量必须为大于0的整数");
return;
}
if(E_Price->text().toFloat() <= 0 ){
E_Price->setText("单品价格必须是数字可以含小数");
return;
}
tmp.append(E_name->text());
tmp.append(E_Price->text());
tmp.append(E_amount->text());
tmp.append(E_person->text());
tmp.append(E_sign->text());
tmp.append(E_remark->text());
emit setinput(tmp,index);
break;
}
case 2:
if(E_amount->text().toInt() == 0 ){
E_amount->setText("数量必须为大于0的整数");
return;
}
tmp.append(name);
tmp.append(E_amount->text());
tmp.append(E_person->text());
tmp.append(E_sign->text());
tmp.append(E_remark->text());
emit setinput(tmp,index);
break;
case 3:
if(E_amount->text().toInt() == 0 ){
E_amount->setText("数量必须为大于0的整数");
return;
}
if(E_Price->text().toFloat() <= 0 ){
E_Price->setText("单品价格必须是数字可以含小数");
return;
}
tmp.append(name);
tmp.append(E_Price->text());
tmp.append(E_amount->text());
tmp.append(E_person->text());
tmp.append(E_sign->text());
tmp.append(E_remark->text());
emit setinput(tmp,index);
break;
case 5:
{
// QSqlQuery query;
// query.exec("create table sql_users_table (id integer primary key,user varchar(15),passwd varchar(100)");
int i = 0;
QSqlQuery querylist;
// qDebug() << querylist.exec(QString("select * from sql_users_table order by id desc"));
qDebug() << querylist.exec(QString("select * from sql_users_table where user_name=\"admin\"" ));
while(querylist.next())
{
i++;
if(querylist.value(2).toString() == E_Price->text()){
emit setinput(tmp,index);
}else {
E_Price->setText("密码错误");
return;
}
// tmp.v_id = querylist.value(0).toString();
// tmp.name = querylist.value(1).toString();
// tmp.state = querylist.value(2).toString();
// tmp.amount = querylist.value(3).toString();
// tmp.price = querylist.value(4).toString();
// tmp.total_price = querylist.value(5).toString();
// tmp.controller = querylist.value(6).toString();
// tmp.remark = querylist.value(7).toString();
// tmp.time = querylist.value(8).toString();
}
if(i == 0){
E_Price->setText("密码错误");
return;
}
break;
}
case 6:
{
int i = 0;
QSqlQuery querylist;
// qDebug() << querylist.exec(QString("select * from sql_users_table order by id desc"));
qDebug() << querylist.exec(QString("select * from sql_users_table where user_name=\"admin\"" ));
while(querylist.next())
{
i++;
if(querylist.value(2).toString() == E_name->text()){
if(E_Price->text() == E_amount->text()){
if(querylist.exec(QString("UPDATE sql_users_table SET user_passwd='" + E_Price->text() + "' WHERE user_name='admin'")))
{
qDebug() << "change passwd is crrect";
}else{
E_Price->setText("密码数据更新失败");
qDebug() << "change passwd is error";
return;
}
emit setinput(tmp,index);
}else {
E_amount->setText("输入不匹配,请重新输入");
return;
}
}else {
E_name->setText("密码错误");
return;
}
// tmp.v_id = querylist.value(0).toString();
// tmp.name = querylist.value(1).toString();
// tmp.state = querylist.value(2).toString();
// tmp.amount = querylist.value(3).toString();
// tmp.price = querylist.value(4).toString();
// tmp.total_price = querylist.value(5).toString();
// tmp.controller = querylist.value(6).toString();
// tmp.remark = querylist.value(7).toString();
// tmp.time = querylist.value(8).toString();
}
break;
}
default:
break;
}
this->close();
}
void AboutUsDialog::translateLanguage()
{
}
AboutUsDialog::~AboutUsDialog()
{
}
void AboutUsDialog::paintEvent(QPaintEvent *)
{
}
void AboutUsDialog::mousePressEvent( QMouseEvent * event )
{
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
mouse_press = true;
}
//窗口移动距离
move_point = event->globalPos() - pos();
}
void AboutUsDialog::mouseReleaseEvent(QMouseEvent *)
{
mouse_press = false;
}
void AboutUsDialog::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(mouse_press)
{
QPoint move_pos = event->globalPos();
move(move_pos - move_point);
}
}
##########################################################
欢迎广大学子交流嵌入式和安卓开发
aiku老师 微信号 :aiku868
微信公众平台:aiku嵌入式视频教程创科之龙
aiku老师QQ:1653687969
技术解答QQ群:234945702
aiku老师 微信号欢迎一起交流!(有任何问题都可以问我,随时解答问题。)
##########################################################
代码下载网盘:(免费下载学习)
第一期视频教程
链接:https://pan.baidu.com/s/1YAnAQVaIlnc2k1pkKzCCBg 密码:4gu6
第二期视频教程
接:https://pan.baidu.com/s/1QoyABxf6J1o6mtA8hjaa3Q 密码:7z01
第三期视频教程
链接:https://pan.baidu.com/s/1Jj6jqBQZC0CABW1kOqZU6A 密码:ox0l
##########################################################
##########################################################