Esempio n. 1
0
        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}.");
        }
Esempio n. 2
0
        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}.");
        }
Esempio n. 3
0
        // check strings for null/spaces is unnecessary, because ibook can be untitled/unauthorized
        // this function checks price, year, culture and isbn
        // returns 0, if input is correct, otherwise returns number of invalid parameter
        public static int IsInputCorrect(string _year, string _price, string _culture, string _ISBN)
        {
            // check year
            int year = 0;

            try
            {
                year = int.Parse(_year);
            }
            catch
            {
                return(1);
            }
            // check price
            double price = 0;

            try
            {
                price = double.Parse(_price);
            }
            catch
            {
                return(2);
            }
            // check culture
            CultureInfo culture = null;

            try
            {
                culture = new CultureInfo(_culture);
            }
            catch
            {
                return(3);
            }
            if (!ISBNFormat.IsISBNValid(_ISBN))
            {
                return(4);
            }
            return(0);
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
 public static int CompareByISBN(Book bookA, Book bookB)
 {
     return(ISBNFormat.Compare(bookA.ISBN, bookB.ISBN));
 }