毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 论文 >> 正文

asp在线考试系统源码及设计 第6页

更新时间:2010-2-20:  来源:毕业论文
asp在线考试系统源码
部分代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class test : System.Web.UI.Page
{
    int numberofti = 11;//生成试题的数量
    int[] testlist;//存放10个随机数的整型数组
    DataTable Test = new DataTable();//用于存放随机抽取的试题;
    OleDbConnection conn;//数据库连接
    protected string[] userselect = new string[10];//考生选择的答案
    protected string[] trueanswer = new string[10]; //该题正确的答案
    protected void Page_Load(object sender, EventArgs e)
    {
        lblname.Text = (string)Session["username"];
        lbllogintime.Text = (string)Session["logintime"];
        Button1.Visible = false;

    }
    /// <summary>
    /// 生成10个随机整数,并存放于数组中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnbegin_Click(object sender, EventArgs e)
    {
        testlist = new int[numberofti];
        string connecionstring = (string)Application["connectstring"];
        conn = new OleDbConnection(connecionstring);
        string commandtext = "select count(id) from question";
        OleDbCommand comm = new OleDbCommand(commandtext);
        comm.Connection = conn;
        OleDbDataAdapter da = new OleDbDataAdapter(commandtext, conn);
        DataTable dt_rowcount = new DataTable("rowcount");
        da.Fill(dt_rowcount);
        int rows = int.Parse(dt_rowcount.Rows[0][0].ToString());

        for (int i = 0; i < numberofti; i++)
        {
            int temp = GetNumber(rows);
            while (ArrayHasItem(testlist, temp))
            {
                temp = GetNumber(rows);

            }
            testlist[i] = temp;
        }

 

        OleDbConnection newconn = new OleDbConnection((string)Application["connectstring"]);
        OleDbCommand newcomm = new OleDbCommand();
        newcomm.Connection = newconn;
        newconn.Open();
        for (int x = 0; x < numberofti; x++)
        {
            newcomm.CommandText = CreateSQL(testlist[x].ToString());
            newcomm.ExecuteNonQuery();//把数组里每一个题的ID所对应的标志位置为1,表示该题已经选上
        }
        da = new OleDbDataAdapter("select * from question where hasselected='1'", conn);//选择题目
        da.Fill(Test);//把选择的题目放入DataTable
        newcomm.CommandText = "update question set hasselected='0' where hasselected='1'";//把已经选择的题目的标志位置为0,以便下次再选
        conn.Open();
        newcomm.ExecuteNonQuery();
        conn.Close();
        GridView1.DataSource = Test;
        GridView1.DataBind();
        Button1.Visible = true;
        int number = Test.Rows.Count;

    }
    /// <summary>
    /// 按照随机数组里的ID号,抽取试题
    /// </summary>
    /// <param name="temarray"></param>
    /// <returns></returns>
    private DataTable GetTestTittle(int[] temarray)
    {
        DataTable testTable = new DataTable();//存放试题的表
        DataTable temptable = new DataTable();

        www.751com.cn
    /// <summary>
    /// 根据每一个ID号生成SQL语句
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    private string CreateSQL(string id)
    {
        return "update question set hasselected='1' where id=" + id;
    }
    /// <summary>
    /// 得到随机数
    /// </summary>
    /// <param name="maxvalue">随机数的最大值</param>
    /// <returns></returns>
    private int GetNumber(int maxvalue)
    {
        Random rd = new Random(DateTime.Now.Second);
        int result = rd.Next(maxvalue + 1);
        if (result == 0)
            result = 1;
        return result;

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页

asp在线考试系统源码及设计 第6页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。