Product.xaml.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WPF01.pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Product.xaml
  19. /// </summary>
  20. public partial class Product : Page
  21. {
  22. db2.Test02Entities database;
  23. public Product()
  24. {
  25. InitializeComponent();
  26. database = new db2.Test02Entities();
  27. LoadProduct("");
  28. }
  29. void LoadProduct(string search)
  30. {
  31. List<db2.Product> products;
  32. if (search.Length == 0)
  33. {
  34. products = database.Product.ToList();
  35. }
  36. else
  37. {
  38. products = database.Product.Where(p => p.Title.IndexOf(search) > -1).ToList();
  39. }
  40. int productCouter = 0;
  41. ProductGrid.Children.Clear();
  42. for (int i = 0; i < 2; i++)
  43. {
  44. for (int j = 0; j < 3; j++) {
  45. // 5 < 4
  46. if ((products.Count - 1) < productCouter)
  47. {
  48. return;
  49. }
  50. Border border = new Border();
  51. border.BorderBrush = Brushes.Gray;
  52. border.BorderThickness = new Thickness(1);
  53. border.Margin = new Thickness(10);
  54. border.Background = Brushes.White;
  55. ProductGrid.Children.Add(border);
  56. Grid.SetRow(border, i);
  57. Grid.SetColumn(border, j);
  58. StackPanel stackPanel = new StackPanel();
  59. border.Child = stackPanel;
  60. //< Image Source = "/WPF01;component/Товары автосервиса/E9308929.jpg" Height = "129" Margin = "20,10,20,0" />
  61. Image image = new Image();
  62. BitmapImage bitmapImage = new BitmapImage();
  63. bitmapImage.BeginInit();
  64. bitmapImage.UriSource = new Uri("pack://application:,,,/" + products[productCouter].MainImagePath);
  65. bitmapImage.EndInit();
  66. image.Source = bitmapImage;
  67. image.Height = 130;
  68. stackPanel.Children.Add(image);
  69. Label l1 = new Label();
  70. l1.Content = products[productCouter].Title;
  71. l1.FontSize = 10;
  72. l1.Foreground = Brushes.DarkMagenta;
  73. l1.Padding = new Thickness(0);
  74. l1.Margin = new Thickness(0);
  75. l1.HorizontalContentAlignment = HorizontalAlignment.Center;
  76. stackPanel.Children.Add(l1);
  77. Label l2 = new Label();
  78. l2.Content = products[productCouter].Cost;
  79. stackPanel.Children.Add(l2);
  80. if (products[productCouter].IsActive == false) {
  81. Label l3 = new Label();
  82. l3.Content = "неактивен";
  83. stackPanel.Children.Add(l3);
  84. border.Background = Brushes.LightGray;
  85. }
  86. productCouter++;
  87. }
  88. }
  89. }
  90. private void TextBox_KeyUp(object sender, KeyEventArgs e)
  91. {
  92. LoadProduct(Search.Text);
  93. }
  94. }
  95. }