1
+ from datetime import date
2
+
3
+ from PyQt5 .QtWidgets import (QWidget ,
4
+ QGridLayout ,
5
+ QLabel ,
6
+ QComboBox ,
7
+ QPushButton ,
8
+ QDoubleSpinBox ,
9
+ QMessageBox )
10
+
11
+ from QueryTool import QueryTool
12
+
13
+ einheiten = ("sec" , "sec" , "sec" , "min" , "m" , "m" , "cm,V" ,"m" , "m" , "m" )
14
+ felderzahl = (1 , 1 , 1 , 1 , 3 , 3 , 3 , 3 , 3 , 3 ) #Anzahl
15
+
16
+ def getDisziplin (alter :int )-> str :
17
+ if alter < 12 :
18
+ yield "50m Sprint"
19
+ yield "60m Hürdenlauf"
20
+ elif alter < 14 :
21
+ yield "75m Sprint"
22
+ yield "80m Hürdenlauf"
23
+ else :
24
+ yield "100m Sprint"
25
+ yield "80m Hürdenlauf"
26
+
27
+ if alter < 10 :
28
+ yield "-"
29
+ else :
30
+ yield "200m Lauf"
31
+
32
+ if alter < 10 :
33
+ yield "400m Lauf"
34
+ else :
35
+ yield "800m Lauf"
36
+
37
+ yield "Weitsprung"
38
+ yield "Stabweitsprung"
39
+ if alter < 10 :
40
+ yield "-"
41
+ else :
42
+ yield "Hochsprung"
43
+ yield "Reifenweitwurf"
44
+ yield "Weitwurf"
45
+ yield "Kugelstoßen"
46
+
47
+ class ErgebnissListe (QWidget ):
48
+ template = "<tr><td>Eintrag von </td><td>{: >20}</td><td>in der Disziplin {:<15} </td><td>{}erfolgreich {}</td></tr>"
49
+ def __init__ (self ,parent = None ):
50
+ super (ErgebnissListe , self ).__init__ (parent )
51
+
52
+ self .auswahlAlter = QComboBox ()
53
+ self .auswahlAlter .addItem ("Bitte auswählen" )
54
+ for i in range (3 ,18 ):
55
+ self .auswahlAlter .addItem ("{} Jahre / Jahrgang {}" .format (i , date .today ().year - i ))
56
+ self .auswahlAlter .activated .connect (self .auswahlKlasse )
57
+ self .auswahlAlter .activated .connect (self .waehleDisziplinen )
58
+
59
+ self .auswahlGeschlecht = QComboBox ()
60
+ self .auswahlGeschlecht .addItem ("Bitte auswählen" )
61
+ self .auswahlGeschlecht .addItem ("Männlich" )
62
+ self .auswahlGeschlecht .addItem ("Weiblich" )
63
+ self .auswahlGeschlecht .activated .connect (self .auswahlKlasse )
64
+ self .auswahlGeschlecht .activated .connect (self .waehleDisziplinen )
65
+
66
+ self .auswahlDisziplin = QComboBox ()
67
+ self .auswahlDisziplin .addItem ("Bitte auswählen" )
68
+ for i in getDisziplin (10 ):
69
+ self .auswahlDisziplin .addItem (i )
70
+ self .auswahlDisziplin .activated .connect (self .auswahlKlasse )
71
+
72
+ self .mainLayout = QGridLayout ()
73
+ self .mainLayout .addWidget (QLabel ("Alter:" ), 0 , 0 )
74
+ self .mainLayout .addWidget (self .auswahlAlter , 0 , 1 , 1 , 3 )
75
+ self .mainLayout .addWidget (QLabel ("Geschlecht:" ), 1 , 0 )
76
+ self .mainLayout .addWidget (self .auswahlGeschlecht , 1 , 1 , 1 , 3 )
77
+ self .mainLayout .addWidget (QLabel ("Disziplin:" ), 2 , 0 )
78
+ self .mainLayout .addWidget (self .auswahlDisziplin , 2 , 1 , 1 , 3 )
79
+
80
+ self ._speichern = QPushButton ("Speichern" )
81
+ self ._speichern .clicked .connect (self .speichern )
82
+
83
+ self .setLayout (self .mainLayout )
84
+
85
+ self ._sportler = []
86
+
87
+ self .update ()
88
+
89
+ def waehleDisziplinen (self ):
90
+ self .auswahlDisziplin .clear ()
91
+ self .auswahlDisziplin .addItem ("Bitte auswählen" )
92
+ for i in getDisziplin (self .auswahlAlter .currentIndex ()+ 2 ):
93
+ self .auswahlDisziplin .addItem (i )
94
+
95
+
96
+ def auswahlKlasse (self ):
97
+ if self .auswahlAlter .currentIndex () == 0 :
98
+ return False
99
+ elif self .auswahlGeschlecht .currentIndex () == 0 :
100
+ return False
101
+ elif self .auswahlDisziplin .currentIndex () == 0 :
102
+ return False
103
+
104
+ self .clearAuswahl ()
105
+
106
+ disziplin = self .auswahlDisziplin .currentIndex ()- 1
107
+ if self .auswahlDisziplin .currentText () is "-" :
108
+ return
109
+
110
+ for sportler in QueryTool ().queryAndFetch ("SELECT ID, Name, Vorname FROM LG_NGD WHERE WieAlt = ? AND Geschlecht = ?" ,
111
+ self .auswahlAlter .currentIndex ()+ 2 ,
112
+ bool (self .auswahlGeschlecht .currentIndex ()- 1 )):
113
+ self ._sportler += [sportler [0 ]]
114
+ name = "{} {}" .format (sportler [2 ],sportler [1 ])
115
+ #UID, Name
116
+
117
+ for werte in reversed (QueryTool ().queryAndFetch ("SELECT Wert1, Wert2, Wert3 FROM LG_NGD_Ergebnisse WHERE UID = ? "
118
+ "AND Typ = ? UNION SELECT 0, 0, 0" ,
119
+ sportler [0 ],
120
+ disziplin )):
121
+
122
+ row = self .mainLayout .rowCount ()
123
+
124
+ self .mainLayout .addWidget (QLabel (name ), row , 0 )
125
+ for i in range (0 ,felderzahl [disziplin ]):
126
+ el = QDoubleSpinBox ()
127
+ el .setMaximum (99999 )
128
+ el .setValue (werte [i ])
129
+ el .setSuffix (" " + einheiten [disziplin ])
130
+ el .setSingleStep (0.01 )
131
+ self .mainLayout .addWidget (el , row , i + 1 , 1 , 3 / felderzahl [disziplin ])
132
+ break
133
+ self ._speichern = QPushButton ("Speichern" )
134
+ self ._speichern .clicked .connect (self .speichern )
135
+ self .mainLayout .addWidget (self ._speichern , self .mainLayout .rowCount (), 0 , 1 , 4 )
136
+
137
+ def speichern (self ):
138
+ row = self .mainLayout .rowCount ()- len (self ._sportler )- 1
139
+ disziplin = self .auswahlDisziplin .currentIndex ()- 1
140
+
141
+ ausgabe = "<table>"
142
+
143
+ for UID in self ._sportler :
144
+ werte = ["0" ,"0" ,"0" ]
145
+ for col in range (1 , 1 + felderzahl [disziplin ]):
146
+ item = self .mainLayout .itemAtPosition (row , col )
147
+ text = "0"
148
+ try :
149
+ if type (item .widget ()) is not type (QDoubleSpinBox ()):
150
+ raise TypeError ("No LineEdit" )
151
+ text = item .widget ().value ()
152
+ except TypeError :
153
+ text = "0"
154
+ except AttributeError :
155
+ text = "0"
156
+ werte [col - 1 ]= text
157
+
158
+ data = QueryTool ().queryAndFetch ("SELECT * FROM LG_NGD_Ergebnisse WHERE UID = ? AND Typ = ?" ,UID ,disziplin )
159
+ ergebnisse = None
160
+ typ = None
161
+ if len (data ) is not 0 :
162
+ ergebniss = QueryTool ().update ("LG_NGD_Ergebnisse" , data [0 ][0 ], Wert1 = werte [0 ], Wert2 = werte [1 ], Wert3 = werte [2 ])
163
+ typ = "aktualisiert"
164
+ else :
165
+ ergebniss = QueryTool ().insert ("LG_NGD_Ergebnisse" , UID = UID , Typ = disziplin , Wert1 = werte [0 ], Wert2 = werte [1 ], Wert3 = werte [2 ])
166
+ typ = "eingetragen"
167
+
168
+ username = self .mainLayout .itemAtPosition (row , 0 )
169
+
170
+ if type (username .widget ()) is not type (QLabel ()):
171
+ username = ""
172
+ else :
173
+ username = username .widget ().text ()
174
+ ausgabe += self .template .format (username , list (getDisziplin (self .auswahlAlter .currentIndex ()+ 2 ))[disziplin ],
175
+ "nicht " if ergebniss is None else "" , typ )
176
+
177
+ row += 1
178
+ ausgabe += "</table>"
179
+ QMessageBox .information (self , "Eintragungsstatus" , ausgabe )
180
+
181
+ def clearAuswahl (self ):
182
+ for w in self .iterWidgets (True ):
183
+ w [0 ].setParent (None )
184
+ self ._sportler = []
185
+
186
+ def iterWidgets (self ,allWidgets = False )-> QWidget :
187
+ for row in range (3 , self .mainLayout .rowCount ()- (1 if not allWidgets else 0 )):
188
+ for col in range (self .mainLayout .columnCount ()):
189
+ item = self .mainLayout .itemAtPosition (row , col )
190
+ if item is not None and item .widget () is not None :
191
+ yield (item .widget (), row , col )
192
+ else :
193
+ break
194
+
195
+ def update (self ):
196
+ if not self .auswahlKlasse ():
197
+ return
0 commit comments