-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm.py
160 lines (139 loc) · 6.53 KB
/
mm.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import sys
from PyQt5 import QtWidgets, QtGui, uic
from PyQt5.QtWidgets import QMessageBox
# sqlite connection
import sqlite3
db = sqlite3.connect("C:\\Users\\Lenovo\\PycharmProjects\\pythonProject1\\employees.sqlite")
cur = db.cursor()
class Dashboard(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(Dashboard, self).__init__(parent)
uic.loadUi("C:\\Users\\Lenovo\\PycharmProjects\\pythonProject1\\venv\\Lib\\site-packages\\QtDesigner\\MyServiceApp.ui", self)
self.show()
self.addserviceBtn.clicked.connect(self.openAddService)
self.updateBtn.clicked.connect(self.openEditService)
self.deleteBtn.clicked.connect(self.openDeleteService)
self.lineEdit.textChanged.connect(self.opensearchdatabase)
# calling a method directly
self.populateTablefromdatabase()
def openAddService(self):
# opening or calling the Add Service class
window = AddService(self)
# closing the current window to prevent multiple windows from opening
self.hide()
def openEditService(self):
window = EditService(self)
self.hide()
def openDeleteService(self):
window = Deleteservice(self)
self.hide()
def populateTablefromdatabase(self):
# selecting all services from the database table
query = cur.execute('SELECT * FROM Services')
content = query.fetchall()
print(content)
self.servicetableWidget.setRowCount(len(content))
row = 0 # row vvariable
for service in content:
self.servicetableWidget.setItem(row,1,QtWidgets.QTableWidgetItem(str(service[0]))) # add str as prefix to convert to string
self.servicetableWidget.setItem(row,2,QtWidgets.QTableWidgetItem(service[1]))
self.servicetableWidget.setItem(row,3,QtWidgets.QTableWidgetItem(service[2]))
self.servicetableWidget.setItem(row,4,QtWidgets.QTableWidgetItem(service[3]))#passes into the table any variable in an orderly manner
row = row + 1
def opensearchdatabase(self):
# getting the text to be searched for
value = self.lineEdit.text()
# returning matching values from the database
query = cur.execute(f"SELECT * FROM Services WHERE Title like '%{value}%' or Description like '%{value}%'")
content = query.fetchall()
self.servicetableWidget.setRowCount(len(content))
row = 0 # row vvariable
for service in content:
self.servicetableWidget.setItem(row, 1, QtWidgets.QTableWidgetItem(
str(service[0]))) # add str as prefix to convert to string
self.servicetableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(service[1]))
self.servicetableWidget.setItem(row, 3, QtWidgets.QTableWidgetItem(service[2]))
self.servicetableWidget.setItem(row, 4, QtWidgets.QTableWidgetItem(service[3])) # passes into the table any variable in an orderly manner
row = row + 1
class AddService(QtWidgets.QDialog):
def __init__(self, parent=None):
super(AddService, self).__init__(parent)
uic.loadUi("C:\\Users\\Lenovo\\PycharmProjects\\pythonProject1\\venv\\Lib\\site-packages\\QtDesigner\\AddService.ui", self)
self.show()
self.addserviceBtn.clicked.connect(self.addnewService)
self.dashboardbtn.clicked.connect(self.opendashboard)
def addnewService(self):
# getting the content within the text boxes
title = self.addtitletype.text()
description = self.descriptiontype.text()
price = self.pricingtype.text()
print(title, description, price)
# add data to database
status = cur.execute("INSERT into Services (Title,Description,Cost) values(?,?,?)", (title, description, price))
db.commit()
print(status)
def opendashboard(self):
# Opening the dashboard
window = Dashboard(self)
# closing the current page _ add service
self.hide()
class EditService(QtWidgets.QDialog):
def __init__(self, parent=None):
super(EditService, self).__init__(parent)
uic.loadUi(
"C:\\Users\\Lenovo\\PycharmProjects\\pythonProject1\\venv\\Lib\\site-packages\\QtDesigner\\updateservice.ui",
self)
self.show()
self.updatebtn.clicked.connect(self.editService)
self.dashboardbtn.clicked.connect(self.opendashboard)
def editService(self):
# getting the content within the text boxes
title = self.addtitletype.text()
description = self.descriptiontype.text()
price = self.pricingtype.text()
print(title, description, price)
# add data to database
status = cur.execute("INSERT into Services (Title,Description,Cost) values(?,?,?)", (title, description, price))
db.commit()
print(status)
def opendashboard(self):
# Opening the dashboard
window = Dashboard(self)
# closing the current page _ add service
self.hide()
class Deleteservice(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Deleteservice, self).__init__(parent)
uic.loadUi(
"C:\\Users\\Lenovo\\PycharmProjects\\pythonProject1\\venv\\Lib\\site-packages\\QtDesigner\\Deleteservice.ui",
self)
self.show()
self.dashboardbtn.clicked.connect(self.opendashboard)
self.deleteBtn.clicked.connect(self.deleteservice)
def opendashboard(self):
# getting the content within the text boxes
window = Dashboard(self)
self.hide()
def deleteservice(self):
# getting the text in the line edits
column = self.deleteoptionsBtn.currentText()
value = self.deletetargetBtn.text()
try:
# update statement logic
if column == "ServiceId":
cur.execute(f"DELETE FROM Services WHERE STAFF ID = {value}")
db.commit()
elif column == "Title":
cur.execute(f"DELETE FROM Services WHERE Title = {value}")
db.commit()
except:
# popping up a notification unto the screen
msgbox = QMessageBox(self) # creating the notification
msgbox.setFixedSize(800,800) # setting the size
msgbox.setIcon(QMessageBox.warning) # choosing the display icon
msgbox.setText("Error: Duplicate values found!") # notification message
msgbox.exec_() # executing the notification command
app = QtWidgets.QApplication(sys.argv)
window = Dashboard()
app.setQuitOnLastWindowClosed(True)
app.exec_()