MainWindow.xaml.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Text;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Data;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Imaging;
  11. using System.Windows.Navigation;
  12. using System.Windows.Shapes;
  13. using WpfApp1.model;
  14. namespace WpfApp1
  15. {
  16. public partial class MainWindow : Window, INotifyPropertyChanged
  17. {
  18. public event PropertyChangedEventHandler PropertyChanged;
  19. private void Invalidate()
  20. {
  21. if (PropertyChanged != null)
  22. PropertyChanged(this, new PropertyChangedEventArgs("ClientList"));
  23. }
  24. public string selectedCategory = "Все категории";
  25. public ClientPrice? selectedPrice = null;
  26. private IEnumerable<Client> _ClientList;
  27. public IEnumerable<Client> ClientList
  28. {
  29. get
  30. {
  31. var res = _ClientList;
  32. res = res
  33. .Where(c => (selectedPrice == null || (c.Price >= selectedPrice.PriceFrom && c.Price < selectedPrice.PriceTo)))
  34. .Where(c => (c.Category == selectedCategory || selectedCategory == "Все категории"));
  35. if (searchFilter != "")
  36. res = res.Where(c => c.Name.IndexOf(
  37. searchFilter,
  38. StringComparison.OrdinalIgnoreCase) >= 0 || c.Category.IndexOf(
  39. searchFilter,
  40. StringComparison.OrdinalIgnoreCase) >= 0 || c.Place.IndexOf(
  41. searchFilter,
  42. StringComparison.OrdinalIgnoreCase) >= 0);
  43. if (sortAsc) res = res.OrderBy(c => c.Price);
  44. else res = res.OrderByDescending(c => c.Price);
  45. if (sortAsc) res = res.OrderBy(c => c.Price);
  46. else res = res.OrderByDescending(c => c.Price);
  47. return res;
  48. }
  49. set
  50. {
  51. _ClientList = value;
  52. }
  53. }
  54. public List<Client> Client { get; set; }
  55. public List<ClientCategory> ClientCategoryList { get; set; }
  56. public List<ClientPrice> ClientPriceList { get; set; }
  57. public MainWindow()
  58. {
  59. {
  60. InitializeComponent();
  61. DataContext = this;
  62. Globals.dataProvider = new LocalDataProvider();
  63. ClientList = Globals.dataProvider.getClient();
  64. ClientPriceList = Globals.dataProvider.getPrice().ToList();
  65. ClientCategoryList = Globals.dataProvider.getCategory().ToList();
  66. ClientCategoryList.Insert(0, new ClientCategory() { title = "Все категории" });
  67. }
  68. }
  69. private void ExitButton_Click(object sender, RoutedEventArgs e)
  70. {
  71. Application.Current.Shutdown();
  72. }
  73. private string searchFilter = "";
  74. private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
  75. {
  76. searchFilter = SearchFilterTextBox.Text;
  77. Invalidate();
  78. }
  79. private void ClientCategoryFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  80. {
  81. selectedCategory = (CategoryFilterComboBox.SelectedItem as ClientCategory).title;
  82. Invalidate();
  83. }
  84. private void ClientPriceFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  85. {
  86. selectedPrice = PriceFilterComboBox.SelectedItem as ClientPrice;
  87. Invalidate();
  88. }
  89. private bool sortAsc = true;
  90. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  91. {
  92. sortAsc = (sender as RadioButton).Tag.ToString() == "1";
  93. Invalidate();
  94. }
  95. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  96. {
  97. }
  98. }
  99. interface IDataProvider
  100. {
  101. IEnumerable<Client> getClient();
  102. IEnumerable<ClientPrice> getPrice();
  103. IEnumerable<ClientCategory> getCategory();
  104. }
  105. public class LocalDataProvider : IDataProvider
  106. {
  107. public IEnumerable<ClientCategory> getCategory()
  108. {
  109. return new ClientCategory[]
  110. {
  111. new ClientCategory()
  112. {
  113. title="По России"
  114. },
  115. new ClientCategory()
  116. {
  117. title="За границей"
  118. },
  119. };
  120. }
  121. public IEnumerable<ClientPrice> getPrice()
  122. {
  123. return new ClientPrice[]
  124. {
  125. new ClientPrice()
  126. {
  127. title = "Все цены",
  128. PriceFrom = 500,
  129. PriceTo = 30000
  130. },
  131. new ClientPrice()
  132. {
  133. title = "Низкая цена",
  134. PriceFrom = 500,
  135. PriceTo = 3000
  136. },
  137. new ClientPrice()
  138. {
  139. title = "Средняя цена",
  140. PriceFrom = 3000,
  141. PriceTo = 15000
  142. },
  143. new ClientPrice()
  144. {
  145. title = "Высокая цена",
  146. PriceFrom = 15000,
  147. PriceTo = 30000
  148. }
  149. };
  150. }
  151. public IEnumerable<Client> getClient()
  152. {
  153. return new Client[]{
  154. new Client{
  155. Name = "Никита",
  156. Age = 20,
  157. Price=2300,
  158. Category="По России",
  159. Place="Москва"},
  160. new Client{
  161. Name = "Маша",
  162. Age = 15,
  163. Price=5000,
  164. Category="По России",
  165. Place="Сочи"},
  166. new Client{
  167. Name = "Алиса",
  168. Age = 35,
  169. Price=15000,
  170. Category="За границей",
  171. Place="Токио"},
  172. new Client{
  173. Name = "Леша",
  174. Age = 19,
  175. Price=20000,
  176. Category="За границей",
  177. Place="Южная Корея"},
  178. new Client{
  179. Name = "Андрей",
  180. Age = 28,
  181. Price=3000,
  182. Category="По России",
  183. Place="Крым"},
  184. new Client{
  185. Name = "Костя",
  186. Age = 14,
  187. Price=18000,
  188. Category="За границей",
  189. Place="Токио"},
  190. new Client{
  191. Name = "Даша",
  192. Age = 12,
  193. Price=25000,
  194. Category="За границей",
  195. Place="Лондон"},
  196. new Client{
  197. Name = "Ольга",
  198. Age = 55,
  199. Price=22000,
  200. Category="За границей",
  201. Place="Люксембург"},
  202. new Client{
  203. Name = "Катя",
  204. Age = 30,
  205. Price=1500,
  206. Category="По России",
  207. Place="Адлер"},
  208. new Client{
  209. Name = "Анжела",
  210. Age = 61,
  211. Price=25000,
  212. Category="За границей",
  213. Place="Мальдивы"},
  214. new Client{
  215. Name = "Миша",
  216. Age = 17,
  217. Price=30000,
  218. Category="За границей",
  219. Place="Дубаи"},
  220. };
  221. }
  222. }
  223. }