예제 #1
0
        private void Add(object sender, RoutedEventArgs e)
        {
            BooksModel model  = DataContext as BooksModel;
            BookFormat format = new BookFormat();

            if (Format.SelectedItem == null || Author.Text == "" || Title.Text == "" || Year.Text == "")
            {
                MessageBox.Show("Put in valid data", "Invalid data", MessageBoxButton.OK);
                return;
            }
            if (Format.SelectedItem.Equals("EBook"))
            {
                format = BookFormat.EBook;
            }
            else if (Format.SelectedItem.Equals("Paper"))
            {
                format = BookFormat.PaperBack;
            }

            model.Books.Add(new Book(model.Books[model.Books.Count() - 1].Id + 1)
            {
                Author = Author.Text,
                Format = format,
                IsRead = (bool)IsRead.IsChecked,
                Title  = Title.Text,
                Year   = int.Parse(Year.Text)
            });

            Id.Content       = "";
            Title.Text       = "";
            Author.Text      = "";
            Year.Text        = "";
            IsRead.IsChecked = false;
        }
예제 #2
0
 /// <summary>
 /// Implementation of IBookListService to store information in binary file.
 /// </summary>
 /// <param name="books">The list of books to store information about.</param>
 public void Save(IEnumerable <Book> books)
 {
     using (BinaryWriter writer = new BinaryWriter(File.Open(this.filePath, FileMode.Create)))
     {
         IFormatProvider fmt = new BookFormat();
         foreach (Book b in books)
         {
             writer.Write(b.ToString("IATYP", fmt));
         }
     }
 }