Esempio n. 1
0
 public DictionaryChanges Add_AddWordsOrTextForms(AddWordsOrTextForms form)
 {
     if (form != null)
     {
         form.AddWordOrTextEvent += WordOrTextAddedEvent;
     }
     return(this);
 }
Esempio n. 2
0
    private void Form1_Load(object sender, EventArgs e)
    {
        DictionaryChangesObserver = new DictionaryChanges();
        training_form             = new TrainingForm(this, TrainingButton, AddIncomprehensible);
        add_word_form             = new AddWordsOrTextForms(this, AddWordsButton, CreateData, AddWordsOrTextForms.AddWordsOrTextFormsType.AddWordForm);
        add_text_form             = new AddWordsOrTextForms(this, AddTextsButton, CreateData, AddWordsOrTextForms.AddWordsOrTextFormsType.AddTextForm);
        dictionary_edit_form      = new DictionaryEditForm(this, DictionaryEditButton);

        DictionaryChangesObserver.Add_AddWordsOrTextForms(add_word_form as AddWordsOrTextForms)
        .Add_AddWordsOrTextForms(add_text_form as AddWordsOrTextForms)
        .Add_DictionaryEditForm(dictionary_edit_form as DictionaryEditForm);

        training_form.BackToMainFormEvent        += SetVisibleMainFormElements;
        add_word_form.BackToMainFormEvent        += SetVisibleMainFormElements;
        add_text_form.BackToMainFormEvent        += SetVisibleMainFormElements;
        dictionary_edit_form.BackToMainFormEvent += SetVisibleMainFormElements;

        try
        {
            data_file = new FileStream("words.data", FileMode.Open);
            if (data_file.Length == 0)
            {
                throw new FileLoadException();
            }
        }
        catch (FileNotFoundException)
        {
            DictionaryEditButton.Enabled = false;
            TrainingButton.Enabled       = false;
            MessageBox.Show("Файл со словарем не найден", "Ошибка");
            return;
        }
        catch (FileLoadException)
        {
            DictionaryEditButton.Enabled = false;
            TrainingButton.Enabled       = false;
            MessageBox.Show("Файл со словарем не содержит данных", "Ошибка");
            return;
        }

        Container data = Serialize.DesirializeFromFile(data_file);

        if (data == null)
        {
            DictionaryEditButton.Enabled = false;
            TrainingButton.Enabled       = false;
            data_file.Close();
            return;
        }
        Data             = new WordsAndTextsData(data.Words, data.Texts);
        Incomprehensible = data.Incomprehensible;
    }