private void Form1_Load(object sender, EventArgs e) { _data = new MyData() { FirstName = "Corey", LastName = "Derochie", Age = 29, LikesCheese = true }; _auto.DataSource = _data; enableButtons(); _auto.DirtyChanged += new AutoControl.DirtyChangeEvent(_auto_DirtyChanged); }
private void BtnDown_Click(object sender, System.EventArgs e) { String StrSQL = "select 答卷.试题编号 as 试题编号,答卷.题型 as 题型,答卷.学生答案 as 学生答案 from 答卷,分值 where 答卷.试卷号=分值.试卷号 and 答卷.学号='" + Session["Student_ID"].ToString() + "' and 分值.使用日期=#" + DateTime.Now.ToShortDateString() + "#"; MyData md = new MyData(Application["connstr"].ToString());//从答卷表中将考试日期为今日的与该生有关的所有试题取出 OleDbDataReader DR = md.eSelect(StrSQL); while (DR.Read()) { //如果能够取出试题,则遍历所有试题 if (DR["学生答案"].ToString() != "") { //如果当前试题的学生答案字段不为空 switch (DR["题型"].ToString()) { case "单选题": //如果当前试题为单选题 for (int i = 0; i < rpCust1.Items.Count; i++) { //从rpCust1控件中找出该试题,并将学生答案标记在相应的RadioButton上 Label lbl = (Label)rpCust1.Items[i].FindControl("lbl_dan_stbh"); //lbl_dan_stbh里存有当前试题的试题号 if (DR["试题编号"].ToString() == lbl.Text) { string rb_name = ""; switch (DR["学生答案"].ToString()) { case "A": rb_name = "rb_xxa"; break; case "B": rb_name = "rb_xxb"; break; case "C": rb_name = "rb_xxc"; break; case "D": rb_name = "rb_xxd"; break; } RadioButton rb = (RadioButton)rpCust1.Items[i].FindControl(rb_name); rb.Checked = true; } } break; case "多选题": //如果当前试题为多选题 for (int i = 0; i < rpCust2.Items.Count; i++) { //从rpCust2控件中找出该试题,并将学生答案标记在相应的CheckBox上 Label lbl = (Label)rpCust2.Items[i].FindControl("lbl_duo_stbh"); //lbl_duo_stbh里存有当前试题的试题号 if (DR["试题编号"].ToString() == lbl.Text) { string cb_name = ""; for (int j = 0; j < DR["学生答案"].ToString().Length; j++) { switch (DR["学生答案"].ToString().Substring(j, 1)) { case "A": cb_name = "cb_xxa"; break; case "B": cb_name = "cb_xxb"; break; case "C": cb_name = "cb_xxc"; break; case "D": cb_name = "cb_xxd"; break; } CheckBox cb = (CheckBox)rpCust2.Items[i].FindControl(cb_name); cb.Checked = true; } } } break; case "判断题": //如果当前试题为判断题 for (int i = 0; i < rpCust3.Items.Count; i++) { //从rpCust3控件中找出该试题,并将学生答案标记在相应的RadioButton上 Label lbl = (Label)rpCust3.Items[i].FindControl("lbl_pan_stbh"); //lbl_pan_stbh里存有当前试题的试题号 if (DR["试题编号"].ToString() == lbl.Text) { string rb_name = ""; if (DR["学生答案"].ToString() == "对") { rb_name = "rb_pan1"; } else { rb_name = "rb_pan2"; } RadioButton rb = (RadioButton)rpCust3.Items[i].FindControl(rb_name); rb.Checked = true; } } break; case "简答题": //如果当前试题为简答题 for (int i = 0; i < rpCust4.Items.Count; i++) { //从rpCust4控件中找出该试题,并将学生答案输出在TextBox上 Label lbl = (Label)rpCust4.Items[i].FindControl("lbl_jian_stbh"); //lbl_jian_stbh里存有当前试题的试题编号 if (DR["试题编号"].ToString() == lbl.Text) { TextBox tb = (TextBox)rpCust4.Items[i].FindControl("txt_jian"); tb.Text = DR["学生答案"].ToString(); } } break; case "编程题": //如果当前试题为编程题 for (int i = 0; i < rpCust5.Items.Count; i++) { //从rpCust5控件中找出该试题,并将学生答案输出在TextBox上 Label lbl = (Label)rpCust5.Items[i].FindControl("lbl_bian_stbh"); //lbl_bian_stbh里存有当前试题的试题编号 if (DR["试题编号"].ToString() == lbl.Text) { TextBox tb = (TextBox)rpCust5.Items[i].FindControl("txt_bian"); tb.Text = DR["学生答案"].ToString(); } } break; case "填空题": //如果当前试题为填空题 for (int i = 0; i < rpCust6.Items.Count; i++) { //从rpCust6控件中找出该试题,并将学生答案输出在相应的TextBox上 Label lbl = (Label)rpCust6.Items[i].FindControl("lbl_tian_stbh"); //lbl_tian_stbh里存有当前试题的试题编号 if (DR["试题编号"].ToString() == lbl.Text) { string[] daan = DR["学生答案"].ToString().Split(','); for (int j = 1; j <= daan.Length; j++) { TextBox tb = (TextBox)rpCust6.Items[i].FindControl("txt_tk" + j); tb.Text = daan[j - 1]; if (j > 0) { tb.Visible = true; } } } } break; } } } md.CloseConn(); }
private void Page_Load(object sender, System.EventArgs e) { Response.Buffer = true; Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1); Response.Expires = 0; Response.CacheControl = "no-cache"; MyData md; if (Session["Student_ID"] == null) { new MyMethods().AlertAndRedirect("'必须登陆才能进行考试!", "/test/login.aspx"); return; } DateTime FirstLoginTime = DateTime.Parse(Session["logintime"].ToString()); System.TimeSpan remain_time = DateTime.Now.Date.AddDays(1) - FirstLoginTime; //计算第一次登陆时间距离第二日凌晨的时差 if (remain_time.TotalSeconds < 7200) { //如果不足120分钟,则考试时间限定在凌晨前1分钟结束 remain_time = DateTime.Now.Date.AddDays(1) - DateTime.Now; Session["Time"] = (int)remain_time.TotalSeconds - 60; } else { //否则计算计算此时到考试登陆之后120分钟的时差 remain_time = DateTime.Now - FirstLoginTime; Session["Time"] = 7200 - (int)remain_time.TotalSeconds; } if (!IsPostBack) { xuehao.Text = Convert.ToString(Session["Student_ID"]); //将学号显示页面上方 name.Text = Convert.ToString(Session["Student_name"]); //将姓名显示在页面上方 xuehao2.Text = xuehao.Text; //将学号显示页面下方 name2.Text = name.Text; //将姓名显示在页面下方 int shijuan_total, curr_tixing_num = 0; //前者记录可选试卷数,后者记录该试卷当前题型的的序号 string StrSQL; OleDbDataReader DR; if (Session["shijuanhao"] != null) { //如果学生非第一次登陆 StrSQL = "select * from 分值 where 试卷号='" + Session["shijuanhao"].ToString() + "'"; md = new MyData(Application["connstr"].ToString()); DR = md.eSelect(StrSQL); DR.Read(); BtnDown.Visible = true; } else { //如果学生第一次登陆 StrSQL = "select count(*) as 试卷数 from 分值 where 使用日期=#" + DateTime.Now.ToShortDateString() + "#"; //统计可选试卷数 md = new MyData(Application["connstr"].ToString()); DR = md.eSelect(StrSQL); bool ishasdata = DR.Read(); shijuan_total = Convert.ToInt16(DR["试卷数"]); DR.Close(); md.CloseConn(); Random r = new Random(unchecked ((int)DateTime.Now.Ticks)); //随机到的试卷的位置 int curr_shijuan_num = (int)((shijuan_total) * r.NextDouble() + 1); StrSQL = "select * from 分值 where 使用日期=#" + DateTime.Now.ToShortDateString() + "# order by 试卷号"; md = new MyData(Application["connstr"].ToString()); DR = md.eSelect(StrSQL); for (int i = 1; i <= curr_shijuan_num; i++) { DR.Read(); //定位到该试卷 } Session["shijuanhao"] = Convert.ToString(DR["试卷号"]); new MyData(Application["connstr"].ToString()).eInsertUpdateDelete("update 学生 set 本次试卷号='" + Session["shijuanhao"].ToString() + "' where 学号='" + xuehao.Text + "'"); //记录学生首次登陆使用的试卷 } for (int i = 0; i <= 5; i++) { //设置各题型题头信息的显示 string curr_tixing = null; System.Text.StringBuilder curr_head = null; GetHeadVariables(ref curr_tixing, ref curr_head, i); //该方法可根据i值,返回不同的题型给curr_tixing,返回不同的用来存题头信息的变量的引用 string str_tl_last, str_fz_last; if (i == 2) { //填空题 str_tl_last = "题空量"; str_fz_last = "题每空分值"; } else { //其他题 str_tl_last = "题量"; str_fz_last = "题每题分值"; } if (Convert.ToString(DR[curr_tixing + str_tl_last]) != "0") { //如果当前题型的题量不为0,则设置题头信息 curr_tixing_num += 1; curr_head.Remove(0, curr_head.ToString().Length); curr_head.Append(num_to_word(curr_tixing_num) + "、" + curr_tixing + "题(共" + Convert.ToString(DR[curr_tixing + str_tl_last]) + "题,每题" + Convert.ToString(DR[curr_tixing + str_fz_last]) + "分)"); } else { //否则题头信息为空 curr_head.Append(""); } } DR.Close(); md.CloseConn(); for (int j = 0; j <= 5; j++) { //将本试卷各题型的试题取出,并绑定到相应的Repeater Repeater rp = null; string tixing = ""; switch (j) { case 0: tixing = "单选题"; rp = rpCust1; break; case 1: tixing = "多选题"; rp = rpCust2; break; case 2: tixing = "判断题"; rp = rpCust3; break; case 3: tixing = "简答题"; rp = rpCust4; break; case 4: tixing = "编程题"; rp = rpCust5; break; case 5: tixing = "填空题"; rp = rpCust6; break; } String strSQL = "select * from " + tixing + ",组卷 where " + tixing + ".id=组卷.试题编号 and 组卷.题型='" + tixing + "' and 组卷.试卷号='" + Session["shijuanhao"].ToString() + "' order by 顺序号 ASC"; new MyMethods().Repeater_bind(rp, ref ds[j], strSQL, Application["connstr"].ToString()); } } else { } }