public void addbBookIntoList() { string sqlQuery = "Select * From Book"; using (SqlCommand selectCommand = new SqlCommand(sqlQuery, dbConnection)) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = selectCommand; DataSet BookDataset = new DataSet(); adapter.Fill(BookDataset, "Book"); DataTable BookDataTable = BookDataset.Tables["Book"]; foreach (DataRow row in BookDataTable.Rows) { Book book = new Book { BookID = int.Parse(row[0].ToString()), Title = row[2].ToString(), Author = row[3].ToString(), Genere = row[4].ToString(), Price = int.Parse(row[5].ToString()), NoOfPages = int.Parse(row[6].ToString()) }; BookList.Add(book.BookID, book); } }; }
public void Call() { #region older versions without generics, code redundancy var numbers = new List(); numbers.Add(2); var booksList = new BookList(); booksList.Add(new Book()); #endregion var numbersList = new GenericList <int>(); numbers.Add(10); var books = new GenericList <Book>(); books.Add(new Book()); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book()); var number = new Nullable <int>(5); Console.WriteLine("Has value? " + number.HasValue); Console.WriteLine("Value: " + number.GetValueOrDefault()); var numberTwo = new Nullable <int>(); Console.WriteLine("Has value? " + numberTwo.HasValue); Console.WriteLine("Value: " + numberTwo.GetValueOrDefault()); }
private static BookList BookMaxYear(SqlConnection connection, int maxYear) { const string query = "select * from Book where Year<=@MaxYear"; using (var command = new SqlCommand(query, connection)) { command.Parameters.Add(new SqlParameter("@MaxYear", maxYear)); Console.WriteLine($"Books with max {maxYear}:"); using (var dataReader = command.ExecuteReader()) { var list = new BookList(); while (dataReader.Read()) { var currentRow = dataReader; var bookId = currentRow["BookId"]; var title = currentRow["Title"]; var year = currentRow["Year"]; var price = currentRow["Price"]; list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(), int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString())); } return(list); } } }
private static BookList Top10Books(SqlConnection connection) { const string query = "select top 10 * from Book"; using (var command = new SqlCommand(query, connection)) { Console.WriteLine("Top 10 Books:"); using (var dataReader = command.ExecuteReader()) { var list = new BookList(); while (dataReader.Read()) { var currentRow = dataReader; var title = currentRow["Title"]; var year = currentRow["Year"]; var price = currentRow["Price"]; list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(), int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString())); } return(list); } } }
static void Main(string[] args) { var book = new Book { Isbn = "1111", Title = "C# Advanced" }; //Classic way var numbers = new List(); numbers.Add(10); var books = new BookList(); books.Add(book); //Generic var numberList = new GenericList <int>(); numberList.Add(10); var bookList = new GenericList <Book>(); bookList.Add(book); var dictionary = new GenericDictionary <string, Book>(); dictionary.Add("1234", new Book()); }
private void ExecuteHttpCommand() { NavigationService.NavigateTo(typeof(HttpPage).FullName); Messenger.Default.Send(new NotificationMessageAction <Book>(null, null, item => { BookList.Add(item); }), "http"); }
/// <summary> /// 追加コマンドを実行する /// </summary> private void AddCommandExecute() { Book addBook = new Book(books.GetList().Count + 1, Book.Title, Book.Author, Book.Price); books.Add(addBook); CollectionList.Add(addBook); }
/// <summary> Add book to the list.</summary> /// <param name="book"> The book to add. </param> public void AddBook(Book book) { if (IfBookExists(book)) { throw new ArgumentException("The book already exists!"); } BookList.Add(book); }
/// <summary> /// 追加コマンドを実行する /// </summary> private void AddCommandExecute() { Book addBook = new Book(DataBaseManager.GetIDNextData(), Book.Title, Book.Author, Book.Price); books.Add(addBook); DataBaseManager.AddDataBase(addBook); CollectionList.Add(addBook); }
/// <summary> /// コンストラクタ /// </summary> public MainViewModel() { Book = new Book(); books = new BookList(); DataBaseManager = new DataBaseManager(); if (!DataBaseManager.IsExistDataBaseFile()) { DataBaseManager.CreateDataBase(); books.Add(new Book() { ID = 1, Title = "簡単すぎる本", Author = "アンドロイド1号", Price = 100 }); books.Add(new Book() { ID = 2, Title = "普通すぎる本", Author = "アンドロイド2号", Price = 200 }); books.Add(new Book() { ID = 3, Title = "難しすぎる本", Author = "アンドロイド3号", Price = 300 }); foreach (var book in books.GetList()) { DataBaseManager.AddDataBase(book); } } else { foreach (var book in DataBaseManager.GetDataBase()) { books.Add(book); } } CollectionList = new ObservableCollection <Book>(books.GetList()); }
void InitData() { var ser = new BookService2(new BookRepository()); var lst = ser.GetBooks(); BookList.Clear(); foreach (var article in lst) { BookList.Add(article); } }
/// <summary> /// コンストラクタ /// </summary> public MainViewModel() { Book = new Book(); books = new BookList(); books.Add(new Book() { ID = 1, Title = "簡単すぎる本", Author = "アンドロイド1号", Price = 100 }); books.Add(new Book() { ID = 2, Title = "普通すぎる本", Author = "アンドロイド2号", Price = 200 }); books.Add(new Book() { ID = 3, Title = "難しすぎる本", Author = "アンドロイド3号", Price = 300 }); CollectionList = new ObservableCollection <Book>(books.GetList()); }
private void sortByName() { List <BOOK> sortedList = BookList.OrderBy(x => x.NAME.ToUpper().Contains(SortByName.ToUpper())).ToList(); sortedList.Reverse(); BookList.Clear(); foreach (var sortedItem in sortedList) { BookList.Add(sortedItem); } SelectedBook = BookList.First(); OnPropertyChanged("BookList"); }
private void sortByBookId() { List <BOOK> sortedList = BookList.OrderBy(x => x.ID.ToString() == Convert.ToString(SearchByBookId)).ToList(); sortedList.Reverse(); BookList.Clear(); foreach (var sortedItem in sortedList) { BookList.Add(sortedItem); } SelectedBook = BookList.First(); OnPropertyChanged("BookList"); }
public bool AddBook(string Title, string Author) { try { BookList.Add(new Book(this.NextBookId, Title, Author)); Console.WriteLine("SUCCESS: Added book to library: " + this.Name); this.NextBookId++; return(true); } catch { Console.WriteLine("ERROR: Faild to add book to library: " + this.Name); return(false); } }
private async Task _addBookAsync() { var books = await BookHelper.OpenAsync(); if (books == null) { return; } books.ForEach(book => { BookList.Add(book); }); NavigationService.NavigateTo(typeof(BookReadPage).FullName, books[0]); }
private void _refresh() { BookList.Clear(); SqlHelper.Conn.Open(); using (var reader = SqlHelper.Select <Book>("ORDER BY ReadTime DESC")) { while (reader.Read()) { if (reader.HasRows) { BookList.Add(new Book(reader)); } } } SqlHelper.Conn.Close(); }
/// <summary> /// Adds the book. /// </summary> /// <param name="book">The book.</param> /// <exception cref="ArgumentNullException">book</exception> /// <exception cref="ArgumentException">book</exception> public void AddBook(Book book) { if (ReferenceEquals(book, null)) { Logger.Error($"{nameof(book)} is null"); throw new ArgumentNullException($"{nameof(book)} is null"); } if (BookList.Contains(book)) { Logger.Error($"{nameof(book)} is already exist!"); throw new ArgumentException($"{nameof(book)} is already exist!"); } BookList.Add(book); Logger.Info($"{nameof(book)} added!"); }
void UpdateBookList(bool setActive = true) { lock (_updateBookLock) { BookList.Clear(); foreach (var book in _localBookList.Books) { _books[book] = null; BookList.Add(book); } if (setActive && BookList.Count > 0) { ActiveBook = BookList[0]; } } }
/// <summary> /// add book for the booklist and with the important entities to the resultList /// </summary> /// <param name="result">the api calls result object</param> private void AddItemToList(BookList result) { foreach (var d in result.Docs) { ImageSource img = _searchService.GetImg(d.Cover_edition_key, "M"); var temp = new BookEntity { Title = d.Title_suggest, Img = img, Isbn = d.Isbn, Oclc = d.Oclc, Lccn = d.Lccn }; ResultList.Add(temp); BookList.Add(d); } }
static void Main(string[] args) { var book = new Book { Isbn = "12133", Title = "CSharp" }; var number = new List(); number.Add(10); var books = new BookList(); books.Add(book); var letters = new GenericList <string>(); letters.Add("teste"); }
//Method that lets a user add a book to the library public static void AddBook() { Console.WriteLine("Would you like to donate a book? (Yes or No)"); string reply = Validator.inputCheck(Console.ReadLine()); if (reply == "yes" || reply == "y") { Console.WriteLine("What is the title?"); string title = Validator.ValidateTitle(); Console.WriteLine("Who is the author?"); string author = Validator.ValidateAuthor(); BookList.Add(new Book(title, author, 0)); } else if (reply == "no" || reply == "n") { } BookToTxtFile(BookList); }
/// <summary> /// 上一页 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnpreviewpage_Click(object sender, RoutedEventArgs e) { PageIndex = (Convert.ToInt32(PageIndex) - 1).ToString(); int pagecount = Convert.ToInt32(PageCount); Books book = new Books() { BookCategory = BookCategoryId, BookName = BookName, BarCode = Barcode, PageIndex = Convert.ToInt32(PageIndex), PageSize = Convert.ToInt32(PageSize) }; List <Books> bookslist = new List <Books>(); bookmaintainb.SearchBookinfoList <Books>(DAL.SQLID.BookMaintain.BookMaintain.selelct_book_bycontation, book, bookslist); BookList.Clear(); if (bookslist.Count != 0) { foreach (var item in bookslist) { BookList.Add(item); } } if (Convert.ToInt32(PageIndex) == 1) { //上一页,首页不可用,其他可以用 ButtonFistpage = "0"; ButtonNexpage = "1"; ButtonPreviewpage = "0"; ButtonLastpage = "1"; ButtonRedirttopage = "1"; //btnfistpage.IsEnabled = false; //btnnextpage.IsEnabled = true; //btnpreviewpage.IsEnabled = false; //btnlastpage.IsEnabled = true; //btnredirettopage.IsEnabled = true; } }
public void PrepareData(List <Book> books, Author author) { Id = author.Id; Name = author.Name; Surname = author.Surname; DateOfBirth = author.DateBorned.ToString("dd.MM.yyyy."); foreach (var book in books) { BookDetailsViewModel viewModel = new BookDetailsViewModel(); viewModel.Id = book.Id; viewModel.Title = book.Title; viewModel.Subtitle = book.Subtitle; viewModel.Isbn = book.Isbn; BookList.Add(viewModel); } NumberOfBooks = BookList.Count; }
private static BookList Books2010(SqlConnection connection, int year) { const string query = "select * from Book where Year=@Year"; using (var command = new SqlCommand(query, connection)) { command.Parameters.Add(new SqlParameter("@Year", year)); using (var dataReader = command.ExecuteReader()) { var list = new BookList(); while (dataReader.Read()) { var currentRow = dataReader; list.Add(int.Parse(currentRow["BookId"].ToString()), currentRow["Title"].ToString(), int.Parse(currentRow["Year"].ToString()), decimal.Parse(currentRow["Price"].ToString())); } return(list); } } }
private void h_TestFill() { BookList.Add( new Book() { Title = "имя 1", Author = "й1 ц у" }); BookList.Add( new Book() { Title = "имя 2", Author = "й2 ц у" }); BookList.Add( new Book() { Title = "имя 3", Author = "й3 ц у" }); }
private void AddButton_Click(object sender, RoutedEventArgs e) { string author = AuthorTextBox.Text; string title = TitleTextBox.Text; string releaseDate, nISBN; Categories category = (Categories)Enum.Parse(typeof(Categories), CategoryComboBox.Text); Types type = (Types)Enum.Parse(typeof(Types), TypeComboBox.Text); int numberOfPages, length, numberOfActors; int selectedCategory = CategoryComboBox.SelectedIndex; switch (selectedCategory) { case 0: try { nISBN = FirstAdditionalInformationInfoTextBox.Text; numberOfPages = int.Parse(SecondAdditionalInformationInfoTextBox.Text); Book book = new Book(title, author, category, type, nISBN, numberOfPages); BookList.Add(book); totalToRead = book.News(totalToRead, "add"); } catch { MessageBox.Show("Ilość stron powinna być podana jako liczba", "Zła wartość"); } break; case 1: try { length = int.Parse(SecondAdditionalInformationInfoTextBox.Text); numberOfActors = int.Parse(FirstAdditionalInformationInfoTextBox.Text); Audiobook audiobook = new Audiobook(title, author, category, type, length, numberOfActors); AudiobookList.Add(audiobook); totalToListen = audiobook.News(totalToListen, "add"); } catch { MessageBox.Show("Czas trwania oraz liczba aktorów powinny być podane jako liczby", "Zła wartość"); } break; case 2: try { releaseDate = FirstAdditionalInformationInfoTextBox.Text; length = int.Parse(SecondAdditionalInformationInfoTextBox.Text); Movie movie = new Movie(title, author, category, type, length, releaseDate); MovieList.Add(movie); totalToWatch = movie.News(totalToWatch, "add"); } catch { MessageBox.Show("Czas trwania powinien być podany jako liczba", "Zła wartość"); } break; } SetNewsTextBlocks(selectedCategory); }
private void ReadTXTFile_Click(object sender, RoutedEventArgs e) { try { string fileName = TXTfilePath.Text + TXTfileName.Text + ".txt"; FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); try { StreamReader streamReader = new StreamReader(fileStream); while (streamReader.EndOfStream == false) { string line = streamReader.ReadLine(); string[] table = line.Split('_'); if (table[0] == "Książka") { Categories category = (Categories)Enum.Parse(typeof(Categories), "Książka"); string title = table[1]; string author = table[2]; string nISBN = table[3]; int numberOfPages = int.Parse(table[4]); Types type = (Types)Enum.Parse(typeof(Types), table[5]); Book book = new Book(title, author, category, type, nISBN, numberOfPages); BookList.Add(book); totalToRead = book.News(totalToRead, "add"); } else if (table[0] == "Audiobook") { Categories category = (Categories)Enum.Parse(typeof(Categories), "Audiobook"); string title = table[1]; string author = table[2]; int length = int.Parse(table[3]); int numberOfActors = int.Parse(table[4]); Types type = (Types)Enum.Parse(typeof(Types), table[5]); Audiobook audiobook = new Audiobook(title, author, category, type, length, numberOfActors); AudiobookList.Add(audiobook); totalToListen = audiobook.News(totalToListen, "add"); } else if (table[0] == "Film") { Categories category = (Categories)Enum.Parse(typeof(Categories), "Film"); string title = table[1]; string author = table[2]; int length = int.Parse(table[3]); string releaseDate = table[4]; Types type = (Types)Enum.Parse(typeof(Types), table[5]); Movie movie = new Movie(title, author, category, type, length, releaseDate); MovieList.Add(movie); totalToWatch = movie.News(totalToWatch, "add"); } else { MessageBox.Show("Wystąpił błąd podczas odczytywana danych z pliku"); } } streamReader.Close(); MessageBox.Show("Wczytano pomyslnie"); } catch (Exception ex) { MessageBox.Show("Nie można wczytać pliku."); } int selectedCategory = CategoryComboBox.SelectedIndex; SetNewsTextBlocks(selectedCategory); } catch (Exception ex) { MessageBox.Show("Nie można otworzyć pliku."); } }
public void AddBook(Book _book) { BookList.Add(_book); }
/// <summary> /// /// </summary> public static void addBookItem(String EPC, String timeStamp, String RSSI, string Title, string Autor, string Genre, Byte[] Image) { BookList.Add(new Itembook(EPC = EPC, timeStamp = timeStamp.ToString(), RSSI = RSSI, Title = Title, Autor = Autor, Genre = Genre, Image = Image)); }