-
Notifications
You must be signed in to change notification settings - Fork 0
/
Employee.cs
142 lines (118 loc) · 3.95 KB
/
Employee.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
using System.ComponentModel.Design;
using System.Net;
using System.Text.RegularExpressions;
namespace Mammoth_Cave_Quick_Trippin_;
public class Employee
{
static List<Employee> _employees = new List<Employee>();
public Employee() { }
public Employee(int id)
{
Id = id;
}
public Employee(int id, string firstName, string lastName, string title, int store)
{
Id = id;
FirstName = firstName;
LastName = lastName;
Title = title;
StoreNumber = store;
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public double Sales { get; set; }
public int StoreNumber { get; set; }
//public string District { get; set; }
public List<Employee> Employees { get; set; }
/*---------------//valid number--------------------*/
public int NumberValidation(string input)
{
int ValidNumber = 0;
bool isInvalid, isOutOfRange;
//bool isInvalid, isOutOfRange, IsOnlyDigits;
isOutOfRange = true;
//IsOnlyDigits = true;
do
{
//if(IsOnlyDigits) {
//foreach (char c in input)
//{
// if (!Char.IsDigit(c))
// input = "";
// Console.Write("Please enter a valid Number valuemmmm: #");
// input = Console.ReadLine();
//}
//}
isInvalid = !int.TryParse(input, out ValidNumber);
if (!isInvalid)
{
isOutOfRange = (ValidNumber < 1 || ValidNumber > 1000);
}
if (isInvalid)
{
Console.Write("Please enter a valid Number value: #");
input = Console.ReadLine();
}
else if (isOutOfRange)
{
Console.Write("Please enter value between 1 and 1000: #");
input = Console.ReadLine();
}
} while (isInvalid || isOutOfRange);
//} while (isInvalid || isOutOfRange || IsOnlyDigits);
return ValidNumber;
}
/*---------------//valid string--------------------*/
public string StringValidation(string input)
{
bool isValid;
do
{
isValid = true;
if (string.IsNullOrEmpty(input))
{
isValid = false;
Console.Write("Name cannot be blank: ");
input = Console.ReadLine();
}
if (isValid)
{
////process 1
isValid = Regex.IsMatch(input, @"^[a-zA-Z]+$");
if (!isValid)
{
input = "";
Console.Write("just contain characters Please enter a valid value: ");
input = Console.ReadLine();
}
//process 2
//foreach (char c in input)
//{
// if (!Char.IsLetter(c))
// {
// isValid = false;
// input = "";
// Console.Write("just contain characters Please enter a valid value: ");
// input = Console.ReadLine();
// break;
// }
//}
}
} while (!isValid);
return input;
}
/*---------------//remove an employee--------------------*/
public void RemoveEmployee(int input)
{
//Employee _employees;
Console.Write("Enter Employee Id to remove: ");
input = int.Parse(Console.ReadLine());
Employee foundEmployeet = _employees.FirstOrDefault(d => d.Id == input);
_employees.Remove(foundEmployeet);
Console.WriteLine($"Employee #{input} was removed from database.");
Console.Write("Press enter to exit.");
Console.ReadLine();
}
}