123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using MsBox.Avalonia;
- using MsBox.Avalonia.Enums;
- using N11_1.Models;
- using ReactiveUI;
- namespace N11_1.ViewModels
- {
- public class VMTeacherAddViewModel : ReactiveObject
- {
- string surname = "";
- string name = "";
- string patronomic = "";
- string mail = "";
- string phone = "";
- string workExpensive = "";
- DateTime dateofbirthd = DateTime.Now;
- bool gender = false;
- List<string> lesson = MainWindowViewModel.connection.TbLessons.Select(tb => tb.Name).ToList();
- List<string> selectedLesson = new List<string>();
- public string Surname { get => surname; set => surname = value; }
- public string Name { get => name; set => name = value; }
- public string Patronomic { get => patronomic; set => patronomic = value; }
- public bool GenderG { get => gender; set => gender = value; }
- public bool GenderM { get => !gender; set => gender = !value; }
- public string Mail { get => mail; set => mail = value; }
- public string Phone { get => phone; set => phone = value; }
- public string WorkExpensive { get => workExpensive; set => workExpensive = value; }
- public DateTimeOffset Dateofbirthd { get => new DateTimeOffset(dateofbirthd); set => dateofbirthd = value.DateTime; }
- public List<string> Lesson { get => lesson; set => lesson = value; }
- public List<string> SelectedLesson { get => selectedLesson; set => this.RaiseAndSetIfChanged(ref selectedLesson, value); }
- public string SelectedValueLesson
- {
- get => null;
- set
- {
- //ïðîâåðêà íà íàëè÷èå ýòîãî ýêçåìïëÿðà
- bool flag = SelectedLesson.Where(tb => tb == value).Count() == 0;
- if (flag)
- {
- selectedLesson.Add(value);
- SelectedLesson = new List<string>(selectedLesson);
- }
- }
- }
- public string DeleteValueLesson
- {
- get => null;
- set
- {
- del(value);
- }
- }
- private async void del(string value)
- {
- switch (await MessageBoxManager
- .GetMessageBoxStandard("Ïîäòâåðæäåíèå óäàëåíèÿ", "Âû äåéñòâèòåëüíî õîòèòå óäàëèòü äàííûé ýëåìåíò?\n(" + value + ")",
- ButtonEnum.YesNo).ShowAsync())
- {
- case ButtonResult.Yes:
- {
- if (selectedLesson.Count == 1)
- selectedLesson = new List<string>();
- else
- selectedLesson.Remove(value);
- SelectedLesson = new List<string>(selectedLesson);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- public string add()
- {
- string result = "";
- Regex checkName = new Regex("^[A-ÿ,.'-]+$");//ïðîâåðêà èìåí
- Regex checkPhone = new Regex(@"^(\+?7|8)\d{10}$");//ïðîâåðêà òåëåôîíà
- Regex checkEmail = new Regex(@"^\S+@\S+\.\S+$");//ïðîâåðêà ïî÷òû
- Regex checkExpensive = new Regex(@"^\d+([\.\,]\d+)?$");//ïðîâåðêà ñòàæà
- if (string.IsNullOrWhiteSpace(Surname) || !checkName.IsMatch(Surname))
- {
- result += "\nÏîëå \"Ôàìèëèÿ\" ââåäåííî íåêîððåêòíî";
- }
- if (string.IsNullOrWhiteSpace(Name) || !checkName.IsMatch(Name))
- {
- result += "\nÏîëå \"Èìÿ\" ââåäåííî íåêîððåêòíî";
- }
- if (string.IsNullOrWhiteSpace(Patronomic) || !checkName.IsMatch(Patronomic))
- {
- result += "\nÏîëå \"Îò÷åñòâî\" ââåäåííî íåêîððåêòíî";
- }
- if (Dateofbirthd > DateTime.Now)
- {
- result += "\nÂûáðàííàÿ äàòà íåêîððåêòíà";
- }
- if (string.IsNullOrWhiteSpace(Mail) || !checkEmail.IsMatch(Mail))
- {
- result += "\nÏîëå \"Ïî÷òà\" ââåäåííî íåêîððåêòíî";
- }
- if (string.IsNullOrWhiteSpace(Phone) || !checkPhone.IsMatch(Phone))
- {
- result += "\nÏîëå \"Òåëåôîí\" ââåäåííî íåêîððåêòíî (+79999999999)";
- }
- if (string.IsNullOrWhiteSpace(WorkExpensive) || !checkExpensive.IsMatch(WorkExpensive))
- {
- result += "\nÏîëå \"Ñòàæ ðàáîòû\" ââåäåííî íåêîððåêòíî";
- }
- if (SelectedLesson.Count == 0)
- {
- result += "\nÂû íå âûáðàëè íè îäíîãî ïðåäìåòà";
- }
- return result;
- }
- }
- }
|