Exemple #1
0
        private void usual_search(TextBox text, ListBox searchlist)
        {
            Stopwatch stopWatch = new Stopwatch();
            TimeSpan  ts;

            stopWatch.Start();
            if (list.Contains(text.Text.ToUpper()))
            {
                stopWatch.Stop();
                ts = stopWatch.Elapsed;

                dataitem t = new dataitem();

                t.word = text.Text;
                t.time = ts.TotalMilliseconds;

                bool flag = false;
                foreach (dataitem i in searchlist.Items)
                {
                    if (i.word.ToUpper() == t.word.ToUpper())
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    searchlist.Items.Add(t);
                }
                else
                {
                    MessageBox.Show("Слово уже найдено!");
                }
                text.Text = "Поиск по файлу";
            }
            else
            {
                MessageBox.Show("Слово не найдено!");
            }
        }
Exemple #2
0
        private void searchlist_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (((ListBox)sender).Items.Count != 0 && ((ListBox)sender).SelectedItem != null)
            {
                selected_item = (dataitem)(((ListBox)sender).SelectedItem);
                if (selected_item.word != "")
                {
                    wordindexs.Clear();
                    count_in_text_word = 0;

                    int index = content.IndexOf(selected_item.word, 0, StringComparison.OrdinalIgnoreCase);
                    do
                    {
                        if (
                            ((content[index + selected_item.word.Length] == ' ') ||
                             (content[index + selected_item.word.Length] == ',') ||
                             (content[index + selected_item.word.Length] == '.') ||
                             (content[index + selected_item.word.Length] == '!') ||
                             (content[index + selected_item.word.Length] == '?') ||
                             (content[index + selected_item.word.Length] == '\'') ||
                             (content[index + selected_item.word.Length] == '\0') ||
                             (content[index + selected_item.word.Length] == '\'') ||
                             (content[index + selected_item.word.Length] == '’') ||
                             (content[index + selected_item.word.Length] == '‘') ||
                             (content[index + selected_item.word.Length] == '\"') ||
                             (content[index + selected_item.word.Length] == ':') ||
                             (content[index + selected_item.word.Length] == '…') ||
                             (content[index + selected_item.word.Length] == '\r') ||
                             (content[index + selected_item.word.Length] == '\n'))
                            &&
                            ((content[index - 1] == ' ') ||
                             (content[index - 1] == ',') ||
                             (content[index - 1] == '.') ||
                             (content[index - 1] == '!') ||
                             (content[index - 1] == '?') ||
                             (content[index - 1] == '\'') ||
                             (content[index - 1] == '\0') ||
                             (content[index - 1] == '\'') ||
                             (content[index - 1] == '’') ||
                             (content[index - 1] == '‘') ||
                             (content[index - 1] == '\"') ||
                             (content[index - 1] == ':') ||
                             (content[index - 1] == '…') ||
                             (content[index - 1] == '\r') ||
                             (content[index - 1] == '\n')))
                        {
                            wordindexs.Add(index);
                        }
                        index = content.IndexOf(selected_item.word, index + selected_item.word.Length, StringComparison.OrdinalIgnoreCase);
                    } while (index > -1);

                    selectwordinform.Content = count_in_text_word + 1;
                    allserchwords.Content    = wordindexs.Count;

                    textfile.Focus();
                    textfile.Select(wordindexs[count_in_text_word], selected_item.word.Length);

                    textfile.SelectionBrush = Brushes.Red;
                }
            }
        }
Exemple #3
0
        private void DistanceLev(distance func, TextBox text, ListBox searchlist, TextBox tlimit)
        {
            string index = "";
            int    min   = text.Text.Length;
            int    limit;

            if (tlimit.Text != "")
            {
                limit = Convert.ToInt32(tlimit.Text);
            }
            else
            {
                limit = min;
            }
            if (r1.IsChecked == true)
            {
                Stopwatch stopWatch = new Stopwatch();
                TimeSpan  ts;
                stopWatch.Start();

                foreach (string s in list)
                {
                    int distance = func(text.Text, s);

                    if ((distance < min) && (distance <= limit))
                    {
                        min   = distance;
                        index = s;
                    }
                }

                stopWatch.Stop();
                ts = stopWatch.Elapsed;

                dataitem t = new dataitem();

                t.word = index;
                t.time = ts.TotalMilliseconds;

                bool flag = false;
                foreach (dataitem i in searchlist.Items)
                {
                    if (i.word.ToUpper() == t.word.ToUpper())
                    {
                        flag = true;
                    }
                }

                if (index == "")
                {
                    MessageBox.Show("Слово не найдено!");
                }
                else if (!flag)
                {
                    searchlist.Items.Add(t);
                }
                else
                {
                    MessageBox.Show("Слово уже найдено!");
                }
                text.Text = "Поиск по файлу";
            }
            else
            {
                searchlist.Items.Clear();
                Stopwatch stopWatch = new Stopwatch();
                TimeSpan  ts;
                stopWatch.Start();

                foreach (string s in list)
                {
                    int distance = func(text.Text, s);

                    if (distance <= limit)
                    {
                        dataradiobtn i = new dataradiobtn();
                        i.word = s;
                        i.dist = distance;
                        searchlist.Items.Add(i);
                    }
                }

                stopWatch.Stop();
                ts = stopWatch.Elapsed;

                if (tlimit.Name == "DLevLimit")
                {
                    timeserachdlev = ts.TotalMilliseconds;
                }
                else
                {
                    timeserachlev = ts.TotalMilliseconds;
                }

                timelev.Content = ts.TotalMilliseconds + " мс";
            }
        }