在Question set
我得到所有特别的问题(topicID,Marks)
。我正在随机显示问题,totqsn
即要显示的问题总数说 10 个问题,我mark1Qsn,mark2Qsn,mark3Qsn,mark4Qsn
分别在这个 int 变量中存储特定标记(1,2,3,4)的问题数的计数,使用下面的代码我能够显示 QuestionSet 中的 Qustions(比如包含 34 个带有(TopicID,marks)的 qustions)用于 totqsn(比如从 QuestionSet 中随机显示 10 个问题)。我的问题是如何显示总共 10 个问题,其中 3 个问题 1 分,3 个问题 2 分,1 题 3 分,3 题 4 分即
totqsn(10 questions= 3 qsn_of_mark1 + 3 qsn_of_mark2 + 1 qsn_of_mark3 + 3 qsn_of_mark3)
public partial class GroupExmStart : Form
{
DBHandling db = new DBHandling();
string GrpID = "";
string TopiID = "";
int totQsn = 0;
int mark1qsn = 0;
int mark2Qsn = 0;
int mark3Qsn = 0;
int mark4Qsn = 0;
int tik = 0;
string QuestionSet = "";
static Random _r = new Random();
string[] randomQsn = null;
string[] QAndA = null;
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
totQsn = Convert.ToInt16(conf[0]);
mark1qsn = Convert.ToInt16(conf[3]);//this variable contains number of question to be display of mark 1
mark2Qsn = Convert.ToInt16(conf[4]);
mark3Qsn = Convert.ToInt16(conf[5]);
mark4Qsn = Convert.ToInt16(conf[6]);
QuestionSet = db.GetQuestions(TopiID, "1");
QuestionSet = QuestionSet + db.GetQuestions(TopiID, "2");
QuestionSet = QuestionSet + db.GetQuestions(TopiID, "3");
QuestionSet = QuestionSet + db.GetQuestions(TopiID, "4");
int z = Quiz(QuestionSet);
foreach (string qa in QAndA.OrderBy(i => _random.Next()))
{
if (qa != null)
if (qa.IndexOf('~') != -1)
{
randomQsn[count] = qa;
count++;
if (count == totQsn)
break;
}
}
int Quiz(string data)
{
string[] words = data.Split('$');
randomQsn = new string[totQsn + 1];
QAndA = new string[words.Length + 1];
for (int i = 0; i < words.Length; i++)
{
QAndA[i] = words[i];
}
return 0;
}
}
}
从 DBHandling 类访问的 GetQuestions 方法
public string GetQuestions(string TopicID, string Marks)
{
string data = "";
try
{
string sql = "select QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions where TopicID IN(" + TopicID + ") and Marks=" + Marks;
cmd = new OleDbCommand(sql, acccon);
rs = cmd.ExecuteReader();
while (rs.Read())
{
data = data + rs[0].ToString() + "~" + rs[1].ToString() + "~" + rs[2].ToString() + "~" + rs[3].ToString() + "~" + rs[4].ToString() + "~" + rs[5].ToString() + "~" + rs[6].ToString() + "~" + rs[7].ToString() + "$";
}
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
return data;
}
提前感谢您的帮助