/
editsemex.py
136 lines (89 loc) · 4.95 KB
/
editsemex.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
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
# For implementing "edit semester" tab. That is, to add or delete subjects.
import sys
from PyQt4 import QtCore, QtGui
from editsem import Ui_window
from global_sql import *
class Starteditsem(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_window()
self.ui.setupUi(self)
self.delete_setsem()
self.ui.semadd.setMinimum(1)
self.ui.semadd.setMaximum(12)
self.ui.attendance.setMaximum(100)
QtCore.QObject.connect(self.ui.add, QtCore.SIGNAL("clicked()"), self.added)
QtCore.QObject.connect(self.ui.semdelete, QtCore.SIGNAL("currentIndexChanged(int)"), self.delete_setsub)
QtCore.QObject.connect(self.ui.delete_2, QtCore.SIGNAL("clicked()"), self.deleted)
self.ui.semdelete.setStyleSheet('selection-background-color: rgb(85, 85, 255); selection-color: rgb(255, 255, 255)')
self.ui.subdelete.setStyleSheet('selection-background-color: rgb(85, 85, 255); selection-color: rgb(255, 255, 255)')
self.ui.subjectcode.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.subjectname.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.attendance.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.classes.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.semadd.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.credits.setStyleSheet('background-color: rgb(255, 255, 255);')
self.ui.add.setStyleSheet('background-color: rgb(0, 147, 203); color: rgb(255, 255, 255);')
self.ui.delete_2.setStyleSheet('background-color: rgb(0, 147, 203); color: rgb(255, 255, 255);')
self.ui.toolButton_2.setStyleSheet('background-color: rgb(0, 147, 203); color: rgb(255, 255, 255);')
self.ui.toolButton_3.setStyleSheet('background-color: rgb(0, 147, 203); color: rgb(255, 255, 255);')
# Filling the delete option from the subjects already in the database for the concerned semester
def delete_setsub(self):
self.ui.subdelete.clear()
cur.execute("select subjectcode from acads where semester = %d"%(int(self.ui.semdelete.currentText())))
a = cur.fetchall()
b = []
for sublist in a:
b.append(str(sublist[0]))
self.ui.subdelete.addItems(b)
# Adding the subject.
def added(self):
if self.subject_already_exists()==1:
self.showmessage()
else:
bunksallowed = int(self.ui.classes.value())-int((self.ui.classes.value()*self.ui.attendance.value()/100))
s = (self.ui.semadd.value(), str(self.ui.subjectcode.text()), str(self.ui.subjectname.text()), self.ui.credits.value(), None, bunksallowed, 0, self.ui.attendance.value(), self.ui.classes.value() )
cur.execute("insert into acads values (?, ?, ?, ?, ?, ?, ?, ?, ?)", s)
con.commit()
self.ui.subjectcode.clear()
self.ui.subjectname.clear()
# Checking if the subject already exists in the database.
def subject_already_exists(self):
a = (self.ui.semadd.value(),)
cur.execute("select subjectcode from acads where semester = ?",a)
for row in cur:
if str(self.ui.subjectcode.text())==row[0] :
return 1
return 0
# Deleting the selected subject.
def deleted(self):
a = (int(self.ui.semdelete.currentText()), str(self.ui.subdelete.currentText()), )
b = (str(self.ui.subdelete.currentText()),)
cur.execute("delete from acads where semester = ? and subjectcode = ?", a)
cur.execute("delete from referencess where subjectcode1 = ?", b)
cur.execute("delete from bunk where semester = ? and subjectcode = ?", a)
cur.execute("delete from reminder where subjectcode = ?", b)
con.commit()
a = 1
cur.execute("select * from acads")
# Setting the semesters for the delete scroll down semester option.
def delete_setsem(self):
cur.execute("select distinct semester from acads")
a = cur.fetchall()
b = ['']
for sublist in a:
b.append(str(sublist[0]))
self.ui.semdelete.clear()
self.ui.semdelete.addItems(b)
# Error message
def showmessage(self):
message = QtGui.QMessageBox(self)
message.setText('Subject already exists')
message.setWindowTitle('acadmin Error')
message.setIcon(QtGui.QMessageBox.Critical)
message.exec_()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = Starteditsem()
myapp.show()
sys.exit(app.exec_())