├── GeneratedFiles ├── Debug │ ├── moc_navdelegate.cpp │ ├── moc_navmodel.cpp │ ├── moc_navview.cpp │ └── moc_test_navview.cpp ├── qrc_test_navview.cpp └── ui_test_navview.h ├── LoginDlg.pro ├── LoginDlg.pro.user ├── MyImages.qrc ├── README.md ├── addgoodtypedlg.cpp ├── addgoodtypedlg.h ├── addgoodtypedlg.ui ├── addpurchasedlg.cpp ├── addpurchasedlg.h ├── addpurchasedlg.ui ├── addsupplierdlg.cpp ├── addsupplierdlg.h ├── addsupplierdlg.ui ├── adduserdlg.cpp ├── adduserdlg.h ├── adduserdlg.ui ├── choicegoodsdlg.cpp ├── choicegoodsdlg.h ├── choicegoodsdlg.ui ├── collectdlg.cpp ├── collectdlg.h ├── collectdlg.ui ├── colordefines.h ├── config ├── configForAdmin.xml └── configForGeneral.xml ├── connection.h ├── goodsnumdelegate.cpp ├── goodsnumdelegate.h ├── histogramview.cpp ├── histogramview.h ├── ico.rc ├── images ├── IndexPage.png ├── addGoodsTypeHead.png ├── addSupplierHead.png ├── addUserHead.png ├── background.png ├── bottom.png ├── button.png ├── button_h.png ├── button_p.png ├── choiceDlgHeader.png ├── close.png ├── close_h.png ├── close_p.png ├── collectHeader.png ├── expand_normal.png ├── expand_selected.png ├── headimg.png ├── mainBottom.png ├── mainHeader.png ├── min.png ├── min_h.png ├── min_p.png ├── modifyUserHead.png ├── purchaseHeadpng.png ├── supplierHead.png ├── tableBack .jpg ├── tlHeaderImg.png ├── toolBoxImg.png ├── unexpand_normal.png └── unexpand_selected.png ├── logindlg.cpp ├── logindlg.h ├── logindlg.ui ├── main.cpp ├── mainform.cpp ├── mainform.h ├── mainform.ui ├── maskwidget.cpp ├── maskwidget.h ├── modifyuserdlg.cpp ├── modifyuserdlg.h ├── modifyuserdlg.ui ├── navdelegate.cpp ├── navdelegate.h ├── navmodel.cpp ├── navmodel.h ├── showinforlabel.cpp ├── showinforlabel.h ├── supermarket.ico ├── supplierdlg.cpp ├── supplierdlg.h ├── supplierdlg.ui └── widget image ├── 1.jpg ├── 10.png ├── 2.jpg ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.jpg /GeneratedFiles/Debug/moc_navdelegate.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'navdelegate.h' 3 | ** 4 | ** Created: Mon Jan 26 10:30:25 2015 5 | ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) 6 | ** 7 | ** WARNING! All changes made in this file will be lost! 8 | *****************************************************************************/ 9 | 10 | #include "../../navdelegate.h" 11 | #if !defined(Q_MOC_OUTPUT_REVISION) 12 | #error "The header file 'navdelegate.h' doesn't include ." 13 | #elif Q_MOC_OUTPUT_REVISION != 63 14 | #error "This file was generated using the moc from 4.8.4. It" 15 | #error "cannot be used with the include files from this version of Qt." 16 | #error "(The moc has changed too much.)" 17 | #endif 18 | 19 | QT_BEGIN_MOC_NAMESPACE 20 | static const uint qt_meta_data_NavDelegate[] = { 21 | 22 | // content: 23 | 6, // revision 24 | 0, // classname 25 | 0, 0, // classinfo 26 | 0, 0, // methods 27 | 0, 0, // properties 28 | 0, 0, // enums/sets 29 | 0, 0, // constructors 30 | 0, // flags 31 | 0, // signalCount 32 | 33 | 0 // eod 34 | }; 35 | 36 | static const char qt_meta_stringdata_NavDelegate[] = { 37 | "NavDelegate\0" 38 | }; 39 | 40 | void NavDelegate::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 41 | { 42 | Q_UNUSED(_o); 43 | Q_UNUSED(_id); 44 | Q_UNUSED(_c); 45 | Q_UNUSED(_a); 46 | } 47 | 48 | const QMetaObjectExtraData NavDelegate::staticMetaObjectExtraData = { 49 | 0, qt_static_metacall 50 | }; 51 | 52 | const QMetaObject NavDelegate::staticMetaObject = { 53 | { &QStyledItemDelegate::staticMetaObject, qt_meta_stringdata_NavDelegate, 54 | qt_meta_data_NavDelegate, &staticMetaObjectExtraData } 55 | }; 56 | 57 | #ifdef Q_NO_DATA_RELOCATION 58 | const QMetaObject &NavDelegate::getStaticMetaObject() { return staticMetaObject; } 59 | #endif //Q_NO_DATA_RELOCATION 60 | 61 | const QMetaObject *NavDelegate::metaObject() const 62 | { 63 | return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; 64 | } 65 | 66 | void *NavDelegate::qt_metacast(const char *_clname) 67 | { 68 | if (!_clname) return 0; 69 | if (!strcmp(_clname, qt_meta_stringdata_NavDelegate)) 70 | return static_cast(const_cast< NavDelegate*>(this)); 71 | return QStyledItemDelegate::qt_metacast(_clname); 72 | } 73 | 74 | int NavDelegate::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 75 | { 76 | _id = QStyledItemDelegate::qt_metacall(_c, _id, _a); 77 | if (_id < 0) 78 | return _id; 79 | return _id; 80 | } 81 | QT_END_MOC_NAMESPACE 82 | -------------------------------------------------------------------------------- /GeneratedFiles/Debug/moc_navmodel.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'navmodel.h' 3 | ** 4 | ** Created: Mon Jan 26 10:41:33 2015 5 | ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) 6 | ** 7 | ** WARNING! All changes made in this file will be lost! 8 | *****************************************************************************/ 9 | 10 | #include "../../navmodel.h" 11 | #if !defined(Q_MOC_OUTPUT_REVISION) 12 | #error "The header file 'navmodel.h' doesn't include ." 13 | #elif Q_MOC_OUTPUT_REVISION != 63 14 | #error "This file was generated using the moc from 4.8.4. It" 15 | #error "cannot be used with the include files from this version of Qt." 16 | #error "(The moc has changed too much.)" 17 | #endif 18 | 19 | QT_BEGIN_MOC_NAMESPACE 20 | static const uint qt_meta_data_NavModel[] = { 21 | 22 | // content: 23 | 6, // revision 24 | 0, // classname 25 | 0, 0, // classinfo 26 | 1, 14, // methods 27 | 0, 0, // properties 28 | 0, 0, // enums/sets 29 | 0, 0, // constructors 30 | 0, // flags 31 | 0, // signalCount 32 | 33 | // slots: signature, parameters, type, tag, flags 34 | 16, 10, 9, 9, 0x0a, 35 | 36 | 0 // eod 37 | }; 38 | 39 | static const char qt_meta_stringdata_NavModel[] = { 40 | "NavModel\0\0index\0Collapse(QModelIndex)\0" 41 | }; 42 | 43 | void NavModel::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 44 | { 45 | if (_c == QMetaObject::InvokeMetaMethod) { 46 | Q_ASSERT(staticMetaObject.cast(_o)); 47 | NavModel *_t = static_cast(_o); 48 | switch (_id) { 49 | case 0: _t->Collapse((*reinterpret_cast< const QModelIndex(*)>(_a[1]))); break; 50 | default: ; 51 | } 52 | } 53 | } 54 | 55 | const QMetaObjectExtraData NavModel::staticMetaObjectExtraData = { 56 | 0, qt_static_metacall 57 | }; 58 | 59 | const QMetaObject NavModel::staticMetaObject = { 60 | { &QAbstractListModel::staticMetaObject, qt_meta_stringdata_NavModel, 61 | qt_meta_data_NavModel, &staticMetaObjectExtraData } 62 | }; 63 | 64 | #ifdef Q_NO_DATA_RELOCATION 65 | const QMetaObject &NavModel::getStaticMetaObject() { return staticMetaObject; } 66 | #endif //Q_NO_DATA_RELOCATION 67 | 68 | const QMetaObject *NavModel::metaObject() const 69 | { 70 | return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; 71 | } 72 | 73 | void *NavModel::qt_metacast(const char *_clname) 74 | { 75 | if (!_clname) return 0; 76 | if (!strcmp(_clname, qt_meta_stringdata_NavModel)) 77 | return static_cast(const_cast< NavModel*>(this)); 78 | return QAbstractListModel::qt_metacast(_clname); 79 | } 80 | 81 | int NavModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 82 | { 83 | _id = QAbstractListModel::qt_metacall(_c, _id, _a); 84 | if (_id < 0) 85 | return _id; 86 | if (_c == QMetaObject::InvokeMetaMethod) { 87 | if (_id < 1) 88 | qt_static_metacall(this, _c, _id, _a); 89 | _id -= 1; 90 | } 91 | return _id; 92 | } 93 | QT_END_MOC_NAMESPACE 94 | -------------------------------------------------------------------------------- /GeneratedFiles/Debug/moc_navview.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'navview.h' 3 | ** 4 | ** Created: Mon Jan 26 10:30:25 2015 5 | ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) 6 | ** 7 | ** WARNING! All changes made in this file will be lost! 8 | *****************************************************************************/ 9 | 10 | #include "../../navview.h" 11 | #if !defined(Q_MOC_OUTPUT_REVISION) 12 | #error "The header file 'navview.h' doesn't include ." 13 | #elif Q_MOC_OUTPUT_REVISION != 63 14 | #error "This file was generated using the moc from 4.8.4. It" 15 | #error "cannot be used with the include files from this version of Qt." 16 | #error "(The moc has changed too much.)" 17 | #endif 18 | 19 | QT_BEGIN_MOC_NAMESPACE 20 | static const uint qt_meta_data_NavView[] = { 21 | 22 | // content: 23 | 6, // revision 24 | 0, // classname 25 | 0, 0, // classinfo 26 | 0, 0, // methods 27 | 0, 0, // properties 28 | 0, 0, // enums/sets 29 | 0, 0, // constructors 30 | 0, // flags 31 | 0, // signalCount 32 | 33 | 0 // eod 34 | }; 35 | 36 | static const char qt_meta_stringdata_NavView[] = { 37 | "NavView\0" 38 | }; 39 | 40 | void NavView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 41 | { 42 | Q_UNUSED(_o); 43 | Q_UNUSED(_id); 44 | Q_UNUSED(_c); 45 | Q_UNUSED(_a); 46 | } 47 | 48 | const QMetaObjectExtraData NavView::staticMetaObjectExtraData = { 49 | 0, qt_static_metacall 50 | }; 51 | 52 | const QMetaObject NavView::staticMetaObject = { 53 | { &QListView::staticMetaObject, qt_meta_stringdata_NavView, 54 | qt_meta_data_NavView, &staticMetaObjectExtraData } 55 | }; 56 | 57 | #ifdef Q_NO_DATA_RELOCATION 58 | const QMetaObject &NavView::getStaticMetaObject() { return staticMetaObject; } 59 | #endif //Q_NO_DATA_RELOCATION 60 | 61 | const QMetaObject *NavView::metaObject() const 62 | { 63 | return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; 64 | } 65 | 66 | void *NavView::qt_metacast(const char *_clname) 67 | { 68 | if (!_clname) return 0; 69 | if (!strcmp(_clname, qt_meta_stringdata_NavView)) 70 | return static_cast(const_cast< NavView*>(this)); 71 | return QListView::qt_metacast(_clname); 72 | } 73 | 74 | int NavView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 75 | { 76 | _id = QListView::qt_metacall(_c, _id, _a); 77 | if (_id < 0) 78 | return _id; 79 | return _id; 80 | } 81 | QT_END_MOC_NAMESPACE 82 | -------------------------------------------------------------------------------- /GeneratedFiles/Debug/moc_test_navview.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'test_navview.h' 3 | ** 4 | ** Created: Mon Jan 26 10:30:25 2015 5 | ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) 6 | ** 7 | ** WARNING! All changes made in this file will be lost! 8 | *****************************************************************************/ 9 | 10 | #include "../../test_navview.h" 11 | #if !defined(Q_MOC_OUTPUT_REVISION) 12 | #error "The header file 'test_navview.h' doesn't include ." 13 | #elif Q_MOC_OUTPUT_REVISION != 63 14 | #error "This file was generated using the moc from 4.8.4. It" 15 | #error "cannot be used with the include files from this version of Qt." 16 | #error "(The moc has changed too much.)" 17 | #endif 18 | 19 | QT_BEGIN_MOC_NAMESPACE 20 | static const uint qt_meta_data_test_NavView[] = { 21 | 22 | // content: 23 | 6, // revision 24 | 0, // classname 25 | 0, 0, // classinfo 26 | 0, 0, // methods 27 | 0, 0, // properties 28 | 0, 0, // enums/sets 29 | 0, 0, // constructors 30 | 0, // flags 31 | 0, // signalCount 32 | 33 | 0 // eod 34 | }; 35 | 36 | static const char qt_meta_stringdata_test_NavView[] = { 37 | "test_NavView\0" 38 | }; 39 | 40 | void test_NavView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 41 | { 42 | Q_UNUSED(_o); 43 | Q_UNUSED(_id); 44 | Q_UNUSED(_c); 45 | Q_UNUSED(_a); 46 | } 47 | 48 | const QMetaObjectExtraData test_NavView::staticMetaObjectExtraData = { 49 | 0, qt_static_metacall 50 | }; 51 | 52 | const QMetaObject test_NavView::staticMetaObject = { 53 | { &QMainWindow::staticMetaObject, qt_meta_stringdata_test_NavView, 54 | qt_meta_data_test_NavView, &staticMetaObjectExtraData } 55 | }; 56 | 57 | #ifdef Q_NO_DATA_RELOCATION 58 | const QMetaObject &test_NavView::getStaticMetaObject() { return staticMetaObject; } 59 | #endif //Q_NO_DATA_RELOCATION 60 | 61 | const QMetaObject *test_NavView::metaObject() const 62 | { 63 | return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; 64 | } 65 | 66 | void *test_NavView::qt_metacast(const char *_clname) 67 | { 68 | if (!_clname) return 0; 69 | if (!strcmp(_clname, qt_meta_stringdata_test_NavView)) 70 | return static_cast(const_cast< test_NavView*>(this)); 71 | return QMainWindow::qt_metacast(_clname); 72 | } 73 | 74 | int test_NavView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 75 | { 76 | _id = QMainWindow::qt_metacall(_c, _id, _a); 77 | if (_id < 0) 78 | return _id; 79 | return _id; 80 | } 81 | QT_END_MOC_NAMESPACE 82 | -------------------------------------------------------------------------------- /GeneratedFiles/ui_test_navview.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'test_navview.ui' 3 | ** 4 | ** Created: Mon Jan 26 10:25:58 2015 5 | ** by: Qt User Interface Compiler version 4.8.4 6 | ** 7 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 8 | ********************************************************************************/ 9 | 10 | #ifndef UI_TEST_NAVVIEW_H 11 | #define UI_TEST_NAVVIEW_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "navview.h" 25 | 26 | QT_BEGIN_NAMESPACE 27 | 28 | class Ui_test_NavViewClass 29 | { 30 | public: 31 | QWidget *centralWidget; 32 | QHBoxLayout *horizontalLayout; 33 | NavView *listView; 34 | QFrame *frame; 35 | QMenuBar *menuBar; 36 | QToolBar *mainToolBar; 37 | 38 | void setupUi(QMainWindow *test_NavViewClass) 39 | { 40 | if (test_NavViewClass->objectName().isEmpty()) 41 | test_NavViewClass->setObjectName(QString::fromUtf8("test_NavViewClass")); 42 | test_NavViewClass->resize(930, 650); 43 | centralWidget = new QWidget(test_NavViewClass); 44 | centralWidget->setObjectName(QString::fromUtf8("centralWidget")); 45 | horizontalLayout = new QHBoxLayout(centralWidget); 46 | horizontalLayout->setSpacing(0); 47 | horizontalLayout->setContentsMargins(0, 0, 0, 0); 48 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); 49 | listView = new NavView(centralWidget); 50 | listView->setObjectName(QString::fromUtf8("listView")); 51 | listView->setMaximumSize(QSize(200, 16777215)); 52 | listView->setFrameShape(QFrame::NoFrame); 53 | 54 | horizontalLayout->addWidget(listView); 55 | 56 | frame = new QFrame(centralWidget); 57 | frame->setObjectName(QString::fromUtf8("frame")); 58 | QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 59 | sizePolicy.setHorizontalStretch(0); 60 | sizePolicy.setVerticalStretch(0); 61 | sizePolicy.setHeightForWidth(frame->sizePolicy().hasHeightForWidth()); 62 | frame->setSizePolicy(sizePolicy); 63 | frame->setFrameShape(QFrame::StyledPanel); 64 | frame->setFrameShadow(QFrame::Raised); 65 | 66 | horizontalLayout->addWidget(frame); 67 | 68 | test_NavViewClass->setCentralWidget(centralWidget); 69 | menuBar = new QMenuBar(test_NavViewClass); 70 | menuBar->setObjectName(QString::fromUtf8("menuBar")); 71 | menuBar->setGeometry(QRect(0, 0, 930, 23)); 72 | test_NavViewClass->setMenuBar(menuBar); 73 | mainToolBar = new QToolBar(test_NavViewClass); 74 | mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); 75 | test_NavViewClass->addToolBar(Qt::TopToolBarArea, mainToolBar); 76 | 77 | retranslateUi(test_NavViewClass); 78 | 79 | QMetaObject::connectSlotsByName(test_NavViewClass); 80 | } // setupUi 81 | 82 | void retranslateUi(QMainWindow *test_NavViewClass) 83 | { 84 | test_NavViewClass->setWindowTitle(QApplication::translate("test_NavViewClass", "test_NavView", 0, QApplication::UnicodeUTF8)); 85 | } // retranslateUi 86 | 87 | }; 88 | 89 | namespace Ui { 90 | class test_NavViewClass: public Ui_test_NavViewClass {}; 91 | } // namespace Ui 92 | 93 | QT_END_NAMESPACE 94 | 95 | #endif // UI_TEST_NAVVIEW_H 96 | -------------------------------------------------------------------------------- /LoginDlg.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-08-25T19:49:56 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui sql xml 8 | 9 | CONFIG+=qaxcontainer 10 | 11 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 12 | 13 | TARGET = LoginDlg 14 | TEMPLATE = app 15 | 16 | SOURCES += main.cpp\ 17 | logindlg.cpp \ 18 | mainform.cpp \ 19 | showinforlabel.cpp \ 20 | goodsnumdelegate.cpp \ 21 | collectdlg.cpp \ 22 | choicegoodsdlg.cpp \ 23 | maskwidget.cpp \ 24 | addpurchasedlg.cpp \ 25 | supplierdlg.cpp \ 26 | addsupplierdlg.cpp \ 27 | navmodel.cpp \ 28 | navdelegate.cpp \ 29 | histogramview.cpp \ 30 | adduserdlg.cpp \ 31 | modifyuserdlg.cpp \ 32 | addgoodtypedlg.cpp 33 | 34 | HEADERS += logindlg.h \ 35 | mainform.h \ 36 | connection.h \ 37 | showinforlabel.h \ 38 | goodsnumdelegate.h \ 39 | collectdlg.h \ 40 | choicegoodsdlg.h \ 41 | maskwidget.h \ 42 | addpurchasedlg.h \ 43 | supplierdlg.h \ 44 | addsupplierdlg.h \ 45 | navmodel.h \ 46 | navdelegate.h \ 47 | histogramview.h \ 48 | adduserdlg.h \ 49 | modifyuserdlg.h \ 50 | addgoodtypedlg.h 51 | 52 | FORMS += logindlg.ui \ 53 | mainform.ui \ 54 | collectdlg.ui \ 55 | choicegoodsdlg.ui \ 56 | addpurchasedlg.ui \ 57 | supplierdlg.ui \ 58 | addsupplierdlg.ui \ 59 | adduserdlg.ui \ 60 | modifyuserdlg.ui \ 61 | addgoodtypedlg.ui 62 | 63 | RESOURCES += \ 64 | MyImages.qrc 65 | 66 | RC_FILE += ico.rc 67 | -------------------------------------------------------------------------------- /MyImages.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/close.png 4 | images/close_h.png 5 | images/close_p.png 6 | images/button.png 7 | images/button_h.png 8 | images/button_p.png 9 | images/tlHeaderImg.png 10 | images/min.png 11 | images/min_h.png 12 | images/min_p.png 13 | images/toolBoxImg.png 14 | images/bottom.png 15 | images/collectHeader.png 16 | images/choiceDlgHeader.png 17 | images/purchaseHeadpng.png 18 | images/background.png 19 | images/supplierHead.png 20 | images/addSupplierHead.png 21 | images/mainBottom.png 22 | images/mainHeader.png 23 | images/expand_normal.png 24 | images/expand_selected.png 25 | images/unexpand_normal.png 26 | images/unexpand_selected.png 27 | images/tableBack .jpg 28 | images/IndexPage.png 29 | images/addUserHead.png 30 | images/modifyUserHead.png 31 | images/addGoodsTypeHead.png 32 | images/headimg.png 33 | 34 | 35 | config/configForAdmin.xml 36 | config/configForGeneral.xml 37 | 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 基于qt4.8开发的商品销存管理系统,利用sqlite数据库引擎 2 | 各功能模块界面图如下: 3 | 4 | ![历史账单](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/1.jpg) 5 | 6 | ![登录界面](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/10.png) 7 | 8 | ![进货管理](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/2.jpg) 9 | 10 | ![修改用户](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/2.png) 11 | 12 | ![添加用户](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/3.png) 13 | 14 | ![用户信息](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/4.png) 15 | 16 | ![添加商品类别](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/5.png) 17 | 18 | ![商品信息管理](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/6.png) 19 | 20 | ![收银台](https://github.com/lidian53/Supermarket_Management_Based-on-Qt/blob/master/widget%20image/9.jpg) 21 | 22 | -------------------------------------------------------------------------------- /addgoodtypedlg.cpp: -------------------------------------------------------------------------------- 1 | #include "addgoodtypedlg.h" 2 | #include "ui_addgoodtypedlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | AddGoodTypeDlg::AddGoodTypeDlg(QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::AddGoodTypeDlg) 13 | { 14 | ui->setupUi(this); 15 | this->setWindowFlags(Qt::FramelessWindowHint); 16 | this->setAttribute(Qt::WA_TranslucentBackground); 17 | } 18 | 19 | AddGoodTypeDlg::~AddGoodTypeDlg() 20 | { 21 | delete ui; 22 | } 23 | 24 | void AddGoodTypeDlg::mousePressEvent(QMouseEvent *event) 25 | { 26 | if(event->button() == Qt::LeftButton && event->pos().y() < 70) //判断是否为左键 27 | { 28 | startPoint = event->globalPos() - frameGeometry().topLeft(); 29 | isDrag = true; 30 | event->accept(); 31 | // startPoint = QPoint(event->pos()); //将单击point存储 32 | } 33 | } 34 | 35 | void AddGoodTypeDlg::paintEvent(QPaintEvent *event) 36 | { 37 | QPainterPath path; 38 | path.setFillRule(Qt::WindingFill); 39 | path.addRect(10,10,this->width()-20,this->height()-20); 40 | QPainter painter(this); 41 | painter.setRenderHint(QPainter::Antialiasing,true); 42 | painter.fillPath(path,QBrush(Qt::white)); 43 | 44 | QColor color(0,0,0,55); 45 | for(int i = 0;i < 9;i++) 46 | { 47 | QPainterPath pathShadow; 48 | pathShadow.setFillRule(Qt::WindingFill); 49 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 50 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 51 | color.setAlpha(155-qSqrt(i)*55); 52 | painter.setPen(color); 53 | painter.drawPath(pathShadow); 54 | } 55 | } 56 | 57 | void AddGoodTypeDlg::mouseMoveEvent(QMouseEvent *event) 58 | { 59 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 60 | { 61 | move(event->globalPos() - startPoint); 62 | event->accept(); 63 | } 64 | } 65 | 66 | void AddGoodTypeDlg::mouseReleaseEvent(QMouseEvent *event) 67 | { 68 | isDrag = false; 69 | } 70 | 71 | void AddGoodTypeDlg::on_cancelBtn_clicked() 72 | { 73 | this->reject(); 74 | } 75 | 76 | void AddGoodTypeDlg::on_okBtn_clicked() 77 | { 78 | QString typeName = ui->nameLineEdit->text(); 79 | if(typeName.isEmpty()) 80 | { 81 | QMessageBox::warning(this,tr("警告"),tr("请输入要添加的商品类别名!"),QMessageBox::Ok); 82 | ui->nameLineEdit->setFocus(); 83 | return; 84 | } 85 | 86 | int id = 0; 87 | QSqlQuery query; 88 | query.exec("SELECT MAX(id) FROM goodsTypeTb"); 89 | while(query.next()) 90 | { 91 | id = query.value(0).toInt(); 92 | } 93 | id = id == 0 ? id: (id+1); //如果已经有数据了,就将id值加一 94 | query.prepare("INSERT INTO goodsTypeTb VALUES(:id,:typename)"); 95 | query.bindValue(":id",id); 96 | query.bindValue(":typename",typeName); 97 | if(query.exec()) 98 | { 99 | QMessageBox::information(this,tr("提示"),tr("添加成功"),QMessageBox::Ok); 100 | } 101 | else 102 | { 103 | QMessageBox::critical(this,tr("严重错误"),tr("抱歉!添加失败。\n错误原因:%1") 104 | .arg(query.lastError().text())); 105 | ui->nameLineEdit->setFocus(); 106 | return; 107 | } 108 | this->accept(); 109 | } 110 | 111 | void AddGoodTypeDlg::on_closeBtn_clicked() 112 | { 113 | this->reject(); 114 | } 115 | -------------------------------------------------------------------------------- /addgoodtypedlg.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDGOODTYPEDLG_H 2 | #define ADDGOODTYPEDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddGoodTypeDlg; 8 | } 9 | 10 | class AddGoodTypeDlg : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit AddGoodTypeDlg(QWidget *parent = 0); 16 | ~AddGoodTypeDlg(); 17 | 18 | private: 19 | Ui::AddGoodTypeDlg *ui; 20 | bool isDrag; 21 | QPoint startPoint; 22 | protected: 23 | void mousePressEvent(QMouseEvent *event); 24 | void paintEvent(QPaintEvent *event); 25 | void mouseMoveEvent(QMouseEvent *event); 26 | void mouseReleaseEvent(QMouseEvent *event); 27 | private slots: 28 | void on_cancelBtn_clicked(); 29 | void on_okBtn_clicked(); 30 | void on_closeBtn_clicked(); 31 | }; 32 | 33 | #endif // ADDGOODTYPEDLG_H 34 | -------------------------------------------------------------------------------- /addgoodtypedlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddGoodTypeDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 286 10 | 170 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QToolButton { 18 | border:0; 19 | } 20 | QToolButton#closeBtn{ 21 | background-image: url(:/images/close.png); 22 | } 23 | 24 | QToolButton#closeBtn:hover { 25 | background-image: url(:/images/close_h.png); 26 | } 27 | 28 | QToolButton#closeBtn:pressed { 29 | background-image: url(:/images/close_p.png); 30 | } 31 | 32 | 33 | QLineEdit{ 34 | color:rgb(127,0,63); 35 | border:2px groove gray; 36 | border-radius:6px; 37 | selection-color: white; 38 | selection-background-color: rgb(191, 31, 127); 39 | } 40 | 41 | QPushButton { 42 | color: white; 43 | font: bold 10pt; 44 | border-image: url(:/images/button.png) 16; 45 | border-width: 16px; 46 | padding: -16px 0px; 47 | min-height: 32px; 48 | min-width: 60px; 49 | } 50 | 51 | QPushButton:hover{ 52 | border-image:url(:/images/button_h.png) 16; 53 | } 54 | QPushButton:pressed{ 55 | border-image:url(:/images/button_p.png) 16; 56 | } 57 | QLabel { 58 | color:gray; 59 | 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 10 67 | 10 68 | 266 69 | 41 70 | 71 | 72 | 73 | 74 | 75 | 76 | :/images/addGoodsTypeHead.png 77 | 78 | 79 | 80 | 81 | 82 | 40 83 | 70 84 | 41 85 | 21 86 | 87 | 88 | 89 | 名称: 90 | 91 | 92 | 93 | 94 | 95 | 110 96 | 70 97 | 151 98 | 25 99 | 100 | 101 | 102 | 103 | 104 | 105 | 80 106 | 120 107 | 92 108 | 32 109 | 110 | 111 | 112 | 确定 113 | 114 | 115 | 116 | 117 | 118 | 180 119 | 120 120 | 92 121 | 32 122 | 123 | 124 | 125 | 取消 126 | 127 | 128 | 129 | 130 | 131 | 244 132 | 10 133 | 32 134 | 32 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /addpurchasedlg.cpp: -------------------------------------------------------------------------------- 1 | #include "addpurchasedlg.h" 2 | #include "ui_addpurchasedlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "choicegoodsdlg.h" 10 | #include 11 | #include "goodsnumdelegate.h" 12 | #include 13 | 14 | AddPurchaseDlg::AddPurchaseDlg(QString handlerName, QWidget *parent) : 15 | QDialog(parent),handler(handlerName), 16 | ui(new Ui::AddPurchaseDlg) 17 | { 18 | ui->setupUi(this); 19 | this->setWindowFlags(Qt::FramelessWindowHint); 20 | this->setAttribute(Qt::WA_TranslucentBackground); 21 | initialisePage(); 22 | createComploeter(); 23 | } 24 | 25 | void AddPurchaseDlg::initialisePage() 26 | { 27 | ui->tableWidget->setItemDelegate(new GoodsNumDelegate(2)); //设置第三列数量的委托 28 | connect(ui->tableWidget,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(updateModel(QTableWidgetItem*))); 29 | ui->addBtn->setDefault(true); 30 | ui->goodsIdLineEdit->installEventFilter(this); 31 | ui->spinBox->installEventFilter(this); 32 | ui->goodsIdLineEdit->setFocus(); 33 | ui->tableWidget->setColumnWidth(0,150); 34 | ui->tableWidget->setColumnWidth(1,150); 35 | ui->tableWidget->horizontalHeader()->setStretchLastSection(true); 36 | ui->dateEdit->setDate(QDate::currentDate()); 37 | ui->spinBox->setMinimum(1); 38 | supplierModel = new QSqlQueryModel; 39 | supplierModel->setQuery(tr("select name from supplierTb")); 40 | ui->supplierComboBox->setModel(supplierModel); 41 | //生成单号 42 | QString str = QDateTime::currentDateTime().toString("yyyyMMddhhmmss") 43 | + QString::number(qrand() % 899 + 100); 44 | ui->purchaseIdLineEdit->setText(str); 45 | purchaseId = str; 46 | ui->handlerLabel->setText(QString("操作员:") + handler); // 47 | } 48 | 49 | void AddPurchaseDlg::createComploeter() //创建文本框自动补全 50 | { 51 | QStringList list; 52 | QSqlQuery query; 53 | query.exec(tr("select num from goodsNameTb")); 54 | while(query.next()) 55 | { 56 | list << query.value(0).toString(); 57 | } 58 | completer = new QCompleter(list,this); 59 | ui->goodsIdLineEdit->setCompleter(completer); 60 | } 61 | 62 | void AddPurchaseDlg::selectGoods() 63 | { 64 | ChoiceGoodsDlg dlg; 65 | QString num; 66 | if(dlg.exec() == QDialog::Accepted) 67 | { 68 | num = dlg.getChoiceGoodsNum(); 69 | ui->goodsIdLineEdit->setText(num); 70 | } 71 | } 72 | 73 | void AddPurchaseDlg::addToTable(const QString &num) //根据商品编号,将商品添加到表格中 74 | { 75 | QSqlQuery query; 76 | //先检查是否已经有了该商品的信息 77 | for(int i = 0;i < ui->tableWidget->rowCount();++i) 78 | { 79 | if(ui->tableWidget->item(i,0)->text() == num) 80 | { 81 | int count = ui->tableWidget->item(i,2)->text().toInt(); 82 | ui->tableWidget->item(i,2)->setText(QString::number(count + ui->spinBox->value())); 83 | updatePrice(); //更新总价 84 | return; 85 | } 86 | } 87 | query.exec(tr("select name,bid from goodsNameTb where num = '%1'").arg(num)); 88 | if(query.next()) 89 | { 90 | int row = ui->tableWidget->rowCount(); 91 | ui->tableWidget->insertRow(row); 92 | QTableWidgetItem *item = new QTableWidgetItem(num); 93 | item->setFlags(item->flags() & ~Qt::ItemIsEditable ); 94 | ui->tableWidget->setItem(row,0,item); 95 | QTableWidgetItem *item1 = new QTableWidgetItem(query.value(0).toString()); 96 | item1->setFlags(item1->flags() & ~Qt::ItemIsEditable ); 97 | ui->tableWidget->setItem(row,1,item1); 98 | QTableWidgetItem *item2 = new QTableWidgetItem(QString::number(ui->spinBox->value())); 99 | ui->tableWidget->setItem(row,2,item2); 100 | QTableWidgetItem *item3 = new QTableWidgetItem(query.value(1).toString()); 101 | item3->setFlags(item3->flags() & ~Qt::ItemIsEditable ); 102 | ui->tableWidget->setItem(row,3,item3); 103 | } 104 | } 105 | 106 | void AddPurchaseDlg::updatePrice() //遍历整个表,计算总价 107 | { 108 | QSqlQuery query; 109 | double totalPrice = 0.0; 110 | for(int i = 0;i < ui->tableWidget->rowCount();i++) 111 | { 112 | QString id = ui->tableWidget->item(i,0)->text(); //商品编号 113 | int count = ui->tableWidget->item(i,2)->text().toInt(); //数量 114 | query.exec(tr("select bid from goodsNameTb where num = '%1'").arg(id)); 115 | query.next(); 116 | double price = query.value(0).toDouble(); 117 | totalPrice += count * price; 118 | } 119 | ui->totalPriceLineEdit->setText(QString::number(totalPrice)); 120 | } 121 | 122 | AddPurchaseDlg::~AddPurchaseDlg() 123 | { 124 | delete ui; 125 | } 126 | 127 | bool AddPurchaseDlg::eventFilter(QObject *target, QEvent *event) 128 | { 129 | if(target == ui->spinBox || target == ui->goodsIdLineEdit) 130 | { 131 | if(event->type() == QEvent::KeyPress) 132 | { 133 | QKeyEvent *keyEvent = static_cast(event); 134 | if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) 135 | { 136 | if(target == ui->goodsIdLineEdit && ui->goodsIdLineEdit->text().isEmpty()) 137 | { 138 | selectGoods(); 139 | } 140 | else 141 | { 142 | focusNextChild(); 143 | } 144 | return true; 145 | 146 | } 147 | } 148 | } 149 | return QDialog::eventFilter(target,event); 150 | } 151 | 152 | void AddPurchaseDlg::mousePressEvent(QMouseEvent *event) 153 | { 154 | if(event->button() == Qt::LeftButton && event->pos().y() < 70) //判断是否为左键 155 | { 156 | startPoint = event->globalPos() - frameGeometry().topLeft(); 157 | isDrag = true; 158 | event->accept(); 159 | // startPoint = QPoint(event->pos()); //将单击point存储 160 | } 161 | } 162 | 163 | void AddPurchaseDlg::paintEvent(QPaintEvent *event) 164 | { 165 | QPainterPath path; 166 | path.setFillRule(Qt::WindingFill); 167 | path.addRect(10,10,this->width()-20,this->height()-20); 168 | QPainter painter(this); 169 | painter.setRenderHint(QPainter::Antialiasing,true); 170 | painter.fillPath(path,QBrush(Qt::white)); 171 | 172 | QColor color(0,0,0,55); 173 | for(int i = 0;i < 9;i++) 174 | { 175 | QPainterPath pathShadow; 176 | pathShadow.setFillRule(Qt::WindingFill); 177 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 178 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 179 | color.setAlpha(155-qSqrt(i)*55); 180 | painter.setPen(color); 181 | painter.drawPath(pathShadow); 182 | } 183 | } 184 | 185 | void AddPurchaseDlg::mouseMoveEvent(QMouseEvent *event) 186 | { 187 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 188 | { 189 | move(event->globalPos() - startPoint); 190 | event->accept(); 191 | } 192 | } 193 | 194 | void AddPurchaseDlg::mouseReleaseEvent(QMouseEvent *event) 195 | { 196 | isDrag = false; 197 | } 198 | 199 | 200 | void AddPurchaseDlg::on_addBtn_clicked() 201 | { 202 | if(ui->goodsIdLineEdit->text().isEmpty()) 203 | { 204 | QMessageBox::warning(this,tr("警告"),tr("请输入商品名")); 205 | ui->goodsIdLineEdit->setFocus(); 206 | return; 207 | } 208 | addToTable(ui->goodsIdLineEdit->text()); 209 | ui->goodsIdLineEdit->clear(); 210 | ui->spinBox->setValue(1); 211 | ui->goodsIdLineEdit->setFocus(); 212 | // updatePrice(); 213 | } 214 | 215 | void AddPurchaseDlg::on_delBtn_clicked() //删除选中的商品 216 | { 217 | int row = ui->tableWidget->currentRow(); 218 | if(row < 0) 219 | { 220 | QMessageBox::warning(this,tr("警告"),tr("请选择需要删除的商品")); 221 | return; 222 | } 223 | ui->tableWidget->removeRow(row); 224 | updatePrice(); 225 | } 226 | 227 | void AddPurchaseDlg::on_purchaseIdLineEdit_editingFinished() 228 | { 229 | if(ui->purchaseIdLineEdit->text().isEmpty()) 230 | { 231 | ui->purchaseIdLineEdit->setText(purchaseId); 232 | return; 233 | } 234 | if(ui->purchaseIdLineEdit->text() != purchaseId) //说明已经改变 235 | { 236 | QString text = ui->purchaseIdLineEdit->text(); 237 | QSqlQuery query; 238 | query.exec(tr("select id from purchaseTb")); 239 | while(query.next()) 240 | { 241 | if(query.value(0).toString() == text) 242 | { 243 | QMessageBox::warning(this,tr("警告"),tr("抱歉,该单号已经存在,单号被重置!")); 244 | ui->purchaseIdLineEdit->setText(purchaseId); 245 | break; 246 | } 247 | } 248 | return; 249 | } 250 | 251 | } 252 | 253 | void AddPurchaseDlg::updateModel(QTableWidgetItem *item) //如果商品数量发生改变,就重新计算价格 254 | { 255 | if(item->column() == 2) 256 | { 257 | updatePrice(); 258 | } 259 | } 260 | 261 | void AddPurchaseDlg::on_okBtn_clicked() //提交这个订单 262 | { 263 | if(ui->tableWidget->rowCount() == 0) 264 | { 265 | QMessageBox::warning(this,tr("警告"),tr("进货清单为空,请添加商品!")); 266 | return; 267 | } 268 | QSqlQuery query; 269 | query.prepare(tr("insert into purchaseTb values(:id,:dateTime,:supplierId,:totalPrice," 270 | ":handler,:note)")); 271 | query.bindValue(":id",purchaseId); //订单号 272 | query.bindValue(":dateTime",ui->dateEdit->date().toString("yyyy-MM-dd")); //时间 273 | QSqlQuery idQuery; 274 | idQuery.exec(tr("select id from supplierTb where name = '%1'").arg(ui->supplierComboBox->currentText())); 275 | idQuery.next(); 276 | query.bindValue(":supplierId",idQuery.value(0).toInt()); 277 | query.bindValue(":totalPrice",ui->totalPriceLineEdit->text().toDouble()); 278 | query.bindValue(":handler",handler); 279 | query.bindValue(":note",ui->textEdit->toPlainText()); 280 | if(! query.exec()) 281 | { 282 | QMessageBox::warning(this,tr("this"),tr("添加失败,%1").arg(query.lastError().text())); 283 | return; 284 | } 285 | else 286 | QMessageBox::information(this,tr("ta"),tr("添加成功")); 287 | //添加商品明细 288 | int id; 289 | QSqlQuery detailIdQuery; 290 | detailIdQuery.exec(tr("select id from purchaseDetailTb")); //取出最后的id 291 | if(detailIdQuery.last()) //如果有记录 292 | { 293 | id = detailIdQuery.value(0).toInt(); 294 | } 295 | else 296 | { 297 | id = 0; 298 | } 299 | 300 | for(int i = 0;i < ui->tableWidget->rowCount();++i) //遍历整个表格 301 | { 302 | query.exec(tr("insert into purchaseDetailTb values(:id,:purchaseId,:goodsId,:count)")); 303 | query.bindValue(":id",++id); //主键id递增 304 | query.bindValue(":purchaseId",ui->purchaseIdLineEdit->text()); 305 | query.bindValue(":goodsId",ui->tableWidget->item(i,0)->text()); 306 | query.bindValue(":count",ui->tableWidget->item(i,2)->text().toInt()); 307 | query.exec(); 308 | } 309 | this->accept(); //关闭窗口 310 | } 311 | -------------------------------------------------------------------------------- /addpurchasedlg.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDPURCHASEDLG_H 2 | #define ADDPURCHASEDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddPurchaseDlg; 8 | } 9 | class QCompleter; 10 | class QSqlQueryModel; 11 | class QTableWidgetItem; 12 | 13 | class AddPurchaseDlg : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit AddPurchaseDlg(QString handlerName,QWidget *parent = 0); 19 | ~AddPurchaseDlg(); 20 | bool eventFilter(QObject *target, QEvent *event); 21 | protected: 22 | void mousePressEvent(QMouseEvent *event); 23 | void paintEvent(QPaintEvent *event); 24 | void mouseMoveEvent(QMouseEvent *event); 25 | void mouseReleaseEvent(QMouseEvent *event); 26 | private slots: 27 | void on_addBtn_clicked(); 28 | 29 | void on_delBtn_clicked(); 30 | 31 | void on_purchaseIdLineEdit_editingFinished(); 32 | void updateModel(QTableWidgetItem *item); 33 | 34 | void on_okBtn_clicked(); 35 | 36 | private: 37 | Ui::AddPurchaseDlg *ui; 38 | bool isDrag; 39 | QString handler; 40 | QPoint startPoint; 41 | QCompleter *completer; 42 | QString purchaseId; 43 | QSqlQueryModel *supplierModel; 44 | void initialisePage(); 45 | void createComploeter(); 46 | void selectGoods(); 47 | void addToTable(const QString &num); 48 | void updatePrice(); 49 | 50 | }; 51 | 52 | #endif // ADDPURCHASEDLG_H 53 | -------------------------------------------------------------------------------- /addpurchasedlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddPurchaseDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 585 10 | 524 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QDialog { 18 | border-radius:3px; 19 | border:1px groove gray; 20 | } 21 | 22 | QToolButton { 23 | border:0; 24 | } 25 | QToolButton#closeBtn{ 26 | background-image: url(:/images/close.png); 27 | } 28 | 29 | QToolButton#closeBtn:hover { 30 | background-image: url(:/images/close_h.png); 31 | } 32 | 33 | QToolButton#closeBtn:pressed { 34 | background-image: url(:/images/close_p.png); 35 | } 36 | 37 | 38 | QLineEdit,QComboBox,QTextEdit { 39 | color:rgb(127,0,63); 40 | border:2px groove gray; 41 | border-radius:6px; 42 | selection-color: white; 43 | selection-background-color: rgb(191, 31, 127); 44 | } 45 | 46 | QPushButton { 47 | color: white; 48 | font: bold 10pt; 49 | border-image: url(:/images/button.png) 16; 50 | border-width: 16px; 51 | padding: -16px 0px; 52 | min-height: 32px; 53 | min-width: 60px; 54 | } 55 | 56 | QPushButton:hover{ 57 | border-image:url(:/images/button_h.png) 16; 58 | } 59 | QPushButton:pressed{ 60 | border-image:url(:/images/button_p.png) 16; 61 | } 62 | QLabel { 63 | color:gray; 64 | 65 | } 66 | 67 | 68 | 69 | 70 | 71 | 20 72 | 60 73 | 51 74 | 16 75 | 76 | 77 | 78 | 进货单号: 79 | 80 | 81 | 82 | 83 | 84 | 390 85 | 60 86 | 61 87 | 16 88 | 89 | 90 | 91 | 进货日期: 92 | 93 | 94 | 95 | 96 | 97 | 200 98 | 60 99 | 41 100 | 16 101 | 102 | 103 | 104 | 供应商: 105 | 106 | 107 | 108 | 109 | 110 | 170 111 | 70 112 | 54 113 | 12 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 80 124 | 60 125 | 113 126 | 20 127 | 128 | 129 | 130 | 131 | 132 | 133 | 250 134 | 60 135 | 131 136 | 22 137 | 138 | 139 | 140 | 141 | 142 | 143 | 450 144 | 60 145 | 110 146 | 22 147 | 148 | 149 | 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 270 157 | 490 158 | 41 159 | 16 160 | 161 | 162 | 163 | 总价: 164 | 165 | 166 | 167 | 168 | 169 | 320 170 | 490 171 | 113 172 | 20 173 | 174 | 175 | 176 | 0.0 177 | 178 | 179 | true 180 | 181 | 182 | 183 | 184 | 185 | 470 186 | 430 187 | 92 188 | 32 189 | 190 | 191 | 192 | 确定 193 | 194 | 195 | 196 | 197 | 198 | 470 199 | 470 200 | 92 201 | 32 202 | 203 | 204 | 205 | 取消 206 | 207 | 208 | 209 | 210 | 211 | 470 212 | 370 213 | 92 214 | 32 215 | 216 | 217 | 218 | 删除 219 | 220 | 221 | 222 | 223 | 224 | 30 225 | 330 226 | 121 227 | 21 228 | 229 | 230 | 231 | 商品编号: 232 | 233 | 234 | 235 | 236 | 237 | 110 238 | 330 239 | 113 240 | 20 241 | 242 | 243 | 244 | 245 | 246 | 247 | 280 248 | 330 249 | 41 250 | 16 251 | 252 | 253 | 254 | 数量: 255 | 256 | 257 | 258 | 259 | 260 | 340 261 | 330 262 | 42 263 | 22 264 | 265 | 266 | 267 | 268 | 269 | 270 | 543 271 | 10 272 | 32 273 | 32 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 32 282 | 32 283 | 284 | 285 | 286 | 287 | 288 | 289 | 10 290 | 10 291 | 565 292 | 40 293 | 294 | 295 | 296 | 297 | 298 | 299 | :/images/purchaseHeadpng.png 300 | 301 | 302 | 303 | 304 | 305 | 470 306 | 330 307 | 92 308 | 32 309 | 310 | 311 | 312 | 添加 313 | 314 | 315 | 316 | 317 | 318 | 20 319 | 90 320 | 541 321 | 221 322 | 323 | 324 | 325 | QAbstractItemView::SingleSelection 326 | 327 | 328 | QAbstractItemView::SelectRows 329 | 330 | 331 | false 332 | 333 | 334 | 100 335 | 336 | 337 | 338 | 商品编号 339 | 340 | 341 | 342 | 343 | 商品名 344 | 345 | 346 | 347 | 348 | 进货数量 349 | 350 | 351 | 352 | 353 | 进价 354 | 355 | 356 | 357 | 358 | 359 | 360 | 40 361 | 380 362 | 51 363 | 16 364 | 365 | 366 | 367 | 备注: 368 | 369 | 370 | 371 | 372 | 373 | 110 374 | 380 375 | 321 376 | 91 377 | 378 | 379 | 380 | false 381 | 382 | 383 | 384 | 385 | 386 | 30 387 | 490 388 | 91 389 | 16 390 | 391 | 392 | 393 | 操作员:admin 394 | 395 | 396 | label_9 397 | label 398 | label_2 399 | label_3 400 | label_4 401 | purchaseIdLineEdit 402 | supplierComboBox 403 | dateEdit 404 | label_6 405 | totalPriceLineEdit 406 | okBtn 407 | cancelBtn 408 | delBtn 409 | label_7 410 | goodsIdLineEdit 411 | label_8 412 | spinBox 413 | closeBtn 414 | addBtn 415 | tableWidget 416 | label_5 417 | textEdit 418 | handlerLabel 419 | 420 | 421 | goodsIdLineEdit 422 | spinBox 423 | addBtn 424 | delBtn 425 | okBtn 426 | cancelBtn 427 | purchaseIdLineEdit 428 | supplierComboBox 429 | dateEdit 430 | tableWidget 431 | totalPriceLineEdit 432 | closeBtn 433 | 434 | 435 | 436 | 437 | 438 | 439 | closeBtn 440 | clicked() 441 | AddPurchaseDlg 442 | reject() 443 | 444 | 445 | 556 446 | 25 447 | 448 | 449 | 584 450 | 59 451 | 452 | 453 | 454 | 455 | cancelBtn 456 | clicked() 457 | AddPurchaseDlg 458 | reject() 459 | 460 | 461 | 537 462 | 394 463 | 464 | 465 | 576 466 | 387 467 | 468 | 469 | 470 | 471 | 472 | -------------------------------------------------------------------------------- /addsupplierdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "addsupplierdlg.h" 2 | #include "ui_addsupplierdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include "showinforlabel.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | AddSupplierDlg::AddSupplierDlg(QWidget *parent) : 14 | QDialog(parent), 15 | ui(new Ui::AddSupplierDlg) 16 | { 17 | ui->setupUi(this); 18 | this->setWindowFlags(Qt::FramelessWindowHint); 19 | this->setAttribute(Qt::WA_TranslucentBackground); 20 | 21 | errorLabel = new ShowInforLabel(this); 22 | errorLabel->setVisible(false); 23 | ui->nameLineEdit->installEventFilter(this); 24 | ui->contactLineEdit->installEventFilter(this); 25 | ui->numberLineEdit->installEventFilter(this); 26 | ui->addressLineEdit->installEventFilter(this); 27 | ui->noteTextEdit->installEventFilter(this); 28 | } 29 | 30 | AddSupplierDlg::~AddSupplierDlg() 31 | { 32 | delete ui; 33 | } 34 | 35 | bool AddSupplierDlg::eventFilter(QObject *target, QEvent *event) 36 | { 37 | if(target == ui->nameLineEdit || target == ui->contactLineEdit || target ==ui->numberLineEdit 38 | || target == ui->addressLineEdit || target == ui->noteTextEdit) 39 | { 40 | if(event->type() == QEvent::KeyPress) 41 | { 42 | QKeyEvent *keyEvent = static_cast(event); 43 | if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) 44 | { 45 | this->focusNextChild(); 46 | return true; 47 | } 48 | } 49 | } 50 | return QDialog::eventFilter(target,event); 51 | } 52 | 53 | void AddSupplierDlg::paintEvent(QPaintEvent *event) 54 | { 55 | QPainterPath path; 56 | path.setFillRule(Qt::WindingFill); 57 | path.addRect(10,10,this->width()-20,this->height()-20); 58 | QPainter painter(this); 59 | painter.setRenderHint(QPainter::Antialiasing,true); 60 | painter.fillPath(path,QBrush(Qt::white)); 61 | 62 | QColor color(0,0,0,55); 63 | for(int i = 0;i < 9;i++) 64 | { 65 | QPainterPath pathShadow; 66 | pathShadow.setFillRule(Qt::WindingFill); 67 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 68 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 69 | color.setAlpha(155-qSqrt(i)*55); 70 | painter.setPen(color); 71 | painter.drawPath(pathShadow); 72 | } 73 | } 74 | 75 | void AddSupplierDlg::mousePressEvent(QMouseEvent *event) 76 | { 77 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 78 | { 79 | startPoint = event->globalPos() - frameGeometry().topLeft(); 80 | isDrag = true; 81 | event->accept(); 82 | // startPoint = QPoint(event->pos()); //将单击point存储 83 | } 84 | } 85 | 86 | void AddSupplierDlg::mouseReleaseEvent(QMouseEvent *event) 87 | { 88 | isDrag = false; 89 | } 90 | 91 | void AddSupplierDlg::mouseMoveEvent(QMouseEvent *event) 92 | { 93 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 94 | { 95 | move(event->globalPos() - startPoint); 96 | event->accept(); 97 | } 98 | } 99 | 100 | void AddSupplierDlg::on_okBtn_clicked() //确定添加按钮 101 | { 102 | if(ui->nameLineEdit->text().isEmpty()) 103 | { 104 | this->setErrorLabelText(tr("请输入供应商名称"),QPoint(ui->nameLineEdit->pos() + QPoint(-12,10))); 105 | ui->nameLineEdit->setFocus(); 106 | return; 107 | } 108 | else if(ui->contactLineEdit->text().isEmpty()) 109 | { 110 | this->setErrorLabelText(tr("请输入联系人"),QPoint(ui->contactLineEdit->pos() + QPoint(-12,10))); 111 | ui->contactLineEdit->setFocus(); 112 | return; 113 | } 114 | else if(ui->numberLineEdit->text().isEmpty()) 115 | { 116 | this->setErrorLabelText(tr("请输入联系电话"),QPoint(ui->numberLineEdit->pos() + QPoint(-12,10))); 117 | ui->numberLineEdit->setFocus(); 118 | return; 119 | } 120 | QSqlQuery query; 121 | //先判断是否已经有了该供应商 122 | query.exec(tr("select name from supplierTb")); 123 | bool hasSupplier = false; 124 | while(query.next()) 125 | { 126 | if(query.value(0).toString() == ui->nameLineEdit->text()) 127 | { 128 | hasSupplier = true; 129 | break; 130 | } 131 | } 132 | if(hasSupplier) //如果已经有了该供应商 133 | { 134 | int r = QMessageBox::question(this,tr("警告"),tr("该供应商已经存在,是否继续添加?"),QMessageBox::No | QMessageBox::Yes); 135 | if(r == QMessageBox::No) 136 | { 137 | ui->nameLineEdit->selectAll(); 138 | ui->nameLineEdit->setFocus(); 139 | return; 140 | } 141 | } 142 | query.exec(tr("select *from supplierTb")); 143 | int id = 0; 144 | if(query.last()) 145 | { 146 | id = query.value(0).toInt(); 147 | } 148 | query.prepare(tr("insert into supplierTb values(:id,:name,:contact,:phone,:address,:note)")); 149 | query.bindValue(":id",++id); 150 | query.bindValue(":name",ui->nameLineEdit->text()); 151 | query.bindValue(":contact",ui->contactLineEdit->text()); 152 | query.bindValue(":phone",ui->numberLineEdit->text()); 153 | QString addressText = ui->addressLineEdit->text(); 154 | query.bindValue(":address",addressText.isEmpty()? tr("none") : addressText); 155 | QString noteText = ui->noteTextEdit->toPlainText(); 156 | query.bindValue(":note",noteText.isEmpty() ? tr("none"):noteText); 157 | if(query.exec()) 158 | { 159 | QMessageBox msgBox; 160 | msgBox.setText("添加成功!"); 161 | // msgBox.setInformativeText("Do you want to save your changes?"); 162 | msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); 163 | msgBox.setWindowTitle(tr("提示")); 164 | msgBox.setButtonText(QMessageBox::Yes,tr("继续添加下一条")); 165 | msgBox.setButtonText(QMessageBox::No,tr("关闭")); 166 | msgBox.setDefaultButton(QMessageBox::No); 167 | int ret = msgBox.exec(); 168 | if(ret == QMessageBox::Yes) //继续添加下一条 169 | { 170 | ui->nameLineEdit->clear(); 171 | ui->contactLineEdit->clear(); 172 | ui->addressLineEdit->clear(); 173 | ui->numberLineEdit->clear(); 174 | ui->noteTextEdit->clear(); 175 | ui->nameLineEdit->setFocus(); 176 | } 177 | else 178 | { 179 | this->accept(); 180 | } 181 | } 182 | else 183 | { 184 | QMessageBox::warning(this,tr("添加供应商"),tr("添加供应商失败。\n原因:%1") 185 | .arg(query.lastError().text())); 186 | } 187 | } 188 | 189 | void AddSupplierDlg::setLabelOpacity() 190 | { 191 | QPropertyAnimation *animation = new QPropertyAnimation(errorLabel,"opacity"); 192 | 193 | animation->setStartValue(1.0); 194 | animation->setEndValue(0.0); 195 | animation->setDuration(1500); 196 | animation->start(QAbstractAnimation::DeleteWhenStopped); 197 | connect(animation,SIGNAL(finished()),errorLabel,SLOT(setWindowVisable()));//当结束时,设置label为不可见 198 | } 199 | 200 | void AddSupplierDlg::setErrorLabelText(const QString &text, const QPoint &point) 201 | { 202 | if(errorLabel->isVisible()) //避免出现动画还没stop,就按下第二次确定的重复动画 203 | return; 204 | errorLabel->setText(text); //设置errorlabel的显示文本 205 | errorLabel->setGeometry(point.x(),point.y(), //设置errorLabel的位置,以及根据文本确定宽度 206 | fontMetrics().width(text) + 30,40); 207 | errorLabel->setVisible(true); //设置label为可见 208 | QTimer::singleShot(500,this,SLOT(setLabelOpacity())); //显示1秒后,执行隐藏动画 209 | } 210 | -------------------------------------------------------------------------------- /addsupplierdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDSUPPLIERDLG_H 2 | #define ADDSUPPLIERDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddSupplierDlg; 8 | } 9 | class ShowInforLabel; 10 | 11 | class AddSupplierDlg : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit AddSupplierDlg(QWidget *parent = 0); 17 | ~AddSupplierDlg(); 18 | bool eventFilter(QObject *target, QEvent *event); 19 | protected: 20 | void paintEvent(QPaintEvent *event); 21 | void mousePressEvent(QMouseEvent *event); 22 | void mouseReleaseEvent(QMouseEvent *event); 23 | void mouseMoveEvent(QMouseEvent *event); 24 | 25 | private slots: 26 | void on_okBtn_clicked(); 27 | void setLabelOpacity(); 28 | 29 | private: 30 | Ui::AddSupplierDlg *ui; 31 | QPoint startPoint; 32 | bool isDrag; //是否拖动 33 | ShowInforLabel *errorLabel; 34 | void setErrorLabelText(const QString &text,const QPoint &point = QPoint(80,95)); 35 | bool hasTheSupplier(const QString); 36 | }; 37 | 38 | #endif // ADDSUPPLIERDLG_H 39 | -------------------------------------------------------------------------------- /addsupplierdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddSupplierDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 370 10 | 411 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QToolButton { 18 | border:0; 19 | } 20 | QToolButton#closeBtn{ 21 | background-image: url(:/images/close.png); 22 | } 23 | 24 | QToolButton#closeBtn:hover { 25 | background-image: url(:/images/close_h.png); 26 | } 27 | 28 | QToolButton#closeBtn:pressed { 29 | background-image: url(:/images/close_p.png); 30 | } 31 | 32 | 33 | QLineEdit ,QTextEdit{ 34 | color:rgb(127,0,63); 35 | border:2px groove gray; 36 | border-radius:6px; 37 | selection-color: white; 38 | selection-background-color: rgb(191, 31, 127); 39 | } 40 | 41 | QPushButton { 42 | color: white; 43 | font: bold 10pt; 44 | border-image: url(:/images/button.png) 16; 45 | border-width: 16px; 46 | padding: -16px 0px; 47 | min-height: 32px; 48 | min-width: 60px; 49 | } 50 | 51 | QPushButton:hover{ 52 | border-image:url(:/images/button_h.png) 16; 53 | } 54 | QPushButton:pressed{ 55 | border-image:url(:/images/button_p.png) 16; 56 | } 57 | QLabel { 58 | color:gray; 59 | 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 30 67 | 60 68 | 81 69 | 21 70 | 71 | 72 | 73 | 供应商名(&N): 74 | 75 | 76 | nameLineEdit 77 | 78 | 79 | 80 | 81 | 82 | 30 83 | 100 84 | 81 85 | 16 86 | 87 | 88 | 89 | 联系人(&P): 90 | 91 | 92 | contactLineEdit 93 | 94 | 95 | 96 | 97 | 98 | 30 99 | 140 100 | 81 101 | 21 102 | 103 | 104 | 105 | 联系电话(&T): 106 | 107 | 108 | numberLineEdit 109 | 110 | 111 | 112 | 113 | 114 | 30 115 | 180 116 | 81 117 | 21 118 | 119 | 120 | 121 | 联系地址(&A): 122 | 123 | 124 | addressLineEdit 125 | 126 | 127 | 128 | 129 | 130 | 30 131 | 210 132 | 61 133 | 21 134 | 135 | 136 | 137 | 备注(&B): 138 | 139 | 140 | noteTextEdit 141 | 142 | 143 | 144 | 145 | 146 | 120 147 | 220 148 | 221 149 | 131 150 | 151 | 152 | 153 | 154 | 155 | 156 | 120 157 | 60 158 | 221 159 | 26 160 | 161 | 162 | 163 | 164 | 165 | 166 | 120 167 | 100 168 | 221 169 | 26 170 | 171 | 172 | 173 | 15 174 | 175 | 176 | 177 | 178 | 179 | 120 180 | 140 181 | 221 182 | 26 183 | 184 | 185 | 186 | 11 187 | 188 | 189 | 190 | 191 | 192 | 120 193 | 180 194 | 221 195 | 26 196 | 197 | 198 | 199 | 200 | 201 | 202 | 150 203 | 360 204 | 92 205 | 32 206 | 207 | 208 | 209 | 确定(&E) 210 | 211 | 212 | 213 | 214 | 215 | 250 216 | 360 217 | 92 218 | 32 219 | 220 | 221 | 222 | 取消(&C) 223 | 224 | 225 | 226 | 227 | 228 | 10 229 | 10 230 | 350 231 | 40 232 | 233 | 234 | 235 | 236 | 237 | 238 | :/images/addSupplierHead.png 239 | 240 | 241 | 242 | 243 | 244 | 328 245 | 10 246 | 32 247 | 32 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 32 256 | 32 257 | 258 | 259 | 260 | 261 | 262 | 263 | 350 264 | 60 265 | 16 266 | 21 267 | 268 | 269 | 270 | <html><head/><body><p><span style=" color:#ff0000;">*</span></p></body></html> 271 | 272 | 273 | 274 | 275 | 276 | 350 277 | 100 278 | 16 279 | 21 280 | 281 | 282 | 283 | <html><head/><body><p><span style=" color:#ff0000;">*</span></p></body></html> 284 | 285 | 286 | 287 | 288 | 289 | 350 290 | 140 291 | 16 292 | 21 293 | 294 | 295 | 296 | <html><head/><body><p><span style=" color:#ff0000;">*</span></p></body></html> 297 | 298 | 299 | 300 | 301 | nameLineEdit 302 | contactLineEdit 303 | numberLineEdit 304 | addressLineEdit 305 | noteTextEdit 306 | okBtn 307 | cancelBtn 308 | 309 | 310 | 311 | 312 | 313 | 314 | closeBtn 315 | clicked() 316 | AddSupplierDlg 317 | reject() 318 | 319 | 320 | 345 321 | 24 322 | 323 | 324 | 359 325 | 66 326 | 327 | 328 | 329 | 330 | cancelBtn 331 | clicked() 332 | AddSupplierDlg 333 | reject() 334 | 335 | 336 | 351 337 | 367 338 | 339 | 340 | 361 341 | 344 342 | 343 | 344 | 345 | 346 | 347 | -------------------------------------------------------------------------------- /adduserdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "adduserdlg.h" 2 | #include "ui_adduserdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "showinforlabel.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | AddUserDlg::AddUserDlg(QWidget *parent) : 16 | QDialog(parent), 17 | ui(new Ui::AddUserDlg) 18 | { 19 | ui->setupUi(this); 20 | this->setWindowFlags(Qt::FramelessWindowHint); 21 | this->setAttribute(Qt::WA_TranslucentBackground); 22 | ui->pswLineEdit->setEchoMode(QLineEdit::Password); 23 | 24 | this->initEvent(); 25 | ui->usernameLineEdit->setFocus(); 26 | 27 | errorLabel = new ShowInforLabel(this); //错误信息 28 | errorLabel->setVisible(false); 29 | 30 | //设置身份证号码文本框的正则表达式,只能输入18位的数字 31 | QRegExp regExp("[0-9]{18}"); 32 | 33 | ui->idCardLineEdit->setValidator(new QRegExpValidator(regExp, this)); 34 | } 35 | 36 | AddUserDlg::~AddUserDlg() 37 | { 38 | delete ui; 39 | } 40 | 41 | //事件过滤器,如果是回车,就跳转到下一个控件,方便输入 42 | bool AddUserDlg::eventFilter(QObject *target, QEvent *event) 43 | { 44 | if(target == ui->usernameLineEdit || target == ui->pswLineEdit || target == ui->jobNumLineEdit 45 | || target == ui->sexComboBox || target == ui->idCardLineEdit) 46 | { 47 | if(event->type() == QEvent::KeyPress) 48 | { 49 | QKeyEvent *keyEvent = static_cast(event); 50 | if(keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) 51 | { 52 | this->focusNextChild(); 53 | return true; 54 | } 55 | } 56 | } 57 | return QDialog::eventFilter(target,event); 58 | } 59 | 60 | void AddUserDlg::setLabelOpacity() //错误信息的消失渐变动画 61 | { 62 | QPropertyAnimation *animation = new QPropertyAnimation(errorLabel,"opacity"); 63 | 64 | animation->setStartValue(1.0); 65 | animation->setEndValue(0.0); 66 | animation->setDuration(1500); 67 | animation->start(QAbstractAnimation::DeleteWhenStopped); 68 | connect(animation,SIGNAL(finished()),errorLabel,SLOT(setWindowVisable()));//当结束时,设置label为不可见 69 | } 70 | 71 | void AddUserDlg::on_okBtn_clicked() //确定按钮,提交用户 72 | { 73 | //判断所有信息是否都填写,没有就提示错误 74 | if(ui->usernameLineEdit->text().isEmpty()) 75 | { 76 | this->setErrorLabelText(tr("请输入用户名"),QPoint(ui->usernameLineEdit->pos() + QPoint(-12,10))); 77 | ui->usernameLineEdit->setFocus(); 78 | return; 79 | } 80 | else if(ui->pswLineEdit->text().isEmpty()) 81 | { 82 | this->setErrorLabelText(tr("请输入密码"),QPoint(ui->pswLineEdit->pos() + QPoint(-12,10))); 83 | ui->pswLineEdit->setFocus(); 84 | return; 85 | } 86 | else if(ui->jobNumLineEdit->text().isEmpty()) 87 | { 88 | this->setErrorLabelText(tr("请输入工作号"),QPoint(ui->jobNumLineEdit->pos() + QPoint(-12,10))); 89 | ui->jobNumLineEdit->setFocus(); 90 | return; 91 | } 92 | else if(ui->idCardLineEdit->text().isEmpty()) 93 | { 94 | this->setErrorLabelText(tr("请输入身份证号码"),QPoint(ui->idCardLineEdit->pos() + QPoint(-12,10))); 95 | ui->idCardLineEdit->setFocus(); 96 | return; 97 | } 98 | else if(ui->idCardLineEdit->text().length() != 18) //如果不是18位就重新输入 99 | { 100 | this->setErrorLabelText(tr("身份证号输入不正确"),QPoint(ui->idCardLineEdit->pos() + QPoint(-12,10))); 101 | ui->idCardLineEdit->setFocus(); 102 | return; 103 | } 104 | 105 | 106 | QSqlQuery query; 107 | QString username = ui->usernameLineEdit->text(); 108 | //根据输入的用户名判断数据表中是否有这个用户 109 | query.exec(tr("SELECT * FROM userTb WHERE username='%1'").arg(username)); 110 | if(query.next()) { 111 | //如果已经有了这个用户 112 | QMessageBox::warning(this,tr("警告"),tr("这个用户已经存在,请输入一个新的用户!")); 113 | ui->usernameLineEdit->setFocus(); 114 | ui->usernameLineEdit->selectAll(); 115 | return ; //选中用户名文本框,并直接返回 116 | } 117 | QString curDateTime = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); 118 | //所有信息都已经符合标准就往数据表存储 119 | query.prepare("INSERT INTO userTb(username,password,jobNum,sex,IDCardNum,lastLogTime)" 120 | " VALUES(:username,:password,:jobNum,:sex,:IDCardNum,:lastLogTime)"); 121 | query.bindValue(":username",username); 122 | query.bindValue(":password",ui->pswLineEdit->text()); 123 | query.bindValue(":jobNum",ui->jobNumLineEdit->text()); 124 | query.bindValue(":sex",ui->sexComboBox->currentText()); 125 | query.bindValue(":IDCardNum",ui->idCardLineEdit->text()); 126 | query.bindValue(":lastLogTime",curDateTime); 127 | if(query.exec()) //添加成功 128 | { 129 | QMessageBox::information(this,tr("提示"),tr("用户添加成功"),QMessageBox::Ok); 130 | this->accept(); 131 | } 132 | else 133 | { 134 | QMessageBox::critical(this,tr("严重错误"),tr("抱歉,用户添加失败。\n错误原因:") 135 | + query.lastError().text()); 136 | } 137 | // this->accept(); 138 | } 139 | 140 | void AddUserDlg::paintEvent(QPaintEvent *event) 141 | { 142 | QPainterPath path; 143 | path.setFillRule(Qt::WindingFill); 144 | path.addRect(10,10,this->width()-20,this->height()-20); 145 | QPainter painter(this); 146 | painter.setRenderHint(QPainter::Antialiasing,true); 147 | painter.fillPath(path,QBrush(Qt::white)); 148 | 149 | QColor color(0,0,0,55); 150 | for(int i = 0;i < 9;i++) 151 | { 152 | QPainterPath pathShadow; 153 | pathShadow.setFillRule(Qt::WindingFill); 154 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 155 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 156 | color.setAlpha(155-qSqrt(i)*55); 157 | painter.setPen(color); 158 | painter.drawPath(pathShadow); 159 | } 160 | } 161 | 162 | void AddUserDlg::mousePressEvent(QMouseEvent *event) 163 | { 164 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 165 | { 166 | startPoint = event->globalPos() - frameGeometry().topLeft(); 167 | isDrag = true; 168 | event->accept(); 169 | // startPoint = QPoint(event->pos()); //将单击point存储 170 | } 171 | } 172 | 173 | void AddUserDlg::mouseReleaseEvent(QMouseEvent *event) 174 | { 175 | isDrag = false; 176 | } 177 | 178 | void AddUserDlg::mouseMoveEvent(QMouseEvent *event) //按下回车跳转到下一个控件 179 | { 180 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 181 | { 182 | move(event->globalPos() - startPoint); 183 | event->accept(); 184 | } 185 | } 186 | 187 | 188 | void AddUserDlg::initEvent() //为控件安装事件过滤器 189 | { 190 | ui->usernameLineEdit->installEventFilter(this); 191 | ui->pswLineEdit->installEventFilter(this); 192 | ui->jobNumLineEdit->installEventFilter(this); 193 | ui->idCardLineEdit->installEventFilter(this); 194 | ui->sexComboBox->installEventFilter(this); 195 | } 196 | 197 | void AddUserDlg::setErrorLabelText(const QString &text, const QPoint &point) 198 | { 199 | if(errorLabel->isVisible()) //避免出现动画还没stop,就按下第二次确定的重复动画 200 | return; 201 | errorLabel->setText(text); //设置errorlabel的显示文本 202 | errorLabel->setGeometry(point.x(),point.y(), //设置errorLabel的位置,以及根据文本确定宽度 203 | fontMetrics().width(text) + 30,40); 204 | errorLabel->setVisible(true); //设置label为可见 205 | QTimer::singleShot(500,this,SLOT(setLabelOpacity())); //显示1秒后,执行隐藏动画 206 | } 207 | 208 | void AddUserDlg::on_closeBtn_clicked() 209 | { 210 | this->reject(); 211 | } 212 | 213 | 214 | void AddUserDlg::on_hidePswCheckBox_clicked(bool checked) 215 | { 216 | if(checked) 217 | ui->pswLineEdit->setEchoMode(QLineEdit::Normal); 218 | else 219 | ui->pswLineEdit->setEchoMode(QLineEdit::Password); 220 | } 221 | 222 | void AddUserDlg::on_cancelBtn_clicked() 223 | { 224 | this->reject(); 225 | } 226 | -------------------------------------------------------------------------------- /adduserdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDUSERDLG_H 2 | #define ADDUSERDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AddUserDlg; 8 | } 9 | class ShowInforLabel; 10 | 11 | class AddUserDlg : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit AddUserDlg(QWidget *parent = 0); 17 | ~AddUserDlg(); 18 | bool eventFilter(QObject *target, QEvent *event); 19 | 20 | private slots: 21 | void setLabelOpacity(); // 22 | void on_okBtn_clicked(); 23 | void on_closeBtn_clicked(); 24 | 25 | void on_hidePswCheckBox_clicked(bool checked); 26 | 27 | void on_cancelBtn_clicked(); 28 | 29 | protected: 30 | void paintEvent(QPaintEvent *event); 31 | void mousePressEvent(QMouseEvent *event); 32 | void mouseReleaseEvent(QMouseEvent *event); 33 | void mouseMoveEvent(QMouseEvent *event); 34 | private: 35 | Ui::AddUserDlg *ui; 36 | QPoint startPoint; 37 | bool isDrag; //是否拖动 38 | 39 | void initEvent(); 40 | ShowInforLabel *errorLabel; 41 | void setErrorLabelText(const QString &text,const QPoint &point = QPoint(80,95)); 42 | }; 43 | 44 | #endif // ADDUSERDLG_H 45 | -------------------------------------------------------------------------------- /adduserdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AddUserDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 275 10 | 316 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QToolButton { 18 | border:0; 19 | } 20 | QToolButton#closeBtn{ 21 | background-image: url(:/images/close.png); 22 | } 23 | 24 | QToolButton#closeBtn:hover { 25 | background-image: url(:/images/close_h.png); 26 | } 27 | 28 | QToolButton#closeBtn:pressed { 29 | background-image: url(:/images/close_p.png); 30 | } 31 | 32 | 33 | QLineEdit ,QTextEdit{ 34 | color:rgb(127,0,63); 35 | border:2px groove gray; 36 | border-radius:6px; 37 | selection-color: white; 38 | selection-background-color: rgb(191, 31, 127); 39 | } 40 | 41 | QPushButton { 42 | color: white; 43 | font: bold 10pt; 44 | border-image: url(:/images/button.png) 16; 45 | border-width: 16px; 46 | padding: -16px 0px; 47 | min-height: 32px; 48 | min-width: 60px; 49 | } 50 | 51 | QPushButton:hover{ 52 | border-image:url(:/images/button_h.png) 16; 53 | } 54 | QPushButton:pressed{ 55 | border-image:url(:/images/button_p.png) 16; 56 | } 57 | QLabel { 58 | color:gray; 59 | 60 | } 61 | 62 | QCheckBox { 63 | color:gray; 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 60 71 | 260 72 | 92 73 | 32 74 | 75 | 76 | 77 | 确定 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 24 87 | 72 88 | 51 89 | 21 90 | 91 | 92 | 93 | 用户名: 94 | 95 | 96 | 97 | 98 | 99 | 24 100 | 110 101 | 51 102 | 21 103 | 104 | 105 | 106 | 密码: 107 | 108 | 109 | 110 | 111 | 112 | 24 113 | 140 114 | 51 115 | 31 116 | 117 | 118 | 119 | 工作号: 120 | 121 | 122 | 123 | 124 | 125 | 24 126 | 175 127 | 41 128 | 31 129 | 130 | 131 | 132 | 性别: 133 | 134 | 135 | 136 | 137 | 138 | 24 139 | 210 140 | 51 141 | 31 142 | 143 | 144 | 145 | 身份证号: 146 | 147 | 148 | 149 | 150 | 151 | 90 152 | 72 153 | 121 154 | 25 155 | 156 | 157 | 158 | 159 | 160 | 161 | 220 162 | 110 163 | 47 164 | 16 165 | 166 | 167 | 168 | 明文 169 | 170 | 171 | 172 | 173 | 174 | 90 175 | 105 176 | 121 177 | 25 178 | 179 | 180 | 181 | 182 | 183 | 184 | 90 185 | 140 186 | 121 187 | 25 188 | 189 | 190 | 191 | 192 | 193 | 194 | 90 195 | 210 196 | 121 197 | 25 198 | 199 | 200 | 201 | 202 | 203 | 204 | 90 205 | 178 206 | 38 207 | 20 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 170 225 | 260 226 | 92 227 | 32 228 | 229 | 230 | 231 | 取消 232 | 233 | 234 | 235 | 236 | 237 | 10 238 | 5 239 | 255 240 | 51 241 | 242 | 243 | 244 | 245 | 246 | 247 | :/images/addUserHead.png 248 | 249 | 250 | 251 | 252 | 253 | 233 254 | 10 255 | 31 256 | 31 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | :/images/close.png:/images/close.png 265 | 266 | 267 | 268 | 32 269 | 32 270 | 271 | 272 | 273 | 274 | 275 | usernameLineEdit 276 | pswLineEdit 277 | jobNumLineEdit 278 | sexComboBox 279 | idCardLineEdit 280 | okBtn 281 | cancelBtn 282 | hidePswCheckBox 283 | closeBtn 284 | 285 | 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /choicegoodsdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "choicegoodsdlg.h" 2 | #include "ui_choicegoodsdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | ChoiceGoodsDlg::ChoiceGoodsDlg(QWidget *parent) : 14 | QDialog(parent), 15 | ui(new Ui::ChoiceGoodsDlg) 16 | { 17 | ui->setupUi(this); 18 | this->setWindowFlags(Qt::FramelessWindowHint); 19 | ui->listView->setStyle(new QPlastiqueStyle); 20 | this->setAttribute(Qt::WA_TranslucentBackground); 21 | typeModel = new QStringListModel(this); 22 | 23 | ui->listView->setModel(typeModel); 24 | loadList(); 25 | model = new QSqlTableModel; 26 | model->setTable("goodsNameTb"); 27 | model->setHeaderData(GoodsName_Id,Qt::Horizontal,tr("条码编号")); 28 | model->setHeaderData(GoodsName_Name,Qt::Horizontal,tr("商品名")); 29 | model->setHeaderData(GoodsName_Retail,Qt::Horizontal,tr("零售价")); 30 | model->select(); 31 | ui->tableView->setModel(model); 32 | ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); 33 | ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection); 34 | ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 35 | ui->tableView->horizontalHeader()->setStretchLastSection(true); 36 | ui->tableView->setColumnHidden(GoodsName_TypeId,true); 37 | ui->tableView->setColumnHidden(GoodsName_Unit,true); 38 | ui->tableView->setColumnHidden(GoodsName_Bid,true); 39 | ui->tableView->setColumnHidden(GoodsName_Format,true); 40 | ui->tableView->setColumnHidden(GoodsName_Stock,true); 41 | ui->tableView->setColumnHidden(GoodsName_Note,true); 42 | ui->tableView->setColumnWidth(GoodsName_Retail,50); 43 | } 44 | 45 | ChoiceGoodsDlg::~ChoiceGoodsDlg() 46 | { 47 | delete ui; 48 | } 49 | 50 | QString ChoiceGoodsDlg::getChoiceGoodsNum() const 51 | { 52 | if(goodsNum.isEmpty()) 53 | return QString(""); 54 | return goodsNum; 55 | } 56 | 57 | void ChoiceGoodsDlg::mousePressEvent(QMouseEvent *event) 58 | { 59 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 60 | { 61 | startPoint = event->globalPos() - frameGeometry().topLeft(); 62 | event->accept(); 63 | isDrag = true; 64 | // startPoint = QPoint(event->pos()); //将单击point存储 65 | } 66 | } 67 | 68 | void ChoiceGoodsDlg::mouseMoveEvent(QMouseEvent *event) 69 | { 70 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 50 && isDrag) 71 | { 72 | move(event->globalPos() - startPoint); 73 | event->accept(); 74 | } 75 | } 76 | 77 | void ChoiceGoodsDlg::mouseReleaseEvent(QMouseEvent *) 78 | { 79 | isDrag = false; 80 | } 81 | 82 | void ChoiceGoodsDlg::paintEvent(QPaintEvent *event) 83 | { 84 | QPainterPath path; 85 | path.setFillRule(Qt::WindingFill); 86 | path.addRect(10,10,this->width()-20,this->height()-20); 87 | QPainter painter(this); 88 | painter.setRenderHint(QPainter::Antialiasing,true); 89 | painter.fillPath(path,QBrush(Qt::white)); 90 | 91 | QColor color(0,0,0,55); 92 | for(int i = 0;i < 9;i++) 93 | { 94 | QPainterPath pathShadow; 95 | pathShadow.setFillRule(Qt::WindingFill); 96 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 97 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 98 | color.setAlpha(155-qSqrt(i)*55); 99 | painter.setPen(color); 100 | painter.drawPath(pathShadow); 101 | } 102 | } 103 | 104 | void ChoiceGoodsDlg::accept()//重新实现,当单击确定或者双击表格项时触发 105 | { 106 | int row = ui->tableView->currentIndex().row(); 107 | if(row != -1) //如果没有选择值为-1 108 | { 109 | //将商品编号存储到私有成员中 110 | goodsNum = ui->tableView->model()->index(row,0).data(Qt::DisplayRole).toString(); 111 | QDialog::accept(); //并调用父类方法以关闭窗体 112 | } 113 | else 114 | { 115 | QMessageBox::warning(this,tr("警告"),tr("请选择需要添加的商品"),QMessageBox::Ok); 116 | 117 | } 118 | } 119 | 120 | void ChoiceGoodsDlg::loadList() //加载所有商品 121 | { 122 | QStringList list; 123 | QSqlQuery query; 124 | query.exec(tr("select typename from goodsTypeTb")); 125 | while(query.next()) 126 | { 127 | list << query.value(0).toString(); 128 | } 129 | typeModel->setStringList(list); 130 | } 131 | 132 | void ChoiceGoodsDlg::on_lineEdit_textChanged(const QString &arg1) //商品类别搜索 133 | { 134 | if(arg1.isEmpty()) 135 | { 136 | loadList(); 137 | return; 138 | } 139 | QSqlQuery query; 140 | QStringList list; 141 | query.exec(tr("select *from goodsTypeTb where typename like '%1%'").arg(arg1)); 142 | while(query.next()) 143 | { 144 | list << query.value(1).toString(); 145 | } 146 | typeModel->setStringList(list); 147 | } 148 | 149 | void ChoiceGoodsDlg::on_listView_clicked(const QModelIndex &index) //商品类别选择 150 | { 151 | ui->lineEdit_2->clear(); 152 | QString text = index.data(Qt::DisplayRole).toString(); 153 | if(text == tr("查看所有商品")) 154 | { 155 | model->setFilter(tr("")); 156 | model->select(); 157 | return; 158 | } 159 | QSqlQuery query; 160 | query.exec(tr("select id from goodsTypeTb where typename = '%1'").arg(text)); 161 | query.next(); 162 | int id = query.value(0).toInt(); 163 | model->setFilter(tr("typeId = '%1'").arg(id)); 164 | model->select(); 165 | 166 | } 167 | 168 | void ChoiceGoodsDlg::on_lineEdit_2_textChanged(const QString &arg1) //商品名称或编号搜索 169 | { 170 | model->setFilter(tr("num like '%1%' or name like '%1%'").arg(arg1)); 171 | model->select(); 172 | if(ui->tableView->model()->rowCount() != 0) 173 | ui->tableView->selectRow(0); 174 | } 175 | 176 | void ChoiceGoodsDlg::on_tableView_doubleClicked(const QModelIndex &index) // 177 | { 178 | accept(); 179 | } 180 | 181 | -------------------------------------------------------------------------------- /choicegoodsdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef CHOICEGOODSDLG_H 2 | #define CHOICEGOODSDLG_H 3 | 4 | #include 5 | class QModelIndex; 6 | class QSqlTableModel; 7 | class QStringListModel; 8 | namespace Ui { 9 | class ChoiceGoodsDlg; 10 | } 11 | 12 | class ChoiceGoodsDlg : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | enum GoodsNameEnum { 18 | GoodsName_Id, 19 | GoodsName_TypeId, 20 | GoodsName_Name, 21 | GoodsName_Stock, 22 | GoodsName_Bid, 23 | GoodsName_Retail, 24 | GoodsName_Format, 25 | GoodsName_Unit, 26 | GoodsName_Note 27 | }; 28 | explicit ChoiceGoodsDlg(QWidget *parent = 0); 29 | ~ChoiceGoodsDlg(); 30 | QString getChoiceGoodsNum() const; 31 | protected: 32 | void mousePressEvent(QMouseEvent *event); 33 | void mouseMoveEvent(QMouseEvent *event); 34 | void mouseReleaseEvent(QMouseEvent *); 35 | void paintEvent(QPaintEvent *event); 36 | void accept(); 37 | 38 | private slots: 39 | void on_lineEdit_textChanged(const QString &arg1); 40 | void on_listView_clicked(const QModelIndex &index); 41 | 42 | void on_lineEdit_2_textChanged(const QString &arg1); 43 | 44 | void on_tableView_doubleClicked(const QModelIndex &index); 45 | 46 | private: 47 | Ui::ChoiceGoodsDlg *ui; 48 | void loadList(); 49 | QPoint startPoint; 50 | bool isDrag; //是否拖动 51 | QString goodsNum; 52 | QSqlTableModel *model; 53 | QStringListModel *typeModel; 54 | }; 55 | 56 | #endif // CHOICEGOODSDLG_H 57 | -------------------------------------------------------------------------------- /choicegoodsdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ChoiceGoodsDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 514 10 | 387 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QPushButton { 18 | color: white; 19 | font: bold 10pt; 20 | border-image: url(:/images/button.png) 16; 21 | border-width: 16px; 22 | padding: -16px 0px; 23 | min-height: 32px; 24 | min-width: 60px; 25 | } 26 | 27 | QPushButton:hover{ 28 | border-image:url(:/images/button_h.png) 16; 29 | } 30 | QPushButton:pressed{ 31 | border-image:url(:/images/button_p.png) 16; 32 | } 33 | QLabel { 34 | color:gray; 35 | 36 | } 37 | QToolButton { 38 | border:0; 39 | } 40 | QToolButton#closeBtn{ 41 | background-image: url(:/images/close.png); 42 | } 43 | 44 | QToolButton#closeBtn:hover { 45 | background-image: url(:/images/close_h.png); 46 | } 47 | 48 | QToolButton#closeBtn:pressed { 49 | background-image: url(:/images/close_p.png); 50 | } 51 | 52 | QListView,QTableView,QLineEdit { 53 | color: rgb(127, 0, 63); 54 | background-color: rgb(255, 255, 241); 55 | selection-color: white; 56 | selection-background-color: rgb(191, 31, 127); 57 | border: 2px groove gray; 58 | border-radius: 10px; 59 | padding: 2px 4px; 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 270 67 | 340 68 | 92 69 | 32 70 | 71 | 72 | 73 | 确定 74 | 75 | 76 | 77 | 78 | 79 | 380 80 | 340 81 | 92 82 | 32 83 | 84 | 85 | 86 | 取消 87 | 88 | 89 | 90 | 91 | 92 | 471 93 | 10 94 | 32 95 | 32 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 32 104 | 32 105 | 106 | 107 | 108 | 109 | 110 | 111 | 10 112 | 10 113 | 494 114 | 41 115 | 116 | 117 | 118 | 119 | 120 | 121 | :/images/choiceDlgHeader.png 122 | 123 | 124 | 125 | 126 | 127 | 160 128 | 100 129 | 331 130 | 231 131 | 132 | 133 | 134 | 135 | 136 | 137 | 20 138 | 60 139 | 121 140 | 31 141 | 142 | 143 | 144 | 145 | 12 146 | 147 | 148 | 149 | 搜索... 150 | 151 | 152 | 153 | 154 | 155 | 160 156 | 60 157 | 241 158 | 31 159 | 160 | 161 | 162 | 163 | 12 164 | 165 | 166 | 167 | 请输入编号或者商品名搜索... 168 | 169 | 170 | 171 | 172 | 173 | 20 174 | 100 175 | 121 176 | 231 177 | 178 | 179 | 180 | label 181 | pushButton 182 | pushButton_2 183 | closeBtn 184 | tableView 185 | lineEdit 186 | lineEdit_2 187 | listView 188 | 189 | 190 | 191 | 192 | 193 | 194 | closeBtn 195 | clicked() 196 | ChoiceGoodsDlg 197 | reject() 198 | 199 | 200 | 471 201 | 19 202 | 203 | 204 | 413 205 | 48 206 | 207 | 208 | 209 | 210 | pushButton_2 211 | clicked() 212 | ChoiceGoodsDlg 213 | reject() 214 | 215 | 216 | 435 217 | 353 218 | 219 | 220 | 492 221 | 352 222 | 223 | 224 | 225 | 226 | pushButton 227 | clicked() 228 | ChoiceGoodsDlg 229 | accept() 230 | 231 | 232 | 327 233 | 351 234 | 235 | 236 | 227 237 | 355 238 | 239 | 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /collectdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "collectdlg.h" 2 | #include "ui_collectdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | collectDlg::collectDlg(double pay, QWidget *parent) : 9 | QDialog(parent), 10 | ui(new Ui::collectDlg) 11 | { 12 | ui->setupUi(this); 13 | this->setWindowFlags(Qt::FramelessWindowHint); 14 | this->setAttribute(Qt::WA_TranslucentBackground); 15 | ui->priceLineEdit->setText(QString::number(pay)); 16 | ui->collectLineEdit->setText(QString::number(pay)); 17 | ui->collectLineEdit->selectAll(); 18 | ui->collectLineEdit->setFocus(); 19 | ui->OkBtn->setDefault(true); 20 | QDoubleValidator *validator = new QDoubleValidator(this); 21 | validator->setDecimals(1); 22 | validator->setBottom(0); 23 | ui->collectLineEdit->setValidator(validator); 24 | } 25 | 26 | collectDlg::~collectDlg() 27 | { 28 | delete ui; 29 | } 30 | 31 | void collectDlg::accept() 32 | { 33 | double pr = ui->changeLineEdit->text().toDouble(); 34 | if(pr < 0) 35 | { 36 | QMessageBox::warning(this,tr("警告"),tr("实付不得小于总价。"),QMessageBox::Ok); 37 | return; 38 | } 39 | QDialog::accept(); 40 | } 41 | 42 | double collectDlg::getPayPrice() const 43 | { 44 | return ui->collectLineEdit->text().toDouble(); 45 | } 46 | 47 | void collectDlg::mousePressEvent(QMouseEvent *event) 48 | { 49 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 50 | { 51 | startPoint = event->globalPos() - frameGeometry().topLeft(); 52 | event->accept(); 53 | isDrag = true; 54 | // startPoint = QPoint(event->pos()); //将单击point存储 55 | } 56 | } 57 | 58 | void collectDlg::mouseMoveEvent(QMouseEvent *event) 59 | { 60 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 50 && isDrag) 61 | { 62 | move(event->globalPos() - startPoint); 63 | event->accept(); 64 | } 65 | } 66 | 67 | void collectDlg::mouseReleaseEvent(QMouseEvent *event) 68 | { 69 | isDrag = false; 70 | } 71 | 72 | void collectDlg::paintEvent(QPaintEvent *event) 73 | { 74 | QPainterPath path; 75 | path.setFillRule(Qt::WindingFill); 76 | path.addRect(10,10,this->width()-20,this->height()-20); 77 | QPainter painter(this); 78 | painter.setRenderHint(QPainter::Antialiasing,true); 79 | painter.fillPath(path,QBrush(Qt::white)); 80 | 81 | QColor color(0,0,0,55); 82 | for(int i = 0;i < 9;i++) 83 | { 84 | QPainterPath pathShadow; 85 | pathShadow.setFillRule(Qt::WindingFill); 86 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 87 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 88 | color.setAlpha(155-qSqrt(i)*55); 89 | painter.setPen(color); 90 | painter.drawPath(pathShadow); 91 | } 92 | } 93 | 94 | void collectDlg::on_collectLineEdit_textChanged(const QString &arg1) 95 | { 96 | double pay = ui->priceLineEdit->text().toDouble(); //应付 97 | double factPay = arg1.toDouble(); 98 | ui->changeLineEdit->setText(QString::number(factPay - pay)); 99 | } 100 | -------------------------------------------------------------------------------- /collectdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLECTDLG_H 2 | #define COLLECTDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class collectDlg; 8 | } 9 | 10 | class collectDlg : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit collectDlg(double pay,QWidget *parent = 0); 16 | ~collectDlg(); 17 | void accept(); 18 | double getPayPrice() const; 19 | protected: 20 | void mousePressEvent(QMouseEvent *event); 21 | void mouseMoveEvent(QMouseEvent *event); 22 | void mouseReleaseEvent(QMouseEvent *event); 23 | void paintEvent(QPaintEvent *event); 24 | private slots: 25 | void on_collectLineEdit_textChanged(const QString &arg1); 26 | 27 | private: 28 | Ui::collectDlg *ui; 29 | QPoint startPoint; 30 | bool isDrag; //是否拖动 31 | }; 32 | 33 | #endif // COLLECTDLG_H 34 | -------------------------------------------------------------------------------- /collectdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | collectDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 289 10 | 283 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QDialog { 18 | border-radius:3px; 19 | border:1px groove gray; 20 | } 21 | 22 | QToolButton { 23 | border:0; 24 | } 25 | QToolButton#closeBtn{ 26 | background-image: url(:/images/close.png); 27 | } 28 | 29 | QToolButton#closeBtn:hover { 30 | background-image: url(:/images/close_h.png); 31 | } 32 | 33 | QToolButton#closeBtn:pressed { 34 | background-image: url(:/images/close_p.png); 35 | } 36 | 37 | 38 | QLineEdit { 39 | color:rgb(127,0,63); 40 | border:2px groove gray; 41 | border-radius:6px; 42 | selection-color: white; 43 | selection-background-color: rgb(191, 31, 127); 44 | } 45 | 46 | QPushButton { 47 | color: white; 48 | font: bold 10pt; 49 | border-image: url(:/images/button.png) 16; 50 | border-width: 16px; 51 | padding: -16px 0px; 52 | min-height: 32px; 53 | min-width: 60px; 54 | } 55 | 56 | QPushButton:hover{ 57 | border-image:url(:/images/button_h.png) 16; 58 | } 59 | QPushButton:pressed{ 60 | border-image:url(:/images/button_p.png) 16; 61 | } 62 | QLabel { 63 | color:gray; 64 | 65 | } 66 | QCheckBox { 67 | color:gray; 68 | } 69 | 70 | QLabel#errorInforLabel { 71 | color:white; 72 | background-color: rgb(255, 0, 0); 73 | } 74 | 75 | 76 | 77 | 78 | 79 | 246 80 | 10 81 | 32 82 | 32 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 32 91 | 32 92 | 93 | 94 | 95 | 96 | 97 | 98 | 10 99 | 10 100 | 269 101 | 40 102 | 103 | 104 | 105 | 106 | 107 | 108 | :/images/collectHeader.png 109 | 110 | 111 | 112 | 113 | 114 | 80 115 | 230 116 | 192 117 | 34 118 | 119 | 120 | 121 | 122 | 123 | 124 | 确定 125 | 126 | 127 | 128 | 129 | 130 | 131 | 取消 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 30 141 | 60 142 | 231 143 | 161 144 | 145 | 146 | 147 | 148 | 149 | 150 | 价格: 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 0 159 | 30 160 | 161 | 162 | 163 | 164 | 12 165 | 166 | 167 | 168 | 70 169 | 170 | 171 | true 172 | 173 | 174 | 175 | 176 | 177 | 178 | 收银: 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 0 187 | 30 188 | 189 | 190 | 191 | 192 | 12 193 | 194 | 195 | 196 | 100 197 | 198 | 199 | 200 | 201 | 202 | 203 | 打折: 204 | 205 | 206 | 207 | 208 | 209 | 210 | % 211 | 212 | 213 | 100.000000000000000 214 | 215 | 216 | 100.000000000000000 217 | 218 | 219 | 220 | 221 | 222 | 223 | Qt::Horizontal 224 | 225 | 226 | 227 | 40 228 | 20 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 找零: 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 0 245 | 30 246 | 247 | 248 | 249 | 250 | 12 251 | 252 | 253 | 254 | 0 255 | 256 | 257 | true 258 | 259 | 260 | 261 | 262 | 263 | 264 | 打印小票 265 | 266 | 267 | 268 | 269 | 270 | layoutWidget 271 | layoutWidget 272 | label_5 273 | closeBtn 274 | 275 | 276 | priceLineEdit 277 | collectLineEdit 278 | doubleSpinBox 279 | changeLineEdit 280 | checkBox 281 | OkBtn 282 | cancelBtn 283 | closeBtn 284 | 285 | 286 | 287 | 288 | 289 | 290 | closeBtn 291 | clicked() 292 | collectDlg 293 | reject() 294 | 295 | 296 | 275 297 | 21 298 | 299 | 300 | 286 301 | 76 302 | 303 | 304 | 305 | 306 | cancelBtn 307 | clicked() 308 | collectDlg 309 | reject() 310 | 311 | 312 | 230 313 | 248 314 | 315 | 316 | 268 317 | 225 318 | 319 | 320 | 321 | 322 | OkBtn 323 | clicked() 324 | collectDlg 325 | accept() 326 | 327 | 328 | 94 329 | 243 330 | 331 | 332 | 51 333 | 240 334 | 335 | 336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /colordefines.h: -------------------------------------------------------------------------------- 1 | #ifndef COLORDEFINES_H 2 | #define COLORDEFINES_H 3 | 4 | #include 5 | 6 | // Title bar 7 | const QColor color_title_bar(88, 115, 201); 8 | 9 | // Navi bar 10 | const QColor color_hover(209, 216, 240); 11 | const QColor color_selected(133, 153, 216); 12 | const QColor color_child_normal(239, 241, 250); 13 | const QColor color_parent_normal(247, 249, 255); 14 | const QColor color_line(214, 216, 224); 15 | const QColor color_text_normal(58, 58, 58); 16 | const QColor color_text_selected(255, 255, 255); 17 | 18 | // Menu 19 | const QColor color_menu_hover(224, 232, 241); 20 | 21 | inline QString ColorToString(QColor color) 22 | { 23 | return QString("rgb(%1,%2, %3)") 24 | .arg(color.red()).arg(color.green()).arg(color.blue()); 25 | } 26 | 27 | #endif // COLORDEFINES_H -------------------------------------------------------------------------------- /config/configForAdmin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /config/configForGeneral.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /connection.h: -------------------------------------------------------------------------------- 1 | #ifndef CONNECTION_H 2 | #define CONNECTION_H 3 | #include 4 | #include 5 | #include 6 | /* 7 | 建立数据库以及表 8 | */ 9 | static bool createConnection() 10 | { 11 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); 12 | db.setDatabaseName("MarketDb.db"); 13 | db.setUserName(QString("hxb")); 14 | db.setPassword(QString("123456")); 15 | if(! db.open()) 16 | { 17 | QMessageBox::critical(0,QString("严重错误") 18 | ,QString("无法创建数据库\n原因:%1").arg(db.lastError().text()), 19 | QMessageBox::Ok); 20 | return false; 21 | } 22 | return true; 23 | } 24 | 25 | static void addData() 26 | { 27 | QProgressDialog dialog; //创建一个进度条,显示添加数据的进度 28 | dialog.setWindowModality(Qt::WindowModal); 29 | dialog.setWindowTitle(QObject::tr("Manager")); 30 | dialog.setLabelText(QObject::tr("Creating database...")); 31 | dialog.setMinimum(0); 32 | dialog.setMaximum(10); 33 | dialog.show(); 34 | qApp->processEvents(); 35 | dialog.setValue(0); 36 | QSqlQuery query; 37 | query.exec(QString("create table userTb (username varchar(15) primary key," 38 | "password varchar(20)," 39 | "jobNum varchar(15) not null," 40 | "sex varchar(2) not null," 41 | "IDcardNum varchar(18) not null,lastLogTime datetime not null)")); 42 | query.exec(QString("insert into userTb values('admin','123456','20150905003','女','330523199509265212','2016-09-02 12:12:32')")); 43 | query.exec(QString("insert into userTb values('hxb','123456','20160805002','男','330523199306202512','2016-09-02 12:12:32')")); 44 | qApp->processEvents(); 45 | dialog.setValue(1); 46 | //商品类别表 47 | query.exec(QString("create table goodsTypeTb (id int primary key,typename varchar(20) not null)")); 48 | query.exec(QString("insert into goodsTypeTb values(00,'查看所有商品')")); 49 | query.exec(QString("insert into goodsTypeTb values(01,'饮料类')")); 50 | query.exec(QString("insert into goodsTypeTb values(02,'零食类')")); 51 | query.exec(QString("insert into goodsTypeTb values(03,'学习用品类')")); 52 | qApp->processEvents(); 53 | dialog.setValue(2); 54 | 55 | //商品表 56 | query.exec(QString("create table goodsNameTb (num varchar(15) primary key,typeId int" 57 | ",name varchar(30) not null,stock int not null,bid double not null" 58 | ",retail double not null," 59 | "format varchar(10) not null,unit varchar(1) not null,note varchar(50)," 60 | "foreign key(typeId) references goodsTypeTb)")); 61 | query.exec(QString("insert into goodsNameTb values('912543524',01,'百事可乐',98,3.7,4.2,'450ML','瓶','none')")); 62 | query.exec(QString("insert into goodsNameTb values('934210249',01,'营养快线',42,3,4.2,'450ML','瓶','none')")); 63 | query.exec(QString("insert into goodsNameTb values('915346324',02,'乐事薯片',54,2,3,'200g','袋','none')")); 64 | query.exec(QString("insert into goodsNameTb values('950024153',02,'德芙巧克力',13,3,4,'100g','袋','none')")); 65 | query.exec(QString("insert into goodsNameTb values('965346813',01,'养乐多',64,3,5,'250ML','瓶','none')")); 66 | qApp->processEvents(); 67 | dialog.setValue(3); 68 | query.exec(QString("insert into goodsNameTb values('965437145',02,'彩虹糖',7,3,5,'80g','袋','none')")); 69 | query.exec(QString("insert into goodsNameTb values('965789786',01,'七喜',46,3,4,'450ML','瓶','none')")); 70 | query.exec(QString("insert into goodsNameTb values('976407358',02,'闲趣饼干',25,3,4,'400g','袋','none')")); 71 | query.exec(QString("insert into goodsNameTb values('930700077',01,'脉动',534,3,4,'450ML','瓶','none')")); 72 | query.exec(QString("insert into goodsNameTb values('912311114',02,'卫龙辣条(大)',14,3,4,'300g','袋','none')")); 73 | query.exec(QString("insert into goodsNameTb values('963876357',01,'冰红茶',67,3,4.8,'400ML','瓶','none')")); 74 | qApp->processEvents(); 75 | dialog.setValue(4); 76 | query.exec(QString("insert into goodsNameTb values('963786371',02,'凤爪',85,3,4.6,'100g','袋','none')")); 77 | query.exec(QString("insert into goodsNameTb values('935672615',01,'+C',98,3,4.1,'400ML','瓶','none')")); 78 | query.exec(QString("insert into goodsNameTb values('900008874',01,'恒大矿泉水',46,1,2.2,'400ML','瓶','none')")); 79 | query.exec(QString("insert into goodsNameTb values('943534643',02,'鲜虾饼',34,3,4,'100g','袋','none')")); 80 | query.exec(QString("insert into goodsNameTb values('914546345',02,'火腿肠',14,3,4,'70g','袋','none')")); 81 | query.exec(QString("insert into goodsNameTb values('946346346',01,'橙汁',65,3,4,'800ML','瓶','none')")); 82 | qApp->processEvents(); 83 | dialog.setValue(5); 84 | query.exec(QString("insert into goodsNameTb values('901410011',01,'可口可乐',85,3,4,'800ML','瓶','none')")); 85 | query.exec(QString("insert into goodsNameTb values('951356716',01,'柠檬水',85,3,4,'450ML','瓶','none')")); 86 | query.exec(QString("insert into goodsNameTb values('916572367',02,'肉松饼',96,3,4,'50g','袋','none')")); 87 | query.exec(QString("insert into goodsNameTb values('935720175',02,'鸡爪',998,3,4,'70g','袋','none')")); 88 | query.exec(QString("insert into goodsNameTb values('963767371',02,'康师傅统一方便面',24,3,4,'300g','桶','none')")); 89 | query.exec(QString("insert into goodsNameTb values('923658362',02,'绿箭口香糖',93,4,5,'30g','盒','none')")); 90 | qApp->processEvents(); 91 | dialog.setValue(6); 92 | query.exec(QString("insert into goodsNameTb values('916358262',02,'炫迈口香糖',35,3,4,'30g','盒','none')")); 93 | query.exec(QString("insert into goodsNameTb values('973876363',02,'益达口香糖',3,3,4,'30g','盒','none')")); 94 | query.exec(QString("insert into goodsNameTb values('907948784',02,'菜园小饼',63,3,4,'100g','袋','none')")); 95 | query.exec(QString("insert into goodsNameTb values('900637496',02,'巧乐兹',25,3,4,'120g','袋','none')")); 96 | qApp->processEvents(); 97 | dialog.setValue(7); 98 | 99 | //出售表 订单号,售货员,出售时间,实际价格,收银 100 | query.exec(QString("create table sellTb(sellId varchar(15) not null," 101 | "sellMan varchar(15) not null references userTb(username)," 102 | "sellDateTime datetime not null," 103 | "factPrice double not null," 104 | "collectPrice double not null,sellCount int not null)")); 105 | query.exec(QString("insert into sellTb values('20160902_001','admin','2016-09-02 12:12:32',100.00,30.00,5)")); 106 | qApp->processEvents(); 107 | dialog.setValue(8); 108 | /* 109 | 出售表:每一件商品单独成一条数据,每一次购买商品有一个唯一的sellId,而每一条数据有一个唯一的serialNum标记 110 | 111 | */ 112 | query.exec(QString("create table sellListTb(serialNum int primary key not null," 113 | "sellId varchar(15) not null references sellTb(sellId)," 114 | "todayCount int not null," 115 | "goodsId varchar(15) references goodsNameTb(num)," 116 | "count int not null," 117 | "dateTime date not null)")); 118 | qApp->processEvents(); 119 | dialog.setValue(9); 120 | //供应商表 121 | query.exec(QString("create table supplierTb(id int primary key not null,name varchar(15) not null," 122 | "contact varchar(10) not null,telephone varchar(11) not null,address varchar(20)," 123 | "note varchar(30))")); 124 | query.exec(QString("insert into supplierTb values(001,'杭州华联批发商城','张胖胖','13857127973','杭州市','none')")); 125 | //进货表 126 | query.exec(QString("create table purchaseTb(num varchar(18) not null primary key,dateTime date not null," 127 | "supplierId int not null references supplierTb(id),totalPrice double not null," 128 | "handler varchar(15) not null references userTb(username),note varchar(30))")); 129 | query.exec(QString("insert into purchaseTb values('123242141','2016-09-07','1',123.51,'admin','note')")); 130 | //进货明细表 131 | query.exec(QString("create table purchaseDetailTb(id int primary key not null," 132 | "purchaseId varchar(18) not null references purchaseTb(id)," 133 | "goodsId varchar(15) references goodsNameTb(num)," 134 | "count int not null)")); 135 | qApp->processEvents(); 136 | dialog.setValue(10); 137 | } 138 | 139 | #endif // CONNECTION_H 140 | -------------------------------------------------------------------------------- /goodsnumdelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "goodsnumdelegate.h" 2 | #include 3 | 4 | GoodsNumDelegate::GoodsNumDelegate(int selectColumn, QObject *parent) : 5 | QItemDelegate(parent) 6 | { 7 | numColumn = selectColumn; 8 | } 9 | 10 | void GoodsNumDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 11 | { 12 | if(index.column() == numColumn) 13 | { 14 | int num = index.model()->data(index,Qt::DisplayRole).toInt(); 15 | QSpinBox *spinBox = qobject_cast(editor); 16 | spinBox->setValue(num); 17 | } 18 | else 19 | { 20 | QItemDelegate::setEditorData(editor,index); 21 | } 22 | } 23 | 24 | void GoodsNumDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const 25 | { 26 | if(index.column() == numColumn) 27 | { 28 | QSpinBox *spinBox = qobject_cast(editor); 29 | model->setData(index,spinBox->value()); 30 | } 31 | else 32 | { 33 | QItemDelegate::setModelData(editor,model,index); 34 | } 35 | } 36 | 37 | QWidget *GoodsNumDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const 38 | { 39 | if(index.column() == numColumn) 40 | { 41 | QSpinBox *spinBox = new QSpinBox(parent); 42 | spinBox->setRange(1,99); 43 | connect(spinBox,SIGNAL(editingFinished()),this,SLOT(commitAndCloseEditor())); 44 | return spinBox; 45 | } 46 | else 47 | { 48 | return QItemDelegate::createEditor(parent,option,index); 49 | } 50 | } 51 | 52 | void GoodsNumDelegate::commitAndCloseEditor() 53 | { 54 | QSpinBox *spinBox = qobject_cast(sender()); 55 | emit commitData(spinBox); 56 | emit closeEditor(spinBox); 57 | } 58 | -------------------------------------------------------------------------------- /goodsnumdelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef GOODSNUMDELEGATE_H 2 | #define GOODSNUMDELEGATE_H 3 | 4 | #include 5 | 6 | class GoodsNumDelegate : public QItemDelegate 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit GoodsNumDelegate(int selectColumn,QObject *parent = 0); 11 | void setEditorData(QWidget *editor, const QModelIndex &index) const; 12 | void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; 13 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; 14 | signals: 15 | 16 | public slots: 17 | private slots: 18 | void commitAndCloseEditor(); 19 | private: 20 | int numColumn; 21 | }; 22 | 23 | #endif // GOODSNUMDELEGATE_H 24 | -------------------------------------------------------------------------------- /histogramview.cpp: -------------------------------------------------------------------------------- 1 | #include "histogramview.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | HistogramView::HistogramView(QWidget *parent) : 8 | QAbstractItemView(parent) 9 | { 10 | QSqlQuery query; 11 | double temp = 0.0; //每一天的总价 12 | totalPrice.clear(); 13 | QDate date = QDate::currentDate().addDays(-7); 14 | QString dateStr = date.toString("yyyy-MM-dd"); //一个星期前 15 | for(int i = 0;i < 7;i++) 16 | { 17 | query.exec(tr("select collectPrice from sellTb where sellDateTime like '%1%'") 18 | .arg(dateStr)); 19 | while(query.next()) 20 | { 21 | temp += query.value(0).toDouble(); 22 | } 23 | totalPrice.append(temp); 24 | date = date.addDays(1); 25 | dateStr = date.toString("yyyy-MM-dd"); 26 | temp = 0.0; 27 | } 28 | //测试用的数据 29 | totalPrice.clear(); 30 | for(int i = 1;i <= 7;++i) 31 | totalPrice.append(double(i * 10)); 32 | } 33 | 34 | QModelIndex HistogramView::indexAt(const QPoint &point) const 35 | { 36 | return QModelIndex(); 37 | } 38 | 39 | void HistogramView::setSelectionModel(QItemSelectionModel *selectionModel) 40 | { 41 | 42 | } 43 | 44 | void HistogramView::paintEvent(QPaintEvent *event) //绘制柱状图 859 * 519 45 | { 46 | /* 47 | *viewport宽 : 859 高: 519 48 | *标尺x轴分别为100 以及 759 ,每一条标尺间相隔140 49 | *前面数字的x轴为50 50 | *标题的起始坐标为(350,50) 51 | * 52 | * 53 | * 54 | * 55 | * 56 | 57 | */ 58 | QPainter painter(this->viewport()); 59 | // painter.setRenderHint(QPainter::Antialiasing,true); 60 | QPen pen(Qt::gray,1); 61 | painter.setPen(pen); 62 | for(int i = 0;i < 10;i++) { 63 | painter.drawLine(QPoint(100,100 + 40 * i),QPoint(759,100 + 40 * i)); 64 | } 65 | painter.setFont(QFont(tr("黑体"), 14, QFont::Bold)); 66 | pen.setColor(Qt::black); 67 | painter.setPen(pen); 68 | for(int i = 0;i < 10;i++) { 69 | painter.drawText(QPoint(50,110 + 40 * i),tr("%1").arg(i * 100)); 70 | } 71 | painter.drawText(QRectF(350,50,500,50),tr("最近一个月销售情况")); 72 | 73 | //绘制柱状图 74 | QColor color(79,129,189); 75 | painter.setBrush(color); 76 | painter.setPen(Qt::NoPen); 77 | // for(int i = 0;i < 10;i++) { 78 | painter.drawRect(100,100,30,500); 79 | painter.drawRect(QRect()); 80 | // } 81 | 82 | } 83 | 84 | //数据发生改变 85 | void HistogramView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) 86 | { 87 | QAbstractItemView::dataChanged(topLeft,bottomRight); 88 | this->viewport()->update(); 89 | } 90 | 91 | //选择发生改变 92 | void HistogramView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) 93 | { 94 | this->viewport()->update(); 95 | } 96 | 97 | //单击柱状图 98 | void HistogramView::mousePressEvent(QMouseEvent *event) 99 | { 100 | QAbstractItemView::mousePressEvent(event); 101 | setSelection(QRect(event->x(),event->y(),1,1),QItemSelectionModel::SelectCurrent); 102 | } 103 | 104 | void HistogramView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) 105 | { 106 | int rows = model()->rowCount(this->rootIndex()); 107 | int columns = model()->columnCount(this->rootIndex()); 108 | QModelIndex selectedIndex; 109 | 110 | } 111 | 112 | 113 | //不需实现,但需要定义 114 | QRegion HistogramView::visualRegionForSelection(const QItemSelection &selection) const{} 115 | 116 | int HistogramView::horizontalOffset() const{} 117 | 118 | int HistogramView::verticalOffset() const {} 119 | 120 | bool HistogramView::isIndexHidden(const QModelIndex &index) const {} 121 | 122 | QRect HistogramView::visualRect(const QModelIndex &index) const {} 123 | 124 | void HistogramView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint){} 125 | 126 | QModelIndex HistogramView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers){} 127 | -------------------------------------------------------------------------------- /histogramview.h: -------------------------------------------------------------------------------- 1 | #ifndef HISTOGRAMVIEW_H 2 | #define HISTOGRAMVIEW_H 3 | 4 | #include 5 | 6 | class HistogramView : public QAbstractItemView 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit HistogramView(QWidget *parent = 0); 11 | QRect visualRect(const QModelIndex &index) const; 12 | void scrollTo(const QModelIndex &index, ScrollHint hint); 13 | QModelIndex indexAt(const QPoint &point) const; 14 | void setSelectionModel(QItemSelectionModel *selectionModel); 15 | 16 | protected: 17 | void paintEvent(QPaintEvent *); 18 | void mousePressEvent(QMouseEvent *event); 19 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers); 20 | int horizontalOffset() const; 21 | int verticalOffset()const; 22 | bool isIndexHidden(const QModelIndex &index) const; 23 | void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command); 24 | QRegion visualRegionForSelection(const QItemSelection &selection) const; 25 | protected slots: 26 | void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 27 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 28 | private: 29 | QItemSelectionModel *selections; 30 | QList MRegionList; 31 | QList CRegionList; 32 | QVector totalPrice; 33 | }; 34 | 35 | #endif // HISTOGRAMVIEW_H 36 | -------------------------------------------------------------------------------- /ico.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "supermarket.ico" -------------------------------------------------------------------------------- /images/IndexPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/IndexPage.png -------------------------------------------------------------------------------- /images/addGoodsTypeHead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/addGoodsTypeHead.png -------------------------------------------------------------------------------- /images/addSupplierHead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/addSupplierHead.png -------------------------------------------------------------------------------- /images/addUserHead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/addUserHead.png -------------------------------------------------------------------------------- /images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/background.png -------------------------------------------------------------------------------- /images/bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/bottom.png -------------------------------------------------------------------------------- /images/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/button.png -------------------------------------------------------------------------------- /images/button_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/button_h.png -------------------------------------------------------------------------------- /images/button_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/button_p.png -------------------------------------------------------------------------------- /images/choiceDlgHeader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/choiceDlgHeader.png -------------------------------------------------------------------------------- /images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/close.png -------------------------------------------------------------------------------- /images/close_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/close_h.png -------------------------------------------------------------------------------- /images/close_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/close_p.png -------------------------------------------------------------------------------- /images/collectHeader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/collectHeader.png -------------------------------------------------------------------------------- /images/expand_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/expand_normal.png -------------------------------------------------------------------------------- /images/expand_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/expand_selected.png -------------------------------------------------------------------------------- /images/headimg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/headimg.png -------------------------------------------------------------------------------- /images/mainBottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/mainBottom.png -------------------------------------------------------------------------------- /images/mainHeader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/mainHeader.png -------------------------------------------------------------------------------- /images/min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/min.png -------------------------------------------------------------------------------- /images/min_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/min_h.png -------------------------------------------------------------------------------- /images/min_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/min_p.png -------------------------------------------------------------------------------- /images/modifyUserHead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/modifyUserHead.png -------------------------------------------------------------------------------- /images/purchaseHeadpng.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/purchaseHeadpng.png -------------------------------------------------------------------------------- /images/supplierHead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/supplierHead.png -------------------------------------------------------------------------------- /images/tableBack .jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/tableBack .jpg -------------------------------------------------------------------------------- /images/tlHeaderImg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/tlHeaderImg.png -------------------------------------------------------------------------------- /images/toolBoxImg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/toolBoxImg.png -------------------------------------------------------------------------------- /images/unexpand_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/unexpand_normal.png -------------------------------------------------------------------------------- /images/unexpand_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/images/unexpand_selected.png -------------------------------------------------------------------------------- /logindlg.cpp: -------------------------------------------------------------------------------- 1 | #include "logindlg.h" 2 | #include "ui_logindlg.h" 3 | #include 4 | #include 5 | #include "connection.h" 6 | #include "showinforlabel.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | LoginDlg::LoginDlg(QWidget *parent) : 13 | QDialog(parent), 14 | ui(new Ui::LoginDlg) 15 | { 16 | ui->setupUi(this); 17 | this->setWindowFlags(Qt::FramelessWindowHint); //设置窗体为无边框 18 | this->setAttribute(Qt::WA_TranslucentBackground); 19 | ui->userNameLineEdit->setFocus(); 20 | ui->loginBtn->setDefault(true); //设置登录按钮为默认按钮(Enter可触发) 21 | errorLabel = new ShowInforLabel(this); //显示密码不正确等错误信息的label 22 | errorLabel->setVisible(false); //先不显示 23 | readSetting(); 24 | } 25 | 26 | LoginDlg::~LoginDlg() 27 | { 28 | delete ui; 29 | } 30 | 31 | QString LoginDlg::getUserName() const 32 | { 33 | return ui->userNameLineEdit->text(); 34 | } 35 | 36 | void LoginDlg::on_loginBtn_clicked() //登录按钮单击 37 | { 38 | if(ui->userNameLineEdit->text().isEmpty()) //判断用户名是否为空 39 | { 40 | this->setErrorLabelText(tr("请输入用户名")) ; 41 | ui->userNameLineEdit->setFocus(); 42 | return; 43 | } 44 | QString name = ui->userNameLineEdit->text().trimmed(); //取出用户名 45 | QString password = ui->passwordLineEdit->text(); //取出密码 46 | QSqlQuery query(tr("select username from userTb"));//遍历表中所有的用户名 47 | bool hasUser = false; 48 | while(query.next()) 49 | { 50 | if(query.value(0).toString() == name) 51 | { 52 | hasUser = true; 53 | break; 54 | } 55 | } 56 | if(hasUser) //如果有这个用户 57 | { 58 | query.exec(QString("select password from userTb where username = '%1'").arg(name)); 59 | query.next(); 60 | if(query.value(0).toString() == password) //如果用户名以及密码都正确,就接受 61 | { 62 | accept(); 63 | } 64 | else 65 | { 66 | this->setErrorLabelText(tr("密码不正确,请重新输入"),QPoint(80,125)); //调用自定义函数,进行显示错误信息 67 | ui->passwordLineEdit->selectAll(); 68 | ui->passwordLineEdit->setFocus(); 69 | } 70 | } 71 | else 72 | { 73 | this->setErrorLabelText(tr("对不起,没有该用户,请重新输入")); 74 | ui->userNameLineEdit->selectAll(); 75 | ui->userNameLineEdit->setFocus(); 76 | } 77 | } 78 | 79 | void LoginDlg::setLabelOpacity() //执行自定义属性“opacity”动画 80 | { 81 | QPropertyAnimation *animation = new QPropertyAnimation(errorLabel,"opacity"); 82 | 83 | animation->setStartValue(1.0); 84 | animation->setEndValue(0.0); 85 | animation->setDuration(1500); 86 | animation->start(QAbstractAnimation::DeleteWhenStopped); 87 | connect(animation,SIGNAL(finished()),errorLabel,SLOT(setWindowVisable()));//当结束时,设置label为不可见 88 | } 89 | 90 | 91 | void LoginDlg::mousePressEvent(QMouseEvent *event) //拉动窗体 92 | { 93 | if(event->button() == Qt::LeftButton && event->pos().y() < 70) //判断是否为左键 94 | { 95 | startPoint = event->globalPos() - frameGeometry().topLeft(); 96 | isDrag = true; 97 | event->accept(); 98 | // startPoint = QPoint(event->pos()); //将单击point存储 99 | } 100 | } 101 | 102 | void LoginDlg::mouseMoveEvent(QMouseEvent *event) 103 | { 104 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 105 | { 106 | move(event->globalPos() - startPoint); 107 | event->accept(); 108 | } 109 | } 110 | 111 | void LoginDlg::mouseReleaseEvent(QMouseEvent *event) 112 | { 113 | isDrag = false; 114 | } 115 | 116 | void LoginDlg::paintEvent(QPaintEvent *event) 117 | { 118 | QPainterPath path; 119 | path.setFillRule(Qt::WindingFill); 120 | path.addRect(10,10,this->width()-20,this->height()-20); 121 | QPainter painter(this); 122 | painter.setRenderHint(QPainter::Antialiasing,true); 123 | painter.fillPath(path,QBrush(Qt::white)); 124 | 125 | QColor color(0,0,0,55); 126 | for(int i = 0;i < 9;i++) 127 | { 128 | QPainterPath pathShadow; 129 | pathShadow.setFillRule(Qt::WindingFill); 130 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 131 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 132 | color.setAlpha(155-qSqrt(i)*55); 133 | painter.setPen(color); 134 | painter.drawPath(pathShadow); 135 | } 136 | } 137 | 138 | void LoginDlg::setErrorLabelText(const QString &text, const QPoint &point) 139 | { 140 | if(errorLabel->isVisible()) //避免出现动画还没stop,就按下第二次确定的重复动画 141 | return; 142 | errorLabel->setText(text); //设置errorlabel的显示文本 143 | errorLabel->setGeometry(point.x(),point.y(), //设置errorLabel的位置,以及根据文本确定宽度 144 | fontMetrics().width(text) + 30,40); 145 | errorLabel->setVisible(true); //设置label为可见 146 | QTimer::singleShot(500,this,SLOT(setLabelOpacity())); //显示1秒后,执行隐藏动画 147 | } 148 | 149 | void LoginDlg::readSetting() //读取配置 150 | { 151 | QSettings settings("Software Inc.","LoginDlg"); 152 | QString userName = settings.value("UserName").toString(); 153 | bool checked = settings.value("Checked").toBool(); 154 | ui->userNameLineEdit->setText(userName); 155 | ui->checkBox->setChecked(checked); 156 | if(! userName.isEmpty()) 157 | { 158 | ui->passwordLineEdit->setFocus(); 159 | } 160 | } 161 | 162 | void LoginDlg::writeSetting() //写入配置 163 | { 164 | QSettings settings("Software Inc.", "LoginDlg"); 165 | QString name; 166 | bool checked; 167 | if(ui->checkBox->isChecked()) 168 | { 169 | name = ui->userNameLineEdit->text().trimmed(); 170 | checked = true; 171 | } 172 | else 173 | { 174 | checked = false; 175 | name = QString(""); 176 | } 177 | 178 | settings.setValue("UserName",name); 179 | settings.setValue("Checked",ui->checkBox->isChecked()); 180 | } 181 | 182 | void LoginDlg::accept() 183 | { 184 | writeSetting(); 185 | QDialog::accept(); 186 | } 187 | 188 | void LoginDlg::on_checkBox_clicked(bool checked) 189 | { 190 | 191 | } 192 | -------------------------------------------------------------------------------- /logindlg.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINDLG_H 2 | #define LOGINDLG_H 3 | 4 | 5 | /* 6 | 登录窗口 7 | */ 8 | #include 9 | class ShowInforLabel; 10 | 11 | namespace Ui { 12 | class LoginDlg; 13 | } 14 | 15 | class LoginDlg : public QDialog 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit LoginDlg(QWidget *parent = 0); 21 | ~LoginDlg(); 22 | QString getUserName() const; 23 | private slots: 24 | void on_loginBtn_clicked(); 25 | void setLabelOpacity(); 26 | void on_checkBox_clicked(bool checked); 27 | 28 | protected: 29 | void mousePressEvent(QMouseEvent *); 30 | void mouseMoveEvent(QMouseEvent *); 31 | void mouseReleaseEvent(QMouseEvent *event); 32 | void paintEvent(QPaintEvent *event); 33 | 34 | 35 | private: 36 | Ui::LoginDlg *ui; 37 | QPoint startPoint; 38 | bool isDrag; //是否拖动 39 | ShowInforLabel *errorLabel; 40 | void setErrorLabelText(const QString &text,const QPoint &point = QPoint(80,95)); 41 | void readSetting(); 42 | void writeSetting(); 43 | void accept(); 44 | }; 45 | 46 | #endif // LOGINDLG_H 47 | -------------------------------------------------------------------------------- /logindlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 313 10 | 234 11 | 12 | 13 | 14 | 15 | 50 16 | false 17 | 18 | 19 | 20 | LoginDlg 21 | 22 | 23 | QDialog { 24 | border-radius:3px; 25 | border:1px groove gray; 26 | } 27 | 28 | QToolButton { 29 | border:0; 30 | } 31 | QToolButton#closeBtn{ 32 | background-image: url(:/images/close.png); 33 | } 34 | 35 | QToolButton#closeBtn:hover { 36 | background-image: url(:/images/close_h.png); 37 | } 38 | 39 | QToolButton#closeBtn:pressed { 40 | background-image: url(:/images/close_p.png); 41 | } 42 | 43 | 44 | QLineEdit { 45 | color:rgb(127,0,63); 46 | border:2px groove gray; 47 | border-radius:6px; 48 | selection-color: white; 49 | selection-background-color: rgb(191, 31, 127); 50 | } 51 | 52 | QPushButton { 53 | color: white; 54 | font: bold 10pt; 55 | border-image: url(:/images/button.png) 16; 56 | border-width: 16px; 57 | padding: -16px 0px; 58 | min-height: 32px; 59 | min-width: 60px; 60 | } 61 | 62 | QPushButton:hover{ 63 | border-image:url(:/images/button_h.png) 16; 64 | } 65 | QPushButton:pressed{ 66 | border-image:url(:/images/button_p.png) 16; 67 | } 68 | QLabel { 69 | color:gray; 70 | 71 | } 72 | QCheckBox { 73 | color:gray; 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 270 83 | 10 84 | 32 85 | 32 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 32 97 | 32 98 | 99 | 100 | 101 | 102 | 103 | 104 | 10 105 | 10 106 | 293 107 | 61 108 | 109 | 110 | 111 | 112 | 113 | 114 | :/images/headimg.png 115 | 116 | 117 | 118 | 119 | 120 | 40 121 | 80 122 | 240 123 | 124 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 11 134 | 75 135 | true 136 | 137 | 138 | 139 | 密码: 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 0 148 | 25 149 | 150 | 151 | 152 | 153 | 12 154 | 155 | 156 | 157 | 158 | 159 | 160 | QLineEdit::Password 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 0 172 | 25 173 | 174 | 175 | 176 | 177 | 12 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 11 193 | 75 194 | true 195 | 196 | 197 | 198 | 账号: 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 50 211 | false 212 | 213 | 214 | 215 | 记住账号 216 | 217 | 218 | true 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 10 231 | 75 232 | false 233 | true 234 | 235 | 236 | 237 | 登录 238 | 239 | 240 | 241 | 242 | 243 | 244 | Qt::Horizontal 245 | 246 | 247 | 248 | 40 249 | 20 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 10 259 | 75 260 | false 261 | true 262 | 263 | 264 | 265 | 取消 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | layoutWidget 274 | label_3 275 | closeBtn 276 | 277 | 278 | 279 | userNameLineEdit 280 | passwordLineEdit 281 | checkBox 282 | loginBtn 283 | cancelBtn 284 | closeBtn 285 | 286 | 287 | 288 | 289 | 290 | 291 | closeBtn 292 | clicked() 293 | LoginDlg 294 | close() 295 | 296 | 297 | 287 298 | 9 299 | 300 | 301 | 290 302 | 51 303 | 304 | 305 | 306 | 307 | cancelBtn 308 | clicked() 309 | LoginDlg 310 | reject() 311 | 312 | 313 | 267 314 | 191 315 | 316 | 317 | 292 318 | 194 319 | 320 | 321 | 322 | 323 | 324 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "logindlg.h" 2 | #include 3 | #include 4 | #include "mainform.h" 5 | #include "connection.h" 6 | #include 7 | #include "collectdlg.h" 8 | #include "choicegoodsdlg.h" 9 | #include "addpurchasedlg.h" 10 | #include "supplierdlg.h" 11 | #include "addsupplierdlg.h" 12 | 13 | #include "adduserdlg.h" //测试添加用户 14 | #include "modifyuserdlg.h" 15 | #include "addgoodtypedlg.h" 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | QApplication a(argc, argv); 20 | QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); //设置编码 21 | QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));//设置编码 22 | bool isExist = QFileInfo("MarketDb.db").exists(); 23 | if(! createConnection()) //调用静态函数建立数据库 24 | return 1; 25 | if(! isExist) //查看数据库文件是否已经存在,如果不存在就添加数据 26 | { 27 | addData(); //调用静态函数添加数据 28 | } 29 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); 30 | // collectDlg dlg(12); 31 | //dlg.show(); 32 | /* ChoiceGoodsDlg dlg; 33 | dlg.show(); 34 | return a.exec(); */ 35 | 36 | /* MainForm form; 37 | form.show(); 38 | return a.exec(); */ 39 | /* SupplierDlg dlg; 40 | dlg.show(); 41 | return a.exec(); */ 42 | /* AddSupplierDlg dlg; 43 | dlg.show(); 44 | return a.exec(); */ 45 | 46 | /* AddPurchaseDlg dlg("admin"); 47 | dlg.show(); 48 | return a.exec(); */ 49 | 50 | /* AddUserDlg dlg; 51 | dlg.show(); 52 | return a.exec(); */ 53 | 54 | /* ModifyUserDlg dlg("admin"); 55 | dlg.show(); 56 | return a.exec(); */ 57 | 58 | /* AddGoodTypeDlg dlg; 59 | dlg.exec(); 60 | return a.exec(); */ 61 | 62 | LoginDlg w; 63 | if(w.exec() == QDialog::Accepted) 64 | { 65 | MainForm form(w.getUserName()); 66 | // form.setUserName(w.getUserName()); 67 | form.show(); 68 | return a.exec(); 69 | } 70 | else 71 | { 72 | return 1; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /mainform.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINFORM_H 2 | #define MAINFORM_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class MainForm; 9 | } 10 | class QComboBox; 11 | class QPushButton; 12 | class QSqlRelationalTableModel; 13 | class QTableView; 14 | class QTableWidget; 15 | class QAction; 16 | class QTableWidgetItem; 17 | class QSqlTableModel; 18 | class QSqlQueryModel; 19 | class MaskWidget; 20 | class NavModel; 21 | class HistogramView; 22 | 23 | class MainForm : public QWidget 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | enum GoodsNameEnum { 29 | GoodsName_Id, 30 | GoodsName_TypeId, 31 | GoodsName_Name, 32 | GoodsName_Stock, 33 | GoodsName_Bid, 34 | GoodsName_Retail, 35 | GoodsName_Format, 36 | GoodsName_Unit, 37 | GoodsName_Note 38 | }; 39 | enum Sell { 40 | Sell_Id, 41 | Sell_Man, 42 | Sell_DateTime, 43 | Sell_FactPrice, 44 | Sell_CollectPrice, 45 | Sell_Count 46 | }; 47 | 48 | enum SellList { 49 | SellList_Num, 50 | SellList_Id, 51 | SellList_TodayCount, 52 | SellList_GoodsId, 53 | SellList_Count, 54 | SellList_DateTime 55 | }; 56 | enum SubmitState { 57 | Submit_Update, 58 | Submit_Insert 59 | }; 60 | enum Supplier { 61 | Supplier_Id, 62 | Supplier_Name, 63 | Supplier_Contact, 64 | Supplier_Telephone, 65 | Supplier_Address, 66 | Supplier_Note 67 | }; 68 | enum Purchase { 69 | Purchase_Id, 70 | Purchase_DateTime, 71 | Purchase_SupplierId, 72 | Purchase_TotalPrice, 73 | Purchase_Handelr, 74 | Purchase_Note 75 | }; 76 | enum PurchaseDetail { 77 | PurDetail_Id, 78 | PurDetail_PurchaseId, 79 | PurDetail_GoodsId, 80 | PurDetail_Count 81 | }; 82 | //用户枚举 83 | enum User { 84 | User_Name, 85 | User_Password, 86 | User_JobNum, 87 | User_Sex, 88 | User_IDCard, 89 | User_LastLoginTime 90 | }; 91 | 92 | explicit MainForm(QString username,QWidget *parent = 0); 93 | ~MainForm(); 94 | bool eventFilter(QObject *target, QEvent *event); 95 | void showName(); 96 | protected: 97 | void mousePressEvent(QMouseEvent *event); 98 | void mouseMoveEvent(QMouseEvent *event); 99 | void mouseReleaseEvent(QMouseEvent *event); 100 | void timerEvent(QTimerEvent *event); 101 | void paintEvent(QPaintEvent *event); 102 | void keyPressEvent(QKeyEvent *event); 103 | void showEvent(QShowEvent *event); 104 | private slots: 105 | void showGoodsInforSlot(); 106 | void showSellPageSlot(); 107 | void showSallStatisticsSlot(); //销售统计报表 108 | void showUserManagementSlot(); //用户管理界面 109 | void on_barcodeLineEdit_S_returnPressed(); 110 | void completerChange(const QString &arg); 111 | void destoryCompleter(); 112 | void goodsListDoubleClick(QModelIndex); //选择商品双击 113 | void deleteSellListSlot(); 114 | void updateSellPrice(); 115 | void updateModel(QTableWidgetItem *item); 116 | void on_delSellGoodsBtn_S_clicked(); 117 | void on_collectionsBtn_S_clicked(); 118 | void on_sellIdLineEdit_S_lostFocus(); 119 | void on_sellIdLineEdit_S_returnPressed(); 120 | void showHistoryBillSlot(); 121 | //历史账单 122 | void updateBillPageSlot(); 123 | void on_startDateTimeEdit_B_dateTimeChanged(const QDateTime &date); 124 | void on_endDateTimeEdit_B_dateTimeChanged(const QDateTime &date); 125 | void on_sellListTableView_B_clicked(const QModelIndex &index); 126 | void on_searchForIdLineEdit_B_textChanged(const QString &arg1); 127 | void on_exportToExcelBtn_B_clicked(); 128 | void on_clearSellListBtn_S_clicked(); 129 | void on_delBillBtn_B_clicked(); 130 | void on_sellManComboBox_B_currentIndexChanged(const QString &arg1); 131 | void on_goodsTypeComboBox_M_currentIndexChanged(const QString &arg1); 132 | void on_goodsNameDelBtn_M_clicked(); 133 | void on_goodsNameTableView_M_clicked(const QModelIndex &index); 134 | void setWidgetStatus_M(bool isEnable); 135 | void on_addGoodsBtn_M_clicked(); 136 | void on_submitBtn_M_clicked(); 137 | void on_reviseBtn_M_clicked(); 138 | void on_searchLineEdit_M_textChanged(const QString &arg1); 139 | // void on_purchaseBtn_P_clicked(); 140 | void purchaseDetailSlot(); //进货明细 141 | void on_addPurchase_P_clicked(); 142 | //进货 143 | void copyPurchaseId(); //右键复制单号 144 | void on_purchaseIdLineEdit_P_textChanged(const QString &arg1); 145 | void on_startDateEdit_P_dateChanged(const QDate &date); 146 | void on_endDateEdit_P_dateChanged(const QDate &date); 147 | void on_purchaseTableView_P_clicked(const QModelIndex &index); 148 | void showSupplierSlot(); 149 | void clickInfor(QString text); 150 | void on_AddBtn_U_clicked(); 151 | void on_DeleteBtn_U_clicked(); 152 | void on_ModifyBtn_U_clicked(); 153 | 154 | void on_okBtn_S_clicked(); 155 | 156 | private: 157 | void showCurrentTime(); 158 | void setUserLastLoginTime(); 159 | void installWidgetEventFilter(); 160 | void createPage(); 161 | Ui::MainForm *ui; 162 | NavModel* model; 163 | 164 | QString userName; 165 | QPoint startPoint; 166 | bool isDrag; //是否拖动 167 | int curTimeId; 168 | MaskWidget *maskWidget; 169 | //商品列表page 170 | 171 | QSqlRelationalTableModel *goodsNameModel_M; 172 | QSqlTableModel *UserManagementModel_U; //用户管理的model 173 | QSqlQueryModel *comboBoxmodel_M; 174 | QTableView *goodsNameView; 175 | QTableView *goodsListWidget; 176 | QAction *delAction; 177 | QAction *addAction; 178 | QAction *reduceAction; 179 | double sumOfPrice; 180 | QString sellIdStr; 181 | int countOfSell; 182 | SubmitState submitState; 183 | void showGoodsListWidget(); 184 | void produceSellID(); //设置单号 185 | void setSellCount(); 186 | 187 | //历史账单 188 | QSqlTableModel *billModel_B; 189 | QSqlRelationalTableModel *billListModel_B; 190 | 191 | //进货 192 | QAction *copyAction_P; 193 | QSqlRelationalTableModel *purchaseModel_P; 194 | QSqlRelationalTableModel *purchaseDetailModel_P; 195 | void updatePurchaseView(); //更新进货界面的进货单号,总价等信息 196 | void purchase(); //主界面的进货按钮 197 | 198 | //统计报表 199 | HistogramView *histogramView; 200 | 201 | //添加商品类别 202 | void addGoodsType(); 203 | }; 204 | 205 | #endif // MAINFORM_H 206 | -------------------------------------------------------------------------------- /maskwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "maskwidget.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | MaskWidget::MaskWidget(const QString &password, QWidget *parent) : 12 | QDialog(parent) 13 | { 14 | this->password = password; 15 | lineEdit = new QLineEdit(this); 16 | lineEdit->setEchoMode(QLineEdit::Password); 17 | connect(lineEdit,SIGNAL(returnPressed()),this,SLOT(accept())); //按下回车时,与点击确定一样 18 | label = new QLabel(tr("请输入密码:"),this); 19 | label->setStyleSheet(tr("color:white;font:bold 16pt;")); 20 | inforLabel = new QLabel(tr("锁定中..."),this); 21 | inforLabel->setStyleSheet(tr("color:white;font:bold 25pt;")); 22 | okBtn = new QPushButton(tr("提交"),this); 23 | okBtn->setDefault(true); 24 | connect(okBtn,SIGNAL(clicked()),this,SLOT(accept())); 25 | errorLabel = new QLabel(this); 26 | errorLabel->setStyleSheet(tr("color:red;font:bold 14pt;")); 27 | errorLabel->setVisible(false); 28 | errorLabel->resize(QSize(250,30)); 29 | /* QVBoxLayout *layout = new QVBoxLayout; 30 | layout->addWidget(label); 31 | layout->addWidget(lineEdit); 32 | layout->addWidget(okBtn); 33 | 34 | this->setLayout(layout); */ 35 | // this->setAutoFillBackground(true); 36 | this->setWindowFlags(Qt::FramelessWindowHint); 37 | this->setAttribute(Qt::WA_TranslucentBackground); 38 | QString style = QString("QPushButton { border: 2px solid #8f8f91;border-radius: 6px;" 39 | "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);" 40 | "min-height:20px; min-width:50px;}" 41 | "QPushButton:hover {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," 42 | "stop: 0 #dadbde, stop: 1 #f6f7fa); }" 43 | " QPushButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," 44 | "stop: 0 #dadbde, stop: 1 #f6f7fa);}" 45 | " QLineEdit {color: rgb(127, 0, 63);background-color: rgb(255, 255, 241); selection-color: white;" 46 | "selection-background-color: rgb(191, 31, 127);border: 2px groove gray;" 47 | "border-radius: 10px; padding: 2px 4px; }"); 48 | this->setStyleSheet(style); 49 | lineEdit->setFocus(); 50 | } 51 | 52 | void MaskWidget::accept() // 53 | { 54 | int width = this->width(); 55 | int height = this->height(); 56 | if(this->lineEdit->text().isEmpty()) 57 | { 58 | QApplication::beep(); 59 | errorLabel->setText(tr("请输入密码...")); 60 | errorLabel->move(width / 2 - 70,height /2 + 150); 61 | errorLabel->setVisible(true); 62 | this->lineEdit->setFocus(); //设置焦点 63 | } 64 | else if(lineEdit->text() != password) //如果密码不正确 65 | { 66 | QApplication::beep(); 67 | errorLabel->setText(tr("密码不正确,请重新输入...")); 68 | errorLabel->move(width / 2 - 70,height /2 + 150); 69 | errorLabel->setVisible(true); 70 | this->lineEdit->selectAll(); 71 | this->lineEdit->setFocus(); 72 | } 73 | else 74 | { 75 | QDialog::accept(); 76 | } 77 | } 78 | 79 | void MaskWidget::paintEvent(QPaintEvent *event) 80 | { 81 | QPainter painter(this); 82 | painter.fillRect(this->rect(),QColor(0,0,0,100)); 83 | } 84 | 85 | void MaskWidget::resizeEvent(QResizeEvent *) 86 | { 87 | int width = this->width(); 88 | int height = this->height(); 89 | inforLabel->move(width / 2- 100,height / 2); 90 | label->move(width / 2 - 200,height /2 + 100); 91 | lineEdit->move(width / 2 - 70,height /2+ 100); 92 | okBtn->move(width / 2 + 60,height /2 + 100); 93 | } 94 | 95 | void MaskWidget::showEvent(QShowEvent *event) //显示时触发,为了清空文本框中原来的密码 96 | { 97 | this->lineEdit->clear(); 98 | this->lineEdit->setFocus(); 99 | this->errorLabel->clear(); 100 | } 101 | -------------------------------------------------------------------------------- /maskwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MASKWIDGET_H 2 | #define MASKWIDGET_H 3 | 4 | #include 5 | class QLineEdit; 6 | class QPushButton; 7 | class QLabel; 8 | 9 | class MaskWidget : public QDialog 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MaskWidget(const QString &password,QWidget *parent = 0); 14 | void accept(); 15 | protected: 16 | void paintEvent(QPaintEvent *event); 17 | void resizeEvent(QResizeEvent *); 18 | void showEvent(QShowEvent *event); 19 | private: 20 | QLineEdit *lineEdit; 21 | QLabel *inforLabel; 22 | QPushButton *okBtn; 23 | QLabel *label; 24 | QString password; 25 | QLabel *errorLabel; 26 | }; 27 | 28 | #endif // MASKWIDGET_H 29 | -------------------------------------------------------------------------------- /modifyuserdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "modifyuserdlg.h" 2 | #include "ui_modifyuserdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | ModifyUserDlg::ModifyUserDlg(QString username, QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::ModifyUserDlg) 13 | { 14 | ui->setupUi(this); 15 | 16 | this->setWindowFlags(Qt::FramelessWindowHint); 17 | this->setAttribute(Qt::WA_TranslucentBackground); 18 | this->username = username; 19 | 20 | initView(); //初始化窗口各信息 21 | //设置身份证号码文本框的正则表达式,只能输入18位的数字 22 | QRegExp regExp("[0-9]{18}"); 23 | 24 | ui->idCardLineEdit->setValidator(new QRegExpValidator(regExp, this)); 25 | } 26 | 27 | ModifyUserDlg::~ModifyUserDlg() 28 | { 29 | delete ui; 30 | } 31 | 32 | void ModifyUserDlg::on_cancelBtn_clicked() 33 | { 34 | this->reject(); 35 | } 36 | 37 | void ModifyUserDlg::on_okBtn_clicked() 38 | { 39 | 40 | QString password = ui->pswLineEdit->text(); 41 | QString jobNum = ui->jobNumLineEdit->text(); 42 | QString IDCardNum = ui->idCardLineEdit->text(); 43 | QString sex = ui->sexComboBox->currentText(); 44 | if(password.isEmpty()) 45 | { 46 | QMessageBox::warning(this,tr("警告"),tr("密码不得为空!")); 47 | ui->pswLineEdit->setFocus(); 48 | return; 49 | } 50 | else if(jobNum.isEmpty()) 51 | { 52 | QMessageBox::warning(this,tr("警告"),tr("工作号不得为空!")); 53 | ui->jobNumLineEdit->setFocus(); 54 | return; 55 | } 56 | else if(IDCardNum.isEmpty()) 57 | { 58 | QMessageBox::warning(this,tr("警告"),tr("身份证号不得为空!")); 59 | ui->idCardLineEdit->setFocus(); 60 | return; 61 | } 62 | else if(IDCardNum.length() != 18) 63 | { 64 | QMessageBox::warning(this,tr("警告"),tr("身份证号填写不正确!")); 65 | ui->idCardLineEdit->setFocus(); 66 | return; 67 | } 68 | //修改用户信息 69 | QSqlDatabase::database().transaction(); 70 | QSqlQuery query; 71 | query.prepare(tr("UPDATE userTb SET password=:password ,jobNum=:jobNum,sex=:sex," 72 | "IDcardNum=:idcard WHERE username=:username")); 73 | query.bindValue(":password",password); 74 | query.bindValue(":jobNum",jobNum); 75 | query.bindValue(":sex",sex); 76 | query.bindValue(":IDcardNum",IDCardNum); 77 | query.bindValue(":username",username); 78 | if(query.exec()) 79 | { 80 | QMessageBox::information(this,tr("提示"),tr("修改成功!"),QMessageBox::Ok); 81 | QSqlDatabase::database().commit(); //提交 82 | this->accept(); 83 | } 84 | else 85 | { 86 | QMessageBox::critical(this,tr("严重错误"),tr("抱歉!信息修改失败!\n错误原因:%1") 87 | .arg(query.lastError().text())); 88 | QSqlDatabase::database().rollback(); //回滚 89 | } 90 | } 91 | 92 | void ModifyUserDlg::paintEvent(QPaintEvent *event) 93 | { 94 | QPainterPath path; 95 | path.setFillRule(Qt::WindingFill); 96 | path.addRect(10,10,this->width()-20,this->height()-20); 97 | QPainter painter(this); 98 | painter.setRenderHint(QPainter::Antialiasing,true); 99 | painter.fillPath(path,QBrush(Qt::white)); 100 | 101 | QColor color(0,0,0,55); 102 | for(int i = 0;i < 9;i++) 103 | { 104 | QPainterPath pathShadow; 105 | pathShadow.setFillRule(Qt::WindingFill); 106 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 107 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 108 | color.setAlpha(155-qSqrt(i)*55); 109 | painter.setPen(color); 110 | painter.drawPath(pathShadow); 111 | } 112 | } 113 | 114 | void ModifyUserDlg::mousePressEvent(QMouseEvent *event) 115 | { 116 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 117 | { 118 | startPoint = event->globalPos() - frameGeometry().topLeft(); 119 | isDrag = true; 120 | event->accept(); 121 | // startPoint = QPoint(event->pos()); //将单击point存储 122 | } 123 | } 124 | 125 | void ModifyUserDlg::mouseReleaseEvent(QMouseEvent *event) 126 | { 127 | isDrag = false; 128 | } 129 | 130 | void ModifyUserDlg::mouseMoveEvent(QMouseEvent *event) 131 | { 132 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 133 | { 134 | move(event->globalPos() - startPoint); 135 | event->accept(); 136 | } 137 | } 138 | 139 | void ModifyUserDlg::initView() //初始化窗口 140 | { 141 | ui->usernameLineEdit->setText(username); 142 | ui->usernameLineEdit->setEnabled(false); //设置用户名不得更改 143 | 144 | QSqlQuery query; 145 | QString password; 146 | QString jobNum; 147 | QString IDCardNum; 148 | QString sex; 149 | query.exec(tr("SELECT password,jobNum,sex,IDCardNum FROM userTb WHERE username = '%1'") 150 | .arg(username)); 151 | if(query.next()) { 152 | password = query.value(0).toString(); 153 | jobNum = query.value(1).toString(); 154 | sex = query.value(2).toString(); 155 | IDCardNum = query.value(3).toString(); 156 | } 157 | ui->pswLineEdit->setText(password); 158 | ui->jobNumLineEdit->setText(jobNum); 159 | ui->idCardLineEdit->setText(IDCardNum); 160 | int index = sex == tr("男") ? 0 : 1; 161 | ui->sexComboBox->setCurrentIndex(index); 162 | 163 | ui->pswLineEdit->setFocus(); 164 | 165 | } 166 | -------------------------------------------------------------------------------- /modifyuserdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef MODIFYUSERDLG_H 2 | #define MODIFYUSERDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ModifyUserDlg; 8 | } 9 | 10 | class ModifyUserDlg : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ModifyUserDlg(QString username, QWidget *parent = 0); 16 | ~ModifyUserDlg(); 17 | 18 | private slots: 19 | void on_cancelBtn_clicked(); 20 | 21 | void on_okBtn_clicked(); 22 | 23 | protected: 24 | void paintEvent(QPaintEvent *event); 25 | void mousePressEvent(QMouseEvent *event); 26 | void mouseReleaseEvent(QMouseEvent *event); 27 | void mouseMoveEvent(QMouseEvent *event); 28 | 29 | private: 30 | Ui::ModifyUserDlg *ui; 31 | QPoint startPoint; 32 | bool isDrag; //是否拖动 33 | QString username; //当前用户名 34 | 35 | void initView(); 36 | }; 37 | 38 | #endif // MODIFYUSERDLG_H 39 | -------------------------------------------------------------------------------- /modifyuserdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModifyUserDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 268 10 | 327 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QToolButton { 18 | border:0; 19 | } 20 | QToolButton#closeBtn{ 21 | background-image: url(:/images/close.png); 22 | } 23 | 24 | QToolButton#closeBtn:hover { 25 | background-image: url(:/images/close_h.png); 26 | } 27 | 28 | QToolButton#closeBtn:pressed { 29 | background-image: url(:/images/close_p.png); 30 | } 31 | 32 | 33 | QLineEdit ,QTextEdit{ 34 | color:rgb(127,0,63); 35 | border:2px groove gray; 36 | border-radius:6px; 37 | selection-color: white; 38 | selection-background-color: rgb(191, 31, 127); 39 | } 40 | 41 | QPushButton { 42 | color: white; 43 | font: bold 10pt; 44 | border-image: url(:/images/button.png) 16; 45 | border-width: 16px; 46 | padding: -16px 0px; 47 | min-height: 32px; 48 | min-width: 60px; 49 | } 50 | 51 | QPushButton:hover{ 52 | border-image:url(:/images/button_h.png) 16; 53 | } 54 | QPushButton:pressed{ 55 | border-image:url(:/images/button_p.png) 16; 56 | } 57 | QLabel { 58 | color:gray; 59 | 60 | } 61 | 62 | QCheckBox { 63 | color:gray; 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 40 71 | 70 72 | 51 73 | 21 74 | 75 | 76 | 77 | 用户名: 78 | 79 | 80 | 81 | 82 | 83 | 40 84 | 110 85 | 51 86 | 21 87 | 88 | 89 | 90 | 密码: 91 | 92 | 93 | 94 | 95 | 96 | 40 97 | 150 98 | 51 99 | 21 100 | 101 | 102 | 103 | 工作号: 104 | 105 | 106 | 107 | 108 | 109 | 40 110 | 230 111 | 61 112 | 21 113 | 114 | 115 | 116 | 身份证号: 117 | 118 | 119 | 120 | 121 | 122 | 40 123 | 190 124 | 51 125 | 21 126 | 127 | 128 | 129 | 性别: 130 | 131 | 132 | 133 | 134 | 135 | 110 136 | 190 137 | 69 138 | 22 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 110 156 | 70 157 | 131 158 | 25 159 | 160 | 161 | 162 | 163 | 164 | 165 | 110 166 | 110 167 | 131 168 | 25 169 | 170 | 171 | 172 | 173 | 174 | 175 | 110 176 | 150 177 | 131 178 | 25 179 | 180 | 181 | 182 | 183 | 184 | 185 | 110 186 | 230 187 | 131 188 | 25 189 | 190 | 191 | 192 | 193 | 194 | 195 | 30 196 | 270 197 | 92 198 | 32 199 | 200 | 201 | 202 | 修改 203 | 204 | 205 | 206 | 207 | 208 | 150 209 | 270 210 | 92 211 | 32 212 | 213 | 214 | 215 | 取消 216 | 217 | 218 | 219 | 220 | 221 | 10 222 | 10 223 | 248 224 | 41 225 | 226 | 227 | 228 | 229 | 230 | 231 | :/images/modifyUserHead.png 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /navdelegate.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "navdelegate.h" 3 | 4 | #include "navmodel.h" 5 | #include "colordefines.h" 6 | 7 | #include 8 | 9 | NavDelegate::NavDelegate(QObject *parent) 10 | : QStyledItemDelegate(parent) 11 | , m_pending(false) 12 | { 13 | 14 | } 15 | 16 | NavDelegate::~NavDelegate() 17 | { 18 | 19 | } 20 | 21 | QSize NavDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const 22 | { 23 | NavModel::TreeNode* node = (NavModel::TreeNode*)index.data(Qt::UserRole).toUInt(); 24 | 25 | if ( node->level == 1) 26 | return QSize(50, 35); 27 | else 28 | return QSize(50, 28); 29 | } 30 | 31 | void NavDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const 32 | { 33 | NavModel::TreeNode* node = (NavModel::TreeNode*)index.data(Qt::UserRole).toUInt(); 34 | 35 | painter->setRenderHint(QPainter::Antialiasing); 36 | 37 | // Fill background. 38 | if ( option.state & QStyle::State_Selected ) 39 | { 40 | painter->fillRect(option.rect, color_selected); 41 | } 42 | else if ( option.state & QStyle::State_MouseOver ) 43 | { 44 | painter->fillRect(option.rect, color_hover); 45 | } 46 | else 47 | { 48 | if ( node->level == 1 ) 49 | painter->fillRect(option.rect, color_parent_normal); 50 | else 51 | painter->fillRect(option.rect, color_child_normal); 52 | } 53 | 54 | // draw decorate 55 | if ( node->children.size() != 0 ) 56 | { 57 | QString imgPath; 58 | 59 | if ( node->collapse ) 60 | { 61 | if ( option.state & QStyle::State_Selected ) 62 | imgPath = ":/images/unexpand_selected.png"; 63 | else 64 | imgPath = ":/images/unexpand_normal.png"; 65 | } 66 | else 67 | { 68 | if ( option.state & QStyle::State_Selected ) 69 | imgPath = ":/images/expand_selected.png"; 70 | else 71 | imgPath = ":/images/expand_normal.png"; 72 | } 73 | 74 | QPixmap img(imgPath); 75 | QRect targetRect = option.rect; 76 | targetRect.setWidth(16); 77 | targetRect.setHeight(16); 78 | QPoint c = option.rect.center(); 79 | c.setX(8); 80 | targetRect.moveCenter(c); 81 | painter->drawPixmap(targetRect, imgPath, img.rect()); 82 | } 83 | 84 | // draw text. 85 | QPen textPen( option.state & QStyle::State_Selected ? color_text_selected : color_text_normal); 86 | painter->setPen(textPen); 87 | 88 | int margin = 25; 89 | 90 | if ( node->level == 2 ) 91 | margin = 45; 92 | 93 | QRect rect = option.rect; 94 | rect.setWidth(rect.width() - margin); 95 | rect.setX(rect.x() + margin); 96 | 97 | QFont normalFont("Microsoft Yahei", 9); 98 | painter->setFont(normalFont); 99 | 100 | painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, index.data(Qt::DisplayRole).toString() ); 101 | 102 | // draw line 103 | 104 | QPen linePen(color_line); 105 | linePen.setWidth(1); 106 | painter->setPen(linePen); 107 | 108 | if ( node->level == 1 109 | || (node->level == 2 && node->theLast ) ) 110 | { 111 | painter->drawLine( 112 | QPointF(option.rect.x(), option.rect.y()+option.rect.height()-1), 113 | QPointF(option.rect.x() + option.rect.width(), option.rect.y()+option.rect.height()-1)); 114 | } 115 | 116 | 117 | // draw record count 118 | int recordCount = node->count; 119 | if ( m_pending || 0 >= recordCount) 120 | return; 121 | 122 | QPen decorationPen(option.state & QStyle::State_Selected ? color_selected : color_text_selected); 123 | QBrush decorationBrush(option.state & QStyle::State_Selected ? color_text_selected : color_selected); 124 | QFont decorationFont("Microsoft Yahei", 8); 125 | painter->setFont(decorationFont); 126 | 127 | QRect decoration = option.rect; 128 | decoration.setHeight(15); 129 | decoration.moveCenter(option.rect.center()); 130 | decoration.setLeft(option.rect.right()-50); 131 | decoration.setRight(option.rect.right()-15); 132 | 133 | painter->setPen(decorationPen); 134 | QPainterPath path; 135 | path.addRoundedRect(decoration, 7, 7); 136 | painter->fillPath(path, decorationBrush); 137 | 138 | QString decorationText = QString("%1").arg(recordCount); 139 | if ( recordCount > 999 ) 140 | decorationText = "999+"; 141 | 142 | painter->drawText(decoration, Qt::AlignCenter | Qt::AlignVCenter, decorationText); 143 | } 144 | -------------------------------------------------------------------------------- /navdelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef NAVDELEGATE_H 2 | #define NAVDELEGATE_H 3 | 4 | #include 5 | 6 | class NavDelegate : public QStyledItemDelegate 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | NavDelegate(QObject *parent); 12 | ~NavDelegate(); 13 | 14 | public: 15 | QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const ; 16 | void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; 17 | 18 | void SetPending(bool pending) { m_pending = pending; } 19 | 20 | private: 21 | bool m_pending; 22 | }; 23 | 24 | #endif // NAVDELEGATE_H 25 | -------------------------------------------------------------------------------- /navmodel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "navmodel.h" 3 | 4 | #include 5 | #include 6 | 7 | NavModel::NavModel(QObject *parent) 8 | : QAbstractListModel(parent) 9 | { 10 | } 11 | 12 | NavModel::~NavModel() 13 | { 14 | for ( std::vector::iterator it = m_nodeList.begin(); 15 | it != m_nodeList.end(); ) 16 | { 17 | for ( std::list::iterator child = (*it)->children.begin(); 18 | child != (*it)->children.end(); ) 19 | { 20 | delete (*child); 21 | child = (*it)->children.erase(child); 22 | } 23 | 24 | delete (*it); 25 | it = m_nodeList.erase(it); 26 | } 27 | } 28 | 29 | void NavModel::ReadDataFromConfig(QString path) 30 | { 31 | QFile xml(path); 32 | 33 | if ( !xml.open(QIODevice::ReadOnly | QIODevice::Text) ) 34 | return; 35 | 36 | QDomDocument doc; 37 | 38 | if ( !doc.setContent(&xml, false) ) 39 | return; 40 | 41 | QDomNode root = doc.documentElement().firstChildElement("layout"); 42 | QDomNodeList children = root.childNodes(); 43 | 44 | for ( int i = 0; i != children.count(); ++i ) 45 | { 46 | QDomElement nodeInfo = children.at(i).toElement(); 47 | TreeNode* node = new TreeNode; 48 | node->label = nodeInfo.attribute("label"); 49 | node->collapse = nodeInfo.attribute("collapse").toInt(); 50 | node->count = nodeInfo.attribute("count").toInt(); 51 | node->level = 1; 52 | node->isSubItem = false; 53 | QDomNodeList secondLevel = nodeInfo.childNodes(); 54 | 55 | for ( int j = 0; j != secondLevel.count(); ++j ) //子目录 56 | { 57 | QDomElement secNodeInfo = secondLevel.at(j).toElement(); 58 | TreeNode* secNode = new TreeNode; 59 | secNode->label = secNodeInfo.attribute("label"); 60 | secNode->count = secNodeInfo.attribute("count").toInt(); 61 | secNode->collapse = false; 62 | secNode->level = 2; 63 | secNode->isSubItem = true; 64 | secNode->theLast = ( j == secondLevel.count()-1 && i != children.count()-1 ); 65 | node->children.push_back(secNode); 66 | } 67 | 68 | m_nodeList.push_back(node); 69 | } 70 | 71 | RefreshList(); 72 | beginInsertRows(QModelIndex(), 0, m_list.size()); 73 | endInsertRows(); 74 | } 75 | 76 | int NavModel::rowCount( const QModelIndex &parent /* = QModelIndex */ ) const 77 | { 78 | return m_list.size(); 79 | } 80 | 81 | QVariant NavModel::data( const QModelIndex &index, int role /* = Qt::DisplayRole */ ) const 82 | { 83 | if ( !index.isValid() ) 84 | return QVariant(); 85 | 86 | if ( index.row() >= m_list.size() || index.row() < 0 ) 87 | return QVariant(); 88 | 89 | if ( role == Qt::DisplayRole ) 90 | return m_list[index.row()].label; 91 | else if ( role == Qt::UserRole ) 92 | return (unsigned int)(m_list[index.row()].treeNode); 93 | 94 | return QVariant(); 95 | } 96 | 97 | void NavModel::RefreshList() 98 | { 99 | m_list.clear(); 100 | 101 | for ( std::vector::iterator it = m_nodeList.begin(); 102 | it != m_nodeList.end(); 103 | ++it ) 104 | { 105 | ListNode node; 106 | node.label = (*it)->label; 107 | node.treeNode = *it; 108 | 109 | m_list.push_back(node); 110 | 111 | if ( (*it)->collapse ) 112 | continue; 113 | 114 | for ( std::list::iterator child = (*it)->children.begin(); 115 | child != (*it)->children.end(); 116 | ++child ) 117 | { 118 | ListNode node; 119 | node.label = (*child)->label; 120 | node.treeNode = *child; 121 | node.treeNode->theLast = false; 122 | 123 | m_list.push_back(node); 124 | } 125 | 126 | if ( !m_list.empty()) 127 | m_list.back().treeNode->theLast = true; 128 | } 129 | } 130 | 131 | void NavModel::Collapse( const QModelIndex& index ) 132 | { 133 | TreeNode* node = m_list[index.row()].treeNode; 134 | if ( node->children.size() == 0 ) 135 | return; 136 | 137 | node->collapse = !node->collapse; 138 | 139 | RefreshList(); 140 | 141 | if ( !node->collapse ) 142 | { 143 | beginInsertRows(QModelIndex(), index.row()+1, index.row()+node->children.size()); 144 | endInsertRows(); 145 | } 146 | else 147 | { 148 | beginRemoveRows(QModelIndex(), index.row()+1, index.row()+node->children.size()); 149 | endRemoveRows(); 150 | } 151 | 152 | } 153 | 154 | void NavModel::clickIndex(const QModelIndex &index) 155 | { 156 | TreeNode* node = m_list[index.row()].treeNode; 157 | if(node->isSubItem) 158 | emit clickItem(index.data().toString()); 159 | } 160 | 161 | void NavModel::Refresh() 162 | { 163 | RefreshList(); 164 | beginResetModel(); 165 | endResetModel(); 166 | } 167 | -------------------------------------------------------------------------------- /navmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef NAVMODEL_H 2 | #define NAVMODEL_H 3 | 4 | #include 5 | #include 6 | 7 | class NavModel : public QAbstractListModel 8 | { 9 | Q_OBJECT 10 | 11 | 12 | public: 13 | 14 | struct TreeNode 15 | { 16 | QString label; 17 | int level; 18 | bool collapse; 19 | bool theLast; 20 | int count; 21 | std::list children; 22 | bool isSubItem; 23 | }; 24 | 25 | struct ListNode 26 | { 27 | QString label; 28 | TreeNode* treeNode; 29 | }; 30 | 31 | NavModel(QObject *parent); 32 | ~NavModel(); 33 | 34 | /*! 35 | \brief 36 | Read data from xml. 37 | */ 38 | void ReadDataFromConfig(QString path); 39 | 40 | void Refresh(); 41 | 42 | public: 43 | int rowCount(const QModelIndex &parent /* = QModelIndex */) const; 44 | QVariant data(const QModelIndex &index, int role /* = Qt::DisplayRole */) const; 45 | 46 | public slots: 47 | void Collapse(const QModelIndex& index); 48 | void clickIndex(const QModelIndex &index); 49 | 50 | private: 51 | void RefreshList(); 52 | signals: 53 | void clickItem(QString text); 54 | 55 | private: 56 | std::vector m_nodeList; 57 | std::vector m_list; 58 | }; 59 | 60 | #endif // NAVMODEL_H 61 | -------------------------------------------------------------------------------- /showinforlabel.cpp: -------------------------------------------------------------------------------- 1 | #include "showinforlabel.h" 2 | #include 3 | 4 | ShowInforLabel::ShowInforLabel(QWidget *parent) : 5 | QLabel(parent) 6 | { 7 | _opacity = 1.0; //私有成员值,存储窗体的不透明度,0.0-1.0,1.0为不透明 8 | } 9 | 10 | void ShowInforLabel::setopacity(double value) //当执行自定义属性动画时,动画会自动调用该函数 11 | { 12 | _opacity = value; //设置不透明度 13 | update(); //重绘 14 | } 15 | 16 | void ShowInforLabel::setWindowVisable() //设置窗体为不可见,用于自定义动画时,结束时调用 17 | { 18 | this->setVisible(false); 19 | _opacity = 1.0; //重新设置不透明度,为下一次属性动画准备 20 | } 21 | 22 | void ShowInforLabel::paintEvent(QPaintEvent *event) 23 | { 24 | QPainter painter(this); 25 | int width = fontMetrics().width(this->text()) + 20;//根据文本,提出宽度 26 | int height = 25; 27 | painter.setRenderHint(QPainter::Antialiasing,true); 28 | painter.setBrush(Qt::white); 29 | QFont font; 30 | font.setPointSize(9); 31 | painter.setFont(font); 32 | QPen pen; 33 | pen.setWidth(2); 34 | pen.setColor(Qt::black); 35 | painter.setPen(pen); 36 | painter.setOpacity(_opacity); //设置不透明度 37 | painter.drawRoundedRect(QRectF(2,10,width,height),20,20);//绘制一个圆矩形 38 | static const QPointF points[3] = { 39 | QPointF(20,0), 40 | QPointF(25,20), 41 | QPointF(35,20) 42 | }; 43 | pen.setWidth(1); 44 | painter.setPen(pen); 45 | painter.drawPolygon(points,3); //绘制一个三角形 46 | painter.setPen(Qt::NoPen); 47 | painter.drawRoundedRect(QRectF(2,10,width,height),20,20); //使用白色填充圆矩形,剔除矩形中多余的东西 48 | painter.setPen(Qt::black); 49 | painter.drawText(12,25,this->text()); //绘制要显示的文本 50 | } 51 | -------------------------------------------------------------------------------- /showinforlabel.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWINFORLABEL_H 2 | #define SHOWINFORLABEL_H 3 | 4 | #include 5 | /* 6 | 子类化一个QLabel 7 | 功能:显示一些错误信息,界面会更加友好 8 | */ 9 | 10 | 11 | class ShowInforLabel : public QLabel 12 | { 13 | Q_OBJECT 14 | Q_PROPERTY(double opacity READ opacity WRITE setopacity) //自定义一个属性,opacity设置窗体的透明度,可以执行自定义的属性动画 15 | public: 16 | explicit ShowInforLabel(QWidget *parent = 0); 17 | double opacity() { return _opacity;} //自定义属性方法 18 | void setopacity(double value); 19 | public slots: 20 | void setWindowVisable(); 21 | protected: 22 | void paintEvent(QPaintEvent *event); 23 | double _opacity; 24 | 25 | }; 26 | 27 | #endif // SHOWINFORLABEL_H 28 | -------------------------------------------------------------------------------- /supermarket.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/supermarket.ico -------------------------------------------------------------------------------- /supplierdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "supplierdlg.h" 2 | #include "ui_supplierdlg.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "addsupplierdlg.h" 8 | #include 9 | #include 10 | #include 11 | 12 | SupplierDlg::SupplierDlg(QWidget *parent) : 13 | QDialog(parent), 14 | ui(new Ui::SupplierDlg) 15 | { 16 | ui->setupUi(this); 17 | this->setWindowFlags(Qt::FramelessWindowHint); 18 | this->setAttribute(Qt::WA_TranslucentBackground); 19 | initialisePage(); 20 | } 21 | 22 | 23 | void SupplierDlg::initialisePage() //初始化 24 | { 25 | supplierModel = new QSqlTableModel(this); 26 | supplierModel->setTable("supplierTb"); 27 | supplierModel->select(); 28 | 29 | supplierModel->setHeaderData(Supplier_Name,Qt::Horizontal,tr("供应商名称")); 30 | supplierModel->setHeaderData(Supplier_Contact,Qt::Horizontal,tr("联系人")); 31 | supplierModel->setHeaderData(Supplier_Telephone,Qt::Horizontal,tr("联系电话")); 32 | supplierModel->setHeaderData(Supplier_Address,Qt::Horizontal,tr("地址")); 33 | supplierModel->setHeaderData(Supplier_Note,Qt::Horizontal,tr("备注")); 34 | 35 | ui->tableView->setModel(supplierModel); 36 | ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); 37 | ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection); 38 | ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 39 | ui->tableView->setColumnHidden(Supplier_Id,true); 40 | ui->tableView->horizontalHeader()->setStretchLastSection(true); 41 | ui->tableView->resizeColumnsToContents(); 42 | 43 | copyNameAction = new QAction(tr("复制供应商名"),this); 44 | connect(copyNameAction,SIGNAL(triggered()),this,SLOT(copyTheNameSlot())); 45 | copyNumberAction = new QAction(tr("复制电话号码"),this); 46 | connect(copyNumberAction,SIGNAL(triggered()),this,SLOT(copyTheNumberSlot())); 47 | ui->tableView->addAction(copyNameAction); 48 | ui->tableView->addAction(copyNumberAction); 49 | ui->tableView->setContextMenuPolicy(Qt::ActionsContextMenu); 50 | } 51 | 52 | SupplierDlg::~SupplierDlg() 53 | { 54 | delete ui; 55 | } 56 | 57 | void SupplierDlg::paintEvent(QPaintEvent *event) 58 | { 59 | QPainterPath path; 60 | path.setFillRule(Qt::WindingFill); 61 | path.addRect(10,10,this->width()-20,this->height()-20); 62 | QPainter painter(this); 63 | painter.setRenderHint(QPainter::Antialiasing,true); 64 | painter.fillPath(path,QBrush(Qt::white)); 65 | 66 | QColor color(0,0,0,55); 67 | for(int i = 0;i < 9;i++) 68 | { 69 | QPainterPath pathShadow; 70 | pathShadow.setFillRule(Qt::WindingFill); 71 | // pathShadow.addRoundRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2,5); 72 | pathShadow.addRect(10-i,10-i,this->width()-(10-i)*2,this->height()-(10-i)*2); 73 | color.setAlpha(155-qSqrt(i)*55); 74 | painter.setPen(color); 75 | painter.drawPath(pathShadow); 76 | } 77 | } 78 | 79 | void SupplierDlg::mousePressEvent(QMouseEvent *event) 80 | { 81 | if(event->button() == Qt::LeftButton && event->pos().y() < 50) //判断是否为左键 82 | { 83 | startPoint = event->globalPos() - frameGeometry().topLeft(); 84 | isDrag = true; 85 | event->accept(); 86 | // startPoint = QPoint(event->pos()); //将单击point存储 87 | } 88 | } 89 | 90 | void SupplierDlg::mouseReleaseEvent(QMouseEvent *event) 91 | { 92 | isDrag = false; 93 | } 94 | 95 | void SupplierDlg::mouseMoveEvent(QMouseEvent *event) 96 | { 97 | if(event->buttons() & Qt::LeftButton && event->pos().y() < 70 && isDrag) 98 | { 99 | move(event->globalPos() - startPoint); 100 | event->accept(); 101 | } 102 | } 103 | 104 | 105 | void SupplierDlg::on_delBtn_clicked() //删除选中行 106 | { 107 | int row = ui->tableView->currentIndex().row(); 108 | QSqlRecord record = supplierModel->record(row); 109 | int id = record.value(Supplier_Id).toInt(); 110 | QSqlQuery query; 111 | if(query.exec(tr("delete from supplierTb where id = %1").arg(id))) 112 | { 113 | supplierModel->setFilter(""); 114 | supplierModel->select(); 115 | } 116 | } 117 | 118 | void SupplierDlg::on_addBtn_clicked() //添加供应商 119 | { 120 | AddSupplierDlg dlg; 121 | if(dlg.exec() == QDialog::Accepted) 122 | { 123 | supplierModel->setFilter(""); 124 | supplierModel->select(); 125 | ui->tableView->selectRow(supplierModel->rowCount() - 1); 126 | } 127 | } 128 | 129 | void SupplierDlg::copyTheNameSlot() //右键复制供应商名字 130 | { 131 | QString name = supplierModel->index(ui->tableView->currentIndex().row(),1).data().toString(); 132 | QApplication::clipboard()->setText(name); 133 | } 134 | 135 | void SupplierDlg::copyTheNumberSlot() //右键复制供应商电话 136 | { 137 | QString number = supplierModel->index(ui->tableView->currentIndex().row(),3).data().toString(); 138 | QApplication::clipboard()->setText(number); 139 | } 140 | -------------------------------------------------------------------------------- /supplierdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef SUPPLIERDLG_H 2 | #define SUPPLIERDLG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SupplierDlg; 8 | } 9 | class QSqlTableModel; 10 | enum { 11 | Supplier_Id, 12 | Supplier_Name, 13 | Supplier_Contact, 14 | Supplier_Telephone, 15 | Supplier_Address, 16 | Supplier_Note 17 | }; 18 | 19 | class SupplierDlg : public QDialog 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit SupplierDlg(QWidget *parent = 0); 25 | ~SupplierDlg(); 26 | protected: 27 | void paintEvent(QPaintEvent *event); 28 | void mousePressEvent(QMouseEvent *event); 29 | void mouseReleaseEvent(QMouseEvent *event); 30 | void mouseMoveEvent(QMouseEvent *event); 31 | private slots: 32 | void on_delBtn_clicked(); 33 | 34 | void on_addBtn_clicked(); 35 | void copyTheNameSlot(); 36 | void copyTheNumberSlot(); 37 | 38 | private: 39 | Ui::SupplierDlg *ui; 40 | QPoint startPoint; 41 | bool isDrag; //是否拖动 42 | QSqlTableModel *supplierModel; 43 | QAction *copyNameAction; 44 | QAction *copyNumberAction; 45 | 46 | void initialisePage(); 47 | }; 48 | 49 | #endif // SUPPLIERDLG_H 50 | -------------------------------------------------------------------------------- /supplierdlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SupplierDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 604 10 | 393 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | QPushButton { 18 | color: white; 19 | font: bold 10pt; 20 | border-image: url(:/images/button.png) 16; 21 | border-width: 16px; 22 | padding: -16px 0px; 23 | min-height: 32px; 24 | min-width: 60px; 25 | } 26 | 27 | QPushButton:hover{ 28 | border-image:url(:/images/button_h.png) 16; 29 | } 30 | QPushButton:pressed{ 31 | border-image:url(:/images/button_p.png) 16; 32 | } 33 | QLabel { 34 | color:gray; 35 | 36 | } 37 | QToolButton { 38 | border:0; 39 | } 40 | QToolButton#closeBtn{ 41 | background-image: url(:/images/close.png); 42 | } 43 | 44 | QToolButton#closeBtn:hover { 45 | background-image: url(:/images/close_h.png); 46 | } 47 | 48 | QToolButton#closeBtn:pressed { 49 | background-image: url(:/images/close_p.png); 50 | } 51 | 52 | QTableView { 53 | color: rgb(127, 0, 63); 54 | background-color: rgb(255, 255, 241); 55 | selection-color: white; 56 | selection-background-color: rgb(191, 31, 127); 57 | border: 2px groove gray; 58 | border-radius: 5px; 59 | padding: 2px 4px; 60 | } 61 | 62 | 63 | 64 | 65 | 66 | 30 67 | 330 68 | 92 69 | 32 70 | 71 | 72 | 73 | 删除(&D) 74 | 75 | 76 | 77 | 78 | 79 | 130 80 | 330 81 | 92 82 | 32 83 | 84 | 85 | 86 | 添加(A) 87 | 88 | 89 | 90 | 91 | 92 | 490 93 | 330 94 | 92 95 | 32 96 | 97 | 98 | 99 | 退出(&Q) 100 | 101 | 102 | true 103 | 104 | 105 | 106 | 107 | 108 | 30 109 | 60 110 | 551 111 | 261 112 | 113 | 114 | 115 | 116 | 117 | 118 | 10 119 | 10 120 | 585 121 | 40 122 | 123 | 124 | 125 | 126 | 127 | 128 | :/images/supplierHead.png 129 | 130 | 131 | 132 | 133 | 134 | 562 135 | 10 136 | 32 137 | 32 138 | 139 | 140 | 141 | 142 | 0 143 | 0 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 32 152 | 32 153 | 154 | 155 | 156 | 157 | 158 | tableView 159 | delBtn 160 | addBtn 161 | quitBtn 162 | closeBtn 163 | 164 | 165 | 166 | 167 | 168 | 169 | closeBtn 170 | clicked() 171 | SupplierDlg 172 | reject() 173 | 174 | 175 | 579 176 | 20 177 | 178 | 179 | 560 180 | 46 181 | 182 | 183 | 184 | 185 | quitBtn 186 | clicked() 187 | SupplierDlg 188 | reject() 189 | 190 | 191 | 531 192 | 340 193 | 194 | 195 | 544 196 | 377 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /widget image/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/1.jpg -------------------------------------------------------------------------------- /widget image/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/10.png -------------------------------------------------------------------------------- /widget image/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/2.jpg -------------------------------------------------------------------------------- /widget image/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/2.png -------------------------------------------------------------------------------- /widget image/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/3.png -------------------------------------------------------------------------------- /widget image/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/4.png -------------------------------------------------------------------------------- /widget image/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/5.png -------------------------------------------------------------------------------- /widget image/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/6.png -------------------------------------------------------------------------------- /widget image/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/7.png -------------------------------------------------------------------------------- /widget image/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/8.png -------------------------------------------------------------------------------- /widget image/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lidian53/Supermarket_Management_Qt/e31d9f7e770a93a832f39fce616c1aa3193b119e/widget image/9.jpg --------------------------------------------------------------------------------