-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.cs
More file actions
132 lines (107 loc) · 3.55 KB
/
Customer.cs
File metadata and controls
132 lines (107 loc) · 3.55 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace DataGridValidationDemo
{
/// <summary>
/// A list of customers.
/// </summary>
public class Customer : INotifyDataErrorInfo
{
#region Field & Object Definitions
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
private List<string> errors = new List<string>();
#endregion
#region Property Definitions
public String FirstName { get; set; }
public String LastName { get; set; }
public String Address { get; set; }
public Boolean IsNew { get; set; }
public bool HasErrors
{
get
{
if (this.LastName.Contains("Smith"))
return true;
return false;
}
}
#endregion
#region Methods
/// <summary>
/// Class constructor.
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <param name="address"></param>
/// <param name="isNew"></param>
public Customer(String firstName, String lastName, String address, Boolean isNew)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Address = address;
this.IsNew = isNew;
}
/// <summary>
/// Class default constructor
/// </summary>
public Customer() { }
/// <summary>
/// Initialize the customer list.
/// </summary>
/// <returns></returns>
public static List<Customer> Customers()
{
return new List<Customer>(new Customer[4]
{
new Customer("A.", "Zero", "12 North Third Street, Apartment 45", false),
new Customer("B.", "One", "34 West Fifth Street, Apartment 67", false),
new Customer("C.", "Two", "56 East Seventh Street, Apartment 89", true),
new Customer("D.", "Three", "78 South Ninth Street, Apartment 10", true)
}
);
}
/// <summary>
/// Gets the errors associated with this validation.
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public System.Collections.IEnumerable GetErrors(string propertyName)
{
if (propertyName == null) return null;
if (!propertyName.Equals("LastName"))
return null;
if (this.LastName.Contains("Smith"))
{
errors.Add("Smith is not a valid Name" + this.LastName);
// OnErrorsChanged(this.LastName);
}
return errors;
}
#endregion
#region Event Handlers
/// <summary>
/// Handles the ErrosChanged event.
/// </summary>
/// <param name="propertyName"></param>
private void OnErrorsChanged(string propertyName)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
#endregion
}
public class ViewModel
{
private List<Customer> customers = new List<Customer>();
public List<Customer> Customers
{
get { return customers; }
set { customers = value; }
}
public ViewModel()
{
this.Customers = new List<Customer>(Customer.Customers());
}
}
}