search.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. сортировка по выбранной дате в date picker
  2. <DatePicker Name="datePicker" SelectedDateChanged="datePicker_SelectedDateChanged"></DatePicker>
  3. private void datePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  4. {
  5. filtres();
  6. }
  7. private void filtresMethod()
  8. {
  9. List<Order> orders = db.tbe.Order.ToList();
  10. List<OrderProduct> orderProducts = db.tbe.OrderProduct.ToList();
  11. List<Product> products = db.tbe.Product.ToList();
  12. if (datePicker.SelectedDate.HasValue)
  13. {
  14. DateTime selectedDate = datePicker.SelectedDate.Value;
  15. // Фильтрация заказов по выбранной дате
  16. var filteredOrders = orders.Where(x => x.OrderDeliveryDate.Date == selectedDate.Date).ToList();
  17. // Сортировка заказов по выбранной дате
  18. filteredOrders = filteredOrders.OrderBy(x => Math.Abs((x.OrderDeliveryDate - selectedDate).TotalDays)).ToList();
  19. // Получение идентификаторов продуктов для отфильтрованных заказов
  20. var productArticleNumbers = filteredOrders
  21. .Join(orderProducts, o => o.OrderID, op => op.OrderID, (o, op) => op.ProductArticleNumber)
  22. .ToList();
  23. // Получение связанных продуктов
  24. var filteredProducts = products
  25. .Join(productArticleNumbers, p => p.ProductArticleNumber, pa => pa, (p, pa) => p)
  26. .ToList();
  27. // Установка источника данных для lvProduct с использованием информации о продукте
  28. lvProduct.ItemsSource = filteredProducts;
  29. }
  30. else
  31. {
  32. // Если дата не выбрана, используйте список продуктов
  33. if (cmbSorted.SelectedItem != null)
  34. {
  35. ComboBoxItem comboBoxItem = (ComboBoxItem)cmbSorted.SelectedItem;
  36. switch (comboBoxItem.Content)
  37. {
  38. case "По умолчанию":
  39. // Ничего не делаем
  40. break;
  41. case "По возрастанию стоимости":
  42. products = products.OrderBy(x => x.ProductCost).ToList();
  43. break;
  44. case "По убыванию стоимости":
  45. products = products.OrderByDescending(x => x.ProductCost).ToList();
  46. break;
  47. }
  48. }
  49. if (cmbFiltres.SelectedItem != null)
  50. {
  51. ComboBoxItem comboBoxItem = (ComboBoxItem)cmbFiltres.SelectedItem;
  52. switch (comboBoxItem.Content)
  53. {
  54. case "Все диапазоны":
  55. // Ничего не делаем
  56. break;
  57. case "0-9,99%":
  58. products = products.Where(x => x.ProductDiscountAmount >= 0 && x.ProductDiscountAmount <= 9.99).ToList();
  59. break;
  60. case "10-14,99%":
  61. products = products.Where(x => x.ProductDiscountAmount >= 10 && x.ProductDiscountAmount <= 14.99).ToList();
  62. break;
  63. case "15% и более":
  64. products = products.Where(x => x.ProductDiscountAmount >= 15).ToList();
  65. break;
  66. }
  67. }
  68. if (tbSearch.Text != null && !string.IsNullOrEmpty(tbSearch.Text))
  69. {
  70. products = products.Where(x => x.ProductName.ToLower().Contains(tbSearch.Text)).ToList();
  71. }
  72. if (products.Count == 0)
  73. {
  74. MessageBox.Show("Отсутствуют критерии, удовлетворяющие результатам поиска!");
  75. }
  76. lvProduct.ItemsSource = products;
  77. }
  78. tblast.Text = lvProduct.Items.Count.ToString();
  79. }
  80. поиск по календарю
  81. <Window x:Class="CalendarSearch.MainWindow"
  82. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  83. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  84. Title="Calendar Search" Height="350" Width="500">
  85. <Grid>
  86. <Grid.RowDefinitions>
  87. <RowDefinition Height="Auto"/>
  88. <RowDefinition Height="*"/>
  89. </Grid.RowDefinitions>
  90. <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
  91. <TextBox x:Name="searchTextBox" Width="200" Margin="5"/>
  92. <Button Content="Search" Click="SearchButton_Click" Margin="5"/>
  93. </StackPanel>
  94. <Calendar x:Name="calendar" Grid.Row="1" SelectionMode="SingleDate"/>
  95. </Grid>
  96. </Window>
  97. using System;
  98. using System.Collections.Generic;
  99. using System.Linq;
  100. using System.Windows;
  101. using System.Windows.Controls;
  102. namespace CalendarSearch
  103. {
  104. public partial class MainWindow : Window
  105. {
  106. public MainWindow()
  107. {
  108. InitializeComponent();
  109. }
  110. private void SearchButton_Click(object sender, RoutedEventArgs e)
  111. {
  112. DateTime selectedDate = calendar.SelectedDate ?? DateTime.Today;
  113. string searchKeyword = searchTextBox.Text.ToLower();
  114. List<DateTime> matchingDates = GetMatchingDates(selectedDate, searchKeyword);
  115. if (matchingDates.Any())
  116. {
  117. MessageBox.Show($"Found {matchingDates.Count} matching dates:\n{string.Join("\n", matchingDates)}");
  118. }
  119. else
  120. {
  121. MessageBox.Show("No matching dates found.");
  122. }
  123. }
  124. private List<DateTime> GetMatchingDates(DateTime selectedDate, string searchKeyword)
  125. {
  126. List<DateTime> matchingDates = new List<DateTime>();
  127. // Perform your search logic here
  128. // You can search for dates in a specific range, or search in your data source, etc.
  129. // For demonstration purposes, let's assume we have a list of dates to search through
  130. List<DateTime> datesToSearch = new List<DateTime>
  131. {
  132. new DateTime(2023, 1, 1),
  133. new DateTime(2023, 1, 15),
  134. new DateTime(2023, 2, 3),
  135. new DateTime(2023, 2, 15),
  136. new DateTime(2023, 3, 5),
  137. new DateTime(2023, 3, 15),
  138. new DateTime(2023, 4, 7),
  139. new DateTime(2023, 4, 15)
  140. };
  141. foreach (DateTime date in datesToSearch)
  142. {
  143. if (date.ToString().ToLower().Contains(searchKeyword))
  144. {
  145. matchingDates.Add(date);
  146. }
  147. }
  148. return matchingDates;
  149. }
  150. }
  151. }