Example #1
1
void Database::deactivateUser(QString &userName)
{
    QSqlTableModel model;
    model.setTable("user");
    model.select();

    for (int i=0; i<model.rowCount(); ++i)
    {
        QSqlRecord record = model.record(i);
        if (record.value("name").toString()==userName)
        {
            record.setValue("isActive", false);
            model.setRecord(i, record);
            model.submitAll();
            break;
        }
    }
}
Example #2
0
void simplePerson::setData(QString idx, QString tableName)
{
    QSqlTableModel model;
    model.setTable(tableName);
    model.setFilter(QString("id = %1").arg(idx));
    model.select();

    id = model.data(model.index(0,0)).toString();
    surname = model.data(model.index(0,1)).toString();
    name = model.data(model.index(0,2)).toString();
    patronimic = model.data(model.index(0,3)).toString();;
}
QString TableSchema::primaryKeyFieldName() const
{
    QSqlTableModel model;
    model.setTable(tablename);
    QSqlIndex index = model.primaryKey();
    if (index.isEmpty()) {
        return QString();
    }

    QSqlField fi = index.field(0);
    return fi.name();
}
SelectSysSwitchDlg::SelectSysSwitchDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SelectSysSwitchDlg)
{
    ui->setupUi(this);

    QSqlTableModel *modelTable = new QSqlTableModel(this);
    modelTable->setTable("tableSysSwitchCard");
    modelTable->select();

    ui->tableView->setModel(modelTable);
}
Example #5
0
void DataViewer::onDatabaseItemActivated(const DatabaseItem &item)
{
    if ((DatabaseItem::Table != item.m_type) &&
            (DatabaseItem::View != item.m_type))
    {
        return;
    }

    d_ptr->database = item.m_database;

    // for table tableShema
    QSqlRecord record = item.m_database.record(item.m_value);

    d_ptr->m_shemaModel->removeRows(0, d_ptr->m_shemaModel->rowCount());
    d_ptr->m_shemaModel->insertRows(0, record.count());

    for (int i = 0; i < record.count(); ++i)
    {
        QSqlField field = record.field(i);

        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 0), field.name());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 1),
                              field.type() == QVariant::Invalid ? "???" : QString(QVariant::typeToName(field.type())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 2),
                              (field.length() < 0) ? QVariant("???") : field.length());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 3),
                              (field.precision() < 0) ? QVariant("???") : field.precision());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 4),
                              field.requiredStatus() == QSqlField::Unknown ? "???" : QVariant(bool(field.requiredStatus())));
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 5), field.isAutoValue());
        d_ptr->m_shemaModel->setData(d_ptr->m_shemaModel->index(i, 6), field.defaultValue());
    }

    d_ptr->m_tableShema->setModel(d_ptr->m_shemaModel.data());
    d_ptr->m_tableShema->setEditTriggers(QAbstractItemView::NoEditTriggers);
    d_ptr->m_tableShema->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Scheme, tr(::c_schemeTable).arg(item.m_value));

    // for table tableData
    QSqlTableModel *modelData = new QSqlTableModel(0, item.m_database);
    modelData->setEditStrategy(QSqlTableModel::OnRowChange);
    modelData->setTable(item.m_value);
    modelData->select();

    d_ptr->m_tableData->setModel(modelData);
    d_ptr->m_tableData->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
    d_ptr->m_tableData->resizeColumnsToContents();

    d_ptr->m_tab->setTabText(::Data, tr(::c_dataTable).arg(item.m_value));

    d_ptr->m_sqlDataModel.reset(modelData);
}
void FormGestioneFerie::on_pbAggiungiPermesso_clicked()
{
    for(QDate a=ui->dePermessiDal->date(); a.operator <=( ui->dePermessiAl->date());a= a.addDays(1) )
   {

    qDebug() << "Permesso per "+ui->cbMatricola->currentText()+" per il giorno "+a.toString("dd/MM/yyyy");


    QSqlQuery query;
    query.prepare("INSERT INTO assenze (ID, matricola, causa, data)" "VALUES (?, ?, ?, ?)");
   // query.addBindValue( ui->cbMatricola->currentText()+"_"+ui->dePermessiDal->date().toString("dd/MM/yyyy"));
    query.addBindValue( ui->cbMatricola->currentText()+"_"+a.toString("dd/MM/yyyy"));
    query.addBindValue( ui->cbMatricola->currentText());
    query.addBindValue( ui->cbTipoPermesso->currentText());
   // query.addBindValue( ui->dePermessiDal->date().toString("dd/MM/yyyy"));
    query.addBindValue( a.toString("dd/MM/yyyy"));
    if(query.exec())
    {
        QMessageBox msgBox;
        msgBox.setText("Inserzione nel database.");
        msgBox.setInformativeText(QString("Permesso per il giorno %1 inserito correttamente.").arg(a.toString("dd/MM/yyyy")));
        msgBox.setStandardButtons(QMessageBox::Ok );
        msgBox.setIcon(QMessageBox::Information);
        msgBox.exec();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setText("Inserzione nel database.");
        msgBox.setInformativeText(QString("Permesso per il giorno %1 NON inserito nel database. Probabilmente è gia stato inserito un permesso per lo stesso giorno.").arg(a.toString("dd/MM/yyyy")));
        msgBox.setStandardButtons(QMessageBox::Ok );
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.exec();
    }

    QSqlTableModel *model = new QSqlTableModel(this, this->db);
    model->setTable("assenze");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    model->setFilter(QString("Matricola=\"%1\"").arg(ui->cbMatricola->currentText()));

    model->sort(2,Qt::AscendingOrder);
      model->setHeaderData(1, Qt::Horizontal, tr("MATRICOLA"));
      model->setHeaderData(2, Qt::Horizontal, tr("DATA"));
      model->setHeaderData(3, Qt::Horizontal, tr("CAUSA"));
      ui->tvPermessi->setModel(model);
      ui->tvPermessi->hideColumn(0);
      ui->tvPermessi->resizeColumnsToContents();
      ui->tvPermessi->resizeRowsToContents();
      ui->tvPermessi->selectRow(0);

  }
}
int TableSchema::primaryKeyIndex() const
{
    QSqlTableModel model;
    model.setTable(tablename);
    QSqlIndex index = model.primaryKey();
    if (index.isEmpty()) {
        return -1;
    }

    QSqlField fi = index.field(0);
    return model.record().indexOf(fi.name());
}
Example #8
0
void Form::afficherDoss()
{
    QSqlTableModel  *model = new QSqlTableModel ();
    model->setTable("info");
    model->select();


    ui->treeView->setModel( model );
    ui->treeView->setColumnHidden(0,true);
    ui->treeView->show();


}
Example #9
0
QSqlTableModel* Dbconnect::select(QString table,QString filter)
{
    qDebug("selectDataSQL");
    QSqlTableModel *model = new QSqlTableModel;
    QString tbName = Db::tbPrefix;
    model->setTable(tbName.append(table));
    if("" != filter){
        model->setFilter(filter);
    }
    model->select();
    qDebug("-------%d",model->rowCount());
    return model;
}
Example #10
0
//插入一条记录
void
Widget::CStudentDialog::insertRecord()
{
    bool ok;
    QString name = m_pNameEdit->text();
    QString Sex = m_pSexEdit->text();
    double age = m_pAgeEdit->text().toDouble( &ok );
    if( !ok ){
        QMessageBox::warning( this , "错误" , "请重新填写年龄" );
        return;
    }
    QString number = m_pNumberEdit->text();
    QString post = m_pPostEdit->text();
    QSqlTableModel table;
    table.setTable( "person" );
    table.select();

    QSqlRecord record;
    record = table.record();
    record.setValue( "name" , name );
    record.setValue( "gender" , Sex );
    record.setValue( "age" , age );
    ok = table.insertRecord( -1, record );
    if( !ok ){
        AddStudentError
    }


    table.submitAll();
    table.setTable( "person" );
    table.setFilter( tr("name = '%0'").arg( name ) );
    qDebug() << table.select();
    int id = table.record(0).value( Enum::PersonSection::Person_id ).toInt( &ok );
    if( !ok ){
        table.removeRow( 0 );
        table.submitAll();
        AddStudentError
    }
Example #11
0
void partner::setUpdate(QString idt)
{
	QSqlTableModel model;
	model.setTable("Partner");
	model.setFilter(QString("id = %1").arg(idt));
	model.select();
	id = model.data(model.index(0,0)).toInt();
	ui->nameEdit->setText(model.data(model.index(0,1)).toString());
	ui->surnameEdit->setText(model.data(model.index(0,2)).toString());
	ui->patronimicEdit->setText(model.data(model.index(0,3)).toString());
	ui->passportEdit->setText(model.data(model.index(0,4)).toString());
	ui->phoneEdit->setText(model.data(model.index(0,5)).toString());
	mode = updateMode;
}
Example #12
0
void FormPerson::loadLayout(QString tableName)
{
    // Recupero link al database
    QSqlDatabase db = QSqlDatabase::database("ConnectionToDB");
    // Creo un modello sche si riferirà alla tabella delle mail
    QSqlTableModel *model = new QSqlTableModel(this, db);

    // Imposto la tabella a cui si riferirà il modello
    model->setTable(tableName);
    // Imposto un filtro sulla persona a cui la tabella è collegata
    model->setFilter("id_person=" + QString::number(this->personId));
    model->select();

    // Per ciascuna riga della tabella...
    for (int i=0; i<model->rowCount(); i++)
    {
        QHBoxLayout *hbl = new QHBoxLayout();

        // Creo un nuovo oggetto QLineEdit
        QLineEdit *qlineedit = new QLineEdit();
        // Creo un pulsante per la successiva rimozione dell'entry nel database
        RemoveRowFromModel *button = new RemoveRowFromModel(i, model, tableName);
        // Collego il pulante alla funzione di refresh
        QObject::connect(button, SIGNAL(rowRemoved(QString)), this, SLOT(refreshLayout(QString)));

        // Creo un mapper
        QDataWidgetMapper *mapperEmailPerson = new QDataWidgetMapper();

        // Collego al mapper il modello della tabella
        mapperEmailPerson->setModel(model);
        // Aggiungo un mapping tra l'oggetto QLineEdit e il modello
        mapperEmailPerson->addMapping(qlineedit, 1);
        // Posiziono il mapper sull'indice opportuno
        mapperEmailPerson->setCurrentIndex(i);

        // Inserisco il mapper nella lista dei mapper per le email
        getQDataWidgetMapperList(tableName)->append(mapperEmailPerson);



        // qlineedit e button, li visualizzo sulla stessa riga (li inserisco in un layout orizzontale)
        hbl->addWidget(qlineedit);
        hbl->addWidget(button);
        // Inserisco il layout orizzontale nel layout delle mail
        getVerticalLayout(tableName)->addLayout(hbl);

        // Collego il pulsante ad uno slot, in modo che venga gestita la rimozione di una riga dal
        // modello
    }
}
Example #13
0
void Control::printNeighbor()
{
    QString whichID = ui->comboBox_5->currentText();
    QSqlTableModel* model = new QSqlTableModel(this);
    model->setTable("Distance");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setFilter("CellID1="+whichID+" and distance<=2 order by distance asc");
    model->setHeaderData(1,Qt::Horizontal,tr("邻居"));
    model->setHeaderData(2,Qt::Horizontal,tr("距离(千米)"));
    model->select();
    ui->tableView->setModel(model);
    ui->tableView->show();
    ui->tableView->setColumnHidden(model->fieldIndex("CellID1"),true);
}
Example #14
0
void QSqlTableModel_snippets()
{
//! [24]
    QSqlTableModel *model = new QSqlTableModel(parentObject, database);
    model->setTable("employee");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    model->setHeaderData(1, Qt::Horizontal, tr("Salary"));

    QTableView *view = new QTableView;
    view->setModel(model);
    view->hideColumn(0); // don't show the ID
    view->show();
//! [24]

    {
//! [25]
    QSqlTableModel model;
    model.setTable("employee");
    QString name = model.record(4).value("name").toString();
//! [25]
    }
}
Example #15
0
void Browser::showTable(const QString &t)
{
    QSqlTableModel *model = new QSqlTableModel(table, connectionWidget->currentDatabase());
    model->setEditStrategy(QSqlTableModel::OnRowChange);
    model->setTable(t);
    model->select();
    if (model->lastError().type() != QSqlError::NoError)
        emit statusMessage(model->lastError().text());
    table->setModel(model);
    table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);

    connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
            this, SLOT(currentChanged()));
    updateActions();
}
Example #16
0
/*----------根据污染元筛选查询数据库-------------*/
void DataDialog::on_nameList_currentIndexChanged(const QString &arg1)
{
    //建立code和name的对应关系方便显示
    mapCodeName mCodeName[] =
    {{"1_voltage","电压"}, {"1_light","光照"}, {"1_a01001","温度"}, {"1_a01002","湿度"},
     {"2_a01001_e","外部温度"}, {"2_a01001_i","内部温度"}, {"2_a06003","PH"}, {"2_a06001","雨量"},
     {"2_a01007","风速"}, {"2_a01008","风向"}, {"2_voltage","电源电压"}, {"2_a06002","是否降雨"},
     {"3_a01001_30","温度(30cm)"}, {"3_a01002_30","湿度(30cm)"}, {"3_a01001_15","温度(15cm)"},
     {"3_a01002_15","湿度(15cm)"}, {"3_a01001_05","温度(5cm)"}, {"3_a01002_05","湿度(5cm)"},
     {"4_a01001","温度"}, {"4_a01002","湿度"}, {"4_w01008_v","垂直盐分"}, {"4_w01008_s","表面盐分"}};
    enum {LENGTH_M = 22};
    QMap<QString,QString>nameCode;

    for(int i = 0; i < LENGTH_M; i++)
    {
        nameCode.insert(tr(mCodeName[i].name),mCodeName[i].code);
    }

    QSqlTableModel *m = new QSqlTableModel(this);
    if(arg1==tr("全部"))
    {
        on_pushButton_clicked();
        return ;
    }

    else
    {

    QSqlQuery query;

    query.exec("drop view if exists temp1");

    QString sql = QString("create view temp1 as(select id,name,dimen,gatewayNo,sensorNo,time,value from scalardata where code = '%1')").arg(nameCode[arg1]);
    qDebug() << "sql = " << sql;
    query.exec(sql);

    m->setTable("temp1");
    m->select();
    m->setHeaderData(0,Qt::Horizontal,tr("编号"));
    m->setHeaderData(1,Qt::Horizontal,tr("标量名称"));
    m->setHeaderData(2,Qt::Horizontal,tr("标量单位"));
    m->setHeaderData(3,Qt::Horizontal,tr("网关编号"));
    m->setHeaderData(4,Qt::Horizontal,tr("传感器编号"));
    m->setHeaderData(5,Qt::Horizontal,tr("检测时间"));
    m->setHeaderData(6,Qt::Horizontal,tr("检测值"));
    ui->tableView->setModel(m);
    }
}
/*!
    Returns a QSqlTableModel object for accessing the table for which
    \a column is a foreign key, or 0 if there is no relation for the
    given \a column.

    The returned object is owned by the QSqlRelationalTableModel.

    \sa setRelation(), relation()
*/
QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const
{
    Q_D(const QSqlRelationalTableModel);
    QRelation relation = d->relations.value(column);
    if (!relation.rel.isValid())
        return 0;

    QSqlTableModel *childModel = relation.model;
    if (!childModel) {
        childModel = new QSqlTableModel(const_cast<QSqlRelationalTableModel *>(this), database());
        childModel->setTable(relation.rel.tableName());
        childModel->select();
        d->relations[column].model = childModel;
    }
    return childModel;
}
Example #18
0
// Leggo dal database le infomazioni "principali" relative alla persona this->personId
// e le rappresento tramite dei QLineEdit
void FormPerson::loadDb()
{
    // De-alloco eventuali model precedentemente creati
    QAbstractItemModel *modelToDelete =  this->mapperPersonData->model();
    delete(this->mapperPersonData);
    delete(modelToDelete);
    this->mapperPersonData = new QDataWidgetMapper();

    // Reference al database
    QSqlDatabase db = QSqlDatabase::database("ConnectionToDB");
    // Creazione di un modello ...
    QSqlTableModel *model = new QSqlTableModel(this, db);

    // ... che si riferisca alla tabella persons
    model->setTable("persons");
    // Imposto un filtro per lavorare su this->personId
    model->setFilter("id=" + QString::number(this->personId));
    // Eseguo la query
    model->select();


    // Associo al mapper il model
    this->mapperPersonData->setModel(model);

    // Eseguo il mapping dei campi del modello con i rispettivi campi di editing

    // Nome della Persona
    this->mapperPersonData->addMapping(this->ui->lineEdit_personName, 3);

    // Nickname della persona
    this->mapperPersonData->addMapping(this->ui->lineEdit_personNickname, 4);

    // Azienda in cui lavora la persona
    this->mapperPersonData->addMapping(this->ui->lineEdit_personComapny, 6 );

    // Titolo o ruolo svolto all'interno dell'azienda
    this->mapperPersonData->addMapping(this->ui->lineEdit_personTitle, 2);

    // Note associate alla persona
    this->mapperPersonData->addMapping(this->ui->textEdit_note, 7);

    this->mapperPersonData->toFirst();


    // Elementi da de-allocare:
    // model
}
Example #19
0
bool MaterialSaverDB::saveTemplate( StockMaterial *mat )
{
    bool res = true;

    // Transaktion ?

    QSqlTableModel model;
    model.setTable("stockMaterial");
    QString templID = QString::number( mat->getID() );
    model.setFilter( "matID=" + templID );
    model.select();

    QSqlRecord buffer = model.record();

    if( model.rowCount() > 0)
    {
        kDebug() << "Updating material " << mat->getID() << endl;

        // mach update
        buffer = model.record(0);
        fillMaterialBuffer( buffer, mat, false );
        model.setRecord(0, buffer);
        model.submitAll();
    }
    else
    {
        // insert
        kDebug() << "Creating new material database entry" << endl;

        fillMaterialBuffer( buffer, mat, true );
        model.insertRecord(-1, buffer);
        model.submitAll();

        /* Jetzt die neue Template-ID selecten */
        dbID id = KraftDB::self()->getLastInsertID();
        kDebug() << "New Database ID=" << id.toInt() << endl;

        if( id.isOk() ) {
            mat->setID( id.toInt() );
            templID = id.toString();
        } else {
            kDebug() << "ERROR: Kann AUTOINC nicht ermitteln" << endl;
            res = false;
        }
    }
    return res;
}
Example #20
0
//------------------Above Date--------------------------
void Liveinfo::UpdateRoom(int RoomNum,int change)
{
	QSqlTableModel * updateroom = new QSqlTableModel;		//修改已入住的房间
	updateroom->setTable("Room");
	updateroom->select();	
	for(int i = 0;i < updateroom->rowCount(); ++i)
	{		
		QSqlRecord Roomrecord = updateroom->record(i);
		int check_room = Roomrecord.value("Num").toInt();
		if( check_room == RoomNum )
		{
			Roomrecord.setValue("Live",change);
			updateroom->setRecord(i, Roomrecord);
		}
	}		
	updateroom->submitAll();
}
Example #21
0
void ListPc::updateUI(){
    QSqlTableModel *model = new QSqlTableModel(this, QSqlDatabase::database());
    model->setTable("pc");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select();
    model->setHeaderData(0, Qt::Horizontal, tr("ID"));
    model->setHeaderData(1, Qt::Horizontal, tr("Processzor"));
    model->setHeaderData(2, Qt::Horizontal, tr("Memórie"));
    model->setHeaderData(3, Qt::Horizontal, tr("Merevlemez"));
    model->setHeaderData(4, Qt::Horizontal, tr("Operációs rendszer"));
    model->setHeaderData(5, Qt::Horizontal, tr("Megjegyzés"));


    ui->tableView_listpc->setModel(model);
    ui->tableView_listpc->hideColumn(0);
    ui->tableView_listpc->resizeColumnsToContents();
}
Example #22
0
openProjectMenu::openProjectMenu(QWidget *parent) :
    QWidget(parent)
    //m_ui(new Ui::openProjectMenu())
{
    //m_ui->setupUi(this);

    this->setWindowTitle("Open...");
    projectsList = new QTableView;
    okButton = new QPushButton("OK");
    okButton->setEnabled(false);
    cancelButton = new QPushButton("Cancel");
    //connectToDatabase();

    QSqlTableModel* model = new QSqlTableModel;

    projectsList->setEditTriggers(QAbstractItemView::NoEditTriggers);
    projectsList->setModel( model );
    model->setTable("projects");
    model->select();
    //model->setQuery("SELECT melUnitName, fortUnitName FROM unitNets WHERE isPlaced IS NOT NULL AND isPlaced != 1");
    projectsList->setSortingEnabled(1);
    projectsList->hideColumn(0);
    //projectsList->hideColumn(0);
    projectsList->resizeColumnsToContents();
    projectsList->show();

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(okButton,1,0);
    layout->addWidget(cancelButton,1,1);

    layout->addWidget(projectsList,0,0,1,0);



    this->setLayout(layout);


    connect(projectsList, SIGNAL(clicked(QModelIndex)), this, SLOT(on_projectsList_clicked(QModelIndex)));
    //connect(cancelButton, SIGNAL(clicked()), this, this->close());
    connect(okButton, SIGNAL(clicked()), this, SLOT(on_okButton_clicked()));
    //connect(okButton, SIGNAL(clicked()),


    this->resize(800, 500);
}
void Widget::on_withdraw_clicked()
{
    QSqlTableModel model;
    model.setTable("bankaccount");
    model.setFilter(tr("bankaccountnumber = '%1'").arg(name));
    model.select();
    int f = model.record(0).value("frozen").toInt();
    if(f==0)
    {
        withdraw withdrawinterface(name);
        withdrawinterface.exec();
    }
    else
    {
        QMessageBox::warning(NULL, "注意","您的账户已冻结!该操作已被禁止。");
    }

}
Example #24
0
void AdminDialog::initBookTableView()
{
    QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
    model->setTable("book");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select(); //选取整个表的所有行
    model->setHeaderData(0,Qt::Horizontal,"图书编号");
    model->setHeaderData(1,Qt::Horizontal,"书名");
    model->setHeaderData(2,Qt::Horizontal,"作者");
    model->setHeaderData(3,Qt::Horizontal,"出版社");
    model->setHeaderData(4,Qt::Horizontal,"出版日期");
    model->setHeaderData(5,Qt::Horizontal,"价格");
    model->setHeaderData(6,Qt::Horizontal,"类型");
    model->setHeaderData(7,Qt::Horizontal,"总数量");
    model->setHeaderData(8,Qt::Horizontal,"在馆数");
    ui->tv1->setModel(model);
    ui->tv1->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
Example #25
0
void AdminDialog::initBorrowTableView()
{
    QSqlTableModel *model = new QSqlTableModel(this,Tool::getInstance()->getDb());
    model->setTable("borrow");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->select(); //选取整个表的所有行
    model->setFilter("isreturn=0");
    model->removeColumn(model->columnCount()-1);
    model->removeColumn(model->columnCount()-1);
    model->setHeaderData(0,Qt::Horizontal,"借阅编号");
    model->setHeaderData(1,Qt::Horizontal,"图书编号");
    model->setHeaderData(2,Qt::Horizontal,"读者编号");
    model->setHeaderData(3,Qt::Horizontal,"剩余续借次数");
    model->setHeaderData(4,Qt::Horizontal,"借阅时间");
    model->setHeaderData(5,Qt::Horizontal,"应还时间");
    ui->tv3->setModel(model);
    ui->tv3->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
Example #26
0
void mainWindow::setupComboBox()
{
    QSqlTableModel* m = new QSqlTableModel();
    m->setTable("Consoles");
    m->removeColumn(0);
    m->select();

    QStringList list;

    for(int i = 0; i < m->rowCount(); i++)
    {
        list.append(m->record(i).value(0).toString());
    }
    list.removeDuplicates();
    list.sort();
    ui->comboConsole->clear();
    ui->comboConsole->addItems(list);
}
Example #27
0
void Database::saveLevel(QString &userName, int level)
{
    QSqlTableModel model;
    model.setTable("user");
    model.select();

    for (int i=0; i<model.rowCount(); ++i)
    {
        QSqlRecord record = model.record(i);
        if (record.value("name").toString()==userName)
        {
            record.setValue("level", level);
            model.setRecord(i, record);
            model.submitAll();
            break;
        }
    }
}
Example #28
0
void MainWindow::viewTable()
{
    QString table;
    //table = "SELECT * FROM '";
    table.append(ui->viewEdit->text());
    //table.append("'");
    
    //dbQuery.exec(table);
    
    QSqlTableModel * tmodel = new QSqlTableModel;
    tmodel->setTable(table);
    tmodel->select();
    tmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    
    tview = new QTableView;
    tview->setModel(tmodel);
    tview->show();
}
Example #29
0
void Database::saveXP(QString &userName, int xp)
{
    QSqlTableModel model;
    model.setTable("user");
    model.select();

    for (int i=0; i<model.rowCount(); ++i)
    {
        QSqlRecord record = model.record(i);
        if (record.value("name").toString()==userName)
        {
            record.setValue("experiencePoints", xp);
            model.setRecord(i, record);
            model.submitAll();
            break;
        }
    }
}
Example #30
0
int Database::loadXP(QString &userName) const
{
    int exp;
    QSqlTableModel model;
    model.setTable("user");
    model.select();

    for (int i=0; i<model.rowCount(); ++i)
    {
        QSqlRecord record = model.record(i);
        if (record.value("name").toString()==userName)
        {
            exp = record.value("experiencePoints").toInt();
            break;
        }
    }
    return exp;
}