MenuAdmin.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using PP_Ven_MosS.Classes;
  2. using PP_Ven_MosS.ModelBase;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace PP_Ven_MosS.Pages
  19. {
  20. /// <summary>
  21. /// Логика взаимодействия для MenuAdmin.xaml
  22. /// </summary>
  23. public partial class MenuAdmin
  24. {
  25. User user = new User();
  26. private string evtype;
  27. public string EventType
  28. {
  29. get { return evtype; }
  30. set { evtype = value; }
  31. }
  32. private string apptype;
  33. public string ApplicType
  34. {
  35. get { return apptype; }
  36. set { apptype = value; }
  37. }
  38. private string employee;
  39. public string Employee
  40. {
  41. get { return employee; }
  42. set { employee = value; }
  43. }
  44. private void CBEmpl_Loaded(object sender, RoutedEventArgs e)
  45. {
  46. ComboBox cb = (ComboBox)sender;
  47. cb.ItemsSource = DB.User.ToList().Where(x => x.Id_role == 2);
  48. cb.DisplayMemberPath = "Surname";
  49. cb.SelectedValuePath = "Id_user";
  50. int appId = int.Parse(cb.Uid);
  51. Applications ap = DB.Applications.FirstOrDefault(x => x.Id_application == appId);
  52. if (ap.Id_employee != null)
  53. {
  54. cb.SelectedValue = Convert.ToInt32(ap.Id_employee);
  55. EmployeeID.employeeid = Convert.ToInt32(cb.SelectedValue);
  56. }
  57. }
  58. private void CBEmpl_SelectionChanged(object sender, SelectionChangedEventArgs e)
  59. {
  60. PP_MininEntities2 DB = new PP_MininEntities2();
  61. ComboBox cb = (ComboBox)sender;
  62. cb.DisplayMemberPath = "Surname";
  63. cb.SelectedValuePath = "Id_user";
  64. if(cb.Uid != null) {
  65. int appId = int.Parse(cb.Uid);
  66. Applications ap = DB.Applications.FirstOrDefault(x => x.Id_application == appId);
  67. if (cb.SelectedItem != null)
  68. {
  69. if (ap != null)
  70. {
  71. ap.Id_employee = Convert.ToInt32(cb.SelectedValue);
  72. DB.SaveChanges();
  73. }
  74. }
  75. }
  76. }
  77. private void Users_Click(object sender, RoutedEventArgs e)
  78. {
  79. FrameClass.MainFrame.Navigate(new Acount());
  80. }
  81. }
  82. public partial class MenuAdmin : Page
  83. {
  84. PP_MininEntities2 DB = new PP_MininEntities2();
  85. int id;
  86. public MenuAdmin()
  87. {
  88. InitializeComponent();
  89. ApplicationList.ItemsSource = DB.Applications.ToList();
  90. Applications appl = DB.Applications.Where(x => x.Id_status_app == id).FirstOrDefault();
  91. CB_Filter_app.ItemsSource = new List<string> { "Фильтр по статусу", "Выполнен", "Не выполнен" };
  92. CB_Sort_app.ItemsSource = new List<string>() { "Фильтр по дате", "Не сегодня", "Сегодня" };
  93. CB_Sort_app.SelectedIndex = 0;
  94. CB_Filter_app.SelectedIndex = 0;
  95. EventList.ItemsSource = DB.Event.ToList();
  96. Event evnt = DB.Event.Where(x => x.Id_event == id).FirstOrDefault();
  97. CB_Filter_event.ItemsSource = new List<string>() { "Фильтр по статусу", "Проведено", "Не проведено" };
  98. CB_Sort_event.ItemsSource = new List<string>() { "Фильтр по дате", "Не сегодня", "Сегодня" };
  99. CB_Sort_event.SelectedIndex = 0;
  100. CB_Filter_event.SelectedIndex = 0;
  101. }
  102. public MenuAdmin(int id)
  103. {
  104. InitializeComponent();
  105. ApplicationList.ItemsSource = DB.Applications.ToList();
  106. Applications appl = DB.Applications.Where(x => x.Id_application == id).FirstOrDefault();
  107. CB_Filter_app.ItemsSource = DB.Applications.ToList();
  108. CB_Sort_app.ItemsSource = DB.Applications.ToList();
  109. CB_Sort_app.SelectedIndex = 0;
  110. CB_Filter_app.SelectedIndex = 0;
  111. this.id = id;
  112. EventList.ItemsSource = DB.Event.ToList();
  113. Event evnt = DB.Event.Where(x => x.Id_event == id).FirstOrDefault();
  114. CB_Filter_event.ItemsSource = new List<string>();
  115. CB_Sort_event.ItemsSource = new List<string>();
  116. CB_Sort_event.SelectedIndex = 0;
  117. CB_Filter_event.SelectedIndex = 0;
  118. this.id = id;
  119. }
  120. private void Filter()
  121. {
  122. List<Applications> applications = DB.Applications.ToList();
  123. if (CB_Sort_app.SelectedIndex != 0)
  124. {
  125. switch (CB_Sort_app.SelectedIndex)
  126. {
  127. case 1:
  128. applications = applications.Where(x => x.Date_app < DateTime.Today).OrderBy(x => x.Date_app).ToList();
  129. break;
  130. case 2:
  131. applications = applications.Where(x => x.Date_app == DateTime.Today).OrderBy(x => x.Date_app).ToList();
  132. break;
  133. }
  134. }
  135. if (CB_Filter_app.SelectedIndex != 0)
  136. {
  137. switch (CB_Filter_app.SelectedIndex)
  138. {
  139. case 1:
  140. applications = applications.Where(x => x.Id_status_app == 1).ToList();
  141. break;
  142. case 2:
  143. applications = applications.Where(x => x.Id_status_app == 2).ToList();
  144. break;
  145. }
  146. }
  147. if (!string.IsNullOrEmpty(TB_Search_app.Text))
  148. {
  149. applications = applications.Where(x => x.Description.ToUpper().Contains(TB_Search_app.Text.ToUpper())).ToList();
  150. }
  151. ApplicationList.ItemsSource = applications;
  152. //Мероприятия
  153. List<Event> events = DB.Event.ToList();
  154. if (CB_Sort_event.SelectedIndex != 0)
  155. {
  156. switch (CB_Sort_event.SelectedIndex)
  157. {
  158. case 1:
  159. events = events.Where(x => x.Date_event < DateTime.Today).OrderBy(x => x.Date_event).ToList();
  160. break;
  161. case 2:
  162. events = events.Where(x => x.Date_event == DateTime.Today).OrderBy(x => x.Date_event).ToList();
  163. break;
  164. }
  165. }
  166. if (CB_Filter_event.SelectedIndex != 0)
  167. {
  168. switch (CB_Filter_event.SelectedIndex)
  169. {
  170. case 1:
  171. events = events.Where(x => x.Id_status_event == 1).ToList();
  172. break;
  173. case 2:
  174. events = events.Where(x => x.Id_status_event == 2).ToList();
  175. break;
  176. }
  177. }
  178. if (!string.IsNullOrEmpty(TB_Search_event.Text))
  179. {
  180. events = events.Where(x => x.Title_event.ToUpper().Contains(TB_Search_event.Text.ToUpper())).ToList();
  181. }
  182. EventList.ItemsSource = events;
  183. }
  184. private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
  185. {
  186. Filter();
  187. }
  188. private void SearchChanged(object sender, TextChangedEventArgs e)
  189. {
  190. Filter();
  191. }
  192. private void TB_Search_event_TextChanged(object sender, TextChangedEventArgs e)
  193. {
  194. Filter();
  195. }
  196. private void CB_Sort_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
  197. {
  198. Filter();
  199. }
  200. private void CB_Filter_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
  201. {
  202. Filter();
  203. }
  204. private void Exit_Click(object sender, RoutedEventArgs e)
  205. {
  206. FrameClass.MainFrame.Navigate(new Avtorization());
  207. }
  208. private void Profile_Click(object sender, RoutedEventArgs e)
  209. {
  210. FrameClass.MainFrame.Navigate(new Profile(user));
  211. }
  212. }
  213. }