// Initialize the book database with some test books: static void AddBooks(BookStore bookDB) { bookDB.AddBook("Life 3.0", "Max Tegmark", 19.95m, true); bookDB.AddBook("Professional Android 4th edition", "Reto Meijer", 28.50m, false); bookDB.AddBook("It", "Stephan King", 27m, true); bookDB.AddBook("Origin", "Dan Brown", 17.95m, true); }
static void Main(string[] args) { const int MAXBOOKS = 10; Console.WriteLine($"Books to add in bookstore: {MAXBOOKS}\n"); //test delegate BookStore l = new BookStore(); //add a book with a custom callback l.AddBook("C# Delegate Sample", 25.99m, delegate(string message, decimal averagePrice) { Console.WriteLine("Custom callback. Message: {0}, Average Price {1:C2}", message, averagePrice); }); //add many books with a common callback ProcessBookCountCallback commonCallback = new ProcessBookCountCallback(delegate(string message, decimal averagePrice) { Console.WriteLine($"Common callback. Message: {message}, Average Price: {averagePrice.ToString("C2")}"); }); for (int i = 0; i < 10; i++) { decimal randomPrice = r.Next(0, 11) * 0.99m; l.AddBook($"C# Delegate Sample {i}", randomPrice, commonCallback); } Console.ReadLine(); }
// connect with the model to add items private void AddBook() { Enum.TryParse(comboCategory.Text, out eCategory category); Book item = new Book(Int32.Parse(txtEdition.Text), Int32.Parse(txtIsbn.Text), txtItemName.Text, DateTime.Parse(dateTime.Text), Convert.ToDouble(txtPrice.Text), Int32.Parse(txtCopyNumber.Text), txtTopic.Text, category, Convert.ToInt32(nUDStock.Value)); bs.AddBook(item); }