Browse Source

Реализован поиск

Alec 3 years ago
parent
commit
6bb14df3ba
2 changed files with 47 additions and 24 deletions
  1. 15 21
      WPF01/pages/Product.xaml
  2. 32 3
      WPF01/pages/Product.xaml.cs

+ 15 - 21
WPF01/pages/Product.xaml

@@ -8,30 +8,24 @@
       d:DesignHeight="450" d:DesignWidth="600"
       Title="Product">
 
-    <Grid x:Name="ProductGrid">
+    <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="1*"/>
-            <RowDefinition Height="1*"/>
+            <RowDefinition Height="20"/>
         </Grid.RowDefinitions>
-        <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="1*"/>
-            <ColumnDefinition Width="1*"/>
-            <ColumnDefinition Width="1*"/>
-        </Grid.ColumnDefinitions>
-        <Border BorderBrush="Gray" BorderThickness="1" Margin="10" Background="White" Grid.Row="1">
-            <StackPanel>
-                <Image Source="/WPF01;component/Товары автосервиса/E9308929.jpg" Height="129" Margin="20,10,20,0" />
-                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0">
-                    <RadioButton Width="14" Height="14" />
-                    <RadioButton Width="14" Height="14" />
-                    <RadioButton Width="14" Height="14" />
-                    <RadioButton Width="14" Height="14" />
-                </StackPanel>
-                <Label Content="Наименование товара" FontSize="10" HorizontalContentAlignment="Center" Foreground="#FF496F95" Padding="0" Margin="0" />
-                <Label Content="1500 рублей" Padding="0" Margin="0" FontSize="10" HorizontalContentAlignment="Center" Foreground="#FF496F95"/>
-                <Label Content="неактивен" Foreground="#FF496F95" Padding="0" FontSize="8" HorizontalContentAlignment="Center"/>
-            </StackPanel>
-        </Border>
+        
+        <Grid x:Name="ProductGrid">
+            <Grid.RowDefinitions>
+                <RowDefinition Height="1*"/>
+                <RowDefinition Height="1*"/>
+            </Grid.RowDefinitions>
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="1*"/>
+                <ColumnDefinition Width="1*"/>
+                <ColumnDefinition Width="1*"/>
+            </Grid.ColumnDefinitions>
+        </Grid>
 
+        <TextBox x:Name="Search" HorizontalAlignment="Left" Height="27" TextWrapping="Wrap" VerticalAlignment="Top" Width="600" KeyUp="TextBox_KeyUp" Grid.Row="1"/>
     </Grid>
 </Page>

+ 32 - 3
WPF01/pages/Product.xaml.cs

@@ -28,19 +28,36 @@ namespace WPF01.pages
 
 			database = new db2.Test02Entities();
 
-			LoadProduct();
+			LoadProduct("");
 		}
 
-		void LoadProduct()
+		void LoadProduct(string search)
 		{
-			var products = database.Product.ToList();
+			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);
@@ -58,6 +75,13 @@ namespace WPF01.pages
 					//< 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);
@@ -90,5 +114,10 @@ namespace WPF01.pages
 				}
 			}
 		}
+
+		private void TextBox_KeyUp(object sender, KeyEventArgs e)
+		{
+			LoadProduct(Search.Text);
+		}
 	}
 }