#include "mainwindow.h"
void MainWindow::setMyLineEdit()
{
ui->stuNumber -> setMaxLength( 11 ); //学号限制为11位
ui->classLevel -> setMaxLength( 4 ); //年级限制为两位
ui->stuPhone -> setMaxLength( 11 ); //手机号13位
QRegExp regExp("[0-9]+$");
QRegExp dor("^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0|1]))/(d{2}|d{4})$");
QRegExpValidator *pattern= new QRegExpValidator(regExp, this);//创建了一个表达式
// QRegExpValidator *pat= new QRegExpValidator(dor, this);//创建了一个表达式
//交付使用
ui->stuNumber ->setValidator(pattern); //学号限输入制为数字
ui->classLevel ->setValidator(pattern); //班级限输入制为数字
ui->stuPhone ->setValidator(pattern); //学生
//设置提示内容
ui->stuName ->setPlaceholderText("示例:张三");
ui->stuNumber ->setPlaceholderText("11位学号");
ui->stuPhone ->setPlaceholderText("请输入手机号");
ui->className ->setPlaceholderText("示例:软件1班");
ui->classLevel ->setPlaceholderText("示例:2018");
ui->headTeacher ->setPlaceholderText("班主任名字");
ui->instructor ->setPlaceholderText("辅导员名字");
QStringList qstr_campus;
QStringList qstr_department;
QStringList qstr_sex;
QStringList qstr_buildingno;
QStringList qstr_floor;
QStringList qstr_dormitoryno;
QStringList qstr_dormitorylevel;
qstr_department << "计算机工程系" << "土木工程系" << "机电信息系" << "化学工程系" << "经济管理系";
qstr_campus << "请选择" << "北校区" << "南校区";
qstr_sex << "请选择" << "男" << "女";
qstr_buildingno << "请选择" << "1栋" << "2栋" << "3栋" << "4栋" << "5栋" << "6栋" << "7栋" << "8栋" << "9栋" << "10栋" << "11栋" << "12栋" << "13栋" << "14栋";
qstr_floor << "请选择" << "一层" << "二层" << "三层" << "四层" << "五层" << "六层" << "七层";
qstr_dormitorylevel << "请选择" << "一级宿舍" << "二级宿舍";
// qstr_dormitoryno << ;
ui->department ->addItems (qstr_department );
ui->campus ->addItems (qstr_campus );
ui->sex ->addItems (qstr_sex );
ui->buildingno ->addItems (qstr_buildingno );
ui->floor ->addItems (qstr_floor );
ui->dormitorylevel ->addItems (qstr_dormitorylevel );
}
void MainWindow::setAddTableWidget()
{
QTableWidgetItem *headerItem;
QStringList headerText;
headerText << "系别" << "校区" << "性别" << "楼号" << "楼层"<< "宿舍号"<< "床位号" << "宿舍级别" << "学 号" << "姓 名" << "学生手机号" << "年级";
ui->addTableWidget->setColumnCount(headerText.count());//列数设置为与 headerText的行数相等
for (int i = 0; i < ui->addTableWidget->columnCount(); i++)
{
headerItem = new QTableWidgetItem(headerText.at(i));//新建一个QTableWidgetItem, headerText.at(i)获取headerText的i行字符串
QFont font = headerItem->font();//获取原有字体设置
font.setBold(true);//设置为粗体
font.setPixelSize(12);//字体大小
headerItem->setTextColor("#2E8B57");//字体颜色
ui->addTableWidget->setHorizontalHeaderItem(i,headerItem);//设置表头单元格的Item
}
selectDormitoryno();
}
void MainWindow::selectDormitoryno()
{
ui->addTableWidget->clearContents();
QSqlDatabase db = star_mysql();
QSqlQuery *query = new QSqlQuery;
QString first = "SELECT * FROM test_db.dorm where ";
QString strdepartment = " department = '" + ui->department->currentText () + "'";
first += strdepartment;
QString campus = ui->campus ->currentText ();
QString strsex = QString::number(ui->sex ->currentIndex());
QString strbuildingno = QString::number(ui->buildingno ->currentIndex());
QString strfloor = QString::number(ui->floor ->currentIndex());
QString strdormitorylevel = QString::number(ui->dormitorylevel ->currentIndex());
if (campus != "请选择" ) first += (campus = " and campus = '" + campus + "'" );
if (strsex != "0") first += (strsex = " and sex = " + strsex );
if (strbuildingno != "0") first += (strbuildingno = " and buildingno = " + strbuildingno );
if (strfloor != "0") first += (strfloor = " and floor = " + strfloor );
if (strdormitorylevel != "0") first += (strdormitorylevel = " and dormitorylevel = " + strdormitorylevel);
query->prepare(first);
if(!query->exec()) qDebug() << "insert fail of selectDormitoryno";
QSqlRecord rec = query->record();
query->next();
//=================================================================================
QSqlQuery *querylist = new QSqlQuery;
QString str1;
QString str2;
// str1 = "SELECT * FROM test_db.stulist where stunumber = ";
// str2 = query->value(rec.indexOf("stunameber")).toString();
// str1 += str2;
// qDebug() << str1;
// querylist->prepare(str1);
// querylist->exec();
// QSqlRecord reclist = querylist->record();
// querylist->next();
// qDebug() << querylist->value(reclist.indexOf("stuname"));
// str2 = querylist->value(reclist.indexOf("stuname")).toString();
//=================================================================================
do{
// query->record();
//=================================================================================
str1 = "SELECT * FROM test_db.stulist where stunumber = ";
str2 = query->value(rec.indexOf("stunameber")).toString();
str1 += str2;
querylist->prepare(str1);
querylist->exec();
QSqlRecord reclist = querylist->record();
querylist->next();
//=================================================================================
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 0, new QTableWidgetItem( query->value(rec.indexOf("department" )).toString()));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 1, new QTableWidgetItem( query->value(rec.indexOf("campus" )).toString()));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 2, new QTableWidgetItem(g_CHSex [query->value(rec.indexOf("sex" )).toInt ()]));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 3, new QTableWidgetItem(g_CHBuildingno [query->value(rec.indexOf("buildingno" )).toInt ()]));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 4, new QTableWidgetItem(g_CHFloor [query->value(rec.indexOf("floor" )).toInt ()]));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 5, new QTableWidgetItem( query->value(rec.indexOf("dormitoryno" )).toString()));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 6, new QTableWidgetItem(g_CHBedno [query->value(rec.indexOf("bedno" )).toInt ()]));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 7, new QTableWidgetItem(g_CHDormitorylevel [query->value(rec.indexOf("dormitorylevel")).toInt ()]));
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 8, new QTableWidgetItem(query->value(rec.indexOf( "stunameber" )).toString()));
//学生表的内容
ui->addTableWidget->setItem(g_rowCountForAddTableWidget, 9, new QTableWidgetItem(querylist->value(reclist.indexOf("stuname")).toString()));
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
"用Qt通过ODBC连接MySQL数据库实现学生管理系统.zip" 是一个基于C++和Qt框架开发的学生管理系统项目。该项目利用Qt的强大图形用户界面(GUI)设计能力,结合ODBC技术访问MySQL数据库,实现了一个功能全面的学生信息管理平台。系统支持对学生信息、课程、成绩等数据的增删改查操作,具备用户登录与权限控制功能。本项目采用面向对象的编程方法,将系统分解为多个独立且协同工作的模块,便于后续维护和扩展。通过Qt的跨平台特性,该系统可在不同操作系统上运行,如Windows、Linux、Mac OS X等。此外,使用ODBC技术使得系统可以方便地更换或升级数据库,提高了系统的灵活性和可移植性。该资源适合计算机相关专业的学生、老师及开发者学习和参考,特别是对初学者来说,这是一个理想的实践项目。所有源码均经过严格测试,确保功能正常运行,可以直接用于课程设计、毕业设计或作业。
资源推荐
资源详情
资源评论
收起资源包目录
用Qt通过ODBC连接MySQL数据库实现学生管理系统.zip (17个子文件)
projectcode1020
StudentSormitoryManagementSystem.pro.user 22KB
StudentSormitoryManagementSystem.pro.user.bba2763 22KB
mainwindow.h 2KB
dialog.ui 3KB
dialog.cpp 1KB
batchAdd.cpp 66B
find.cpp 4KB
mainwindow.cpp 3KB
deletestu.cpp 4KB
addorm.cpp 9KB
main.cpp 423B
mainwindow.ui 30KB
StudentSormitoryManagementSystem.pro 1KB
add.cpp 17KB
StudentSormitoryManagementSystem.pro.user.4.8-pre1 23KB
dialog.h 367B
delet.cpp 175B
共 17 条
- 1
资源评论
- 龙年行大运2024-11-21支持这个资源,内容详细,主要是能解决当下的问题,感谢大佬分享,希望多一些这类资源~
葡萄籽儿
- 粉丝: 469
- 资源: 662
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功