protected void AnswerOnQuestion(object sender, EventArgs e)
        {
            FLAGLAR userQuenstionAnswer = new FLAGLAR();
            int     ag = 0;
            int     ab = 0;
            int     aa = 0;

            if (Session["Answergood"] != null)
            {
                ag = (int)Session["Answergood"];
            }
            if (Session["Answerbad"] != null)
            {
                ab = (int)Session["Answerbad"];
            }
            if (Session["AnswerAll"] != null)
            {
                aa = (int)Session["AnswerAll"];
            }
            var    testId    = Convert.ToInt32(Request["testId"]);
            var    questId   = Convert.ToInt32(Request["questId"]);
            var    Qest_list = Session["quest_list"] as List <Questionss>;
            var    Answ_list = Session["answ_list"] as List <Answerss>;
            var    answerss  = Session["answerss"];
            string textQ     = "";

            if (questId == 0)
            {
                foreach (var td in Qest_list)
                {
                    if (td.ID != questId)
                    {
                        questId = td.ID;
                    }
                    break;
                }
            }
            foreach (var g in Qest_list)
            {
                if (g.ID == questId)
                {
                    textQ = g.QuestName;
                }
                else
                {
                    continue;
                }
            }
            var chks = new List <Proverka>();

            //  var text_otveta = new List<string>();
            foreach (var chk in Panel2.Controls)
            {
                if (chk is RadioButton)
                {
                    if ((chk as RadioButton).Checked)
                    {
                        Proverka row = new Proverka
                        {
                            IsChoosed = true,
                            textO     = (chk as RadioButton).Text
                        };
                        chks.Add(row);
                        //chks.Add(true);
                        //text_otveta.Add((chk as RadioButton).Text);
                    }
                    else
                    {
                        Proverka row = new Proverka
                        {
                            IsChoosed = false,
                            textO     = (chk as RadioButton).Text
                        };
                        chks.Add(row);
                        //chks.Add(false);
                        //text_otveta.Add((chk as RadioButton).Text);
                    }
                }
            }
            var t       = 0;
            var counter = 0;
            var flags   = Answ_list.Where(s => s.QuestionId == questId).Select(s => s);

            // var texts = Answ_list.Where(s => s.QuestionId == questId).Select(s => s.TextOtv);

            foreach (var tx in chks)
            {
                foreach (var tw in flags)
                {
                    if (tx.textO.Equals(tw.AnswerText) & tx.IsChoosed == tw.IsAnswerCorrect)
                    {
                    }
                    else if (tx.textO.Equals(tw.AnswerText) & tx.IsChoosed != tw.IsAnswerCorrect)
                    {
                        counter++;
                    }
                }
            }

            userQuenstionAnswer = new FLAGLAR {
                IdQuestion = questId, UserAnswerText = chks.Select(d => d.IsChoosed).ToList(), textQ = textQ
            };
            for (int i = 0; i < chks.Count; i++)
            {
                if (chks[i].IsChoosed == true)
                {
                    userQuenstionAnswer.IdUserAnswer = obj.QA.Where(l => l.QUESTIONID == questId).ToList()[i].ANSWERID.Value;
                    break;
                }
            }
            List <FLAGLAR> Flag_list;

            if (Session["chks"] == null)
            {
                Flag_list = new List <FLAGLAR>();
            }
            else
            {
                Flag_list = (List <FLAGLAR>)Session["chks"];
            }
            Flag_list.Add(userQuenstionAnswer);
            Session["chks"] = Flag_list;

            var result = false;

            if (counter > 0)
            {
                ab++;
                Session["Answerbad"] = ab;
            }
            else
            {
                ag++;
                Session["Answergood"] = ag;
                result = true;
            }

            aa = ag + ab;

            Session["AnswerAll"] = aa;

            var element = new ResultClassMy {
                QuestionId = questId, Result = result
            };

            List <ResultClassMy> element_list = new List <ResultClassMy>();

            element_list.Add(element);
            if (Session["Values"] == null)
            {
                Session["Values"] = element_list;
            }
            else
            {
                (Session["Values"] as List <ResultClassMy>).Add(element);
            }

            int index = (int)Session["Index"];

            Session["Index"] = ++index;
            if (aa == obj.QUESTION.Where(l => l.TESTID == testId).Count())
            {
                Labeltimer.Text = (finishTime - DateTime.Now).ToString(@"mm\:ss");
                if (Session["finishTime"] != null)
                {
                    Session["finishTime"] = null;
                }
                Timer1.Enabled = false;
                //!!!!!!!
                Response.Redirect("UserResult.aspx?testId=" + testId);
            }
            try
            {
                questId = Qest_list.AsEnumerable().ElementAt(index).ID;
            }
            catch { }
            string url = "ExamQuestion.aspx?testId=" + testId + "&questId=" + questId;

            Response.Redirect(url);
        }
Exemple #2
0
        /*-------------------------------кнопка: "ответить"------------------------------------------------------*/


        protected void Ans(object sender, EventArgs e)
        {
            int schetchik = 0;

            if (Session["sch"] != null)
            {
                schetchik = (int)Session["sch"];
            }

            FLAGLARsew flagi = new FLAGLARsew();

            ResultClassMy element = new ResultClassMy();
            int           ag      = 0;
            int           ab      = 0;
            int           aa      = 0;

            if (Session["Answergood"] != null)
            {
                ag = (int)Session["Answergood"];
            }
            if (Session["Answerbad"] != null)
            {
                ab = (int)Session["Answerbad"];
            }
            if (Session["AnswerAll"] != null)
            {
                aa = (int)Session["AnswerAll"];
            }
            var    testId     = Convert.ToInt32(Request["testId"]);
            var    questId    = Convert.ToInt32(Request["questId"]);
            var    Qest_list  = Session["quest_list"] as List <Questionss>; //список вопросов по разделу
            var    Answ_list  = Session["answ_list"] as List <Answerss>;    //список ответов по разделу
            var    answerss   = Session["answerss"];
            string textquesta = "";

            if (questId == 0)
            {
                foreach (var td in Qest_list)
                {
                    if (td.ID != questId)
                    {
                        questId = td.ID;
                    }
                    break;
                }
            }
            foreach (var g in Qest_list)
            {
                if (g.ID == questId)
                {
                    textquesta = g.QuestName;
                }
                else
                {
                    continue;
                }
            }
            /*......................если  обычный вопрос...................................*/
            //if (Session["ss"] == null)
            {
                var chks = new List <Proverka>();
                foreach (var chk in Panel2.Controls)
                {
                    if (chk is CheckBox)
                    {
                        if ((chk as CheckBox).Checked)
                        {
                            Proverka row = new Proverka
                            {
                                pravda = true,
                                textO  = (chk as CheckBox).Text
                            };
                            chks.Add(row);
                            //chks.Add(true);
                            //text_otveta.Add((chk as CheckBox).Text);
                        }
                        else
                        {
                            Proverka row = new Proverka
                            {
                                pravda = false,
                                textO  = (chk as CheckBox).Text
                            };
                            chks.Add(row);
                            //chks.Add(false);
                            //text_otveta.Add((chk as CheckBox).Text);
                        }
                    }
                }
                var t       = 0;
                var counter = 0;
                var flags   = Answ_list.Where(s => s.QuestionId == questId).Select(s => s);

                foreach (var tx in chks)
                {
                    foreach (var tw in flags)
                    {
                        if (tx.textO.Equals(tw.TextOtv) & tx.pravda == tw.AnswerCorrect)
                        {
                        }
                        else if (tx.textO.Equals(tw.TextOtv) & tx.pravda != tw.AnswerCorrect)
                        {
                            counter++;
                        }
                    }
                }
                Session["sch"] = schetchik;


                flagi = new FLAGLARsew {
                    IDvoprosa = questId, flagiotvetov = chks.Select(d => d.pravda).ToList(), textquestion = textquesta
                };
                List <FLAGLARsew> Flag_list;

                if (Session["chks"] == null)
                {
                    Flag_list = new List <FLAGLARsew>();
                }
                else
                {
                    Flag_list = (List <FLAGLARsew>)Session["chks"];
                }
                Flag_list.Add(flagi);
                Session["chks"] = Flag_list;
                var result = false;

                if (counter > 0)
                {
                    ab++;
                    Session["Answerbad"] = ab;//неправильно
                }
                else
                {
                    ag++;
                    Session["Answergood"] = ag;//правильно
                    result = true;
                }

                aa = ag + ab;//кол-во ответов

                Session["AnswerAll"] = aa;
                element = new ResultClassMy {
                    QuestionId = questId, Result = result
                };
                List <ResultClassMy> element_list;
                if (Session["Values"] == null)
                {
                    element_list = new List <ResultClassMy>();
                }
                else
                {
                    element_list = (List <ResultClassMy>)Session["Values"];
                    // (Session["Values"] as List<ResultClassMy>).Add(element);
                }
                element_list.Add(element);
                Session["Values"] = element_list;
            }
            /*.............................не обычный вопрос.........................................*/
            //else
            //{
            //    var poro = new List<int>();
            //    var porydk = obj.ANSWER.Where(hj => hj.idpart == testId && hj.id_questions == questId && hj.order != null && hj.flag == false).Select(hj => hj.order);
            //    var pop = porydk.Count();
            //    var textb = TextBox1.Text;
            //    int p = 0;
            //    string[] split = textb.Split(new Char[] { ' ', ',', '.' });
            //    var cou = split.Count();
            //    /*..........................если кол-во ответов совпадает с эталонным количеством...............................*/
            //    if (cou == pop)
            //    {
            //        int[] io = new int[cou];
            //        foreach (string s in split)
            //        {
            //            if (s.Trim() != "")
            //                io[p] = Convert.ToInt32(s);
            //            poro.Add(io[p]);
            //            p++;
            //        }
            //        int t = 0;
            //        int counter = 0;
            //        foreach (var po in porydk)
            //        {
            //            if (io[t] != po)
            //            {
            //                counter++;
            //            }
            //            t++;
            //        }
            //        flagi = new FLAGLARsew { IDvoprosa = questId, order = poro, textquestion = textquesta };
            //        List<FLAGLARsew> Flag_list;
            //        if (Session["chks"] == null)
            //        {
            //            Flag_list = new List<FLAGLARsew>();
            //        }
            //        else
            //        {
            //            Flag_list = (List<FLAGLARsew>)Session["chks"];
            //        }
            //        Flag_list.Add(flagi);
            //        Session["chks"] = Flag_list;
            //        var result = false;
            //        if (counter > 0)
            //        {
            //            ab++;
            //            Session["Answerbad"] = ab;
            //        }
            //        else
            //        {
            //            ag++;
            //            Session["Answergood"] = ag;
            //            result = true;
            //        }
            //        aa = ag + ab;
            //        Session["AnswerAll"] = aa;
            //        element = new ResultClassMy { QuestionId = questId, Result = result };
            //        List<ResultClassMy> element_list = new List<ResultClassMy>();
            //        element_list.Add(element);
            //        if (Session["Values"] == null)
            //        {
            //            Session["Values"] = element_list;
            //        }
            //        else
            //        {
            //            (Session["Values"] as List<ResultClassMy>).Add(element);
            //        }
            //    }
            //    /*..................если перебор или недобор...........................................*/
            //    else
            //    {
            //        var result = false;
            //        element = new ResultClassMy { QuestionId = questId, Result = result };
            //        List<ResultClassMy> element_list = new List<ResultClassMy>();
            //        element_list.Add(element);
            //        if (Session["Values"] == null)
            //        {
            //            Session["Values"] = element_list;
            //        }
            //        else
            //        {
            //            (Session["Values"] as List<ResultClassMy>).Add(element);
            //        }
            //    }
            //    Session["ss"] = null;
            //}
            int index = (int)Session["Index"];

            Session["Index"] = ++index;
            if (aa == 15)                //переход при ответах
            {
                Response.Redirect("Primer.aspx?testId=" + testId);
            }

            questId = Qest_list.AsEnumerable().ElementAt(index).ID;
            string url = "Answers.aspx?testId=" + testId + "&questId=" + questId;

            Response.Redirect(url);
        }
Exemple #3
0
        /*-------------------------------кнопка: "ответить"------------------------------------------------------*/

        protected void Ans(object sender, EventArgs e)
        {
            FLAGLAR flagi = new FLAGLAR();
            int     ag    = 0;
            int     ab    = 0;
            int     aa    = 0;

            if (Session["Answergood"] != null)
            {
                ag = (int)Session["Answergood"];
            }
            if (Session["Answerbad"] != null)
            {
                ab = (int)Session["Answerbad"];
            }
            if (Session["AnswerAll"] != null)
            {
                aa = (int)Session["AnswerAll"];
            }
            var    testId     = Convert.ToInt32(Request["testId"]);
            var    questId    = Convert.ToInt32(Request["questId"]);
            var    Qest_list  = Session["quest_list"] as List <Questionss>; //список вопросов по разделу
            var    Answ_list  = Session["answ_list"] as List <Answerss>;    //список ответов по разделу
            var    answerss   = Session["answerss"];
            string textquesta = "";

            if (questId == 0)
            {
                foreach (var td in Qest_list)
                {
                    if (td.ID != questId)
                    {
                        questId = td.ID;
                    }
                    break;
                }
            }
            foreach (var g in Qest_list)
            {
                if (g.ID == questId)
                {
                    textquesta = g.QuestName;
                }
                else
                {
                    continue;
                }
            }
            /*...........................если обычный вопрос..................................................... */
            if (Session["ss"] == null)
            {
                var chks = new List <Proverka>();
                //  var text_otveta = new List<string>();
                foreach (var chk in Panel2.Controls)
                {
                    if (chk is CheckBox)
                    {
                        if ((chk as CheckBox).Checked)
                        {
                            Proverka row = new Proverka
                            {
                                pravda = true,
                                textO  = (chk as CheckBox).Text
                            };
                            chks.Add(row);
                            //chks.Add(true);
                            //text_otveta.Add((chk as CheckBox).Text);
                        }
                        else
                        {
                            Proverka row = new Proverka
                            {
                                pravda = false,
                                textO  = (chk as CheckBox).Text
                            };
                            chks.Add(row);
                            //chks.Add(false);
                            //text_otveta.Add((chk as CheckBox).Text);
                        }
                    }
                }
                var t       = 0;
                var counter = 0;
                var flags   = Answ_list.Where(s => s.QuestionId == questId).Select(s => s);
                // var texts = Answ_list.Where(s => s.QuestionId == questId).Select(s => s.TextOtv);

                foreach (var tx in chks)
                {
                    foreach (var tw in flags)
                    {
                        if (tx.textO.Equals(tw.TextOtv) & tx.pravda == tw.AnswerCorrect)
                        {
                        }
                        else if (tx.textO.Equals(tw.TextOtv) & tx.pravda != tw.AnswerCorrect)
                        {
                            counter++;
                        }
                    }
                }

                //foreach (var flag in flags)
                //{
                //    if (flag == true)
                //    {
                //       // (FindControl("chk" + t.ToString()) as CheckBox).BackColor = System.Drawing.Color.AliceBlue;
                //    }
                //    else
                //    {
                //      //  (FindControl("chk" + t.ToString()) as CheckBox).BackColor = System.Drawing.Color.Yellow;
                //    }
                //    if (flag != chks[t])
                //    {
                //        counter++;
                //    }
                //    t++;

                //}
                flagi = new FLAGLAR {
                    IDvoprosa = questId, flagiotvetov = chks.Select(d => d.pravda).ToList(), textquestion = textquesta
                };
                List <FLAGLAR> Flag_list;
                if (Session["chks"] == null)
                {
                    Flag_list = new List <FLAGLAR>();
                }
                else
                {
                    Flag_list = (List <FLAGLAR>)Session["chks"];
                }
                Flag_list.Add(flagi);
                Session["chks"] = Flag_list;

                var result = false;

                if (counter > 0)
                {
                    // Result.ForeColor = System.Drawing.Color.Red;
                    //Result.Text = "Неправильный ответ";
                    ab++;
                    Session["Answerbad"] = ab;
                }
                else
                {
                    ag++;
                    Session["Answergood"] = ag;

                    // Result.ForeColor = System.Drawing.Color.Green;
                    // Result.Text = "Правильный ответ";

                    result = true;
                }

                aa = ag + ab;

                Session["AnswerAll"] = aa;

                var element = new ResultClassMy {
                    QuestionId = questId, Result = result
                };

                List <ResultClassMy> element_list = new List <ResultClassMy>();
                element_list.Add(element);
                if (Session["Values"] == null)
                {
                    Session["Values"] = element_list;
                }
                else
                {
                    (Session["Values"] as List <ResultClassMy>).Add(element);
                }
            }
            /*................................необычный вопрос.....................................................................*/
            //else
            //{

            //    var porydk = obj.Answers.Where(hj => hj.idpart == testId && hj.id_questions == questId && hj.order != null && hj.flag == false).Select(hj => hj.order);
            //    var pop = porydk.Count();
            //    var textb = TextBoxVariant.Text;
            //    int p = 0;
            //    string[] split = textb.Split(new Char[] { ' ', ',', '.', ':' });
            //    var cou = split.Count();
            //    /*..........................если кол-во ответов совпадает с эталонным количеством...............................*/
            //    if (cou == pop)
            //    {
            //        int[] io = new int[cou];
            //        foreach (string s in split)
            //        {
            //            if (s.Trim() != "")
            //                io[p] = Convert.ToInt32(s);
            //            p++;
            //        }

            //        int t = 0;
            //        int counter = 0;

            //        foreach (var po in porydk)
            //        {
            //            if (io[t] != po)
            //            {
            //                counter++;
            //            }
            //            t++;
            //        }
            //        flagi = new FLAGLAR { IDvoprosa = questId, textquestion = textquesta };
            //        List<FLAGLAR> Flag_list;
            //        if (Session["chks"] == null)
            //        {
            //            Flag_list = new List<FLAGLAR>();

            //        }
            //        else
            //        {
            //            Flag_list = (List<FLAGLAR>)Session["chks"];
            //        }
            //        Flag_list.Add(flagi);
            //        Session["chks"] = Flag_list;
            //        var result = false;
            //        if (counter > 0)
            //        {
            //            ab++;
            //            Session["Answerbad"] = ab;
            //        }
            //        else
            //        {
            //            ag++;
            //            Session["Answergood"] = ag;
            //            result = true;
            //        }
            //        aa = ag + ab;
            //        Session["AnswerAll"] = aa;
            //        var element = new ResultClassMy { QuestionId = questId, Result = result };
            //        List<ResultClassMy> element_list = new List<ResultClassMy>();
            //        element_list.Add(element);
            //        if (Session["Values"] == null)
            //        {
            //            Session["Values"] = element_list;
            //        }
            //        else
            //        {
            //            (Session["Values"] as List<ResultClassMy>).Add(element);
            //        }
            //    }
            //    /*..................если перебор или недобор...........................................*/
            //    else
            //    {
            //        var result = false;
            //        var element = new ResultClassMy { QuestionId = questId, Result = result };
            //        List<ResultClassMy> element_list = new List<ResultClassMy>();
            //        element_list.Add(element);
            //        if (Session["Values"] == null)
            //        {
            //            Session["Values"] = element_list;
            //        }
            //        else
            //        {
            //            (Session["Values"] as List<ResultClassMy>).Add(element);
            //        }
            //    }
            //    Session["ss"] = null;
            //}
            int index = (int)Session["Index"];

            Session["Index"] = ++index;
            if (aa == 15)
            {
                Labeltimer.Text = (finishTime - DateTime.Now).ToString(@"mm\:ss");
                if (Session["finishTime"] != null)
                {
                    Session["finishTime"] = null;
                }
                Timer1.Enabled = false;

                //  Response.Redirect("Login.aspx?testId=" + testId);
            }
            try
            {
                questId = Qest_list.AsEnumerable().ElementAt(index).ID;
            }
            catch { }
            string url = "EkzQuest.aspx?testId=" + testId + "&questId=" + questId;

            Response.Redirect(url);
        }