ShowAgentPage.xaml.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace Golyshev43p180322
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ShowAgentPage.xaml
  19. /// </summary>
  20. public partial class ShowAgentPage : Page
  21. {
  22. List<Agent> AgentStart = BaseClass.Base.Agent.ToList();
  23. public ShowAgentPage()
  24. {
  25. InitializeComponent();
  26. LVAgent.ItemsSource = BaseClass.Base.Agent.ToList();
  27. CBFilter.Items.Add("Все типы");
  28. List<AgentType> AT = BaseClass.Base.AgentType.ToList();
  29. foreach(AgentType s in AT)
  30. {
  31. CBFilter.Items.Add(s.Title);
  32. }
  33. CBFilter.SelectedIndex = 0;
  34. CBSort.Items.Add("Все типы");
  35. CBSort.Items.Add("Наименование");
  36. CBSort.Items.Add("Размер скидки");
  37. CBSort.Items.Add("Приоритет агента");
  38. CBSort.SelectedIndex = 0;
  39. }
  40. private void TBTypeTitle_Loaded(object sender, RoutedEventArgs e)
  41. {
  42. TextBlock tb = (TextBlock)sender;
  43. int index = Convert.ToInt32(tb.Uid);
  44. string typename = "";
  45. List<Agent> A = BaseClass.Base.Agent.Where(x => x.ID == index).ToList();
  46. foreach (Agent s in A)
  47. {
  48. typename += s.AgentType.Title + " | " + s.Title;
  49. }
  50. tb.Text = typename;
  51. }
  52. private void TBSellsPerYear_Loaded(object sender, RoutedEventArgs e)
  53. {
  54. TextBlock tb = (TextBlock)sender;
  55. int index = Convert.ToInt32(tb.Uid);
  56. DateTime dtnow = DateTime.Now;
  57. DateTime dt = dtnow.AddYears(-1);
  58. List<ProductSale> PS = BaseClass.Base.ProductSale.Where(x => x.SaleDate >= dt && x.SaleDate <= dtnow&&x.AgentID==index).ToList();
  59. int count = 0;
  60. foreach(ProductSale s in PS)
  61. {
  62. count += s.ProductCount;
  63. }
  64. string countdeals = count+ " продаж(и) за год";
  65. tb.Text = countdeals;
  66. }
  67. List<Agent> AgentFilter;
  68. private void Filter()
  69. {
  70. int index = CBFilter.SelectedIndex;
  71. if(index!=0)
  72. {
  73. AgentFilter = BaseClass.Base.Agent.Where(x => x.AgentTypeID ==index).ToList();
  74. }
  75. else
  76. {
  77. AgentFilter = AgentStart;
  78. }
  79. if(!string.IsNullOrWhiteSpace(TBTextFilter.Text))
  80. {
  81. AgentFilter = AgentFilter.Where(x => x.Title.ToLower().Contains(TBTextFilter.Text.ToLower()) || x.Phone.ToLower().Contains(TBTextFilter.Text.ToLower())).ToList();
  82. }
  83. LVAgent.ItemsSource = AgentFilter;
  84. }
  85. private void TBTextFilter_TextChanged(object sender, TextChangedEventArgs e)
  86. {
  87. Filter();
  88. }
  89. private void TBDiscount_Loaded(object sender, RoutedEventArgs e)
  90. {
  91. TextBlock tb = (TextBlock)sender;
  92. int index = Convert.ToInt32(tb.Uid);
  93. List<ProductSale> A = BaseClass.Base.ProductSale.Where(x => x.AgentID == index).ToList();
  94. double total = 0;
  95. foreach(ProductSale s in A)
  96. {
  97. total += (double)(s.ProductCount * s.Product.MinCostForAgent);
  98. }
  99. if(total<=10000)
  100. {
  101. tb.Text = "0%";
  102. }
  103. if(total>10000&&total<=50000)
  104. {
  105. tb.Text = "5%";
  106. }
  107. if (total > 50000 && total <= 150000)
  108. {
  109. tb.Text = "10%";
  110. }
  111. if (total > 150000 && total <= 500000)
  112. {
  113. tb.Text = "20%";
  114. }
  115. if (total > 500000)
  116. {
  117. tb.Text = "25%";
  118. }
  119. }
  120. private void Button_Click(object sender, RoutedEventArgs e)
  121. {
  122. if(CBSort.SelectedIndex==0)
  123. {
  124. AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
  125. LVAgent.Items.Refresh();
  126. }
  127. if (CBSort.SelectedIndex == 1)
  128. {
  129. AgentFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  130. LVAgent.Items.Refresh();
  131. }
  132. if (CBSort.SelectedIndex == 2)
  133. {
  134. AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
  135. LVAgent.Items.Refresh();
  136. }
  137. if (CBSort.SelectedIndex == 3)
  138. {
  139. AgentFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
  140. LVAgent.Items.Refresh();
  141. }
  142. }
  143. private void Button_Click_1(object sender, RoutedEventArgs e)
  144. {
  145. if (CBSort.SelectedIndex == 0)
  146. {
  147. AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
  148. AgentFilter.Reverse();
  149. LVAgent.Items.Refresh();
  150. }
  151. if (CBSort.SelectedIndex == 1)
  152. {
  153. AgentFilter.Sort((x, y) => x.Title.CompareTo(y.Title));
  154. AgentFilter.Reverse();
  155. LVAgent.Items.Refresh();
  156. }
  157. if (CBSort.SelectedIndex == 2)
  158. {
  159. AgentFilter.Sort((x, y) => x.ID.CompareTo(y.ID));
  160. AgentFilter.Reverse();
  161. LVAgent.Items.Refresh();
  162. }
  163. if (CBSort.SelectedIndex == 3)
  164. {
  165. AgentFilter.Sort((x, y) => x.Priority.CompareTo(y.Priority));
  166. AgentFilter.Reverse();
  167. LVAgent.Items.Refresh();
  168. }
  169. }
  170. private void CBFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
  171. {
  172. Filter();
  173. }
  174. private void btnAddNewAgent_Click(object sender, RoutedEventArgs e)
  175. {
  176. FrameClass.MainFrame.Navigate(new CreateOrUpdate());
  177. }
  178. private void btnChange_Click(object sender, RoutedEventArgs e)
  179. {
  180. Button B = (Button)sender;
  181. int id = Convert.ToInt32(B.Uid);
  182. Agent AgentUpdate = BaseClass.Base.Agent.FirstOrDefault(x => x.ID == id);
  183. FrameClass.MainFrame.Navigate(new CreateOrUpdate(AgentUpdate));
  184. }
  185. }
  186. }