-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMainViewModel.cs
177 lines (156 loc) · 6.84 KB
/
MainViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
Copyright (c) 2015-2021 Developer Express Inc.
{*******************************************************************}
{ }
{ Developer Express Mobile UI for Xamarin.Forms }
{ }
{ }
{ Copyright (c) 2015-2021 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING }
{ CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{*******************************************************************}
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using DevExpress.Maui.Editors;
namespace EditorsGetStarted {
public class MainViewModel : NotificationObject {
BoxMode selectedBoxMode;
public BoxMode SelectedBoxMode {
get { return selectedBoxMode; }
set { SetProperty(ref selectedBoxMode, value); }
}
string notes = "";
public string Notes {
get { return notes; }
set { SetProperty(ref notes, value); }
}
bool notesHasError = false;
public bool NotesHasError {
get { return notesHasError; }
set { SetProperty(ref notesHasError, value); }
}
string email;
public string Email {
get { return email; }
set { SetProperty(ref email, value); }
}
bool emailHasError = false;
public bool EmailHasError {
get { return emailHasError; }
set { SetProperty(ref emailHasError, value); }
}
DateTime? birthDate;
public DateTime? BirthDate {
get { return birthDate; }
set { SetProperty(ref birthDate, value); }
}
bool birthDateHasError = false;
public bool BirthDateHasError {
get { return birthDateHasError; }
set { SetProperty(ref birthDateHasError, value); }
}
string phone;
public string Phone {
get { return phone; }
set { SetProperty(ref phone, value); }
}
bool phoneHasError = false;
public bool PhoneHasError {
get { return phoneHasError; }
set { SetProperty(ref phoneHasError, value); }
}
string login = "";
public string Login {
get { return login; }
set { SetProperty(ref login, value); }
}
bool loginHasError = false;
public bool LoginHasError {
get { return loginHasError; }
set { SetProperty(ref loginHasError, value); }
}
string password = "";
public string Password {
get { return password; }
set { SetProperty(ref password, value); }
}
bool passwordHasError = false;
public bool PasswordHasError {
get { return passwordHasError; }
set { SetProperty(ref passwordHasError, value); }
}
public IList<BoxMode> BoxModes { get; }
public MainViewModel() {
BoxModes = new List<BoxMode> {
BoxMode.Outlined,
BoxMode.Filled
};
SelectedBoxMode = BoxModes[0];
}
public bool Validate() {
EmailHasError = string.IsNullOrEmpty(Email);
LoginHasError = string.IsNullOrEmpty(Login);
PasswordHasError = !CheckPassword();
BirthDateHasError = BirthDate == null;
PhoneHasError = Phone == null || Phone.Length != 10;
NotesHasError = Notes.Length > 100;
return !(NotesHasError || PhoneHasError || EmailHasError || LoginHasError || PasswordHasError);
}
bool CheckPassword() {
return Regex.IsMatch(password, @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{5,}$");
}
}
public class NotificationObject : INotifyPropertyChanged {
protected bool SetProperty<T>(ref T backingStore, T value, Action onChanged = null, [CallerMemberName] string propertyName = "") {
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
backingStore = value;
onChanged?.Invoke();
OnPropertyChanged(propertyName);
return true;
}
protected bool SetProperty<T>(ref T backingStore, T value, Action<T, T> onChanged, [CallerMemberName] string propertyName = "") {
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
T oldValue = backingStore;
backingStore = value;
onChanged?.Invoke(oldValue, value);
OnPropertyChanged(propertyName);
return true;
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "") {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}