图书管理系统课程设计报告
- 格式:doc
- 大小:332.50 KB
- 文档页数:22
管理信息系统课程设计设计内容:学生班级:学生姓名:学号:班内序号:设计日期:一、课设目的通过对图书管理信息系统的系统分析、系统设计、编码和调试等工作的实践,了解管理信息系统的一般设计方法和实现思路,深入了解数据库设计的基本理论及方法。
二、系统功能框图该系统主要由四大功能模块组成:用户登录、图书管理、用户管理和借阅查询。
各大功能模块又由一些子功能模块构成,其功能框图如下。
三、数据库结构1、读者类别表(ReaderType)2、读者信息表(Reader)3、图书信息表(Book)4、借阅信息表(Borrow)四、功能模块图书管理用户管理借阅查询五、界面设计1、登入窗口2、图书管理窗口3、用户管理窗口4、系统管理窗口5、借阅信息窗口6、图书借阅窗口7、还书窗口8、个人信息修改窗口六、实现代码1、登入代码int right=1;QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");QString strDatabaseName=QString("DRIVER={SQLServer};SERVER=TERRY;Database=book;uid=tt;pwd=123");db.setDatabaseName(strDatabaseName);db.setPort(1433);bool ok=db.open();if(ok){QSqlQuery query;query.exec(tr("select 用户编号,用户姓名,用户密码,用户类别 from users"));if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("查找用户失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query.next()){this->rid=query.value(0).toString();QString name=query.value(1).toString();QString passward=query.value(2).toString();this->type=query.value(3).toString();if(this->lineEdit0->text()==name&&this->lineEdit1->text()==passw ard){right=0;if(type=="1"){managesystem *w1=new managesystem;w1->rid=this->rid;w1->type=this->type;w1->show();this->close();}else if(type=="2"){manageusers *w2=new manageusers;w2->rid=this->rid;w2->type=this->type;w2->show();this->close();}else if(type=="3"){managebooks *w3=new managebooks;w3->rid=this->rid;w3->type=this->type;w3->show();this->close();}else{reader *w4=new reader;w4->rid=this->rid;w4->type=this->type;w4->show();this->close();}}}if(right){QMessageBox tempMsgBox(QMessageBox::Warning,tr("消息"),tr("用户名或密码错误,请重新输入!"),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBoxtempMsgBox(QMessageBox::Information,tr("消息"),tr("欢迎进入图书管理系统!"),QMessageBox::Ok); tempMsgBox.exec();}}}else{QMessageBox tempMsgBox(QMessageBox::Warning,tr("消息"),tr("数据库连接错误,请重新连接!"),QMessageBox::Ok); tempMsgBox.exec();}2、添加图书代码//构造sql添加语句QString sqlString(tr("insert into books(图书编号,书名,作者,出版社,出版日期,分类名,语言,页数,价格,入馆日期,内容简介,是否在馆)"));sqlString.append(QString("values('")+this->lineEdit0->text()+ QString("',"));sqlString.append(QString("'")+this->lineEdit1->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit2->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit3->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit4->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit5->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit6->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit7->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit8->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit9->text()+QString ("',"));sqlString.append(QString("'")+this->lineEdit10->text()+QStrin g("',"))sqlString.append(QString("'")+this->lineEdit11->text()+QStrin g("')"))//执行添加QSqlQuery query;query.exec(sqlString);//显示QSqlTableModel *model=new QSqlTableModel;model->setTable("books");model->select();this->tableView->setModel(model);//判断添加是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("添加失败"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("添加成功!"),QMessageBox::Ok);tempMsgBox.exec();}3、删除图书代码//构造sql删除语句QString sqlString(tr("delete from books where 图书编号='")); sqlString.append(this->lineEdit0->text()+QString("'"));QSqlQuery query;query.exec(sqlString);//显示QSqlTableModel *model=new QSqlTableModel;model->setTable("books");model->select();this->tableView->setModel(model);//判断删除是否成功if(!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("删除失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("删除成功!"),QMessageBox::Ok);tempMsgBox.exec();}4、查询图书代码//构造sql查询语句QString sqlString(tr("select 书名,作者,出版社,出版日期,分类名,语言,页数,价格,入馆日期,内容简介,是否在馆 from books where 图书编号='"));sqlString.append(this->lineEdit0->text()+QString("'"));QSqlQuery query;query.exec(sqlString);if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("查找图书失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query.next()){this->lineEdit1->setText(query.value(0).toString()); this->lineEdit2->setText(query.value(1).toString()); this->lineEdit3->setText(query.value(2).toString()); this->lineEdit4->setText(query.value(3).toString()); this->lineEdit5->setText(query.value(4).toString()); this->lineEdit6->setText(query.value(5).toString()); this->lineEdit7->setText(query.value(6).toString()); this->lineEdit8->setText(query.value(7).toString()); this->lineEdit9->setText(query.value(8).toString()); this->lineEdit10->setText(query.value(9).toString());this->lineEdit11->setText(query.value(10).toString()); }}5、修改图书代码//构造sql更新语句QString sqlString(tr("update books"));sqlString.append(QString(tr(" set 书名 ='"))+this->lineEdit1->text()+QString("',"));sqlString.append(QString(tr("作者 ='"))+this->lineEdit2->text()+QString("',"));sqlString.append(QString(tr("出版社 ='"))+this->lineEdit3->text()+QString("',"));sqlString.append(QString(tr("出版日期 ='"))+this->lineEdit4->text()+QString("',"));sqlString.append(QString(tr("分类名 ='"))+this->lineEdit5->text()+QString("',"));sqlString.append(QString(tr("语言 ='"))+this->lineEdit6->text()+QString("',"));sqlString.append(QString(tr("页数 ='"))+this->lineEdit7->text()+QString("',"));sqlString.append(QString(tr("价格 ='"))+this->lineEdit8->text()+QString("',"));sqlString.append(QString(tr("入馆日期 ='"))+this->lineEdit9->text()+QString("',"));sqlString.append(QString(tr("内容简介 ='"))+this->lineEdit10->text()+QString("',"));sqlString.append(QString(tr("是否在馆 ='"))+this->lineEdit11->text()+QString("' "));sqlString.append(QString(tr("where 图书编号 ="))+this->lineEdit0->text()+QString(";"));//执行更新QSqlQuery query;query.exec(sqlString);//显示QSqlTableModel *model=new QSqlTableModel;model->setTable("books");model->select();this->tableView->setModel(model);//判断更新是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("更新失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("更新成功!"),QMessageBox::Ok);tempMsgBox.exec();}6、借阅图书代码int right,isin,haveborrownum,canborrownum,canborrowdays;right=1;//构造sql查询语句QString sqlString(tr("select 是否在馆 from books where 图书编号 ='"));sqlString.append(this->lineEdit0->text()+QString("'"));QSqlQuery query;query.exec(sqlString);if(!query.isActive()){right=0;QMessageBox tempMsgBox(QMessageBox::Warning,tr("数据库连接失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query.next())isin=query.value(0).toInt();}//构造sql查询语句1QString sqlString1(tr("select 已借书数量 from users where 用户编号 ='"));sqlString1.append(rid+QString("'"));QSqlQuery query1;query1.exec(sqlString1);if(!query1.isActive()){right=0;QMessageBox tempMsgBox(QMessageBox::Warning,tr("数据库连接失败!"),stError().text(),QMessageBox::Ok); tempMsgBox.exec();}else{while(query1.next())haveborrownum=query1.value(0).toInt(); }//构造sql查询语句2QString sqlString2(tr("select 可借书数量,可借书天数 from usertype where 用户类别 ='"));sqlString2.append(type+QString("'"));QSqlQuery query2;query2.exec(sqlString2);if(!query2.isActive()){right=0;QMessageBox tempMsgBox(QMessageBox::Warning,tr("数据库连接失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query2.next()){canborrownum=query2.value(0).toInt();canborrowdays=query2.value(1).toInt();}}if(isin==0){right=0;QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("本图书已经借出,请借阅其他书籍!"),QMessageBox::Ok);tempMsgBox.exec();}if(haveborrownum>=canborrownum){right=0;QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("您图书已经借满,请还书后再借!"),QMessageBox::Ok); tempMsgBox.exec();}if(right){QDateTime dateTime = QDateTime::currentDateTime();QDateTime dateTime1;dateTime1=dateTime.addDays(canborrowdays);QString strtime=dateTime1.time().toString();int y=dateTime.date().year();int m=dateTime.date().month();int d=dateTime.date().day();int y1=dateTime1.date().year();int m1=dateTime1.date().month();int d1=dateTime1.date().day();QStringdate1(QString::number(y)+"-"+QString::number(m)+"-"+QString::number(d)+" "+strtime);QStringdate2(QString::number(y1)+"-"+QString::number(m1)+"-"+QString::number(d1)+" "+strtime);//this->lineEdit1->setText(date1);//构造sql添加语句3QString sqlString3(tr("insert into borrow(图书编号,用户编号,续借次数,借书日期,应还日期,超期天数,超期金额)"));sqlString3.append(QString("values('")+this->lineEdit0->text()+QString("',"));sqlString3.append(QString("'")+rid+QString("','0',"));sqlString3.append(QString("'")+QString(date1)+QString("',"));sqlString3.append(QString("'")+QString(date2)+QString("','0','0')"));sqlString3.append(QString("'")+date2+QString("','0','0')"));//执行添加QSqlQuery query3;query3.exec(sqlString3);//判断添加是否成功if (!query3.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("借阅失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBox tempMsgBox(QMessageBox::Information,tr("消息"),tr("借阅成功!"),QMessageBox::Ok);tempMsgBox.exec();isin=0;haveborrownum+=1;//构造sql更新语句QString sqlString(tr("update books"));sqlString.append(QString(tr(" set 是否在馆 ='"))+QString::number(isin)+QString("'"));sqlString.append(QString(tr("where 图书编号 ="))+this->lineEdit0->text()+QString(";"));//执行更新QSqlQuery query;query.exec(sqlString);//显示this->lineEdit11->setText("0");QSqlTableModel *model=new QSqlTableModel;model->setTable("books");model->select();this->tableView->setModel(model);//判断更新是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("更新图书失败!"),stError().text(),QMessageBox::Ok); tempMsgBox.exec();}else{//构造sql更新语句QString sqlString(tr("update users"));sqlString.append(QString(tr(" set 已借书数量 ='"))+QString::number(haveborrownum)+QString("'"));sqlString.append(QString(tr("where 用户编号 ="))+rid+QString(";"));//执行更新QSqlQuery query;query.exec(sqlString);//判断更新是否成功if (!query.isActive()){QMessageBoxtempMsgBox(QMessageBox::Warning,tr("更新用户失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}}}}7、续借图书代码int right=1;int borrowtimes,canborrowtimes,canborrowdays;QString shouldreturndays;//构造sql查询语句QString sqlString(tr("select 续借次数,可续借的次数,可借书天数,应还日期 from borrowagainview where 图书编号 ="));sqlString.append(this->lineEdit0->text()+QString(" "));QSqlQuery query;query.exec(sqlString);if (!query.isActive()){right=0;QMessageBox tempMsgBox(QMessageBox::Warning,tr("续借失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query.next()){borrowtimes=query.value(0).toInt();canborrowtimes=query.value(1).toInt();canborrowdays=query.value(2).toInt();shouldreturndays=query.value(3).toString();}}if(borrowtimes>=canborrowtimes){right=0;QMessageBox tempMsgBox(QMessageBox::Information,tr("续借失败"),tr("续借次数已满,不能续借!"),QMessageBox::Ok);tempMsgBox.exec();}if(right){QDateTime dateTime = QDateTime::currentDateTime();QDateTime dateTime1;dateTime1=dateTime.addDays(canborrowdays);QString strtime=dateTime1.time().toString();int y1=dateTime1.date().year();int m1=dateTime1.date().month();int d1=dateTime1.date().day();QStringdate2(QString::number(y1)+"-"+QString::number(m1)+"-"+QString::number(d1)+" "+strtime);borrowtimes+=1;//构造sql更新语句QString sqlString(tr("update borrowagainview"));sqlString.append(QString(tr(" set 续借次数 ='"))+QString::number(borrowtimes)+QString("',"));sqlString.append(QString(tr(" 应还日期 ='"))+QString(date2)+QString("'"));sqlString.append(QString(tr("where 图书编号 ='"))+this->lineEdit0->text()+QString("'"));//执行更新QSqlQuery query;query.exec(sqlString);//显示QSqlTableModel *model=new QSqlTableModel;model->setTable("borrowedview");model->select();this->tableView->setModel(model);//判断更新是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("续借失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBoxtempMsgBox(QMessageBox::Information,tr("消息"),tr("续借成功!"),QMessageBox::Ok);tempMsgBox.exec();}}}8、还书代码int haveborrownum;//构造sql查询语句QString sqlString1(tr("select 已借书数量 from borrowagainview where 图书编号 = '"));sqlString1.append(this->lineEdit0->text()+QString("'"));QSqlQuery query1;query1.exec(sqlString1);if (!query1.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("查询失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{while(query1.next())haveborrownum=query1.value(0).toInt(); }haveborrownum-=1;//构造sql更新语句QString sqlString(tr("update books"));sqlString.append(QString(tr(" set 是否在馆 ='"))+"1"+QString("'"));sqlString.append(QString(tr("where 图书编号 ="))+this->lineEdit0->text()+QString(";"));//执行更新QSqlQuery query;query.exec(sqlString);//判断更新是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("更新图书失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{//构造sql更新语句QString sqlString(tr("update users"));sqlString.append(QString(tr(" set 已借书数量 ='"))+QString::number(haveborrownum)+QString("'"));sqlString.append(QString(tr("where 用户编号 ="))+rid+QString(";"));//执行更新QSqlQuery query;query.exec(sqlString);//判断更新是否成功if (!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("更新用户失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{//构造sql删除语句QString sqlString(tr("delete from borrow where 图书编号 = '"));sqlString.append(this->lineEdit0->text()+QString("'"));QSqlQuery query;query.exec(sqlString);//显示this->display();//判断删除是否成功if(!query.isActive()){QMessageBox tempMsgBox(QMessageBox::Warning,tr("删除借阅表失败!"),stError().text(),QMessageBox::Ok);tempMsgBox.exec();}else{QMessageBoxtempMsgBox(QMessageBox::Information,tr("消息"),tr("还书成功!"),QMessageBox::Ok);tempMsgBox.exec();}}七、总结其实在这次课设的过程中我发现了自己的很多不足,很多的知识不是没有掌握,是根本就不理解也不去研究,在做课设的过程中有好多的知识都是现学现用,还有好多是在网络上面找到的,通过同学的帮助,与老师的指导在最后才做出来一个半成品,有点觉得自己没有用,但是在课设的过程我也学会了很多的东西。