大四课程设计之基于RFID技术的考勤管理系统(三)数据库设计
----------------------------------------------------------------------------------------
源碼下載地址:
http://download.csdn.net/download/qq78442761/9971770
----------------------------------------------------------------------------------------
用SQLyog查看如下圖所示:
數(shù)據(jù)庫(kù)涉及3個(gè)表的構(gòu)建下面是相關(guān)代碼。
ER圖如下所示:
下面是上課和下課打卡的流程圖:
左圖為上課,右圖為下課
具體代碼如下:
DROP TABLE IF EXISTS `subject`;CREATE TABLE `subject` (`id` int(11) NOT NULL,`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,`time_from` time NOT NULL,`time_to` time NOT NULL,PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;CREATE TABLE `student` (`CardNum` int(11) NOT NULL,`id` int(11) NOT NULL,`class` int(11) NOT NULL,`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;CREATE TABLE `chose` (`subject_id` int(11) NOT NULL,`student_id` int(11) NOT NULL,`in_num` int(11) NOT NULL,`out_num` int(11) NOT NULL,KEY `Stu_id` (`student_id`),KEY `Sub_id` (`subject_id`),CONSTRAINT `Stu_id` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT `Sub_id` FOREIGN KEY (`subject_id`) REFERENCES `subject` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
下面是一些簡(jiǎn)單的SQL語(yǔ)句,都插入到Qt程序里面了:
//上課打卡時(shí):查詢選課表中是否有此人 select * from student where id in (select student_id from chose where student_id =(select id from Student where CardNum=0110 and subject_id=(select id from subject where now()>=time_from and now()<=time_to))); 如果有就: update chose set in_num=in_num+1 where student_id=XXXXXXXX;//下課打卡時(shí):查詢選課表中是否有此人 select * from student where id in (select student_id from chose where student_id =(select id from Student where CardNum=0110 and subject_id=(select id from subject where now()>time_to))); 如果有就 update chose set out_num=in_num+1 where student_id=XXXXXXXX;//根據(jù)學(xué)號(hào)查詢對(duì)應(yīng)學(xué)號(hào)所有課程的出勤信息 select student.id,subject.name,chose.in_num from student,chose,subject where chose.student_id=14220307 and student.id=14220307//根據(jù)姓名查詢對(duì)應(yīng)學(xué)號(hào)所有課程的出勤信息 SELECT student.name,subject.name,chose.in_num FROM student,chose,SUBJECT WHERE chose.student_id = (SELECT id FROM student WHERE NAME='張三') AND student.id=(SELECT id FROM student WHERE NAME='張三');//查詢選取了此課表的所有出勤人信息,和出勤分?jǐn)?shù): select subject.id,subject.name,student.id,student.name,chose.in_num,chose.in_num*10 as '出勤分?jǐn)?shù)'from subject,student,chose where subject.id=chose.subject_id and chose.student_id=student.id;//更具學(xué)號(hào)刪除學(xué)生數(shù)據(jù) delete from student where id=14220310;//添加學(xué)生 insert into student values(9999,14220388,142203,'小白');
QStringAndBool ConnMysql::LinkMySQL() {db=QSqlDatabase::addDatabase("QMYSQL");db.setHostName("localhost");db.setDatabaseName(m_DataBase);db.setUserName(m_UserName);db.setPassword(m_PassWd);QStringAndBool returnValues;if(!db.open()){QMessageBox::information(NULL,"提示","數(shù)據(jù)庫(kù)連接失敗!");returnValues.MesQString="數(shù)據(jù)庫(kù)連接失敗!";returnValues.MesBool=0;return returnValues;}else{QMessageBox::information(NULL,"提示","數(shù)據(jù)庫(kù)連接成功!",QMessageBox::Ok);returnValues.MesQString="數(shù)據(jù)庫(kù)連接成功!";returnValues.MesBool=1;return returnValues;} }void ConnMysql::DisLinkMysql() {QString SqlQuery="exit";model->setQuery(SqlQuery);}
注意:具體代碼在本博文開(kāi)頭,此處只有關(guān)鍵代碼;
上一篇博文:
大四課程設(shè)計(jì)之基于RFID技術(shù)的考勤管理系統(tǒng)(二)讀取COM口數(shù)據(jù)
http://blog.csdn.net/qq78442761/article/details/77950585
下一篇博文:
大四課程設(shè)計(jì)之基于RFID技術(shù)的考勤管理系統(tǒng)(四)Qt界面設(shè)計(jì)
http://blog.csdn.net/qq78442761/article/details/77951707
總結(jié)
以上是生活随笔為你收集整理的大四课程设计之基于RFID技术的考勤管理系统(三)数据库设计的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C/C++ OpenCV读取视频与调用摄
- 下一篇: windows配置Python多版本共存