/
PersonAccaunt.cs
209 lines (198 loc) · 7.33 KB
/
PersonAccaunt.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Phonebook_v2._2
{
class PersonAccaunt
{
#region Filds
string firstName;
string lastName;
string cityOfResidence;
uint postIndex;
string cityStreet;
uint numberOfHous;
uint apartmentNumber;
uint mobilPhone;
readonly string dateOfRegistration;
readonly string timeOfRegistration;
#endregion
#region Constructors
public PersonAccaunt(string name = "", string soname = "", string city = "", uint index = 0, string strt = "", uint hous = 0, uint kv = 0, uint phone = 0)
{
FirstName = name;
LastName = soname;
CityOfResidence = city;
PostIndex = index;
//PersonalID = ID;
CityStreet = strt;
NumberOfHous = hous;
ApartmentNumber = kv;
MobilPhone = phone;
dateOfRegistration = DateTime.Today.ToShortDateString();
timeOfRegistration = DateTime.Now.ToShortTimeString();
}
#endregion
#region Properties
public string FirstName
{
get { return firstName; }
set
{
if (!String.IsNullOrEmpty(value) && !String.IsNullOrWhiteSpace(value))
firstName = value;
else firstName = "unknown";
}
}
public string LastName
{
get { return lastName; }
set
{
if (!String.IsNullOrEmpty(value) && !String.IsNullOrWhiteSpace(value))
lastName = value;
else lastName = "unknown";
}
}
public string CityOfResidence
{
get { return cityOfResidence; }
set
{
if (!String.IsNullOrEmpty(value) && !String.IsNullOrWhiteSpace(value))
cityOfResidence = value;
else cityOfResidence = "unknown";
}
}
public uint PostIndex
{
get { return postIndex; }
set
{
if (value < 1000000) postIndex = value;
else postIndex = 0;
}
}
public string CityStreet
{
get { return cityStreet; }
set
{
if (!String.IsNullOrEmpty(value) && !String.IsNullOrWhiteSpace(value))
cityStreet = value;
else
cityStreet = "unknown";
}
}
public uint NumberOfHous
{
get { return numberOfHous; }
set
{
if (value < 150) numberOfHous = value;
else numberOfHous = 0;
}
}
public uint ApartmentNumber
{
get { return apartmentNumber; }
set
{
if (value < 500) apartmentNumber = value;
else apartmentNumber = 0;
}
}
public uint MobilPhone
{
get { return mobilPhone; }
set
{
if ((value > 100) & (value < 1000000000)) mobilPhone = value;
else mobilPhone = 0;
}
}
public string DateOfRegistration
{
get { return dateOfRegistration; }
}
public string TimeOfRegistration
{
get { return timeOfRegistration; }
}
#endregion
#region Methods
#region Method that Display Person Accaunt data on Console
/// <summary>
/// Method for displaying the current values of class fields
/// </summary>
/// <param name="p"></param>
public static void DisplayPersonAccaunt(PersonAccaunt p)
{
Console.Clear();
Console.WriteLine("----------------------------");
Console.WriteLine("First name : {0}", p.FirstName);
Console.WriteLine("Last name : {0}", p.LastName);
Console.WriteLine("City : {0}", p.CityOfResidence);
if (p.PostIndex == 0)
Console.WriteLine("Post index : unknown");
else
Console.WriteLine("Post index : {0}", p.PostIndex);
Console.WriteLine("Street : {0}", p.CityStreet);
if (p.NumberOfHous == 0)
Console.WriteLine("Hous : unknown");
else
Console.WriteLine("Hous : {0}", p.NumberOfHous);
if (p.ApartmentNumber == 0)
Console.WriteLine("Apartment : unknown");
else
Console.WriteLine("Apartment : {0}", p.ApartmentNumber);
if (p.MobilPhone == 0)
Console.WriteLine("Phone : unknown");
else
Console.WriteLine("Phone : +380{0}", p.MobilPhone);
Console.WriteLine("Time of registration : {0}", p.DateOfRegistration);
Console.WriteLine("Date of registration : {0}", p.TimeOfRegistration);
}
#endregion
#region WritePersonInFile
/// <summary>
/// Block of writing data to a file
/// </summary>
/// <param name="sb">temporary data storage</param>
/// <param name="phoneBookDirectory">The path to the file</param>
public void WritePersonInFile(StringBuilder sb, DirectoryInfo phoneBookDirectory)
{
sb.AppendLine("========================================");
sb.AppendLine("First name : " + FirstName);
sb.AppendLine("Last name : " + LastName);
sb.AppendLine("City : " + CityOfResidence);
if (PostIndex == 0)
sb.AppendLine("Post index : unknown");
else
sb.AppendLine("Post index : " + PostIndex);
sb.AppendLine("Street : " + CityStreet);
if (NumberOfHous == 0)
sb.AppendLine("Hous : unknown");
else
sb.AppendLine("Hous : " + NumberOfHous);
if (ApartmentNumber == 0)
sb.AppendLine("Apartment : unknown");
else
sb.AppendLine("Apartment : " + ApartmentNumber);
if (MobilPhone == 0)
sb.AppendLine("Phone : unknown");
else
sb.AppendLine("Phone : +380" + MobilPhone);
sb.AppendLine("Time of registration : " + DateOfRegistration);
sb.AppendLine("Date of registration : " + TimeOfRegistration);
foreach (var s in sb.ToString())
{
File.AppendAllText(Path.Combine(Convert.ToString(phoneBookDirectory), "phonebook.txt"), $"{s}");
}
sb.Clear();
}
#endregion
#endregion
}
}