#ifndef SUPPLY_H#define SUPPLY_H#include <QMainWindow>#include <QCloseEvent>#include <QVBoxLayout>#include <QButtonGroup>#include <QPushButton>#include <QLabel>#include <QKeySequence>#include <QSqlTableModel>#include <QDialog>class QTextEdit;class supply:public QDialog{ Q_OBJECTpublic: supply(); ~supply(); QVBoxLayout *body; void setStatus(const char*); QPushButton *addButton(const char *text,const QKeySequence &key);protected: void closeEvent(QCloseEvent *event);private slots: void about(); void documentWasModified(); void task_filter(); void stuff_filter(); void job_list(); void invoice(); private: void createStatusBar(); void readSettings(); void writeSettings(); bool maybeSave(); QString strippedName(const QString &fullFileName); QTextEdit *textEdit; QSqlTableModel *model; QString curFile; QHBoxLayout *buttons; QPushButton *buttonHelp; QPushButton *buttonCancel; QLabel *status; int button;};class TaskFilter:public QDialog{ Q_OBJECT public: TaskFilter(); ~TaskFilter(); QVBoxLayout *body; QHBoxLayout *buttons;};class StuffFilter:public QDialog{ Q_OBJECT public: StuffFilter(); ~StuffFilter(); QVBoxLayout *body; QHBoxLayout *buttons;};class Invoice:public QDialog{ Q_OBJECT public: Invoice(); ~Invoice(); QVBoxLayout *body; QHBoxLayout *buttons; private slots: void print();};class JobList:public QDialog{ Q_OBJECT public: JobList(); ~JobList(); QVBoxLayout *body; QHBoxLayout *buttons; private slots: void print();};#endif
#include <QtGui>#include <QHBoxLayout>#include <QtSql>#include "supply.h"Invoice::Invoice(){ int col=0; setWindowTitle(tr("%1").arg(tr("Supply - накладная"))); QVBoxLayout *mainLayout = new QVBoxLayout(); body = new QVBoxLayout(); mainLayout->addLayout(body); mainLayout->addSpacing(10); QSqlTableModel *model = new QSqlTableModel; model->setTable("invoice_new"); model->setEditStrategy(QSqlTableModel::OnRowChange); model->select(); model->setHeaderData(col++, Qt::Horizontal, tr("Заказ")); model->setHeaderData(col++, Qt::Horizontal, tr("Зад#")); model->setHeaderData(col++, Qt::Horizontal, tr("Поз")); model->setHeaderData(col++, Qt::Horizontal, tr("Обозначение")); model->setHeaderData(col++, Qt::Horizontal, tr("Наименование")); model->setHeaderData(col++, Qt::Horizontal, tr("Материал")); model->setHeaderData(col++, Qt::Horizontal, tr("Размер")); model->setHeaderData(col++, Qt::Horizontal, tr("Кол-во")); model->setHeaderData(col++, Qt::Horizontal, tr("Получатель")); QTableView *view = new QTableView(); view->setModel(model); view->show(); body->addWidget(view); buttons = new QHBoxLayout(); QPushButton *but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("Сохранить+Печатать")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( print() ) ); but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("Отмена")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( close() ) ); mainLayout->addLayout(buttons); setLayout(mainLayout);}Invoice::~Invoice(){}void Invoice::print(){ close();}
#include <QtGui>#include <QHBoxLayout>#include <QtSql>#include "supply.h"#include <QSqlQuery>JobList::JobList(){ int col=0; setWindowTitle(tr("%1").arg(tr("Supply - задание"))); QVBoxLayout *mainLayout = new QVBoxLayout(); body = new QVBoxLayout(); mainLayout->addLayout(body); mainLayout->addSpacing(10);// mainLayout->addStretch(10); QSqlQuery query; query.exec("delete from job_list_new"); query.exec("insert into job_list_new (ordernum,tasknum,position,nick,name,stuff_name,stuff_size,qty,jobqty) (select ordernum,tasknum,position,nick,name,'','',qty,qty from tasklist)"); QSqlTableModel *model = new QSqlTableModel; model->setTable("job_list_new"); model->setEditStrategy(QSqlTableModel::OnRowChange); model->select(); model->setHeaderData(col++, Qt::Horizontal, tr("Заказ")); model->setHeaderData(col++, Qt::Horizontal, tr("Зад#")); model->setHeaderData(col++, Qt::Horizontal, tr("Поз")); model->setHeaderData(col++, Qt::Horizontal, tr("Обозначение")); model->setHeaderData(col++, Qt::Horizontal, tr("Наименование")); model->setHeaderData(col++, Qt::Horizontal, tr("Материал")); model->setHeaderData(col++, Qt::Horizontal, tr("Размер")); model->setHeaderData(col++, Qt::Horizontal, tr("Кол-во надо")); model->setHeaderData(col++, Qt::Horizontal, tr("Кол-во сделать")); QTableView *view = new QTableView(); view->setModel(model); view->show(); body->addWidget(view); buttons = new QHBoxLayout(); QPushButton *but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("Печатать ярлыки")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( print() ) ); but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("Отмена")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( close() ) ); mainLayout->addLayout(buttons); setLayout(mainLayout);}JobList::~JobList(){}void JobList::print(){ close();}
#include <QApplication>#include <QMessageBox>#include <QTextCodec>#include <QSqlDatabase>#include <QSqlError> #include <QSqlQuery> #include "supply.h"int initdb() { QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setDatabaseName("chaos");// QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");// db.setDatabaseName(":memory:"); if (!db.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information how " "to build it.\n\n" "Click Cancel to exit."), QMessageBox::Cancel); return false; } return true;}int main(int argc, char *argv[]){// Q_INIT_RESOURCE(application); QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF8")); initdb(); supply * mw = new supply(); mw->show(); return app.exec();}
#include <QtGui>#include <QHBoxLayout>#include <QtSql>#include "supply.h"StuffFilter::StuffFilter(){ int col=0; setWindowTitle(tr("%1").arg(tr("Supply - материалы"))); QVBoxLayout *mainLayout = new QVBoxLayout(); body = new QVBoxLayout(); mainLayout->addLayout(body); mainLayout->addSpacing(10);// mainLayout->addStretch(10); QSqlTableModel *model = new QSqlTableModel; model->setTable("stuff_filter"); model->setEditStrategy(QSqlTableModel::OnRowChange); model->select(); model->setHeaderData(col++, Qt::Horizontal, tr("Код")); model->setHeaderData(col++, Qt::Horizontal, tr("Наименование")); QTableView *view = new QTableView(); view->setModel(model); view->show(); body->addWidget(view); buttons = new QHBoxLayout(); QPushButton *but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("OK")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( close() ) ); mainLayout->addLayout(buttons); setLayout(mainLayout);}StuffFilter::~StuffFilter(){}
#include <QtGui>#include "supply.h"#include <QCloseEvent>#include <QGroupBox>#include <QGridLayout>#include <QHBoxLayout>#include <QList>#include <QtSql>#include <QIcon>supply::supply(){ QHBoxLayout *hlay; QLabel *label; QPushButton *butt; int col=0; // textEdit = new QTextEdit;// setCentralWidget(textEdit); resize(800,600); setWindowTitle(tr("%1").arg(tr("Supply - снабжулики"))); setWindowIcon(QIcon("logo.gif")); QVBoxLayout *mainLayout = new QVBoxLayout(); body = new QVBoxLayout(); mainLayout->addLayout(body); mainLayout->addSpacing(10);// mainLayout->addStretch(10); hlay = new QHBoxLayout(); body->addLayout(hlay); label = new QLabel(tr("Фильтр по материалу"), this); hlay->addWidget(label); model = new QSqlTableModel; model->setTable("tasklist"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); model->setHeaderData(col++, Qt::Horizontal, tr("Заказ")); model->setHeaderData(col++, Qt::Horizontal, tr("Зад#")); model->setHeaderData(col++, Qt::Horizontal, tr("Поз")); model->setHeaderData(col++, Qt::Horizontal, tr("Обозначение")); model->setHeaderData(col++, Qt::Horizontal, tr("Наименование")); model->setHeaderData(col++, Qt::Horizontal, tr("Материал")); model->setHeaderData(col++, Qt::Horizontal, tr("Размер")); model->setHeaderData(col++, Qt::Horizontal, tr("Кол-во")); QTableView *view = new QTableView(); view->setModel(model); view->show(); body->addWidget(view); buttons = new QHBoxLayout(); buttonHelp = new QPushButton( "buttonHelp" ); buttonHelp->setText( tr("F1-Справка")); buttonHelp->setShortcut( Qt::Key_F1 ); buttonHelp->setFocusPolicy(Qt::NoFocus); connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( about() ) ); buttons->addWidget(buttonHelp); buttons->addStretch(10); buttonCancel = new QPushButton( "buttonCancel" ); buttonCancel->setText( tr("F10-Выход")); buttonCancel->setShortcut( Qt::Key_F10 ); buttonCancel->setFocusPolicy(Qt::NoFocus); buttons->addWidget(buttonCancel); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( close() ) ); mainLayout->addLayout(buttons); // createStatusBar(); // mainLayout->addSpacing(10); status = new QLabel( this ); setStatus("Слушаюсь и повинуюсь!!!"); status->setFrameStyle( QFrame::Panel | QFrame::Sunken ); status->setFixedHeight( status->sizeHint().height() ); status->setAlignment( Qt::AlignVCenter | Qt::AlignLeft ); mainLayout->addWidget( status );// topLayout->activate(); button=1; setLayout(mainLayout); butt=addButton("F2-Мат.Фильтр", Qt::Key_F2 ); connect( butt, SIGNAL( clicked() ), this, SLOT( stuff_filter() ) ); butt=addButton("F3-Зак.Фильтр", Qt::Key_F3 ); connect( butt, SIGNAL( clicked() ), this, SLOT( task_filter() ) ); butt=addButton("F4-Счета", Qt::Key_F4 ); connect( butt, SIGNAL( clicked() ), this, SLOT( job_list() ) ); butt=addButton("F5-Оприходование", Qt::Key_F5 ); connect( butt, SIGNAL( clicked() ), this, SLOT( invoice() ) );}void supply::task_filter(){ TaskFilter *w=new TaskFilter(); w->exec(); printf("tsk execed\n"); model->select();}void supply::stuff_filter(){ StuffFilter *w=new StuffFilter(); w->exec(); printf("st execed\n"); model->select();}void supply::job_list(){ JobList *w=new JobList(); w->exec(); printf("jl execed\n"); model->select();}void supply::invoice(){ Invoice *w=new Invoice(); w->exec(); printf("inv execed\n"); model->select();}QPushButton *supply::addButton(const char *text,const QKeySequence &key) { QPushButton *b; b = new QPushButton(this); b->setText( tr(text)); b->setShortcut( key ); b->setFocusPolicy(Qt::NoFocus); buttons->insertWidget(button++,b); return b;}void supply::setStatus(const char *m) { status->setText(tr(m));}void supply::closeEvent(QCloseEvent *event){ if (maybeSave()) { writeSettings(); event->accept(); } else { event->ignore(); }}void supply::about(){ QMessageBox::about(this, tr("About Application"), tr("<b>Supply v1.0</b> - рабочее место снабжения по металлу\n" "Copyright (C) 2008 by Олег Петькин"));}void supply::documentWasModified(){ setWindowModified(true);}void supply::createStatusBar(){ /* statusBar()->showMessage(tr("Слушаюсь и повинуюсь!!!"));*/}void supply::readSettings(){ QSettings settings("TybydymSteed", "supply"); QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); QSize size = settings.value("size", QSize(400, 400)).toSize(); resize(size); move(pos);}void supply::writeSettings(){ QSettings settings("TybydymSteed", "supply"); settings.setValue("pos", pos()); settings.setValue("size", size());}bool supply::maybeSave(){/* if (textEdit->document()->isModified()) { int ret = QMessageBox::warning(this, tr("supply"), tr("Документ был изменен.\n" "Хотите ли Вы сохранить изменения?"), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); if (ret == QMessageBox::Yes) return save(); else if (ret == QMessageBox::Cancel) return false;}*/ return true;}supply::~supply(){}
#include <QtGui>#include <QHBoxLayout>#include <QtSql>#include "supply.h"TaskFilter::TaskFilter(){// QHBoxLayout *hlay;// QLabel *label; int col=0; setWindowTitle(tr("%1").arg(tr("Supply - фильтрация"))); QVBoxLayout *mainLayout = new QVBoxLayout(); body = new QVBoxLayout(); mainLayout->addLayout(body); mainLayout->addSpacing(10);// mainLayout->addStretch(10); QSqlTableModel *model = new QSqlTableModel; model->setTable("task_filter"); model->setSort(0,Qt::AscendingOrder); model->setEditStrategy(QSqlTableModel::OnRowChange); model->select(); model->setHeaderData(col++, Qt::Horizontal, tr("Заказ")); model->setHeaderData(col++, Qt::Horizontal, tr("ПриорС")); model->setHeaderData(col++, Qt::Horizontal, tr("ПриорПо")); QTableView *view = new QTableView(); view->setModel(model); view->show(); body->addWidget(view); buttons = new QHBoxLayout(); QPushButton *but_ok = new QPushButton( "buttonCancel" ); but_ok->setText( tr("OK")); but_ok->setFocusPolicy(Qt::NoFocus); buttons->addWidget(but_ok); connect( but_ok, SIGNAL( clicked() ), this, SLOT( close() ) ); mainLayout->addLayout(buttons); setLayout(mainLayout);}TaskFilter::~TaskFilter(){}