public Book(string _author, string _title, string _publisher, int _year, double _price, string _cultureName, string _ISBN) { Author = _author; Title = _title; Publisher = _publisher; Year = new YearFormat(_year); Price = new PriceFormat(_price, new CultureInfo(_cultureName)); ISBN = new ISBNFormat(_ISBN); logger.Debug($"Created new book: {this}."); }
public Book(string _author, string _title, string _publisher, YearFormat _year, PriceFormat _price, ISBNFormat _ISBN) { Author = _author; Title = _title; Publisher = _publisher; Year = _year; Price = _price; ISBN = _ISBN; logger.Debug($"Created new book: {this}."); }
private void btnSaveChanges_Click(object sender, RoutedEventArgs e) { try { int err = MainWindow.IsInputCorrect(txtYear.Text, txtPrice.Text, cmbbxCulture.SelectedItem.ToString(), txtISBN.Text); switch (err) { case 1: throw new Exception("Invalid year value!"); case 2: throw new Exception("Invalid price value!"); case 3: throw new Exception("Invalid culture value!"); case 4: throw new Exception("Invalid ISBN value!"); } NewAuthor = txtAuthor.Text; NewTitle = txtTitle.Text; NewPublisher = txtPublisher.Text; NewYear = new YearFormat(int.Parse(txtYear.Text)); NewPrice = new PriceFormat(double.Parse(txtPrice.Text), new CultureInfo(cmbbxCulture.SelectedItem.ToString())); NewISBN = new ISBNFormat(txtISBN.Text); Book newBook = new Book(NewAuthor, NewTitle, NewPublisher, NewYear, NewPrice, NewISBN); // check if this book already exists if ((booksList.IndexOf(newBook) != -1) && (booksList.IndexOf(newBook) != oldIndex)) { throw new Exception("Such book already exists!"); } DialogResult = true; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static int CompareByPrice(Book bookA, Book bookB) { return(PriceFormat.Compare(bookA.Price, bookB.Price)); }