protected void btnSubmit_Click(object sender, EventArgs e)
        {
            CheckAnswer(Convert.ToInt32(ViewState["num"]));     //to check last question binded answer with database answer
            string Email     = Session["Email"].ToString();
            int    ressubmit = Convert.ToInt32(Session["res"]); //stores final score to insert in db
            List <Tuple <string, string> > parametersList = new List <Tuple <string, string> >();

            parametersList.Add(new Tuple <string, string>("@email", Email));
            parametersList.Add(new Tuple <string, string>("@result", ressubmit.ToString()));
            var data = SqlDataBind.SaveDataByStoredProcedure("usp_UpdateResultData", "ConnectionString", parametersList);

            if (data > 0)
            {
                lblresult.Visible   = true;
                btnNext.Visible     = false;
                btnSubmit.Visible   = false;
                lblQuestion.Visible = false;
                lblQNumber.Visible  = false;
                rboption1.Visible   = false;
                rboption2.Visible   = false;
                rboption3.Visible   = false;
                rboption4.Visible   = false;
                lblresult.Text      = "Your Result is: " + ressubmit.ToString() + "/10";
            }
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            sqlConnection.Open();
            SqlCommand cmd = new SqlCommand("usp_CheckEmailExists", sqlConnection);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@email", txtEmail.Text);
            int result = (Int32)cmd.ExecuteScalar();

            if (result == 1)
            {
                Session["Email"] = txtEmail.Text;
                Response.Redirect("Exam.aspx");
                ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Logged in successfully');", true);
            }
            else
            {
                List <Tuple <string, string> > parametersList = new List <Tuple <string, string> >();
                parametersList.Add(new Tuple <string, string>("@email", txtEmail.Text));
                var data = SqlDataBind.SaveDataByStoredProcedure("usp_InsertUserData", "ConnectionString", parametersList);
                if (data > 0)
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Logged in successfully');", true);
                }
                Session["Email"] = txtEmail.Text;
                Response.Redirect("Exam.aspx");
            }
        }
Пример #3
0
        void BindData()//Get all questions in grid view
        {
            var data = SqlDataBind.GetDataByStoredProcedure("usp_GetAllQuestions", "ConnectionString");

            if (data.Tables[0].Rows.Count > 0)
            {
                gvBlog.DataSource = data.Tables[0];
                gvBlog.DataBind();
            }
        }
Пример #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string        value;
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            sqlConnection.Open();
            SqlCommand cmd = new SqlCommand("usp_GetCountOfQuestion", sqlConnection);//get count of question

            cmd.CommandType = CommandType.StoredProcedure;
            int count = (Int32)cmd.ExecuteScalar();

            if (count == 10)//check count is less than or equal because not to allow more than 10 questions to add
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Only 10 questions allowed');", true);
            }
            else
            {
                if (rboption1.Checked)
                {
                    value = "1";
                }
                else if (rboption2.Checked)
                {
                    value = "2";
                }
                else if (rboption3.Checked)
                {
                    value = "3";
                }
                else
                {
                    value = "4";
                }
                int id = 0;
                List <Tuple <string, string> > parametersList = new List <Tuple <string, string> >();
                if (!string.IsNullOrWhiteSpace(Request.QueryString["QuestionID"]))
                {
                    id = Convert.ToInt32(Request.QueryString["QuestionID"]);
                }
                parametersList.Add(new Tuple <string, string>("@Id", id.ToString()));
                parametersList.Add(new Tuple <string, string>("@question", txtQuestion.Text.Trim()));
                parametersList.Add(new Tuple <string, string>("@option1", txtOption1.Text.Trim()));
                parametersList.Add(new Tuple <string, string>("@option2", txtOption2.Text.Trim()));
                parametersList.Add(new Tuple <string, string>("@option3", txtOption3.Text.Trim()));
                parametersList.Add(new Tuple <string, string>("@option4", txtOption4.Text.Trim()));
                parametersList.Add(new Tuple <string, string>("@answer", value.Trim()));
                var data = SqlDataBind.SaveDataByStoredProcedure("usp_InsertQuestion", "ConnectionString", parametersList);
                ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Data saved successfully');", true);
                Clear();
                BindData();
            }
        }
Пример #5
0
        //Delete question by its ID
        protected void gvBlog_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int QuestionID = (int)e.Keys["QuestionID"];
            List <Tuple <string, string> > parameterList = new List <Tuple <string, string> >();

            parameterList.Add(new Tuple <string, string>("@Id", QuestionID.ToString()));
            var data = SqlDataBind.SaveDataByStoredProcedure("usp_DeleteQuestionById", "ConnectionString", parameterList);

            if (data > 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Data Deleted successfully');", true);
            }
            BindData();
        }
 int value  = 0; //to get value of which radio button clicked.
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["Email"] != null)
         {
             string Email = Session["Email"].ToString();
             List <Tuple <string, string> > parameterList = new List <Tuple <string, string> >();
             parameterList.Add(new Tuple <string, string>("@email", Email));
             var data = SqlDataBind.GetDataByStoredProcedure("usp_SelectUserData", "ConnectionString", parameterList);
             if (data.Tables[0].Rows.Count > 0)
             {
                 ViewState["num"] = Convert.ToInt32(data.Tables[0].Rows[0]["Session"]);
                 int results  = Convert.ToInt32(data.Tables[0].Rows[0]["Result"]);
                 int issubmit = Convert.ToInt32(data.Tables[0].Rows[0]["IsSubmit"]);
                 if (issubmit > 0)//Check whether user already submitted.
                 {
                     lblresult.Visible   = true;
                     btnNext.Visible     = false;
                     btnSubmit.Visible   = false;
                     lblQuestion.Visible = false;
                     lblQNumber.Visible  = false;
                     rboption1.Visible   = false;
                     rboption2.Visible   = false;
                     rboption3.Visible   = false;
                     rboption4.Visible   = false;
                     lblresult.Text      = "Your Result is: " + results.ToString() + "/10";
                 }
                 else
                 {
                     BindQuestion(Convert.ToInt32(ViewState["num"]));
                     Points            = results;
                     lblresult.Visible = false;
                 }
             }
             else
             {
                 Points           = Convert.ToInt32(Session["res"]);//if there is value in session variable then it assign to point then next flow continue from there.
                 ViewState["num"] = Number;
                 BindQuestion(Number);
             }
         }
         else
         {
             Response.Redirect("Login.aspx");
         }
     }
 }
        private void BindQuestion(int Number)//To get question one by one on next button click
        {
            List <Tuple <string, string> > parameterList = new List <Tuple <string, string> >();

            parameterList.Add(new Tuple <string, string>("@Id", Number.ToString()));
            var data = SqlDataBind.GetDataByStoredProcedure("usp_GetQuestionsOneByOne", "ConnectionString", parameterList);

            if (data.Tables[0].Rows.Count > 0)
            {
                lblQNumber.InnerText  = data.Tables[0].Rows[0]["QuestionID"].ToString() + ". ";
                lblQuestion.InnerText = data.Tables[0].Rows[0]["Question"].ToString();
                rboption1.Text        = data.Tables[0].Rows[0]["Option1"].ToString();
                rboption2.Text        = data.Tables[0].Rows[0]["Option2"].ToString();
                rboption3.Text        = data.Tables[0].Rows[0]["Option3"].ToString();
                rboption4.Text        = data.Tables[0].Rows[0]["Option4"].ToString();
            }
        }
Пример #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!IsPostBack)
         {
             BindData();
             if (!string.IsNullOrWhiteSpace(Request.QueryString["QuestionID"]))
             {
                 string id = Request.QueryString["QuestionID"].ToString();
                 List <Tuple <string, string> > parametersList = new List <Tuple <string, string> >();
                 parametersList.Add(new Tuple <string, string>("@Id", id));
                 var data = SqlDataBind.GetDataByStoredProcedure("usp_GetQuestionById", "ConnectionString", parametersList);//Get Question in textboxes to update
                 if (data.Tables[0].Rows.Count > 0)
                 {
                     txtQuestion.Text = data.Tables[0].Rows[0]["Question"].ToString();
                     txtOption1.Text  = data.Tables[0].Rows[0]["Option1"].ToString();
                     txtOption2.Text  = data.Tables[0].Rows[0]["Option2"].ToString();
                     txtOption3.Text  = data.Tables[0].Rows[0]["Option3"].ToString();
                     txtOption4.Text  = data.Tables[0].Rows[0]["Option4"].ToString();
                     string answer = data.Tables[0].Rows[0]["Answer"].ToString();
                     if (answer == "1")
                     {
                         rboption1.Checked = true;
                     }
                     else if (answer == "2")
                     {
                         rboption2.Checked = true;
                     }
                     else if (answer == "3")
                     {
                         rboption3.Checked = true;
                     }
                     else
                     {
                         rboption4.Checked = true;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
 }
        private void CheckAnswer(int Number)//to check answer of currect question binded in elements.
        {
            if (rboption1.Checked == true)
            {
                value = 1;
            }
            else if (rboption2.Checked == true)
            {
                value = 2;
            }
            else if (rboption3.Checked == true)
            {
                value = 3;
            }
            else if (rboption4.Checked == true)
            {
                value = 4;
            }
            List <Tuple <string, string> > parameterList = new List <Tuple <string, string> >();

            parameterList.Add(new Tuple <string, string>("@Id", Number.ToString()));
            var data = SqlDataBind.GetDataByStoredProcedure("usp_GetQuestionsOneByOne", "ConnectionString", parameterList);

            if (data.Tables[0].Rows.Count > 0)
            {
                string answer = data.Tables[0].Rows[0]["Answer"].ToString();
                if (value == Convert.ToInt32(answer))             //Check whether database and user selected answer match?
                {
                    Points = Convert.ToInt32(Session["res"]) + 1; //Correct
                }
                else
                {
                    Points = Convert.ToInt32(Session["res"]); //incorrect
                }
                Session["res"]    = Points;                   //assign point to session because page is going to load again and again
                rboption1.Checked = false;
                rboption2.Checked = false;
                rboption3.Checked = false;
                rboption4.Checked = false;
            }
        }
        protected void btnLogout_Click(object sender, EventArgs e)
        {
            CheckAnswer(Convert.ToInt32(ViewState["num"]));
            int    Number = Convert.ToInt32(ViewState["num"]);
            int    result = Convert.ToInt32(Session["res"]);
            string Email  = Session["Email"].ToString();
            List <Tuple <string, string> > parametersList = new List <Tuple <string, string> >();

            parametersList.Add(new Tuple <string, string>("@session", Number.ToString()));
            parametersList.Add(new Tuple <string, string>("@result", result.ToString()));
            parametersList.Add(new Tuple <string, string>("@email", Email));

            var data = SqlDataBind.SaveDataByStoredProcedure("usp_UpdateSessionData", "ConnectionString", parametersList);//store all values because if this user comes back then get him/her to directly there where he left.

            if (data > 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "success", "alert('Logout successfully');", true);
                Session["Email"] = null;
                Session.Abandon();
                Response.Redirect("Login.aspx");
            }
        }