-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathW_empHistory.py
79 lines (65 loc) · 2.87 KB
/
W_empHistory.py
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
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidgetItem
from GUI_empHistory import Ui_FormEmpHist
from DatabaseAPI import CompanyDB
import sys
class main(QWidget, Ui_FormEmpHist):
#------------ class atribute ----------------
empID = int()
currentZone = int()
def __init__(self):
QWidget.__init__(self)
self.setupUi(self)
self.setWindowTitle(" {} : {} {}".format(sys.argv[1], sys.argv[2], sys.argv[3]).upper())
self.raise_()
self.empID = sys.argv[1]
self.T_EmpHisto.setColumnWidth(0, self.T_EmpHisto.width()/2) # resize header table with
self.T_EmpHisto.setColumnWidth(1, self.T_EmpHisto.width()/2) # resize header table with
self.showCurrentZone()
self.updateEmpHistoTable()
##-------------------------- connect signals --------------------------
# call updateEmpHistoTable() if any radioButton toogled
self.RB_zone1.toggled.connect(self.updateEmpHistoTable)
self.RB_zone2.toggled.connect(self.updateEmpHistoTable)
self.RB_zone2.toggled.connect(self.updateEmpHistoTable)
##-------------------------------------------------------------------------
##--------- fill table of histo emp switch selected zone by in radioButton -------------
def updateEmpHistoTable(self):
##---------------------- get which radioButton is checked ---------------------------
zoneChecked = int()
if self.RB_zone1.isChecked():
zoneChecked = 1
elif self.RB_zone2.isChecked():
zoneChecked = 2
elif self.RB_zone3.isChecked():
zoneChecked = 3
##------------------- get table from Database ---------------------------
db = CompanyDB()
db.connectdDB()
table = db.selectEmpHistory(zoneChecked, self.empID)
db.closeDB()
##------------------------ fill table -----------------------------------
if len(table):
self.T_EmpHisto.setRowCount(len(table))
self.T_EmpHisto.setColumnCount(len(table[0]))
j = 0
for row in table:
for col in row:
self.T_EmpHisto.setItem(0, j, QTableWidgetItem(str(col)))
j += 1
else:
while self.T_EmpHisto.rowCount() > 0 :
self.T_EmpHisto.removeRow(0)
##--------- show employee current zone in Label(LB_currentZone) -------------
def showCurrentZone(self):
db = CompanyDB()
db.connectdDB()
zones = ('Outside', 'Zone 1', 'Zone 2', 'Zone 3')
self.currentZone = db.getEmpCurrentZone(self.empID)
self.LB_currentZone.setText(zones[self.currentZone]) #set label current zone
db.closeDB()
##----------------- Loop --------------------
if __name__ == '__main__':
app = QApplication(sys.argv)
window = main()
window.show()
app.exec()