Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            answers = new List <ListItem> {
                answer1, answer2, answer3, answer4
            };

            if (!IsPostBack)
            {
                User user = new classes.User();

                bool whichQuestions = user.GetLicenseApproved((string)Session["username"]);
                if (whichQuestions == true)
                {
                    int getExam = 2;
                    typeOfExam.Text        = "Typ: Årligt kunskapstest";
                    questionIDs            = examina.GetQuestionIDs(getExam);
                    Session["questionIDs"] = questionIDs;
                }
                else
                {
                    int getExam = 1;
                    typeOfExam.Text        = "Typ: Licensieringstest";
                    questionIDs            = examina.GetQuestionIDs(getExam);
                    Session["questionIDs"] = questionIDs;
                }

                qnbr.Visible = false;
                CheckBoxListAnswers.Visible = false;
                hr.Visible       = false;
                btnNext.Visible  = false;
                btnStart.Visible = true;
                H1.Visible       = true;
                text.Visible     = true;
            }
            else
            {
                qnbr.Visible = true;
                CheckBoxListAnswers.Visible = true;
                hr.Visible       = true;
                btnNext.Visible  = true;
                btnStart.Visible = false;
                H1.Visible       = false;
                text.Visible     = false;
            }
        }
Ejemplo n.º 2
0
        //EVENTS
        protected void btnNext_Click(object sender, EventArgs e)
        {
            Exam   xam                   = new Exam();
            string selectedAnswer        = "";
            int    countNoSelections     = 0;
            int    countToManySelected   = 0;
            bool   correctAmountSelected = false;

            questionCounter++;

            var questInList = (List <int>)Session["questionIDs"];

            questcounter.Text = "Frågor kvar: " + questInList.Count.ToString() + "";

            ScriptManager.RegisterStartupScript(this, GetType(), "Resume", "resumeCountdown()", true);

            XmlDocument doc = new XmlDocument();

            doc.Load(Server.MapPath("xml/prov.xml"));

            XmlNode nodeOne = doc.SelectSingleNode("//Prov/Kategori[@ id='" + xam.GetCategory((int)Session["rqID"]) + "']");

            foreach (ListItem item in CheckBoxListAnswers.Items)
            {
                if (item.Selected == true)
                {
                    countToManySelected++;
                    if (countToManySelected > 1)
                    {
                        Response.Write("<script>alert('Du har markerat för många svar! Markera endast ett svar, tack.');</script>");
                        return;
                    }
                    else
                    {
                        correctAmountSelected = item.Selected;
                    }
                }
            }

            foreach (ListItem item in CheckBoxListAnswers.Items)
            {
                countNoSelections++;

                if (correctAmountSelected == true && item.Text == xam.GetCorrectAnswerTemp((int)Session["rqID"]))
                {
                    selectedAnswer = item.Text;
                    break;
                }
                else if (correctAmountSelected == true && item.Text != xam.GetCorrectAnswerTemp((int)Session["rqID"]))
                {
                    selectedAnswer = item.Text;
                    break;
                }
                else if (countNoSelections >= 4)
                {
                    Response.Write("<script>alert('Markera ett svar!');</script>");
                    return;
                }
            }

            XElement question = new XElement("Fråga");
            XElement ans1     = new XElement("Svar");

            question.SetAttributeValue("id", (int)Session["rqID"]);
            question.SetElementValue("Text", (string)Session["RandomQuestion"]);
            question.SetElementValue("SvarEtt", Session["0"]);
            question.SetElementValue("SvarTvå", Session["1"]);
            question.SetElementValue("SvarTre", Session["2"]);
            question.SetElementValue("SvarFyra", Session["3"]);
            question.SetElementValue("RättSvar", xam.GetCorrectAnswerTemp((int)Session["rqID"]));
            question.SetElementValue("Markeratsvar", selectedAnswer);

            XmlDocument docTwo = new XmlDocument();

            docTwo.LoadXml("" + question + "");

            XmlNode nodeTwo = doc.ImportNode(docTwo.FirstChild, true);

            nodeOne.AppendChild(nodeTwo);

            doc.Save(Server.MapPath("xml/prov.xml"));

            User user = new classes.User();

            var list = (List <int>)Session["questionIDs"];

            if (list.Count == 0)
            {
                string   xmlstring = doc.OuterXml;
                string   uname     = (string)Session["username"];
                DateTime date      = DateTime.Now;
                xam.xmlToDb(uname, xmlstring, date);

                doc.DocumentElement.RemoveAll();

                XDeclaration dec     = new XDeclaration("1.0", "utf-8", "no");
                XElement     etik    = new XElement("Kategori");
                XElement     produkt = new XElement("Kategori");
                XElement     ekonomi = new XElement("Kategori");

                etik.SetAttributeValue("id", "Etik");
                produkt.SetAttributeValue("id", "Produkt");
                ekonomi.SetAttributeValue("id", "Ekonomi");

                doc.LoadXml("" + dec + " <Prov>" + etik + " " + produkt + " " + ekonomi + "</Prov>");

                doc.Save(Server.MapPath("xml/prov.xml"));

                questionCounter = 0;

                Response.Redirect("examDone.aspx");
            }

            CheckBoxListAnswers.ClearSelection();

            GetNewQuestionAndAnswers();

            category.InnerText = "Kategori: " + xam.GetCategory((int)Session["rqID"]) + "";
        }