MenuAdmin.xaml.cs 9.4 KB

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