123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- сортировка по выбранной дате в date picker
- <DatePicker Name="datePicker" SelectedDateChanged="datePicker_SelectedDateChanged"></DatePicker>
- private void datePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
- {
- filtres();
- }
- private void filtresMethod()
- {
- List<Order> orders = db.tbe.Order.ToList();
- List<OrderProduct> orderProducts = db.tbe.OrderProduct.ToList();
- List<Product> products = db.tbe.Product.ToList();
- if (datePicker.SelectedDate.HasValue)
- {
- DateTime selectedDate = datePicker.SelectedDate.Value;
- // Фильтрация заказов по выбранной дате
- var filteredOrders = orders.Where(x => x.OrderDeliveryDate.Date == selectedDate.Date).ToList();
- // Сортировка заказов по выбранной дате
- filteredOrders = filteredOrders.OrderBy(x => Math.Abs((x.OrderDeliveryDate - selectedDate).TotalDays)).ToList();
- // Получение идентификаторов продуктов для отфильтрованных заказов
- var productArticleNumbers = filteredOrders
- .Join(orderProducts, o => o.OrderID, op => op.OrderID, (o, op) => op.ProductArticleNumber)
- .ToList();
- // Получение связанных продуктов
- var filteredProducts = products
- .Join(productArticleNumbers, p => p.ProductArticleNumber, pa => pa, (p, pa) => p)
- .ToList();
- // Установка источника данных для lvProduct с использованием информации о продукте
- lvProduct.ItemsSource = filteredProducts;
- }
- else
- {
- // Если дата не выбрана, используйте список продуктов
- if (cmbSorted.SelectedItem != null)
- {
- ComboBoxItem comboBoxItem = (ComboBoxItem)cmbSorted.SelectedItem;
- switch (comboBoxItem.Content)
- {
- case "По умолчанию":
- // Ничего не делаем
- break;
- case "По возрастанию стоимости":
- products = products.OrderBy(x => x.ProductCost).ToList();
- break;
- case "По убыванию стоимости":
- products = products.OrderByDescending(x => x.ProductCost).ToList();
- break;
- }
- }
- if (cmbFiltres.SelectedItem != null)
- {
- ComboBoxItem comboBoxItem = (ComboBoxItem)cmbFiltres.SelectedItem;
- switch (comboBoxItem.Content)
- {
- case "Все диапазоны":
- // Ничего не делаем
- break;
- case "0-9,99%":
- products = products.Where(x => x.ProductDiscountAmount >= 0 && x.ProductDiscountAmount <= 9.99).ToList();
- break;
- case "10-14,99%":
- products = products.Where(x => x.ProductDiscountAmount >= 10 && x.ProductDiscountAmount <= 14.99).ToList();
- break;
- case "15% и более":
- products = products.Where(x => x.ProductDiscountAmount >= 15).ToList();
- break;
- }
- }
- if (tbSearch.Text != null && !string.IsNullOrEmpty(tbSearch.Text))
- {
- products = products.Where(x => x.ProductName.ToLower().Contains(tbSearch.Text)).ToList();
- }
- if (products.Count == 0)
- {
- MessageBox.Show("Отсутствуют критерии, удовлетворяющие результатам поиска!");
- }
- lvProduct.ItemsSource = products;
- }
- tblast.Text = lvProduct.Items.Count.ToString();
- }
- поиск по календарю
- <Window x:Class="CalendarSearch.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Calendar Search" Height="350" Width="500">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
-
- <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
- <TextBox x:Name="searchTextBox" Width="200" Margin="5"/>
- <Button Content="Search" Click="SearchButton_Click" Margin="5"/>
- </StackPanel>
-
- <Calendar x:Name="calendar" Grid.Row="1" SelectionMode="SingleDate"/>
- </Grid>
- </Window>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace CalendarSearch
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
-
- private void SearchButton_Click(object sender, RoutedEventArgs e)
- {
- DateTime selectedDate = calendar.SelectedDate ?? DateTime.Today;
- string searchKeyword = searchTextBox.Text.ToLower();
-
- List<DateTime> matchingDates = GetMatchingDates(selectedDate, searchKeyword);
-
- if (matchingDates.Any())
- {
- MessageBox.Show($"Found {matchingDates.Count} matching dates:\n{string.Join("\n", matchingDates)}");
- }
- else
- {
- MessageBox.Show("No matching dates found.");
- }
- }
-
- private List<DateTime> GetMatchingDates(DateTime selectedDate, string searchKeyword)
- {
- List<DateTime> matchingDates = new List<DateTime>();
-
- // Perform your search logic here
- // You can search for dates in a specific range, or search in your data source, etc.
- // For demonstration purposes, let's assume we have a list of dates to search through
-
- List<DateTime> datesToSearch = new List<DateTime>
- {
- new DateTime(2023, 1, 1),
- new DateTime(2023, 1, 15),
- new DateTime(2023, 2, 3),
- new DateTime(2023, 2, 15),
- new DateTime(2023, 3, 5),
- new DateTime(2023, 3, 15),
- new DateTime(2023, 4, 7),
- new DateTime(2023, 4, 15)
- };
-
- foreach (DateTime date in datesToSearch)
- {
- if (date.ToString().ToLower().Contains(searchKeyword))
- {
- matchingDates.Add(date);
- }
- }
-
- return matchingDates;
- }
- }
- }
|