Skip to content

jyzhangchn/stu_infromatoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

stu_infromatoin

qt+database

#学生信息管理系统 说明文档

注:若要运行此程序需要有qt5.7环境并将database.cpp中的数据库路径改为本地路径

##简介 本程序基于SQLite为支撑,Qt为界面完成,除了基本的对学生信息的增删改查功能外,还可个性化定制学生兴趣从而发现某学生的可能朋友。 ##基于软件工程思想优化说明 ###密文回显

主界面 为完善用户体验,本程序更改为两个不同的接口:教师+学生,同时添加了密文回显

主界面.png

改进代码是文件qpasswordlineedit.h和相应.cpp文件

###修改密码 学生界面

学生界面.png

改进后,学生界面添加了修改密码的功能,相关代码如下:

void password::on_pushButton_save_clicked()
{
 QSqlDatabase db = QSqlDatabase::database("sqlite1"); //建立数据库连接
 QSqlQuery query(db);

 QString key=ui->lineEdit_old->text();
 query.prepare(QObject::tr("select 密码 from stu_password where 用户名 = ?"));
 query.addBindValue(ui->lineEdit_num->text());
 query.exec();
 if(!query.next())
 {
	 QMessageBox::information(NULL,"information","用户名不存在",QMessageBox::tr("OK"));
	 ui->lineEdit_num->clear();
 }
 else
 {
	 if(key==query.value(0).toString())
	 {
		 query.prepare(QObject::tr("update stu_password set 密码=? where 用户名 = ?"));
		 query.bindValue(0,ui->lineEdit_new->text());
		 query.bindValue(1,ui->lineEdit_num->text());
		
		 if(query.exec())
		 {
			 QMessageBox::information(NULL,"information","修改密码成功!",QMessageBox::tr("OK"));
			 this->close();
		 }
		 else
		 	QMessageBox::information(NULL,"information","啊哦,修改失败",QMessageBox::tr("OK"));
		
	 }
	 else
	 {
		 QMessageBox::information(NULL,"information","原密码错误",QMessageBox::tr("OK"));
		 ui->lineEdit_old->clear();
	 }
}

修改密码界面: ######学生端更改密码界面 更改密码.png ######老师端更改密码界面 更改密码2.png 相应实现文件在password.cpppassword_t.cpp以及对应.h文件中,分别对应学生和管理员界面的更改密码...

###容错 优化了容错功能

添加学生容错

容错1.png

相关代码如下:

 if(query.exec())
 {
	 QMessageBox::information(NULL,"information","修改成功!",QMessageBox::tr("OK"));
	 this->close();
 }
 else
 {
	 QMessageBox::critical(NULL,"critical","所填信息不完整或有误!",QMessageBox::tr("OK"));
 }

编辑学生信息容错 容错2.png

相关代码如下:

if(ui->label_name->text()==NULL)
 QMessageBox::information(NULL,"information","请先选择一个学生",QMessageBox::tr("OK"));

修改密码容错

容错3.png

相关代码如下:

if(!query.next())
 {
	 QMessageBox::information(NULL,"information","用户名不存在",QMessageBox::tr("OK"));
	 ui->lineEdit_num->clear();
 }
 if(key==query.value(0).toString())
 {
	 query.prepare(QObject::tr("update stu_password set 密码=? where 用户名 = ?"));
	 query.bindValue(0,ui->lineEdit_new->text());
	 query.bindValue(1,ui->lineEdit_num->text());
	
	 if(query.exec())
	 {
		 QMessageBox::information(NULL,"information","修改密码成功!",QMessageBox::tr("OK"));
		 this->close();
	 }
	 else
	 	QMessageBox::information(NULL,"information","啊哦,修改失败",QMessageBox::tr("OK"));

 }
 else
 {
	 QMessageBox::information(NULL,"information","原密码错误",QMessageBox::tr("OK"));
	 ui->lineEdit_old->clear();
 }

登录容错

容错4.png

相关代码如下:

if((!query.next()))
   QMessageBox::critical(NULL,"critical","用户名不存在",QMessageBox::tr("朕知错了"));

 else
 {
   QString key1 =query.value(0).toString();
     if(key1==key)
     {
     //此处登录成功后界面
     t_view.show();
     this->show();
     }
    else
    {
       QMessageBox::critical(NULL,"critical","密码错误!",QMessageBox::tr("朕知错了")); 
       ui->name_lineEdit->clear();
       this->ui->name_lineEdit->setFocus();
    }
 }

Releases

No releases published

Packages

No packages published