MainWindow.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System.ComponentModel;
  2. using System.Diagnostics;
  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 WpfApp4.model;
  14. namespace WpfApp4
  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. // Globals.dataProvider = new LocalDataProvider();
  68. Globals.dataProvider = new CSVDataProvider();
  69. ClientList = Globals.dataProvider.getClient();
  70. }
  71. }
  72. private void ExitButton_Click(object sender, RoutedEventArgs e)
  73. {
  74. Application.Current.Shutdown();
  75. }
  76. private string searchFilter = "";
  77. private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
  78. {
  79. searchFilter = SearchFilterTextBox.Text;
  80. Invalidate();
  81. }
  82. private void ClientCategoryFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  83. {
  84. selectedCategory = (CategoryFilterComboBox.SelectedItem as ClientCategory).title;
  85. Invalidate();
  86. }
  87. private void ClientPriceFilterComboBox_selectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  88. {
  89. selectedPrice = PriceFilterComboBox.SelectedItem as ClientPrice;
  90. Invalidate();
  91. }
  92. private bool sortAsc = true;
  93. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  94. {
  95. sortAsc = (sender as RadioButton).Tag.ToString() == "1";
  96. Invalidate();
  97. }
  98. private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  99. {
  100. }
  101. }
  102. interface IDataProvider
  103. {
  104. IEnumerable<Client> getClient();
  105. IEnumerable<ClientPrice> getPrice();
  106. IEnumerable<ClientCategory> getCategory();
  107. }
  108. public class LocalDataProvider : IDataProvider
  109. {
  110. public IEnumerable<ClientCategory> getCategory()
  111. {
  112. return new ClientCategory[]
  113. {
  114. new ClientCategory()
  115. {
  116. title="По России"
  117. },
  118. new ClientCategory()
  119. {
  120. title="За границей"
  121. },
  122. };
  123. }
  124. public IEnumerable<ClientPrice> getPrice()
  125. {
  126. return new ClientPrice[]
  127. {
  128. new ClientPrice()
  129. {
  130. title = "Все цены",
  131. PriceFrom = 500,
  132. PriceTo = 30000
  133. },
  134. new ClientPrice()
  135. {
  136. title = "Низкая цена",
  137. PriceFrom = 500,
  138. PriceTo = 3000
  139. },
  140. new ClientPrice()
  141. {
  142. title = "Средняя цена",
  143. PriceFrom = 3000,
  144. PriceTo = 15000
  145. },
  146. new ClientPrice()
  147. {
  148. title = "Высокая цена",
  149. PriceFrom = 15000,
  150. PriceTo = 30000
  151. }
  152. };
  153. }
  154. public IEnumerable<Client> getClient()
  155. {
  156. return new Client[]{
  157. new Client{
  158. Name = "Никита",
  159. Age = 20,
  160. Price=2300,
  161. Category="По России",
  162. Place="Москва"
  163. },
  164. new Client{
  165. Name = "Маша",
  166. Age = 15,
  167. Price=5000,
  168. Category="По России",
  169. Place="Сочи"
  170. },
  171. new Client{
  172. Name = "Алиса",
  173. Age = 35,
  174. Price=15000,
  175. Category="За границей",
  176. Place="Токио"
  177. },
  178. new Client{
  179. Name = "Леша",
  180. Age = 19,
  181. Price=20000,
  182. Category="За границей",
  183. Place="Южная Корея"
  184. },
  185. new Client{
  186. Name = "Андрей",
  187. Age = 28,
  188. Price=3000,
  189. Category="По России",
  190. Place="Крым"
  191. },
  192. new Client{
  193. Name = "Костя",
  194. Age = 14,
  195. Price=18000,
  196. Category="За границей",
  197. Place="Токио"
  198. },
  199. new Client{
  200. Name = "Даша",
  201. Age = 12,
  202. Price=25000,
  203. Category="За границей",
  204. Place="Лондон"
  205. },
  206. new Client{
  207. Name = "Ольга",
  208. Age = 55,
  209. Price=22000,
  210. Category="За границей",
  211. Place="Люксембург"
  212. },
  213. new Client{
  214. Name = "Катя",
  215. Age = 30,
  216. Price=1500,
  217. Category="По России",
  218. Place="Адлер"
  219. },
  220. new Client{
  221. Name = "Анжела",
  222. Age = 61,
  223. Price=25000,
  224. Category="За границей",
  225. Place="Мальдивы"
  226. },
  227. new Client{
  228. Name = "Миша",
  229. Age = 17,
  230. Price=30000,
  231. Category="За границей",
  232. Place="Дубаи"
  233. },
  234. };
  235. }
  236. }
  237. }