这是自动考试系统上的 开始考试 按钮的代码
private void btnStart_Click(object sender, EventArgs e)
{
string StrSql="";
if (this.btnStart.Text == "开始考试")
{
this.label3.Text = DateTime.Now.ToShortTimeString();
StrSql = "Update tbl_XuanKe set stats='T' where classid='" + this.cmbClass.Text.Substring(0, 3) + "' and kcid='" + this.cmbKeMu.Text.Substring(0, 2) + "'";
this.timer1.Enabled = true;
this.btnStart.Text = "停止考试";
this.cmbClass.Enabled = cmbKeMu.Enabled = false;
}
else
{
StrSql = "Update tbl_XuanKe set stats='F' where classid='" + this.cmbClass.Text.Substring(0, 3) + "' and kcid='" + this.cmbKeMu.Text.Substring(0, 2) + "'";
this.timer1.Enabled = false;
this.btnStart.Text = "开始考试";
this.cmbClass.Enabled = cmbKeMu.Enabled = true;
}
if (MyClass.ExecuteDate(StrSql) < 0)
{
MessageBox.Show("考试开始出错!");
return;
}
listView1.Items.Clear();
DataSet myset1 = new DataSet();
myset1 = MyClass.QueryDate("select nostudent,name from studentname where banji='" + cmbClass.Text.Substring(0, 3) + "'");
for (int i = 0; i < myset1.Tables[0].Rows.Count; i++)
{
ListViewItem aa = new ListViewItem();
aa.ImageIndex = 0;
aa.Text = myset1.Tables[0].Rows[i][0].ToString() +"_"+ myset1.Tables[0].Rows[i][1].ToString();
this.listView1.Items.Add(aa);
}
}
private void btnStart_Click(object sender, EventArgs e)
{
string StrSql="";
if (this.btnStart.Text == "开始考试")
{
this.label3.Text = DateTime.Now.ToShortTimeString();
StrSql = "Update tbl_XuanKe set stats='T' where classid='" + this.cmbClass.Text.Substring(0, 3) + "' and kcid='" + this.cmbKeMu.Text.Substring(0, 2) + "'";
this.timer1.Enabled = true;
this.btnStart.Text = "停止考试";
this.cmbClass.Enabled = cmbKeMu.Enabled = false;
}
else
{
StrSql = "Update tbl_XuanKe set stats='F' where classid='" + this.cmbClass.Text.Substring(0, 3) + "' and kcid='" + this.cmbKeMu.Text.Substring(0, 2) + "'";
this.timer1.Enabled = false;
this.btnStart.Text = "开始考试";
this.cmbClass.Enabled = cmbKeMu.Enabled = true;
}
if (MyClass.ExecuteDate(StrSql) < 0)
{
MessageBox.Show("考试开始出错!");
return;
}
listView1.Items.Clear();
DataSet myset1 = new DataSet();
myset1 = MyClass.QueryDate("select nostudent,name from studentname where banji='" + cmbClass.Text.Substring(0, 3) + "'");
for (int i = 0; i < myset1.Tables[0].Rows.Count; i++)
{
ListViewItem aa = new ListViewItem();
aa.ImageIndex = 0;
aa.Text = myset1.Tables[0].Rows[i][0].ToString() +"_"+ myset1.Tables[0].Rows[i][1].ToString();
this.listView1.Items.Add(aa);
}
}