private async void BackToMy_Click(object sender, RoutedEventArgs e) { string usname = MainWindow.THIS.UsernameTop.Text; MyBooks myBooks = new MyBooks(); using (SqlConnection con2 = new SqlConnection(ConnectionString)) { con2.Open(); string sqlExpression = "select id_book from Book_" + usname; 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(); 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) { MyBookItem mybookItem = new MyBookItem(n); myBooks.MyBookWrapPanel.Children.Add(mybookItem); } } } MainWindow.THIS.ContentGrid.Children.Clear(); MainWindow.THIS.ContentGrid.Children.Add(myBooks); }
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; } }