public void InitTestingProcess(TestingProvider provider, ClientScriptManager clientScript) { _provider = provider; _clientScript = clientScript; if (Request["isEnd"] != null && Request["isEnd"] == "true") { _provider.EndTest(); InitQuestionHTML(); return; } if (InitTimeLimit()) { return; } if (!this.IsPostBack) { InitQuestionHTML(); if (provider.CurrentQuestion == null) { Response.Redirect("/Default.aspx"); } Session[SESSIONCURRENTQUESTION] = provider.CurrentQuestion.QuestIndex; } if (Session[SESSIONCURRENTQUESTION] != null) { _provider.SetQuestId((int)Session[SESSIONCURRENTQUESTION]); } }
private bool InitTimeLimit() { if (_provider.TimeLimit == 0) { return(false); } double timeLimit = _provider.TimeLimit * 60; double currentTime = (DateTime.Now - _provider.TestStartTime).TotalSeconds; double remainingTime = timeLimit - currentTime; if (remainingTime <= 0) { _provider.EndTest(); InitQuestionHTML(); return(true); } else { int tlMin = (int)remainingTime / 60; int tlSec = (int)remainingTime % 60; LabelShowTime.Visible = true; if (!Page.IsPostBack) { _clientScript.RegisterStartupScript(Page.GetType(), "ShowTime", @"<script type='text/javascript'> var st=" + tlMin.ToString() + ";var ss=" + tlSec.ToString() + ";showTime();</script>"); } LabelShowTime.Text = String.Format("<div id=\"tm\" style=\"text-align:right;font-family:Tahoma;font-size:9pt;display:inline\">{0}:{1}</div>", tlMin, tlSec.ToString("00")); } return(false); }