-
Notifications
You must be signed in to change notification settings - Fork 3
/
deletePromotionWidget.py
45 lines (40 loc) · 1.54 KB
/
deletePromotionWidget.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
import connectDb
from DeletePromotion import Ui_DeletePromotion
from PyQt4 import QtGui, QtCore
def isNumber(s):
try:
float(s)
return True
except ValueError:
return False
class DeletePromotion(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self)
self.ui = Ui_DeletePromotion()
self.ui.setupUi(self)
self.ui.deletePromo.clicked.connect(self.removePromo)
self.parent = parent
def removePromo(self):
self.ui.error_promoId.clear()
promoId = self.ui.lineEdit_Id.text()
if (len(str(promoId)) > 0):
if (isNumber(promoId)):
promoId = int(promoId)
conn, cur = connectDb.connectToDatabase()
checkForExistence = "SELECT count(*) FROM promotion WHERE promoid = %d AND active = 1;" % promoId
cur.execute(checkForExistence)
count = cur.fetchone()
count = count[0]
if (count == 1):
query = "UPDATE promotion SET active = 0 WHERE promoid = %d;" % promoId
cur.execute(query)
conn.commit()
self.parent.viewPromo()
self.close()
else:
self.ui.error_promoId.setText("*no such promoId")
connectDb.closeDatabaseConnection(conn, cur)
else:
self.ui.error_promoId.setText("*incorrect input")
else:
self.ui.error_promoId.setText("*required")