|
@@ -0,0 +1,200 @@
|
|
|
+//Работа с заглушкой картинки:
|
|
|
+<Page.Resources>
|
|
|
+ <BitmapImage x:Key="defaultImage" UriSource="/image/picture.png"/>
|
|
|
+ </Page.Resources>
|
|
|
+<Image Width="100" Height="100" Source="{Binding ProductPhoto, TargetNullValue={StaticResource defaultImage}}"/>
|
|
|
+//Поиск, фильтрация, сортировка:
|
|
|
+void Filter()
|
|
|
+ {
|
|
|
+ List<Product> product = new List<Product>();
|
|
|
+ product = ClassDBase.DB.Product.ToList();
|
|
|
+
|
|
|
+ //Поиск по названию
|
|
|
+ if (!string.IsNullOrWhiteSpace(SearchName.Text)) // Проверка пустую запись и запись состоящую из пробелов
|
|
|
+ {
|
|
|
+ product = product.Where(x => x.ProductName.ToLower().Contains(SearchName.Text.ToLower())).ToList();
|
|
|
+ if (product.Count == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Записей с таким названием нет");
|
|
|
+ SearchName.Text = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Фильтрация по размеру скидки
|
|
|
+ switch (Filtering.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ product = product.ToList();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ product = product.Where(x => ((x.ProductDiscountAmount >= 0) && (x.ProductDiscountAmount < 10))).ToList();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ {
|
|
|
+ product = product.Where(x => ((x.ProductDiscountAmount >= 10) && (x.ProductDiscountAmount < 15))).ToList();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ {
|
|
|
+ product = product.Where(x => (x.ProductDiscountAmount>= 15)).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ //сортировка
|
|
|
+ switch (Sorting.SelectedIndex)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ product.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ product.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
|
|
|
+ product.Reverse();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ListProduct.ItemsSource = product;
|
|
|
+
|
|
|
+//количество записей на странице
|
|
|
+ if (product.Count == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("нет записей");
|
|
|
+ CountProduct.Text = ClassDBase.DB.Product.ToList().Count + "/" + ClassDBase.DB.Product.ToList().Count;
|
|
|
+ SearchName.Text = "";
|
|
|
+ Sorting.SelectedIndex = 0;
|
|
|
+ Filtering.SelectedIndex = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+ CountProduct.Text = product.Count + "/" + ClassDBase.DB.Product.ToList().Count;
|
|
|
+ }
|
|
|
+// добавление в корзину
|
|
|
+// в классе с создание объекта бд
|
|
|
+public static List<Product> products = new List<Product>();
|
|
|
+// событие на правую кнопку мыши
|
|
|
+<Grid.ContextMenu>
|
|
|
+ <ContextMenu>
|
|
|
+ <MenuItem Header="Добавить к заказу" Click="MenuItem_Click" Uid="{Binding ProductArticleNumber}"/>
|
|
|
+ </ContextMenu>
|
|
|
+</Grid.ContextMenu>
|
|
|
+ private void MenuItem_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ MenuItem mi = (MenuItem)sender;
|
|
|
+ string index = mi.Uid;
|
|
|
+ Product product = ClassDBase.DB.Product.FirstOrDefault(x => x.ProductArticleNumber == index);
|
|
|
+ ClassDBase.products.Add(product);
|
|
|
+ ShowOrders.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+// обновление суммы товаров корзины
|
|
|
+ private void ButonDelete_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Button Buton = (Button)sender;
|
|
|
+ int index = Convert.ToInt32(Buton.Uid);
|
|
|
+ ProductBasket productBasket = bascet.FirstOrDefault(x => x.product.ID == index);
|
|
|
+ _ = bascet.Remove(productBasket);
|
|
|
+ if (bascet.Count == 0)
|
|
|
+ {
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ lvProduct.Items.Refresh();
|
|
|
+ calculateSummaAndDiscount();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Подсчёт суммы заказа и скидок
|
|
|
+ /// </summary>
|
|
|
+ private void calculateSummaAndDiscount()
|
|
|
+ {
|
|
|
+ summa = 0;
|
|
|
+ summaDiscount = 0;
|
|
|
+ foreach (ProductBasket productBasket in bascet)
|
|
|
+ {
|
|
|
+ summa += productBasket.count * productBasket.product.costWithDiscount;
|
|
|
+ summaDiscount += productBasket.count * ((double)productBasket.product.ProductCost - productBasket.product.costWithDiscount);
|
|
|
+ }
|
|
|
+ TBSumma.Text = "Сумма заказа: " + summa.ToString("0.00") + " руб.";
|
|
|
+ TBSummaDiscount.Text = "Сумма скидки: " + summaDiscount.ToString("0.00") + " руб.";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ TextBox TB = (TextBox)sender;
|
|
|
+ int index = Convert.ToInt32(TB.Uid);
|
|
|
+ ProductBasket productBasket = bascet.FirstOrDefault(x => x.product.ID == index);
|
|
|
+ productBasket.count = TB.Text.Replace(" ", "") == "" ? 0 : Convert.ToInt32(TB.Text);
|
|
|
+ if (productBasket.count == 0) // Если колличество 0, то продукт из корзины удаляется
|
|
|
+ {
|
|
|
+ _ = bascet.Remove(productBasket);
|
|
|
+ }
|
|
|
+ if (bascet.Count == 0) // Если в корзине нет товаров, то окно закрывается
|
|
|
+ {
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ lvProduct.Items.Refresh();
|
|
|
+ calculateSummaAndDiscount();
|
|
|
+ }
|
|
|
+
|
|
|
+// вывод на всякий
|
|
|
+<ListView Grid.Row="3" Name="ListProduct" Height="300" ScrollViewer.HorizontalScrollBarVisibility="Hidden" HorizontalContentAlignment="Stretch">
|
|
|
+ <ListView.ItemTemplate>
|
|
|
+ <DataTemplate>
|
|
|
+ <Border Style="{StaticResource BorderStyle}">
|
|
|
+ <Grid Height="150" VerticalAlignment="Center" Background="{Binding Brush}">
|
|
|
+ <Grid.ContextMenu>
|
|
|
+ <ContextMenu>
|
|
|
+ <MenuItem Header="Добавить к заказу" Click="MenuItem_Click" Uid="{Binding ProductArticleNumber}"/>
|
|
|
+ </ContextMenu>
|
|
|
+ </Grid.ContextMenu>
|
|
|
+ <Grid.ColumnDefinitions>
|
|
|
+ <ColumnDefinition Width="300"/>
|
|
|
+ <ColumnDefinition/>
|
|
|
+ <ColumnDefinition/>
|
|
|
+ </Grid.ColumnDefinitions>
|
|
|
+ <Grid Grid.Column="0" >
|
|
|
+ <Image Width="100" Height="100" Source="{Binding ProductPhoto, TargetNullValue={StaticResource defaultImage}}"/>
|
|
|
+ </Grid>
|
|
|
+ <Grid Grid.Column="1">
|
|
|
+ <Grid>
|
|
|
+ <StackPanel>
|
|
|
+ <StackPanel Orientation="Horizontal">
|
|
|
+ <TextBlock Text="Название:"/>
|
|
|
+ <TextBlock Name="product" Text="{Binding ProductName}" FontWeight="Bold" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ </StackPanel>
|
|
|
+ <StackPanel Orientation="Horizontal">
|
|
|
+ <TextBlock Text="Описание:"/>
|
|
|
+ <TextBlock Name="Description" Text="{Binding ProductDescription}" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ </StackPanel>
|
|
|
+ <StackPanel Orientation="Horizontal">
|
|
|
+ <TextBlock Text="Производитель:"/>
|
|
|
+ <TextBlock Name="Manufacturer" Text="{Binding Manufacturer.NameProductManufacturer}" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ </StackPanel>
|
|
|
+ <StackPanel Orientation="Horizontal">
|
|
|
+ <TextBlock Text="Цена:"/>
|
|
|
+ <TextBlock Name="Price" Text="{Binding Price}" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ <TextBlock Name="Cost" Text="{Binding Cost}" TextDecorations="Strikethrough" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ </StackPanel>
|
|
|
+ </StackPanel>
|
|
|
+ </Grid>
|
|
|
+ </Grid>
|
|
|
+ <Grid Grid.Column="2">
|
|
|
+ <Grid.RowDefinitions>
|
|
|
+ <RowDefinition Height="1*"/>
|
|
|
+ <RowDefinition Height="1*"/>
|
|
|
+ </Grid.RowDefinitions>
|
|
|
+ <StackPanel Orientation="Horizontal" Grid.Row="0">
|
|
|
+ <TextBlock Name="Discount" Text="{Binding Discount}" Style="{StaticResource TextList}"></TextBlock>
|
|
|
+ </StackPanel>
|
|
|
+ <Button Grid.Row="1" Name="Delete" Visibility="Collapsed" Content="Удалить" Click="Delete_Click" Uid="{Binding ProductArticleNumber}" Loaded="Delete_Loaded" Template="{StaticResource ButtonInElement}"/>
|
|
|
+ </Grid>
|
|
|
+ </Grid>
|
|
|
+ </Border>
|
|
|
+ </DataTemplate>
|
|
|
+ </ListView.ItemTemplate>
|
|
|
+ </ListView>
|