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,"提示","对不起,商品出库失败,请重新检查?");
    }

}
相关推荐
傻乐u兔6 小时前
C语言进阶————指针4
c语言·开发语言
大模型玩家七七6 小时前
基于语义切分 vs 基于结构切分的实际差异
java·开发语言·数据库·安全·batch
历程里程碑6 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
牛奔7 小时前
Go 如何避免频繁抢占?
开发语言·后端·golang
寻星探路11 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
lly20240612 小时前
Bootstrap 警告框
开发语言
2601_9491465313 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧13 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX13 小时前
服务异步通信
开发语言·后端·微服务·ruby
zmzb010313 小时前
C++课后习题训练记录Day98
开发语言·c++