多用户在线考试系统中的计时器问题 [英] Timer Problem in multi user online exam system

查看:109
本文介绍了多用户在线考试系统中的计时器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须开发多用户在线考试系统所有工作都已完成,但有一个问题是,当另一个用户登录考试系统时,他的计时器值会改变之前的用户计时器值。

。 >
i使用2个静态int值分钟和秒。

请帮助我的代码是



i have to develop multi user online exam system all work is completed but one problem is that
when another user login in exam system then his timer value change the previous user Timer value.
i have use 2 static int value for minute and second.
Please help my code is

static int tmpStartmin = 0;
static int tmpStartSecond = 59;

 protected void SetExamTimer()
    {

        Timer1.Enabled = false;
        if (Session["QStartTime"] == null)
            Session.Add("QStartTime", DateTime.Now);
        else
            Session["QStartTime"] = DateTime.Now;
        SqlConnection sqcontime = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString);
        string sqtime = "";
        DataTable dtt = new DataTable();
        sqtime = "Select Top 1 * from TimeLog Where QuestionPaper_ID=" + int.Parse(Session["QuesPaper_ID"].ToString()) + " and Registration_ID=" + int.Parse(Session["RegistrationID"].ToString()) + " and isdeleted=0 Order by Timelog_Id desc ";
        SqlDataAdapter adptime = new SqlDataAdapter(sqtime, sqcontime);
        adptime.Fill(dtt);
        if (dtt.Rows.Count > 0)
        {
            divTime.Visible = true;
            Timer1.Enabled = true;
            if (Session["QStartTime"] == null)
                Session.Add("QStartTime", DateTime.Now);
            else
                Session["QStartTime"] = DateTime.Now;
            lblTime.Text = dtt.Rows[0]["Time"].ToString();          
            tmpStartmin = Convert.ToInt32(dtt.Rows[0]["Min"].ToString());
            tmpStartSecond = Convert.ToInt32(dtt.Rows[0]["Sec"].ToString());
            lblMinute.Text = tmpStartmin.ToString();
            lblSeconds.Text = tmpStartSecond.ToString();

        }
        else
        {


            string sqq = "";
            DataTable dt = new DataTable();
            sqq = "Select * from StDetail Where QuestionPaper_ID=" + int.Parse(Session["QuesPaper_ID"].ToString()) + " and isdeleted=0";
            SqlDataAdapter dq = new SqlDataAdapter(sqq, System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStr"].ConnectionString);
            dq.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                divTime.Visible = true;
                Timer1.Enabled = true;
                if (Session["QStartTime"] == null)
                    Session.Add("QStartTime", DateTime.Now);
                else
                    Session["QStartTime"] = DateTime.Now;
                lblTime.Text = dt.Rows[0]["FixedExamTime"].ToString();
                tmpStartmin = Convert.ToInt32(dt.Rows[0]["FixedExamTime"].ToString()) - 1;
                lblMinute.Text = tmpStartmin.ToString();
                lblSeconds.Text = tmpStartSecond.ToString();
            }
            else
            {
                divTime.Visible = false;
                Timer1.Enabled = false;
                if (Session["QStartTime"] == null)
                    Session.Add("QStartTime", DateTime.Now);
                else
                    Session["QStartTime"] = DateTime.Now;
            }


        }
    }

推荐答案

你回答了对于你自己 - 不要使用需要实例变量的静态变量 -
You answered it for yourself - don't use static variables where instance variables are needed -


当用户登录时你可以重置下面的值

when user logged in you can reset the values as below
protected void SetExamTimer()
{
  tmpStartmin=0;
  tmpStartSecond = 59;





或使用另外两个会话值作为开始分钟和开始秒。清除用户注销时的会话值并登录。



or use another two session values for start minutes and start seconds. clear those session values on user log out and log in.


这篇关于多用户在线考试系统中的计时器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆