public static void EditClick(PronVM voc, PronWpfItem wpf_item, StackPanel item_line)
        {
            var edited = new PronVM(voc.Id,
                                    wpf_item.Words.Text,
                                    wpf_item.Phonemes.Text,
                                    (Importance)(wpf_item.Imp).SelectedValue,
                                    wpf_item.IsActive.IsActived);

            EditQuestion(voc, edited, item_line);
        }
Exemple #2
0
        protected static bool RemovePronunciation(PronVM Pron)
        {
            string query = string.Format(RemoveSQL, Model.Pron.ToDesc(), Pron.Id);

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

            Pronunciations.Remove(Pron);

            return(true);
        }
        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);
            }
        }
        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);
        }