public ListBooks() { LoggerUtil.HandleLogPath(); Logs.Info($"[WPFBigRemGUI.ListBooks] Starting ListBooks wpf gui."); InitializeComponent(); booksUtil = new BooksUtil(); WindowStartupLocation = WindowStartupLocation.CenterScreen; lblListBook.Foreground = Brushes.Green; // Disable resize ResizeMode = ResizeMode.CanMinimize; // Count object in db countObjectList.Content = booksUtil.GetListBooks().Count; countObjectList.Foreground = Brushes.ForestGreen; // show list book if (booksUtil.GetListBooks() != null) { var stopwatch = new Stopwatch(); stopwatch.Restart(); listviewBook.ItemsSource = booksUtil.GetListBooks(); Show_ms.Content = stopwatch.Elapsed.TotalMilliseconds; Show_ms.Foreground = Brushes.ForestGreen; } else { Logs.Warn($"[ListBooks] There's no element in Db Book."); } }
private void DeleteThisBook_Click(object sender, RoutedEventArgs e) { var getBook = (RememberUtility.Model.Books)listviewBook.SelectedItem; if (MessageBox.Show($"Found '{getBook.bookName}'." + $" Do you wanna delete '{getBook.bookName}'", "Confirm delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { booksUtil.DeleteBook(getBook.bookName); lblExportBookResult.Foreground = Brushes.Green; lblExportBookResult.Content = "Deleted"; // Count second var stopwatch = new Stopwatch(); stopwatch.Restart(); // Count this object loading listviewBook.ItemsSource = booksUtil.GetListBooks(); Show_ms.Content = stopwatch.Elapsed.TotalMilliseconds; // Count again countObjectList.Foreground = Brushes.ForestGreen; countObjectList.Content = booksUtil.GetListBooks().Count; } else { lblExportBookResult.Foreground = Brushes.Red; lblExportBookResult.Content = "Canceled"; } }
private async void DoBackupAsync() { await Task.Run(() => { // Backup Database if (booksUtil.GetListBooks() != null) { booksUtil.BackupDatabase(EnumFileConstant.BOOKCONSTANT, FileConstant.BackUpDb); // Backup by zipfile ZipBackupFiles.ZipFile(EnumFileConstant.BOOK); } }); }
private void TextBox_KeyUp(object sender, KeyEventArgs e) { bool found = false; var border = (resultStack.Parent as ScrollViewer).Parent as Border; var data = booksUtil.GetListBooks(); string query = (sender as TextBox).Text; if (query.Length == 0) { // Clear resultStack.Children.Clear(); border.Visibility = Visibility.Collapsed; } else { border.Visibility = Visibility.Visible; } // Clear the list resultStack.Children.Clear(); // Add the result foreach (var book in data) { if (book.bookName.ToLower().StartsWith(query.ToLower())) { // The word starts with this... Autocomplete must work AddItem(book.bookName); found = true; } } if (!found) { resultStack.Children.Add(new TextBlock() { Text = "No results found." }); } }
private static void Main() { Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; LoggerUtil.HandleLogPath(); var bookUtil = new BooksUtil(); int choose; int tempChoose; HandleRandom.ChooseColorForString("--- Welcome to Web Bookmark ---", ConsoleColor.Yellow); Console.WriteLine("1. Get list books"); Console.WriteLine("2. Add book"); Console.WriteLine("3. Find book"); Console.WriteLine("4. Delete book"); Console.WriteLine("5. Upate book"); Console.WriteLine("6. Save book to Excel"); Console.WriteLine("7. Save book Model to db"); HandleRandom.ChooseColorForString("0. Exit", ConsoleColor.Red); Console.Write("Choose: "); while (int.TryParse(Console.ReadLine(), out tempChoose)) { choose = tempChoose; switch (choose) { case 1: foreach (var itemBook in bookUtil.GetListBooks()) { Console.WriteLine("Book Id: " + itemBook.BookId); HandleRandom.ChooseColorForString($"Book name: {itemBook.BookName}", ConsoleColor.Green); Console.WriteLine("Author: " + itemBook.Author); Console.WriteLine("Category: " + itemBook.Category); Console.WriteLine("-----------------------------"); } break; case 2: // add book Console.Write("Book Name: "); var bookName = Console.ReadLine(); Console.Write("Author: "); var author = Console.ReadLine(); Console.WriteLine("Types of Category"); string category; var count = 1; var listConstantValue = typeof(CategoriesBookConstant).GetAllPublicConstantValues <string>(); listConstantValue.Sort(); foreach (var propertyInfo in listConstantValue) { Console.WriteLine(count++ + ". " + propertyInfo); } Console.WriteLine("Please choose a category: "); category = Console.ReadLine(); if (category != null) { if (int.Parse(category) > 0 && int.Parse(category) <= listConstantValue.Count) { category = listConstantValue[int.Parse(category) - 1]; } } bookUtil.AddBook(new Books() { BookId = HandleRandom.RandomString(8), BookName = bookName, Author = author, Category = category }); HandleRandom.ChooseColorForString("Adding successful", ConsoleColor.Blue); break; case 3: // find book Console.Write("Book name: "); var findBookName = Console.ReadLine(); var result = bookUtil.FindBookBy(findBookName); if (result != null) { Console.WriteLine("Info Book---"); Console.WriteLine("Id: " + result.BookId); Console.WriteLine("Book Name: " + result.BookName); Console.WriteLine("Author: " + result.Author); Console.WriteLine("Category: " + result.Category); Console.WriteLine("-----------------------------"); break; } HandleRandom.ChooseColorForString("There are no book you find", ConsoleColor.Blue); break; case 4: Console.Write("Book name to delete: "); var findBookToDelete = Console.ReadLine(); Console.WriteLine($"Are you sure wants to delete '{findBookToDelete}'"); Console.Write("Y/n? "); var yesNoQuestion = Console.ReadLine(); if (yesNoQuestion.ToLower() == "y") { if (bookUtil.DeleteBook(findBookToDelete)) { HandleRandom.ChooseColorForString("Deleted successful", ConsoleColor.Blue); break; } HandleRandom.ChooseColorForString("Nothing book name to delete", ConsoleColor.DarkRed); break; } break; case 5: // update book Console.Write("Find book to UPDATE: "); var placeHoldBookName = Console.ReadLine(); if (bookUtil.FindBookBy(placeHoldBookName) != null) { var currentBookResult = bookUtil.FindBookBy(placeHoldBookName); HandleRandom.ChooseColorForString("Found book", ConsoleColor.Blue); Console.WriteLine("Book Info---"); Console.WriteLine("Id: " + currentBookResult.BookId); Console.WriteLine("Book Name: " + currentBookResult.BookName); Console.WriteLine("Author: " + currentBookResult.Author); Console.WriteLine("Category: " + currentBookResult.Category); Console.WriteLine("-----------------------------"); Console.Write("Book name to update: "); var bookNameToUpdate = Console.ReadLine(); Console.Write("Author to update: "); var authorToUpdate = Console.ReadLine(); Console.WriteLine("Types of Category"); var counts = 1; var listConstantValues = typeof(CategoriesBookConstant).GetAllPublicConstantValues <string>(); listConstantValues.Sort(); foreach (var propertyInfo in listConstantValues) { Console.WriteLine(counts++ + ". " + propertyInfo); } Console.Write("Please choose a category to update: "); var categoryToUpdate = Console.ReadLine(); if (categoryToUpdate != null) { if (int.Parse(categoryToUpdate) > 0 && int.Parse(categoryToUpdate) <= listConstantValues.Count) { categoryToUpdate = listConstantValues[int.Parse(categoryToUpdate) - 1]; } } if (bookUtil.UpdateBook(currentBookResult.BookName, bookNameToUpdate, authorToUpdate, categoryToUpdate)) { HandleRandom.ChooseColorForString("Update book success", ConsoleColor.Blue); break; } HandleRandom.ChooseColorForString("Update book Failed", ConsoleColor.DarkRed); } else { HandleRandom.ChooseColorForString("Nothing found book", ConsoleColor.DarkRed); } break; case 6: // save book to excel var saveFile = new SaveFileDialog(); Console.Write("Table Name: "); var tableName = Console.ReadLine(); var filePath = ""; if (saveFile.ShowDialog() == DialogResult.OK) { filePath = Path.GetFullPath(saveFile.FileName); } bookUtil.SaveBookToExcel(filePath, tableName); break; case 7: break; } if (choose == 0) { HandleRandom.ChooseColorForString("There is no option you chose", ConsoleColor.Blue); Thread.Sleep(2000); Environment.Exit(0); } else { Console.WriteLine("1. Get list books"); Console.WriteLine("2. Add book"); Console.WriteLine("3. Find book"); Console.WriteLine("4. Delete book"); Console.WriteLine("5. Upate book"); Console.WriteLine("6. Save book to Excel"); Console.WriteLine("0. Exit"); Console.Write("Choose: "); } } }
// GET: Books public ActionResult Index(string sortingOrder, string searchData, string filterValue, int?pageNo) { if (Session["Name"] != null) { ViewBag.CurrentSortOrder = sortingOrder; ViewBag.BookId = IsNullOrEmpty(sortingOrder) ? "Book Id" : ""; ViewBag.BookName = IsNullOrEmpty(sortingOrder) ? "Book name" : ""; ViewBag.Author = IsNullOrEmpty(sortingOrder) ? "Author" : ""; ViewBag.Category = IsNullOrEmpty(sortingOrder) ? "Category" : ""; ViewBag.CreatedDate = IsNullOrEmpty(sortingOrder) ? "Created date" : ""; ViewBag.LastModifiedDate = IsNullOrEmpty(sortingOrder) ? "Last modified date" : ""; if (searchData != null) { pageNo = 1; // default is 1 } else { searchData = filterValue; } //filter ViewBag.FilterValue = searchData; IEnumerable <Books> books = _booksUtil.GetListBooks(); if (!IsNullOrEmpty(searchData)) { books = books.Where(b => b.BookName.ToUpper().Contains(searchData.ToUpper()) || b.Author.ToUpper().Contains(searchData.ToUpper()) || b.Category.ToUpper().Contains(searchData.ToUpper()) || b.CreatedDate.ToUpper().Contains(searchData.ToUpper()) || b.LastModifiedDate.ToUpper().Contains(searchData.ToUpper())); } switch (sortingOrder) { case "Book Id": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.BookId); break; case "Book name": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.BookName); break; case "Author": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.Author); break; case "Category": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.Category); break; case "Created date": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.CreatedDate); break; case "Last modified date": books = (books ?? throw new InvalidOperationException()).OrderBy(b => b.LastModifiedDate); break; default: books = (books ?? throw new InvalidOperationException()).OrderByDescending(b => b.BookName); break; } const int sizeOfPage = 7; // records number show in 1 page var noOfPage = (pageNo ?? 1); // page default is 1 return(View(books.ToPagedList(noOfPage, sizeOfPage))); } return(RedirectToAction("Login", "Home")); }