MainWindow.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using WpfApp1.SQL;
  17. using WpfApp1.Windows;
  18. namespace WpfApp1
  19. {
  20. public partial class Agent
  21. {
  22. public string ImagePres
  23. {
  24. get
  25. {
  26. if(Logo == null)
  27. {
  28. return "\\image\\picture.png";
  29. }
  30. else
  31. {
  32. return Logo;
  33. }
  34. }
  35. }
  36. public string TypAndNameAgent
  37. {
  38. get
  39. {
  40. return AgentType.Title + " | " + Title;
  41. }
  42. }
  43. public string ProdazhZaGod
  44. {
  45. get
  46. {
  47. int str = 0;
  48. foreach (var item in ProductSale)
  49. {
  50. str = item.ProductCount;
  51. }
  52. return str + " продаж за год";
  53. }
  54. }
  55. public string Prioritys
  56. {
  57. get
  58. {
  59. return "Приоритетность: " + Priority;
  60. }
  61. }
  62. public string BackgroundColor
  63. {
  64. get
  65. {
  66. if (ProductSale.Count > 0.025) return "#46B29D";
  67. return "#C6D7FF";
  68. }
  69. }
  70. //public string Prozents
  71. //{
  72. // get
  73. // {
  74. // }
  75. //}
  76. }
  77. /// <summary>
  78. /// Логика взаимодействия для MainWindow.xaml
  79. /// </summary>
  80. public partial class MainWindow : Window, INotifyPropertyChanged
  81. {
  82. public string[] SotrList { get; set; } =
  83. {
  84. "Без сортировки",
  85. "Название по убыванию",
  86. "Название по повзрастанию",
  87. "Скидка по убыванию",
  88. "Скидка по повзрастанию",
  89. "Приоритета по убыванию",
  90. "Приоритета по повзрастанию",
  91. };
  92. private int SortType = 0;
  93. private int Poiskid = 0;
  94. private IEnumerable<Agent> _AgentList;
  95. public IEnumerable<Agent> AgentList
  96. {
  97. get
  98. {
  99. var Result =_AgentList;
  100. if (Poiskid > 0) Result = Result.Where(i => i.AgentType.ID == Poiskid);
  101. switch (SortType)
  102. {
  103. case 1:
  104. Result = Result.OrderBy(p => Title);
  105. break;
  106. case 2:
  107. Result = Result.OrderByDescending(p => Title);
  108. break;
  109. }
  110. return Result;
  111. }
  112. set
  113. {
  114. _AgentList = value;
  115. //PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  116. }
  117. }
  118. public MainWindow()
  119. {
  120. InitializeComponent();
  121. DataContext = this;
  122. AgentList = Core.DB.Agent.ToList();
  123. }
  124. private void Exit_Click(object sender, RoutedEventArgs e)
  125. {
  126. if (MessageBox.Show("Выйти из приложения?", "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  127. {
  128. Application.Current.Shutdown();
  129. }
  130. }
  131. private void AddAgent_Click(object sender, RoutedEventArgs e)
  132. {
  133. var NewAgent = new Agent();
  134. var NewAgentWindow = new AddEditAgent(NewAgent);
  135. if ((bool)NewAgentWindow.ShowDialog())
  136. {
  137. AgentList = Core.DB.Agent.ToList();
  138. Core.DB.SaveChanges();
  139. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  140. }
  141. }
  142. private void MainListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  143. {
  144. }
  145. public event PropertyChangedEventHandler PropertyChanged;
  146. private void MainListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  147. {
  148. var MouseWindow = MainListView.SelectedItem as Agent;
  149. var NewMouseWindow = new AddEditAgent(MouseWindow);
  150. if ((bool)NewMouseWindow.ShowDialog())
  151. {
  152. AgentList = Core.DB.Agent.ToList();
  153. Core.DB.SaveChanges();
  154. PropertyChanged(this, new PropertyChangedEventArgs("AgentList"));
  155. }
  156. }
  157. private void Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  158. {
  159. SortType = Sort.SelectedIndex;
  160. return;
  161. }
  162. private void Poisk_SelectionChanged(object sender, RoutedEventArgs e)
  163. {
  164. }
  165. }
  166. }