♻️ 资源
大小: 9.04MB
➡️ 资源下载:https://download.csdn.net/download/s1t16/87484785
https://download.csdn.net/download/s1t16/87484785
学生信息管理系统
一、需求分析
在科技日益发展的今天,智能化、信息化的学生信息管理系统更方便快捷地统计学生的信息,记录学生信息,对学生信息的变化及时更新,同样也可以使人们实时了解学生成绩的动态,更好地管理学生,更准确地指引学生方向。
设计与分析一个学生信息管理系统,能够对学生的学号、姓名和各科成绩进行统计、处理和更新,并且可以方便学校老师和领导对学生成绩进行整体分析。
二、程序的主要功能
1、使用可视化界面来实现此次 C++ 课程设计
2、能够从数据库输入和输出数据;
将学生的个人信息(学号、姓名、性别、高等数学成绩、大学英语成绩、C 语言课程设计成绩、出生年月、年龄)录入并且同步到 MySQL 数据库并保存。
3、能够对学生信息进行检索操作;
通过输入学生的学号,查找所有符合条件的学生并显示这些学生所有项目的信息。
4、具有增、删、改信息的功能;
能通过界面指示录入信息,通过学号查找学生信息,之后能在系统内将学生的信息进行修改以及按照科目删除学生成绩条目或者直接删除该学生相关所有信息。
5、能够对学生的成绩从高到低排序;
通过某个条目,将所有学生的信息按照该条目数值的降序或者升序进行排序。
三、程序运行平台
Visual studio 2017 Professional
Qt 5.12.2
MySQL 8.0.15
运行程序“GuiApplication.exe”,进入学生信息管理系统欢迎界面如下

一、点击“Enter| 进入”进入功能选择界面,点击“退出系统退出”:

点击“1.录入学生成绩”进入录入学生信息模块:

点击“2.删除学生信息”进入删除学生信息模块:

点击“3.修改学生信息”进入修改学生信息模块

点击“4.显示全部学生信息”进入显示学生信息模块:

点击“5.计算平均成绩”进入显示平均成绩模块:

点击“6.查询学生信息”进入查询学生信息模块:

点击“7.按单科成绩排序”进入学生信息排序模块:

四、 系统总框架图

五、程序类的说明
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString strPath = QApplication::applicationDirPath();
strPath = strPath + "tobiichi_origami.png";
a.setWindowIcon(QIcon(strPath));
GuiApplication w;
w.show();
return a.exec();
}
main()函数是程序的入口。几乎在使用 Qt 的所有情况下,main()只需要在把控制转交给 Qt
库之前执行一些初始化,然后 Qt 库通过事件来向程序告知用户的行为。
argc 是命令行变量的数量,argv 是命令行变量的数组。这是一个 C/C++ 特征。它不是 Qt
专有的,无论如何 Qt 需要处理这些变量 QApplication a( argc, argv );的话。
a 是这个程序的 QApplication。它在这里被创建并且处理这些命令行变量(比如在 X 窗口下的-display)。请注意,所有被 Qt 识别的命令行参数都会从 argv 中被移(并且 argc 也因此而减少)。
w.show();
创建一个窗口部件的时候,它是不可见的。必须调用 show()来使它变为可见的。
main()把控制转交给 Qt,并且当应用程序退出的时候 exec()就会返回。在 exec()中,Qt 接受并处理用户和系统的事件并且把它们传递给适当的窗口部件。
六、模块分析
- 添加模块
系统将提示用户输入新添加的航班的信息,插入在 MySQL 数据中
- 功能选择模块
功能显示模块将显示所有可以操作的功能按钮。
- 查找模块
首先由用户输入要查找学生的学号,然后系统用查找函数查找,并且输出再界面指定位置,输出所查找的学生信息。
- 删除模块
首先由用户输入要删除的学生学号,然后依据情况来选择删除该人或是仅删除一项或者几项成绩,或是直接删除该生的所有信息。
- 显示所有模块
系统将会把所有学生的的信息显示出来。
- 成绩排序模块
程序可以按照某一指定成绩进行升序或者降序排序。
- 学生信息修改模块
首先由用户输入要查找学生的学号,然后系统用查找函数查找,并且输出再界面指定位置,根据用户需要自行进行修改。
七、比较有特色的函数
初始化数据库连接并且利用出生年月算年龄
void FormHomePage::ConnectMysql()
{
QSqlDatabase db = InitMySql();//初始化数据库句柄
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}//确认是否连接成功
QSqlQuery query("SELECT studentinformation.`出生年月` ,studentinformation.`学号` FROM `password`.`studentinformation` LIMIT 0,1000");
while (query.next())
{
QString temp = query.value(0).toString();
QString temp2 = query.value(1).toString();
//qDebug() << query.value(0).toString();
string str = temp.toStdString();
str.erase(4, 1);//除去第一个-
str.erase(6, 1);//除去第二个-
int num = atoi(str.c_str());
int temp44 = int((20190428-num)/10000);
string temp3 = to_string(temp44);
QString q_str = QString::fromStdString(temp3);
QSqlQuery query("UPDATE `password`.`studentinformation` SET `年龄` = '"
+ q_str +
"' WHERE `学号` = '"+temp2+"'");
}
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
while (query.next())
{
/*qDebug() << query.value(0).toString();*/
}
QSqlQuery query1("select *from `password`.`studentinformation`");
while (query1.next())
{
/*qDebug() << query1.value(0).toString() << query1.value(1).toString();*/
}
db.close();
}
else
{
qDebug() << "fail";
}
}
初始化数据库函数
QSqlDatabase FormHomePage::InitMySql()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}
return db;
}
在工程中加载了.rc 文件来实现应用程序的图标的设置
Qrc.rc 文件中代码如下
IDI_ICON1 ICON DISCARDABLE "origami.ico"
其中 origami.ico 已经提前放入程序根目录下。
说明:连接了本地的 MySQL 数据库,从数据库中进行数据的读取,读取数据库中表头设置对 qt 界面的 tableview 进行表头的初始化,之后遍历数据库中 studentinformation 表中数据填入表格进行显示。使得输出全部学生信息变得更加方便,从而减少了代码的复杂度。
在年龄的计算方面,抽取数据库中的年龄列的值存在 Qstring 中,然后强制类型转换为 string 类型,用 erase 函数剔除出生年月中的-,再转换为 int 类型计算,计算完成后转为 string 再转为 Qstring,使用 SQL 语句再录入进数据库中显示输出。
八、程序源代码
此部分含有头文件代码,cpp 文件,部分界面生成代码,PHP 网页代码
头文件代码:
CalculationPage.h
# pragma once
# include <QWidget>
# include "ui_CalculationPage.h"
class CalculationPage : public QWidget
{
Q_OBJECT
public:
CalculationPage(QWidget *parent = Q_NULLPTR);
~CalculationPage();
void CalculatingGrades();
private:
Ui::CalculationPage ui;
};
DeletePage.h
# pragma once
# include <QWidget>
# include "ui_DeletePage.h"
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
class DeletePage : public QWidget
{
Q_OBJECT
public:
DeletePage(QWidget *parent = Q_NULLPTR);
~DeletePage();
private Q_SLOT:
void DataSearch();
void DataDelete();
void DeletePeople();
private:
Ui::DeletePage ui;
};
EntryPage.h
# pragma once
# include <QWidget>
# include "ui_EntryPage.h"
class EntryPage : public QWidget
{
Q_OBJECT
public:
EntryPage(QWidget *parent = Q_NULLPTR);
~EntryPage();
private Q_SLOT:
void ConfirmEntry();
private:
Ui::EntryPage ui;
};
FormHomePage.h
# pragma once
# include <QWidget>
# include "ui_FormHomePage.h"
# include <QtSql>
class FormHomePage : public QWidget
{
Q_OBJECT
public:
FormHomePage(QWidget *parent = Q_NULLPTR);
~FormHomePage();
private Q_SLOT:
void ConnectMysql();
QSqlDatabase InitMySql();
private:
Ui::FormHomePage ui;
QSqlDatabase db;
};
GuiApplication.h
# pragma once
# include <QtWidgets/QMainWindow>
# include "ui_GuiApplication.h"
# include "StudentMenu.h"
# include <QtSql>
namespace Ui
{
class GuiApplication;
}
class GuiApplication : public QMainWindow
{
Q_OBJECT
public:
GuiApplication(QWidget *parent = Q_NULLPTR);
private Q_SLOT:
void condButtonPressed();
private:
Ui::GuiApplicationClass ui;
StudentMenu *view;
//QSqlDatabase db;//数据库句柄
//void InitMySql();//初始化数据库
};
RankPage.h
# pragma once
# include <QWidget>
# include "ui_RankPage.h"
class RankPage : public QWidget
{
Q_OBJECT
public:
RankPage(QWidget *parent = Q_NULLPTR);
~RankPage();
private Q_SLOT:
void RankDesign();
void RankMath();
void RankEnglish();
void RankDesignDown();
void RankMathDown();
void RankEnglishDown();
private:
Ui::RankPage ui;
};
RevisePage.h
# pragma once
# include <QWidget>
# include "ui_RevisePage.h"
class RevisePage : public QWidget
{
Q_OBJECT
public:
RevisePage(QWidget *parent = Q_NULLPTR);
~RevisePage();
private Q_SLOT:
void DateSearch();
void DataRevise();
private:
Ui::RevisePage ui;
};
SearchPage.h
# pragma once
# include <QWidget>
# include "ui_SearchPage.h"
class SearchPage : public QWidget
{
Q_OBJECT
public:
SearchPage(QWidget *parent = Q_NULLPTR);
~SearchPage();
private Q_SLOT:
void DataSearch();
private:
Ui::SearchPage ui;
};
StudentMenu.h
# pragma once
# include <QWidget>
# include "ui_SearchPage.h"
class SearchPage : public QWidget
{
Q_OBJECT
public:
SearchPage(QWidget *parent = Q_NULLPTR);
~SearchPage();
private Q_SLOT:
void DataSearch();
private:
Ui::SearchPage ui;
};
Ui 界面设计代码
Ui_DeletePage.h
# ifndef UI_DELETEPAGE_H
# define UI_DELETEPAGE_H
# include <QtCore/QVariant>
# include <QtWidgets/QApplication>
# include <QtWidgets/QCheckBox>
# include <QtWidgets/QLabel>
# include <QtWidgets/QLineEdit>
# include <QtWidgets/QPushButton>
# include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_DeletePage
{
public:
QLabel *label;
QLineEdit *lineEdit;
QLabel *label_2;
QLabel *label_3;
QLabel *label_4;
QLabel *label_5;
QLabel *label_6;
QLabel *label_7;
QLabel *label_8;
QLabel *label_9;
QLabel *label_10;
QPushButton *SearchButton;
QPushButton *pushButton_2;
QPushButton *deleteButton;
QCheckBox *checkBox;
QCheckBox *checkBox_2;
QCheckBox *checkBox_3;
QLabel *label_11;
QLabel *label_12;
QLabel *label_13;
QLabel *label_14;
QLabel *label_15;
QLabel *label_16;
QLabel *label_17;
QLabel *label_18;
QPushButton *pushButton;
QLabel *label_19;
void setupUi(QWidget *DeletePage)
{
if (DeletePage->objectName().isEmpty())
DeletePage->setObjectName(QString::fromUtf8("DeletePage"));
DeletePage->resize(922, 590);
label = new QLabel(DeletePage);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(180, 60, 221, 41));
label->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
lineEdit = new QLineEdit(DeletePage);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(430, 60, 151, 31));
lineEdit->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_2 = new QLabel(DeletePage);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(70, 120, 191, 51));
label_2->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_3 = new QLabel(DeletePage);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(120, 190, 101, 41));
label_3->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_4 = new QLabel(DeletePage);
label_4->setObjectName(QString::fromUtf8("label_4"));
label_4->setGeometry(QRect(120, 340, 81, 51));
label_4->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_5 = new QLabel(DeletePage);
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setGeometry(QRect(120, 260, 81, 41));
label_5->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_6 = new QLabel(DeletePage);
label_6->setObjectName(QString::fromUtf8("label_6"));
label_6->setGeometry(QRect(120, 420, 101, 41));
label_6->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_7 = new QLabel(DeletePage);
label_7->setObjectName(QString::fromUtf8("label_7"));
label_7->setGeometry(QRect(120, 490, 111, 51));
label_7->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_8 = new QLabel(DeletePage);
label_8->setObjectName(QString::fromUtf8("label_8"));
label_8->setGeometry(QRect(440, 180, 171, 61));
label_8->setMouseTracking(false);
label_8->setTabletTracking(false);
label_8->setAcceptDrops(false);
label_8->setAutoFillBackground(false);
label_8->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_8->setScaledContents(false);
label_8->setWordWrap(false);
label_8->setOpenExternalLinks(false);
label_9 = new QLabel(DeletePage);
label_9->setObjectName(QString::fromUtf8("label_9"));
label_9->setGeometry(QRect(440, 260, 111, 51));
label_9->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_10 = new QLabel(DeletePage);
label_10->setObjectName(QString::fromUtf8("label_10"));
label_10->setGeometry(QRect(440, 360, 111, 41));
label_10->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
SearchButton = new QPushButton(DeletePage);
SearchButton->setObjectName(QString::fromUtf8("SearchButton"));
SearchButton->setGeometry(QRect(610, 60, 121, 31));
SearchButton->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
pushButton_2 = new QPushButton(DeletePage);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(730, 530, 131, 31));
pushButton_2->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
deleteButton = new QPushButton(DeletePage);
deleteButton->setObjectName(QString::fromUtf8("deleteButton"));
deleteButton->setGeometry(QRect(560, 530, 131, 31));
deleteButton->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
checkBox = new QCheckBox(DeletePage);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setGeometry(QRect(800, 200, 81, 31));
checkBox->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
checkBox_2 = new QCheckBox(DeletePage);
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
checkBox_2->setGeometry(QRect(800, 280, 71, 16));
checkBox_2->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
checkBox_3 = new QCheckBox(DeletePage);
checkBox_3->setObjectName(QString::fromUtf8("checkBox_3"));
checkBox_3->setGeometry(QRect(800, 380, 71, 16));
checkBox_3->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_11 = new QLabel(DeletePage);
label_11->setObjectName(QString::fromUtf8("label_11"));
label_11->setGeometry(QRect(280, 180, 111, 61));
label_11->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_12 = new QLabel(DeletePage);
label_12->setObjectName(QString::fromUtf8("label_12"));
label_12->setGeometry(QRect(280, 260, 121, 51));
label_12->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_13 = new QLabel(DeletePage);
label_13->setObjectName(QString::fromUtf8("label_13"));
label_13->setGeometry(QRect(280, 340, 101, 51));
label_13->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_14 = new QLabel(DeletePage);
label_14->setObjectName(QString::fromUtf8("label_14"));
label_14->setGeometry(QRect(280, 420, 101, 51));
label_14->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_15 = new QLabel(DeletePage);
label_15->setObjectName(QString::fromUtf8("label_15"));
label_15->setGeometry(QRect(280, 490, 101, 51));
label_15->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_16 = new QLabel(DeletePage);
label_16->setObjectName(QString::fromUtf8("label_16"));
label_16->setGeometry(QRect(640, 190, 111, 51));
label_16->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_17 = new QLabel(DeletePage);
label_17->setObjectName(QString::fromUtf8("label_17"));
label_17->setGeometry(QRect(640, 260, 111, 51));
label_17->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_18 = new QLabel(DeletePage);
label_18->setObjectName(QString::fromUtf8("label_18"));
label_18->setGeometry(QRect(640, 360, 101, 51));
label_18->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
pushButton = new QPushButton(DeletePage);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(390, 530, 131, 31));
pushButton->setStyleSheet(QString::fromUtf8("font: 14pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_19 = new QLabel(DeletePage);
label_19->setObjectName(QString::fromUtf8("label_19"));
label_19->setGeometry(QRect(-10, -10, 951, 621));
label_19->setPixmap(QPixmap(QString::fromUtf8("background.jpg")));
label_19->raise();
label->raise();
lineEdit->raise();
label_2->raise();
label_3->raise();
label_4->raise();
label_5->raise();
label_6->raise();
label_7->raise();
label_8->raise();
label_9->raise();
label_10->raise();
SearchButton->raise();
pushButton_2->raise();
deleteButton->raise();
checkBox->raise();
checkBox_2->raise();
checkBox_3->raise();
label_11->raise();
label_12->raise();
label_13->raise();
label_14->raise();
label_15->raise();
label_16->raise();
label_17->raise();
label_18->raise();
pushButton->raise();
QWidget::setTabOrder(lineEdit, SearchButton);
QWidget::setTabOrder(SearchButton, checkBox);
QWidget::setTabOrder(checkBox, checkBox_2);
QWidget::setTabOrder(checkBox_2, checkBox_3);
QWidget::setTabOrder(checkBox_3, deleteButton);
QWidget::setTabOrder(deleteButton, pushButton_2);
retranslateUi(DeletePage);
QMetaObject::connectSlotsByName(DeletePage);
} // setupUi
void retranslateUi(QWidget *DeletePage)
{
DeletePage->setWindowTitle(QApplication::translate("DeletePage", "DeletePage", nullptr));
label->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_2->setText(QApplication::translate("DeletePage", "\344\273\245\344\270\213\346\230\257\344\275\240\346\237\245\350\257\242\345\210\260\347\273\223\346\236\234\357\274\232", nullptr));
label_3->setText(QApplication::translate("DeletePage", "\345\255\246\345\217\267", nullptr));
label_4->setText(QApplication::translate("DeletePage", "\346\200\247\345\210\253", nullptr));
label_5->setText(QApplication::translate("DeletePage", "\345\247\223\345\220\215", nullptr));
label_6->setText(QApplication::translate("DeletePage", "\345\207\272\347\224\237\346\227\245\346\234\237", nullptr));
label_7->setText(QApplication::translate("DeletePage", "\345\271\264\351\276\204", nullptr));
label_8->setText(QApplication::translate("DeletePage", "C\350\257\255\350\250\200\350\257\276\347\250\213\350\256\276\350\256\241\346\210\220\347\273\251", nullptr));
label_9->setText(QApplication::translate("DeletePage", "\351\253\230\347\255\211\346\225\260\345\255\246\346\210\220\347\273\251", nullptr));
label_10->setText(QApplication::translate("DeletePage", "\345\244\247\345\255\246\350\213\261\350\257\255\346\210\220\347\273\251", nullptr));
SearchButton->setText(QApplication::translate("DeletePage", "\346\237\245\346\211\276", nullptr));
pushButton_2->setText(QString());
deleteButton->setText(QApplication::translate("DeletePage", "\345\210\240\351\231\244\351\200\211\344\270\255\351\241\271\347\233\256", nullptr));
checkBox->setText(QString());
checkBox_2->setText(QString());
checkBox_3->setText(QString());
label_11->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_12->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_13->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_14->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_15->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_16->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_17->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
label_18->setText(QApplication::translate("DeletePage", "TextLabel", nullptr));
pushButton->setText(QApplication::translate("DeletePage", "\345\210\240\351\231\244\346\255\244\344\272\272", nullptr));
label_19->setText(QString());
} // retranslateUi
};
namespace Ui {
class DeletePage: public Ui_DeletePage {};
} // namespace Ui
QT_END_NAMESPACE
# endif // UI_DELETEPAGE_H
Ui_StudentMenu.h
# ifndef UI_STUDENTMENU_H
# define UI_STUDENTMENU_H
# include <QtCore/QVariant>
# include <QtWidgets/QApplication>
# include <QtWidgets/QLabel>
# include <QtWidgets/QPushButton>
# include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_StudentMenu
{
public:
QPushButton *EntryButton;
QPushButton *DeleteButton;
QPushButton *ReviseButton;
QPushButton *DisPlayButton;
QPushButton *CalculationButton;
QPushButton *SearchButton;
QPushButton *RankButton;
QPushButton *Exit;
QLabel *label_2;
QLabel *label_3;
void setupUi(QWidget *StudentMenu)
{
if (StudentMenu->objectName().isEmpty())
StudentMenu->setObjectName(QString::fromUtf8("StudentMenu"));
StudentMenu->resize(910, 581);
EntryButton = new QPushButton(StudentMenu);
EntryButton->setObjectName(QString::fromUtf8("EntryButton"));
EntryButton->setGeometry(QRect(280, 130, 301, 41));
EntryButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
DeleteButton = new QPushButton(StudentMenu);
DeleteButton->setObjectName(QString::fromUtf8("DeleteButton"));
DeleteButton->setGeometry(QRect(280, 180, 301, 41));
DeleteButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
ReviseButton = new QPushButton(StudentMenu);
ReviseButton->setObjectName(QString::fromUtf8("ReviseButton"));
ReviseButton->setGeometry(QRect(280, 230, 301, 41));
ReviseButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
DisPlayButton = new QPushButton(StudentMenu);
DisPlayButton->setObjectName(QString::fromUtf8("DisPlayButton"));
DisPlayButton->setGeometry(QRect(280, 280, 301, 41));
DisPlayButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
CalculationButton = new QPushButton(StudentMenu);
CalculationButton->setObjectName(QString::fromUtf8("CalculationButton"));
CalculationButton->setGeometry(QRect(280, 330, 301, 41));
CalculationButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
SearchButton = new QPushButton(StudentMenu);
SearchButton->setObjectName(QString::fromUtf8("SearchButton"));
SearchButton->setGeometry(QRect(280, 380, 301, 41));
SearchButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
RankButton = new QPushButton(StudentMenu);
RankButton->setObjectName(QString::fromUtf8("RankButton"));
RankButton->setGeometry(QRect(280, 430, 301, 41));
RankButton->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
Exit = new QPushButton(StudentMenu);
Exit->setObjectName(QString::fromUtf8("Exit"));
Exit->setGeometry(QRect(710, 510, 141, 31));
Exit->setStyleSheet(QString::fromUtf8("font: 16pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_2 = new QLabel(StudentMenu);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(250, 40, 431, 71));
label_2->setStyleSheet(QString::fromUtf8("font: 30pt \"\345\215\216\346\226\207\346\245\267\344\275\223\";"));
label_3 = new QLabel(StudentMenu);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(-10, -10, 931, 591));
label_3->setPixmap(QPixmap(QString::fromUtf8("../../QtGuiApplication/QtGuiApplication1/normal background.jpg")));
label_3->setScaledContents(true);
label_3->raise();
EntryButton->raise();
DeleteButton->raise();
ReviseButton->raise();
DisPlayButton->raise();
CalculationButton->raise();
SearchButton->raise();
RankButton->raise();
Exit->raise();
label_2->raise();
retranslateUi(StudentMenu);
QMetaObject::connectSlotsByName(StudentMenu);
} // setupUi
void retranslateUi(QWidget *StudentMenu)
{
StudentMenu->setWindowTitle(QApplication::translate("StudentMenu", "StudentMenu", nullptr));
EntryButton->setText(QApplication::translate("StudentMenu", "1.\345\275\225\345\205\245\345\255\246\347\224\237\346\210\220\347\273\251", nullptr));
DeleteButton->setText(QApplication::translate("StudentMenu", "2.\345\210\240\351\231\244\345\255\246\347\224\237\346\210\220\347\273\251", nullptr));
ReviseButton->setText(QApplication::translate("StudentMenu", "3.\344\277\256\346\224\271\345\255\246\347\224\237\346\210\220\347\273\251", nullptr));
DisPlayButton->setText(QApplication::translate("StudentMenu", "4.\346\230\276\347\244\272\345\205\250\351\203\250\345\255\246\347\224\237\344\277\241\346\201\257", nullptr));
CalculationButton->setText(QApplication::translate("StudentMenu", "5.\350\256\241\347\256\227\345\271\263\345\235\207\346\210\220\347\273\251", nullptr));
SearchButton->setText(QApplication::translate("StudentMenu", "6.\346\237\245\350\257\242\345\255\246\347\224\237\344\277\241\346\201\257", nullptr));
RankButton->setText(QApplication::translate("StudentMenu", "7.\346\214\211\345\215\225\347\247\221\346\210\220\347\273\251\346\216\222\345\272\217", nullptr));
Exit->setText(QApplication::translate("StudentMenu", "Exit", nullptr));
label_2->setText(QApplication::translate("StudentMenu", "\345\255\246\347\224\237\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237\350\217\234\345\215\225", nullptr));
label_3->setText(QString());
} // retranslateUi
};
namespace Ui {
class StudentMenu: public Ui_StudentMenu {};
} // namespace Ui
QT_END_NAMESPACE
# endif // UI_STUDENTMENU_H
Ui 界面代码过于繁长,不全在此报告中展示
cpp 代码
CalculationPage.cpp
# include "CalculationPage.h"
# include <qsqlquery.h>
# include <qdebug.h>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
CalculationPage::CalculationPage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.pushButton->setText("返回上一级");
CalculatingGrades();
//connect(ui.pushButton_2, &QPushButton::clicked, this, &CalculationPage::CalculatingGrades);
connect(ui.pushButton, &QPushButton::clicked, this, &CalculationPage::close);
}
void CalculationPage::CalculatingGrades()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
QString temp2 = "SELECT AVG(`高等数学成绩`) AS OrderAverage FROM `password`.`studentinformation`";
QSqlQuery query2(temp2);
while (query2.next())
{
QString temp3 = query2.value(0).toString();
ui.label_5->setText(temp3);
}
QString temp = "SELECT AVG(`C语言程序设计成绩`) AS OrderAverage FROM `password`.`studentinformation`";
QSqlQuery query1(temp);
while (query1.next())
{
QString temp1 = query1.value(0).toString();
ui.label_3->setText(temp1);
}
QString temp4 = "SELECT AVG(`大学英语成绩`) AS OrderAverage FROM `password`.`studentinformation`";
QSqlQuery query3(temp4);
while (query3.next())
{
QString temp5 = query3.value(0).toString();
ui.label_7->setText(temp5);
}
}
CalculationPage::~CalculationPage()
{
}
DeletePage.cpp
# include "DeletePage.h"
# include <qmessagebox.h>
# include <qdebug.h>
# include <string>
# include <QSqlQuery>
# include "FormHomePage.h"
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
using namespace std;
DeletePage::DeletePage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.label->setText("请输入要查询的学号:");
ui.pushButton_2->setText("返回上一级");
ui.lineEdit->setText("");
ui.label_11->setText("");
ui.label_12->setText("");
ui.label_13->setText("");
ui.label_14->setText("");
ui.label_15->setText("");
ui.label_16->setText("");
ui.label_17->setText("");
ui.label_18->setText("");
connect(ui.pushButton_2, &QPushButton::clicked, this, &DeletePage::close);
connect(ui.SearchButton, &QPushButton::clicked, this, &DeletePage::DataSearch);
connect(ui.deleteButton, &QPushButton::clicked, this, &DeletePage::DataDelete);
connect(ui.pushButton, &QPushButton::clicked, this, &DeletePage::DeletePeople);
}
void DeletePage::DataSearch()
{
qDebug() << "OK";
QString num = ui.lineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}
//以上为初始化数据连接
int flag = 0;
if (num.length())
{
QString temp_qt = "select *from `password`.`studentinformation`WHERE studentinformation.`学号`=" + num;
QSqlQuery query1(temp_qt);
ui.label_11->setText("no data");
ui.label_12->setText("no data");
ui.label_13->setText("no data");
ui.label_14->setText("no data");
ui.label_15->setText("no data");
ui.label_16->setText("no data");
ui.label_17->setText("no data");
ui.label_18->setText("no data");
while (query1.next())
{
/*qDebug() << query1.value(0).toString() << query1.value(1).toString();*/
ui.label_11->setText(query1.value(0).toString());
ui.label_12->setText(query1.value(1).toString());
ui.label_13->setText(query1.value(2).toString());
ui.label_14->setText(query1.value(6).toString());
ui.label_15->setText(query1.value(7).toString());
ui.label_16->setText(query1.value(3).toString());
ui.label_17->setText(query1.value(4).toString());
ui.label_18->setText(query1.value(5).toString());
flag = 1;
}
if (flag == 0)
{
QMessageBox::warning(this, tr("Warning!"), tr(" 不存在该信息! "));
}
}
else
{
QMessageBox::warning(this, tr("Warning!"), tr(" 学号不能为空!"));
}
}
void DeletePage::DataDelete()
{
QString temp_qt = "UPDATE `password`.`studentinformation` SET";
int flag = 0;
if (ui.checkBox->isChecked() == true)
{
if (flag == 0)
{
temp_qt = temp_qt + "`C语言程序设计成绩` = ''";
flag = 1;
}
}
if(ui.checkBox_2->isChecked() == true)
{
if (flag == 0)
{
temp_qt = temp_qt + "`高等数学成绩` = ''";
flag = 1;
}
else
{
temp_qt = temp_qt + ",`高等数学成绩` = ''";
}
}
if (ui.checkBox_3->isChecked() == true)
{
if (flag == 0)
{
temp_qt = temp_qt + "`大学英语成绩` = ''";
flag = 1;
}
else
{
temp_qt = temp_qt + ",`大学英语成绩` = ''";
}
}
temp_qt = temp_qt + " WHERE `学号` = " + ui.label_11->text();
QSqlQuery query1(temp_qt);
}
void DeletePage::DeletePeople()
{
QString temp_qt = "DELETE FROM `password`.`studentinformation` WHERE `学号` = "+ ui.label_11->text();
QSqlQuery query1(temp_qt);
}
DeletePage::~DeletePage()
{
}
EntryPage.cpp
# include "EntryPage.h"
# include <QSqlQuery>
# include <QtSql>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
EntryPage::EntryPage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.Exit->setText("返回上一级");
ui.ConfirmButton->setText("确认录入");
connect(ui.Exit, &QPushButton::clicked, this, &EntryPage::close);
connect(ui.ConfirmButton, &QPushButton::clicked, this, &EntryPage::ConfirmEntry);
}
void EntryPage::ConfirmEntry()
{
QString num = ui.lineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
//QString number = ;
//QString name = ui.lineEdit_2->text();
//QString sex = ;
//QString birthday = ui.lineEdit_4->text();
//QString age = ui.lineEdit_5->text();
//QString cscore = ui.lineEdit_6->text();
//QString math = ui.lineEdit_7->text();
//QString english = ui.lineEdit_8->text();
QString temp = "INSERT INTO `password`.`studentinformation`(`学号`, `姓名`, `性别`, `C语言程序设计成绩`, `高等数学成绩`, `大学英语成绩`, `出生年月`, `年龄`)VALUES ( ";
temp = temp + "'" + ui.lineEdit->text() + "'" + ","
+ "'" + ui.lineEdit_2->text() + "'" + ","
+ "'" + ui.lineEdit_3->text() + "'" + ","
+ "'" + ui.lineEdit_4->text() + "'" + ","
+ "'" + ui.lineEdit_5->text() + "'" + ","
+ "'" + ui.lineEdit_6->text() + "'" + ","
+ "'" + ui.lineEdit_7->text() + "'" + ","
+ "'" + ui.lineEdit_8->text() + "'" + ")";
QSqlQuery query1(temp);
}
EntryPage::~EntryPage()
{
}
FormHomePage.cpp
# include "FormHomePage.h"
# include <string>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
using namespace std;
FormHomePage::FormHomePage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.pushButton->setText("返回上一级");
ConnectMysql();
connect(ui.pushButton, &QPushButton::clicked, this, &FormHomePage::close);
connect(ui.pushButton_2, &QPushButton::clicked, this, &FormHomePage::ConnectMysql);
}
void FormHomePage::ConnectMysql()
{
QSqlDatabase db = InitMySql();//初始化数据库句柄
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}//确认是否连接成功
QSqlQuery query("SELECT studentinformation.`出生年月` ,studentinformation.`学号` FROM `password`.`studentinformation` LIMIT 0,1000");
while (query.next())
{
QString temp = query.value(0).toString();
QString temp2 = query.value(1).toString();
//qDebug() << query.value(0).toString();
string str = temp.toStdString();
str.erase(4, 1);//除去第一个-
str.erase(6, 1);//除去第二个-
int num = atoi(str.c_str());
int temp44 = int((20190428-num)/10000);
string temp3 = to_string(temp44);
QString q_str = QString::fromStdString(temp3);
QSqlQuery query("UPDATE `password`.`studentinformation` SET `年龄` = '"
+ q_str +
"' WHERE `学号` = '"+temp2+"'");
}
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
while (query.next())
{
/*qDebug() << query.value(0).toString();*/
}
QSqlQuery query1("select *from `password`.`studentinformation`");
while (query1.next())
{
/*qDebug() << query1.value(0).toString() << query1.value(1).toString();*/
}
db.close();
}
else
{
qDebug() << "fail";
}
}
QSqlDatabase FormHomePage::InitMySql()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else{
qDebug() << "False";
}
return db;
}
FormHomePage::~FormHomePage()
{
}
GuiApplication.cpp
# include "GuiApplication.h"
# include "ui_StudentMenu.h"
# include <QSqlQuery>
# include <QSqlTableModel>
# include <QSqlError>
# include <QMessageBox>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
GuiApplication::GuiApplication(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
setWindowTitle(QString::fromUtf8("制作者2018023417,苗壮"));
QStringList drivers = QSqlDatabase::drivers();//打印MySQL驱动查看
qDebug() << drivers;
//InitMySql();
connect(ui.startButton, &QPushButton::clicked, this, &GuiApplication::condButtonPressed);
connect(ui.closeButton, &QPushButton::clicked, this, &GuiApplication::close);
/*connect(ui.pushButton, &QPushButton::clicked, this, &GuiApplication::connectMysql);*/
//setWindowFlags(Qt::FramelessWindowHint);//消除运行时的边框
}
void GuiApplication::condButtonPressed()
{
qDebug("succeed");
view = new StudentMenu(this);
view->show();
//指针写法新建窗体
}
Main.cpp
# include "GuiApplication.h"
# include "ui_StudentMenu.h"
# include <QSqlQuery>
# include <QSqlTableModel>
# include <QSqlError>
# include <QMessageBox>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
GuiApplication::GuiApplication(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
setWindowTitle(QString::fromUtf8("制作者2018023417,苗壮"));
QStringList drivers = QSqlDatabase::drivers();//打印MySQL驱动查看
qDebug() << drivers;
//InitMySql();
connect(ui.startButton, &QPushButton::clicked, this, &GuiApplication::condButtonPressed);
connect(ui.closeButton, &QPushButton::clicked, this, &GuiApplication::close);
/*connect(ui.pushButton, &QPushButton::clicked, this, &GuiApplication::connectMysql);*/
//setWindowFlags(Qt::FramelessWindowHint);//消除运行时的边框
}
void GuiApplication::condButtonPressed()
{
qDebug("succeed");
view = new StudentMenu(this);
view->show();
//指针写法新建窗体
}
RankPage.cpp
# include "RankPage.h"
# include <QtSql>
# include <QSqlQuery>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
RankPage::RankPage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
setWindowTitle(QString::fromUtf8("Dialog"));
ui.CstudyButton->setText("按C语言课设成绩排序");
ui.EnglishButton->setText("按英语成绩排序");
ui.MathButton->setText("按高等数学成绩排序");
ui.pushButton->setText("按C语言课设成绩排序");
ui.pushButton_2->setText("按英语成绩排序");
ui.pushButton_3->setText("按高等数学成绩排序");
ui.EXIT->setText("返回上一级");
connect(ui.EXIT, &QPushButton::clicked, this, &RankPage::close);
connect(ui.CstudyButton, &QPushButton::clicked, this, &RankPage::RankDesign);
connect(ui.EnglishButton, &QPushButton::clicked, this, &RankPage::RankEnglish);
connect(ui.MathButton, &QPushButton::clicked, this, &RankPage::RankMath);
connect(ui.pushButton, &QPushButton::clicked, this, &RankPage::RankDesignDown);
connect(ui.pushButton_2, &QPushButton::clicked, this, &RankPage::RankEnglishDown);
connect(ui.pushButton_3, &QPushButton::clicked, this, &RankPage::RankMathDown);
}
void RankPage::RankDesign()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}//测试数据库连接情况
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `C语言程序设计成绩` ";//sql默认排序即为升序
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
void RankPage::RankEnglish()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
db.open();
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `大学英语成绩` ";
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
void RankPage::RankMath()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
db.open();
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `高等数学成绩`";
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
void RankPage::RankDesignDown()
{
//SELECT * FROM `password`.`studentinformation`
//FORM C语言课程设 计成绩
//ORDER BY C语言课程设计成绩 DESC
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `C语言程序设计成绩` DESC LIMIT 0,1000 ";//DESC为降序关键字
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
void RankPage::RankEnglishDown()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `大学英语成绩` DESC LIMIT 0,1000";
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
void RankPage::RankMathDown()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//本地端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
if (db.open())
{
qDebug() << "success!";
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery("SELECT * FROM `password`.`studentinformation` LIMIT 0,1000");
ui.tableView->setModel(model);
QSqlQuery query("show tables from `password`.`studentinformation`");
QString temp = "SELECT * FROM `password`.`studentinformation` ORDER BY `高等数学成绩` DESC LIMIT 0,1000";
QSqlQuery query1(temp);
model->setQuery(temp);
ui.tableView->setModel(model);
db.close();
}
else
{
qDebug() << "fail";
}
}
RankPage::~RankPage()
{
}
RevisePage.cpp
# include "RevisePage.h"
# include <qmessagebox.h>
# include <qdebug.h>
# include <string>
# include <QSqlQuery>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
RevisePage::RevisePage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButton_4, &QPushButton::clicked, this, &RevisePage::close);
connect(ui.pushButton, &QPushButton::clicked, this, &RevisePage::DateSearch);
connect(ui.pushButton_2, &QPushButton::clicked, this, &RevisePage::DataRevise);
}
void RevisePage::DateSearch()
{
qDebug() << "OK";
QString num = ui.lineEdit->text();
QString number = ui.lineEdit_2->text();
QString name = ui.lineEdit_3->text();
QString sex = ui.lineEdit_4->text();
QString birthday = ui.lineEdit_5->text();
QString age = ui.lineEdit_6->text();
QString cscore = ui.lineEdit_7->text();
QString math = ui.lineEdit_8->text();
QString english = ui.lineEdit_9->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}//确认数据库连接情况
int flag = 0;
if (num.length())
{
QString temp_qt = "select *from `password`.`studentinformation`WHERE studentinformation.`学号`=" + num;
QSqlQuery query1(temp_qt);
ui.lineEdit_2->setText("no data");
ui.lineEdit_3->setText("no data");
ui.lineEdit_4->setText("no data");
ui.lineEdit_5->setText("no data");
ui.lineEdit_6->setText("no data");
ui.lineEdit_7->setText("no data");
ui.lineEdit_8->setText("no data");
ui.lineEdit_9->setText("no data");
while (query1.next())
{
/*qDebug() << query1.value(0).toString() << query1.value(1).toString();*/
ui.lineEdit_2->setText(query1.value(0).toString());
ui.lineEdit_3->setText(query1.value(1).toString());
ui.lineEdit_4->setText(query1.value(2).toString());
ui.lineEdit_5->setText(query1.value(6).toString());
ui.lineEdit_6->setText(query1.value(7).toString());
ui.lineEdit_7->setText(query1.value(3).toString());
ui.lineEdit_8->setText(query1.value(4).toString());
ui.lineEdit_9->setText(query1.value(5).toString());
flag = 1;
}
if (flag == 0)
{
QMessageBox::warning(this, tr("Warning!"), tr(" 不存在该信息! "));
}
}
else
{
QMessageBox::warning(this, tr("Warning!"), tr(" 学号不能为空!"));
}
}
void RevisePage::DataRevise()
{
QString num = ui.lineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");//主机名
db.setPort(3306);//端口号
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227");//设置数据库连接账号的密码
db.open();
QString temp_qt = "UPDATE `password`.`studentinformation` SET `学号` = '"
+ ui.lineEdit_2->text() + "'" + ",`姓名` = "
+ "'" + ui.lineEdit_3->text() + "'" + ",`性别` = "
+ "'" + ui.lineEdit_4->text() + "'" + ",`C语言程序设计成绩` = "
+ "'" + ui.lineEdit_2->text() + "'" + ",`高等数学成绩` = "
+ "'" + ui.lineEdit_2->text() + "'" + ",`大学英语成绩` = "
+ "'" + ui.lineEdit_9->text() + "'" + ",`出生年月` = "
+ "'" + ui.lineEdit_5->text() + "'" + ",`年龄` = "
+ "'" + ui.lineEdit_6->text();
temp_qt=temp_qt + "' WHERE `学号` = " + ui.lineEdit->text();
QSqlQuery query1(temp_qt);
}
RevisePage::~RevisePage()
{
}
SearchPage.cpp
# include "SearchPage.h"
# include <qmessagebox.h>
# include <qdebug.h>
# include <string>
# include <QSqlQuery>
# if _MSC_VER >= 1600
# pragma execution_character_set("utf-8")
# endif
SearchPage::SearchPage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.label->setText("请输入要查询的学号:");
ui.label_11->setText("");
ui.label_12->setText("");
ui.label_13->setText("");
ui.label_14->setText("");
ui.label_15->setText("");
ui.label_16->setText("");
ui.label_17->setText("");
ui.label_18->setText("");
connect(ui.Exit, &QPushButton::clicked, this, &SearchPage::close);
connect(ui.pushButton, &QPushButton::clicked, this, &SearchPage::DataSearch);
}
void SearchPage::DataSearch()
{
qDebug() << "OK";
QString num = ui.lineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("kuandong1227"); //设置数据库连接账号的密码
bool ok = db.open();
if (ok)
{
qDebug() << "OK";
}
else
{
qDebug() << "False";
}
//以上为初始化数据连接
int flag = 0;
if (num.length())
{
QString temp_qt = "select *from `password`.`studentinformation`WHERE studentinformation.`学号`=" + num;
QSqlQuery query1(temp_qt);
ui.label_11->setText("no data");
ui.label_12->setText("no data");
ui.label_13->setText("no data");
ui.label_14->setText("no data");
ui.label_15->setText("no data");
ui.label_16->setText("no data");
ui.label_17->setText("no data");
ui.label_18->setText("no data");
while (query1.next())
{
/*qDebug() << query1.value(0).toString() << query1.value(1).toString();*/
ui.label_11->setText(query1.value(0).toString());
ui.label_12->setText(query1.value(1).toString());
ui.label_13->setText(query1.value(2).toString());
ui.label_14->setText(query1.value(6).toString());
ui.label_15->setText(query1.value(7).toString());
ui.label_16->setText(query1.value(3).toString());
ui.label_17->setText(query1.value(4).toString());
ui.label_18->setText(query1.value(5).toString());
flag = 1;
}
if (flag == 0)
{
QMessageBox::warning(this, tr("Warning!"), tr(" 不存在该信息! "));
}
}
else
{
QMessageBox::warning(this, tr("Warning!"), tr(" 学号不能为空!"));
}
}
SearchPage::~SearchPage()
{
}
StudentMenu.cpp
# include "StudentMenu.h"
# include "RankPage.h"
# include "DeletePage.h"
# include "CalculationPage.h"
# include "EntryPage.h"
# include "FormHomePage.h"
# include "RevisePage.h"
# include "SearchPage.h"
StudentMenu::StudentMenu(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.Exit->setText("返回");
connect(ui.Exit, &QPushButton::clicked, this, &StudentMenu::close);
connect(ui.DisPlayButton, &QPushButton::clicked, this, &StudentMenu::ShowFormPage);
connect(ui.DeleteButton, &QPushButton::clicked, this, &StudentMenu::ShowDeletePage);
connect(ui.ReviseButton, &QPushButton::clicked, this, &StudentMenu::ShowRevisePage);
connect(ui.SearchButton, &QPushButton::clicked, this, &StudentMenu::ShowSearchPage);
connect(ui.RankButton, &QPushButton::clicked, this, &StudentMenu::ShowRankPage);
connect(ui.EntryButton, &QPushButton::clicked, this, &StudentMenu::ShowEntryPage);
connect(ui.CalculationButton, &QPushButton::clicked, this, &StudentMenu::ShowCalculationPage);
}
void StudentMenu::ShowFormPage()
{
view = new FormHomePage(this);
view->show();
//view.show();//不用指针的显示新页面
}
void StudentMenu::ShowDeletePage()
{
view2 = new DeletePage(this);
view2->show();
}
void StudentMenu::ShowRevisePage()
{
view3 = new RevisePage(this);
view3->show();
}
void StudentMenu::ShowCalculationPage()
{
view4 = new CalculationPage(this);
view4->show();
}
void StudentMenu::ShowSearchPage()
{
view5 = new SearchPage(this);
view5->show();
}
void StudentMenu::ShowRankPage()
{
view6 = new RankPage(this);
view6->show();
}
void StudentMenu::ShowEntryPage()
{
view7 = new EntryPage(this);
view7->show();
}
StudentMenu::~StudentMenu()
{
}
PHP 页面代码
chart.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>学生成绩管理系统</title>
</head>
<body>
<div class="text" style=" text-align:center;">
<h1>学生成绩折线图</h1>
</div>
<img src="wendu_shidu_chart.php" alt="学生成绩折线图" width="100%">
<!-- <?php
require_once 'bool_data.php';
?> -->
</body>
</html>
sql_connect.php
<?php
/**
* Created by PhpStorm.
* User: liwen
* Date: 2018/9/14 0014
* Time: 13:05
*/
$servername = "XXX.XXX.XXX.XXX";
$username = "XXXXX";
$password = "XXXXXXXX";
$dbname = "XXXXXXXXX";
$conn = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno()) {
echo 'Connect failed' . mysqli_connect_error();
}
mysqli_query($conn,"set character_set_server 'utf8'");
mysqli_query($conn,"SET NAMES 'utf8'");
?>
Students_grades_chart.php
<?php
require_once ('C:/php7/jpgraph/jpgraph.php');
require_once ('C:/php7/jpgraph/jpgraph_line.php');
require_once 'sql_connect.php';
$query="
SELECT * FROM `c++_course_design`.`studentinformation` LIMIT 0,1000
";
$Data1 = mysqli_query($conn,$query);
$Data2 = mysqli_query($conn,$query);
$Data3 = mysqli_query($conn,$query);
$Data4 = mysqli_query($conn,$query);
$y=array();
$x=array();
$x1=array();
$x2=array();
while($row = mysqli_fetch_array($Data1)){
$y[]=$row["number"];
}
while($row1 = mysqli_fetch_array($Data2)){
$x[]=$row1["C_score"];
}
while($row2 = mysqli_fetch_array($Data3)){
$x1[]=$row2["math_score"];
}
while($row3 = mysqli_fetch_array($Data4)){
$x2[]=$row3["english_score"];
}
$graph = new Graph(1990,610);//创建新的Graph对象
$graph->SetScale("textlin");//设置刻度样式
$graph->img->SetMargin(70,50,50,70);//设置图表边界
$graph->title->Set(iconv("UTF-8","GB2312//IGNORE",""));//设置图表标题
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);//标题字体
$graph->xaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","学号"));//设置X轴
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD,16);//设置X轴样式
$graph->xaxis->title->SetMargin(20);
$graph->xaxis->SetTickLabels($y);//设置X轴坐标值
$graph->yaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","C++/Math/English"));//设置Y轴
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD,16);//设置Y轴样式
$graph->yaxis->title->SetMargin(20);
$graph->title->SetColor("blue");
$graph->title->SetMargin(20);//设置标题空间
// Create the linear plot
$line_plot=new LinePlot($x);// 创建新的LinePlot对象
$line_plot->SetColor("red"); //设置曲线颜色
$line_plot->SetLegend(iconv("UTF-8","GB2312//IGNORE","C++"));
$line_plot->SetWeight(5);
$line_plot->value->show(true);//显示值
$line2_plot=new LinePlot($x1);// 创建新的LinePlot对象
$line2_plot->SetColor("red"); //设置曲线颜色
$line2_plot->SetLegend(iconv("UTF-8","GB2312//IGNORE","Math"));
$line2_plot->SetWeight(5);
$line2_plot->value->show(true);//显示值
$line3_plot=new LinePlot($x2);// 创建新的LinePlot对象
$line3_plot->SetColor("red"); //设置曲线颜色
$line3_plot->SetLegend(iconv("UTF-8","GB2312//IGNORE","English"));
$line3_plot->SetWeight(5);
$line3_plot->value->show(true);//显示值
// Add the plot to the graph
$graph->Add($line_plot);//在统计图上绘制曲线
$graph->Add($line2_plot);
$graph->Add($line3_plot);
// Display the graph
$graph->Stroke();//输出图像
?>
+MySQL实现学生信息管理系统&spm=1001.2101.3001.5002&articleId=167261903&d=1&t=3&u=bde5226a30f6438dbf8497cbcac161e2)
361

被折叠的 条评论
为什么被折叠?



