VMTeacherAddViewModel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using MsBox.Avalonia;
  6. using MsBox.Avalonia.Enums;
  7. using N11_1.Models;
  8. using ReactiveUI;
  9. namespace N11_1.ViewModels
  10. {
  11. public class VMTeacherAddViewModel : ReactiveObject
  12. {
  13. string surname = "";
  14. string name = "";
  15. string patronomic = "";
  16. string mail = "";
  17. string phone = "";
  18. string workExpensive = "";
  19. DateTime dateofbirthd = DateTime.Now;
  20. bool gender = false;
  21. List<string> lesson = MainWindowViewModel.connection.TbLessons.Select(tb => tb.Name).ToList();
  22. List<string> selectedLesson = new List<string>();
  23. public string Surname { get => surname; set => surname = value; }
  24. public string Name { get => name; set => name = value; }
  25. public string Patronomic { get => patronomic; set => patronomic = value; }
  26. public bool GenderG { get => gender; set => gender = value; }
  27. public bool GenderM { get => !gender; set => gender = !value; }
  28. public string Mail { get => mail; set => mail = value; }
  29. public string Phone { get => phone; set => phone = value; }
  30. public string WorkExpensive { get => workExpensive; set => workExpensive = value; }
  31. public DateTimeOffset Dateofbirthd { get => new DateTimeOffset(dateofbirthd); set => dateofbirthd = value.DateTime; }
  32. public List<string> Lesson { get => lesson; set => lesson = value; }
  33. public List<string> SelectedLesson { get => selectedLesson; set => this.RaiseAndSetIfChanged(ref selectedLesson, value); }
  34. public string SelectedValueLesson
  35. {
  36. get => null;
  37. set
  38. {
  39. //ïðîâåðêà íà íàëè÷èå ýòîãî ýêçåìïëÿðà
  40. bool flag = SelectedLesson.Where(tb => tb == value).Count() == 0;
  41. if (flag)
  42. {
  43. selectedLesson.Add(value);
  44. SelectedLesson = new List<string>(selectedLesson);
  45. }
  46. }
  47. }
  48. public string DeleteValueLesson
  49. {
  50. get => null;
  51. set
  52. {
  53. del(value);
  54. }
  55. }
  56. private async void del(string value)
  57. {
  58. switch (await MessageBoxManager
  59. .GetMessageBoxStandard("Ïîäòâåðæäåíèå óäàëåíèÿ", "Âû äåéñòâèòåëüíî õîòèòå óäàëèòü äàííûé ýëåìåíò?\n(" + value + ")",
  60. ButtonEnum.YesNo).ShowAsync())
  61. {
  62. case ButtonResult.Yes:
  63. {
  64. if (selectedLesson.Count == 1)
  65. selectedLesson = new List<string>();
  66. else
  67. selectedLesson.Remove(value);
  68. SelectedLesson = new List<string>(selectedLesson);
  69. break;
  70. }
  71. default:
  72. {
  73. break;
  74. }
  75. }
  76. }
  77. public string add()
  78. {
  79. string result = "";
  80. Regex checkName = new Regex("^[A-ÿ,.'-]+$");//ïðîâåðêà èìåí
  81. Regex checkPhone = new Regex(@"^(\+?7|8)\d{10}$");//ïðîâåðêà òåëåôîíà
  82. Regex checkEmail = new Regex(@"^\S+@\S+\.\S+$");//ïðîâåðêà ïî÷òû
  83. Regex checkExpensive = new Regex(@"^\d+([\.\,]\d+)?$");//ïðîâåðêà ñòàæà
  84. if (string.IsNullOrWhiteSpace(Surname) || !checkName.IsMatch(Surname))
  85. {
  86. result += "\nÏîëå \"Ôàìèëèÿ\" ââåäåííî íåêîððåêòíî";
  87. }
  88. if (string.IsNullOrWhiteSpace(Name) || !checkName.IsMatch(Name))
  89. {
  90. result += "\nÏîëå \"Èìÿ\" ââåäåííî íåêîððåêòíî";
  91. }
  92. if (string.IsNullOrWhiteSpace(Patronomic) || !checkName.IsMatch(Patronomic))
  93. {
  94. result += "\nÏîëå \"Îò÷åñòâî\" ââåäåííî íåêîððåêòíî";
  95. }
  96. if (Dateofbirthd > DateTime.Now)
  97. {
  98. result += "\nÂûáðàííàÿ äàòà íåêîððåêòíà";
  99. }
  100. if (string.IsNullOrWhiteSpace(Mail) || !checkEmail.IsMatch(Mail))
  101. {
  102. result += "\nÏîëå \"Ïî÷òà\" ââåäåííî íåêîððåêòíî";
  103. }
  104. if (string.IsNullOrWhiteSpace(Phone) || !checkPhone.IsMatch(Phone))
  105. {
  106. result += "\nÏîëå \"Òåëåôîí\" ââåäåííî íåêîððåêòíî (+79999999999)";
  107. }
  108. if (string.IsNullOrWhiteSpace(WorkExpensive) || !checkExpensive.IsMatch(WorkExpensive))
  109. {
  110. result += "\nÏîëå \"Ñòàæ ðàáîòû\" ââåäåííî íåêîððåêòíî";
  111. }
  112. if (SelectedLesson.Count == 0)
  113. {
  114. result += "\nÂû íå âûáðàëè íè îäíîãî ïðåäìåòà";
  115. }
  116. return result;
  117. }
  118. }
  119. }