VWRegistr.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Rkis29.Model;
  9. using Rkis29.View;
  10. using System.Windows.Controls;
  11. using System.Windows;
  12. namespace Rkis29.ViewModel
  13. {
  14. public class VWRegistr : INotifyPropertyChanged
  15. {
  16. public event PropertyChangedEventHandler PropertyChanged;
  17. public void OnPropertyChanged([CallerMemberName] string prop = "")
  18. {
  19. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
  20. }
  21. private string _tbSupname; //текст бокс Фамилии
  22. public string TbSurname
  23. {
  24. get { return _tbSupname; }
  25. set { _tbSupname = value; OnPropertyChanged(); }
  26. }
  27. private string _tbName; //текс бокс Имени
  28. public string TbName
  29. {
  30. get { return _tbName; }
  31. set { _tbName = value; OnPropertyChanged(); }
  32. }
  33. private string _tbPatronomic; //текст бокс Отчества
  34. public string TbPatronomic
  35. {
  36. get { return _tbPatronomic; }
  37. set { _tbPatronomic = value; OnPropertyChanged(); }
  38. }
  39. private string _tbNumber; //текст бокс Номер телефона
  40. public string TbPhoneName
  41. {
  42. get { return _tbNumber; }
  43. set { _tbNumber = value; OnPropertyChanged(); }
  44. }
  45. private string _tbLogin; //текст бокс логина
  46. public string TbLogin
  47. {
  48. get { return _tbLogin; }
  49. set { _tbLogin = value; OnPropertyChanged(); }
  50. }
  51. private string _tbPassword; //текст бокс пароля
  52. public string TbPassword
  53. {
  54. get { return _tbPassword; }
  55. set { _tbPassword = value; OnPropertyChanged(); }
  56. }
  57. private RelayCommand _go_RegistrBt;
  58. public RelayCommand Go_RegistrBt
  59. {
  60. get
  61. {
  62. return _go_RegistrBt ?? new RelayCommand(obj =>
  63. {
  64. if (_tbSupname != null && _tbName != null && TbPatronomic != null && _tbNumber != null && _tbLogin != null && _tbPassword != null)
  65. {
  66. var _d = ModelPublic.GetContext().Person.Where(w => w.Logins == _tbLogin).FirstOrDefault(); //сравнение логинов для авторизации
  67. if (_d != null)
  68. {
  69. MessageBox.Show("Придумайте другой логин");
  70. }
  71. else
  72. {
  73. //сохранение результатов
  74. ModelPublic.GetContext().Person.Add(new Person() { SurnameP = _tbSupname, NameP = _tbName, PatronomycP = TbPatronomic, PhoneNumber = _tbNumber, Logins = _tbLogin, Passwords = _tbPassword });
  75. ModelPublic.GetContext().SaveChanges();
  76. OnPropertyChanged();
  77. MainWindow mainWindow = new MainWindow();
  78. mainWindow.Show();
  79. Window window = (Window)obj;
  80. window.Close();
  81. }
  82. }
  83. else
  84. {
  85. MessageBox.Show("Заполните все поля");
  86. }
  87. });
  88. }
  89. }
  90. }
  91. }