Example #1
0
        private void sendMessage()
        {
            ChatBot bot = new ChatBot();

            try
            {
                int    c    = 0;
                string data = chat_msg.Text;
                if (string.IsNullOrEmpty(data))
                {
                    return;
                }
                if (data.Contains("Крио") || data.Contains("крио"))//вопрос точно должен содержать один знак или цифру(главное чтобы все не были буквамии пробелами!!!!)
                {
                    char[] ch = data.ToCharArray();
                    for (int i = 0; i < ch.Length; i++)
                    {
                        if ((Char.IsLetter(ch[i]) && ch[i] >= 'А' && ch[i] <= 'я') || (Char.IsLetter(ch[i]) && ((ch[i] == 'Ё') || (ch[i] == 'ё'))) || ch[i] == ' ')
                        {
                            c++;
                        }
                    }
                    if (c == ch.Length - 1)
                    {
                        if (bot.Que(data, @"C:\Users\Люба\Desktop\chatClient\question_answer.txt") == 1)
                        {
                            flag = true;//запись ответа сразу без проверок
                            send("#newmsg&" + data + "введите ответ: ");
                        }
                        else
                        {
                            flag = false;
                            send("#newmsg&" + data);
                        }
                    }
                    if (c != ch.Length - 1 && flag == true) //ответа в базе нет
                    {
                        send("#newmsg&" + "ответ бота " + bot.Ans(data, @"C:\Users\Люба\Desktop\chatClient\question_answer.txt"));
                    }
                    if (c != ch.Length - 1 && flag == false) //ответ есть
                    {
                        send("#newmsg&" + "ответ бота " + bot.Anss(data, @"C:\Users\Люба\Desktop\chatClient\question_answer.txt"));
                    }
                }
                else
                {
                    send("#newmsg&" + data);//отправка сообщения на сервер
                }
                chat_msg.Text = string.Empty;
            }
            catch { MessageBox.Show("Ошибка при отправке сообщения!"); }
        }