AddRemovePage.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Shapes;
  14. namespace PsychoTest.Pages
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для AddRemovePage.xaml
  18. /// </summary>
  19. public partial class AddRemovePage : Window
  20. {
  21. public PsychoBase DB = new PsychoBase();
  22. public Users user = new Users();
  23. public int psId;
  24. public AddRemovePage(int psId)
  25. {
  26. InitializeComponent();
  27. PatientList.ItemsSource = DB.Users.Where(x=>x.Id_role==2).ToList();
  28. this.psId = psId;
  29. }
  30. private void AddPatient(object sender, RoutedEventArgs e)
  31. {
  32. CheckBox cb = (CheckBox)sender;
  33. int id = Convert.ToInt32(cb.Uid);
  34. user = DB.Users.Where(x=>x.User_id == id).FirstOrDefault();
  35. if(user.Id_doctor != psId)
  36. {
  37. user.Id_doctor = psId;
  38. DB.SaveChanges();
  39. MainFrame.frame.Navigate(new PsychoPage(psId));
  40. }
  41. }
  42. private void RemovePatient(object sender, RoutedEventArgs e)
  43. {
  44. CheckBox cb = (CheckBox)sender;
  45. int id = Convert.ToInt32(cb.Uid);
  46. user = DB.Users.Where(x => x.User_id == id).FirstOrDefault();
  47. if (user.Id_doctor == psId)
  48. {
  49. user.Id_doctor = null;
  50. DB.SaveChanges();
  51. MainFrame.frame.Navigate(new PsychoPage(psId));
  52. }
  53. }
  54. private void FullnameLoad(object sender, RoutedEventArgs e)
  55. {
  56. TextBlock tb = (TextBlock)sender;
  57. int id = Convert.ToInt32(tb.Uid);
  58. tb.Text = DB.Users.Where(x => x.User_id == id).Select(x => x.Surname).FirstOrDefault() + " "
  59. + DB.Users.Where(x => x.User_id == id).Select(x => x.Name).FirstOrDefault() + " "
  60. + DB.Users.Where(x => x.User_id == id).Select(x => x.Patronymic).FirstOrDefault();
  61. }
  62. private void CheckBoxLoad(object sender, RoutedEventArgs e)
  63. {
  64. CheckBox cb = (CheckBox)sender;
  65. int id = Convert.ToInt32(cb.Uid);
  66. if (DB.Users.Where(x=>x.User_id == id).Select(x=>x.Id_doctor).FirstOrDefault() == psId)
  67. {
  68. cb.IsChecked = true;
  69. }
  70. else
  71. {
  72. cb.IsChecked = false;
  73. }
  74. }
  75. }
  76. }