├── .gitignore ├── rsc └── icon │ ├── logo.png │ ├── open.png │ ├── quit.png │ ├── append.png │ ├── delete.png │ ├── insert.png │ ├── revert.png │ └── submit.png ├── globle.cpp ├── main.cpp ├── globle.h ├── rsc.qrc ├── teacherwindow.h ├── studentwindow.h ├── login.h ├── README.md ├── adminwindow.h ├── EduManager.pro ├── teacherwindow.cpp ├── studentwindow.cpp ├── edumanager.sql ├── login.cpp ├── teacherwindow.ui ├── studentwindow.ui ├── adminwindow.ui ├── login.ui └── adminwindow.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | EduManager.pro.user -------------------------------------------------------------------------------- /rsc/icon/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/logo.png -------------------------------------------------------------------------------- /rsc/icon/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/open.png -------------------------------------------------------------------------------- /rsc/icon/quit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/quit.png -------------------------------------------------------------------------------- /rsc/icon/append.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/append.png -------------------------------------------------------------------------------- /rsc/icon/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/delete.png -------------------------------------------------------------------------------- /rsc/icon/insert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/insert.png -------------------------------------------------------------------------------- /rsc/icon/revert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/revert.png -------------------------------------------------------------------------------- /rsc/icon/submit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeinrw/edumanager/HEAD/rsc/icon/submit.png -------------------------------------------------------------------------------- /globle.cpp: -------------------------------------------------------------------------------- 1 | #include "globle.h" 2 | 3 | QString DB_HOSTNAME="localhost"; 4 | QString DB_USERNAME="root"; 5 | QString DB_PASSWORD="******"; //mysql数据库的密码 6 | QString DB_NAME="edumanager"; 7 | 8 | QString LoginId=""; 9 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "login.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | Login w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /globle.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBLE_H 2 | #define GLOBLE_H 3 | 4 | #include 5 | extern QString DB_HOSTNAME; 6 | extern QString DB_USERNAME; 7 | extern QString DB_PASSWORD; 8 | extern QString DB_NAME; 9 | 10 | extern QString LoginId; 11 | 12 | #endif // GLOBLE_H 13 | -------------------------------------------------------------------------------- /rsc.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | rsc/icon/insert.png 4 | rsc/icon/open.png 5 | rsc/icon/submit.png 6 | rsc/icon/append.png 7 | rsc/icon/delete.png 8 | rsc/icon/quit.png 9 | rsc/icon/revert.png 10 | rsc/icon/logo.png 11 | 12 | 13 | -------------------------------------------------------------------------------- /teacherwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef TEACHERWINDOW_H 2 | #define TEACHERWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "globle.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Ui { 13 | class TeacherWindow; 14 | } 15 | 16 | class TeacherWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit TeacherWindow(QWidget *parent = nullptr); 22 | ~TeacherWindow(); 23 | 24 | 25 | 26 | private slots: 27 | void on_pushButton_clicked(); 28 | 29 | private: 30 | Ui::TeacherWindow *ui; 31 | QSqlDatabase db; 32 | void openTable(); 33 | }; 34 | 35 | #endif // TEACHERWINDOW_H 36 | -------------------------------------------------------------------------------- /studentwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef STUDENTWINDOW_H 2 | #define STUDENTWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "globle.h" 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | namespace Ui { 14 | class StudentWindow; 15 | } 16 | 17 | class StudentWindow : public QMainWindow 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit StudentWindow(QWidget *parent = nullptr); 23 | ~StudentWindow(); 24 | 25 | 26 | 27 | private slots: 28 | void on_btnChange_clicked(); 29 | 30 | private: 31 | Ui::StudentWindow *ui; 32 | QSqlDatabase db; 33 | 34 | void openTable(); 35 | }; 36 | 37 | #endif // STUDENTWINDOW_H 38 | -------------------------------------------------------------------------------- /login.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGIN_H 2 | #define LOGIN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "globle.h" 11 | #include "adminwindow.h" 12 | #include "studentwindow.h" 13 | #include "teacherwindow.h" 14 | 15 | namespace Ui { 16 | class Login; 17 | } 18 | 19 | class Login : public QWidget 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit Login(QWidget *parent = nullptr); 25 | ~Login(); 26 | //连接数据库 27 | bool database_connection(); 28 | 29 | //匹配登陆信息 30 | bool match_name_password(QString ID,QString PASSWORD,QString table); 31 | 32 | private slots: 33 | void on_btnQuit_clicked(); 34 | 35 | void on_btnReset_clicked(); 36 | 37 | void on_btnLogin_clicked(); 38 | 39 | private: 40 | Ui::Login *ui; 41 | QSqlDatabase db; 42 | }; 43 | 44 | #endif // LOGIN_H 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # edumanager 2 | 3 | 基于C++ Qt和Mysql的教务管理系统. 4 | 5 | 软件工程大作业,适合GUI编程和数据库入门. 6 | 7 | * **已经实现的模块(v1.0)** 8 | 9 | 1. 登陆界面 10 | 11 | 2. 管理员的管理界面(功能最为复杂的模块) 12 | 13 | * 可以一次打开4个表 14 | 15 | * 增删改查功能 16 | 17 | 3. 学生和老师模块(功能较为简单,仅仅实现密码修改功能) 18 | 19 | * **待实现的模块(有时间的话......)** 20 | 1. 学生选课模块 21 | 2. 老师录入成绩 22 | 23 | 24 | 25 | --- 26 | 27 | ### NOTICE 28 | 29 | 数据库依赖文件(***edumanager.sql***)的导入方法 30 | 31 | 1. 进入命令行模式,输入以下命令打开mysql命令行 32 | 33 | `mysql -u root -p;` 34 | 35 | 2. 输入数据库密码 36 | 37 | 3. 创建数据库并使用 38 | 39 | `CREATE DATABASE edumanager;` 40 | `USE edumanager;` 41 | 42 | 4. 导入文件 43 | 44 | `SOURCE C:/....... ;` 45 | 46 | 后面为edumanager.sql的绝对路径(记得分号) 47 | 48 | 49 | 50 | 数据库**密码**的修改 51 | 52 | 打开***globle.cpp***修改其中的一行代码 53 | 54 | `QString DB_PASSWORD="******"; //mysql数据库的密码` 55 | 56 | 把其中的\*\*\*\*\*\*修改成你自己MySql数据库的密码 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /adminwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef STUWINDOWS_H 2 | #define STUWINDOWS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "globle.h" 11 | 12 | namespace Ui { 13 | class AdminWindow; 14 | } 15 | 16 | class AdminWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit AdminWindow(QWidget *parent = nullptr); 22 | ~AdminWindow(); 23 | 24 | private slots: 25 | void on_currentChanged(const QModelIndex ¤t,const QModelIndex &previous); 26 | 27 | void on_actOpenDB_triggered(); 28 | 29 | void on_actQuit_triggered(); 30 | 31 | void on_actRecAppend_triggered(); 32 | 33 | void on_actRecDelete_triggered(); 34 | 35 | void on_actRecInsert_triggered(); 36 | 37 | void on_actSubmit_triggered(); 38 | 39 | void on_actRevert_triggered(); 40 | 41 | private: 42 | Ui::AdminWindow *ui; 43 | QSqlDatabase db; 44 | 45 | QSqlTableModel *tabModelStudent; 46 | QItemSelectionModel *theSelectionStudent; 47 | 48 | QSqlTableModel *tabModelTeacher; 49 | QItemSelectionModel *theSelectionTeacher; 50 | 51 | QSqlTableModel *tabModelCourse; 52 | QItemSelectionModel *theSelectionCourse; 53 | 54 | QSqlTableModel *tabModelAdmin; 55 | QItemSelectionModel *theSelectionAdmin; 56 | 57 | void openTable(); 58 | void getFieldNames(); 59 | 60 | }; 61 | 62 | #endif // STUWINDOWS_H 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /EduManager.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-06-03T16:32:24 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui sql 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = EduManager 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | login.cpp \ 30 | globle.cpp \ 31 | studentwindow.cpp \ 32 | adminwindow.cpp \ 33 | teacherwindow.cpp 34 | 35 | HEADERS += \ 36 | login.h \ 37 | globle.h \ 38 | studentwindow.h \ 39 | adminwindow.h \ 40 | teacherwindow.h 41 | 42 | FORMS += \ 43 | login.ui \ 44 | studentwindow.ui \ 45 | adminwindow.ui \ 46 | teacherwindow.ui 47 | 48 | # Default rules for deployment. 49 | qnx: target.path = /tmp/$${TARGET}/bin 50 | else: unix:!android: target.path = /opt/$${TARGET}/bin 51 | !isEmpty(target.path): INSTALLS += target 52 | 53 | RESOURCES += \ 54 | rsc.qrc 55 | -------------------------------------------------------------------------------- /teacherwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "teacherwindow.h" 2 | #include "ui_teacherwindow.h" 3 | 4 | TeacherWindow::TeacherWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::TeacherWindow) 7 | { 8 | ui->setupUi(this); 9 | 10 | this->setWindowTitle("老师面板"); 11 | this->setFixedSize(400,300); 12 | this->setAttribute(Qt::WA_DeleteOnClose);//关闭时释放内存 13 | 14 | openTable(); 15 | } 16 | 17 | TeacherWindow::~TeacherWindow() 18 | { 19 | delete ui; 20 | } 21 | 22 | 23 | void TeacherWindow::openTable() 24 | { 25 | db=QSqlDatabase::addDatabase("QMYSQL"); 26 | 27 | db.setHostName(DB_HOSTNAME); 28 | db.setDatabaseName(DB_NAME); 29 | db.setUserName(DB_USERNAME); 30 | db.setPassword(DB_PASSWORD); 31 | 32 | if(!db.open()) 33 | { 34 | QMessageBox::warning(this,"错误","打开数据库失败,错误信息\n" 35 | +db.lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 36 | return; 37 | } 38 | 39 | QSqlQuery query; 40 | query.prepare("SELECT id,name,password FROM teacher WHERE id=:ID"); 41 | query.bindValue(":ID",LoginId); 42 | query.exec(); 43 | query.first(); 44 | 45 | ui->editId->setText(query.value("id").toString()); 46 | ui->editName->setText(query.value("name").toString()); 47 | ui->editPassword->setText(query.value("password").toString()); 48 | 49 | } 50 | 51 | 52 | 53 | void TeacherWindow::on_pushButton_clicked() 54 | { 55 | QSqlQuery modify; 56 | modify.prepare("UPDATE teacher SET password=? WHERE id=?"); 57 | modify.bindValue(0,ui->editPassword->text()); 58 | modify.bindValue(1,LoginId); 59 | if(modify.exec()) 60 | QMessageBox::information(this, "提示", "密码修改成功"); 61 | else 62 | QMessageBox::warning(this,"错误","修改密码失败,错误信息\n" 63 | +modify.lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 64 | } 65 | -------------------------------------------------------------------------------- /studentwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "studentwindow.h" 2 | #include "ui_studentwindow.h" 3 | #include 4 | 5 | StudentWindow::StudentWindow(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::StudentWindow) 8 | { 9 | ui->setupUi(this); 10 | 11 | this->setWindowTitle("学生面板"); 12 | this->setFixedSize(400,300); 13 | this->setAttribute(Qt::WA_DeleteOnClose);//关闭时释放内存 14 | 15 | openTable(); 16 | 17 | 18 | } 19 | 20 | StudentWindow::~StudentWindow() 21 | { 22 | delete ui; 23 | } 24 | 25 | void StudentWindow::openTable() 26 | { 27 | db=QSqlDatabase::addDatabase("QMYSQL"); 28 | 29 | db.setHostName(DB_HOSTNAME); 30 | db.setDatabaseName(DB_NAME); 31 | db.setUserName(DB_USERNAME); 32 | db.setPassword(DB_PASSWORD); 33 | 34 | if(!db.open()) 35 | { 36 | QMessageBox::warning(this,"错误","打开数据库失败,错误信息\n" 37 | +db.lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 38 | return; 39 | } 40 | 41 | QSqlQuery query; 42 | query.prepare("SELECT id,name,class,password FROM student WHERE id=:ID"); 43 | query.bindValue(":ID",LoginId); 44 | query.exec(); 45 | query.first(); 46 | 47 | ui->editId->setText(query.value("id").toString()); 48 | ui->editClass->setText(query.value("class").toString()); 49 | ui->editName->setText(query.value("name").toString()); 50 | ui->editPassword->setText(query.value("password").toString()); 51 | 52 | } 53 | 54 | 55 | void StudentWindow::on_btnChange_clicked() 56 | { 57 | QSqlQuery modify; 58 | modify.prepare("UPDATE student SET password=? WHERE id=?"); 59 | modify.bindValue(0,ui->editPassword->text()); 60 | modify.bindValue(1,LoginId); 61 | if(modify.exec()) 62 | QMessageBox::information(this, "提示", "密码修改成功"); 63 | else 64 | QMessageBox::warning(this,"错误","修改密码失败,错误信息\n" 65 | +modify.lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /edumanager.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 本地 5 | Source Server Version : 80015 6 | Source Host : localhost:3306 7 | Source Database : edumanager 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 80015 11 | File Encoding : 65001 12 | 13 | Date: 2019-06-03 18:48:08 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for admin 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `admin`; 22 | CREATE TABLE `admin` ( 23 | `id` varchar(255) NOT NULL, 24 | `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 27 | 28 | -- ---------------------------- 29 | -- Records of admin 30 | -- ---------------------------- 31 | INSERT INTO `admin` VALUES ('001', '001'); 32 | INSERT INTO `admin` VALUES ('admin', 'admin'); 33 | 34 | -- ---------------------------- 35 | -- Table structure for course 36 | -- ---------------------------- 37 | DROP TABLE IF EXISTS `course`; 38 | CREATE TABLE `course` ( 39 | `id` varchar(255) NOT NULL, 40 | `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 41 | `teacher` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 42 | PRIMARY KEY (`id`) 43 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 44 | 45 | -- ---------------------------- 46 | -- Records of course 47 | -- ---------------------------- 48 | INSERT INTO `course` VALUES ('001', '高等数学', '李四'); 49 | INSERT INTO `course` VALUES ('002', '线性代数', '张三'); 50 | 51 | -- ---------------------------- 52 | -- Table structure for student 53 | -- ---------------------------- 54 | DROP TABLE IF EXISTS `student`; 55 | CREATE TABLE `student` ( 56 | `id` varchar(255) NOT NULL, 57 | `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 58 | `class` varchar(255) DEFAULT NULL, 59 | `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 60 | PRIMARY KEY (`id`) 61 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 62 | 63 | -- ---------------------------- 64 | -- Records of student 65 | -- ---------------------------- 66 | INSERT INTO `student` VALUES ('A003', '杜兰特', '自动化', '111111'); 67 | INSERT INTO `student` VALUES ('C001', '库里', '高分子', '123456'); 68 | 69 | -- ---------------------------- 70 | -- Table structure for teacher 71 | -- ---------------------------- 72 | DROP TABLE IF EXISTS `teacher`; 73 | CREATE TABLE `teacher` ( 74 | `id` varchar(255) NOT NULL, 75 | `name` varchar(255) NOT NULL, 76 | `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 77 | PRIMARY KEY (`id`) 78 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 79 | 80 | -- ---------------------------- 81 | -- Records of teacher 82 | -- ---------------------------- 83 | INSERT INTO `teacher` VALUES ('023', '张三', '123456'); 84 | INSERT INTO `teacher` VALUES ('045', '李四', '111111'); 85 | -------------------------------------------------------------------------------- /login.cpp: -------------------------------------------------------------------------------- 1 | #include "login.h" 2 | #include "ui_login.h" 3 | 4 | 5 | Login::Login(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::Login) 8 | { 9 | ui->setupUi(this); 10 | 11 | //设置固定大小 12 | this->setFixedSize(500,400); 13 | //设置标题 14 | this->setWindowTitle("教务管理系统"); 15 | 16 | // ui->editPassword->setText("admin"); 17 | // ui->editUsername->setText("admin"); 18 | 19 | ui->rbtnAdmin->setChecked(true); 20 | 21 | if(!database_connection()) 22 | { 23 | QMessageBox::warning(this,"错误","打开数据库失败",QMessageBox::Ok,QMessageBox::NoButton); 24 | } 25 | 26 | } 27 | 28 | Login::~Login() 29 | { 30 | delete ui; 31 | } 32 | 33 | bool Login::database_connection() 34 | { 35 | db=QSqlDatabase::addDatabase("QMYSQL"); 36 | db.setHostName(DB_HOSTNAME); 37 | db.setDatabaseName(DB_NAME); 38 | db.setUserName(DB_USERNAME); 39 | db.setPassword(DB_PASSWORD); 40 | 41 | 42 | if(db.open()) 43 | return true; 44 | else 45 | return false; 46 | 47 | } 48 | 49 | //退出按钮 50 | void Login::on_btnQuit_clicked() 51 | { 52 | this->close(); 53 | } 54 | 55 | //重置按钮 56 | void Login::on_btnReset_clicked() 57 | { 58 | ui->editPassword->clear(); 59 | ui->editUsername->clear(); 60 | } 61 | 62 | //登陆按钮 63 | void Login::on_btnLogin_clicked() 64 | { 65 | QString Id=ui->editUsername->text(); 66 | QString Password=ui->editPassword->text(); 67 | 68 | //管理员登陆 69 | if(ui->rbtnAdmin->isChecked()) 70 | { 71 | if(match_name_password(Id,Password,"admin")) 72 | { 73 | qDebug()<<"管理员登陆成功"; 74 | QMessageBox::information(this, "提示", "管理员登陆成功"); 75 | this->hide(); 76 | AdminWindow *admin=new AdminWindow; 77 | admin->show(); 78 | 79 | } 80 | else 81 | QMessageBox::information(this, "警告", "用户名或密码错误"); 82 | } 83 | 84 | //教师登陆 85 | if(ui->rbtnTeacher->isChecked()) 86 | { 87 | if(match_name_password(Id,Password,"teacher")) 88 | { 89 | LoginId=Id; 90 | qDebug()<<"教师登陆成功"; 91 | QMessageBox::information(this, "提示", "老师登陆成功"); 92 | 93 | this->hide(); 94 | TeacherWindow *teacher=new TeacherWindow; 95 | teacher->show(); 96 | 97 | } 98 | else 99 | QMessageBox::information(this, "警告", "用户名或密码错误"); 100 | } 101 | 102 | //学生登陆 103 | if(ui->rbtnStudent->isChecked()) 104 | { 105 | if(match_name_password(Id,Password,"student")) 106 | { 107 | LoginId=Id; 108 | qDebug()<<"学生登陆成功"; 109 | QMessageBox::information(this, "提示", "学生登陆成功"); 110 | this->hide(); 111 | StudentWindow *student=new StudentWindow; 112 | student->show(); 113 | 114 | } 115 | else 116 | QMessageBox::information(this, "警告", "用户名或密码错误"); 117 | } 118 | 119 | } 120 | 121 | bool Login::match_name_password(QString ID,QString PASSWORD,QString table) 122 | { 123 | QString select="select id,password from "; 124 | QSqlQuery query(db); 125 | 126 | query.exec(select+table); 127 | bool flag=false; 128 | while(query.next()) 129 | { 130 | QString id = query.value(0).toString(); 131 | QString password = query.value(1).toString(); 132 | //qDebug() << id << password ; 133 | if(ID.compare(id)==0 && PASSWORD.compare(password)==0) 134 | flag=true; 135 | } 136 | return flag; 137 | } 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /teacherwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TeacherWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 329 10 | 193 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | :/icon/rsc/icon/logo.png:/icon/rsc/icon/logo.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 工号 28 | 29 | 30 | 31 | 32 | 33 | 34 | Qt::Horizontal 35 | 36 | 37 | QSizePolicy::Fixed 38 | 39 | 40 | 41 | 40 42 | 20 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 姓名 58 | 59 | 60 | 61 | 62 | 63 | 64 | Qt::Horizontal 65 | 66 | 67 | QSizePolicy::Fixed 68 | 69 | 70 | 71 | 40 72 | 20 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 密码 88 | 89 | 90 | 91 | 92 | 93 | 94 | Qt::Horizontal 95 | 96 | 97 | QSizePolicy::Fixed 98 | 99 | 100 | 101 | 40 102 | 20 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | Qt::Horizontal 116 | 117 | 118 | QSizePolicy::Minimum 119 | 120 | 121 | 122 | 40 123 | 20 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 修改 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /studentwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | StudentWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 434 10 | 295 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | :/icon/rsc/icon/logo.png:/icon/rsc/icon/logo.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 学号 28 | 29 | 30 | 31 | 32 | 33 | 34 | Qt::Horizontal 35 | 36 | 37 | QSizePolicy::Minimum 38 | 39 | 40 | 41 | 40 42 | 20 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 姓名 58 | 59 | 60 | 61 | 62 | 63 | 64 | Qt::Horizontal 65 | 66 | 67 | QSizePolicy::Minimum 68 | 69 | 70 | 71 | 40 72 | 20 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 班级 88 | 89 | 90 | 91 | 92 | 93 | 94 | Qt::Horizontal 95 | 96 | 97 | QSizePolicy::Minimum 98 | 99 | 100 | 101 | 40 102 | 20 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 密码 118 | 119 | 120 | 121 | 122 | 123 | 124 | Qt::Horizontal 125 | 126 | 127 | QSizePolicy::Minimum 128 | 129 | 130 | 131 | 40 132 | 20 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | Qt::Horizontal 146 | 147 | 148 | QSizePolicy::Fixed 149 | 150 | 151 | 152 | 50 153 | 20 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 修改 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /adminwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AdminWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 438 10 | 268 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | :/icon/rsc/icon/logo.png:/icon/rsc/icon/logo.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 3 26 | 27 | 28 | 29 | 学生表 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 老师表 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 课程表 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 管理员表 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | toolBar 74 | 75 | 76 | false 77 | 78 | 79 | 80 | 30 81 | 30 82 | 83 | 84 | 85 | Qt::ToolButtonTextBesideIcon 86 | 87 | 88 | false 89 | 90 | 91 | TopToolBarArea 92 | 93 | 94 | false 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | rsc/icon/open.png 110 | :/icon/rsc/icon/open.pngrsc/icon/open.png 111 | 112 | 113 | 打开 114 | 115 | 116 | 打开数据库 117 | 118 | 119 | 120 | 121 | 122 | :/icon/rsc/icon/quit.png:/icon/rsc/icon/quit.png 123 | 124 | 125 | 退出 126 | 127 | 128 | 退出 129 | 130 | 131 | 132 | 133 | 134 | :/icon/rsc/icon/append.png:/icon/rsc/icon/append.png 135 | 136 | 137 | 添加 138 | 139 | 140 | 添加记录 141 | 142 | 143 | 144 | 145 | 146 | :/icon/rsc/icon/insert.png:/icon/rsc/icon/insert.png 147 | 148 | 149 | 插入 150 | 151 | 152 | 插入记录 153 | 154 | 155 | 156 | 157 | 158 | :/icon/rsc/icon/submit.png:/icon/rsc/icon/submit.png 159 | 160 | 161 | 保存 162 | 163 | 164 | 保存修改 165 | 166 | 167 | 168 | 169 | 170 | :/icon/rsc/icon/revert.png:/icon/rsc/icon/revert.png 171 | 172 | 173 | 取消 174 | 175 | 176 | 取消修改 177 | 178 | 179 | 180 | 181 | 182 | :/icon/rsc/icon/delete.png:/icon/rsc/icon/delete.png 183 | 184 | 185 | 删除 186 | 187 | 188 | 删除记录 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /login.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Login 4 | 5 | 6 | 7 | 0 8 | 0 9 | 410 10 | 298 11 | 12 | 13 | 14 | Login 15 | 16 | 17 | 18 | :/icon/rsc/icon/logo.png:/icon/rsc/icon/logo.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Qt::Vertical 27 | 28 | 29 | 30 | 20 31 | 20 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | font: 18pt "Adobe 黑体 Std R"; 40 | 41 | 42 | 教务管理系统 43 | 44 | 45 | Qt::AlignCenter 46 | 47 | 48 | 49 | 50 | 51 | 52 | Qt::Vertical 53 | 54 | 55 | 56 | 20 57 | 30 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Qt::Horizontal 70 | 71 | 72 | 73 | 28 74 | 18 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | Qt::Vertical 83 | 84 | 85 | 86 | 87 | 88 | 89 | 用户名 90 | 91 | 92 | Qt::AlignCenter 93 | 94 | 95 | 96 | 97 | 98 | 99 | 密码 100 | 101 | 102 | Qt::AlignCenter 103 | 104 | 105 | 106 | 107 | 108 | 109 | QLineEdit::Password 110 | 111 | 112 | Qt::LogicalMoveStyle 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Qt::Horizontal 127 | 128 | 129 | QSizePolicy::MinimumExpanding 130 | 131 | 132 | 133 | 10 134 | 20 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | Qt::Vertical 145 | 146 | 147 | 148 | 20 149 | 40 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | Qt::Horizontal 160 | 161 | 162 | 163 | 48 164 | 15 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 学生 173 | 174 | 175 | 176 | 177 | 178 | 179 | 教师 180 | 181 | 182 | 183 | 184 | 185 | 186 | 管理员 187 | 188 | 189 | 190 | 191 | 192 | 193 | Qt::Horizontal 194 | 195 | 196 | 197 | 38 198 | 17 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | Qt::Vertical 209 | 210 | 211 | 212 | 20 213 | 10 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | Qt::Horizontal 224 | 225 | 226 | 227 | 108 228 | 18 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 登陆 237 | 238 | 239 | 240 | 241 | 242 | 243 | 重置 244 | 245 | 246 | 247 | 248 | 249 | 250 | 退出 251 | 252 | 253 | 254 | 255 | 256 | 257 | Qt::Horizontal 258 | 259 | 260 | 261 | 108 262 | 13 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | Qt::Vertical 273 | 274 | 275 | 276 | 20 277 | 40 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /adminwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "adminwindow.h" 2 | #include "ui_adminwindow.h" 3 | 4 | AdminWindow::AdminWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::AdminWindow) 7 | { 8 | ui->setupUi(this); 9 | 10 | this->setWindowTitle("管理员面板"); 11 | this->setFixedSize(800,600); 12 | this->setAttribute(Qt::WA_DeleteOnClose);//关闭时释放内存 13 | ui->tableViewStudent->setSelectionBehavior(QAbstractItemView::SelectItems); 14 | ui->tableViewStudent->setSelectionMode(QAbstractItemView::SingleSelection); 15 | ui->tableViewStudent->setAlternatingRowColors(true); 16 | 17 | ui->tabWidget->setCurrentIndex(0); 18 | 19 | ui->actSubmit->setEnabled(false); 20 | ui->actRevert->setEnabled(false); 21 | ui->actRecAppend->setEnabled(false); 22 | ui->actRecDelete->setEnabled(false); 23 | ui->actRecInsert->setEnabled(false); 24 | 25 | } 26 | 27 | AdminWindow::~AdminWindow() 28 | { 29 | delete ui; 30 | } 31 | 32 | 33 | void AdminWindow::on_currentChanged(const QModelIndex ¤t, const QModelIndex &previous) 34 | { 35 | Q_UNUSED(current); 36 | Q_UNUSED(previous); 37 | 38 | ui->actSubmit->setEnabled(tabModelStudent->isDirty() | 39 | tabModelAdmin->isDirty() | 40 | tabModelCourse->isDirty() | 41 | tabModelTeacher->isDirty()); 42 | ui->actRevert->setEnabled(tabModelStudent->isDirty() | 43 | tabModelAdmin->isDirty() | 44 | tabModelCourse->isDirty() | 45 | tabModelTeacher->isDirty()); 46 | 47 | } 48 | 49 | 50 | //打开数据表 51 | void AdminWindow::on_actOpenDB_triggered() 52 | { 53 | db=QSqlDatabase::addDatabase("QMYSQL"); 54 | 55 | db.setHostName(DB_HOSTNAME); 56 | db.setDatabaseName(DB_NAME); 57 | db.setUserName(DB_USERNAME); 58 | db.setPassword(DB_PASSWORD); 59 | 60 | if(!db.open()) 61 | { 62 | QMessageBox::warning(this,"错误","打开数据库失败,错误信息\n" 63 | +db.lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 64 | 65 | return; 66 | } 67 | openTable(); 68 | 69 | } 70 | 71 | void AdminWindow::openTable() 72 | { 73 | //学生表 74 | tabModelStudent=new QSqlTableModel(this,db); 75 | tabModelStudent->setTable("student"); 76 | tabModelStudent->setEditStrategy(QSqlTableModel::OnManualSubmit); 77 | if(!(tabModelStudent->select())) 78 | { 79 | QMessageBox::critical(this,"错误","打开数据表错误,错误信息\n" 80 | +tabModelStudent->lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 81 | return; 82 | } 83 | tabModelStudent->setHeaderData(tabModelStudent->fieldIndex("id"),Qt::Horizontal,"学号"); 84 | tabModelStudent->setHeaderData(tabModelStudent->fieldIndex("name"),Qt::Horizontal,"姓名"); 85 | tabModelStudent->setHeaderData(tabModelStudent->fieldIndex("class"),Qt::Horizontal,"班级"); 86 | tabModelStudent->setHeaderData(tabModelStudent->fieldIndex("password"),Qt::Horizontal,"密码"); 87 | 88 | theSelectionStudent=new QItemSelectionModel(tabModelStudent); 89 | 90 | ui->tableViewStudent->setModel(tabModelStudent); 91 | ui->tableViewStudent->setSelectionModel(theSelectionStudent); 92 | 93 | 94 | //课程表 95 | tabModelCourse=new QSqlTableModel(this,db); 96 | tabModelCourse->setTable("course"); 97 | tabModelCourse->setEditStrategy(QSqlTableModel::OnManualSubmit); 98 | if(!(tabModelCourse->select())) 99 | { 100 | QMessageBox::critical(this,"错误","打开数据表错误,错误信息\n" 101 | +tabModelCourse->lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 102 | return; 103 | } 104 | tabModelCourse->setHeaderData(tabModelCourse->fieldIndex("id"),Qt::Horizontal,"课程号"); 105 | tabModelCourse->setHeaderData(tabModelCourse->fieldIndex("name"),Qt::Horizontal,"课程名"); 106 | tabModelCourse->setHeaderData(tabModelCourse->fieldIndex("teacher"),Qt::Horizontal,"任课老师"); 107 | 108 | theSelectionCourse=new QItemSelectionModel(tabModelCourse); 109 | 110 | ui->tableViewCourse->setModel(tabModelCourse); 111 | ui->tableViewCourse->setSelectionModel(theSelectionCourse); 112 | 113 | //老师表 114 | tabModelTeacher=new QSqlTableModel(this,db); 115 | tabModelTeacher->setTable("teacher"); 116 | tabModelTeacher->setEditStrategy(QSqlTableModel::OnManualSubmit); 117 | if(!(tabModelTeacher->select())) 118 | { 119 | QMessageBox::critical(this,"错误","打开数据表错误,错误信息\n" 120 | +tabModelTeacher->lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 121 | return; 122 | } 123 | tabModelTeacher->setHeaderData(tabModelTeacher->fieldIndex("id"),Qt::Horizontal,"老师号"); 124 | tabModelTeacher->setHeaderData(tabModelTeacher->fieldIndex("name"),Qt::Horizontal,"姓名"); 125 | tabModelTeacher->setHeaderData(tabModelTeacher->fieldIndex("password"),Qt::Horizontal,"密码"); 126 | 127 | theSelectionTeacher=new QItemSelectionModel(tabModelTeacher); 128 | 129 | ui->tableViewTeacher->setModel(tabModelTeacher); 130 | ui->tableViewTeacher->setSelectionModel(theSelectionTeacher); 131 | 132 | //管理员表 133 | tabModelAdmin=new QSqlTableModel(this,db); 134 | tabModelAdmin->setTable("admin"); 135 | tabModelAdmin->setEditStrategy(QSqlTableModel::OnManualSubmit); 136 | if(!(tabModelAdmin->select())) 137 | { 138 | QMessageBox::critical(this,"错误","打开数据表错误,错误信息\n" 139 | +tabModelAdmin->lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 140 | return; 141 | } 142 | tabModelAdmin->setHeaderData(tabModelAdmin->fieldIndex("id"),Qt::Horizontal,"管理员号"); 143 | tabModelAdmin->setHeaderData(tabModelAdmin->fieldIndex("password"),Qt::Horizontal,"密码"); 144 | 145 | theSelectionAdmin=new QItemSelectionModel(tabModelAdmin); 146 | 147 | ui->tableViewAdmin->setModel(tabModelAdmin); 148 | ui->tableViewAdmin->setSelectionModel(theSelectionAdmin); 149 | 150 | 151 | 152 | //信号和槽函数关联 153 | connect(theSelectionStudent,SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(on_currentChanged(QModelIndex,QModelIndex))); 154 | 155 | connect(theSelectionTeacher,SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(on_currentChanged(QModelIndex,QModelIndex))); 156 | 157 | connect(theSelectionCourse,SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(on_currentChanged(QModelIndex,QModelIndex))); 158 | 159 | connect(theSelectionAdmin,SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(on_currentChanged(QModelIndex,QModelIndex))); 160 | 161 | 162 | // 163 | ui->actSubmit->setEnabled(false); 164 | ui->actRevert->setEnabled(false); 165 | ui->actRecAppend->setEnabled(true); 166 | ui->actRecDelete->setEnabled(true); 167 | ui->actRecInsert->setEnabled(true); 168 | } 169 | 170 | 171 | //退出 172 | void AdminWindow::on_actQuit_triggered() 173 | { 174 | this->close(); 175 | } 176 | 177 | 178 | //添加 179 | void AdminWindow::on_actRecAppend_triggered() 180 | { 181 | switch (ui->tabWidget->currentIndex()) 182 | { 183 | case 0: 184 | tabModelStudent->insertRow(tabModelStudent->rowCount(),QModelIndex()); 185 | // QModelIndex curIndexStudent=tabModelStudent->index(tabModelStudent->rowCount()-1,1); 186 | // theSelectionStudent->clearSelection(); 187 | // theSelectionStudent->setCurrentIndex(curIndexStudent,QItemSelectionModel::Select); 188 | break; 189 | case 1: 190 | tabModelTeacher->insertRow(tabModelTeacher->rowCount(),QModelIndex()); 191 | break; 192 | case 2: 193 | tabModelCourse->insertRow(tabModelCourse->rowCount(),QModelIndex()); 194 | break; 195 | case 3: 196 | tabModelAdmin->insertRow(tabModelAdmin->rowCount(),QModelIndex()); 197 | break; 198 | } 199 | 200 | 201 | ui->actSubmit->setEnabled(true); 202 | ui->actRevert->setEnabled(true); 203 | } 204 | 205 | 206 | void AdminWindow::on_actRecDelete_triggered() 207 | { 208 | switch (ui->tabWidget->currentIndex()) 209 | { 210 | case 0: 211 | tabModelStudent->removeRow(theSelectionStudent->currentIndex().row()); 212 | break; 213 | case 1: 214 | tabModelTeacher->removeRow(theSelectionTeacher->currentIndex().row()); 215 | break; 216 | case 2: 217 | tabModelCourse->removeRow(theSelectionCourse->currentIndex().row()); 218 | break; 219 | case 3: 220 | tabModelAdmin->removeRow(theSelectionAdmin->currentIndex().row()); 221 | break; 222 | } 223 | 224 | 225 | 226 | ui->actSubmit->setEnabled(true); 227 | ui->actRevert->setEnabled(true); 228 | } 229 | 230 | 231 | void AdminWindow::on_actRecInsert_triggered() 232 | { 233 | switch (ui->tabWidget->currentIndex()) 234 | { 235 | case 0: 236 | tabModelStudent->insertRow(ui->tableViewStudent->currentIndex().row()); 237 | break; 238 | case 1: 239 | tabModelTeacher->insertRow(ui->tableViewTeacher->currentIndex().row()); 240 | break; 241 | case 2: 242 | tabModelCourse->insertRow(ui->tableViewCourse->currentIndex().row()); 243 | break; 244 | case 3: 245 | tabModelAdmin->insertRow(ui->tableViewAdmin->currentIndex().row()); 246 | break; 247 | } 248 | 249 | 250 | ui->actSubmit->setEnabled(true); 251 | ui->actRevert->setEnabled(true); 252 | } 253 | 254 | void AdminWindow::on_actSubmit_triggered() 255 | { 256 | bool res=tabModelStudent->submitAll() | tabModelAdmin->submitAll() | tabModelCourse->submitAll() | tabModelTeacher->submitAll(); 257 | if(!res) 258 | { 259 | QMessageBox::information(this,"消息","数据保存错误,错误信息\n" 260 | +tabModelStudent->lastError().text(),QMessageBox::Ok,QMessageBox::NoButton); 261 | } 262 | else 263 | { 264 | QMessageBox::information(this,"消息","保存成功",QMessageBox::Ok,QMessageBox::NoButton); 265 | 266 | ui->actSubmit->setEnabled(false); 267 | ui->actRevert->setEnabled(false); 268 | } 269 | } 270 | 271 | 272 | 273 | void AdminWindow::on_actRevert_triggered() 274 | { 275 | switch (ui->tabWidget->currentIndex()) 276 | { 277 | case 0: 278 | tabModelStudent->revertAll(); 279 | break; 280 | case 1: 281 | tabModelTeacher->revertAll(); 282 | break; 283 | case 2: 284 | tabModelCourse->revertAll(); 285 | break; 286 | case 3: 287 | tabModelTeacher->revertAll(); 288 | break; 289 | 290 | } 291 | 292 | ui->actSubmit->setEnabled(false); 293 | ui->actRevert->setEnabled(false); 294 | } 295 | --------------------------------------------------------------------------------