private void button1_Click(object sender, EventArgs e) { if (index == -1) { timer1.Start(); label2.Text = "Выберите команду"; return; } if (listBox1.Items.Count == 1) { timer1.Start(); label2.Text = "Нельзя удалить все команды!"; return; } File.WriteAllLines(path_close, deletecommand(path_close, listBox1.SelectedItem.ToString()), Encoding.Default); File.WriteAllLines(path_open, deletecommand(path_open, listBox1.SelectedItem.ToString()), Encoding.Default); listBox1.Items.Remove(listBox1.Items[index]); Form1 form1 = new Form1(); form1.determinant1.LoadGrammar(form1.Grammar()); form1.determinant1.LoadGrammar(form1.Grammar1()); }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "" && textBox2.Text == "") { label3.Text = "Введите ключевую фразу и имя процесса."; } else if (textBox1.Text.Length < 4) { label3.Text = "Ключевая фраза слишком короткая."; } else if (textBox2.Text.Length < 4) { label3.Text = "Фраза слишком короткая."; } else if (textBox2.Text == "") { label3.Text = "Введите имя процесса."; } else if (textBox1.Text == "") { label3.Text = "Введите ключевую фразу."; } else if (!Exist(textBox1.Text)) { label3.Text = "Такая фраза уже существует."; } else if (textBox2.Text.IndexOf(@"http://") != 0 && textBox2.Text.IndexOf(@"https://") != 0 && textBox2.Text.IndexOf(@"www.") != 0 && url) { label3.Text = "Некорректная ссылка."; } else if (textBox2.Text.IndexOf(@".") == -1 && url) { label3.Text = "Некорректная ссылка."; } else { StreamWriter sw = new StreamWriter(@"C:\VoiceAssistant\commandsclose.txt", true, Encoding.Default); StreamWriter sw1 = new StreamWriter(@"C:\VoiceAssistant\commandsopen.txt", true, Encoding.Default); if (process_path == null) { process_path = textBox2.Text; } sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw1.WriteLine(textBox1.Text); sw1.WriteLine(process_path); sw.Close(); sw1.Close(); url = true; timer1.Stop(); timer1.Start(); textBox1.Text = ""; textBox2.Text = ""; label4.Text = "Команда успешно добавлена"; label3.Text = ""; Form1 form1 = new Form1(); form1.determinant1.LoadGrammar(form1.Grammar()); form1.determinant1.LoadGrammar(form1.Grammar1()); } }