コード例 #1
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
        ui->setupUi(this);

        setFixedSize(750, 500); // 窗口大小
        ui->stackedWidget->setCurrentIndex(0);

        QSqlQueryModel *typeModel = new QSqlQueryModel(this);
        typeModel->setQuery("select name from type");
        ui->sellTypeComboBox->setModel(typeModel);

        QSplitter *splitter = new QSplitter(ui->managePage);
        splitter->resize(700, 360);
        splitter->move(0, 50);

        splitter->addWidget(ui->toolBox);
        splitter->addWidget(ui->dailyList);
        splitter->setStretchFactor(0, 1);
        splitter->setStretchFactor(1, 1);

        on_sellCancelBtn_clicked();

        showDailyList();
}
コード例 #2
0
// 出售商品的确定按钮
void Widget::on_sellOkBtn_clicked()
{
        QString type = ui->sellTypeComboBox->currentText();
        QString name = ui->sellBrandComboBox->currentText();
        int value = ui->sellNumSpinBox->value();
        // cellNumSpinBox的最大值就是以前的剩余量
        int last = ui->sellNumSpinBox->maximum() - value;

        QSqlQuery query;

        // 获取以前的销售量
        query.exec(QString("select sell from brand where name='%1' and type='%2'")
                           .arg(name).arg(type));
        query.next();
        int sell = query.value(0).toInt() + value;

        // 事务操作
        QSqlDatabase::database().transaction();
        bool rtn = query.exec(
                    QString("update brand set sell=%1,last=%2 where name='%3' and type='%4'")
                    .arg(sell).arg(last).arg(name).arg(type));

        if (rtn) {
                QSqlDatabase::database().commit();
                QMessageBox::information(this, tr("提示"), tr("购买成功!"), QMessageBox::Ok);
                writeXml();
                showDailyList();
                on_sellCancelBtn_clicked();
        } else {
                QSqlDatabase::database().rollback();
        }
}
コード例 #3
0
// 出售商品的商品类型改变时
void Widget::on_sellTypeComboBox_currentIndexChanged(QString type)
{
        if (type == "请选择类型") {
                // 进行其他部件的状态设置
                on_sellCancelBtn_clicked();
        } else {
                ui->sellBrandComboBox->setEnabled(true);
                QSqlQueryModel *model = new QSqlQueryModel(this);
                model->setQuery(QString("select name from brand where type='%1'").arg(type));
                ui->sellBrandComboBox->setModel(model);
                ui->sellCancelBtn->setEnabled(true);
        }
}
コード例 #4
0
ファイル: widget.cpp プロジェクト: JasonDean-1/Qt-Training
void Widget::on_sellBrandComboBox_currentIndexChanged(const QString &arg1)
{
    if(arg1=="请选择厂家")
    {
        on_sellCancelBtn_clicked();

    }
    else
    {
        ui->sellBrandComboBox->setEditable(true);
        QSqlQueryModel *model=new QSqlQueryModel(this);
        model->setQuery(QString("select name from brand where factory='%1'").arg(arg1));
        ui->sellBrandComboBox->setModel(model);
        ui->sellCancelBtn->setEnabled(true);
    }

}