#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
static bool createConnection()
{
db.setDatabaseName("frezen");
db.setHostName("localhost");
db.setUserName("jan");
db.setPassword("asdfgh");
if (!db.open()) {
("Unable to establish a database connection.\n") + db.lastError().text());
return false;
}
query.exec("create table frezen (materiaal varchar(20), treksterkte varchar(20),"
"freestype varchar(20), freesdiameter varchar(20), aantaltanden varchar(20),"
"koeling varchar(10), freesbewerking varchar(20), snijsnelheid varchar(20),"
"voedingpertand varchar(20), snedediepte varchar(10), snedebreedte varchar(10))");
return true;
}
#endif
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("frezen");
db.setHostName("localhost");
db.setUserName("jan");
db.setPassword("asdfgh");
if (!db.open()) {
QMessageBox::warning(0, ("Cannot open database"),
("Unable to establish a database connection.\n") + db.lastError().text());
return false;
}
QSqlQuery query;
query.exec("create table frezen (materiaal varchar(20), treksterkte varchar(20),"
"freestype varchar(20), freesdiameter varchar(20), aantaltanden varchar(20),"
"koeling varchar(10), freesbewerking varchar(20), snijsnelheid varchar(20),"
"voedingpertand varchar(20), snedediepte varchar(10), snedebreedte varchar(10))");
return true;
}
#endif
To copy to clipboard, switch view to plain text mode
#include <QtGui>
#include <QtSql>
#include <QSqlError>
#include <QSqlRecord>
#include "frezen.h"
#include "frees.h"
{
model->setTable(frezen);
model->setSort(1, Qt::DescendingOrder);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Materiaal"));
model->setHeaderData(1, Qt::Horizontal, tr("Treksterkte"));
model->setHeaderData(2, Qt::Horizontal, tr("Frees type"));
model->setHeaderData(3, Qt::Horizontal, tr("Frees diameter"));
model->setHeaderData(4, Qt::Horizontal, tr("Aantal tanden"));
model->setHeaderData(5, Qt::Horizontal, tr("Koeling"));
model->setHeaderData(6, Qt::Horizontal, tr("Frees bewerking"));
model->setHeaderData(7, Qt::Horizontal, tr("Snijsnelheid"));
model->setHeaderData(8, Qt::Horizontal, tr("Voeding per tand"));
model->setHeaderData(9, Qt::Horizontal, tr("Snedediepte"));
model->setHeaderData(10, Qt::Horizontal, tr("Snedebreedte"));
view->setModel(model);
submitButton->setDefault(true);
connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(addButton, SIGNAL(clicked()), this, SLOT(setData()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
buttonLayout->addWidget(addButton);
buttonLayout->addWidget(removeButton);
buttonLayout->addWidget(submitButton);
buttonLayout->addStretch(1);
buttonLayout->addWidget(quitButton);
mainLayout->addWidget(view);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Frezen"));
resize (400, 400);
}
void Frezen::submit()
{
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
} else {
model->database().rollback();
tr("The database reported an error: %1")
.arg(model->lastError().text()));
}
}
void Frezen::setData()
{
freesDialog dlg(this);
if( dlg.
exec() == QDialog::Accepted ) {
QString materiaal
= dlg.
matComboBox->currentText
();
QString treksterkte
= dlg.
trekComboBox->currentText
();
QString freestype
= dlg.
freesComboBox->currentText
();
QString freesdiameter
= dlg.
diaComboBox->currentText
();
QString aantaltanden
= dlg.
tandComboBox->currentText
();
QString koeling
= dlg.
koelComboBox->currentText
();
QString freesbewerking
= dlg.
freesbComboBox->currentText
();
QString snijsnelheid
= dlg.
snijComboBox->currentText
();
QString voedingpertand
= dlg.
voedingComboBox->currentText
();
QString snedediepte
= dlg.
snedeComboBox->currentText
();
QString snedebreedte
= dlg.
snedebComboBox->currentText
();
model->insertRows(0, 1);
model->setData(model->index(0, 0), materiaal);
model->setData(model->index(0, 1), treksterkte);
model->setData(model->index(0, 2), freestype);
model->setData(model->index(0, 3), freesdiameter);
model->setData(model->index(0, 4), aantaltanden);
model->setData(model->index(0, 5), koeling);
model->setData(model->index(0, 6), freesbewerking);
model->setData(model->index(0, 7), snijsnelheid);
model->setData(model->index(0, 8), voedingpertand);
model->setData(model->index(0, 9), snedediepte);
model->setData(model->index(0, 10), snedebreedte);
return;
}
}
void Frezen::deleteRow()
{
}
#include <QtGui>
#include <QtSql>
#include <QSqlError>
#include <QSqlRecord>
#include "frezen.h"
#include "frees.h"
Frezen::Frezen(const QString &frezen, QWidget *parent)
: QDialog(parent)
{
model = new QSqlTableModel(this);
model->setTable(frezen);
model->setSort(1, Qt::DescendingOrder);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Materiaal"));
model->setHeaderData(1, Qt::Horizontal, tr("Treksterkte"));
model->setHeaderData(2, Qt::Horizontal, tr("Frees type"));
model->setHeaderData(3, Qt::Horizontal, tr("Frees diameter"));
model->setHeaderData(4, Qt::Horizontal, tr("Aantal tanden"));
model->setHeaderData(5, Qt::Horizontal, tr("Koeling"));
model->setHeaderData(6, Qt::Horizontal, tr("Frees bewerking"));
model->setHeaderData(7, Qt::Horizontal, tr("Snijsnelheid"));
model->setHeaderData(8, Qt::Horizontal, tr("Voeding per tand"));
model->setHeaderData(9, Qt::Horizontal, tr("Snedediepte"));
model->setHeaderData(10, Qt::Horizontal, tr("Snedebreedte"));
QTableView *view = new QTableView;
view->setModel(model);
addButton = new QPushButton("Toevoegen");
removeButton = new QPushButton(" Verwijderen");
submitButton = new QPushButton(tr("Submit"));
submitButton->setDefault(true);
quitButton = new QPushButton("Afsluiten");
connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(addButton, SIGNAL(clicked()), this, SLOT(setData()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout->addWidget(addButton);
buttonLayout->addWidget(removeButton);
buttonLayout->addWidget(submitButton);
buttonLayout->addStretch(1);
buttonLayout->addWidget(quitButton);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Frezen"));
resize (400, 400);
}
void Frezen::submit()
{
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
} else {
model->database().rollback();
QMessageBox::warning(this, tr("frezen"),
tr("The database reported an error: %1")
.arg(model->lastError().text()));
}
}
void Frezen::setData()
{
freesDialog dlg(this);
if( dlg.exec() == QDialog::Accepted ) {
QString materiaal = dlg.matComboBox->currentText();
QString treksterkte = dlg.trekComboBox->currentText();
QString freestype = dlg.freesComboBox->currentText();
QString freesdiameter = dlg.diaComboBox->currentText();
QString aantaltanden= dlg.tandComboBox->currentText();
QString koeling = dlg.koelComboBox->currentText();
QString freesbewerking = dlg.freesbComboBox->currentText();
QString snijsnelheid = dlg.snijComboBox->currentText();
QString voedingpertand = dlg.voedingComboBox->currentText();
QString snedediepte = dlg.snedeComboBox->currentText();
QString snedebreedte = dlg.snedebComboBox->currentText();
model->insertRows(0, 1);
model->setData(model->index(0, 0), materiaal);
model->setData(model->index(0, 1), treksterkte);
model->setData(model->index(0, 2), freestype);
model->setData(model->index(0, 3), freesdiameter);
model->setData(model->index(0, 4), aantaltanden);
model->setData(model->index(0, 5), koeling);
model->setData(model->index(0, 6), freesbewerking);
model->setData(model->index(0, 7), snijsnelheid);
model->setData(model->index(0, 8), voedingpertand);
model->setData(model->index(0, 9), snedediepte);
model->setData(model->index(0, 10), snedebreedte);
return;
}
}
void Frezen::deleteRow()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks