超市信息管理系统开发文档
源码下及所有文件载链接
演示视频
超市信息管理系统演示视频
一、环境及技术
1、环境
- Qt Creator 5.3
- ODBC Data Sources (32-bit)
- mysql-8.0.28-winx64
- Navicat 15 for MySQL
2、技术
- QT开发
- C++
- mysql
二、项目开发流程
- 数据库设计
- 界面UI设计
- 代码逻辑编写
- 开发文档编写
三、流程介绍
1、数据库设计
1、1数据库代码
/*
Navicat MySQL Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 80028
Source Host : localhost:3306
Source Schema : shop
Target Server Type : MySQL
Target Server Version : 80028
File Encoding : 65001
Date: 06/06/2022 20:30:21
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`id` int NOT NULL COMMENT '商品编号',
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '商品名称',
`num` int NOT NULL COMMENT '商品数量',
`price` double(10, 2) NOT NULL COMMENT '商品价格',
`kind` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '商品种类',
`picture` blob NULL COMMENT '商品图片',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES (1, '可乐', 300, 3.00, '饮料', NULL);
INSERT INTO `goods` VALUES (2, '上衣', 20, 99.00, '服装', NULL);
INSERT INTO `goods` VALUES (3, '大豆油', 300, 55.50, '食品', NULL);
-- ----------------------------
-- Table structure for worker
-- ----------------------------
DROP TABLE IF EXISTS `worker`;
CREATE TABLE `worker` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '职工编号',
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '职工姓名',
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '职工电话',
`usename` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '职工账号',
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '职工密码',
`address` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '职工联系地址',
`picture` blob NULL COMMENT '职工照片',
PRIMARY KEY (`id`) USING BTREE,
CONSTRAINT `id` FOREIGN KEY (`id`) REFERENCES `goods` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of worker
-- ----------------------------
INSERT INTO `worker` VALUES (1, '马师傅', '123', '123', '123', '陕西省西安市', NULL);
INSERT INTO `worker` VALUES (2, '石师傅', '1234', '1234', '1234', '陕西省西安市', NULL);
INSERT INTO `worker` VALUES (3, '野球帝', '12345', '12345', '12345', '陕西省西安市', NULL);
SET FOREIGN_KEY_CHECKS = 1;
1、2 表设计
- goods表
- worker表
1、3 视图
2、界面UI设计
2、1 登录界面
- 效果图
- 结构说明
2、2 系统展示界面
3、代码逻辑编写
3、1 登录逻辑
login.h:
#ifndef LOGIN_H
#define LOGIN_H
#include <QDialog>
#include<QSqlQuery> //查询mysql数据库
#include<QMessageBox>
#include<QCryptographicHash> //包含MD5算法库
#include <QWidget>
#include<QPoint>
namespace Ui {
class Login;
}
class Login : public QDialog
{
Q_OBJECT
public:
explicit Login(QWidget *parent = 0);
~Login();
//鼠标移动
void mouseMoveEvent(QMouseEvent *event);
//鼠标点击
void mousePressEvent(QMouseEvent *event);
//鼠标拖动
void mouseReleaseEvent(QMouseEvent *event);
private slots:
//关闭窗口
void on_pushButton_clicked();
//登录事件
void on_btn_login_clicked();
private:
Ui::Login *ui;
QPoint z;
};
#endif // LOGIN_H
login.cpp:
#include "login.h"
#include "ui_login.h"
#include<QWidget>
#include<QPoint>
#include<QMouseEvent>
#include<QGraphicsDropShadowEffect>
Login::Login(QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
//去掉系统无边框
this->setWindowFlags(Qt::FramelessWindowHint);
//阴影边框效果
QGraphicsDropShadowEffect *shadow =new QGraphicsDropShadowEffect();
shadow->setBlurRadius(20);
shadow->setColor(Qt::black);
shadow->setOffset(0);
ui->showwidget->setGraphicsEffect(shadow);
//设置父窗口为透明
this->setAttribute(Qt::WA_TranslucentBackground);
//用户名焦点
ui->Username->setFocus();
}
Login::~Login()
{
delete ui;
}
//鼠标移动
void Login::mouseMoveEvent(QMouseEvent *event)
{
QWidget::mouseMoveEvent(event);
//鼠标相对于桌面左上角的位置,鼠标的全局位置
QPoint y = event->globalPos();
QPoint x =y-this->z;
this->move(x);
}
//鼠标点击
void Login::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
//鼠标相对于桌面左上角的位置,鼠标的全局位置
QPoint y = event->globalPos();
//窗口左上角相对于桌面左上角的位置
QPoint x =this->geometry().topLeft();
this->z = y-x; //定值
}
//鼠标释放
void Login::mouseReleaseEvent(QMouseEvent *event)
{
QWidget::mouseReleaseEvent(event);
//清空
this->z=QPoint();
}
//关闭窗口
void Login::on_pushButton_clicked()
{
this->close();
}
//登录事件
void Login::on_btn_login_clicked()
{
if(!ui->Password->text().isEmpty()){
QSqlQuery query;
query.exec("select password from worker where usename='" + ui->Username->text()+"'");
query.next();
if(query.value(0).toString()==ui->Password->text()){
//验证通过
QDialog::accept();
}else{
//信息错误弹出警告
QMessageBox::warning(this,tr("密码或账号错误!"),tr("请输入正确的信息"),QMessageBox::Ok);
//清空输入框
ui->Username->clear();
ui->Password->clear();
}
}else{
ui->Password->setFocus();
}
}
3、2 系统功能逻辑
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QMessageBox>
#include<QFileDialog>
#include<QBuffer>
#include<QSqlDatabase> //mysql数据库类
#include<QSqlTableModel> //mysql表模型库
#include<QSqlQuery> //mysql查询类库
#include<QSqlQueryModel>
#include<QTime>
#include<QPixmap> //图形处理类库
#include <QWidget>
#include<QPoint>
#include <QTableView>
#include <QStandardItemModel>
#include<QString>
#include<QTableWidgetItem>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
/*鼠标事件*/
//鼠标移动
void mouseMoveEvent(QMouseEvent *event);
//鼠标点击
void mousePressEvent(QMouseE