├── .gitignore ├── Inventory-Management.pro ├── LICENSE ├── README.md ├── const.h ├── docs ├── images │ └── usage_sample │ │ ├── 2019-01-12_18-31-23.png │ │ ├── 2019-01-12_18-33-25.png │ │ ├── 2019-01-12_18-33-28.png │ │ ├── 2019-01-12_18-33-31.png │ │ ├── 2019-01-12_18-33-34.png │ │ ├── 2019-01-12_18-34-18.png │ │ └── 2019-01-12_18-34-28.png ├── usage_sample.md └── usage_sample_debug.log ├── inboundwidget.cpp ├── inboundwidget.h ├── inboundwidget.ui ├── inventorywidget.cpp ├── inventorywidget.h ├── inventorywidget.ui ├── logindialog.cpp ├── logindialog.h ├── logindialog.ui ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── outboundwidget.cpp ├── outboundwidget.h ├── outboundwidget.ui ├── userswidget.cpp ├── userswidget.h └── userswidget.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | -------------------------------------------------------------------------------- /Inventory-Management.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-01-03T12:39:24 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui sql 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = Inventory-Management 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp \ 30 | logindialog.cpp \ 31 | userswidget.cpp \ 32 | inventorywidget.cpp \ 33 | inboundwidget.cpp \ 34 | outboundwidget.cpp \ 35 | 36 | HEADERS += \ 37 | mainwindow.h \ 38 | logindialog.h \ 39 | const.h \ 40 | userswidget.h \ 41 | inventorywidget.h \ 42 | inboundwidget.h \ 43 | outboundwidget.h \ 44 | 45 | FORMS += \ 46 | mainwindow.ui \ 47 | logindialog.ui \ 48 | userswidget.ui \ 49 | inventorywidget.ui \ 50 | inboundwidget.ui \ 51 | outboundwidget.ui \ 52 | 53 | # Default rules for deployment. 54 | qnx: target.path = /tmp/$${TARGET}/bin 55 | else: unix:!android: target.path = /opt/$${TARGET}/bin 56 | !isEmpty(target.path): INSTALLS += target 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Inventory Management 库存管理 2 | 3 | ## Features 功能 4 | 5 | > Usage Sample 使用示例: [docs/usage_sample.md](docs/usage_sample.md) 6 | 7 | - Inventory Management 库存管理 8 | - Inbound Items 商品入库 9 | - Outbound Items 商品出库 10 | - In/outbound Log Query 入库出库记录查询 11 | - Search Item Name by Keyword 搜索商品名称关键词 12 | - Display Certain Category Logs Only 仅显示某个分类的记录 13 | - User Login/Adding 用户登录/新建 14 | 15 | ## Data Dictionary 数据字典 16 | 17 | > Corresponding lengths defined in [const.h](const.h). 相应长度定义于 [const.h](const.h)。 18 | 19 | ### Inventory Table 库存表 20 | 21 | 22 | | Field 数据域 | Type 类型 | Meaning 含义 | Other 其他 | 23 | | ------------ | --------- | ---------------------- | ---------------- | 24 | | `name` | char(16) | Item Name 商品名称 | Primary Key 主码 | 25 | | `cate` | char(16) | Item Category 商品分类 | 26 | | `amount` | int | Item Amount 商品数量 | 27 | 28 | ### In/outbound Table 入库出库表 29 | 30 | | Field 数据域 | Type 类型 | Meaning 含义 | Other 其他 | 31 | | ------------ | --------- | ---------------------- | ---------------- | 32 | | `name` | char(16) | Item Name 商品名称 | 33 | | `cate` | char(16) | Item Category 商品分类 | 34 | | `amount` | int | I/O Amount 出入数量 | 35 | | `time` | char(20) | I/O time 出入时间 | Primary Key 主码 | 36 | 37 | > Known issue: When multiple I/O manipulation occur in same second, only the first log will be recorded. 38 | > 39 | > 已知问题:当多个入库/出库操作在同一秒内发生,只有第一条日志将被记录。 40 | 41 | ### Users Table 用户表 42 | 43 | | Field 数据域 | Type 类型 | Meaning 含义 | Other 其他 | 44 | | ------------ | --------- | ---------------- | ---------------- | 45 | | `name` | char(16) | User Name 用户名 | Primary Key 主码 | 46 | | `pswd` | char(16) | Password 密码 | 47 | 48 | ## Development Environment 开发环境 49 | 50 | - Operating System: Arch Linux x86_64 (4.20.0-arch1-1-ARCH) 51 | - QT: qt5-base 5.12.0 52 | - SQL: sqlite 3.26.0 53 | - IDE: qtcreator 4.8.0 54 | - Editor: vscodium-bin 1.30.2 55 | -------------------------------------------------------------------------------- /const.h: -------------------------------------------------------------------------------- 1 | #ifndef CONST_H 2 | #define CONST_H 3 | 4 | #include 5 | 6 | // Database 7 | const QString DB_TYPE = "QSQLITE"; 8 | const QString DB_PATH = "./database.sqlite"; 9 | 10 | // User 11 | const unsigned int USERNAME_MAX_LEN = 16; 12 | const unsigned int PASSWORD_MAX_LEN = 16; 13 | // Note that length must be less than max length above. 14 | const QString DEFAULT_USERNAME = "admin"; 15 | const QString DEFAULT_PASSWORD = "admin"; 16 | 17 | // Item 18 | const unsigned int ITEMNAME_MAX_LEN = 16; 19 | const unsigned int CATEGORY_MAX_LEN = 16; 20 | // This value should be quite small to avoid overflow. 21 | const unsigned int INVENTORY_IO_MAX = 1000; 22 | 23 | #endif // CONST_H 24 | -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-31-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-31-23.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-33-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-33-25.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-33-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-33-28.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-33-31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-33-31.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-33-34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-33-34.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-34-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-34-18.png -------------------------------------------------------------------------------- /docs/images/usage_sample/2019-01-12_18-34-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liolok/Inventory-Management/9d774453ff9a0c68141f4c75fc30bbb324ce5236/docs/images/usage_sample/2019-01-12_18-34-28.png -------------------------------------------------------------------------------- /docs/usage_sample.md: -------------------------------------------------------------------------------- 1 | # Usage Sample 使用示例 2 | 3 | > Debug Log 调试日志: [usage_sample_debug.log](usage_sample_debug.log) 4 | 5 | ## Login Dialog 登录对话框 6 | 7 | Default username/password: `admin` 8 | 9 | 默认用户名/密码:`admin` 10 | 11 | ![Login Dialog](images/usage_sample/2019-01-12_18-31-23.png) 12 | 13 | ## Inventory Management Tab 库存管理标签页 14 | 15 | In/outbound items and display inventory table. 入库/出库商品并显示库存表格。 16 | 17 | ![Inventory Management Tab](images/usage_sample/2019-01-12_18-33-25.png) 18 | 19 | ## Inbound Log Query Tab 入库记录查询标签页 20 | 21 | ![Inbound Log Query Tab](images/usage_sample/2019-01-12_18-33-28.png) 22 | 23 | ## Outbound Log Query Tab 出库记录查询标签页 24 | 25 | ![Outbound Log Query Tab](images/usage_sample/2019-01-12_18-33-31.png) 26 | 27 | ## User Management Tab 用户管理标签页 28 | 29 | ![User Management Tab](images/usage_sample/2019-01-12_18-33-34.png) 30 | 31 | ## Inbound Log Query Sample#1 入库记录查询示例#1 32 | 33 | Search by item name key word. 以商品名称关键词搜索。 34 | 35 | ![Inbound Log Query Sample#1](images/usage_sample/2019-01-12_18-34-18.png) 36 | 37 | ## Inbound Log Query Sample#2 入库记录查询示例#2 38 | 39 | Display certain category logs only. 仅显示某一分类的记录。 40 | 41 | ![Inbound Log Query Sample#2](images/usage_sample/2019-01-12_18-34-28.png) 42 | -------------------------------------------------------------------------------- /docs/usage_sample_debug.log: -------------------------------------------------------------------------------- 1 | ```console 2 | 18:31:10: Starting /home/liolok/Data/Repos/build-Inventory-Management-Desktop-Debug/Inventory-Management... 3 | qt5ct: using qt5ct plugin 4 | [Login Dialog] Constructing... 5 | "CREATE TABLE IF NOT EXISTS Users (name char(16) PRIMARY KEY, pswd char(16))" true 6 | "SELECT COUNT(*) FROM Users" true 7 | "INSERT INTO Users VALUES ('admin', 'admin')" true 8 | [Login Button] Clicked... 9 | "SELECT COUNT(*) FROM Users WHERE name='admin' AND pswd='admin'" true 10 | [Inventory Widget] Constructing... 11 | "CREATE TABLE IF NOT EXISTS Inventory (name char(16) PRIMARY KEY, cate char(16), amount int)" true 12 | "CREATE TABLE IF NOT EXISTS Inbound (name char(16), cate char(16), amount int, time char(20) PRIMARY KEY)" true 13 | "CREATE TABLE IF NOT EXISTS Outbound (name char(16), cate char(16), amount int, time char(20) PRIMARY KEY)" true 14 | Refreshing inventory table... 15 | [Inbound Widget] Constructing... 16 | Refreshing inbound table view... 17 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 18 | Refreshing category combo box... 19 | [Outbound Widget] Constructing... 20 | Refreshing outbound table view... 21 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 22 | Refreshing category combo box... 23 | [Users Widget] Constructing... 24 | Refreshing user list... 25 | "SELECT name FROM Users" true 26 | [Main Window] Constructing... 27 | [Inventory Widget] Inbound button clicked... 28 | "INSERT INTO Inventory VALUES('Item 1', 'Category 1', 20) ON CONFLICT(name) DO UPDATE SET amount = amount + 20" true 29 | Refreshing inventory table... 30 | Logging inbound... 31 | "INSERT INTO Inbound VALUES('Item 1', 'Category 1', 20, datetime('now', 'localtime'))" true 32 | Refreshing category combo box... 33 | [Inbound Widget] Query button clicked... 34 | Refreshing inbound table view... 35 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 36 | [Inventory Widget] Inbound button clicked... 37 | "INSERT INTO Inventory VALUES('Item 1', 'Category 1', 40) ON CONFLICT(name) DO UPDATE SET amount = amount + 40" true 38 | Refreshing inventory table... 39 | Logging inbound... 40 | "INSERT INTO Inbound VALUES('Item 1', 'Category 1', 40, datetime('now', 'localtime'))" true 41 | Refreshing category combo box... 42 | [Inbound Widget] Query button clicked... 43 | Refreshing inbound table view... 44 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 45 | [Inventory Widget] Inbound button clicked... 46 | "INSERT INTO Inventory VALUES('Item 2', 'Category 2', 50) ON CONFLICT(name) DO UPDATE SET amount = amount + 50" true 47 | Refreshing inventory table... 48 | Logging inbound... 49 | "INSERT INTO Inbound VALUES('Item 2', 'Category 2', 50, datetime('now', 'localtime'))" true 50 | Refreshing category combo box... 51 | [Inbound Widget] Query button clicked... 52 | Refreshing inbound table view... 53 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 54 | [Inventory Widget] Outbound button clicked... 55 | "SELECT cate, amount FROM Inventory WHERE name='Item 1'" true 56 | "UPDATE Inventory SET amount = amount - 5 WHERE name = 'Item 1'" true 57 | Refreshing inventory table... 58 | Logging outbound... 59 | "INSERT INTO Outbound VALUES('Item 1', 'Category 1', 5, datetime('now', 'localtime'))" true 60 | Refreshing category combo box... 61 | [Outbound Widget] Query button clicked... 62 | Refreshing outbound table view... 63 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 64 | [Inventory Widget] Inbound button clicked... 65 | "INSERT INTO Inventory VALUES('Item 3', 'Category 3', 60) ON CONFLICT(name) DO UPDATE SET amount = amount + 60" true 66 | Refreshing inventory table... 67 | Logging inbound... 68 | "INSERT INTO Inbound VALUES('Item 3', 'Category 3', 60, datetime('now', 'localtime'))" true 69 | Refreshing category combo box... 70 | [Inbound Widget] Query button clicked... 71 | Refreshing inbound table view... 72 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 73 | [Inventory Widget] Outbound button clicked... 74 | "SELECT cate, amount FROM Inventory WHERE name='Item 2'" true 75 | "UPDATE Inventory SET amount = amount - 5 WHERE name = 'Item 2'" true 76 | Refreshing inventory table... 77 | Logging outbound... 78 | "INSERT INTO Outbound VALUES('Item 2', 'Category 2', 5, datetime('now', 'localtime'))" true 79 | Refreshing category combo box... 80 | [Outbound Widget] Query button clicked... 81 | Refreshing outbound table view... 82 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 83 | [Inventory Widget] Outbound button clicked... 84 | "SELECT cate, amount FROM Inventory WHERE name='Item 2'" true 85 | "UPDATE Inventory SET amount = amount - 5 WHERE name = 'Item 2'" true 86 | Refreshing inventory table... 87 | Logging outbound... 88 | "INSERT INTO Outbound VALUES('Item 2', 'Category 2', 5, datetime('now', 'localtime'))" true 89 | Refreshing category combo box... 90 | [Outbound Widget] Query button clicked... 91 | Refreshing outbound table view... 92 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 93 | [Inventory Widget] Inbound button clicked... 94 | "INSERT INTO Inventory VALUES('Item 4', 'Category 4', 40) ON CONFLICT(name) DO UPDATE SET amount = amount + 40" true 95 | Refreshing inventory table... 96 | Logging inbound... 97 | "INSERT INTO Inbound VALUES('Item 4', 'Category 4', 40, datetime('now', 'localtime'))" true 98 | Refreshing category combo box... 99 | [Inbound Widget] Query button clicked... 100 | Refreshing inbound table view... 101 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound" 102 | [Inventory Widget] Outbound button clicked... 103 | "SELECT cate, amount FROM Inventory WHERE name='Item 4'" true 104 | "UPDATE Inventory SET amount = amount - 5 WHERE name = 'Item 4'" true 105 | Refreshing inventory table... 106 | Logging outbound... 107 | "INSERT INTO Outbound VALUES('Item 4', 'Category 4', 5, datetime('now', 'localtime'))" true 108 | Refreshing category combo box... 109 | [Outbound Widget] Query button clicked... 110 | Refreshing outbound table view... 111 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 112 | [Inventory Widget] Outbound button clicked... 113 | "SELECT cate, amount FROM Inventory WHERE name='Item 3'" true 114 | "UPDATE Inventory SET amount = amount - 10 WHERE name = 'Item 3'" true 115 | Refreshing inventory table... 116 | Logging outbound... 117 | "INSERT INTO Outbound VALUES('Item 3', 'Category 3', 10, datetime('now', 'localtime'))" true 118 | Refreshing category combo box... 119 | [Outbound Widget] Query button clicked... 120 | Refreshing outbound table view... 121 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Outbound" 122 | [Inbound Widget] Query button clicked... 123 | Refreshing inbound table view... 124 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound WHERE name LIKE '%1%'" 125 | [Inbound Widget] Query button clicked... 126 | Refreshing inbound table view... 127 | "SELECT name AS Name, cate AS Category, amount as Amount, time as Time FROM Inbound WHERE cate = 'Category 3'" 128 | [Main Window] Destructing... 129 | [Inventory Widget] Destructing... 130 | [Inbound Widget] Destructing... 131 | [Outbound Widget] Destructing... 132 | [Users Widget] Destructing... 133 | [Login Dialog] Destructing... 134 | 18:34:49: /home/liolok/Data/Repos/build-Inventory-Management-Desktop-Debug/Inventory-Management exited with code 0 135 | ``` -------------------------------------------------------------------------------- /inboundwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "const.h" 2 | #include "inboundwidget.h" 3 | #include "ui_inboundwidget.h" 4 | #include 5 | 6 | InboundWidget::InboundWidget(QWidget *parent) : 7 | QWidget(parent), 8 | ui(new Ui::InboundWidget), 9 | qry(new QSqlQuery), 10 | modelInbound(new QSqlQueryModel), 11 | modelCategory(new QSqlQueryModel) 12 | { 13 | qDebug() << "[Inbound Widget] Constructing..."; 14 | ui->setupUi(this); 15 | ui->lineEditNameKey->setMaxLength(ITEMNAME_MAX_LEN); 16 | ui->tableViewInbound->horizontalHeader()-> 17 | setSectionResizeMode(QHeaderView::Stretch); 18 | 19 | refreshInboundTableView(); 20 | refreshCategoryComboBox(); 21 | } 22 | 23 | InboundWidget::~InboundWidget() 24 | { 25 | qDebug() << "[Inbound Widget] Destructing..."; 26 | delete ui; 27 | delete qry; 28 | delete modelInbound; 29 | delete modelCategory; 30 | } 31 | 32 | void InboundWidget::on_pushButtonQuery_clicked() 33 | { 34 | qDebug() << "[Inbound Widget] Query button clicked..."; 35 | QString nameKey = ui->lineEditNameKey->text(); 36 | QString category = ui->comboBoxCategory->currentText(); 37 | bool searchName = ui->checkBoxName->isChecked(); 38 | bool categoryOnly = ui->checkBoxCate->isChecked(); 39 | 40 | QString clause = ""; // Prepare query where cluase if needed. 41 | QString nameCondition = QString("name LIKE '%%1%'").arg(nameKey); 42 | QString cateCondition = QString("cate = '%1'").arg(category); 43 | if (searchName) 44 | { 45 | clause += " WHERE " + nameCondition; 46 | if (categoryOnly) clause += " AND " + cateCondition; 47 | } 48 | else if (categoryOnly) clause += " WHERE " + cateCondition; 49 | 50 | refreshInboundTableView(clause); 51 | } 52 | 53 | void InboundWidget::refreshInboundTableView(const QString& qry_clause/*=""*/) 54 | { 55 | qDebug() << "Refreshing inbound table view..."; 56 | QString s = "SELECT name AS %1, cate AS %2, " 57 | "amount as %3, time as %4 FROM Inbound"; 58 | QString view_inbound = s.arg( 59 | tr("Name"), tr("Category"), tr("Amount"), tr("Time")) + qry_clause; 60 | qDebug() << view_inbound; 61 | modelInbound->setQuery(view_inbound); 62 | ui->tableViewInbound->setModel(modelInbound); 63 | } 64 | 65 | void InboundWidget::refreshCategoryComboBox() 66 | { 67 | qDebug() << "Refreshing category combo box..."; 68 | QString get_distinct_cate = "SELECT DISTINCT cate FROM Inbound"; 69 | modelCategory->setQuery(get_distinct_cate); 70 | ui->comboBoxCategory->setModel(modelCategory); 71 | } 72 | -------------------------------------------------------------------------------- /inboundwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef INBOUNDWIDGET_H 2 | #define INBOUNDWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class InboundWidget; 10 | } 11 | 12 | class InboundWidget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit InboundWidget(QWidget *parent = nullptr); 18 | ~InboundWidget(); 19 | 20 | private: 21 | Ui::InboundWidget *ui; 22 | QSqlQuery *qry; 23 | QSqlQueryModel *modelInbound; 24 | QSqlQueryModel *modelCategory; 25 | void refreshInboundTableView(const QString& qry_clause = ""); 26 | 27 | public slots: 28 | void refreshCategoryComboBox(); 29 | void on_pushButtonQuery_clicked(); 30 | }; 31 | 32 | #endif // INBOUNDWIDGET_H 33 | -------------------------------------------------------------------------------- /inboundwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InboundWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | 15 | 16 | 17 | 12 18 | 19 | 20 | 12 21 | 22 | 23 | 12 24 | 25 | 26 | 12 27 | 28 | 29 | 12 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | Category only 47 | 48 | 49 | 50 | 51 | 52 | 53 | Search Name 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Query 63 | 64 | 65 | 66 | 67 | 68 | 69 | Qt::Vertical 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | QAbstractItemView::NoEditTriggers 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /inventorywidget.cpp: -------------------------------------------------------------------------------- 1 | #include "inventorywidget.h" 2 | #include "ui_inventorywidget.h" 3 | #include 4 | 5 | InventoryWidget::InventoryWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::InventoryWidget), 8 | qry(new QSqlQuery), 9 | model(new QSqlQueryModel) 10 | { 11 | qDebug() << "[Inventory Widget] Constructing..."; 12 | ui->setupUi(this); 13 | ui->lineEditInName->setMaxLength(ITEMNAME_MAX_LEN); 14 | ui->lineEditInCategory->setMaxLength(CATEGORY_MAX_LEN); 15 | ui->spinBoxInAmount->setMaximum(INVENTORY_IO_MAX); 16 | ui->lineEditOutName->setMaxLength(ITEMNAME_MAX_LEN); 17 | ui->spinBoxOutAmount->setMaximum(INVENTORY_IO_MAX); 18 | ui->tableViewInventory->horizontalHeader() 19 | ->setSectionResizeMode(QHeaderView::Stretch); 20 | 21 | // If no inventory table yet, create it. 22 | QString s = "CREATE TABLE IF NOT EXISTS Inventory (" 23 | "name char(%1) PRIMARY KEY, cate char(%2), amount int)"; 24 | QString create_inventory_table = s.arg( 25 | QString::number(ITEMNAME_MAX_LEN), QString::number(CATEGORY_MAX_LEN)); 26 | qDebug() << create_inventory_table << qry->exec(create_inventory_table); 27 | 28 | // If no inbound table yet, create it. 29 | s = "CREATE TABLE IF NOT EXISTS Inbound (" 30 | "name char(%1), cate char(%2), amount int, time char(20) PRIMARY KEY)"; 31 | QString create_inbound_table = s.arg( 32 | QString::number(ITEMNAME_MAX_LEN), QString::number(CATEGORY_MAX_LEN)); 33 | qDebug() << create_inbound_table << qry->exec(create_inbound_table); 34 | 35 | // If no outbound table yet, create it. 36 | s = "CREATE TABLE IF NOT EXISTS Outbound (" 37 | "name char(%1), cate char(%2), amount int, time char(20) PRIMARY KEY)"; 38 | QString create_outbound_table = s.arg( 39 | QString::number(ITEMNAME_MAX_LEN), QString::number(CATEGORY_MAX_LEN)); 40 | qDebug() << create_outbound_table << qry->exec(create_outbound_table); 41 | 42 | refreshInventoryTable(); 43 | } 44 | 45 | InventoryWidget::~InventoryWidget() 46 | { 47 | qDebug() << "[Inventory Widget] Destructing..."; 48 | delete ui; 49 | delete qry; 50 | delete model; 51 | } 52 | 53 | void InventoryWidget::on_pushButtonInbound_clicked() 54 | { 55 | qDebug() << "[Inventory Widget] Inbound button clicked..."; 56 | QString name = ui->lineEditInName->text(); 57 | QString cate = ui->lineEditInCategory->text(); 58 | int increment = ui->spinBoxInAmount->value(); 59 | 60 | if (!(name.length() && cate.length())) 61 | { 62 | qDebug() << "Field no input, won't inbound item."; 63 | return; 64 | } 65 | 66 | // Special Syntax Addition | NOT Standard SQL | SQLite >= 3.24.0 67 | // See: https://www.sqlite.org/lang_UPSERT.html 68 | QString s = "INSERT INTO Inventory VALUES('%1', '%2', %3) " 69 | "ON CONFLICT(name) DO UPDATE SET amount = amount + %3"; 70 | QString inbound = s.arg(name, cate, QString::number(increment)); 71 | bool success = qry->exec(inbound); 72 | qDebug() << inbound << success; 73 | if (success) 74 | { 75 | refreshInventoryTable(); 76 | qDebug() << "Logging inbound..."; 77 | QString s = "INSERT INTO Inbound VALUES(" 78 | "'%1', '%2', %3, datetime('now', 'localtime'))"; 79 | QString log_inbound = s.arg(name, cate, QString::number(increment)); 80 | qDebug() << log_inbound << qry->exec(log_inbound); 81 | inbounded(); 82 | } 83 | } 84 | 85 | void InventoryWidget::on_pushButtonOutbound_clicked() 86 | { 87 | qDebug() << "[Inventory Widget] Outbound button clicked..."; 88 | QString name = ui->lineEditOutName->text(), cate; 89 | int amount, decrement = ui->spinBoxOutAmount->value(); 90 | 91 | // Get category and currnet amount of item. 92 | QString s = "SELECT cate, amount FROM Inventory WHERE name='%1'"; 93 | QString get_item_info = s.arg(name); 94 | qDebug() << get_item_info << qry->exec(get_item_info); 95 | if (!qry->first()) { qDebug() << "Item not found."; return; } 96 | else { cate = qry->value(0).toString(); amount = qry->value(1).toInt(); } 97 | // Ensure amount would still be non-negtaive after outbound. 98 | if (amount < decrement) { qDebug() << "Amount not enough."; return; } 99 | 100 | s = "UPDATE Inventory SET amount = amount - %1 WHERE name = '%2'"; 101 | QString outbound = s.arg(QString::number(decrement), name); 102 | bool success = qry->exec(outbound); 103 | qDebug() << outbound << success; 104 | if (success) 105 | { 106 | refreshInventoryTable(); 107 | qDebug() << "Logging outbound..."; 108 | s = "INSERT INTO Outbound VALUES(" 109 | "'%1', '%2', %3, datetime('now', 'localtime'))"; 110 | QString log_outbound = s.arg(name, cate, QString::number(decrement)); 111 | qDebug() << log_outbound << qry->exec(log_outbound); 112 | outbounded(); 113 | } 114 | } 115 | 116 | void InventoryWidget::refreshInventoryTable() 117 | { 118 | qDebug() << "Refreshing inventory table..."; 119 | QString s = "SELECT name AS %1, cate AS %2, amount AS %3 FROM Inventory"; 120 | QString view_inventory = s.arg(tr("Name"), tr("Category"), tr("Amount")); 121 | model->setQuery(view_inventory); 122 | ui->tableViewInventory->setModel(model); 123 | } 124 | -------------------------------------------------------------------------------- /inventorywidget.h: -------------------------------------------------------------------------------- 1 | #ifndef INVENTORYWIDGET_H 2 | #define INVENTORYWIDGET_H 3 | 4 | #include "const.h" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class InventoryWidget; 11 | } 12 | 13 | class InventoryWidget : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit InventoryWidget(QWidget *parent = nullptr); 19 | ~InventoryWidget(); 20 | 21 | private: 22 | Ui::InventoryWidget *ui; 23 | QSqlQuery *qry; 24 | QSqlQueryModel *model; 25 | void refreshInventoryTable(); 26 | 27 | signals: 28 | void inbounded(); 29 | void outbounded(); 30 | 31 | private slots: 32 | void on_pushButtonInbound_clicked(); 33 | void on_pushButtonOutbound_clicked(); 34 | }; 35 | 36 | #endif // INVENTORYWIDGET_H 37 | -------------------------------------------------------------------------------- /inventorywidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InventoryWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | 15 | 16 | 17 | 12 18 | 19 | 20 | 12 21 | 22 | 23 | 12 24 | 25 | 26 | 12 27 | 28 | 29 | 12 30 | 31 | 32 | 33 | 34 | 35 | 36 | true 37 | 38 | 39 | 40 | 41 | 42 | 43 | Name 44 | 45 | 46 | 47 | 48 | 49 | 50 | 1 51 | 52 | 53 | 54 | 55 | 56 | 57 | Category 58 | 59 | 60 | 61 | 62 | 63 | 64 | Amount 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Inbound Item 81 | 82 | 83 | true 84 | 85 | 86 | 87 | 88 | 89 | 90 | Qt::Vertical 91 | 92 | 93 | 94 | 0 95 | 0 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | Name 106 | 107 | 108 | 109 | 110 | 111 | 112 | true 113 | 114 | 115 | 116 | 117 | 118 | 119 | 1 120 | 121 | 122 | 123 | 124 | 125 | 126 | Amount 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | Outbound Item 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | QAbstractItemView::NoEditTriggers 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /logindialog.cpp: -------------------------------------------------------------------------------- 1 | #include "logindialog.h" 2 | #include "ui_logindialog.h" 3 | #include 4 | 5 | LoginDialog::LoginDialog(QWidget *parent) : 6 | QDialog(parent), 7 | ui(new Ui::LoginDialog), 8 | qry(new QSqlQuery) 9 | { 10 | qDebug() << "[Login Dialog] Constructing..."; 11 | ui->setupUi(this); 12 | ui->lineEditUsername->setMaxLength(USERNAME_MAX_LEN); 13 | ui->lineEditPassword->setMaxLength(PASSWORD_MAX_LEN); 14 | 15 | // If no user table yet, create it. 16 | QString s = "CREATE TABLE IF NOT EXISTS Users (" 17 | "name char(%1) PRIMARY KEY, pswd char(%2))"; 18 | QString create_user_table = s.arg( 19 | QString::number(USERNAME_MAX_LEN), QString::number(PASSWORD_MAX_LEN)); 20 | qDebug() << create_user_table << qry->exec(create_user_table); 21 | // WONTDO: visual feedback, like initial message box. 22 | 23 | // If no user yet, add a default one to login. 24 | QString count_users = "SELECT COUNT(*) FROM Users"; 25 | qDebug() << count_users << qry->exec(count_users); 26 | if (qry->first() && !qry->value(0).toInt()) 27 | { 28 | QString s = "INSERT INTO Users VALUES ('%1', '%2')"; 29 | QString add_default_user = s.arg(DEFAULT_USERNAME, DEFAULT_PASSWORD); 30 | qDebug() << add_default_user << qry->exec(add_default_user); 31 | } 32 | } 33 | 34 | LoginDialog::~LoginDialog() 35 | { 36 | qDebug() << "[Login Dialog] Destructing..."; 37 | delete ui; 38 | delete qry; 39 | } 40 | 41 | void LoginDialog::on_loginButton_clicked() 42 | { 43 | qDebug() << "[Login Button] Clicked..."; 44 | QString username = ui->lineEditUsername->text(); 45 | QString password = ui->lineEditPassword->text(); 46 | 47 | // Validate input user info against user table in database 48 | QString s = "SELECT COUNT(*) FROM Users WHERE name='%1' AND pswd='%2'"; 49 | QString validate_user = s.arg(username, password); 50 | qDebug() << validate_user << qry->exec(validate_user); 51 | if (qry->first() && qry->value(0).toInt()) accept(); 52 | // WONTDO: Exceoption when input user info incorrect 53 | } 54 | -------------------------------------------------------------------------------- /logindialog.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINDIALOG_H 2 | #define LOGINDIALOG_H 3 | 4 | #include "const.h" 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class LoginDialog; 10 | } 11 | 12 | class LoginDialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit LoginDialog(QWidget *parent = nullptr); 18 | ~LoginDialog(); 19 | 20 | private: 21 | Ui::LoginDialog *ui; 22 | QSqlQuery *qry; 23 | 24 | private slots: 25 | void on_loginButton_clicked(); 26 | }; 27 | 28 | #endif // LOGINDIALOG_H 29 | -------------------------------------------------------------------------------- /logindialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 320 10 | 160 11 | 12 | 13 | 14 | 15 | 320 16 | 160 17 | 18 | 19 | 20 | 21 | 320 22 | 160 23 | 24 | 25 | 26 | User Login - Inventory Management 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 320 37 | 160 38 | 39 | 40 | 41 | 42 | 0 43 | 0 44 | 45 | 46 | 47 | 48 | 12 49 | 50 | 51 | 12 52 | 53 | 54 | 55 | 56 | 57 | 0 58 | 0 59 | 60 | 61 | 62 | QLineEdit::Password 63 | 64 | 65 | Password 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | QLineEdit::Normal 76 | 77 | 78 | Username 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | 87 | 88 | Login 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | lineEditUsername 97 | lineEditPassword 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "const.h" 2 | #include "logindialog.h" 3 | #include "mainwindow.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | QSqlDatabase db = QSqlDatabase::addDatabase(DB_TYPE); 12 | db.setDatabaseName(DB_PATH); 13 | if (!db.open()) 14 | { 15 | qDebug() << "Fails opening database:" << db.lastError(); 16 | return -1; 17 | } 18 | 19 | QApplication app(argc, argv); 20 | LoginDialog ld; 21 | 22 | if (ld.exec() == QDialog::Accepted) 23 | { 24 | MainWindow mw; 25 | mw.show(); 26 | app.exec(); 27 | } 28 | else app.quit(); 29 | 30 | db.close(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::MainWindow), 8 | inventory(new InventoryWidget(this)), 9 | inbound(new InboundWidget(this)), 10 | outbound(new OutboundWidget(this)), 11 | users(new UsersWidget(this)) 12 | { 13 | qDebug() << "[Main Window] Constructing..."; 14 | ui->setupUi(this); 15 | 16 | ui->tabWidget->addTab(inventory, tr("Inventory")); 17 | ui->tabWidget->addTab(inbound, tr("Inbound")); 18 | ui->tabWidget->addTab(outbound, tr("Outbound")); 19 | ui->tabWidget->addTab(users, tr("Users")); 20 | 21 | connect(inventory, &InventoryWidget::inbounded, 22 | inbound, &InboundWidget::refreshCategoryComboBox); 23 | connect(inventory, &InventoryWidget::inbounded, 24 | inbound, &InboundWidget::on_pushButtonQuery_clicked); 25 | 26 | connect(inventory, &InventoryWidget::outbounded, 27 | outbound, &OutboundWidget::refreshCategoryComboBox); 28 | connect(inventory, &InventoryWidget::outbounded, 29 | outbound, &OutboundWidget::on_pushButtonQuery_clicked); 30 | } 31 | 32 | MainWindow::~MainWindow() 33 | { 34 | qDebug() << "[Main Window] Destructing..."; 35 | delete ui; 36 | delete inventory; 37 | delete inbound; 38 | delete outbound; 39 | delete users; 40 | } 41 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include "inventorywidget.h" 6 | #include "inboundwidget.h" 7 | #include "outboundwidget.h" 8 | #include "userswidget.h" 9 | 10 | namespace Ui { 11 | class MainWindow; 12 | } 13 | 14 | class MainWindow : public QMainWindow 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit MainWindow(QWidget *parent = nullptr); 20 | ~MainWindow(); 21 | 22 | private: 23 | Ui::MainWindow *ui; 24 | 25 | InventoryWidget *inventory; 26 | InboundWidget *inbound; 27 | OutboundWidget *outbound; 28 | UsersWidget *users; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1280 10 | 720 11 | 12 | 13 | 14 | 15 | 1280 16 | 720 17 | 18 | 19 | 20 | Inventory Management 21 | 22 | 23 | 24 | 25 | 0 26 | 0 27 | 28 | 29 | 30 | 31 | 32 | 33 | -1 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /outboundwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "const.h" 2 | #include "outboundwidget.h" 3 | #include "ui_outboundwidget.h" 4 | #include 5 | 6 | OutboundWidget::OutboundWidget(QWidget *parent) : 7 | QWidget(parent), 8 | ui(new Ui::OutboundWidget), 9 | qry(new QSqlQuery), 10 | modelOutbound(new QSqlQueryModel), 11 | modelCategory(new QSqlQueryModel) 12 | { 13 | qDebug() << "[Outbound Widget] Constructing..."; 14 | ui->setupUi(this); 15 | ui->lineEditNameKey->setMaxLength(ITEMNAME_MAX_LEN); 16 | ui->tableViewOutbound->horizontalHeader()-> 17 | setSectionResizeMode(QHeaderView::Stretch); 18 | 19 | refreshOutboundTableView(); 20 | refreshCategoryComboBox(); 21 | } 22 | 23 | OutboundWidget::~OutboundWidget() 24 | { 25 | qDebug() << "[Outbound Widget] Destructing..."; 26 | delete ui; 27 | delete qry; 28 | delete modelOutbound; 29 | delete modelCategory; 30 | } 31 | 32 | void OutboundWidget::on_pushButtonQuery_clicked() 33 | { 34 | qDebug() << "[Outbound Widget] Query button clicked..."; 35 | QString nameKey = ui->lineEditNameKey->text(); 36 | QString category = ui->comboBoxCategory->currentText(); 37 | bool searchName = ui->checkBoxName->isChecked(); 38 | bool categoryOnly = ui->checkBoxCate->isChecked(); 39 | 40 | QString clause = ""; // Prepare query where cluase if needed. 41 | QString nameCondition = QString("name LIKE '%%1%'").arg(nameKey); 42 | QString cateCondition = QString("cate = '%1'").arg(category); 43 | if (searchName) 44 | { 45 | clause += " WHERE " + nameCondition; 46 | if (categoryOnly) clause += " AND " + cateCondition; 47 | } 48 | else if (categoryOnly) clause += " WHERE " + cateCondition; 49 | 50 | refreshOutboundTableView(clause); 51 | } 52 | 53 | void OutboundWidget::refreshOutboundTableView(const QString& qry_clause/*=""*/) 54 | { 55 | qDebug() << "Refreshing outbound table view..."; 56 | QString s = "SELECT name AS %1, cate AS %2, " 57 | "amount as %3, time as %4 FROM Outbound"; 58 | QString view_outbound = s.arg( 59 | tr("Name"), tr("Category"), tr("Amount"), tr("Time")) + qry_clause; 60 | qDebug() << view_outbound; 61 | modelOutbound->setQuery(view_outbound); 62 | ui->tableViewOutbound->setModel(modelOutbound); 63 | } 64 | 65 | void OutboundWidget::refreshCategoryComboBox() 66 | { 67 | qDebug() << "Refreshing category combo box..."; 68 | QString get_distinct_cate = "SELECT DISTINCT cate FROM Outbound"; 69 | modelCategory->setQuery(get_distinct_cate); 70 | ui->comboBoxCategory->setModel(modelCategory); 71 | } 72 | -------------------------------------------------------------------------------- /outboundwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef OUTBOUNDWIDGET_H 2 | #define OUTBOUNDWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class OutboundWidget; 10 | } 11 | 12 | class OutboundWidget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit OutboundWidget(QWidget *parent = nullptr); 18 | ~OutboundWidget(); 19 | 20 | private: 21 | Ui::OutboundWidget *ui; 22 | QSqlQuery *qry; 23 | QSqlQueryModel *modelOutbound; 24 | QSqlQueryModel *modelCategory; 25 | void refreshOutboundTableView(const QString& qry_clause = ""); 26 | 27 | public slots: 28 | void refreshCategoryComboBox(); 29 | void on_pushButtonQuery_clicked(); 30 | }; 31 | 32 | #endif // OUTBOUNDWIDGET_H -------------------------------------------------------------------------------- /outboundwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | OutboundWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | 15 | 16 | 17 | 12 18 | 19 | 20 | 12 21 | 22 | 23 | 12 24 | 25 | 26 | 12 27 | 28 | 29 | 12 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | Category only 47 | 48 | 49 | 50 | 51 | 52 | 53 | Search Name 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Query 63 | 64 | 65 | 66 | 67 | 68 | 69 | Qt::Vertical 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | QAbstractItemView::NoEditTriggers 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /userswidget.cpp: -------------------------------------------------------------------------------- 1 | #include "userswidget.h" 2 | #include "ui_userswidget.h" 3 | #include 4 | 5 | UsersWidget::UsersWidget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::UsersWidget), 8 | qry(new QSqlQuery) 9 | { 10 | qDebug() << "[Users Widget] Constructing..."; 11 | ui->setupUi(this); 12 | ui->lineEditUsername->setMaxLength(USERNAME_MAX_LEN); 13 | ui->lineEditPassword->setMaxLength(PASSWORD_MAX_LEN); 14 | ui->lineEditPasswordConfirm->setMaxLength(PASSWORD_MAX_LEN); 15 | 16 | refreshUserList(); 17 | } 18 | 19 | UsersWidget::~UsersWidget() 20 | { 21 | qDebug() << "[Users Widget] Destructing..."; 22 | delete ui; 23 | delete qry; 24 | } 25 | 26 | void UsersWidget::on_addUserButton_clicked() 27 | { 28 | qDebug() << "[Users Widget] Clicked add user button..."; 29 | QString name = ui->lineEditUsername->text(); 30 | QString pswd = ui->lineEditPassword->text(); 31 | QString pswdConfirm = ui->lineEditPasswordConfirm->text(); 32 | 33 | if (!(name.length() && pswd.length() && pswdConfirm.length()) 34 | || (pswd != pswdConfirm)) 35 | { 36 | qDebug() << "Field no input or password not confirmed, won't add user."; 37 | return; // WONTDO: visual feedback, like lineEdit border get red. 38 | } 39 | 40 | QString s = "INSERT INTO Users VALUES ('%1', '%2')"; 41 | QString add_user = s.arg(name, pswd); 42 | bool success = qry->exec(add_user); 43 | qDebug() << add_user << success; 44 | if (success) refreshUserList(); 45 | } 46 | 47 | void UsersWidget::refreshUserList() 48 | { 49 | qDebug() << "Refreshing user list..."; 50 | QString get_all_username = "SELECT name FROM Users"; 51 | qDebug() << get_all_username << qry->exec(get_all_username); 52 | ui->userList->clear(); 53 | while (qry->next()) { ui->userList->addItem(qry->value(0).toString()); } 54 | } 55 | -------------------------------------------------------------------------------- /userswidget.h: -------------------------------------------------------------------------------- 1 | #ifndef USERSWIDGET_H 2 | #define USERSWIDGET_H 3 | 4 | #include "const.h" 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class UsersWidget; 10 | } 11 | 12 | class UsersWidget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit UsersWidget(QWidget *parent = nullptr); 18 | ~UsersWidget(); 19 | 20 | private: 21 | Ui::UsersWidget *ui; 22 | QSqlQuery *qry; 23 | void refreshUserList(); 24 | 25 | private slots: 26 | void on_addUserButton_clicked(); 27 | }; 28 | 29 | #endif // USERSWIDGET_H 30 | -------------------------------------------------------------------------------- /userswidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | UsersWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 640 10 | 480 11 | 12 | 13 | 14 | 15 | 16 | 17 | QAbstractItemView::NoEditTriggers 18 | 19 | 20 | 0 21 | 22 | 23 | 24 | 25 | 26 | 27 | 12 28 | 29 | 30 | 12 31 | 32 | 33 | 12 34 | 35 | 36 | 12 37 | 38 | 39 | 40 | 41 | Username 42 | 43 | 44 | true 45 | 46 | 47 | 48 | 49 | 50 | 51 | QLineEdit::Password 52 | 53 | 54 | Password 55 | 56 | 57 | true 58 | 59 | 60 | 61 | 62 | 63 | 64 | QLineEdit::Password 65 | 66 | 67 | Confirm Password 68 | 69 | 70 | true 71 | 72 | 73 | 74 | 75 | 76 | 77 | Add User 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 87 | Qt::Vertical 88 | 89 | 90 | 91 | 20 92 | 40 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | --------------------------------------------------------------------------------