Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
Competition.cs
1using CommunityToolkit.Mvvm.ComponentModel;
4
6{
10 public partial class Competition : ObservableObject, IEquatable<Competition>, ICloneable
11 {
12 #region Constructors
13
17 public Competition()
18 {
19 }
20
25 public Competition(Competition other) : this()
26 {
27 if (other == null) { return; }
28 this.Id = other.Id;
29 this.Gender = other.Gender;
30 this.SwimmingStyle = other.SwimmingStyle;
31 this.Age = other.Age;
32 this.Distance = other.Distance;
33 this.BestTime = other.BestTime;
34 this.IsTimeFromRudolphTable = other.IsTimeFromRudolphTable;
35 this.IsTimeInterpolatedFromRudolphTable = other.IsTimeInterpolatedFromRudolphTable;
36 this.IsOpenAgeTimeFromRudolphTable = other.IsOpenAgeTimeFromRudolphTable;
37 }
38
39 #endregion
40
41 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
43 #region Basic properties
44
45 private int _id = 0;
49 [FileServiceOrder]
50 public int Id
51 {
52 get => _id;
53 set => SetProperty(ref _id, value);
54 }
55
56 private Genders _gender;
60 [FileServiceOrder]
62 {
63 get => _gender;
64 set => SetProperty(ref _gender, value);
65 }
66
67 private SwimmingStyles _swimmingStyle;
71 [FileServiceOrder]
73 {
74 get => _swimmingStyle;
75 set => SetProperty(ref _swimmingStyle, value);
76 }
77
78 private byte _age = 0;
82 [FileServiceOrder]
83 public byte Age
84 {
85 get => _age;
86 set => SetProperty(ref _age, value);
87 }
88
89 private TimeSpan _bestTime;
93 [FileServiceOrder]
94 public TimeSpan BestTime
95 {
96 get => _bestTime;
97 set
98 {
99 if (SetProperty(ref _bestTime, value))
100 {
104 }
105 }
106 }
107
108 private bool _isTimeFromRudolphTable = false;
113 [FileServiceOrder]
115 {
116 get => _isTimeFromRudolphTable;
117 set => SetProperty(ref _isTimeFromRudolphTable, value);
118 }
119
120 private bool _isTimeInterpolatedFromRudolphTable = false;
125 [FileServiceOrder]
127 {
128 get => _isTimeInterpolatedFromRudolphTable;
129 set => SetProperty(ref _isTimeInterpolatedFromRudolphTable, value);
130 }
131
132 private bool _isOpenAgeTimeFromRudolphTable = false;
137 [FileServiceOrder]
139 {
140 get => _isOpenAgeTimeFromRudolphTable;
141 set => SetProperty(ref _isOpenAgeTimeFromRudolphTable, value);
142 }
143
144 private ushort _distance = 0;
148 [FileServiceIgnore]
149 public ushort Distance
150 {
151 get => _distance;
152 set
153 {
154 if (SetProperty(ref _distance, value))
155 {
158 OnPropertyChanged(nameof(IsDistanceValid));
159 }
160 }
161 }
162
166 [FileServiceIgnore]
167 public bool IsDistanceValid => Distance > 0;
168
169 #endregion
170
171 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172
173 #region Other properties
174
175 private bool _hasDuplicates = false;
180 [FileServiceIgnore]
181 public bool HasDuplicates
182 {
183 get => _hasDuplicates;
184 set => SetProperty(ref _hasDuplicates, value);
185 }
186
187 #endregion
188
189 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
190
191 #region SetPropertyFromString helper
192
199 public static void SetPropertyFromString(Competition dataObj, string propertyName, string value)
200 {
201 switch (propertyName)
202 {
203 case nameof(Id): dataObj.Id = int.Parse(value); break;
204 case nameof(Gender): if (EnumCoreLocalizedStringHelper.TryParse(value, out Genders parsedGender)) { dataObj.Gender = parsedGender; } break;
205 case nameof(SwimmingStyle): if (EnumCoreLocalizedStringHelper.TryParse(value, out SwimmingStyles parsedStyle)) { dataObj.SwimmingStyle = parsedStyle; } break;
206 case nameof(Age): dataObj.Age = byte.Parse(value); break;
207 case nameof(BestTime): dataObj.BestTime = TimeSpan.Parse(value); break;
208 case nameof(IsTimeFromRudolphTable): dataObj.IsTimeFromRudolphTable = !string.IsNullOrEmpty(value); break;
209 case nameof(IsTimeInterpolatedFromRudolphTable): dataObj.IsTimeInterpolatedFromRudolphTable = !string.IsNullOrEmpty(value); break;
210 case nameof(IsOpenAgeTimeFromRudolphTable): dataObj.IsOpenAgeTimeFromRudolphTable = !string.IsNullOrEmpty(value); break;
211 default: break;
212 }
213 }
214
215 #endregion
216
217 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
218
219 #region Equality, HashCode, ToString, Clone
220
226 public override bool Equals(object obj)
227 => obj is Competition c && (c.Id, c.Gender, c.SwimmingStyle, c.Age, c.BestTime, c.IsTimeFromRudolphTable, c.IsTimeInterpolatedFromRudolphTable, c.IsOpenAgeTimeFromRudolphTable).Equals((Id, Gender, SwimmingStyle, Age, BestTime, IsTimeFromRudolphTable, IsTimeInterpolatedFromRudolphTable, IsOpenAgeTimeFromRudolphTable));
228
234 public bool Equals(Competition other)
235 => Equals((object)other);
236
243 public override int GetHashCode()
244 => base.GetHashCode();
245 //=> (Id, Gender, SwimmingStyle, Age, BestTime, IsTimeFromRudolphTable, IsTimeInterpolatedFromRudolphTable, IsOpenAgeTimeFromRudolphTable).GetHashCode();
246
251 public override string ToString()
252 => $"{Id}: {Distance}m {SwimmingStyle} {Gender} (Age: {Age}{(IsTimeFromRudolphTable ? ", from rudolph table" : "")}{(IsOpenAgeTimeFromRudolphTable ? " (open age)" : "")}{(IsTimeInterpolatedFromRudolphTable ? ", interpolated from rudolph table" : "")})";
253
258 public object Clone()
259 => new Competition(this);
260
261 #endregion
262 }
263}
override int GetHashCode()
Serves as the default hash function.
override bool Equals(object obj)
Compare if two Competitions are equal.
Genders Gender
Gender for this competition.
bool Equals(Competition other)
Indicates wheather the current object is equal to another object of the same type.
bool IsOpenAgeTimeFromRudolphTable
True, when the BestTime was the open age value taken from the RudolphTable.
ushort Distance
Distance in meters for this competition (e.g.
SwimmingStyles SwimmingStyle
Swimming style for this competition.
bool HasDuplicates
This flag indicates if there are duplicates of this in the competition list.
TimeSpan BestTime
Time for this competition to reach the maximum points.
byte Age
Age for the person that is assigned for this competition.
bool IsTimeInterpolatedFromRudolphTable
True, when the BestTime was an interpolated value based on the competitions with IsTimeFromRudolphTab...
static void SetPropertyFromString(Competition dataObj, string propertyName, string value)
Set the requested property in the Competition object by parsing the given string value.
bool IsTimeFromRudolphTable
True, when the BestTime was the value taken from the RudolphTable.
bool IsDistanceValid
Only true when the Distance is greater 0.
Competition()
Constructor for a new Competition object.
Competition(Competition other)
Clone constructor for a Competition object.
override string ToString()
Returns a string that represents the current object.
object Clone()
Create a new object that has the same property values than this one.
SwimmingStyles
Available swimming styles.
Genders
Available genders for a person.
Definition Genders.cs:7