Page_ResultAddEdit.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using MedicallCenter;
  2. using MedicallCenter.Clasees;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.Entity.Migrations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace MedicalCenter.Pages
  20. {
  21. /// <summary>
  22. /// Логика взаимодействия для Result.xaml
  23. /// </summary>
  24. public partial class Page_ResultAddEdit : Page
  25. {
  26. private Result currentresult = new Result();
  27. public Page_ResultAddEdit(Result currentresult2)
  28. {
  29. InitializeComponent();
  30. currentresult = currentresult2;
  31. ComboUser112.ItemsSource = CurrentData.db.User.ToList();
  32. ComboWorker.ItemsSource = CurrentData.db.Worker.ToList();
  33. ComboService.ItemsSource = CurrentData.db.Service.ToList();
  34. if (currentresult.id != 0)
  35. {
  36. InputData();
  37. btnEditResult.Visibility = Visibility.Visible;
  38. }
  39. }
  40. private void btnBack_Click(object sender, RoutedEventArgs e)
  41. {
  42. Manager.frame.Navigate(new Page_Result());
  43. }
  44. private void InputData()
  45. {
  46. ComboUser112.Text = currentresult.User.name;
  47. ComboWorker.Text = currentresult.Worker.name;
  48. ComboService.Text = currentresult.Service.service1;
  49. ComboResultResult.Text = currentresult.result1;
  50. tbDateResult.Text = currentresult.date;
  51. }
  52. private void btnEditSecodnResult_Click(object sender, RoutedEventArgs e)
  53. {
  54. if (GetData())
  55. {
  56. CurrentData.db.Result.AddOrUpdate(currentresult);
  57. SaveChang();
  58. MessageBox.Show("Запись успешно добавлена");
  59. btnEditResult.Visibility = Visibility.Visible;
  60. }
  61. }
  62. private bool GetData()
  63. {
  64. StringBuilder stringBuilder = new StringBuilder();
  65. if (ComboUser112.SelectedItem == null)
  66. stringBuilder.Append("Заполните поле Пациент: пусто\n");
  67. if (ComboWorker.SelectedItem == null)
  68. stringBuilder.Append("Заполните поле Работник: пусто\n");
  69. if (ComboService.SelectedItem == null)
  70. stringBuilder.Append("Заполните поле Услуга: пусто\n");
  71. if (ComboResultResult.Text == "")
  72. stringBuilder.Append("Заполните поле Результат: пусто\n");
  73. if (tbDateResult.Text == "")
  74. stringBuilder.Append("Заполните поле Дата: пусто\n");
  75. if (stringBuilder.ToString() == "")
  76. {
  77. currentresult.id_user = CurrentData.users.FirstOrDefault(x => x.name == ComboUser112.Text).id;
  78. currentresult.id_lab = CurrentData.workers.FirstOrDefault(x => x.name == ComboWorker.Text).id;
  79. currentresult.id_service = CurrentData.services.FirstOrDefault(x => x.service1 == ComboService.Text).id;
  80. currentresult.result1 = ComboResultResult.Text;
  81. currentresult.date = tbDateResult.Text;
  82. return true;
  83. }
  84. MessageBox.Show(stringBuilder.ToString());
  85. return false;
  86. }
  87. private void SaveChang()
  88. {
  89. CurrentData.db.SaveChanges();
  90. }
  91. private void bntAddResult_Click(object sender, RoutedEventArgs e)
  92. {
  93. if (GetData())
  94. {
  95. CurrentData.db.Result.Add(currentresult);
  96. SaveChang();
  97. MessageBox.Show("Запись успешно добавлена");
  98. Manager.frame.Navigate(new Page_Result());
  99. }
  100. }
  101. private void btnEditResult_Click(object sender, RoutedEventArgs e)
  102. {
  103. if (GetData())
  104. {
  105. CurrentData.db.Result.AddOrUpdate(currentresult);
  106. SaveChang();
  107. MessageBox.Show("Запись успешно отредактирована");
  108. Manager.frame.Navigate(new Page_Result());
  109. }
  110. }
  111. private void btnPrint_Click(object sender, RoutedEventArgs e)
  112. {
  113. }
  114. }
  115. }