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

}
相关推荐
mjhcsp37 分钟前
MATLAB 疑难问题诊疗:从常见报错到深度优化的全流程指南
开发语言·matlab
Lynnxiaowen44 分钟前
今天我们开始学习python语句和模块
linux·运维·开发语言·python·学习
逐步前行1 小时前
C标准库--浮点<float.h>
c语言·开发语言
zoyation1 小时前
多线程简介和在JAVA中应用
java·开发语言
余辉zmh1 小时前
【C++篇】:ServiceBus RPC 分布式服务总线框架项目
开发语言·c++·rpc
Tony Bai1 小时前
释放 Go 的极限潜能:CPU 缓存友好的数据结构设计指南
开发语言·后端·缓存·golang
Main. 242 小时前
从0到1学习Qt -- 创建项目
qt
仲夏幻境2 小时前
js利用ajax同步调用如何
开发语言·javascript·ajax
aramae2 小时前
详细分析平衡树--红黑树(万字长文/图文详解)
开发语言·数据结构·c++·笔记·算法
一百天成为python专家2 小时前
python爬虫入门(小白五分钟从入门到精通)
开发语言·爬虫·python·opencv·yolo·计算机视觉·正则表达式