public static void Verify(ChalLine line, Button btn_verify, Button btn_next)
        {
            line.Chal.Cb_Answer.IsEnabled = false;

            int  score     = 0;
            bool isCorrect = false;

            if (line.Quest.Type == Model.Voc)
            {
                isCorrect = line.Chal.Cb_Answer.IsCorrect();
            }
            else if (line.Quest.Type == Model.Spell)
            {
                isCorrect = line.Chal.Txt_Spell.Text.ContainsInsensitive(line.Quest.Text);
            }

            if (isCorrect)
            {
                line.Chal.Grid_chal.Background = UtilWPF.Colour_Correct;
                score = 10;
            }
            else
            {
                line.Chal.Grid_chal.Background = UtilWPF.Colour_Incorrect;
            }

            var att = new AttemptVM(line.Quest.Id, score, DateTime.Now, line.Quest.Type);

            AttemptsControl.Insert(att);

            var updated_quest = QuestControl.Get(line.Quest.Type).First(x => x.Id == line.Quest.Id);

            line.Chal.Avg_w.Content   = updated_quest.Avg_week + "% (w)";
            line.Chal.Avg_m.Content   = updated_quest.Avg_month + "% (m)";
            line.Chal.Avg_all.Content = updated_quest.Avg_all + "% (all)";
            line.Chal.Tries.Content   = updated_quest.Tries.Count + " tries";

            foreach (var lbl in line.Chal.Quest_words)
            {
                if (line.Quest.Text.SplitSentence().Contains(lbl.Content.ToString()))
                {
                    lbl.FontWeight = FontWeights.Bold;
                }
            }

            TurnElemsVisible(line);
            btn_next.IsEnabled   = true;
            btn_verify.IsEnabled = false;
        }
Esempio n. 2
0
        public static (string, int) CheckAnswers(List <CellTemplate> cellList)
        {
            var total    = 0;
            var corrects = 0;

            foreach (var item in cellList)
            {
                if (item.Txt != null)
                {
                    item.Txt.IsReadOnly = true;
                    var answer = string.Empty;

                    if (!item.Txt.IsEmpty())
                    {
                        answer = item.Txt.Text;
                    }

                    var isCorrect = answer.Equals(item.Quest.Text, StringComparison.OrdinalIgnoreCase);
                    var score     = 0;

                    if (isCorrect)
                    {
                        score = 10;
                        item.Txt.Background = Brushes.LightGreen;
                        corrects            = corrects + 1;
                    }
                    else
                    {
                        item.Txt.Background = Brushes.LightSalmon;
                        item.Txt.ToolTip    = item.Quest.Text;
                    }

                    var vm = new AttemptVM(item.Quest.Id, score, DateTime.Now, item.Quest.Type);
                    AttemptsControl.Insert(vm);
                    total = total + 1;
                }
            }

            var percent_corrects = 0;

            if (corrects != 0)
            {
                percent_corrects = (int)Math.Round((double)(100 * corrects) / total);
            }

            return(percent_corrects + "% (" + corrects + " corrects)", percent_corrects);
        }
Esempio n. 3
0
        protected static bool RemoveQuestionAttempt(AttemptVM att)
        {
            string query = string.Format(RemoveSQL, GetDBAttemptName(att.Type), att.Id);

            if (!SendQuery(query))
            {
                return(false);
            }

            if (att.Type == Model.Voc)
            {
                VocabularyAttempts.Remove(att);
            }
            else if (att.Type == Model.Spell)
            {
                SpellingAttempts.Remove(att);
            }

            return(true);
        }
Esempio n. 4
0
        protected static bool InsertAttempt(AttemptVM att)
        {
            string query = string.Format(InsertSQL + "'{1}', '{2}', '{3}')",
                                         GetDBAttemptName(att.Type),
                                         att.IdQuestion, att.Score, att.When);

            if (!SendQuery(query))
            {
                return(false);
            }

            var inserted = GetLast(GetDBAttemptName(att.Type));

            if (att.Type == Model.Voc)
            {
                if (VocabularyAttempts == null)
                {
                    VocabularyAttempts = new List <AttemptVM>();
                }

                VocabularyAttempts.Add(inserted.Tables[0].AsEnumerable().
                                       Select(GetDatarowAttempts(att.Type)).First());
            }
            else if (att.Type == Model.Essay)
            {
                if (EssayAttempts == null)
                {
                    EssayAttempts = new List <AttemptVM>();
                }

                EssayAttempts.Add(inserted.Tables[0].AsEnumerable().
                                  Select(GetDatarowAttempts(att.Type)).First());
            }
            else if (att.Type == Model.SumRetell)
            {
                if (SumRetellAttempts == null)
                {
                    SumRetellAttempts = new List <AttemptVM>();
                }

                SumRetellAttempts.Add(inserted.Tables[0].AsEnumerable().
                                      Select(GetDatarowAttempts(att.Type)).First());
            }
            else if (att.Type == Model.DescImg)
            {
                if (DescImgAttempts == null)
                {
                    DescImgAttempts = new List <AttemptVM>();
                }

                DescImgAttempts.Add(inserted.Tables[0].AsEnumerable().
                                    Select(GetDatarowAttempts(att.Type)).First());
            }
            if (att.Type == Model.Spell)
            {
                if (SpellingAttempts == null)
                {
                    SpellingAttempts = new List <AttemptVM>();
                }

                SpellingAttempts.Add(inserted.Tables[0].AsEnumerable().
                                     Select(GetDatarowAttempts(att.Type)).First());
            }

            return(true);
        }