├── README.md ├── head ├── Beverage.h ├── Commodity.h ├── Cosmetic.h ├── Daily.h ├── Food.h ├── Manager.h ├── RepManager.h ├── Saler.h ├── Sorter.h ├── commodities.h └── doc │ ├── 面向对象课程设计报告刘家麒.pdf │ └── 面向对象课设答辩.pptx ├── inputwidget.cpp ├── inputwidget.h ├── inputwidget.ui ├── logindia.cpp ├── logindia.h ├── logindia.ui ├── logo.ico ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── oop_qt.pro ├── oop_qt.pro.user ├── rc.qrc ├── rc ├── 9954a5f7dfd64e7bafc23eda4e8b9487.gif ├── buyCar.png ├── key.png ├── manage.gif ├── money.png ├── n133f35jvek.jpg └── show.gif ├── removeWindows.cpp └── s ├── Beverage.cpp ├── Commodity.cpp ├── Cosmetic.cpp ├── Daily.cpp ├── Food.cpp ├── Manager.cpp ├── RepManager.cpp ├── Saler.cpp └── Sorter.cpp /README.md: -------------------------------------------------------------------------------- 1 | # cpp-qt-manageSystem 2 | ## 基于C++和qt的超市商品管理系统 3 | wtu 计科21级面向对象课程设计 4 | 5 | 6 | ### 一 简要介绍 7 | 1.本项目为面向对象程序设计的大作业,基于Qt creator进行开发,Qt框架版本6.4.1,编译环境MINGW 11.2.0。 8 | 9 | 2.项目结构简介:关于系统逻辑部分的代码的头文件在head文件夹中,源文件在s文件夹中。与图形界面相关的代码在项目头文件和源文件的文件夹内。 10 | 应用程序内使用的一些图片、动图在rc文件夹内。 11 | 12 | 3.UML类图: 13 | 14 | ![image](https://user-images.githubusercontent.com/62981633/210293721-0eb891fa-3d48-40a9-a200-b0c28bec0b27.png) 15 | 16 | 17 | ### 二 使用方式 18 | 1.可下载源码使用Qt creator进行构建后运行 19 | 20 | 2.若无Qt环境,可以直接下载Releases版本运行,无需任何依赖。若需要测试用例,可将文件夹内的测试数据文件夹内的文件移动至可执行程序目录中。 21 | 若不移动,则系统无初始数据,需要输入初始密码。 22 | 23 | 24 | ### 三 运行截图 25 | 26 | #### 登录界面 27 | ![image](https://user-images.githubusercontent.com/62981633/210294033-f7e02c26-da1d-4c05-9e13-3b8331364956.png) 28 | 29 | #### 商品信息输入窗口 30 | ![image](https://user-images.githubusercontent.com/62981633/210294299-c2056e56-7a04-4214-9b72-13dcb360a7a3.png) 31 | 32 | #### 主界面 33 | ![image](https://user-images.githubusercontent.com/62981633/210294056-8ddd168e-9bab-4ce7-9e53-55e0298c30e8.png) 34 | 35 | #### 库存商品页面 36 | ![捕获](https://user-images.githubusercontent.com/62981633/210294159-a906ff7b-1eb8-4c30-a6a3-d9e0d3c13546.PNG) 37 | 38 | #### 销售统计 39 | ![捕获1](https://user-images.githubusercontent.com/62981633/210294246-6fa44107-65e4-4e38-b881-617fff50bad4.PNG) 40 | 41 | #### 收银台界面 42 | ![捕获3](https://user-images.githubusercontent.com/62981633/210294373-2b68c470-4253-4441-945f-b9959dc34785.PNG) 43 | 44 | -------------------------------------------------------------------------------- /head/Beverage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Commodity.h" 3 | #include 4 | #include 5 | #include 6 | 7 | class Beverage :public Commodity { 8 | public: 9 | enum class BeverageKind { 10 | JUICE, WINE, SODA 11 | //普通饮料,酒,碳酸饮料 12 | }; 13 | protected: 14 | int _capacity; //容量 15 | BeverageKind _kind; 16 | static long maxNo; 17 | static const std::array kindStrs; 18 | public: 19 | Beverage(); 20 | Beverage(std::string name, std::string brand, 21 | std::string manufactuer, double price, 22 | double cost, int amount, bool onSale, int saleCount, int _capacity, BeverageKind); 23 | friend std::ifstream& operator>>(std::ifstream& ifs, Beverage& b); 24 | friend std::ofstream& operator<<(std::ofstream& ofs, Beverage& b); 25 | ~Beverage() = default; 26 | int getKind() override; 27 | double getWeiOrCapa() override; 28 | void setWeiOrCapa(double wc) override; 29 | std::string getKindStr(void) override; 30 | void setKind(int k) override; 31 | }; 32 | -------------------------------------------------------------------------------- /head/Commodity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | class Commodity 6 | { 7 | protected: 8 | 9 | std::string _no; //商品编号 10 | std::string _name; //商品名称 11 | std::string _brand; //品牌 12 | std::string _manufacturer; //厂家 13 | double _price; //价格 14 | double _cost; // 成本 15 | int _amount; //库存数量 16 | bool _onSale; //是否在售 17 | int _saleCount; //销量 18 | public: 19 | Commodity() = default; 20 | Commodity(std::string no, std::string name, std::string brand, 21 | std::string manufacturer, double price, double cost, int amount,bool onSale,int saleCount); 22 | virtual ~Commodity() = default; 23 | 24 | int getAmount(void); 25 | int getSaleCount(void); 26 | void setSaleCount(int c); 27 | std::string getManufacturer(); 28 | double getPrice(void); 29 | void setPrice(double p); 30 | double getCost(void); 31 | std::string getNo(void); 32 | std::string getName(void); 33 | std::string getBrand(void); 34 | std::string getClassStr(void);//获得商品类型 35 | void setName(std::string name); 36 | void setCost(int c); 37 | void setManufacturer(std::string m); 38 | void setAmount(int a); 39 | bool onSale(void); //判断是否在售 40 | void setOffSale(); //下架商品 41 | void setBrand(std::string b); 42 | virtual int getKind(void)=0; //返回种类 43 | virtual double getWeiOrCapa(void)=0;//获得重量或容量 44 | virtual void setWeiOrCapa(double wc)=0; 45 | virtual std::string getKindStr(void)=0; 46 | virtual void setKind(int k)=0; //重设商品类型 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /head/Cosmetic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Commodity.h" 3 | #include 4 | #include 5 | class Cosmetic : public Commodity 6 | { 7 | public: 8 | enum class CosmeticKind{ 9 | HAIRDRESS, CLEAR, CARE //美容,清洁,护肤 10 | }; 11 | protected: 12 | double _weight; 13 | CosmeticKind _kind; 14 | static long maxNo; 15 | static const std::array kindStrs; 16 | public: 17 | Cosmetic(); 18 | Cosmetic(std::string name, std::string brand, 19 | std::string manufacturer, double price, 20 | double cost, int amount, bool onSale, int saleCount, double weight, CosmeticKind kind); 21 | ~Cosmetic() = default; 22 | friend std::ifstream &operator>>(std::ifstream &ifs, Cosmetic &c); 23 | friend std::ofstream &operator<<(std::ofstream &ofs, Cosmetic &c); 24 | int getKind()override; 25 | double getWeiOrCapa() override; 26 | void setWeiOrCapa(double wc) override; 27 | std::string getKindStr(void) override; 28 | void setKind(int k) override; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /head/Daily.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Commodity.h" 3 | #include 4 | //日用品类 5 | class Daily : public Commodity 6 | { 7 | public: 8 | enum class DailyKind { 9 | BEDDING,KITCHENWARE,ELECTRIC,USUAL 10 | //床上用品 厨房用品 电器 常用品 11 | }; 12 | protected: 13 | double _weight; //重量 14 | DailyKind _kind; 15 | static long maxNo; 16 | static const std::array kindStrs; 17 | public: 18 | Daily(); 19 | Daily(std::string name, std::string brand, 20 | std::string manufactuer, double price, 21 | double cost, int amount, bool onSale, int saleCount,double weight ,DailyKind kind); 22 | friend std::ifstream& operator>>(std::ifstream& ifs, Daily& d); 23 | friend std::ofstream& operator<<(std::ofstream& ofs, Daily& d); 24 | ~Daily() = default; 25 | int getKind() override; 26 | double getWeiOrCapa() override; 27 | void setWeiOrCapa(double wc) override; 28 | std::string getKindStr(void) override; 29 | void setKind(int k) override; 30 | }; 31 | -------------------------------------------------------------------------------- /head/Food.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Commodity.h" 4 | #include 5 | 6 | class Food :public Commodity 7 | { 8 | public: 9 | enum class FoodKind 10 | { 11 | COOKED,UN_COOKED,PACKAGED //熟食,生食,袋装食品 12 | }; 13 | 14 | protected: 15 | double _weight; //重量 16 | FoodKind _kind; //食品类型 17 | static long maxNo;//当前的最大编号 18 | static const std::array kindStrs; 19 | public: 20 | Food(); 21 | Food(std::string name, std::string brand, 22 | std::string manufacturer, double price, 23 | double cost, int amount, bool onSale, int saleCount,double weight, FoodKind kind); 24 | friend std::ifstream& operator>>(std::ifstream& ifs, Food& f); 25 | friend std::ofstream& operator<<(std::ofstream& ofs, Food& f); 26 | ~Food() = default; 27 | int getKind() override; 28 | double getWeiOrCapa() override; 29 | void setWeiOrCapa(double wc) override; 30 | std::string getKindStr(void) override; 31 | void setKind(int k) override; 32 | }; 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /head/Manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include"commodities.h" 5 | #include"ui_mainwindow.h" 6 | using namespace std; 7 | 8 | class Manager 9 | { 10 | protected: 11 | using Commodities = vector; 12 | protected: 13 | static Commodities _repository; //当前库存 14 | static double _sumRevenue; //营业额 15 | static double _sumCost; //成本 16 | static double _useCount; //资源的使用计数 17 | public: 18 | Manager(); 19 | virtual ~Manager(); 20 | bool comExist(std::string name,std::string brand); //检验商品是否存在 21 | double getSumRevenue(); 22 | double getSumCost(); 23 | static void displayRepCom(Commodity* com, QTableWidget* bigTable); //大表格展示库存中的商品 24 | static void displaySaledCom(Commodity* saledCom,QTableWidget* samllTable,int amount); //小表格展示已经购买的商品 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /head/RepManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Manager.h" 3 | #include 4 | #include 5 | #include 6 | class RepManager :public Manager //库存管理类 7 | { 8 | protected: 9 | static map _noComMap; //编号到商品的单射 10 | public: 11 | RepManager() = default; 12 | ~RepManager() override = default; 13 | 14 | Commodity* searchNo(std::string no); //寻找给定编号的在售商品 基于map寻找 15 | Commodity* searchNoAll(std::string no); //寻找商品(包含不在售) 16 | std::list searchName(std::string name); //按照名称寻找所有符合的商品 17 | std::list searchBrand(std::string brand);//按照品牌寻找所有符合的商品 18 | std::list searchClass(char classCh); //按照类型搜索所有符合的商品 19 | bool addFood(std::string name, std::string brand, //新增食物商品 20 | std::string manufacturer, double price, 21 | double cost, int amount, double weight, 22 | Food::FoodKind kind); 23 | 24 | bool addCosmetic(std::string name, std::string brand, //新增化妆品 25 | std::string manufacturer, double price, 26 | double cost, int amount, double weight, Cosmetic::CosmeticKind kind); 27 | 28 | bool addBeverage(std::string name, std::string brand, //新增饮料 29 | std::string manufacturer, double price, 30 | double cost, int amount, int capacity, 31 | Beverage::BeverageKind kind); 32 | 33 | 34 | bool addDaily(std::string name, std::string brand, //新增日用品 35 | std::string manufacturer, double price, 36 | double cost, int amount, double weight, Daily::DailyKind kind); 37 | 38 | void setAmount(std::string no,int newAmount); //改变某商品的库存 39 | void setPricre(std::string no, int newPrice); //改变某商品的价格 40 | void deleteCommodity(std::string no); //删除库存中的某件商品 41 | void loadRepository(void); //读取库存商品 42 | void saveRepository(void); //保存商品到文件 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /head/Saler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Manager.h" 3 | #include 4 | #include 5 | #include"ui_mainwindow.h" 6 | 7 | class Saler : public Manager //销售管理类 8 | { 9 | protected: 10 | static vector_tradeComs; //交易商品记录 11 | static vector>_tradeAmount; //商品数量记录 12 | static vector>_tradePrices; //商品成交价格记录 13 | static vector _tradeIncome; //交易额记录 14 | static vector _tradeId; //交易号 15 | 16 | static long long _maxId; //当前的最大交易号 17 | 18 | Commodities _coms; //购买的商品 19 | vector _amount;//当前对应商品的数量 20 | vector _price;//当前对应商品的价格 21 | double _income; //当前交易金额 22 | 23 | public: 24 | Saler(); 25 | tuple endBuy(); //结束购买 26 | void buy(Commodity* com, int amount = 1); 27 | double locIncome(); //当前交易金额 28 | void saveTradeRecord(void); //保存交易记录 29 | void loadTradeRecord(void); //读取交易记录 30 | void clearRecord(); //清空所有交易记录 31 | int getPosition(std::string trid); //获取对应订单号的下标 32 | void reSetTrRecord(const std::string& trid, Commodity* com = nullptr, int newAmount = 0); //重设某商品的数量 默认全部退 和某商品全部退 33 | void showRecord(std::string trid,QTableWidget* table);//显示特定订单号的商品 34 | double getTradeIncome(const std::string& trid); 35 | QStringList getNoList(const string& trid); //返回所有订单号的字符串 36 | std::string getLastTrid(const string& trid); //获取上一个订单号 37 | std::string getNextTrid(const string& trid);//获取下一个订单号 38 | std::string getFirstId(void); //获得第一个id 39 | }; 40 | 41 | 42 | -------------------------------------------------------------------------------- /head/Sorter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Manager.h" 3 | #include"ui_mainwindow.h" 4 | class Sorter :public Manager 5 | { 6 | public: 7 | Sorter() = default; 8 | ~Sorter() = default; 9 | enum class SortKey 10 | { 11 | PRICE_UP, PRICE_DOWN, 12 | AMOUNT_UP, AMOUNT_DOWN, 13 | NAME_UP, NAME_DOWN, 14 | SALE_CNT_UP,SALE_CNT_DOWN 15 | }; 16 | void operator()(SortKey key,QTableWidget* comTab); //排序并显示 17 | protected: 18 | Commodities _onSalecoms; //当前在售的商品(未被删除的) 19 | void copyComs(); //拷贝一份商品数据 20 | void _sort(SortKey key); //按照指定的规则排序 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /head/commodities.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include"Food.h" 4 | #include"Cosmetic.h" 5 | #include "Daily.h" 6 | #include "Beverage.h" 7 | constexpr auto u = 1; 8 | -------------------------------------------------------------------------------- /head/doc/面向对象课程设计报告刘家麒.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/head/doc/面向对象课程设计报告刘家麒.pdf -------------------------------------------------------------------------------- /head/doc/面向对象课设答辩.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/head/doc/面向对象课设答辩.pptx -------------------------------------------------------------------------------- /inputwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "inputwidget.h" 2 | #include "ui_inputwidget.h" 3 | #include 4 | InputWidget::InputWidget(char classCh,QWidget *parent,Commodity* com) : 5 | QWidget(parent), 6 | ui(new Ui::InputWidget),rm(),_classCh(classCh),_com(com) 7 | { 8 | ui->setupUi(this); 9 | QStringList kList ; 10 | switch(_classCh) 11 | { 12 | case'F': 13 | kList = {tr("熟食"), tr("生食"),tr("袋装食品")}; 14 | break; 15 | case'C': 16 | kList={tr("美容"),tr("清洁"),tr("护肤")}; 17 | break; 18 | case 'B': 19 | kList={tr("普通饮料"),tr("酒"),tr("碳酸饮料")}; 20 | ui->weiOrCapaLab->setText(tr("商品容量")); 21 | break; 22 | case 'D': 23 | kList={tr("床上用品"),tr("厨房用品"),tr("电器"),tr("常用品")}; 24 | } 25 | ui->kindBox->clear(); 26 | ui->kindBox->addItems(kList); //设置下拉选择框内容 27 | if(com) 28 | { 29 | ui->kindBox->setCurrentIndex(com->getKind()); 30 | ui->nameEdit->setText(tr(com->getName().c_str())); 31 | ui->brandEdit->setText(tr(com->getBrand().c_str())); 32 | ui->manuEdit->setText(tr(com->getManufacturer().c_str())); 33 | ui->priceBox->setValue(com->getPrice()); 34 | ui->costBox->setValue(com->getCost()); 35 | ui->weightOrCapaBox->setValue((com->getWeiOrCapa())); 36 | ui->amountBox->setValue(com->getAmount()); 37 | } 38 | } 39 | 40 | InputWidget::~InputWidget() 41 | { 42 | delete ui; 43 | } 44 | 45 | 46 | void InputWidget::on_okBtn_released() //录入信息 47 | { 48 | int kind = ui->kindBox->currentIndex(); 49 | auto name = ui->nameEdit->text().toStdString(); 50 | auto brand = ui->brandEdit->text().toStdString(); 51 | auto manufacturer=ui->manuEdit->text().toStdString(); 52 | double price = ui->priceBox->value(); 53 | double cost = ui->costBox->value(); 54 | double weiOrCapa=ui->weightOrCapaBox->value(); 55 | int amount = ui->amountBox->value(); 56 | if(brand==""||manufacturer==""||brand==""||cost<=0|| 57 | price<=0||weiOrCapa<=0||amount<=0) 58 | { 59 | QMessageBox::critical(this,tr("错误"),tr("输入信息有误,请重新输入!")); 60 | return ; 61 | } 62 | if(_com) //修改 63 | { 64 | std::string no = _com->getNo(); 65 | rm.setPricre(no,price); 66 | rm.setAmount(no,amount); 67 | _com->setName(name); 68 | _com->setCost(cost); 69 | _com->setManufacturer(manufacturer); 70 | _com->setBrand(brand); 71 | _com->setWeiOrCapa(weiOrCapa); 72 | _com->setKind(kind); 73 | } 74 | else //新增 75 | { 76 | if(rm.comExist(name,brand)) //查重 品牌+商品名 相同为重复 77 | { 78 | QMessageBox::information(this,tr("提示"),tr("该商品已存在!")); 79 | this->close(); 80 | return; 81 | } 82 | switch (_classCh) 83 | { 84 | 85 | case 'F': //food 86 | 87 | rm.addFood(std::move(name),std::move(brand),std::move(manufacturer), 88 | price,cost,amount,weiOrCapa,(Food::FoodKind)kind); 89 | break; 90 | case 'C': 91 | 92 | rm.addCosmetic(std::move(name),std::move(brand),std::move(manufacturer), 93 | price,cost,amount,weiOrCapa,(Cosmetic::CosmeticKind)kind); 94 | break; 95 | case 'B': 96 | rm.addBeverage(std::move(name),std::move(brand),std::move(manufacturer), 97 | price,cost,amount,weiOrCapa,(Beverage::BeverageKind)kind); 98 | break; 99 | case 'D': 100 | rm.addDaily(std::move(name),std::move(brand),std::move(manufacturer), 101 | price,cost,amount,weiOrCapa,(Daily::DailyKind)kind); 102 | break; 103 | } 104 | } 105 | QMessageBox::information(this,tr("提示"),tr("成功!")); 106 | this->close(); 107 | } 108 | 109 | 110 | void InputWidget::on_cancelBtn_released() 111 | { 112 | this->close(); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /inputwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef INPUTWIDGET_H 2 | #define INPUTWIDGET_H 3 | 4 | #include 5 | #include"head/RepManager.h" 6 | 7 | namespace Ui { 8 | class InputWidget; 9 | } 10 | 11 | class InputWidget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit InputWidget(char claasCh,QWidget *parent = nullptr,Commodity* com=nullptr); 17 | ~InputWidget(); 18 | 19 | private slots: 20 | 21 | void on_okBtn_released(); 22 | void on_cancelBtn_released(); 23 | 24 | private: 25 | Ui::InputWidget *ui; 26 | RepManager rm; 27 | char _classCh; 28 | Commodity* _com; 29 | }; 30 | 31 | #endif // INPUTWIDGET_H 32 | -------------------------------------------------------------------------------- /inputwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InputWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 659 10 | 410 11 | 12 | 13 | 14 | 15 | 659 16 | 410 17 | 18 | 19 | 20 | 21 | 659 22 | 410 23 | 24 | 25 | 26 | 输入商品信息 27 | 28 | 29 | .InputWidget 30 | { 31 | background-color:rgb(38,38,38); 32 | } 33 | 34 | 35 | 36 | 37 | QAbstractSpinBox 38 | { 39 | font: 14pt "楷体"; 40 | } 41 | 42 | QLineEdit 43 | { 44 | font: 14pt "楷体"; 45 | } 46 | 47 | QComboBox 48 | { 49 | font: 14pt "楷体"; 50 | } 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 9 59 | 47 60 | 80 61 | 19 62 | 63 | 64 | 65 | color: rgb(255, 255, 255); 66 | font: 14pt "楷体"; 67 | 68 | 69 | 商品名称 70 | 71 | 72 | 73 | 74 | 75 | 9 76 | 119 77 | 80 78 | 19 79 | 80 | 81 | 82 | color: rgb(255, 255, 255); 83 | font: 14pt "楷体"; 84 | 85 | 86 | 商品品牌 87 | 88 | 89 | 90 | 91 | 92 | 95 93 | 119 94 | 176 95 | 27 96 | 97 | 98 | 99 | 100 | 101 | 102 | 95 103 | 47 104 | 176 105 | 27 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 9 116 | 191 117 | 80 118 | 19 119 | 120 | 121 | 122 | color: rgb(255, 255, 255); 123 | font: 14pt "楷体"; 124 | 125 | 126 | 商品厂家 127 | 128 | 129 | 130 | 131 | 132 | 95 133 | 191 134 | 176 135 | 27 136 | 137 | 138 | 139 | 140 | 141 | 142 | 420 143 | 60 144 | 80 145 | 19 146 | 147 | 148 | 149 | color: rgb(255, 255, 255); 150 | font: 14pt "楷体"; 151 | 152 | 153 | 商品价格 154 | 155 | 156 | 157 | 158 | 159 | 526 160 | 47 161 | 124 162 | 27 163 | 164 | 165 | 166 | 0.010000000000000 167 | 168 | 169 | 999999.000000000000000 170 | 171 | 172 | 173 | 174 | 175 | 420 176 | 130 177 | 80 178 | 19 179 | 180 | 181 | 182 | color: rgb(255, 255, 255); 183 | font: 14pt "楷体"; 184 | 185 | 186 | 商品成本 187 | 188 | 189 | 190 | 191 | 192 | 526 193 | 119 194 | 124 195 | 27 196 | 197 | 198 | 199 | 0.010000000000000 200 | 201 | 202 | 999999.000000000000000 203 | 204 | 205 | 1.000000000000000 206 | 207 | 208 | 1.000000000000000 209 | 210 | 211 | 212 | 213 | 214 | 420 215 | 200 216 | 80 217 | 19 218 | 219 | 220 | 221 | color: rgb(255, 255, 255); 222 | font: 14pt "楷体"; 223 | 224 | 225 | 商品重量 226 | 227 | 228 | 229 | 230 | 231 | 526 232 | 191 233 | 124 234 | 27 235 | 236 | 237 | 238 | 2 239 | 240 | 241 | 0.010000000000000 242 | 243 | 244 | 999999.000000000000000 245 | 246 | 247 | 1.000000000000000 248 | 249 | 250 | 1.000000000000000 251 | 252 | 253 | 254 | 255 | 256 | 526 257 | 263 258 | 121 259 | 27 260 | 261 | 262 | 263 | 1 264 | 265 | 266 | 999999 267 | 268 | 269 | 270 | 271 | 272 | 420 273 | 270 274 | 80 275 | 19 276 | 277 | 278 | 279 | color: rgb(255, 255, 255); 280 | font: 14pt "楷体"; 281 | 282 | 283 | 库存数量 284 | 285 | 286 | 287 | 288 | 289 | 9 290 | 263 291 | 80 292 | 19 293 | 294 | 295 | 296 | color: rgb(255, 255, 255); 297 | font: 14pt "楷体"; 298 | 299 | 300 | 商品分类 301 | 302 | 303 | 304 | 305 | 306 | 95 307 | 263 308 | 161 309 | 27 310 | 311 | 312 | 313 | 314 | 315 | 316 | 140 317 | 340 318 | 111 319 | 25 320 | 321 | 322 | 323 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 324 | font: 9pt "楷体"; 325 | font-size:25px; 326 | color: rgb(255, 255, 255); 327 | border:none; 328 | border-radius:8px 329 | 330 | 331 | 确定 332 | 333 | 334 | 335 | 336 | 337 | 390 338 | 340 339 | 115 340 | 25 341 | 342 | 343 | 344 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 345 | font: 9pt "楷体"; 346 | font-size:25px; 347 | color: rgb(255, 255, 255); 348 | border:none; 349 | border-radius:8px 350 | 351 | 352 | 取消 353 | 354 | 355 | 356 | 357 | 358 | 359 | -------------------------------------------------------------------------------- /logindia.cpp: -------------------------------------------------------------------------------- 1 | #include "logindia.h" 2 | #include "ui_logindia.h" 3 | #include 4 | #include 5 | #include 6 | 7 | LoginDia::LoginDia(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::LoginDia) 10 | { 11 | _canLog=false; 12 | ui->setupUi(this); 13 | this->setWindowIcon(QIcon(":/new/prefix1/rc/n133f35jvek.jpg")); 14 | QImage* keyImg=new QImage(":/new/prefix1/rc/key.png"); 15 | ui->imgLab->setScaledContents(true); 16 | ui->imgLab->setPixmap(QPixmap::fromImage(*keyImg)); 17 | std::ifstream ifs("passWord.pwd"); 18 | if(ifs.is_open()) 19 | { 20 | std::string buff; 21 | ifs>>buff; 22 | _passWord = buff.c_str(); 23 | ifs.close(); 24 | } 25 | else //不存在密码文件 26 | { 27 | 28 | bool ok=false; 29 | _passWord = QInputDialog::getText(this,"设置密码","请输入新密码:",QLineEdit::Password,"",&ok); 30 | if(!ok) 31 | { 32 | this->close(); 33 | } 34 | std::ofstream ofs("passWord.pwd"); 35 | ofs<<_passWord.toStdString(); 36 | ofs.close(); 37 | } 38 | 39 | } 40 | 41 | LoginDia::~LoginDia() 42 | { 43 | delete ui; 44 | std::ofstream ofs("password.pwd"); 45 | ofs<<_passWord.toStdString(); 46 | } 47 | 48 | bool LoginDia::canLog() 49 | { 50 | return _canLog; 51 | } 52 | 53 | void LoginDia::on_okBtn_released() //确定密码 54 | { 55 | if(ui->pwdEdit->text() ==_passWord&&ui->accountEdit->text()==QString("admin")) 56 | { 57 | _canLog=true; 58 | this->close(); 59 | } 60 | 61 | else 62 | { 63 | QMessageBox::critical(this,tr("错误"),tr("密码错误,请重新输入")); 64 | } 65 | 66 | } 67 | 68 | 69 | void LoginDia::on_cancelBtn_released() //关闭窗口 70 | { 71 | this->close(); 72 | } 73 | 74 | 75 | void LoginDia::on_chPwdEdit_released() //改密码 76 | { 77 | bool ok; 78 | auto oriPwd = QInputDialog::getText(this,"输入","请输入旧密码:", 79 | QLineEdit::Password,"",&ok); 80 | if(ok) 81 | { 82 | if(oriPwd==_passWord) 83 | { 84 | auto newPwd = QInputDialog::getText(this,"输入","请输入新密码:",QLineEdit::Password,"",&ok); 85 | if(ok) 86 | { 87 | _passWord = newPwd; 88 | QMessageBox::information(this,tr("提示"),tr("修改成功!")); 89 | } 90 | } 91 | else 92 | { 93 | QMessageBox::critical(this,tr("错误"),tr("原密码错误")); 94 | } 95 | } 96 | } 97 | 98 | 99 | void LoginDia::on_aboutBtn_released() 100 | { 101 | QMessageBox::about(this,tr("关于系统"),tr("制作者:刘家麒 赵鹿均\n\n系统版本:V1.0\n\nQt版本:Qt 6.4.1")); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /logindia.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINDIA_H 2 | #define LOGINDIA_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class LoginDia; 8 | } 9 | 10 | class LoginDia : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit LoginDia(QWidget *parent = nullptr); 16 | ~LoginDia(); 17 | bool canLog(); 18 | private slots: 19 | 20 | 21 | void on_okBtn_released(); 22 | 23 | void on_cancelBtn_released(); 24 | 25 | void on_chPwdEdit_released(); 26 | 27 | void on_aboutBtn_released(); 28 | 29 | private: 30 | Ui::LoginDia *ui; 31 | QString _passWord; 32 | bool _canLog; 33 | }; 34 | 35 | #endif // LOGINDIA_H 36 | -------------------------------------------------------------------------------- /logindia.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginDia 4 | 5 | 6 | 7 | 0 8 | 0 9 | 692 10 | 409 11 | 12 | 13 | 14 | 15 | 692 16 | 409 17 | 18 | 19 | 20 | 21 | 692 22 | 409 23 | 24 | 25 | 26 | 登录 27 | 28 | 29 | color: rgb(255,255,255); 30 | background-color: rgb(38, 38, 38); 31 | 32 | 33 | 34 | 35 | 140 36 | 280 37 | 151 38 | 41 39 | 40 | 41 | 42 | background-color: rgb(17, 145, 255); 43 | color: rgb(255, 255, 255); 44 | font: 9pt "楷体"; 45 | font-size:25px; 46 | 47 | border:none; 48 | border-radius:8px 49 | 50 | 51 | 确定 52 | 53 | 54 | 55 | 56 | 57 | 360 58 | 280 59 | 151 60 | 41 61 | 62 | 63 | 64 | background-color: rgb(17, 145, 255); 65 | color: rgb(255, 255, 255); 66 | background-color: rgb(17, 145, 255); 67 | color: rgb(255, 255, 255); 68 | font: 9pt "楷体"; 69 | font-size:25px; 70 | 71 | border:none; 72 | border-radius:8px 73 | 74 | 75 | 取消 76 | 77 | 78 | 79 | 80 | 81 | 340 82 | 100 83 | 221 84 | 51 85 | 86 | 87 | 88 | color: rgb(255, 255, 255); 89 | font: 16pt "Microsoft YaHei UI"; 90 | 91 | 92 | 93 | 94 | 95 | 340 96 | 200 97 | 221 98 | 51 99 | 100 | 101 | 102 | color: rgb(255, 255, 255); 103 | font: 16pt "Microsoft YaHei UI"; 104 | 105 | 106 | QLineEdit::Password 107 | 108 | 109 | 110 | 111 | 112 | 220 113 | 110 114 | 81 115 | 41 116 | 117 | 118 | 119 | font: 22pt "楷体"; 120 | color: rgb(255,255,255); 121 | 122 | 123 | 124 | 账号: 125 | 126 | 127 | 128 | 129 | 130 | 220 131 | 200 132 | 81 133 | 41 134 | 135 | 136 | 137 | font: 22pt "楷体"; 138 | color: rgb(255, 255, 255); 139 | 140 | 141 | 142 | 密码: 143 | 144 | 145 | 146 | 147 | 148 | 140 149 | 350 150 | 151 151 | 41 152 | 153 | 154 | 155 | 156 | background-color: rgb(17, 145, 255); 157 | color: rgb(255, 255, 255); 158 | font: 9pt "楷体"; 159 | font-size:25px; 160 | 161 | border:none; 162 | border-radius:8px 163 | 164 | 165 | 修改密码 166 | 167 | 168 | 169 | 170 | 171 | 200 172 | 10 173 | 301 174 | 61 175 | 176 | 177 | 178 | font: 25pt "楷体"; 179 | color: rgb(255,255, 255); 180 | 181 | 182 | 183 | 超市商品管理系统 184 | 185 | 186 | 187 | 188 | 189 | 80 190 | 130 191 | 90 192 | 90 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 360 203 | 350 204 | 151 205 | 41 206 | 207 | 208 | 209 | 210 | background-color: rgb(17, 145, 255); 211 | color: rgb(255, 255, 255); 212 | font: 9pt "楷体"; 213 | font-size:25px; 214 | 215 | border:none; 216 | border-radius:8px 217 | 218 | 219 | 关于系统 220 | 221 | 222 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/logo.ico -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include"logindia.h" 3 | #include 4 | 5 | //#define IS_DEBUG 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication a(argc, argv); 10 | MainWindow w; 11 | #ifndef IS_DEBUG 12 | LoginDia logDia; 13 | logDia.exec(); 14 | if(!logDia.canLog()) 15 | { 16 | return 0; 17 | } 18 | 19 | #endif 20 | w.show(); 21 | return a.exec(); 22 | } 23 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include"inputwidget.h" 10 | #include 11 | #include 12 | #include 13 | 14 | MainWindow::MainWindow(QWidget *parent) 15 | : QMainWindow(parent) 16 | , ui(new Ui::MainWindow),rm(),saler() 17 | { 18 | rm.loadRepository(); 19 | saler.loadTradeRecord(); 20 | 21 | ui->setupUi(this); 22 | 23 | //设置图标 24 | this->setWindowIcon(QIcon(":/new/prefix1/rc/n133f35jvek.jpg")); 25 | 26 | auto setImg = [](QString imgStr,QLabel *& label) //设置图片 27 | { 28 | QImage* img=new QImage(imgStr); 29 | label->setScaledContents(true); //完整显示 30 | label->setPixmap(QPixmap::fromImage(*img)); 31 | 32 | }; 33 | auto setGif= [](QString gifStr,QLabel *&label,MainWindow *parent,QSize size) 34 | { 35 | QMovie *gif = new QMovie(gifStr); 36 | gif->setParent(parent); 37 | gif->setScaledSize(size); 38 | label->setMovie(gif); 39 | gif->start(); 40 | }; 41 | setImg(":/new/prefix1/rc/money.png",ui->moneyImgLab); 42 | setImg(":/new/prefix1/rc/buyCar.png",ui->buyCarLab); 43 | setGif(":/new/prefix1/rc/9954a5f7dfd64e7bafc23eda4e8b9487.gif",ui->gifLab,this,QSize(311,121)); 44 | setGif(":/new/prefix1/rc/show.gif",ui->gifShowLab,this,QSize(171,171)); 45 | setGif(":/new/prefix1/rc/manage.gif",ui->gifManLab,this,QSize(151,151)); 46 | //设置定时器 47 | ui->timeLcd->setSegmentStyle(QLCDNumber::Filled); 48 | ui->timeLcd->setDigitCount(20); //数字位数 49 | QTimer* timer = new QTimer(this); 50 | timer->start(1000); 51 | connect(timer,&QTimer::timeout,[&]() 52 | { 53 | ui->timeLcd->display(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); 54 | }); 55 | 56 | //背景透明 设置字体色 57 | ui->timeLcd->setStyleSheet("background:transparent;color:#00ccff;"); 58 | ui->totalMoneyLcd->setStyleSheet("background:transparent;color:#00ccff;"); 59 | ui->totalLcd->setStyleSheet("background:transparent;color:#00ccff;"); 60 | ui->sumCostLcd->setStyleSheet("background:transparent;color:#00ccff;"); 61 | ui->sumRevenLcd->setStyleSheet("background:transparent;color:#00ccff;"); 62 | //表格禁止编辑 63 | ui->saledComsTab->setEditTriggers(QAbstractItemView::NoEditTriggers); 64 | ui->comsTab->setEditTriggers(QAbstractItemView::NoEditTriggers); 65 | ui->comTabRec->setEditTriggers(QAbstractItemView::NoEditTriggers); 66 | ui->comsManTab->setEditTriggers(QAbstractItemView::NoEditTriggers); 67 | 68 | //表头大小自适应 69 | ui->comTabRec->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 70 | ui->saledComsTab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 71 | ui->comsTab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 72 | ui->comsManTab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); 73 | } 74 | 75 | MainWindow::~MainWindow() 76 | { 77 | rm.saveRepository(); 78 | saler.saveTradeRecord(); 79 | delete ui; 80 | } 81 | 82 | 83 | 84 | 85 | 86 | void MainWindow::on_endBuyBtn_released() //结算 87 | { 88 | if(ui->saledComsTab->rowCount()==0) 89 | { 90 | QMessageBox::critical(this,tr("错误"),tr("还没有商品!")); 91 | return ; 92 | } 93 | auto [trid,money] = saler.endBuy(); 94 | QMessageBox::information(this,tr("结算"), 95 | QString("订单号:%1\n\n总金额:%2").arg(trid.c_str()).arg(money)); 96 | ui->countBox->setValue(1); 97 | ui->totalLcd->display(0); 98 | ui->saledComsTab->clearContents(); 99 | while(ui->saledComsTab->rowCount()>=1) 100 | { 101 | ui->saledComsTab->removeRow(ui->saledComsTab->rowCount()-1); 102 | } 103 | } 104 | 105 | 106 | 107 | void MainWindow::on_sureAddBtn_released() //购买商品 108 | { 109 | try 110 | { 111 | auto qNo = ui->noEdit->text(); 112 | int amount = ui->countBox->value(); 113 | auto com = rm.searchNo(qNo.toStdString()); 114 | saler.buy(com,amount); 115 | ui->totalLcd->display(saler.locIncome()); 116 | Manager::displaySaledCom(com,ui->saledComsTab,amount); 117 | } 118 | catch(runtime_error& re) 119 | { 120 | QMessageBox::critical(this,tr("错误"),re.what()); 121 | } 122 | } 123 | 124 | 125 | void MainWindow::on_displayBtn_released() //排序 126 | { 127 | Sorter sorter; 128 | int toKey[]={0,2,4,6}; 129 | int selKey = ui->sortKeyBox->currentIndex(); //排序项 130 | int selDir = ui->sortdirBox->currentIndex(); //升降序 131 | selDir==1?toKey[selKey]++:0; 132 | sorter((Sorter::SortKey)toKey[selKey],ui->comsTab); 133 | } 134 | 135 | 136 | void MainWindow::on_searchBtn_released() //查找交易记录 137 | { 138 | ui->sumRevenLcd->display(rm.getSumRevenue()); 139 | ui->sumCostLcd->display(rm.getSumCost()); 140 | auto trid = ui->trIdEdit->text().toStdString(); 141 | try 142 | { 143 | if(trid=="") 144 | { 145 | trid=saler.getFirstId(); 146 | ui->trIdEdit->setText(trid.c_str()); 147 | } 148 | saler.showRecord(trid,ui->comTabRec); 149 | ui->totalMoneyLcd->display(saler.getTradeIncome(trid)); 150 | } 151 | catch(std::exception &e) 152 | { 153 | QMessageBox::critical(this,tr("错误"),QString(e.what())); 154 | } 155 | } 156 | 157 | 158 | void MainWindow::on_changeBtn_released() //修改购买商品的数量 159 | { 160 | auto trid = ui->trIdEdit->text().toStdString(); 161 | try //检查交易号合法性 162 | { 163 | saler.getPosition(trid); 164 | } 165 | catch(std::exception& e) 166 | { 167 | QMessageBox::critical(this,tr("错误"),QString(e.what())); 168 | return; 169 | } 170 | ui->searchBtn->released(); //先查询再修改 171 | QStringList noList = saler.getNoList(trid); 172 | QString no = QInputDialog::getItem(this,tr("输入"),tr("选择商品"),noList); 173 | auto com = rm.searchNo(no.toStdString()); 174 | bool ok; //是否点击确认 175 | int newAmount = QInputDialog::getInt(this,tr("输入"),tr("输入新购买数量") ,0,0,com->getAmount(),1,&ok); 176 | if(ok) 177 | { 178 | saler.reSetTrRecord(trid,com,newAmount); 179 | QMessageBox::information(this,tr("提示"),tr("商品数量修改成功")); 180 | ui->searchBtn->released(); 181 | } 182 | } 183 | 184 | 185 | 186 | void MainWindow::on_returnBtn_2_released() //退货 187 | { 188 | auto trid = ui->trIdEdit->text().toStdString(); 189 | try //检查交易号合法性 190 | { 191 | saler.getPosition(trid); 192 | } 193 | catch(std::exception& e) 194 | { 195 | QMessageBox::critical(this,tr("错误"),QString(e.what())); 196 | return; 197 | } 198 | ui->searchBtn->released(); //先查询再退货 199 | saler.reSetTrRecord(trid); 200 | QMessageBox::information(this,tr("提示"),tr("退货成功")); 201 | } 202 | 203 | 204 | void MainWindow::on_startSeachBtn_released() //查询商品 205 | { 206 | int searchKey = ui->searchKeyBox->currentIndex(); 207 | QString qKey; 208 | int index; 209 | char keyCh[4] = {'F','C','B','D'}; 210 | if(searchKey==3) 211 | { 212 | QStringList kindList={"食品","化妆品","饮料","日用品"}; 213 | qKey = QInputDialog::getItem(this,tr("选择"),tr("选择商品类型"), kindList); 214 | index=kindList.indexOf(qKey); 215 | } 216 | else if(searchKey!=4) 217 | { 218 | bool ok; 219 | qKey = QInputDialog::getText(this,tr("输入"),QString("输入%1").arg(ui->searchKeyBox->currentText()) 220 | ,QLineEdit::Normal,"",&ok); //格式化字符串 221 | if(!ok) return; 222 | } 223 | std::string key = qKey.toStdString(); 224 | 225 | std::list res; 226 | 227 | if(searchKey==0) //商品号搜索 228 | { 229 | try 230 | { 231 | res.push_back(rm.searchNo(key)); //唯一结果 232 | } 233 | catch(runtime_error& re) 234 | { 235 | QMessageBox::critical(this,tr("错误"),tr(re.what())); 236 | return; 237 | } 238 | } 239 | else if(searchKey==1) //商品名搜索 240 | { 241 | res=std::move(rm.searchName(key)); 242 | } 243 | else if(searchKey==2) //品牌搜索 244 | { 245 | res=std::move(rm.searchBrand(key)); 246 | } 247 | else if(searchKey==3) //商品类型搜索 248 | { 249 | res=std::move(rm.searchClass(keyCh[index])); 250 | } 251 | if(searchKey==4)//默认全查询 252 | { 253 | res=std::move(rm.searchName("")); 254 | } 255 | while(ui->comsManTab->rowCount()>=1) //清除原有数据 256 | { 257 | ui->comsManTab->removeRow(ui->comsManTab->rowCount()-1); 258 | } 259 | for(auto& com:res) 260 | { 261 | Manager::displayRepCom(com,ui->comsManTab); 262 | } 263 | } 264 | 265 | 266 | 267 | void MainWindow::on_comsManTab_itemDoubleClicked(QTableWidgetItem *item) //修改商品 268 | { 269 | if(item->column()==0) 270 | { 271 | std::string no = item->text().toStdString(); 272 | Commodity* com=rm.searchNo(no); //要修改的商品 273 | InputWidget* iWid=new InputWidget(no[0],this,com); //用于输入的子窗口 274 | iWid->setWindowFlags(iWid->windowFlags() |Qt::Dialog); 275 | iWid->setWindowModality(Qt::ApplicationModal); //阻塞除当前窗体之外的所有的窗体 276 | iWid->show(); 277 | } 278 | else //展示详细信息 279 | { 280 | QMessageBox::information(this,tr("信息"),item->text()); 281 | } 282 | } 283 | 284 | void MainWindow::on_addBtn_released() //新增商品 285 | { 286 | QStringList classList={"食品","化妆品","饮料","日用品"}; 287 | bool ok=false; 288 | QString qKey = QInputDialog::getItem(this,tr("选择"),tr("选择商品类型"), classList,0,true,&ok); 289 | if(ok) 290 | { 291 | int index=classList.indexOf(qKey); 292 | char keyCh[4] = {'F','C','B','D'}; 293 | InputWidget* iWid = new InputWidget(keyCh[index],this); //新增商品 294 | iWid->setWindowFlags(iWid->windowFlags() |Qt::Dialog); 295 | iWid->setWindowModality(Qt::ApplicationModal); //阻塞除当前窗体之外的所有的窗体 296 | iWid->show(); 297 | } 298 | } 299 | 300 | 301 | void MainWindow::on_comsTab_itemDoubleClicked(QTableWidgetItem *item) 302 | { 303 | QMessageBox::information(this,tr("信息"),item->text()); 304 | } 305 | 306 | 307 | void MainWindow::on_deleteBtn_released() //商品删除 308 | { 309 | bool ok; 310 | auto no = QInputDialog::getText(this,tr("删除商品"),tr("输入商品号"),QLineEdit::Normal,"",&ok).toStdString(); 311 | if(ok) 312 | { 313 | try 314 | { 315 | rm.deleteCommodity(no); 316 | } 317 | catch(std::exception& e) 318 | { 319 | QMessageBox::critical(this,tr("错误"),e.what()); 320 | return; 321 | } 322 | QMessageBox::information(this,tr("提示"),tr("删除成功!")); 323 | ui->searchKeyBox->setCurrentIndex(4); 324 | ui->startSeachBtn->released(); //更新表单 325 | } 326 | 327 | } 328 | 329 | 330 | void MainWindow::on_lastBtn_released() //查看上一条记录 331 | { 332 | auto trid = ui->trIdEdit->text().toStdString(); 333 | try 334 | { 335 | auto lastTrid = saler.getLastTrid(trid); //找到上一条 336 | ui->trIdEdit->setText(tr(lastTrid.c_str())); //更新输入框 337 | saler.showRecord(lastTrid,ui->comTabRec); //更新表格 338 | ui->totalMoneyLcd->display(saler.getTradeIncome(lastTrid));//更新总金额 339 | } 340 | catch(std::exception &e) 341 | { 342 | QMessageBox::critical(this,tr("错误"),tr(e.what())); 343 | } 344 | } 345 | 346 | 347 | void MainWindow::on_nextBtn_released() //查看下一条记录 348 | { 349 | auto trid = ui->trIdEdit->text().toStdString(); 350 | try 351 | { 352 | auto nextTrid = saler.getNextTrid(trid); 353 | ui->trIdEdit->setText(tr(nextTrid.c_str())); 354 | saler.showRecord(nextTrid,ui->comTabRec); 355 | ui->totalMoneyLcd->display(saler.getTradeIncome(nextTrid)); 356 | } 357 | catch(std::exception &e) 358 | { 359 | QMessageBox::critical(this,tr("错误"),tr(e.what())); 360 | } 361 | } 362 | 363 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | #include"head/RepManager.h" 7 | #include"head/Saler.h" 8 | #include"head/Sorter.h" 9 | 10 | QT_BEGIN_NAMESPACE 11 | namespace Ui { class MainWindow; } 12 | QT_END_NAMESPACE 13 | 14 | class MainWindow : public QMainWindow 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | MainWindow(QWidget *parent = nullptr); 20 | ~MainWindow(); 21 | 22 | private slots: 23 | void on_buyBtn_released(); 24 | 25 | void on_endBuyBtn_released(); 26 | 27 | void on_sureAddBtn_released(); 28 | 29 | void on_backBtn_released(); 30 | 31 | void on_exitBtn_released(); 32 | 33 | void on_showBtn_released(); 34 | 35 | void on_backBtn_2_released(); 36 | 37 | void on_displayBtn_released(); 38 | 39 | void on_saleStatBtn_released(); 40 | 41 | void on_backBtn_3_released(); 42 | 43 | void on_searchBtn_released(); 44 | 45 | void on_changeBtn_released(); 46 | 47 | void on_returnBtn_2_released(); 48 | 49 | void on_addBtn_released(); 50 | 51 | 52 | void on_backBtn_5_released(); 53 | 54 | void on_comManagerBtn_released(); 55 | 56 | void on_startSeachBtn_released(); 57 | 58 | void on_comsManTab_itemDoubleClicked(QTableWidgetItem *item); 59 | 60 | void on_comsTab_itemDoubleClicked(QTableWidgetItem *item); 61 | 62 | void on_deleteBtn_released(); 63 | 64 | void on_lastBtn_released(); 65 | 66 | void on_nextBtn_released(); 67 | 68 | private: 69 | Ui::MainWindow *ui; 70 | RepManager rm; 71 | Saler saler; 72 | }; 73 | #endif // MAINWINDOW_H 74 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1167 10 | 688 11 | 12 | 13 | 14 | 15 | 1167 16 | 688 17 | 18 | 19 | 20 | 21 | 1167 22 | 688 23 | 24 | 25 | 26 | 超市商品管理系统 27 | 28 | 29 | 30 | 31 | 32 | 33 | background-color: rgb(38, 38, 38); 34 | 35 | 36 | 37 | 38 | 39 | 40 | true 41 | 42 | 43 | QStackedWidget 44 | { 45 | background-color: rgb(38, 38, 38); 46 | 47 | border:None; 48 | margin:0 0 0 0; 49 | } 50 | 51 | QLabel 52 | { 53 | color: rgb(255, 255, 255); 54 | } 55 | 56 | QInputDialog 57 | { 58 | color:white; 59 | } 60 | 61 | 62 | 63 | 64 | 0 65 | 66 | 67 | 68 | 69 | 70 | 360 71 | 20 72 | 411 73 | 91 74 | 75 | 76 | 77 | font: 36pt "楷体"; 78 | 79 | 80 | 超市商品管理系统 81 | 82 | 83 | 84 | 85 | 86 | 100 87 | 180 88 | 191 89 | 51 90 | 91 | 92 | 93 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 94 | font: 9pt "楷体"; 95 | font-size:25px; 96 | color: rgb(255, 255, 255); 97 | border:none; 98 | border-radius:8px 99 | 100 | 101 | 新增商品 102 | 103 | 104 | 105 | 106 | 107 | 430 108 | 180 109 | 191 110 | 51 111 | 112 | 113 | 114 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 115 | font: 9pt "楷体"; 116 | font-size:25px; 117 | color: rgb(255, 255, 255); 118 | border:none; 119 | border-radius:8px 120 | 121 | 122 | 123 | 显示所有商品 124 | 125 | 126 | 127 | 128 | 129 | 780 130 | 180 131 | 191 132 | 51 133 | 134 | 135 | 136 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 137 | font: 9pt "楷体"; 138 | font-size:25px; 139 | color: rgb(255, 255, 255); 140 | border:none; 141 | border-radius:8px 142 | 143 | 144 | 收银台 145 | 146 | 147 | 148 | 149 | 150 | 780 151 | 300 152 | 191 153 | 51 154 | 155 | 156 | 157 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 158 | font: 9pt "楷体"; 159 | font-size:25px; 160 | color: rgb(255, 255, 255); 161 | border:none; 162 | border-radius:8px 163 | 164 | 165 | 166 | 退出系统 167 | 168 | 169 | 170 | 171 | 172 | 100 173 | 300 174 | 191 175 | 51 176 | 177 | 178 | 179 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 180 | font: 9pt "楷体"; 181 | font-size:25px; 182 | color: rgb(255, 255, 255); 183 | border:none; 184 | border-radius:8px 185 | 186 | 187 | 销售统计 188 | 189 | 190 | 191 | 192 | 193 | 430 194 | 300 195 | 191 196 | 51 197 | 198 | 199 | 200 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 201 | font: 9pt "楷体"; 202 | font-size:25px; 203 | color: rgb(255, 255, 255); 204 | border:none; 205 | border-radius:8px 206 | 207 | 208 | 商品管理 209 | 210 | 211 | 212 | 213 | 214 | 540 215 | 430 216 | 471 217 | 91 218 | 219 | 220 | 221 | false 222 | 223 | 224 | QLCDNumber::Dec 225 | 226 | 227 | 1055.000000000000000 228 | 229 | 230 | 1055 231 | 232 | 233 | 234 | 235 | 236 | 80 237 | 420 238 | 311 239 | 121 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 340 252 | 410 253 | 91 254 | 20 255 | 256 | 257 | 258 | font: 18pt "楷体"; 259 | 260 | 261 | 商品号: 262 | 263 | 264 | 265 | 266 | 267 | 360 268 | 490 269 | 91 270 | 31 271 | 272 | 273 | 274 | font: 18pt "楷体"; 275 | 276 | 277 | 数量: 278 | 279 | 280 | 281 | 282 | 283 | 470 284 | 400 285 | 161 286 | 41 287 | 288 | 289 | 290 | background-color: rgb(255, 255, 255); 291 | color: rgb(0, 0, 0); 292 | 293 | 294 | 295 | 296 | 297 | 输入商品号 298 | 299 | 300 | 301 | 302 | 303 | 470 304 | 490 305 | 81 306 | 41 307 | 308 | 309 | 310 | background-color: rgb(255, 255, 255); 311 | color: rgb(0, 0, 0); 312 | 313 | 314 | 1 315 | 316 | 317 | 318 | 319 | 320 | 590 321 | 480 322 | 151 323 | 51 324 | 325 | 326 | 327 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 328 | font: 9pt "楷体"; 329 | font-size:25px; 330 | color: rgb(255, 255, 255); 331 | border:none; 332 | border-radius:8px 333 | 334 | 335 | 添加 336 | 337 | 338 | 339 | 340 | 341 | 920 342 | 260 343 | 151 344 | 51 345 | 346 | 347 | 348 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 349 | font: 9pt "楷体"; 350 | font-size:25px; 351 | color: rgb(255, 255, 255); 352 | border:none; 353 | border-radius:8px 354 | 355 | 356 | 结算 357 | 358 | 359 | 360 | 361 | 362 | 820 363 | 430 364 | 111 365 | 51 366 | 367 | 368 | 369 | font: 25pt "楷体"; 370 | 371 | 372 | 总金额 373 | 374 | 375 | 376 | 377 | 378 | 0 379 | 0 380 | 131 381 | 61 382 | 383 | 384 | 385 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 386 | font: 9pt "楷体"; 387 | font-size:25px; 388 | color: rgb(255, 255, 255); 389 | border:none; 390 | border-radius:8px 391 | 392 | 393 | 返回 394 | 395 | 396 | 397 | 398 | 399 | 170 400 | 120 401 | 731 402 | 241 403 | 404 | 405 | 406 | .QTableWidget 407 | { 408 | color: rgb(255, 255, 255); 409 | font: 17pt "楷体"; 410 | } 411 | 412 | 413 | 414 | 商品号 415 | 416 | 417 | 418 | 楷体 419 | 15 420 | true 421 | true 422 | 423 | 424 | 425 | 426 | 427 | 商品名 428 | 429 | 430 | 431 | 楷体 432 | 15 433 | true 434 | 435 | 436 | 437 | 438 | 439 | 商品类型 440 | 441 | 442 | 443 | 楷体 444 | 15 445 | true 446 | 447 | 448 | 449 | 450 | 451 | 单价 452 | 453 | 454 | 455 | 楷体 456 | 15 457 | true 458 | 459 | 460 | 461 | 462 | 463 | 数量 464 | 465 | 466 | 467 | 楷体 468 | 15 469 | true 470 | 471 | 472 | 473 | 474 | 475 | 总价 476 | 477 | 478 | 479 | 楷体 480 | 15 481 | true 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 450 490 | 10 491 | 201 492 | 91 493 | 494 | 495 | 496 | font: 36pt "楷体"; 497 | color: rgb(255, 255, 255); 498 | 499 | 500 | 收银台 501 | 502 | 503 | Qt::AlignCenter 504 | 505 | 506 | 507 | 508 | 509 | 930 510 | 420 511 | 151 512 | 51 513 | 514 | 515 | 516 | 8 517 | 518 | 519 | 520 | 521 | 522 | 620 523 | 0 524 | 141 525 | 101 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 350 538 | -10 539 | 411 540 | 91 541 | 542 | 543 | 544 | font: 36pt "楷体"; 545 | color: rgb(255, 255, 255); 546 | 547 | 548 | 商品管理 549 | 550 | 551 | Qt::AlignCenter 552 | 553 | 554 | 555 | 556 | 557 | 0 558 | 80 559 | 1161 560 | 321 561 | 562 | 563 | 564 | .QTableWidget 565 | { 566 | color: rgb(255, 255, 255); 567 | font: 13pt "楷体"; 568 | } 569 | 570 | 571 | 572 | 商品号 573 | 574 | 575 | 576 | 577 | 商品名 578 | 579 | 580 | 581 | 582 | 商品类型 583 | 584 | 585 | 586 | 587 | 单价 588 | 589 | 590 | 591 | 592 | 库存数量 593 | 594 | 595 | 596 | 597 | 品牌 598 | 599 | 600 | 601 | 602 | 生产商 603 | 604 | 605 | 606 | 607 | 销量 608 | 609 | 610 | 611 | 612 | 成本 613 | 614 | 615 | 616 | 617 | 种类 618 | 619 | 620 | 621 | 622 | 重(容)量 623 | 624 | 625 | 626 | 627 | 628 | 629 | 0 630 | 0 631 | 131 632 | 61 633 | 634 | 635 | 636 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 637 | font: 9pt "楷体"; 638 | font-size:25px; 639 | color: rgb(255, 255, 255); 640 | border:none; 641 | border-radius:8px 642 | 643 | 644 | 返回 645 | 646 | 647 | 648 | 649 | 650 | 730 651 | 430 652 | 161 653 | 51 654 | 655 | 656 | 657 | font: 25pt "楷体"; 658 | color: rgb(255, 255, 255); 659 | 660 | 661 | 查询方式: 662 | 663 | 664 | 665 | 666 | 667 | 900 668 | 430 669 | 91 670 | 51 671 | 672 | 673 | 674 | color: rgb(255, 255, 255); 675 | 676 | 677 | 4 678 | 679 | 680 | 681 | 商品号 682 | 683 | 684 | 685 | 686 | 商品名 687 | 688 | 689 | 690 | 691 | 品牌 692 | 693 | 694 | 695 | 696 | 类型 697 | 698 | 699 | 700 | 701 | 所有 702 | 703 | 704 | 705 | 706 | 707 | 708 | 1000 709 | 450 710 | 71 711 | 31 712 | 713 | 714 | 715 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 716 | font: 9pt "楷体"; 717 | font-size:25px; 718 | color: rgb(255, 255, 255); 719 | border:none; 720 | border-radius:8px 721 | 722 | 723 | 确定 724 | 725 | 726 | 727 | 728 | 729 | 0 730 | 420 731 | 351 732 | 41 733 | 734 | 735 | 736 | font: 18pt "楷体"; 737 | color: rgb(255, 255, 255); 738 | 739 | 740 | 双击商品号可修改对应商品信息 741 | 742 | 743 | 744 | 745 | 746 | 430 747 | 420 748 | 241 749 | 61 750 | 751 | 752 | 753 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 754 | font: 9pt "楷体"; 755 | font-size:25px; 756 | color: rgb(255, 255, 255); 757 | border:none; 758 | border-radius:8px 759 | 760 | 761 | 删除商品 762 | 763 | 764 | 765 | 766 | 767 | 840 768 | 500 769 | 151 770 | 151 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 0 783 | 0 784 | 131 785 | 61 786 | 787 | 788 | 789 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 790 | font: 9pt "楷体"; 791 | font-size:25px; 792 | color: rgb(255, 255, 255); 793 | border:none; 794 | border-radius:8px 795 | 796 | 797 | 返回 798 | 799 | 800 | 801 | 802 | 803 | 10 804 | 120 805 | 831 806 | 301 807 | 808 | 809 | 810 | .QTableWidget 811 | { 812 | color: rgb(255, 255, 255); 813 | font: 17pt "楷体"; 814 | } 815 | 816 | 817 | 818 | 商品号 819 | 820 | 821 | 822 | 楷体 823 | 15 824 | true 825 | true 826 | 827 | 828 | 829 | 830 | 831 | 商品名 832 | 833 | 834 | 835 | 楷体 836 | 15 837 | true 838 | 839 | 840 | 841 | 842 | 843 | 商品类型 844 | 845 | 846 | 847 | 楷体 848 | 15 849 | true 850 | 851 | 852 | 853 | 854 | 855 | 售价 856 | 857 | 858 | 859 | 楷体 860 | 15 861 | true 862 | 863 | 864 | 865 | 866 | 867 | 数量 868 | 869 | 870 | 871 | 楷体 872 | 15 873 | true 874 | 875 | 876 | 877 | 878 | 879 | 总价 880 | 881 | 882 | 883 | 楷体 884 | 15 885 | true 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 50 894 | 460 895 | 91 896 | 31 897 | 898 | 899 | 900 | font: 18pt "楷体"; 901 | 902 | 903 | 订单号: 904 | 905 | 906 | 907 | 908 | 909 | 160 910 | 450 911 | 161 912 | 51 913 | 914 | 915 | 916 | background-color: rgb(255, 255, 255); 917 | color: rgb(0, 0, 0); 918 | font: 16pt "楷体"; 919 | 920 | 921 | 922 | 923 | 924 | 请输入订单号 925 | 926 | 927 | 928 | 929 | 930 | 60 931 | 510 932 | 101 933 | 31 934 | 935 | 936 | 937 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 938 | font: 9pt "楷体"; 939 | font-size:25px; 940 | color: rgb(255, 255, 255); 941 | border:none; 942 | border-radius:8px 943 | 944 | 945 | 查询 946 | 947 | 948 | 949 | 950 | 951 | 90 952 | 560 953 | 161 954 | 31 955 | 956 | 957 | 958 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 959 | font: 9pt "楷体"; 960 | font-size:25px; 961 | color: rgb(255, 255, 255); 962 | border:none; 963 | border-radius:8px 964 | 965 | 966 | 修改购买数量 967 | 968 | 969 | 970 | 971 | 972 | 220 973 | 510 974 | 101 975 | 31 976 | 977 | 978 | 979 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 980 | font: 9pt "楷体"; 981 | font-size:25px; 982 | color: rgb(255, 255, 255); 983 | border:none; 984 | border-radius:8px 985 | 986 | 987 | 退货 988 | 989 | 990 | 991 | 992 | 993 | 580 994 | 430 995 | 151 996 | 41 997 | 998 | 999 | 1000 | font: 18pt "楷体"; 1001 | 1002 | 1003 | 总金额: 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 370 1010 | 10 1011 | 261 1012 | 91 1013 | 1014 | 1015 | 1016 | font: 36pt "楷体"; 1017 | 1018 | 1019 | 销售统计 1020 | 1021 | 1022 | Qt::AlignCenter 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 850 1029 | 160 1030 | 121 1031 | 31 1032 | 1033 | 1034 | 1035 | font: 18pt "楷体"; 1036 | 1037 | 1038 | 统计信息: 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 850 1045 | 250 1046 | 91 1047 | 31 1048 | 1049 | 1050 | 1051 | font: 14pt "楷体"; 1052 | 1053 | 1054 | 总营业额: 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 850 1061 | 350 1062 | 91 1063 | 31 1064 | 1065 | 1066 | 1067 | font: 14pt "楷体"; 1068 | 1069 | 1070 | 总成本: 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 690 1077 | 430 1078 | 151 1079 | 51 1080 | 1081 | 1082 | 1083 | 8 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 950 1090 | 240 1091 | 201 1092 | 51 1093 | 1094 | 1095 | 1096 | 11 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 950 1103 | 340 1104 | 201 1105 | 51 1106 | 1107 | 1108 | 1109 | 11 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 330 1116 | 480 1117 | 51 1118 | 20 1119 | 1120 | 1121 | 1122 | background-color: rgb(17, 145, 255); 1123 | color: rgb(255, 255, 255); 1124 | font: 1pt "楷体"; 1125 | font-size:25px; 1126 | 1127 | border:none; 1128 | border-radius:8px 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 330 1138 | 450 1139 | 51 1140 | 20 1141 | 1142 | 1143 | 1144 | background-color: rgb(17, 145, 255); 1145 | color: rgb(255, 255, 255); 1146 | font: 1pt "楷体"; 1147 | font-size:25px; 1148 | 1149 | border:none; 1150 | border-radius:8px 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 930 1160 | 30 1161 | 141 1162 | 101 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 0 1175 | 0 1176 | 131 1177 | 61 1178 | 1179 | 1180 | 1181 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 1182 | font: 9pt "楷体"; 1183 | font-size:25px; 1184 | color: rgb(255, 255, 255); 1185 | border:none; 1186 | border-radius:8px 1187 | 1188 | 1189 | 返回 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 0 1196 | 80 1197 | 1161 1198 | 401 1199 | 1200 | 1201 | 1202 | .QTableWidget 1203 | { 1204 | color: rgb(255, 255, 255); 1205 | font: 13pt "楷体"; 1206 | } 1207 | 1208 | 1209 | 1210 | 商品号 1211 | 1212 | 1213 | 1214 | 1215 | 商品名 1216 | 1217 | 1218 | 1219 | 1220 | 商品类型 1221 | 1222 | 1223 | 1224 | 1225 | 单价 1226 | 1227 | 1228 | 1229 | 1230 | 库存数量 1231 | 1232 | 1233 | 1234 | 1235 | 品牌 1236 | 1237 | 1238 | 1239 | 1240 | 生产商 1241 | 1242 | 1243 | 1244 | 1245 | 销量 1246 | 1247 | 1248 | 1249 | 1250 | 成本 1251 | 1252 | 1253 | 1254 | 1255 | 种类 1256 | 1257 | 1258 | 1259 | 1260 | 重(容)量 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 440 1268 | 0 1269 | 261 1270 | 71 1271 | 1272 | 1273 | 1274 | font: 36pt "楷体"; 1275 | color: rgb(255, 255, 255); 1276 | 1277 | 1278 | 库存商品 1279 | 1280 | 1281 | Qt::AlignCenter 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 580 1288 | 510 1289 | 111 1290 | 41 1291 | 1292 | 1293 | 1294 | color: rgb(255, 255, 255); 1295 | 1296 | 1297 | 1298 | 价格 1299 | 1300 | 1301 | 1302 | 1303 | 库存数量 1304 | 1305 | 1306 | 1307 | 1308 | 名称 1309 | 1310 | 1311 | 1312 | 1313 | 销量 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 580 1321 | 590 1322 | 111 1323 | 41 1324 | 1325 | 1326 | 1327 | color: rgb(255, 255, 255); 1328 | 1329 | 1330 | 1331 | 升序 1332 | 1333 | 1334 | 1335 | 1336 | 降序 1337 | 1338 | 1339 | 1340 | 1341 | 1342 | 1343 | 390 1344 | 500 1345 | 111 1346 | 51 1347 | 1348 | 1349 | 1350 | font: 18pt "楷体"; 1351 | color: rgb(255, 255, 255); 1352 | 1353 | 1354 | 排序依据: 1355 | 1356 | 1357 | 1358 | 1359 | 1360 | 390 1361 | 590 1362 | 111 1363 | 41 1364 | 1365 | 1366 | 1367 | font: 18pt "楷体"; 1368 | color: rgb(255, 255, 255); 1369 | 1370 | 1371 | 排序规则: 1372 | 1373 | 1374 | 1375 | 1376 | 1377 | 970 1378 | 550 1379 | 161 1380 | 71 1381 | 1382 | 1383 | 1384 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0.189944 rgba(202, 144, 87, 255), stop:0.726257 rgba(235, 148, 61, 255), stop:1 rgba(143, 143, 143, 255)); 1385 | font: 9pt "楷体"; 1386 | font-size:25px; 1387 | color: rgb(255, 255, 255); 1388 | border:none; 1389 | border-radius:8px 1390 | 1391 | 1392 | 显示 1393 | 1394 | 1395 | 1396 | 1397 | 1398 | 200 1399 | 490 1400 | 171 1401 | 171 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1416 | 0 1417 | 0 1418 | 1167 1419 | 21 1420 | 1421 | 1422 | 1423 | 1424 | 1425 | 1426 | 1427 | 1428 | -------------------------------------------------------------------------------- /oop_qt.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 3 | 4 | CONFIG += c++20 5 | 6 | # You can make your code fail to compile if it uses deprecated APIs. 7 | # In order to do so, uncomment the following line. 8 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 9 | 10 | SOURCES += \ 11 | inputwidget.cpp \ 12 | logindia.cpp \ 13 | main.cpp \ 14 | mainwindow.cpp \ 15 | removeWindows.cpp \ 16 | s/Beverage.cpp \ 17 | s/Commodity.cpp \ 18 | s/Cosmetic.cpp \ 19 | s/Daily.cpp \ 20 | s/Food.cpp \ 21 | s/Manager.cpp \ 22 | s/RepManager.cpp \ 23 | s/Saler.cpp \ 24 | s/Sorter.cpp 25 | 26 | HEADERS += \ 27 | head/Beverage.h \ 28 | head/Commodity.h \ 29 | head/Cosmetic.h \ 30 | head/Daily.h \ 31 | head/Food.h \ 32 | head/Manager.h \ 33 | head/RepManager.h \ 34 | head/Saler.h \ 35 | head/Sorter.h \ 36 | head/commodities.h \ 37 | inputwidget.h \ 38 | logindia.h \ 39 | mainwindow.h 40 | 41 | FORMS += \ 42 | inputwidget.ui \ 43 | logindia.ui \ 44 | mainwindow.ui 45 | 46 | # Default rules for deployment. 47 | qnx: target.path = /tmp/$${TARGET}/bin 48 | else: unix:!android: target.path = /opt/$${TARGET}/bin 49 | !isEmpty(target.path): INSTALLS += target 50 | 51 | RESOURCES += \ 52 | rc.qrc 53 | 54 | DISTFILES += 55 | -------------------------------------------------------------------------------- /oop_qt.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {a7469cf9-46d0-4bb4-b204-fd37d75ff980} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | false 41 | true 42 | false 43 | 0 44 | true 45 | true 46 | 0 47 | 8 48 | true 49 | false 50 | 1 51 | true 52 | true 53 | true 54 | *.md, *.MD, Makefile 55 | false 56 | true 57 | true 58 | 59 | 60 | 61 | ProjectExplorer.Project.PluginSettings 62 | 63 | 64 | true 65 | false 66 | true 67 | true 68 | true 69 | true 70 | 71 | 72 | 0 73 | true 74 | 75 | true 76 | true 77 | Builtin.DefaultTidyAndClazy 78 | 8 79 | 80 | 81 | 82 | true 83 | 84 | 85 | true 86 | 87 | 88 | 89 | 90 | ProjectExplorer.Project.Target.0 91 | 92 | Desktop 93 | Desktop Qt 6.4.1 MinGW 64-bit 94 | Desktop Qt 6.4.1 MinGW 64-bit 95 | qt.qt6.641.win64_mingw_kit 96 | 0 97 | 0 98 | 0 99 | 100 | 0 101 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Debug 102 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Debug 103 | 104 | 105 | true 106 | QtProjectManager.QMakeBuildStep 107 | false 108 | 109 | 110 | 111 | true 112 | Qt4ProjectManager.MakeStep 113 | 114 | 2 115 | 构建 116 | 构建 117 | ProjectExplorer.BuildSteps.Build 118 | 119 | 120 | 121 | true 122 | Qt4ProjectManager.MakeStep 123 | clean 124 | 125 | 1 126 | Clean 127 | Clean 128 | ProjectExplorer.BuildSteps.Clean 129 | 130 | 2 131 | false 132 | 133 | false 134 | 135 | Debug 136 | Qt4ProjectManager.Qt4BuildConfiguration 137 | 2 138 | 139 | 140 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Release 141 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Release 142 | 143 | 144 | true 145 | QtProjectManager.QMakeBuildStep 146 | false 147 | 148 | 149 | 150 | true 151 | Qt4ProjectManager.MakeStep 152 | 153 | 2 154 | 构建 155 | 构建 156 | ProjectExplorer.BuildSteps.Build 157 | 158 | 159 | 160 | true 161 | Qt4ProjectManager.MakeStep 162 | clean 163 | 164 | 1 165 | Clean 166 | Clean 167 | ProjectExplorer.BuildSteps.Clean 168 | 169 | 2 170 | false 171 | 172 | false 173 | 174 | Release 175 | Qt4ProjectManager.Qt4BuildConfiguration 176 | 0 177 | 0 178 | 179 | 180 | 0 181 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Profile 182 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MinGW_64_bit-Profile 183 | 184 | 185 | true 186 | QtProjectManager.QMakeBuildStep 187 | false 188 | 189 | 190 | 191 | true 192 | Qt4ProjectManager.MakeStep 193 | 194 | 2 195 | 构建 196 | 构建 197 | ProjectExplorer.BuildSteps.Build 198 | 199 | 200 | 201 | true 202 | Qt4ProjectManager.MakeStep 203 | clean 204 | 205 | 1 206 | Clean 207 | Clean 208 | ProjectExplorer.BuildSteps.Clean 209 | 210 | 2 211 | false 212 | 213 | false 214 | 215 | Profile 216 | Qt4ProjectManager.Qt4BuildConfiguration 217 | 0 218 | 0 219 | 0 220 | 221 | 3 222 | 223 | 224 | 0 225 | 部署 226 | 部署 227 | ProjectExplorer.BuildSteps.Deploy 228 | 229 | 1 230 | 231 | false 232 | ProjectExplorer.DefaultDeployConfiguration 233 | 234 | 1 235 | 236 | true 237 | true 238 | true 239 | 240 | 2 241 | 242 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/family/Desktop/CPP_QT/oop_qt/oop_qt.pro 243 | C:/Users/family/Desktop/CPP_QT/oop_qt/oop_qt.pro 244 | false 245 | true 246 | true 247 | false 248 | true 249 | 250 | 1 251 | 252 | 253 | 254 | ProjectExplorer.Project.Target.1 255 | 256 | Desktop 257 | Desktop Qt 6.4.1 MSVC2019 64bit 258 | Desktop Qt 6.4.1 MSVC2019 64bit 259 | qt.qt6.641.win64_msvc2019_64_kit 260 | 0 261 | 0 262 | 0 263 | 264 | 0 265 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Debug 266 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Debug 267 | 268 | 269 | true 270 | QtProjectManager.QMakeBuildStep 271 | false 272 | 273 | 274 | 275 | true 276 | Qt4ProjectManager.MakeStep 277 | 278 | 2 279 | 构建 280 | 构建 281 | ProjectExplorer.BuildSteps.Build 282 | 283 | 284 | 285 | true 286 | Qt4ProjectManager.MakeStep 287 | clean 288 | 289 | 1 290 | Clean 291 | Clean 292 | ProjectExplorer.BuildSteps.Clean 293 | 294 | 2 295 | false 296 | 297 | false 298 | 299 | Debug 300 | Qt4ProjectManager.Qt4BuildConfiguration 301 | 2 302 | 303 | 304 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Release 305 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Release 306 | 307 | 308 | true 309 | QtProjectManager.QMakeBuildStep 310 | false 311 | 312 | 313 | 314 | true 315 | Qt4ProjectManager.MakeStep 316 | 317 | 2 318 | 构建 319 | 构建 320 | ProjectExplorer.BuildSteps.Build 321 | 322 | 323 | 324 | true 325 | Qt4ProjectManager.MakeStep 326 | clean 327 | 328 | 1 329 | Clean 330 | Clean 331 | ProjectExplorer.BuildSteps.Clean 332 | 333 | 2 334 | false 335 | 336 | false 337 | 338 | Release 339 | Qt4ProjectManager.Qt4BuildConfiguration 340 | 0 341 | 0 342 | 343 | 344 | 0 345 | C:\Users\family\Desktop\oop_qt\oop_qt\..\build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Profile 346 | C:/Users/family/Desktop/oop_qt/build-oop_qt-Desktop_Qt_6_4_1_MSVC2019_64bit-Profile 347 | 348 | 349 | true 350 | QtProjectManager.QMakeBuildStep 351 | false 352 | 353 | 354 | 355 | true 356 | Qt4ProjectManager.MakeStep 357 | 358 | 2 359 | 构建 360 | 构建 361 | ProjectExplorer.BuildSteps.Build 362 | 363 | 364 | 365 | true 366 | Qt4ProjectManager.MakeStep 367 | clean 368 | 369 | 1 370 | Clean 371 | Clean 372 | ProjectExplorer.BuildSteps.Clean 373 | 374 | 2 375 | false 376 | 377 | false 378 | 379 | Profile 380 | Qt4ProjectManager.Qt4BuildConfiguration 381 | 0 382 | 0 383 | 0 384 | 385 | 3 386 | 387 | 388 | 0 389 | 部署 390 | 部署 391 | ProjectExplorer.BuildSteps.Deploy 392 | 393 | 1 394 | 395 | false 396 | ProjectExplorer.DefaultDeployConfiguration 397 | 398 | 1 399 | 400 | true 401 | true 402 | true 403 | 404 | 2 405 | 406 | ProjectExplorer.CustomExecutableRunConfiguration 407 | 408 | false 409 | true 410 | false 411 | true 412 | 413 | 1 414 | 415 | 416 | 417 | ProjectExplorer.Project.TargetCount 418 | 2 419 | 420 | 421 | ProjectExplorer.Project.Updater.FileVersion 422 | 22 423 | 424 | 425 | Version 426 | 22 427 | 428 | 429 | -------------------------------------------------------------------------------- /rc.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | rc/n133f35jvek.jpg 4 | rc/9954a5f7dfd64e7bafc23eda4e8b9487.gif 5 | rc/key.png 6 | rc/buyCar.png 7 | rc/money.png 8 | rc/show.gif 9 | rc/manage.gif 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /rc/9954a5f7dfd64e7bafc23eda4e8b9487.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/9954a5f7dfd64e7bafc23eda4e8b9487.gif -------------------------------------------------------------------------------- /rc/buyCar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/buyCar.png -------------------------------------------------------------------------------- /rc/key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/key.png -------------------------------------------------------------------------------- /rc/manage.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/manage.gif -------------------------------------------------------------------------------- /rc/money.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/money.png -------------------------------------------------------------------------------- /rc/n133f35jvek.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/n133f35jvek.jpg -------------------------------------------------------------------------------- /rc/show.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bigwhites/cpp-qt-manageSystem/ba2e13e63bc231693bd42c7fba492eaeeed90f9b/rc/show.gif -------------------------------------------------------------------------------- /removeWindows.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | void MainWindow::on_backBtn_released() 5 | { 6 | ui->stackedWidget->setCurrentWidget(ui->mainPg); 7 | } 8 | 9 | void MainWindow::on_backBtn_2_released() 10 | { 11 | ui->stackedWidget->setCurrentWidget(ui->mainPg); 12 | } 13 | 14 | void MainWindow::on_backBtn_3_released() 15 | { 16 | ui->stackedWidget->setCurrentWidget(ui->mainPg); 17 | } 18 | 19 | 20 | void MainWindow::on_backBtn_5_released() 21 | { 22 | ui->stackedWidget->setCurrentWidget(ui->mainPg); 23 | } 24 | void MainWindow::on_showBtn_released() 25 | { 26 | ui->stackedWidget->setCurrentWidget(ui->showPg); 27 | } 28 | 29 | void MainWindow::on_buyBtn_released() 30 | { 31 | ui->stackedWidget->setCurrentWidget(ui->buyPg); 32 | } 33 | 34 | void MainWindow::on_saleStatBtn_released() 35 | { 36 | ui->stackedWidget->setCurrentWidget(ui->saleStatPg); 37 | //更新总成本和总收入 38 | ui->sumRevenLcd->display(rm.getSumRevenue()); 39 | ui->sumCostLcd->display(rm.getSumCost()); 40 | } 41 | 42 | 43 | void MainWindow::on_comManagerBtn_released() 44 | { 45 | ui->stackedWidget->setCurrentWidget(ui->managerPg); 46 | } 47 | 48 | void MainWindow::on_exitBtn_released() 49 | { 50 | this->close(); 51 | } 52 | -------------------------------------------------------------------------------- /s/Beverage.cpp: -------------------------------------------------------------------------------- 1 | #include "head/Beverage.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | long Beverage::maxNo = 1000000; 8 | const array Beverage::kindStrs={"普通饮料","酒","碳酸饮料"}; 9 | 10 | Beverage::Beverage() 11 | { 12 | _no = "B" + to_string(++maxNo); 13 | 14 | } 15 | 16 | Beverage::Beverage(std::string name, std::string brand, 17 | std::string manufactuer, double price, double cost, 18 | int amount, bool onSale, int saleCount, int capacity, BeverageKind kind): 19 | Commodity(to_string(++maxNo), name, brand, 20 | manufactuer, price, cost, amount,onSale,saleCount), _capacity(capacity), _kind(kind) 21 | { 22 | _no = "B" + _no; 23 | } 24 | 25 | int Beverage::getKind() 26 | { 27 | return (int)_kind; 28 | } 29 | 30 | double Beverage::getWeiOrCapa() 31 | { 32 | return _capacity; 33 | } 34 | 35 | void Beverage::setWeiOrCapa(double wc) 36 | { 37 | _capacity=(int)wc; 38 | } 39 | 40 | string Beverage::getKindStr() 41 | { 42 | return kindStrs[(int)_kind]; 43 | } 44 | 45 | void Beverage::setKind(int k) 46 | { 47 | _kind=(BeverageKind)k; 48 | } 49 | 50 | 51 | std::ifstream& operator>>(std::ifstream& ifs, Beverage& b) 52 | { 53 | int k; 54 | ifs >> b._no >> b._name >> b._brand >> b._manufacturer 55 | >> b._price >> b._cost >> b._amount 56 | >> b._capacity >> k >> b._onSale>>b._saleCount; 57 | b._kind = (Beverage::BeverageKind)k; 58 | return ifs; 59 | } 60 | 61 | std::ofstream& operator<<(std::ofstream& ofs, Beverage& b) 62 | { 63 | ofs << b._no << " " << b._name << " " << b._brand << " " << 64 | b._manufacturer << " " << b._price << " " << b._cost 65 | << " " << b._amount << " " << b._capacity << " " 66 | << (int)b._kind << " " << b._onSale<<" " << b._saleCount; 67 | return ofs; 68 | } 69 | -------------------------------------------------------------------------------- /s/Commodity.cpp: -------------------------------------------------------------------------------- 1 | #include "head/Commodity.h" 2 | #include 3 | 4 | using namespace std; 5 | 6 | 7 | Commodity::Commodity(string no, string name, string brand, string manufacturer, double price, double cost, int amount,bool onSale, int saleCount) 8 | :_no(no), _name(name), _brand(brand), _manufacturer(manufacturer), _price(price), _cost(cost), _amount(amount),_onSale(onSale),_saleCount(saleCount) 9 | { 10 | } 11 | 12 | 13 | int Commodity::getAmount(void) 14 | { 15 | return _amount; 16 | } 17 | 18 | int Commodity::getSaleCount(void) 19 | { 20 | return _saleCount; 21 | } 22 | void Commodity::setSaleCount(int c) 23 | { 24 | _saleCount = c; 25 | } 26 | 27 | string Commodity::getManufacturer() 28 | { 29 | return _manufacturer; 30 | } 31 | 32 | double Commodity::getPrice(void) 33 | { 34 | return _price; 35 | } 36 | 37 | void Commodity::setPrice(double p) 38 | { 39 | _price = p; 40 | } 41 | 42 | double Commodity::getCost(void) 43 | { 44 | return _cost; 45 | } 46 | 47 | 48 | std::string Commodity::getNo(void) 49 | { 50 | return _no; 51 | } 52 | 53 | std::string Commodity::getName(void) 54 | { 55 | return _name; 56 | } 57 | 58 | std::string Commodity::getBrand(void) 59 | { 60 | return _brand; 61 | } 62 | 63 | string Commodity::getClassStr() 64 | { 65 | switch(_no[0]) 66 | { 67 | case'F': return move("食品"); 68 | case'C': return move("化妆品"); 69 | case'B': return move("饮料"); 70 | case'D': return move("日用品"); 71 | } 72 | } 73 | 74 | void Commodity::setName(std::string name) 75 | { 76 | _name=move(name); 77 | } 78 | 79 | void Commodity::setCost(int c) 80 | { 81 | _cost=c; 82 | } 83 | 84 | void Commodity::setManufacturer(std::string m) 85 | { 86 | _manufacturer=move(m); 87 | } 88 | 89 | void Commodity::setAmount(int a) 90 | { 91 | _amount = a; 92 | } 93 | 94 | bool Commodity::onSale(void) 95 | { 96 | return _onSale; 97 | } 98 | 99 | void Commodity::setOffSale() 100 | { 101 | _onSale = false; 102 | } 103 | 104 | void Commodity::setBrand(std::string b) 105 | { 106 | _brand=move(b); 107 | } 108 | -------------------------------------------------------------------------------- /s/Cosmetic.cpp: -------------------------------------------------------------------------------- 1 | #include "head/Cosmetic.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | long Cosmetic::maxNo = 1000000; 8 | const array Cosmetic::kindStrs={"美容","清洁","护肤"}; 9 | 10 | Cosmetic::Cosmetic() 11 | { 12 | _no = "C" + to_string(++maxNo); 13 | } 14 | 15 | Cosmetic::Cosmetic(std::string name, std::string brand, 16 | std::string manufacturer, double price, 17 | double cost, int amount, bool onSale, int saleCount,double weight, 18 | CosmeticKind kind) 19 | :Commodity(to_string(++maxNo), name, brand, 20 | manufacturer, price, cost, amount,onSale,saleCount),_weight(weight), _kind(kind) 21 | { 22 | _no = "C" + _no; 23 | } 24 | 25 | int Cosmetic::getKind() 26 | { 27 | return (int)_kind; 28 | } 29 | 30 | double Cosmetic::getWeiOrCapa() 31 | { 32 | return _weight; 33 | } 34 | 35 | void Cosmetic::setWeiOrCapa(double wc) 36 | { 37 | _weight=wc; 38 | } 39 | 40 | string Cosmetic::getKindStr() 41 | { 42 | return kindStrs[(int)_kind]; 43 | } 44 | 45 | void Cosmetic::setKind(int k) 46 | { 47 | _kind = (CosmeticKind)k; 48 | } 49 | 50 | 51 | std::ifstream &operator>>(std::ifstream &ifs, Cosmetic &c) 52 | { 53 | int k; 54 | ifs >> c._no >> c._name >> c._brand >> 55 | c._manufacturer >> c._price >> c._cost >> 56 | c._amount >> c._weight >> k >> c._onSale>>c._saleCount; 57 | c._kind = (Cosmetic::CosmeticKind)k; 58 | return ifs; 59 | } 60 | 61 | std::ofstream &operator<<(std::ofstream &ofs, Cosmetic &c) 62 | { 63 | ofs << c._no << " " << c._name << " " << c._brand << " " << 64 | c._manufacturer << " " << c._price << " " << c._cost 65 | << " " << c._amount << " " << c._weight << " " << (int)c._kind << " " << c._onSale<<" " << c._saleCount; 66 | return ofs; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /s/Daily.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include"head/Daily.h" 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | long Daily::maxNo = 1000000; 9 | const arrayDaily::kindStrs={"床上用品","厨房用品","电器","常用品"}; 10 | 11 | Daily::Daily() { 12 | _no = "D" + to_string(++maxNo); 13 | } 14 | 15 | Daily::Daily(string name, string brand, string manufacturer, 16 | double price, double cost, int amount, bool onSale, int saleCount,double weight ,DailyKind kind) : 17 | Commodity(to_string(++maxNo), name, brand, manufacturer, price, 18 | cost, amount,onSale,saleCount),_weight(weight), _kind(kind) { 19 | _no = "D" + _no; 20 | } 21 | 22 | int Daily::getKind() 23 | { 24 | return (int)_kind; 25 | } 26 | 27 | double Daily::getWeiOrCapa() 28 | { 29 | return _weight; 30 | } 31 | 32 | void Daily::setWeiOrCapa(double wc) 33 | { 34 | _weight=wc; 35 | } 36 | 37 | string Daily::getKindStr() 38 | { 39 | return kindStrs[(int)_kind]; 40 | } 41 | 42 | void Daily::setKind(int k) 43 | { 44 | _kind = (DailyKind)k; 45 | } 46 | 47 | 48 | ifstream& operator>>(ifstream& ifs, Daily& d) 49 | { 50 | int k; 51 | ifs >> d._no >> d._name >> d._brand >> d._manufacturer 52 | >> d._price >> d._cost >> d._amount 53 | >> d._weight >> k >> d._onSale>>d._saleCount; 54 | d._kind = (Daily::DailyKind)k; 55 | return ifs; 56 | } 57 | 58 | ofstream& operator<<(ofstream& ofs, Daily& d) 59 | { 60 | ofs << d._no << " " << d._name << " " << d._brand << " " << 61 | d._manufacturer << " " << d._price << " " << d._cost 62 | << " " << d._amount << " " << d._weight << " " 63 | << (int)d._kind << " " << d._onSale<<" " << d._saleCount; 64 | return ofs; 65 | } 66 | -------------------------------------------------------------------------------- /s/Food.cpp: -------------------------------------------------------------------------------- 1 | #include "head/Food.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | long Food::maxNo = 1000000; 8 | const array Food::kindStrs={"熟食","生食","袋装食品"}; 9 | Food::Food() 10 | { 11 | _no = "F" + to_string(++maxNo); 12 | } 13 | 14 | Food::Food(string name, string brand, string manufacturer, 15 | double price, double cost, int amount, bool onSale, int saleCount, 16 | double weight, FoodKind kind) 17 | :Commodity(to_string(++maxNo), name, brand, 18 | manufacturer, price, cost, amount,onSale,saleCount), 19 | _weight(weight), _kind(kind) 20 | { 21 | _no = "F" + _no; 22 | } 23 | 24 | int Food::getKind() 25 | { 26 | return (int)_kind; 27 | } 28 | 29 | double Food::getWeiOrCapa() 30 | { 31 | return _weight; 32 | } 33 | 34 | void Food::setWeiOrCapa(double wc) 35 | { 36 | _weight=wc; 37 | } 38 | 39 | string Food::getKindStr() 40 | { 41 | return kindStrs[(int)_kind]; 42 | } 43 | 44 | void Food::setKind(int k) 45 | { 46 | _kind=(FoodKind)k; 47 | } 48 | 49 | ifstream& operator>>(ifstream& ifs, Food& f) 50 | { 51 | int k; 52 | ifs >> f._no >> f._name >> f._brand >> f._manufacturer 53 | >> f._price >> f._cost >> f._amount 54 | >> f._weight >> k>>f._onSale>>f._saleCount; 55 | f._kind = (Food::FoodKind)k; 56 | return ifs; 57 | } 58 | 59 | std::ofstream& operator<<(std::ofstream& ofs, Food& f) 60 | { 61 | ofs << f._no << " " << f._name << " " << f._brand << " " << 62 | f._manufacturer << " " << f._price << " " << f._cost 63 | << " " << f._amount << " " < 4 | #include 5 | using namespace std; 6 | 7 | double Manager::_sumCost = 0; 8 | double Manager::_sumRevenue = 0; 9 | Manager::Commodities Manager::_repository; 10 | double Manager::_useCount = 0; 11 | 12 | Manager::Manager() 13 | { 14 | ++_useCount; 15 | } 16 | 17 | Manager::~Manager() 18 | { 19 | --_useCount; 20 | if (_useCount == 0) //资源引用计数为0时释放 21 | { 22 | for (auto& pCommodity : _repository) 23 | { 24 | if (pCommodity) 25 | { 26 | delete pCommodity; 27 | pCommodity = nullptr; 28 | } 29 | } 30 | } 31 | } 32 | 33 | bool Manager::comExist(string name, string brand) //商品查重 34 | { 35 | bool b=false,c=false; 36 | auto check = [](auto begin,auto end,const string& n,const string& b,bool* exist) 37 | { 38 | for(auto it=begin;it!=end;++it) 39 | { 40 | if((*it)->getName()==n && (*it)->getBrand()==b && (*it)->onSale()) 41 | { 42 | *exist=true; 43 | return; 44 | } 45 | } 46 | }; 47 | int half = _repository.size()/2; 48 | thread th(check,_repository.begin()+half 49 | ,_repository.end(),name,brand,&c); //多线程查询 50 | check(_repository.begin(),_repository.begin()+half,name,brand,&b); 51 | th.join(); 52 | return b||c; 53 | } 54 | 55 | double Manager::getSumRevenue() 56 | { 57 | return _sumRevenue; 58 | } 59 | 60 | double Manager::getSumCost() 61 | { 62 | return _sumCost; 63 | } 64 | 65 | void Manager::displayRepCom(Commodity* com, QTableWidget *bigTable) 66 | { 67 | int row=bigTable->rowCount(); 68 | bigTable->insertRow(row); 69 | QString qNo=com->getNo().c_str(); 70 | bigTable->setItem(row,0,new QTableWidgetItem(qNo)); 71 | bigTable->setItem(row,1,new QTableWidgetItem(com->getName().c_str())); 72 | bigTable->setItem(row,2,new QTableWidgetItem(com->getClassStr().c_str())); 73 | bigTable->setItem(row,3,new QTableWidgetItem(QString::number(com->getPrice()))); 74 | bigTable->setItem(row,4,new QTableWidgetItem(QString::number(com->getAmount()))); 75 | bigTable->setItem(row,5,new QTableWidgetItem(com->getBrand().c_str())); 76 | bigTable->setItem(row,6,new QTableWidgetItem(com->getManufacturer().c_str())); 77 | bigTable->setItem(row,7,new QTableWidgetItem(QString::number(com->getSaleCount()))); 78 | bigTable->setItem(row,8,new QTableWidgetItem(QString::number(com->getCost()))); 79 | bigTable->setItem(row,9,new QTableWidgetItem(com->getKindStr().c_str())); 80 | bigTable->setItem(row,10,new QTableWidgetItem(QString::number(com->getWeiOrCapa()))); 81 | } 82 | 83 | void Manager::displaySaledCom(Commodity* saledCom,QTableWidget* smallTable,int amount) 84 | { 85 | int row=smallTable->rowCount(); 86 | smallTable->insertRow(row); //新增一个空行 87 | //插入数据 88 | QString qNo=saledCom->getNo().c_str(); 89 | smallTable->setItem(row,0,new QTableWidgetItem(qNo)); 90 | smallTable->setItem(row,1,new QTableWidgetItem(saledCom->getName().c_str())); 91 | smallTable->setItem(row,2,new QTableWidgetItem(saledCom->getClassStr().c_str())); 92 | smallTable->setItem(row,3,new QTableWidgetItem(QString::number(saledCom->getPrice()))); 93 | smallTable->setItem(row,4,new QTableWidgetItem(QString::number(amount))); 94 | smallTable->setItem(row,5,new QTableWidgetItem(QString::number(amount*saledCom->getPrice()))); 95 | } 96 | -------------------------------------------------------------------------------- /s/RepManager.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "head/RepManager.h" 3 | #include 4 | #include 5 | #include 6 | 7 | map RepManager::_noComMap; 8 | 9 | Commodity* RepManager::searchNo(std::string no) 10 | { 11 | if (_noComMap.count(no) == 0) 12 | { 13 | throw runtime_error("不存在该商品"); 14 | } 15 | return _noComMap[no]; 16 | } 17 | 18 | Commodity* RepManager::searchNoAll(std::string no) 19 | { 20 | for (auto& com : _repository) 21 | { 22 | if (no == com->getNo()) 23 | { 24 | return com; 25 | } 26 | } 27 | return nullptr; 28 | } 29 | 30 | std::list RepManager::searchName(std::string name) 31 | { 32 | std::list resList;//符合条件的商品 33 | auto check = [&](Commodity* c) 34 | { 35 | 36 | return c->getName().find(name) != string::npos; 37 | }; 38 | for (auto com : _repository) 39 | { 40 | if (check(com)&&com->onSale()) 41 | { 42 | resList.push_back(com); 43 | } 44 | } 45 | return resList; 46 | } 47 | 48 | std::list RepManager::searchBrand(std::string brand) 49 | { 50 | std::list resList; 51 | for (auto com : _repository) 52 | { 53 | if (brand==com->getBrand()&&com->onSale()) 54 | { 55 | resList.push_back(com); 56 | } 57 | } 58 | return resList; 59 | } 60 | 61 | std::list RepManager::searchClass(char classCh) 62 | { 63 | list resList; 64 | for_each(_repository.begin(),_repository.end(), 65 | [&](Commodity* com) 66 | { 67 | if(com->onSale()&&com->getNo()[0]==classCh) 68 | { 69 | resList.push_back(com); 70 | } 71 | } ); 72 | return resList; 73 | } 74 | 75 | 76 | bool RepManager::addFood(std::string name, std::string brand, 77 | std::string manufacturer, double price, 78 | double cost, int amount, double weight, Food::FoodKind kind) 79 | { 80 | 81 | Commodity* f = new Food(name, brand, manufacturer, 82 | price, cost, amount, true, 0, weight, kind); 83 | _repository.push_back(f); 84 | _noComMap.insert(make_pair(f->getNo(), f)); 85 | _sumCost+=amount*cost; 86 | return true; 87 | } 88 | 89 | bool RepManager::addCosmetic(std::string name, std::string brand, 90 | std::string manufacturer, double price, double cost, int amount, 91 | double weight,Cosmetic::CosmeticKind kind) 92 | { 93 | Commodity* c = new Cosmetic(name, brand, manufacturer, 94 | price, cost, amount, true, 0, weight, kind); 95 | _repository.push_back(c); 96 | _noComMap.insert(make_pair(c->getNo(), c)); 97 | _sumCost+=amount*cost; 98 | return true; 99 | } 100 | 101 | bool RepManager::addBeverage(string name, string brand, string manufacturer, 102 | double price, double cost, int amount, 103 | int capacity, Beverage::BeverageKind kind) 104 | { 105 | 106 | Commodity* b = new Beverage(name, brand, manufacturer, 107 | price, cost, amount, true, 0, capacity, kind); 108 | _repository.push_back(b); 109 | _noComMap.insert(make_pair(b->getNo(), b)); 110 | _sumCost+=amount*cost; 111 | return true; 112 | 113 | } 114 | 115 | bool RepManager::addDaily(string name, string brand, string manufacturer, 116 | double price, double cost, int amount, 117 | double weight, Daily::DailyKind kind) 118 | { 119 | 120 | Commodity* d = new Daily(name, brand, manufacturer, 121 | price, cost, amount, true, 0, weight, kind); 122 | _repository.push_back(d); 123 | _noComMap.insert(make_pair(d->getNo(), d)); 124 | _sumCost+=amount*cost; 125 | return true; 126 | } 127 | 128 | void RepManager::setAmount(std::string no, int newAmount) 129 | { 130 | auto pCom = this->searchNo(no); 131 | int oriAmount = pCom->getAmount(); 132 | int delta = newAmount-oriAmount; 133 | pCom->setAmount(newAmount); 134 | _sumCost += delta*pCom->getCost(); //更新总成本 135 | } 136 | 137 | void RepManager::setPricre(std::string no, int newPrice) 138 | { 139 | auto com = this->searchNo(no); 140 | com->setPrice(newPrice); 141 | } 142 | 143 | void RepManager::deleteCommodity(std::string no) 144 | { 145 | auto com = this->searchNo(no); 146 | com->setOffSale(); 147 | _sumCost-=com->getCost()*com->getAmount(); 148 | _noComMap.erase(com->getNo()); 149 | } 150 | 151 | void RepManager::loadRepository(void) 152 | { 153 | ifstream ifs; 154 | ifs.open("food.txt"); 155 | if (ifs.is_open()) 156 | { 157 | Food* f; 158 | while (!ifs.eof()) 159 | { 160 | f = new Food; 161 | ifs >> *f; 162 | _repository.push_back((Commodity*)f); 163 | if(f->onSale()) _noComMap.insert(make_pair(f->getNo(), (Commodity*)f)); 164 | _sumCost+=f->getCost()*f->getAmount(); 165 | } 166 | } 167 | ifs.close(); 168 | 169 | ifs.open("cosmetic.txt"); 170 | if (ifs.is_open()) 171 | { 172 | Cosmetic* c; 173 | while (!ifs.eof()) 174 | { 175 | c = new Cosmetic; 176 | ifs >> *c; 177 | _repository.push_back((Commodity*)c); 178 | if(c->onSale()) _noComMap.insert(make_pair(c->getNo(), (Commodity*)c)); 179 | _sumCost+=c->getCost()*c->getAmount(); 180 | 181 | } 182 | } 183 | ifs.close(); 184 | 185 | ifs.open("beverage.txt"); 186 | if (ifs.is_open()) 187 | { 188 | Beverage* b; 189 | while (!ifs.eof()) 190 | { 191 | b = new Beverage; 192 | ifs >> *b; 193 | _repository.push_back((Commodity*)b); 194 | if(b->onSale()) _noComMap.insert(make_pair(b->getNo(), (Commodity*)b)); 195 | _sumCost+=b->getCost()*b->getAmount(); 196 | } 197 | } 198 | ifs.close(); 199 | 200 | ifs.open("daily.txt"); 201 | if (ifs.is_open()) 202 | { 203 | Daily* d; 204 | while (!ifs.eof()) 205 | { 206 | d = new Daily; 207 | ifs >> *d; 208 | _repository.push_back((Commodity*)d); 209 | if(d->onSale()) _noComMap.insert(make_pair(d->getNo(), (Commodity*)d)); 210 | _sumCost+=d->getCost()*d->getAmount(); 211 | } 212 | } 213 | ifs.close(); 214 | 215 | 216 | 217 | } 218 | 219 | void RepManager::saveRepository(void) 220 | { 221 | if(_repository.size()==0) 222 | { 223 | return ; 224 | } 225 | map files; //商品种类和文件流的映射 226 | files['F'] = new ofstream; 227 | files['C'] = new ofstream; 228 | files['B'] = new ofstream; 229 | files['D'] = new ofstream; 230 | int nf = 0, nc = 0, nb = 0, nd = 0; 231 | for (auto& com : _repository) 232 | { 233 | auto& pFileStream = (files[com->getNo()[0]]); //确定输出文件 234 | if (Food* f = dynamic_cast(com); f) 235 | { 236 | if (nf++ != 0) *pFileStream<< endl; //不是第一个数据才 输出换行 237 | else pFileStream->open("food.txt", ios::out); //真有数据写才打开文件 238 | *pFileStream << *f; 239 | } 240 | 241 | if (Cosmetic* c = dynamic_cast(com); c) 242 | { 243 | if (nc++ != 0) *pFileStream << endl; 244 | else pFileStream->open("cosmetic.txt", ios::out); 245 | *pFileStream << *c; 246 | } 247 | 248 | if(Beverage * b = dynamic_cast(com);b) 249 | { 250 | if(nb++!=0) *pFileStream << endl; 251 | else pFileStream->open("beverage.txt",ios::out); 252 | *pFileStream << *b; 253 | } 254 | 255 | if(Daily * d = dynamic_cast(com);d) 256 | { 257 | if(nd++!=0) *pFileStream << endl; 258 | else pFileStream->open("daily.txt",ios::out); 259 | *pFileStream << *d; 260 | } 261 | } 262 | for (auto& [k, f] : files) //关闭所有文件 263 | { 264 | 265 | f->close(); 266 | delete f; 267 | } 268 | 269 | } 270 | -------------------------------------------------------------------------------- /s/Saler.cpp: -------------------------------------------------------------------------------- 1 | #pragma execution_character_set("utf-8") 2 | #include "head/Saler.h" 3 | #include"head/RepManager.h" 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | vector Saler::_tradeComs; //交易记录 10 | vector> Saler::_tradeAmount; //商品数量记录 11 | vector Saler::_tradeIncome; //交易额记录 12 | vector> Saler::_tradePrices; //商品成交价格记录 13 | vector Saler::_tradeId; //交易号 14 | 15 | long long Saler::_maxId = 100000; 16 | 17 | int Saler::getPosition(std::string trid) 18 | { 19 | if(trid.size()<9) throw runtime_error("非合法订单号"); 20 | trid.erase(trid.begin(), trid.begin() + 3); 21 | long long id = stoull(trid); //转为数字 22 | if (id < 0 || id - 100000 - 1 >= _tradeId.size()) 23 | { 24 | throw runtime_error("没有该订单"); 25 | } 26 | return id - 100000 - 1; //对应数组下标 27 | } 28 | 29 | Saler::Saler() 30 | { 31 | static bool first = true; 32 | if (first){ 33 | //读取文件 获得记录 34 | first = false; 35 | } 36 | _income = 0; //金额置为0 37 | _coms.clear(); //清除旧的记录 38 | } 39 | 40 | tuple Saler::endBuy() 41 | { 42 | _tradeAmount.push_back(move(_amount)); 43 | _amount.clear(); 44 | 45 | _tradePrices.push_back(move(_price)); 46 | _price.clear(); 47 | 48 | _tradeIncome.push_back(_income); 49 | 50 | _tradeComs.push_back(move(_coms)); 51 | _coms.clear(); 52 | 53 | _tradeId.push_back("Tr-" + to_string(++_maxId)); 54 | auto res=_income; 55 | _income=0; 56 | return {*(_tradeId.end()-1),res}; //返回商品的总金额 57 | } 58 | 59 | void Saler::buy(Commodity* com, int amount) 60 | { 61 | if (com==nullptr || amount > com->getAmount()) 62 | { 63 | throw runtime_error("库存不足"); //商品库存不足已买这么多 或不存在该商品 64 | 65 | } 66 | else 67 | { 68 | bool noSame=true; 69 | for(int i = 0;auto boughtCom:_coms) //若有重复则合并 70 | { 71 | if(boughtCom==com) 72 | { 73 | _amount[i]+=amount; 74 | noSame=false; 75 | } 76 | i++; 77 | } 78 | if(noSame) //无重复则新增 79 | { 80 | _coms.push_back(com); 81 | _amount.push_back(amount); 82 | _price.push_back(com->getPrice()); //购买时的价格 83 | } 84 | com->setAmount(com->getAmount() - amount); //更新库存中的数量 85 | com->setSaleCount(com->getSaleCount() + amount); 86 | _sumRevenue += (com->getPrice()) * amount; //更新总营业额 87 | _income += (com->getPrice()) * amount; 88 | } 89 | } 90 | 91 | double Saler::locIncome() 92 | { 93 | return _income; 94 | } 95 | 96 | void Saler::saveTradeRecord(void) 97 | { 98 | ofstream ofs; 99 | ofs.open("tradeRecord.txt", ios::out); 100 | for (int i = 0; i < _tradeId.size(); ++i) 101 | { 102 | ofs << _tradeId[i] << " " << _tradeIncome[i] << " " << _tradeComs[i].size() << endl; 103 | for (int j = 0; j < _tradeComs[i].size(); ++j) 104 | { 105 | ofs << _tradeComs[i][j]->getNo() << " " << _tradeAmount[i][j] << " " << _tradePrices[i][j] << endl; 106 | } 107 | ofs << endl; 108 | } 109 | ofs.close(); 110 | } 111 | 112 | void Saler::loadTradeRecord(void) 113 | { 114 | ifstream ifs; 115 | RepManager rm; 116 | ifs.open("tradeRecord.txt"); 117 | if (!ifs.is_open()) 118 | { 119 | // TODO 120 | return; 121 | } 122 | clearRecord(); 123 | int i = 0; 124 | string trId, no; 125 | double trIncome; 126 | int n; //购买商品种数 127 | while (ifs >> trId >> trIncome >> n) 128 | { 129 | Manager::_sumRevenue += trIncome; //总营业额增加 130 | _tradeComs.push_back(Commodities(n)); 131 | _tradeAmount.push_back(vector(n)); 132 | _tradePrices.push_back(vector(n)); 133 | _tradeId.push_back(trId); 134 | _tradeIncome.push_back(trIncome); 135 | for (int j = 0; j < n; ++j) 136 | { 137 | ifs >> no >> _tradeAmount[i][j] >> _tradePrices[i][j]; 138 | _tradeComs[i][j] = rm.searchNoAll(no); 139 | } 140 | i++; 141 | ++_maxId; 142 | } 143 | ifs.close(); 144 | } 145 | 146 | void Saler::clearRecord() 147 | { 148 | //清空所有的记录 149 | _tradeComs.clear(); 150 | _tradeAmount.clear(); 151 | _tradeIncome.clear(); 152 | _tradeId.clear(); 153 | _tradePrices.clear(); 154 | _maxId = 100000; 155 | } 156 | 157 | void Saler::reSetTrRecord(const string& trid, Commodity* com, int newAmount) 158 | { 159 | int pos = getPosition(trid); 160 | bool noFind = true; 161 | for (int i = 0; i < _tradeAmount[pos].size(); ++i)//在记录中寻找 162 | { 163 | if (com == nullptr || _tradeComs[pos][i] == com) //找到该商品 或需要全部删除 164 | { 165 | noFind = false; 166 | 167 | int delta = newAmount - _tradeAmount[pos][i]; //新旧数量差距 168 | if (delta > 0 && com->getAmount() < delta) 169 | { 170 | throw("当前库存不足,无法修改"); 171 | } 172 | Manager::_sumRevenue += delta * _tradePrices[pos][i]; //更新总收入 173 | _tradeIncome[pos] += delta * _tradePrices[pos][i]; //更新交易额 174 | if (newAmount != 0) //新数量不为零时更新数量 175 | { 176 | _tradeAmount[pos][i] = newAmount; 177 | } 178 | _tradeComs[pos][i]->setAmount(_tradeComs[pos][i]->getAmount() - delta); //更新库存数量 179 | _tradeComs[pos][i]->setSaleCount(_tradeComs[pos][i]->getSaleCount() + delta);//更新商品的销量记录 180 | if (newAmount == 0) //等于0时清除数据 181 | { 182 | _tradeComs[pos].erase(_tradeComs[pos].begin() + i); 183 | _tradePrices[pos].erase(_tradePrices[pos].begin() + i); 184 | _tradeAmount[pos].erase(_tradeAmount[pos].begin() + i); 185 | --i;//有数据删除时指针不移动 186 | } 187 | } 188 | } 189 | if (com != nullptr && noFind) throw runtime_error("未购买该商品"); 190 | } 191 | 192 | void Saler::showRecord(string trid, QTableWidget *table) 193 | { 194 | int pos; 195 | pos = getPosition(trid); 196 | while(table->rowCount()>=1) //清空原行 197 | { 198 | table->removeRow(table->rowCount()-1); 199 | } 200 | int row=table->rowCount(); 201 | if(_tradeComs[pos].size()==0) 202 | { 203 | throw runtime_error("没有该订单"); 204 | } 205 | for(int i=0;i<_tradeComs[pos].size();++i) 206 | { 207 | auto com=_tradeComs[pos][i]; 208 | table->insertRow(row); 209 | QString qNo=com->getNo().c_str(); 210 | table->setItem(row,0,new QTableWidgetItem(qNo)); 211 | table->setItem(row,1,new QTableWidgetItem(com->getName().c_str())); 212 | table->setItem(row,2,new QTableWidgetItem(com->getClassStr().c_str())); 213 | table->setItem(row,3,new QTableWidgetItem(QString::number(_tradePrices[pos][i]))); 214 | table->setItem(row,4,new QTableWidgetItem(QString::number(_tradeAmount[pos][i]))); 215 | double totalPrice = _tradePrices[pos][i]*_tradeAmount[pos][i]; 216 | table->setItem(row,5,new QTableWidgetItem(QString::number(totalPrice))); 217 | ++row; 218 | } 219 | } 220 | 221 | double Saler::getTradeIncome(const string &trid) 222 | { 223 | return _tradeIncome[getPosition(trid)]; 224 | } 225 | 226 | QStringList Saler::getNoList(const string &trid) 227 | { 228 | QStringList noList; 229 | int pos=getPosition(trid); 230 | for(auto com:_tradeComs[pos]) 231 | { 232 | noList<getNo().c_str(); 233 | } 234 | return move(noList); 235 | } 236 | 237 | string Saler::getLastTrid(const string &trid) 238 | { 239 | int pos = this->getPosition(trid); 240 | --pos; 241 | for(;pos>=0;--pos) 242 | { 243 | if(_tradeComs[pos].size()!=0) 244 | { 245 | return _tradeId[pos]; 246 | } 247 | } 248 | throw runtime_error("没有上一条!"); 249 | } 250 | 251 | string Saler::getNextTrid(const string &trid) 252 | { 253 | int pos = this->getPosition(trid); 254 | ++pos; 255 | for(;pos< _tradeComs.size();++pos) 256 | { 257 | if(_tradeComs[pos].size()!=0) 258 | { 259 | return _tradeId[pos]; 260 | } 261 | } 262 | throw runtime_error("没有下一条!"); 263 | } 264 | 265 | string Saler::getFirstId() 266 | { 267 | if(_tradeId.empty()) 268 | { 269 | throw runtime_error("没有交易记录"); 270 | } 271 | for(int i=0;i<_tradeId.size();++i) 272 | { 273 | if(_tradeComs[i].size()!=0) 274 | { 275 | return _tradeId[i]; 276 | } 277 | } 278 | return ""; 279 | } 280 | 281 | 282 | -------------------------------------------------------------------------------- /s/Sorter.cpp: -------------------------------------------------------------------------------- 1 | #include "head/Sorter.h" 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void Sorter::operator()(SortKey key,QTableWidget* comTab) 8 | { 9 | copyComs(); 10 | _sort(key); 11 | while(comTab->rowCount()>=1) 12 | { 13 | comTab->removeRow(comTab->rowCount()-1); 14 | } 15 | for(auto& com:_onSalecoms)//显示排序结果 16 | { 17 | Manager::displayRepCom(com,comTab); 18 | } 19 | } 20 | 21 | void Sorter::copyComs() 22 | { 23 | for (auto& com : _repository) 24 | { 25 | if (com->onSale()) 26 | { 27 | _onSalecoms.push_back(com); 28 | } 29 | } 30 | } 31 | 32 | void Sorter::_sort(SortKey key) 33 | { 34 | function cmp; 35 | 36 | if ((int)key == 0 || (int)key == 1) 37 | { 38 | cmp = [](Commodity* c1, Commodity* c2) 39 | { 40 | return c1->getPrice() < c2->getPrice(); 41 | }; 42 | } 43 | else if ((int)key == 2 || (int)key == 3) 44 | { 45 | cmp = [](Commodity* c1, Commodity* c2) 46 | { 47 | return c1->getAmount() < c2->getAmount(); 48 | }; 49 | } 50 | else if ((int)key == 4 || (int)key == 5) 51 | { 52 | 53 | cmp = [](Commodity* c1, Commodity* c2) 54 | { 55 | return c1->getName() < c2->getName(); 56 | }; 57 | } 58 | else 59 | { 60 | cmp = [](Commodity* c1, Commodity* c2) 61 | { 62 | return c1->getSaleCount() < c2->getSaleCount(); 63 | }; 64 | } 65 | 66 | if ((int)key % 2 == 0) //升序 67 | { 68 | sort(_onSalecoms.begin(), _onSalecoms.end(), cmp); 69 | } 70 | else //降序 71 | { 72 | sort(_onSalecoms.rbegin(), _onSalecoms.rend(), cmp); 73 | } 74 | } 75 | 76 | --------------------------------------------------------------------------------