예제 #1
0
        public async void Searching(SearchData data)
        {
            await helper.UnHideAllRowsAsyncUnsafe(DataBooks);

            int countOfRes = await helper.StartSearchAnsyc(data, DataBooks);

            MessageBox.Show("Совпадений найдено: " + countOfRes.ToString());
            sf.Close();
        }
예제 #2
0
        private void ThreadSearch(Object data)
        {
            SearchData inf            = data as SearchData;
            string     str            = inf.str;
            int        countOfResults = 0;

            if (inf.RegistrON)
            {
                if (inf.UseWordWhole)
                {
                    string[] str_words = str.Split(' ');
                    string[] buf_words;
                    if (inf.numberOfColumn == 5)
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                buf_words = DataBooks.Rows[i].Cells[j].Value.ToString().Split(' ');
                                if (buf_words.Length == str_words.Length)
                                {
                                    for (int indx = 0; indx < str_words.Length; indx++)
                                    {
                                        if (str_words[indx] != buf_words[indx])
                                        {
                                            Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                            goto lalala;
                                        }
                                    }
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    countOfResults++;
                                    j = 3;
                                    continue;
                                }
                                if (buf_words.Length < str_words.Length)
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                    continue;
                                }
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                for (int indx = 0; indx < buf_words.Length - str_words.Length + 1; indx++)
                                {
                                    if (buf_words[indx] == str_words[0])
                                    {
                                        for (int I = 0; I < str_words.Length; I++)
                                        {
                                            if (str_words[I] != buf_words[indx + I])
                                            {
                                                goto сontinue;
                                            }
                                        }
                                        Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                        countOfResults++;
                                        j = 3;
                                        break;
                                        сontinue :;
                                    }
                                }
                                lalala :;
                            }
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                    else
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            buf_words = DataBooks.Rows[i].Cells[inf.numberOfColumn].Value.ToString().Split(' ');
                            if (buf_words.Length == str_words.Length)
                            {
                                for (int indx = 0; indx < str_words.Length; indx++)
                                {
                                    if (str_words[indx] != buf_words[indx])
                                    {
                                        Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                        goto lalala;
                                    }
                                }
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                countOfResults++;
                                continue;
                            }
                            if (buf_words.Length < str_words.Length)
                            {
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                continue;
                            }
                            Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                            for (int indx = 0; indx < buf_words.Length - str_words.Length + 1; indx++)
                            {
                                if (buf_words[indx] == str_words[0])
                                {
                                    for (int I = 0; I < str_words.Length; I++)
                                    {
                                        if (str_words[I] != buf_words[indx + I])
                                        {
                                            goto сontinue;
                                        }
                                    }
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    countOfResults++;
                                    break;
                                    сontinue :;
                                }
                            }
                            lalala :;
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                }
                else
                {
                    string bufferWord = null;
                    if (inf.numberOfColumn == 5)
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                bufferWord = DataBooks.Rows[i].Cells[j].Value.ToString();
                                if (bufferWord.Length < str.Length)
                                {
                                    continue;
                                }
                                if (bufferWord.Contains(str))
                                {
                                    countOfResults++;
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    break;
                                }
                                else
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                }
                            }
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                    else
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            bufferWord = DataBooks.Rows[i].Cells[inf.numberOfColumn].Value.ToString();
                            if (bufferWord.Length < str.Length)
                            {
                                continue;
                            }
                            if (bufferWord.Contains(str))
                            {
                                countOfResults++;
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                continue;
                            }
                            else
                            {
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                            }
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                }
            }
            else
            {
                string bufferWord = null;
                str = str.ToLower(); // и так со всеми строками
                if (inf.UseWordWhole)
                {
                    string[] str_words = str.Split(' ');
                    string[] buf_words;
                    if (inf.numberOfColumn == 5)
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                buf_words = DataBooks.Rows[i].Cells[j].Value.ToString().ToLower().Split(' ');
                                if (buf_words.Length == str_words.Length)
                                {
                                    for (int indx = 0; indx < str_words.Length; indx++)
                                    {
                                        if (str_words[indx] != buf_words[indx])
                                        {
                                            Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                            goto lalala;
                                        }
                                    }
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    countOfResults++;
                                    j = 3;
                                    continue;
                                }
                                if (buf_words.Length < str_words.Length)
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                    continue;
                                }
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                for (int indx = 0; indx < buf_words.Length - str_words.Length + 1; indx++)
                                {
                                    if (buf_words[indx] == str_words[0])
                                    {
                                        for (int I = 0; I < str_words.Length; I++)
                                        {
                                            if (str_words[I] != buf_words[indx + I])
                                            {
                                                goto сontinue;
                                            }
                                        }
                                        Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                        countOfResults++;
                                        j = 3;
                                        break;
                                        сontinue :;
                                    }
                                }
                                lalala :;
                            }
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                    else
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            buf_words = DataBooks.Rows[i].Cells[inf.numberOfColumn].Value.ToString().Split(' ');
                            if (buf_words.Length == str_words.Length)
                            {
                                for (int indx = 0; indx < str_words.Length; indx++)
                                {
                                    if (str_words[indx] != buf_words[indx].ToLower())
                                    {
                                        Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                        goto lalala;
                                    }
                                }
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                countOfResults++;
                                continue;
                            }
                            if (buf_words.Length < str_words.Length)
                            {
                                Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                continue;
                            }
                            Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                            for (int indx = 0; indx < buf_words.Length - str_words.Length + 1; indx++)
                            {
                                if (buf_words[indx].ToLower() == str_words[0])
                                {
                                    for (int I = 0; I < str_words.Length; I++)
                                    {
                                        if (str_words[I] != buf_words[indx + I].ToLower())
                                        {
                                            goto сontinue;
                                        }
                                    }
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    countOfResults++;
                                    break;
                                    сontinue :;
                                }
                            }
                            lalala :;
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                }
                else
                {
                    if (inf.numberOfColumn == 5)
                    {
                        for (int i = inf.first_index; i < inf.second_index; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                bufferWord = DataBooks.Rows[i].Cells[j].Value.ToString().ToLower();
                                if (bufferWord.Length < str.Length)
                                {
                                    continue;
                                }
                                if (bufferWord.Contains(str))
                                {
                                    countOfResults++;
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    break;
                                }
                                else
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                }
                            }
                        }
                        if (!inf.UseMultiThreading)
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                            Invoke((Action) delegate { sf.Close(); }); //////////////////////
                        }
                        else
                        {
                            Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                            if (Thread.CurrentThread.Name == "LAST")
                            {
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                        }
                    }
                    else
                    {
                        if (inf.numberOfColumn != 2)
                        {
                            for (int i = inf.first_index; i < inf.second_index; i++)
                            {
                                bufferWord = DataBooks.Rows[i].Cells[inf.numberOfColumn].Value.ToString().ToLower();
                                if (bufferWord.Length < str.Length)
                                {
                                    continue;
                                }
                                if (bufferWord.Contains(str))
                                {
                                    countOfResults++;
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    continue;
                                }
                                else
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                }
                            }
                            if (!inf.UseMultiThreading)
                            {
                                Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                            else
                            {
                                Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                                if (Thread.CurrentThread.Name == "LAST")
                                {
                                    Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                    Invoke((Action) delegate { sf.Close(); }); //////////////////////
                                }
                            }
                        }
                        else
                        {
                            for (int i = inf.first_index; i < inf.second_index; i++)
                            {
                                bufferWord = DataBooks.Rows[i].Cells[inf.numberOfColumn].Value.ToString().ToLower();
                                if (bufferWord == str)
                                {
                                    countOfResults++;
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = true; });
                                    continue;
                                }
                                else
                                {
                                    Invoke((Action) delegate { DataBooks.Rows[i].Visible = false; });
                                }
                            }
                            if (!inf.UseMultiThreading)
                            {
                                Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                                Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                Invoke((Action) delegate { sf.Close(); }); //////////////////////
                            }
                            else
                            {
                                Invoke((Action) delegate { countOfTrueRows += countOfResults; });
                                if (Thread.CurrentThread.Name == "LAST")
                                {
                                    Invoke((Action) delegate { MessageBox.Show("Совпадений: " + countOfTrueRows.ToString(), "Поиск завершен"); });
                                    Invoke((Action) delegate { sf.Close(); }); //////////////////////
                                }
                            }
                        }
                    }
                }
            }
        }