Exemplo n.º 1
0
        public new void Filter(IQuestWpfHeader header)
        {
            var wpf_header = header as PronWpfHeader;

            base.Filter(wpf_header);

            var filtered_Prons = Filtered_quests.Cast <PronVM>();

            if (!wpf_header.Txt_words.IsEmpty())
            {
                if (wpf_header.Txt_words.Text.IsDigitsOnly() && filtered_Prons.Any(x => x.Id == Convert.ToInt16(wpf_header.Txt_words.Text)))
                {
                    filtered_Prons = filtered_Prons.Where(q => q.Id == Convert.ToInt16(wpf_header.Txt_words.Text));
                }
                else
                {
                    filtered_Prons = filtered_Prons.Where(q => q.Text.Contains(wpf_header.Txt_words.Text));
                }
            }

            if (!wpf_header.Txt_phonemes.IsEmpty())
            {
                filtered_Prons = filtered_Prons.Where(q => q.Phonemes.Contains(wpf_header.Txt_phonemes.Text));
            }

            Filtered_quests = filtered_Prons;

            BuildStack(wpf_header.Stk_items);
        }
Exemplo n.º 2
0
        protected void Filter(IQuestWpfHeader wpf_header)
        {
            Filtered_quests = Original_quests;

            if (wpf_header.Cob_imp.SelectedIndex != Convert.ToInt16(Importance.Any))
            {
                Filtered_quests = Filtered_quests.Where(q => q.Importance == (Importance)wpf_header.Cob_imp.SelectedIndex).ToList();
            }

            if (!wpf_header.Txt_avg_w.Text.IsEmpty())
            {
                if (!Errors.IsDigitsOnly(wpf_header.Txt_avg_w.Text))
                {
                    return;
                }

                Filtered_quests = Filtered_quests.Where(q => q.Avg_week >= Convert.ToInt16(wpf_header.Txt_avg_w.Text)).ToList();
            }
            if (!wpf_header.Txt_avg_m.Text.IsEmpty())
            {
                if (!Errors.IsDigitsOnly(wpf_header.Txt_avg_m.Text))
                {
                    return;
                }

                Filtered_quests = Filtered_quests.Where(q => q.Avg_month >= Convert.ToInt16(wpf_header.Txt_avg_m.Text)).ToList();
            }
            if (!wpf_header.Txt_avg_all.Text.IsEmpty())
            {
                if (!Errors.IsDigitsOnly(wpf_header.Txt_avg_all.Text))
                {
                    return;
                }

                Filtered_quests = Filtered_quests.Where(q => q.Avg_all >= Convert.ToInt16(wpf_header.Txt_avg_all.Text)).ToList();
            }
            if (!wpf_header.Txt_tries.Text.IsEmpty())
            {
                if (!Errors.IsDigitsOnly(wpf_header.Txt_tries.Text))
                {
                    return;
                }

                Filtered_quests = Filtered_quests.Where(q => q.Tries.Count >= Convert.ToInt16(wpf_header.Txt_tries.Text)).ToList();
            }
            if (!wpf_header.Txt_chance.Text.IsEmpty())
            {
                if (!Errors.IsDigitsOnly(wpf_header.Txt_chance.Text))
                {
                    return;
                }

                Filtered_quests = Filtered_quests.Where(q => q.Chance >= Convert.ToInt16(wpf_header.Txt_chance.Text)).ToList();
            }

            Filtered_quests = Filtered_quests.Where(q => q.IsActive == wpf_header.Btn_isActive.IsActived).ToList();

            (wpf_header.Stk_items.Parent as ScrollViewer).ScrollToTop();
        }
Exemplo n.º 3
0
        private static void SuccessfulInserted(IQuestWpfHeader header, List <bool> successful)
        {
            var type = header is VocWpfHeader ? Model.Voc :
                       header is PronWpfHeader ? Model.Pron :
                       header is SpellWpfHeader ? Model.Spell : 0;

            var added = QuestControl.Get(type).Last();

            added.LoadCrossData();
            QuestWpfUtil.AddWpfItem(header.Stk_items, added);
            successful.Add(true);
        }
Exemplo n.º 4
0
        public static Button Bulk_back(Grid parent, IQuestWpfHeader header)
        {
            var btn = new Button();

            btn.Content           = "Back";
            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Margin            = new Thickness(1, 0, 1, 0);
            btn.Height            = 28;
            btn.Click            += (source, e) =>
            {
                header.Grid_bulk_insert.Visibility = Visibility.Collapsed;
                header.Stk_insert.Visibility       = Visibility.Visible;
            };
            UtilWPF.SetGridPosition(btn, 2, 1, parent);

            return(btn);
        }
Exemplo n.º 5
0
        public static Button Show_bulk_insert(int row, int Column, Grid parent, IQuestWpfHeader header)
        {
            var btn = new Button();

            btn.Content           = UtilWPF.GetIconButton("bulk_insert_2");
            btn.VerticalAlignment = VerticalAlignment.Center;
            //btn.Margin = new Thickness(1, 0, 1, 0);
            btn.Width       = 32;
            btn.Height      = 32;
            btn.Background  = Brushes.Transparent;
            btn.BorderBrush = Brushes.Transparent;
            btn.Click      += (source, e) =>
            {
                header.Grid_bulk_insert.Visibility = Visibility.Visible;
                header.Stk_insert.Visibility       = Visibility.Collapsed;
            };
            UtilWPF.SetGridPosition(btn, row, Column, parent);

            return(btn);
        }
        public new void Filter(IQuestWpfHeader header)
        {
            var wpf_header = header as VocWpfHeader;

            base.Filter(wpf_header);

            var filtered_Vocs = Filtered_quests.Cast <VocVM>();

            if (!wpf_header.Txt_words.IsEmpty())
            {
                if (wpf_header.Txt_words.Text.IsDigitsOnly() && filtered_Vocs.Any(x => x.Id == Convert.ToInt16(wpf_header.Txt_words.Text)))
                {
                    filtered_Vocs = filtered_Vocs.Where(q => q.Id == Convert.ToInt16(wpf_header.Txt_words.Text));
                }
                else
                {
                    filtered_Vocs = filtered_Vocs.Where(q => q.Text.Contains(wpf_header.Txt_words.Text));
                }
            }

            if (!wpf_header.Txt_answer.IsEmpty())
            {
                filtered_Vocs = filtered_Vocs.Where(q => q.Answer.Contains(wpf_header.Txt_answer.Text));
            }

            if (!wpf_header.Txt_def.Text.IsEmpty())
            {
                filtered_Vocs = filtered_Vocs.Where(q => q.Definition.Contains(wpf_header.Txt_def.Text)).ToList();
            }

            if (!wpf_header.Txt_ptbr.Text.IsEmpty())
            {
                filtered_Vocs = filtered_Vocs.Where(q => q.PtBr.Contains(wpf_header.Txt_ptbr.Text)).ToList();
            }

            Filtered_quests = filtered_Vocs;

            BuildStack(wpf_header.Stk_items);
        }
Exemplo n.º 7
0
        public static void InsertClick(StackPanel stk_items, IQuestWpfHeader wpf_header)
        {
            if (wpf_header.Cob_imp.SelectedIndex == Convert.ToInt16(Importance.Any))
            {
                Errors.ThrowErrorMsg(ErrorType.InvalidImportanceAny, wpf_header.Cob_imp.SelectedIndex);
                return;
            }

            if (wpf_header is VocWpfHeader voc)
            {
                InsertClick(stk_items, voc);
            }
            else if (wpf_header is PronWpfHeader pron)
            {
                InsertClick(stk_items, pron);
            }
            else if (wpf_header is SpellWpfHeader spell)
            {
                InsertClick(stk_items, spell);
            }

            Footer.Log("The question has been inserted.");
        }
Exemplo n.º 8
0
 private static void FailedInsert(IQuestWpfHeader header, List <bool> successful, string line)
 {
     header.Txt_bulk_insert.Text += "\nInsert failed (DB validation): " + line;
     successful.Add(false);
 }
Exemplo n.º 9
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);
        }