Exemple #1
0
        private bool SaveFile(bool saveAsNewFile)
        {
            //Datei-Speichern-unter Dialogfeld öffnen
            if (string.IsNullOrWhiteSpace(CurrentBook.FilePath) ||
                string.IsNullOrWhiteSpace(CurrentBook.VhrCode) ||
                saveAsNewFile)
            {
                using (SaveFileDialog save = new SaveFileDialog
                {
                    Title = Words.SaveVocabularyBook,
                    FileName = CurrentBook.MotherTongue + " - " + CurrentBook.ForeignLang,
                    InitialDirectory = Settings.Default.VhfPath,
                    Filter = Words.VocupVocabularyBookFile + " (*.vhf)|*.vhf"
                })
                {
                    if (save.ShowDialog() == DialogResult.OK)
                    {
                        CurrentBook.FilePath = save.FileName;
                        CurrentBook.GenerateVhrCode();
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            Cursor.Current = Cursors.WaitCursor;

            if (VocabularyFile.WriteVhfFile(CurrentBook.FilePath, CurrentBook) &&
                VocabularyFile.WriteVhrFile(CurrentBook))
            {
                CurrentBook.UnsavedChanges = false;

                Settings.Default.LastFile = CurrentBook.FilePath;
                Settings.Default.Save();

                Cursor.Current = Cursors.Default;
                return(true);
            }
            else
            {
                Cursor.Current = Cursors.Default;
                return(false);
            }
        }