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

}
相关推荐
心扬3 分钟前
python网络编程
开发语言·网络·python·tcp/ip
qq_4541757910 分钟前
c++学习-this指针
开发语言·c++·学习
尘浮72836 分钟前
60天python训练计划----day45
开发语言·python
sss191s41 分钟前
校招 java 面试基础题目及解析
java·开发语言·面试
sduwcgg1 小时前
python的numpy的MKL加速
开发语言·python·numpy
钢铁男儿1 小时前
Python 接口:从协议到抽象基 类(定义并使用一个抽象基类)
开发语言·python
暴力求解1 小时前
C++类和对象(上)
开发语言·c++·算法
让我们一起加油好吗2 小时前
【基础算法】枚举(普通枚举、二进制枚举)
开发语言·c++·算法·二进制·枚举·位运算
大锦终2 小时前
【C++】特殊类设计
开发语言·c++
Bruce_Liuxiaowei2 小时前
PHP文件包含漏洞详解:原理、利用与防御
开发语言·网络安全·php·文件包含