博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
驾校理论考试系统之数据库编程二
阅读量:5789 次
发布时间:2019-06-18

本文共 5186 字,大约阅读时间需要 17 分钟。

数据库操作类:

来自周公的: 文件取自

这个图标是从文件中提取出来的,后面会介绍这个方法

根据理论考试题目分布:

道路交通安全法规和规章 25 (违法行为综合判断与案例分析)

地方性法规 5%

道路交通信号 20% (常见交通标志标线和交警手势信号辨识)

安全行车,文明驾驶知识 20% (驾驶职业道德和文明驾驶常识)(安全行车常识)

复杂条件道路下的安全驾驶知识 10% (恶劣气候和复杂道路条件下驾驶常识)

紧急情况处理10% (紧急情况下避险常识)

常见故障判断,车辆维护5%

自救和危险品 5% (交通事故救护及常见危化品处置常识)

 

根据我的题库改为

违法行为综合判断与案例分析 15% 单选7

安全行车常识 25% 判断10 单选 15

常见交通标志标线和交警手势信号辨识 20% 判断10 单选8

驾驶职业道德和文明驾驶常识 10% 判断5 单选5

恶劣气候和复杂道路条件下驾驶常识 10% 判断 5 单选5

紧急情况下避险常识 10% 判断 5 单选5

交通事故救护及常见危化品处置常识 10% 判断5 单选5

多选题10个从总题库中抽取10个

说明:

    在先前数据库设计中我在题库中设计了两个属性,Rate和Random, 其中Rate是用来提高错题的出现次数,Random则用来随机抽取题目,从下面的select语句中可看出:

ORDER BY Rate DESC,Random ,按照先Rate降序排列,再按随机数Random降序排列,Limit使用来限定一次去多少个的!IN则是集合操作,表示在这里面取数据

 

选择

  1. 取50个选择题

SELECT TestID,BelongTo,Type,Question,Answer,Image,Video FROM COMPREHENSIVE_EXAM

WHERE TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1001')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 7)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1002')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 15)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1003')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 8)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1004')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1005')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1006')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1007')

AND Type = '单选'

ORDER BY Rate DESC,Random

LIMIT 5)

  1.     取40个判断题

SELECT TestID,BelongTo,Type,Question,Answer,Image,Video FROM COMPREHENSIVE_EXAM

WHERE TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1002')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 10)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1003')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 10)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1004')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1005')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1006')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 5)

OR

TestID IN (SELECT TestID FROM COMPREHENSIVE_EXAM

WHERE BelongTo IN (SELECT NodeID FROM NODE WHERE ParNodeID = 'N1007')

AND Type = '判断'

ORDER BY Rate DESC,Random

LIMIT 5)

  1.     取10个多选题

SELECT TestID,BelongTo,Type,Question,Answer,Image,Video

FROM COMPREHENSIVE_EXAM

WHERE Type = '多选'

ORDER BY Rate DESC,Random

LIMIT 10

插入

//向表ERRORLIST插入数据

private void InsertERRORLIST(string TableName, string TestID)

{

string sql = "INSERT INTO ERRORLIST(UID, TableName, TestID, DateTime)" + "values(@UID, @TableName, @TestID, @DateTime)";

SQLiteParameter[] parameters = new SQLiteParameter[]{

new SQLiteParameter("@UID","UI1001"),

new SQLiteParameter("@TableName", TableName),

new SQLiteParameter("@TestID", TestID),

new SQLiteParameter("@DateTime", DateTime.Now.ToString("yyyy-MM-dd")),

};

db.ExecuteNonQuery(sql, parameters);

}

更新

//错题比率清零

private void SetZero()

{

string sql = "UPDATE COMPREHENSIVE_EXAM SET Rate = 500 ";

db.ExecuteNonQuery(sql, null);

MessageBox.Show("清零成功");

}

 

//更新数据库中题目排名rate,答对减一,答错加一,并且将错误的答案写到表ErrorList

private void UpadateSqlRate()

{

using (SQLiteConnection connection = new SQLiteConnection("Data Source= CarTraining.db"))

{

connection.Open();

using (DbTransaction transaction = connection.BeginTransaction())

{

using (SQLiteCommand command = new SQLiteCommand(connection))

{

int toAdd = 0;

string sqlsel;

string sqlupd;

 

for (int i = 0; i < 100; i++)

{

int rightAnswer = Convert.ToInt32(dt.Rows[i][4]);

 

if (allAnswer[i] == rightAnswer)

{

toAdd = -1;

}

else

{

toAdd = 1;

}

//根据testID获取表COMPREHENSIVE_EXAM中的Rate排名值

sqlsel = "SELECT Rate FROM COMPREHENSIVE_EXAM WHERE TestID = '"

+ dt.Rows[i][0].ToString() +"'";

command.CommandText = sqlsel;

SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);

DataTable data = new DataTable();

adapter.Fill(data);

//更新表COMPREHENSIVE_EXAM中的排名值

toAdd = Convert.ToInt32(data.Rows[0][0]) + toAdd;

sqlupd = "UPDATE COMPREHENSIVE_EXAM SET Rate = " + toAdd

+ " WHERE TestID = '" + dt.Rows[i][0].ToString() + "'";

command.CommandText = sqlupd;

command.ExecuteNonQuery();

}

}

transaction.Commit();

}

}

}

删除

//错题集清空

private void EmptyErrorList()

{

string sql = "DELETE FROM ERRORLIST";

db.ExecuteNonQuery(sql, null);

MessageBox.Show("错题集清空成功");

}

转载于:https://www.cnblogs.com/zuizuihao/archive/2012/07/18/2598395.html

你可能感兴趣的文章
一致性哈希
查看>>
Web日志安全分析工具 v2.0发布
查看>>
JS重载
查看>>
python2和python3同安装在Windows上,切换问题
查看>>
php加速工具xcache的安装与使用(基于LNMP环境)
查看>>
android超链接
查看>>
统计数据库大小
查看>>
第十六章:脚本化HTTP
查看>>
EXCEL表中如何让数值变成万元或亿元
查看>>
L104
查看>>
用javascript获取地址栏参数
查看>>
一起谈.NET技术,你应该知道的15个Silverlight诀窍
查看>>
商教助手!解析夏普液晶高清宽屏投影机系列
查看>>
云南去年有望实现151万贫困人口净脱贫
查看>>
Java架构师面试题系列整理(大全)
查看>>
延伸产业链 中国产粮大省向“精深”问发展
查看>>
消费贷用户70%月收入低于5000元 80、90后是主要人群
查看>>
2018年内蒙古外贸首次突破1000亿元
查看>>
CTOR有助于BCH石墨烯技术更上一层楼
查看>>
被遗忘的CSS
查看>>