private void ComeBack_Click(object sender, RoutedEventArgs e) { SearchBooks searchBooks = new SearchBooks(); foreach (Book n in library.MyBooks) { BookItem bookItem = new BookItem(n); searchBooks.ListBookWrapPanel.Children.Add(bookItem); } MainWindow.THIS.ContentGrid.Children.Clear(); MainWindow.THIS.ContentGrid.Children.Add(searchBooks); }
public OpenRedBook(Book book, SearchBooks searchBooks) { InitializeComponent(); this.book = book; this.searchBooks = searchBooks; BookTitle.Text = book.BookName; Author.Text = book.Author; Country.Text = book.Country; Year.Text = Convert.ToString(book.GodIzdaniya); Genre.Text = book.Genre; Disc.Text = book.Discription; string z = "pack://application:,,,/Resources/" + book.Picture; this.PictureBox.Source = new BitmapImage(new Uri(z)); }
private async void MenuListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { int index = MenuListView.SelectedIndex; if (index == -1) { return; } if (GridMenu.Width != 60) { OpenMenuButton.Visibility = Visibility.Visible; UserInfo.Visibility = CloseMenuButton.Visibility = Visibility.Collapsed; DoubleAnimation buttonAnimation = new DoubleAnimation { From = GridMenu.ActualWidth, To = 60, Duration = TimeSpan.FromSeconds(0.2), FillBehavior = FillBehavior.Stop }; GridMenu.BeginAnimation(Button.WidthProperty, buttonAnimation); Storyboard sb = new Storyboard(); ThicknessAnimation commGridAnimation = new ThicknessAnimation { From = new Thickness(200, 0, 0, 0), To = new Thickness(0, 0, 0, 0), FillBehavior = FillBehavior.Stop, Duration = TimeSpan.FromSeconds(0.3) }; Storyboard.SetTarget(commGridAnimation, ContentGrid); Storyboard.SetTargetProperty(commGridAnimation, new PropertyPath(MarginProperty)); sb.Children.Add(commGridAnimation); sb.Begin(); } switch (index) { case 0: ContentGrid.Children.Clear(); ContentGrid.Children.Add(new MyAccount(user)); break; case 1: MyBooks myBooks = new MyBooks(); ProgressBar1.Visibility = Visibility.Visible; using (SqlConnection con2 = new SqlConnection(ConnectionString)) { con2.Open(); string sqlExpression = "select id_book from Book_" + user.username; SqlCommand command = new SqlCommand(sqlExpression, con2); SqlDataReader reader = command.ExecuteReader(); List <int> id_list = new List <int>(); if (reader.HasRows) { while (reader.Read()) { id_list.Add(Convert.ToInt32(reader.GetValue(0))); } } reader.Close(); if (id_list.Count() != 0) { List <Book> Spisok = await Task.Run(() => Founder(library.MyBooks)); for (int i = 0; i < id_list.Count; i++) { var spc = from n in Spisok where n.Id == id_list[i] select n; foreach (Book n in spc) { myBooks.MyBookWrapPanel.Children.Add(new MyBookItem(n)); } } ContentGrid.Children.Clear(); ContentGrid.Children.Add(myBooks); } else { Empty.IsOpen = true; } ProgressBar1.Visibility = Visibility.Collapsed; } break; case 2: SearchBooks searchBooks = new SearchBooks(); ProgressBar1.Visibility = Visibility.Visible; List <Book> Res = await Task.Run(() => Founder(library.MyBooks)); ProgressBar1.Visibility = Visibility.Collapsed; foreach (Book n in Res) { searchBooks.ListBookWrapPanel.Children.Add(new BookItem(n)); } ContentGrid.Children.Clear(); ContentGrid.Children.Add(searchBooks); break; case 3: ContentGrid.Children.Clear(); ContentGrid.Children.Add(new AddNewBookAdmin()); break; } }
private async void Search_Click(object sender, RoutedEventArgs e) { if (SearchTextBox.Text != "") { SearchBooks searchBooks = new SearchBooks(); Books library = new Books(); ThicknessAnimation anim1 = new ThicknessAnimation(); anim1.From = new Thickness(0, 10, 0, 0); anim1.To = new Thickness(0, 30, 0, 0); anim1.FillBehavior = FillBehavior.Stop; anim1.Duration = new Duration(TimeSpan.FromSeconds(0.25)); scroll.BeginAnimation(Label.MarginProperty, anim1); SearchSelIndBack = SearchCombo.SelectedIndex; SearchTextBack = SearchTextBox.Text.ToLower(); This = this; int selected_index = SearchCombo.SelectedIndex; switch (selected_index) { case 0: List <Book> Res1 = await Task.Run(() => Founder(library.MyBooks)); var BookName = from n in Res1 where n.BookName.ToLower().StartsWith(SearchTextBox.Text.ToLower()) select n; FounderTwo(BookName); break; case 1: List <Book> Res2 = await Task.Run(() => Founder(library.MyBooks)); var Author = from n in Res2 where n.Author.ToLower().StartsWith(SearchTextBox.Text.ToLower()) select n; FounderTwo(Author); break; case 2: List <Book> Res3 = await Task.Run(() => Founder(library.MyBooks)); var PubCountry = from n in Res3 where n.Country.ToLower().StartsWith(SearchTextBox.Text.ToLower()) select n; FounderTwo(PubCountry); break; case 3: List <Book> Res4 = await Task.Run(() => Founder(library.MyBooks)); var Genres = from n in Res4 where n.Genre.ToLower().StartsWith(SearchTextBox.Text.ToLower()) select n; FounderTwo(Genres); break; case 4: int outyear; bool result = Int32.TryParse(SearchTextBox.Text, out outyear); if (result) { List <Book> Res5 = await Task.Run(() => Founder(library.MyBooks)); var GodIzd = from n in Res5 where n.GodIzdaniya == outyear select n; FounderTwo(GodIzd); } else { Icon1.Foreground = Brushes.Red; } break; } } else { Icon1.Foreground = Brushes.Red; } }
public SearchBooks() { InitializeComponent(); This = this; }
public OpenBook(Book book, SearchBooks searchBooks) { InitializeComponent(); THIS = this; username = MainWindow.THIS.UsernameTop.Text.Trim(); if (username == "admin") { RedStack.Visibility = Visibility.Visible; } this.searchBooks = searchBooks; string a = searchBooks.SearchTextBox.Text; this.book = book; BookTitle.Text = book.BookName; Author.Text = book.Author; Country.Text = book.Country; Year.Text = Convert.ToString(book.GodIzdaniya); Genre.Text = book.Genre; Disc.Text = book.Discription; string z = "pack://application:,,,/Resources/" + book.Picture; Picture.Source = new BitmapImage(new Uri(z)); try { using (SqlConnection con = new SqlConnection(ConnectionString)) { con.Open(); string CmdString = "select AVG(value) from Rating where book_id =" + book.Id; SqlCommand cmd = new SqlCommand(CmdString, con); string value = cmd.ExecuteScalar().ToString(); if (value.Length > 3) { value = value.Substring(0, 3); } RateBlock.Text = value; } using (SqlConnection con = new SqlConnection(ConnectionString)) { con.Open(); string Cmd = "SELECT (select COUNT(*) from Rating where book_id = " + book.Id + " and value = 1)[1]," + "(select COUNT(*) from Rating where book_id = " + book.Id + " and value = 2)[2]," + "(select COUNT(*) from Rating where book_id = " + book.Id + " and value = 3)[3]," + "(select COUNT(*) from Rating where book_id = " + book.Id + " and value = 4)[4]," + "(select COUNT(*) from Rating where book_id = " + book.Id + " and value = 5)[5]," + "(select COUNT(*) from Rating where book_id = " + book.Id + ")[count]"; SqlCommand command = new SqlCommand(Cmd, con); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) // если есть данные { reader.Read(); Rating rating = new Rating(Convert.ToInt32(reader.GetValue(0)), Convert.ToInt32(reader.GetValue(1)), Convert.ToInt32(reader.GetValue(2)), Convert.ToInt32(reader.GetValue(3)), Convert.ToInt32(reader.GetValue(4)), Convert.ToInt32(reader.GetValue(5))); if (rating.total == 0) { NoRatesPanel.Visibility = Visibility.Visible; RatesPanel.Visibility = Visibility.Collapsed; } else { int[] array = new int[] { rating.five, rating.four, rating.three, rating.two, rating.one }; int[] sorted = (from element in array orderby element ascending select element).ToArray(); double part = 150 / (double)sorted[4]; Five.Width = (double)rating.five * part; Four.Width = (double)rating.four * part; Three.Width = (double)rating.three * part; Two.Width = (double)rating.two * part; One.Width = (double)rating.one * part; } } reader.Close(); } } catch (Exception err) { NoRatesPanel.Visibility = Visibility.Visible; RatesPanel.Visibility = Visibility.Collapsed; } try { using (SqlConnection con = new SqlConnection(ConnectionString)) { con.Open(); string CmdString = "select username, comment, value from Rating where book_id = " + book.Id; SqlCommand cmd = new SqlCommand(CmdString, con); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) // если есть данные { while (reader.Read()) { CommentItem item = new CommentItem(Convert.ToString(reader.GetValue(0)), Convert.ToString(reader.GetValue(1)), Convert.ToInt32(reader.GetValue(2))); CommentPanel.Children.Add(item); } } reader.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }