MenuAdmin.xaml.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. }
  99. public partial class MenuAdmin : Page
  100. {
  101. PP_MininEntities DB = new PP_MininEntities();
  102. int id;
  103. public MenuAdmin()
  104. {
  105. InitializeComponent();
  106. ApplicationList.ItemsSource = DB.Applications.ToList();
  107. Applications appl = DB.Applications.Where(x => x.Id_status_app == id).FirstOrDefault();
  108. CB_Filter_app.ItemsSource = new List<string> { "Фильтр по статусу", "Выполнен", "Не выполнен" };
  109. CB_Sort_app.ItemsSource = new List<string>() { "Фильтр по дате", "Не сегодня", "Сегодня" };
  110. CB_Sort_app.SelectedIndex = 0;
  111. CB_Filter_app.SelectedIndex = 0;
  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. }
  119. public MenuAdmin(int id)
  120. {
  121. InitializeComponent();
  122. ApplicationList.ItemsSource = DB.Applications.ToList();
  123. Applications appl = DB.Applications.Where(x => x.Id_application == id).FirstOrDefault();
  124. CB_Filter_app.ItemsSource = DB.Applications.ToList();
  125. CB_Sort_app.ItemsSource = DB.Applications.ToList();
  126. CB_Sort_app.SelectedIndex = 0;
  127. CB_Filter_app.SelectedIndex = 0;
  128. this.id = id;
  129. EventList.ItemsSource = DB.Event.ToList();
  130. Event evnt = DB.Event.Where(x => x.Id_event == id).FirstOrDefault();
  131. CB_Filter_event.ItemsSource = new List<string>();
  132. CB_Sort_event.ItemsSource = new List<string>();
  133. CB_Sort_event.SelectedIndex = 0;
  134. CB_Filter_event.SelectedIndex = 0;
  135. this.id = id;
  136. }
  137. private void Filter()
  138. {
  139. List<Applications> applications = DB.Applications.ToList();
  140. if (CB_Sort_app.SelectedIndex != 0)
  141. {
  142. switch (CB_Sort_app.SelectedIndex)
  143. {
  144. case 1:
  145. applications = applications.Where(x => x.Date_app < DateTime.Today).OrderBy(x => x.Date_app).ToList();
  146. break;
  147. case 2:
  148. applications = applications.Where(x => x.Date_app == DateTime.Today).OrderBy(x => x.Date_app).ToList();
  149. break;
  150. }
  151. }
  152. if (CB_Filter_app.SelectedIndex != 0)
  153. {
  154. switch (CB_Filter_app.SelectedIndex)
  155. {
  156. case 1:
  157. applications = applications.Where(x => x.Id_status_app == 1).ToList();
  158. break;
  159. case 2:
  160. applications = applications.Where(x => x.Id_status_app == 2).ToList();
  161. break;
  162. }
  163. }
  164. if (!string.IsNullOrEmpty(TB_Search_app.Text))
  165. {
  166. applications = applications.Where(x => x.Description.ToUpper().Contains(TB_Search_app.Text.ToUpper())).ToList();
  167. }
  168. ApplicationList.ItemsSource = applications;
  169. //Мероприятия
  170. List<Event> events = DB.Event.ToList();
  171. if (CB_Sort_event.SelectedIndex != 0)
  172. {
  173. switch (CB_Sort_event.SelectedIndex)
  174. {
  175. case 1:
  176. events = events.Where(x => x.Date_event < DateTime.Today).OrderBy(x => x.Date_event).ToList();
  177. break;
  178. case 2:
  179. events = events.Where(x => x.Date_event == DateTime.Today).OrderBy(x => x.Date_event).ToList();
  180. break;
  181. }
  182. }
  183. if (CB_Filter_event.SelectedIndex != 0)
  184. {
  185. switch (CB_Filter_event.SelectedIndex)
  186. {
  187. case 1:
  188. events = events.Where(x => x.Id_status_event == 1).ToList();
  189. break;
  190. case 2:
  191. events = events.Where(x => x.Id_status_event == 2).ToList();
  192. break;
  193. }
  194. }
  195. if (!string.IsNullOrEmpty(TB_Search_event.Text))
  196. {
  197. events = events.Where(x => x.Title_event.ToUpper().Contains(TB_Search_event.Text.ToUpper())).ToList();
  198. }
  199. EventList.ItemsSource = events;
  200. }
  201. private void SortFilterChanged(object sender, SelectionChangedEventArgs e)
  202. {
  203. Filter();
  204. }
  205. private void SearchChanged(object sender, TextChangedEventArgs e)
  206. {
  207. Filter();
  208. }
  209. private void TB_Search_event_TextChanged(object sender, TextChangedEventArgs e)
  210. {
  211. Filter();
  212. }
  213. private void CB_Sort_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
  214. {
  215. Filter();
  216. }
  217. private void CB_Filter_event_SelectionChanged(object sender, SelectionChangedEventArgs e)
  218. {
  219. Filter();
  220. }
  221. private void Exit_Click(object sender, RoutedEventArgs e)
  222. {
  223. FrameClass.MainFrame.Navigate(new Avtorization());
  224. }
  225. private void Profile_Click(object sender, RoutedEventArgs e)
  226. {
  227. FrameClass.MainFrame.Navigate(new Profile(user));
  228. }
  229. }
  230. }