QT 商品入库与出库(库存管理系统)

商品入库

cpp 复制代码
void GoodsWarehousing::InitComboBoxFunc() // 初始化Combo box控件
{
    int i=0;
    QSqlQuery sqlQuery;
    sqlQuery.exec("SELECT * FROM commoditydatatable");

    QString StrId;

    while(sqlQuery.next())
    {
        StrId=sqlQuery.value(0).toString();
        ui->comboBox_Id->insertItem(i,StrId);
        i++;
    }

}
cpp 复制代码
void GoodsWarehousing::on_pushButton_InputGoods_clicked()
{
    // 获取Combo Box控件里面的值
    QString StrCBId=ui->comboBox_Id->currentText();


    // 判断商品入库的数量是否为空
    if(ui->lineEdit_Amount->text().isEmpty())
    {
        QMessageBox::critical(this,"提示","商品入库的数量不能为空,请重新检查?");
        ui->lineEdit_Amount->setFocus();
        return;
    }

    // 设计SQL查询语句条件
    // SQL查询 SELECT * FROM commoditydatatable where StockId=1001

    QSqlQuery sqlquery;
    QString strid="StockId=";
    strid+=StrCBId;

    QString str=QString("SELECT * FROM commoditydatatable where %1").arg(strid);
    sqlquery.exec(str);
    // QMessageBox::critical(this,"提示",str);

    // 获取数据表中的商品编号对应的数量
    int i=0;
    QString strAmount;
    while(sqlquery.next())
    {
        strAmount=sqlquery.value(2).toString();
        // QMessageBox::information(this,"提示",strAmount);
    }


    // 将输入数量+数量表当中的数量
    int inputamount=ui->lineEdit_Amount->text().toInt(); // 用户输入数量
    int tableamount=strAmount.toUInt(); // 数据表里面的数量转换为整型
    int isum=inputamount+tableamount; // 实现相加

    // int 转换QString
    QString strresult=QString::number(isum);

    // 更新数据表中数量字段的值
    QString strdb=QString("update commoditydatatable set stockamount=%1 where %2").arg(strresult).arg(strid);

    if(sqlquery.exec(strdb))
    {
        QMessageBox::information(this,"提示","恭喜你,商品入库成功!");
    }
    else
    {
        QMessageBox::critical(this,"提示","对不起,商品入库失败,请重新检查?");
    }


}

商品出库

cpp 复制代码
void GoodsDelivery::on_pushButton_OutputGoods_clicked()
{
    // 获取Combo Box控件里面的值
    QString StrCBId=ui->comboBox_Id->currentText();


    // 判断商品入库的数量是否为空
    if(ui->lineEdit_Amount->text().isEmpty())
    {
        QMessageBox::critical(this,"提示","商品出库的数量不能为空,请重新检查?");
        ui->lineEdit_Amount->setFocus();
        return;
    }

    // 设计SQL查询语句条件
    // SQL查询 SELECT * FROM commoditydatatable where StockId=1001

    QSqlQuery sqlquery;
    QString strid="StockId=";
    strid+=StrCBId;

    QString str=QString("SELECT * FROM commoditydatatable where %1").arg(strid);
    sqlquery.exec(str);
    // QMessageBox::critical(this,"提示",str);

    // 获取数据表中的商品编号对应的数量
    int i=0;
    QString strAmount;
    while(sqlquery.next())
    {
        strAmount=sqlquery.value(2).toString();
        // QMessageBox::information(this,"提示",strAmount);
    }


    // 将输入数量+数量表当中的数量
    int inputamount=ui->lineEdit_Amount->text().toInt(); // 用户输入数量
    int tableamount=strAmount.toUInt(); // 数据表里面的数量转换为整型
    int isum=tableamount-inputamount; // 实现相加

    // int 转换QString
    QString strresult=QString::number(isum);

    // 更新数据表中数量字段的值
    QString strdb=QString("update commoditydatatable set stockamount=%1 where %2").arg(strresult).arg(strid);

    if(sqlquery.exec(strdb))
    {
        QMessageBox::information(this,"提示","恭喜你,商品出库成功!");
    }
    else
    {
        QMessageBox::critical(this,"提示","对不起,商品出库失败,请重新检查?");
    }

}
相关推荐
Y4090012 分钟前
C语言转Java语言,相同与相异之处
java·c语言·开发语言·笔记
古月-一个C++方向的小白5 小时前
C++11之lambda表达式与包装器
开发语言·c++
沐知全栈开发6 小时前
Eclipse 生成 jar 包
开发语言
杭州杭州杭州7 小时前
Python笔记
开发语言·笔记·python
tanyongxi667 小时前
C++ AVL树实现详解:平衡二叉搜索树的原理与代码实现
开发语言·c++
阿葱(聪)8 小时前
java 在k8s中的部署流程
java·开发语言·docker·kubernetes
浮生带你学Java9 小时前
2025Java面试题及答案整理( 2025年 7 月最新版,持续更新)
java·开发语言·数据库·面试·职场和发展
斯是 陋室9 小时前
在CentOS7.9服务器上安装.NET 8.0 SDK
运维·服务器·开发语言·c++·c#·云计算·.net
李长渊哦9 小时前
深入理解Java中的Map.Entry接口
java·开发语言
koooo~10 小时前
JavaScript中的Window对象
开发语言·javascript·ecmascript