123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace WPF01.pages
- {
- /// <summary>
- /// Логика взаимодействия для Product.xaml
- /// </summary>
- public partial class Product : Page
- {
- db2.Test02Entities database;
- public Product()
- {
- InitializeComponent();
- database = new db2.Test02Entities();
- LoadProduct("");
- }
- void LoadProduct(string search)
- {
- List<db2.Product> products;
- if (search.Length == 0)
- {
- products = database.Product.ToList();
- }
- else
- {
- products = database.Product.Where(p => p.Title.IndexOf(search) > -1).ToList();
- }
- int productCouter = 0;
- ProductGrid.Children.Clear();
-
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++) {
- // 5 < 4
- if ((products.Count - 1) < productCouter)
- {
- return;
- }
- Border border = new Border();
- border.BorderBrush = Brushes.Gray;
- border.BorderThickness = new Thickness(1);
- border.Margin = new Thickness(10);
- border.Background = Brushes.White;
- ProductGrid.Children.Add(border);
- Grid.SetRow(border, i);
- Grid.SetColumn(border, j);
- StackPanel stackPanel = new StackPanel();
- border.Child = stackPanel;
- //< Image Source = "/WPF01;component/Товары автосервиса/E9308929.jpg" Height = "129" Margin = "20,10,20,0" />
- Image image = new Image();
- BitmapImage bitmapImage = new BitmapImage();
- bitmapImage.BeginInit();
- bitmapImage.UriSource = new Uri("pack://application:,,,/" + products[productCouter].MainImagePath);
- bitmapImage.EndInit();
- image.Source = bitmapImage;
- image.Height = 130;
- stackPanel.Children.Add(image);
- Label l1 = new Label();
- l1.Content = products[productCouter].Title;
- l1.FontSize = 10;
- l1.Foreground = Brushes.DarkMagenta;
- l1.Padding = new Thickness(0);
- l1.Margin = new Thickness(0);
- l1.HorizontalContentAlignment = HorizontalAlignment.Center;
- stackPanel.Children.Add(l1);
- Label l2 = new Label();
- l2.Content = products[productCouter].Cost;
- stackPanel.Children.Add(l2);
- if (products[productCouter].IsActive == false) {
- Label l3 = new Label();
- l3.Content = "неактивен";
- stackPanel.Children.Add(l3);
- border.Background = Brushes.LightGray;
- }
- productCouter++;
- }
- }
- }
- private void TextBox_KeyUp(object sender, KeyEventArgs e)
- {
- LoadProduct(Search.Text);
- }
- }
- }
|