/
Note.cs
223 lines (199 loc) · 4.93 KB
/
Note.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using diNo.diNoDataSetTableAdapters;
using System;
namespace diNo
{
/// <summary>
/// Typ einer Note.
/// </summary>
public enum Notentyp
{
/// <summary>
/// Default
/// </summary>
NONE = 0,
/// <summary>
/// Schulaufgabe.
/// </summary>
Schulaufgabe = 1,
/// <summary>
/// Kurzarbeit
/// </summary>
Kurzarbeit = 2,
/// <summary>
/// Ex.
/// </summary>
Ex = 3,
/// <summary>
/// Echte mündliche Note.
/// </summary>
EchteMuendliche = 4,
/// <summary>
/// Fachreferat.
/// </summary>
Fachreferat = 5, // TODO: 5-7 raus, wenn AlteFOBOSO raus
/// <summary>
/// Seminararfach.
/// </summary>
Seminarfach = 6,
/// <summary>
/// Ersatzprüfung.
/// </summary>
Ersatzprüfung = 7,
/// <summary>
/// Schriftliche Abschlussprüfung.
/// </summary>
APSchriftlich = 8,
/// <summary>
/// Mündliche Abschlussprüfung.
/// </summary>
APMuendlich = 9
}
/// <summary>
/// Enumeration fuer Halbjahre. Bitte Nummern nicht ändern (die werden so in die Datenbank als int gecasted).
/// </summary>
public enum Halbjahr
{
/// <summary>
/// Keine Zuordnung zu einem Halbjahr möglich.
/// </summary>
Ohne = 0,
/// <summary>
/// Erstes Halbjahr.
/// </summary>
Erstes = 1,
/// <summary>
/// Zweites Halbjahr.
/// </summary>
Zweites = 2
}
/// <summary>
/// Enumeration für Zeitpunkte zur Standspeicherung und Überprüfung der Notenkonsistenzen
/// Bitte Nummern nicht ändern (die werden so in die Datenbank als int gecasted).
/// </summary>
public enum Zeitpunkt
{
None = 0,
ProbezeitBOS = 1,
HalbjahrUndProbezeitFOS = 2,
ErstePA = 3,
ZweitePA = 4,
DrittePA = 5,
Jahresende = 6
}
/// <summary>
/// Eine Note.
/// </summary>
public class Note
{
private int kursid, schuelerid;
private diNoDataSet.NoteRow row;
// baut Notenobjekt aus einer DB-Zeile auf
public Note(diNoDataSet.NoteRow nr)
{
kursid = nr.KursId;
schuelerid = nr.SchuelerId;
Typ = (Notentyp)nr.Notenart;
Punktwert = nr.Punktwert;
Datum = nr.Datum;
Zelle = nr.Zelle;
Halbjahr = (Halbjahr)nr.Halbjahr;
row = nr;
}
// Note von Hand eingeben (z.B. aus Excel)
public Note(int aKursId, int aSchuelerId)
{
this.kursid = aKursId;
this.schuelerid = aSchuelerId;
}
/// <summary>
/// Der Typ der Note, z. B. Schulaufgabe oder Ex.
/// </summary>
public Notentyp Typ
{
get;
set;
}
/// <summary>
/// Der Punktwert der Note (0-15).
/// </summary>
public byte Punktwert
{
get;
set;
}
/// <summary>
/// Das Datum der Note.
/// </summary>
public DateTime Datum
{
get;
set;
}
/// <summary>
/// In welcher Zelle diese Note steht.
/// </summary>
public string Zelle
{
get;
set;
}
/// <summary>
/// Das Halbjahr, welchem die Note zuzuordnen ist.
/// </summary>
public Halbjahr Halbjahr
{
get;
set;
}
// schreibt ein Notenobjekt in die DB
public void writeToDB()
{
NoteTableAdapter na = new NoteTableAdapter();
if (row == null)
{
int noteid;
na.Insert((int)Typ, Punktwert, DateTime.Now.Date, Zelle, (byte)Halbjahr, schuelerid, kursid, out noteid);
row = na.GetDataById(noteid)[0]; // todo: testen ob das so auch wirklich geht, d.h. steht in noteId tatsächlich die ID der Note nach dem Insert?
}
else
{
row.Datum = this.Datum;
row.Halbjahr = (byte)this.Halbjahr;
row.KursId = this.kursid;
row.Notenart = (int)this.Typ;
row.Punktwert = this.Punktwert;
row.SchuelerId = this.schuelerid;
na.Update(row);
}
}
}
public static class Notentools
{
public static decimal Aufrunden2NK(decimal schnitt)
{
return Math.Ceiling(schnitt * 100) / 100;
}
public static byte RundeJF(decimal schnitt)
{
if (schnitt < 1)
return 0;
else
return (byte)Math.Round((double)schnitt, 0, MidpointRounding.AwayFromZero);
}
public static byte BerechneZeugnisnote(decimal? jf, decimal? sap, decimal? map)
{
decimal abi;
// bei externen ist jf==null
if (jf != null && map == null && sap == null) return RundeJF(jf.GetValueOrDefault());
if (map == null) abi = sap.GetValueOrDefault();
else if (sap == null) abi = map.GetValueOrDefault();
else abi = Aufrunden2NK((2 * sap.GetValueOrDefault() + map.GetValueOrDefault()) / 3);
if (jf == null) return RundeJF(abi);
else return RundeJF(Aufrunden2NK((jf.GetValueOrDefault() + abi) / 2));
}
public static byte BerechneAbiGes(int sap, int map)
{
return RundeJF((2 * sap + map) / (decimal)3);
}
}
}