Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {
- if (textBox4->Text == "" || textBox5->Text == "") {
- textBox4->BackColor = BackColor.Red;
- textBox5->BackColor = BackColor.Red;
- MessageBox::Show("Заполните поля");
- }
- else {
- textBox4->BackColor = BackColor.White;
- textBox5->BackColor = BackColor.White;
- dataGridView1->Rows->Clear();
- String^ path; // создаем переменную, в которую будем заносить путь программы
- path = Directory::GetCurrentDirectory(); // Заносим в перемнную путь данной программы
- path += "Dictionary.txt"; // Дописываем в переменную путь текстового файла (он лежит в след папке files)
- BinaryReader ^ bR = gcnew BinaryReader(File::Open(path, FileMode::Open)); // Инициализируем переменную потока бинарного ввода в файл
- try { // Для обработки исключений, если что-то пойдет не так
- int i = 0;
- arDictionary->Clear();
- while (bR->PeekChar() != -1) {
- Word^ word = gcnew Word;
- word->eng = bR->ReadString();
- word->rus = bR->ReadString();
- arDictionary->Add(word);
- i++;
- }
- }
- catch (IOException ^ ex) { // Если сработало исключение
- MessageBox::Show(ex->Message); // Выводим сообщение об ошибке
- }
- finally{
- if (bR != nullptr) // Если поток вывода неравен пустоте не существует
- bR->Close(); // Закрываем файл
- }
- bR->Close();
- for (int i = 0; i < arDictionary->Count; i++)
- if (arDictionary[i]->eng == textBox4->Text)
- arDictionary[i]->rus = textBox5->Text;
- // Запись в бинрный файл
- BinaryWriter ^ bW = gcnew BinaryWriter(File::Open(path, FileMode::Create)); // Инициализируем переменную потока бинарного ввода в файл
- try { // Для обработки исключений, если что-то пойдет не так
- for (int i = 0; i < arDictionary->Count; i++) {
- bW->Write(arDictionary[i]->eng);
- bW->Write(arDictionary[i]->rus);
- }
- }
- catch (IOException ^ ex) { // Если сработало исключение
- MessageBox::Show(ex->Message); // Выводим сообщение об ошибке
- }
- finally{
- if (bW != nullptr) // Если поток вывода неравен пустоте не существует
- bW->Close(); // Закрываем файл
- }
- bW->Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement