Ejemplo n.º 1
0
        private static void InsertClick(StackPanel stk_items, SpellWpfHeader wpf_header)
        {
            var spell = new SpellVM(wpf_header.Txt_words.Text,
                                    (Importance)wpf_header.Cob_imp.SelectedIndex,
                                    wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(spell))
            {
                wpf_header.Txt_words.Text = string.Empty;
                InsertQuestion(stk_items, Model.Spell);
            }
        }
Ejemplo n.º 2
0
        private static void InsertClick(StackPanel stk_items, PronWpfHeader wpf_header)
        {
            var pron = new PronVM(wpf_header.Txt_words.Text,
                                  wpf_header.Txt_phonemes.Text,
                                  (Importance)wpf_header.Cob_imp.SelectedIndex,
                                  wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(pron))
            {
                wpf_header.Txt_words.Text    = string.Empty;
                wpf_header.Txt_phonemes.Text = string.Empty;

                InsertQuestion(stk_items, Model.Pron);
            }
        }
Ejemplo n.º 3
0
        private static void InsertClick(StackPanel stk_items, VocWpfHeader wpf_header)
        {
            var Voc = new VocVM(wpf_header.Txt_words.Text,
                                wpf_header.Txt_answer.Text,
                                wpf_header.Txt_def.Text,
                                wpf_header.Txt_ptbr.Text,
                                (Importance)wpf_header.Cob_imp.SelectedIndex,
                                wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(Voc))
            {
                wpf_header.Txt_words.Text  = string.Empty;
                wpf_header.Txt_answer.Text = string.Empty;
                wpf_header.Txt_def.Text    = string.Empty;
                wpf_header.Txt_ptbr.Text   = string.Empty;

                InsertQuestion(stk_items, Model.Voc);
            }
        }
Ejemplo n.º 4
0
        public static Button Insert_Bulk(Grid parent, IQuestWpfHeader header)
        {
            var btn = new Button();

            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Margin            = new Thickness(1, 0, 1, 0);
            Get(btn, 1, 1, parent, "Insert");

            btn.Click += (source, e) =>
            {
                var watcher = new Stopwatch();
                watcher.Start();

                var lines = header.Txt_bulk_insert.Text.Replace("\r", "").Split('\n');

                header.Txt_bulk_insert.Text = "// format:  words;answer";

                var successful = new List <bool>();

                var inserts = new List <string>();
                var imp     = (Importance)header.Cob_bulk_imp.SelectedIndex;

                foreach (var line in lines)
                {
                    if (line.StartsWith("//") || line.StartsWith("Insert failed") || line.IsEmpty())
                    {
                        continue;
                    }

                    //if (line.Count(x => x == '1') != 1)
                    //{
                    //    successful.Add(false);
                    //    header.Txt_bulk_insert.Text += "\nInsert failed (must has 1 ';'): " + line;
                    //    continue;
                    //}

                    var parts = line.Split(';');

                    if (parts.Count() != 2 && !(header is SpellWpfController))
                    {
                        successful.Add(false);
                        header.Txt_bulk_insert.Text += "\nInsert failed (must has 2 parts): " + line;
                        continue;
                    }

                    var part1 = parts[0];
                    var part2 = parts[1];

                    if (header is VocWpfController)
                    {
                        if (!part1.IsLettersOnly() || !part2.IsLettersOnly())
                        {
                            successful.Add(false);
                            header.Txt_bulk_insert.Text += "\nInsert failed (parts must have only letters): " + line;
                            continue;
                        }
                    }

                    var vm = new QuestVM();

                    if (header is VocWpfHeader)
                    {
                        vm = new VocVM(part1, part2, "", "", imp, true);
                    }
                    if (header is PronWpfHeader)
                    {
                        vm = new PronVM(part1, part2, imp, true);
                    }
                    if (header is SpellWpfHeader)
                    {
                        vm = new SpellVM(part1, imp, true);
                    }

                    if (QuestControl.Insert(vm))
                    {
                        SuccessfulInserted(header, successful);
                    }
                    else
                    {
                        FailedInsert(header, successful, line);
                    }
                }
                Footer.Log("Of a total of " + successful.Count + " attempts, " +
                           successful.Where(x => x).Count() + " were inserted, while " +
                           successful.Where(x => !x).Count() + " failed. Time spent: " +
                           Math.Round(watcher.Elapsed.TotalSeconds, 2) + " seconds.");
            };

            return(btn);
        }