def getTotalProfit(): query = "SELECT SUM((product.selling_price-product.price)*product_order.quantity) FROM product_order JOIN product ON product_order.product_id=product.id;" db = DB() result = db.fetch(query) if result: return result[0][0] return None
def __init__(self, parent, update, id=None): super().__init__(parent) self.parent = parent self.db = DB() self.initUI(update, id)
def __init__(self, id=None, name=None, password=None): # Database Class object for communication with database; will be used down in the function self._db = DB() # Id of admin used for database primary key self.id = id # name of admin self.name = name # password of admin self.password = password
def login(self): query = "SELECT * FROM admin where admin_name=%s and password=%s" db = DB() values = (self.name, self.password) result = db.fetch(query, values) if result: self.id = result[0][0] self.name = result[0][1] self.password = result[0][2] return True return False
def login(self, name, password): query = "update admin set logged_in='no' where logged_in='yes'" db = DB() values = (self.name, self.password) self.name = name self.password = password query = "SELECT * FROM admin where admin_name=%s and password=%s" db = DB() values = (self.name, self.password) result = db.fetch(query, values) if result: self.id = result[0][0] self.name = result[0][1] self.password = result[0][2] return True return False
class DashboardOrders(QFrame): def __init__(self): super().__init__() self.db = DB() self.initUI() def initUI(self): frame = QFrame() frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) frame.setFixedWidth(200) frame.setFixedHeight(150) main_label = QLabel(frame) main_label.setAlignment(Qt.AlignCenter) main_label.setGeometry(QRect(40, 10, 120, 41)) main_label.setStyleSheet("font: 75 28pt \"MS Shell Dlg 2\";\n" "color: rgb(255, 255, 255);\n" "font: 36pt \"MS Shell Dlg 2\";") main_label.setText("Orders") data = self.get_orders() sales = QLabel(frame) sales.setAlignment(Qt.AlignCenter) sales.setGeometry(QRect(40, 60, 120, 41)) sales.setStyleSheet("font: 75 18pt \"MS Shell Dlg 2\";\n" "color: rgb(255, 255, 255);\n" "font: 20pt \"MS Shell Dlg 2\";") sales.setText(str(data)) layout = QVBoxLayout() layout.addWidget(frame) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) self.setGeometry(QRect(30, 5, 200, 150)) def get_orders(self): query = "select id from orders;" values = () result = self.db.fetch(query, values) for (sales) in result: sales = sales[0] print("Rows") print(len(result)) return len(result)
class Table(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "tables" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() add_and_search = AddSearchFrame(in_class) add_and_search.add_button.clicked.connect( lambda: self.add_tables(in_class)) add_and_search.search_button.clicked.connect( lambda: self.search_tables(add_and_search.search_box)) self.table = QTableWidget() self.table.setColumnCount(4) # self.table.setStyleSheet("border: none") # self.table.setStyleSheet( # "background-color: rgb(255, 255, 255);\n" # 'font: 10pt "MS Shell Dlg 2";\n' # "color: rgb(30, 45, 66);" # ) # self.table.setHorizontalHeaderItem(0, QTableWidgetItem("ID")) self.table.setHorizontalHeaderItem(0, QTableWidgetItem("Table Name")) self.table.setHorizontalHeaderItem(1, QTableWidgetItem("Covers")) self.table.setHorizontalHeaderItem(2, QTableWidgetItem("Edit")) self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Delete")) # self.table.insertRow(self.table.rowCount()) # # self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem("ID1")) # self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem("Name1")) # self.table.setItem(self.table.rowCount() - 1, 2, QTableWidgetItem("Job1")) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem("Joining Date1")) # self.table.setItem(self.table.rowCount() - 1, 4, QTableWidgetItem("Salary1")) # self.table.setItem(self.table.rowCount() - 1, 5, QTableWidgetItem("Bonus1")) # self.table.setItem(self.table.rowCount() - 1, 6, QTableWidgetItem("Total Salary1")) # self.table.setItem(self.table.rowCount() - 1, 7, QTableWidgetItem("Edit1")) # self.table.setItem(self.table.rowCount() - 1, 8, QTableWidgetItem("Delete1")) data = self.load_tables_data() print(data) for x in data: print(x) self.populate_table(data) layout = QVBoxLayout() layout.addWidget(header) layout.addWidget(add_and_search) layout.addWidget(self.table) # layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) # self.resize(800, 600) self.setWindowTitle("Login") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: pass elif value == 4: self.hide() view = sidebar.Reservations(self) elif value == 5: self.hide() view = sidebar.Category(self) elif value == 6: self.hide() view = sidebar.Settings(self) elif value == 7: self.hide() view = sidebar.Orders(self) elif value == 8: self.hide() view = sidebar.Menu(self) elif value == 9: self.hide() view = sidebar.Bill(self) def load_tables_data(self): query = "SELECT id, table_number, covers FROM tables;" result = self.db.fetch(query) return result ''' This function is called after an employee has been added and returns only the last row. ''' def add_update_tables_data(self): query = "SELECT id, table_number, covers FROM tables " \ "order by id desc limit 1;" result = self.db.fetch(query) return result def edit_tables(self): emp_row = self.table.indexAt(self.sender().pos()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) print(emp_row.row()) print(id) print(type(id)) ''' Get the data from the database for that user. ''' data = self.get_data(id) print("Data") print(data) # print(type(data[4])) view = AddTableDetails(self, "update", data[0]) view.tablenotextbox.setText(data[1]) view.covertextbox.setText(str(data[2])) view.closing.connect(self.editupdate_emp) def editupdate_emp(self, check): print("I am here") print(check) self.table.clearContents() self.table.setRowCount(0) data = self.load_tables_data() self.populate_table(data) # self.table.resizeColumnsToContents() def get_data(self, id): query = "SELECT id, table_number, covers FROM tables " \ "where id=%s" values = (id, ) result = self.db.fetch(query, values) for (id, table_number, covers) in result: id = id table_number = table_number covers = covers return [id, table_number, covers] def delete_tables(self): emp_row = self.table.indexAt(self.sender().pos()) # print(emp_row.row()) # print(emp_row.column()) # print(self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) # print(id) # print(emp_row.child(emp_row.row(), emp_row.column())) query = "DELETE FROM tables WHERE id=%s" values = (id, ) try: result = self.db.execute(query, values) except: pass self.table.clearContents() self.table.setRowCount(0) data = self.load_tables_data() self.populate_table(data) def add_tables(self, where): if where == "tables": print("Category Button Clicked from tables") view = AddTableDetails(self, "add") view.closing.connect(self.update_tables) elif where == "stocks": print("Stock Button Clicked") def search_tables(self, search_obj): search = search_obj.text() search_obj.setText("") print("Search") if search != "": query = "SELECT * FROM tables WHERE table_number like %s" values = ("%" + search + "%", ) else: query = "SELECT * FROM tables" values = () self.table.clearContents() self.table.setRowCount(0) data = self.db.fetch(query, values) self.populate_table(data) ''' Repopulates the employee table with the updated data. ''' def update_tables(self, check): print("I am here") print(check) data = self.add_update_tables_data() self.populate_table(data) ''' This function populates the employee table with data. ''' def populate_table(self, data): for (id, table_number, covers) in data: self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem(str(table_number))) self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(str(covers))) edit = QPushButton(self.table) edit.setObjectName(str(id)) edit.setStyleSheet("background-color: rgb(50,205,50);") edit.setText("Edit") edit.adjustSize() edit.clicked.connect(self.edit_tables) self.table.setCellWidget(self.table.rowCount() - 1, 2, edit) delete = QPushButton(self.table) delete.setObjectName(str(id)) delete.setStyleSheet("background-color: #d63447;") delete.setText("Delete") delete.adjustSize() delete.clicked.connect(self.delete_tables) # delete.mousePressEvent = functools.partial(self.delete_emp, source_object=delete) self.table.setCellWidget(self.table.rowCount() - 1, 3, delete)
class Sidebar(QDockWidget): window = pyqtSignal(int) def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI(parent) def initUI(self, parent): frame = QFrame() label1 = QLabel("Dashboard", frame) # label1.setStyleSheet("border: 3px solid red; text-align: center;") label1.setAlignment(Qt.AlignCenter) label1.setMinimumHeight(50) label1.setObjectName("Dashboard") label1.setMouseTracking(True) label1.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label1, parent]) label1.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label1) label1.leaveEvent = functools.partial(self.tabsleft, source_object=label1) # label1.setFixedHeight(50) label2 = QLabel("Employees", frame) label2.setAlignment(Qt.AlignCenter) label2.setMinimumHeight(50) label2.setObjectName("Employees") label2.setMouseTracking(True) label2.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label2, parent]) label2.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label2) label2.leaveEvent = functools.partial(self.tabsleft, source_object=label2) label3 = QLabel("Users", frame) label3.setAlignment(Qt.AlignCenter) label3.setMinimumHeight(50) label3.setObjectName("Users") label3.setMouseTracking(True) label3.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label3, parent]) label3.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label3) label3.leaveEvent = functools.partial(self.tabsleft, source_object=label3) label4 = QLabel("Tables", frame) label4.setAlignment(Qt.AlignCenter) label4.setMinimumHeight(50) label4.setObjectName("Tables") label4.setMouseTracking(True) label4.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label4, parent]) label4.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label4) label4.leaveEvent = functools.partial(self.tabsleft, source_object=label4) label5 = QLabel("Reservations", frame) label5.setAlignment(Qt.AlignCenter) label5.setMinimumHeight(50) label5.setObjectName("Reservations") label5.setMouseTracking(True) label5.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label5, parent]) label5.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label5) label5.leaveEvent = functools.partial(self.tabsleft, source_object=label5) label6 = QLabel("Orders", frame) label6.setAlignment(Qt.AlignCenter) label6.setMinimumHeight(50) label6.setObjectName("Orders") label6.setMouseTracking(True) label6.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label6, parent]) label6.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label6) label6.leaveEvent = functools.partial(self.tabsleft, source_object=label6) label7 = QLabel("Bill", frame) label7.setAlignment(Qt.AlignCenter) label7.setMinimumHeight(50) label7.setObjectName("Bill") label7.setMouseTracking(True) label7.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label7, parent]) label7.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label7) label7.leaveEvent = functools.partial(self.tabsleft, source_object=label7) label8 = QLabel("Settings", frame) label8.setAlignment(Qt.AlignCenter) label8.setMinimumHeight(50) label8.setObjectName("Settings") label8.setMouseTracking(True) label8.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label8, parent]) label8.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label8) label8.leaveEvent = functools.partial(self.tabsleft, source_object=label8) label9 = QLabel("Logout", frame) label9.setAlignment(Qt.AlignCenter) label9.setMinimumHeight(50) label9.setObjectName("Logout") label9.setMouseTracking(True) label9.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label9, parent]) label9.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label9) label9.leaveEvent = functools.partial(self.tabsleft, source_object=label9) label10 = QLabel("Category", frame) label10.setAlignment(Qt.AlignCenter) label10.setMinimumHeight(50) label10.setObjectName("Category") label10.setMouseTracking(True) label10.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label10, parent]) label10.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label10) label10.leaveEvent = functools.partial(self.tabsleft, source_object=label10) label11 = QLabel("Menu", frame) label11.setAlignment(Qt.AlignCenter) label11.setMinimumHeight(50) label11.setObjectName("Menu") label11.setMouseTracking(True) label11.mousePressEvent = functools.partial(self.tabsClicked, source_object=[label11, parent]) label11.mouseMoveEvent = functools.partial(self.tabsHovered, source_object=label11) label11.leaveEvent = functools.partial(self.tabsleft, source_object=label11) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) privileges = self.get_privileges() list_privileges = privileges.split(", ") print("All the Privileges") print(list_privileges) for x in list_privileges: if x == 'Dashboard': layout.addWidget(label1, 0) if x == 'Employees': layout.addWidget(label2, 0) if x == 'Users': layout.addWidget(label3, 0) if x == 'Tables': layout.addWidget(label4, 0) if x == 'Reservations': layout.addWidget(label5, 0) if x == 'Category': layout.addWidget(label10, 0) if x == 'Menu': layout.addWidget(label11, 0) if x == 'Orders': layout.addWidget(label6, 0) if x == 'Bill': layout.addWidget(label7, 0) if x == 'Settings': layout.addWidget(label8, 0) layout.addWidget(label9, 0) # self.setLayout(layout) # when extending QFrame ''' Removes the title bar from the DockWidget. ''' self.setTitleBarWidget(QWidget(None)) ''' Make the DockWidget non-resizable. Set the minimum & maximum width/height value equal to same amount. ''' self.setMinimumWidth(200) self.setMaximumWidth(200) ''' Removes the close button from the DockWidget ''' # self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) self.setFeatures(self.NoDockWidgetFeatures) self.setStyleSheet("background-color: rgb(30, 45, 66); color: white; border-width: 0px; ") self.setContentsMargins(0, 0, 0, 0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setWidget(centralWidget) # self.setWindowTitle("Test") self.show() def get_privileges(self): list = "" query = "SELECT roles FROM admin where logged_in='yes' " \ "order by id desc limit 1;" result = self.db.fetch(query) for (roles) in result: list = roles[0] print(list) return list def tabsClicked(self, event, source_object=None): print("Clicked, from: ", source_object[0].objectName()) tab = source_object[0].objectName() if tab == "Dashboard": # self.window.emit(1) source_object[1].hide() view = Dashboard(source_object[1]) elif tab == "Employees": # self.window.emit(2) source_object[1].hide() view = Employee(source_object[1]) elif tab == "Users": source_object[1].hide() view = Users(source_object[1]) elif tab == "Tables": # self.window.emit(3) source_object[1].hide() view = Table(source_object[1]) elif tab == "Reservations": # self.window.emit(4) source_object[1].hide() view = Reservations(source_object[1]) elif tab == "Category": # self.window.emit(5) source_object[1].hide() view = Category(source_object[1]) elif tab == "Menu": # self.window.emit(8) source_object[1].hide() view = Menu(source_object[1]) elif tab == "Orders": # self.window.emit(7) source_object[1].hide() view = Orders(source_object[1]) elif tab == "Bill": # self.window.emit(9) source_object[1].hide() view = Bill(source_object[1]) elif tab == "Settings": # self.window.emit(6) source_object[1].hide() view = Settings(source_object[1]) elif tab == "Logout": query = "update admin set logged_in='no' where logged_in='yes'" values = () data = self.db.execute(query, values) source_object[1].hide() view = Logout(source_object[1]) def tabsHovered(self, event, source_object= None): source_object.setStyleSheet("background-color: white; color: black") def tabsleft(self, event, source_object= None): source_object.setStyleSheet("background-color: rgb(30, 45, 66); color: white")
class Reservations(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "reservations" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() add_and_search = AddSearchFrame(in_class) add_and_search.add_button.clicked.connect( lambda: self.add_reservation(in_class)) add_and_search.search_button.clicked.connect( lambda: self.search_reservation(add_and_search.search_box)) self.table = QTableWidget() self.table.setColumnCount(6) # self.table.setStyleSheet("border: none") # self.table.setStyleSheet( # "background-color: rgb(255, 255, 255);\n" # 'font: 10pt "MS Shell Dlg 2";\n' # "color: rgb(30, 45, 66);" # ) # self.table.setHorizontalHeaderItem(0, QTableWidgetItem("ID")) self.table.setHorizontalHeaderItem(0, QTableWidgetItem("Customer Name")) self.table.setHorizontalHeaderItem(1, QTableWidgetItem("Phone No.")) self.table.setHorizontalHeaderItem(2, QTableWidgetItem("Date")) # self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Bonus")) self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Time")) # self.table.setHorizontalHeaderItem(6, QTableWidgetItem("Total Salary")) self.table.setHorizontalHeaderItem(4, QTableWidgetItem("Edit")) self.table.setHorizontalHeaderItem(5, QTableWidgetItem("Delete")) data = self.load_reservation_data() print(data) for x in data: print(x) self.populate_table(data) layout = QVBoxLayout() layout.addWidget(header) layout.addWidget(add_and_search) layout.addWidget(self.table) # layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) # self.resize(800, 600) self.setWindowTitle("Login") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: self.hide() view = sidebar.Table(self) elif value == 4: pass elif value == 5: self.hide() view = sidebar.Category(self) elif value == 6: self.hide() view = sidebar.Settings(self) elif value == 7: self.hide() view = sidebar.Orders(self) elif value == 8: self.hide() view = sidebar.Menu(self) elif value == 9: self.hide() view = sidebar.Bill(self) def load_reservation_data(self): query = "select id, customer_name, phone_number, date(booking_date) as date, " \ "time_format(time(booking_date), '%H:%i') as time from customerBooking;" result = self.db.fetch(query) return result ''' This function is called after an employee has been added and returns only the last row. ''' def add_update_reservation_data(self): query = "select id, customer_name, phone_number, date(booking_date) as date, " \ "time_format(time(booking_date), '%H:%i') as time from customerBooking " \ "order by id desc limit 1;" result = self.db.fetch(query) return result def edit_reservation(self): emp_row = self.table.indexAt(self.sender().pos()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) print(emp_row.row()) print(id) print(type(id)) ''' Get the data from the database for that user. ''' data = self.get_data(id) print("Data") print(data) # print(type(data[4])) view = AddBookingDetails(self, "update", data[0]) view.customernametextbox.setText(data[1]) view.customercontacttextbox.setText(str(data[2])) view.datetextbox.setDate(QDate.fromString(data[3], "dd-MM-yyyy")) # view.starttimetextbox.setTime(QTime.fromString(data[4]), "hh:mm") view.closing.connect(self.editupdate_emp) def editupdate_emp(self): self.table.clearContents() self.table.setRowCount(0) data = self.load_reservation_data() self.populate_table(data) def get_data(self, id): query = "select id, customer_name, phone_number, date(booking_date) as date, " \ "time_format(time(booking_date), '%H:%i') as time FROM customerBooking " \ "where id=%s" values = (id, ) result = self.db.fetch(query, values) for (id, customer_name, phone_number, date, time) in result: id = id customer_name = customer_name phone_number = phone_number date = date time = time return [ id, customer_name, phone_number, str(date.strftime("%d-%m-%Y")) ] def delete_reservation(self): emp_row = self.table.indexAt(self.sender().pos()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) query = "DELETE FROM customerBooking WHERE id=%s" values = (id, ) result = self.db.execute(query, values) self.table.clearContents() self.table.setRowCount(0) data = self.load_reservation_data() self.populate_table(data) def add_reservation(self, where): if where == "reservations": print("Employee Button Clicked from employee") view = AddBookingDetails(self, "add") view.closing.connect(self.update_reservation) elif where == "stocks": print("Stock Button Clicked") def search_reservation(self, search_obj): search = search_obj.text() search_obj.setText("") print("Search") if search != "": query = "select id, customer_name, phone_number, date(booking_date) as date, " \ "time_format(time(booking_date), '%H:%i') as time FROM customerBooking " \ "WHERE customer_name like %s" values = ("%" + search + "%", ) else: query = "select id, customer_name, phone_number, date(booking_date) as date, " \ "time_format(time(booking_date), '%H:%i') as time FROM customerBooking" values = () self.table.clearContents() self.table.setRowCount(0) data = self.db.fetch(query, values) self.populate_table(data) ''' Repopulates the employee table with the updated data. ''' def update_reservation(self, check): print("I am here") print(check) data = self.add_update_reservation_data() self.populate_table(data) ''' This function populates the employee table with data. ''' def populate_table(self, data): for (id, employee_name, job_title, salary, joining_date) in data: self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem(str(employee_name))) self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(str(job_title))) self.table.setItem( self.table.rowCount() - 1, 2, QTableWidgetItem(str(salary.strftime("%d-%m-%Y")))) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(bonus))) self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(joining_date))) edit = QPushButton(self.table) edit.setObjectName(str(id)) edit.setStyleSheet("background-color: rgb(50,205,50);") edit.setText("Edit") edit.adjustSize() edit.clicked.connect(self.edit_reservation) self.table.setCellWidget(self.table.rowCount() - 1, 4, edit) delete = QPushButton(self.table) delete.setObjectName(str(id)) delete.setStyleSheet("background-color: #d63447;") delete.setText("Delete") delete.adjustSize() delete.clicked.connect(self.delete_reservation) # delete.mousePressEvent = functools.partial(self.delete_emp, source_object=delete) self.table.setCellWidget(self.table.rowCount() - 1, 5, delete)
class Users(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "users" self.sidebar = sidebar.Sidebar(self) # self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() add_and_search = AddSearchFrame(in_class) add_and_search.add_button.clicked.connect( lambda: self.add_users(in_class)) add_and_search.search_button.clicked.connect( lambda: self.search_users(add_and_search.search_box)) self.table = QTableWidget() self.table.setColumnCount(5) # self.table.setStyleSheet("border: none") # self.table.setStyleSheet( # "background-color: rgb(255, 255, 255);\n" # 'font: 10pt "MS Shell Dlg 2";\n' # "color: rgb(30, 45, 66);" # ) # self.table.setHorizontalHeaderItem(0, QTableWidgetItem("ID")) self.table.setHorizontalHeaderItem(0, QTableWidgetItem("Usernmae")) self.table.setHorizontalHeaderItem(1, QTableWidgetItem("Password")) self.table.setHorizontalHeaderItem(2, QTableWidgetItem("Roles")) # self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Bonus")) # self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Joining Date")) # self.table.setHorizontalHeaderItem(6, QTableWidgetItem("Total Salary")) self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Edit")) self.table.setHorizontalHeaderItem(4, QTableWidgetItem("Delete")) data = self.load_users_data() print(data) for x in data: print(x) self.populate_table(data) self.table.resizeColumnsToContents() layout = QVBoxLayout() layout.addWidget(header) layout.addWidget(add_and_search) layout.addWidget(self.table) # layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) # self.resize(800, 600) self.setWindowTitle("Employee") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def load_users_data(self): query = "SELECT id, admin_name, password, roles FROM admin where admin_name != 'admin'" result = self.db.fetch(query) return result # for (name, job_title, salary, bonus, joining_date) in result: # print("=========Start==========") # print(" " + str(name)) # print(" " + str(job_title)) # print(" " + str(salary)) # print(" " + str(bonus)) # print(" " + str(joining_date)) # print("=========End==========") # print("\n") ''' This function is called after an employee has been added and returns only the last row. ''' def add_update_users_data(self): query = "SELECT id, admin_name, password, roles FROM admin where admin_name != 'admin' " \ "order by id desc limit 1;" result = self.db.fetch(query) return result def edit_users(self): emp_row = self.table.indexAt(self.sender().pos()) print(emp_row.row()) def delete_users(self): emp_row = self.table.indexAt(self.sender().pos()) # print(emp_row.row()) # print(emp_row.column()) # print(self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) # print(id) # print(emp_row.child(emp_row.row(), emp_row.column())) query = "DELETE FROM admin WHERE id=%s" values = (id, ) result = self.db.execute(query, values) self.table.clearContents() self.table.setRowCount(0) data = self.load_users_data() self.populate_table(data) def add_users(self, where): if where == "employees": print("Employee Button Clicked from employee") view = AddEmployeeDetails(self) view.closing.connect(self.update_users) elif where == "stocks": print("Stock Button Clicked") def search_users(self, search_obj): search = search_obj.text() search_obj.setText("") print("Search") if search != "": query = "SELECT id, admin_name, password, roles FROM admin " \ "where admin_name != 'admin' and admin_name like %s" values = ("%" + search + "%", ) else: query = "SELECT id, admin_name, password, roles FROM admin " \ "where admin_name != 'admin'" values = () self.table.clearContents() self.table.setRowCount(0) data = self.db.fetch(query, values) self.populate_table(data) ''' Repopulates the employee table with the updated data. ''' def update_users(self, check): print("I am here") print(check) data = self.add_update_users_data() self.populate_table(data) ''' This function populates the employee table with data. ''' def populate_table(self, data): for (id, admin_name, password, roles) in data: self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem(str(admin_name))) self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(str(password))) self.table.setItem(self.table.rowCount() - 1, 2, QTableWidgetItem(str(roles))) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(bonus))) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(joining_date.strftime("%d-%m-%Y")))) edit = QPushButton(self.table) edit.setStyleSheet("background-color: rgb(50,205,50);") edit.setText("Edit") edit.adjustSize() edit.clicked.connect(self.edit_users) self.table.setCellWidget(self.table.rowCount() - 1, 3, edit) delete = QPushButton(self.table) delete.setObjectName(str(id)) delete.setStyleSheet("background-color: #d63447;") delete.setText("Delete") delete.adjustSize() delete.clicked.connect(self.delete_users) # delete.mousePressEvent = functools.partial(self.delete_users, source_object=delete) self.table.setCellWidget(self.table.rowCount() - 1, 4, delete)
def getOrdersCounts(): query = "SELECT Count(id) FROM `order`" db = DB() result = db.fetch(query) return result[0][0]
class AddBookingDetails(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent, update, id=None): super().__init__(parent) self.db = DB() self.initUI(update, id) def initUI(self, update, id): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setMinimumWidth(430) # frame.setFixedHeight(395) # frame.setStyleSheet("border: none") add_booking_button = QLabel(frame) add_booking_button.setAlignment(Qt.AlignCenter) add_booking_button.setGeometry(QRect(110, 30, 210, 41)) add_booking_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") add_booking_button.setText("Add Reservation Details") # tablelabel = QLabel(frame) # tablelabel.setText("Table") # tablelabel.setGeometry(QRect(50, 120, 81, 20)) # # tabletextbox = QComboBox(frame) # tabletextbox.setGeometry(QRect(170, 110, 181, 31)) # tabletextbox.setFixedWidth(180) # tabletextbox.addItems(["Table 1", "Table 2"]) customernamelabel = QLabel(frame) customernamelabel.setText("Customer Name") customernamelabel.setGeometry(QRect(50, 120, 100, 20)) self.customernametextbox = QLineEdit(frame) self.customernametextbox.setGeometry(QRect(170, 110, 181, 31)) self.customernametextbox.setFixedWidth(180) customercontactlabel = QLabel(frame) customercontactlabel.setText("Customer Contact") customercontactlabel.setGeometry(QRect(50, 160, 145, 19)) self.customercontacttextbox = QLineEdit(frame) self.customercontacttextbox.setGeometry(QRect(170, 150, 181, 31)) self.customercontacttextbox.setFixedWidth(180) datelabel = QLabel(frame) datelabel.setText("Date") datelabel.setGeometry(QRect(50, 200, 145, 19)) self.datetextbox = QDateEdit(frame) self.datetextbox.setGeometry(QRect(170, 190, 181, 31)) self.datetextbox.setFixedWidth(180) self.datetextbox.setDate(QDate.currentDate()) self.datetextbox.setMinimumDate(QDate.currentDate()) self.datetextbox.setDisplayFormat("dd-MM-yyyy") starttimelabel = QLabel(frame) starttimelabel.setText("Start Time") starttimelabel.setGeometry(QRect(50, 240, 121, 16)) self.starttimetextbox = QTimeEdit(frame) self.starttimetextbox.setGeometry(QRect(170, 230, 181, 31)) self.starttimetextbox.setFixedWidth(180) # self.starttimetextbox.setTime(QDate.currentDate()) # self.starttimetextbox.setMinimumDate(QDate.currentDate()) self.addbutton = QPushButton(frame) self.addbutton.setText("Add Booking") self.addbutton.setGeometry(QRect(160, 300, 151, 31)) self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") # self.addbutton.clicked.connect(lambda: self.add_button_click("reservations")) if update == 'add': print("Add") print(id) self.addbutton.setText("Add Reservation") self.addbutton.clicked.connect( lambda: self.add_button_click("reservations")) else: print("Update") print(id) self.addbutton.setText("Update Reservation") self.addbutton.clicked.connect( lambda: self.update_button_click("reservations", id)) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(frame) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) # self.setLayout(layout) self.setWindowTitle("Add Reservation Details") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def update_button_click(self, where, id): if where == "reservations": print("Tables Finally here") customer_name = self.customernametextbox.text() customer_contact = self.customercontacttextbox.text() start_time = self.starttimetextbox.text() try: date = datetime.datetime.strptime(self.datetextbox.text(), "%d-%m-%Y") booking_date = datetime.datetime.strftime(date, "%Y-%m-%d") except Exception as e: ''' Make sure to add an error message. ''' print(e) return if customer_name != "" and customer_contact != "": query = "update customerBooking set `customer_name`=%s, " \ "`phone_number`=%s, `booking_date`=concat(%s, ' ', %s)" \ "where id=%s;" values = (customer_name, customer_contact, booking_date, start_time, id) result = self.db.execute(query, values) self.closeEvent = self.message() def add_button_click(self, where): if where == "reservations": print("Finally here") customer_name = self.customernametextbox.text() customer_contact = self.customercontacttextbox.text() start_time = self.starttimetextbox.text() try: date = datetime.datetime.strptime(self.datetextbox.text(), "%d-%m-%Y") booking_date = datetime.datetime.strftime(date, "%Y-%m-%d") except Exception as e: ''' Make sure to add an error message. ''' print(e) return if customer_name != "" and customer_contact != "": print("Got Here") query = "insert into customerBooking (`customer_name`, `phone_number`, `booking_date`)" \ "values (%s, %s, concat(%s, ' ', %s));" values = (customer_name, customer_contact, booking_date, start_time) result = self.db.execute(query, values) self.closeEvent = self.message() def message(self): self.closing.emit(1) self.close()
class Settings(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "settings" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() change_passwordbtn = QPushButton("Change Password") change_passwordbtn.setStyleSheet("background-color: rgb(30, 45, 66);\n" "font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(255, 255, 255);") change_passwordbtn.setFixedWidth(170) change_passwordbtn.setFixedHeight(40) change_passwordbtn.clicked.connect(self.change_password) add_userbtn = QPushButton("Add User") add_userbtn.setStyleSheet("background-color: rgb(30, 45, 66);\n" "font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(255, 255, 255);") add_userbtn.setFixedWidth(170) add_userbtn.setFixedHeight(40) add_userbtn.clicked.connect(self.add_user) edit_restaurant_label = QLabel("Edit Restaurant Information") edit_restaurant_label.setStyleSheet( "color: rgb(30, 45, 66);\n" "font: 75 20pt \"MS Shell Dlg 2\";") restaurantlabel = QLabel() restaurantlabel.setText("Name") restaurantlabel.setGeometry(QRect(80, 100, 47, 13)) restaurantlabel.setFixedWidth(190) restaurantlabel.setFixedHeight(40) restaurantlabel.setStyleSheet("color: rgb(30, 45, 66);\n" 'font: 75 18pt "MS Shell Dlg 2";') self.restauranttextbox = QLineEdit() self.restauranttextbox.setGeometry(QRect(160, 90, 181, 31)) self.restauranttextbox.setFixedWidth(280) self.restauranttextbox.setFixedHeight(40) addresslabel = QLabel() addresslabel.setText("Job Title") addresslabel.setGeometry(QRect(80, 140, 61, 16)) addresslabel.setFixedWidth(190) addresslabel.setFixedHeight(40) addresslabel.setStyleSheet("color: rgb(30, 45, 66);\n" 'font: 75 18pt "MS Shell Dlg 2";') self.addresstextbox = QLineEdit() self.addresstextbox.setGeometry(QRect(160, 130, 181, 31)) self.addresstextbox.setFixedWidth(280) self.addresstextbox.setFixedHeight(40) contact = QLabel() contact.setText("Salary") contact.setGeometry(QRect(80, 180, 47, 13)) contact.setFixedWidth(190) contact.setFixedHeight(40) contact.setStyleSheet("color: rgb(30, 45, 66);\n" 'font: 75 18pt "MS Shell Dlg 2";') self.contacttextbox = QLineEdit() self.contacttextbox.setGeometry(QRect(160, 170, 181, 31)) self.contacttextbox.setFixedWidth(280) self.contacttextbox.setFixedHeight(40) self.contacttextbox.setValidator(QIntValidator()) update_btn = QPushButton("Update") update_btn.setGeometry(QRect(370, 500, 131, 41)) update_btn.setStyleSheet("background-color: rgb(30, 45, 66);\n" "font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(255, 255, 255);") update_btn.setFixedWidth(130) update_btn.setFixedHeight(40) update_btn.clicked.connect(self.update_data) self.load_data() hlayout1 = QHBoxLayout() hlayout1.addStretch() hlayout1.addWidget(change_passwordbtn) hlayout1.addWidget(add_userbtn) hlayout1.addStretch() hlayout2 = QHBoxLayout() hlayout2.addStretch() hlayout2.addWidget(edit_restaurant_label) hlayout2.addStretch() hlayout3 = QHBoxLayout() hlayout3.addStretch() hlayout3.addWidget(restaurantlabel) hlayout3.addWidget(self.restauranttextbox) hlayout3.addStretch() hlayout4 = QHBoxLayout() hlayout4.addStretch() hlayout4.addWidget(addresslabel) hlayout4.addWidget(self.addresstextbox) hlayout4.addStretch() hlayout5 = QHBoxLayout() hlayout5.addStretch() hlayout5.addWidget(contact) hlayout5.addWidget(self.contacttextbox) hlayout5.addStretch() hlayout6 = QHBoxLayout() hlayout6.addStretch() hlayout6.addWidget(update_btn) hlayout6.addStretch() layout = QVBoxLayout() layout.addWidget(header) layout.addLayout(hlayout1) layout.addStretch() layout.addLayout(hlayout2) layout.addLayout(hlayout3) layout.addLayout(hlayout4) layout.addLayout(hlayout5) layout.addLayout(hlayout6) layout.addStretch() layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) self.setWindowTitle("Settings") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: self.hide() view = sidebar.Table(self) elif value == 4: self.hide() view = sidebar.Reservations(self) elif value == 5: self.hide() view = sidebar.Category(self) elif value == 6: pass elif value == 7: self.hide() view = sidebar.Orders(self) elif value == 8: self.hide() view = sidebar.Menu(self) def change_password(self): view = ChangePassword(self) def add_user(self): print("Add user here") view = AddUser(self) # view.closing.connect(self.update_setting) ''' Repopulates the employee table with the updated data. ''' def update_setting(self, check): print("I am here") print(check) # data = self.add_update_emp_data() # # self.populate_table(data) def load_data(self): print("Got here.") query = "SELECT restaurant_name, address, contact FROM rest_info;" values = () result = self.db.fetch(query, values) for (restaurant_name, address, contact) in result: self.restauranttextbox.setText(restaurant_name) self.addresstextbox.setText(address) self.contacttextbox.setText(contact) def update_data(self): print("Updated " + self.restauranttextbox.text()) print("Updated " + self.addresstextbox.text()) print("Updated " + self.contacttextbox.text()) ''' To do.. Update the restaurant information in the database with the given values. ''' query = "update rest_info set restaurant_name=%s, address=%s, contact=%s" values = (self.restauranttextbox.text(), self.addresstextbox.text(), self.contacttextbox.text()) result = self.db.execute(query, values)
class Orders(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "orders" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() self.scrollArea = QScrollArea() # self.scrollArea.setContentsMargins(0, 0, 0, 0) self.scrollArea.setStyleSheet("Border: none") left_content = QVBoxLayout(self.scrollArea) left_content.setContentsMargins(0, 0, 0, 0) left_content.setSpacing(0) table = QLabel("Table No") table_list = self.get_tables() self.table_no = QComboBox() self.table_no.setFixedWidth(250) self.table_no.addItems(table_list) hl = QHBoxLayout() hl.addStretch() hl.addWidget(table) hl.addStretch() hl.addWidget(self.table_no) hl.addStretch() # left_content.addLayout(hlayout1) left_content.addLayout(hl) menu_list = self.get_menu_items() for key, value in menu_list.items(): if value: category = QLabel(key) category.setAlignment(Qt.AlignCenter) left_content.addWidget(category) for x in value: quantity = QLineEdit() quantity.setFixedWidth(50) quantity.setFixedHeight(50) xtimes = QLabel(" X ") widget2 = MenuItems(x) widget2.setMouseTracking(True) widget2.mouseMoveEvent = functools.partial(self.mouse_moved, source_object=widget2) widget2.leaveEvent = functools.partial(self.mouse_left, source_object=widget2) widget2.mousePressEvent = functools.partial(self.mouse_pressed, source_object=[quantity, widget2]) widget2.setStyleSheet("background-color: grey; color: black") hlayout2 = QHBoxLayout() hlayout2.setContentsMargins(10, 10, 0, 0) hlayout2.addWidget(quantity) hlayout2.addWidget(xtimes) hlayout2.addWidget(widget2) # widget2.mousePressEvent = functools.partial(self.mouse_pressed, source_object=hlayout2) left_content.addLayout(hlayout2) left_content.addStretch() # left_content.addLayout(hlayout2) # self.thumbnail = QHBoxLayout() # self.scrollArea.setMaximumWidth(self.width()/2) self.scrollChildArea = QWidget() self.scrollChildArea.setLayout(left_content) self.scrollArea.setWidgetResizable(True) self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) # self.scrollArea.setMinimumHeight(160) # self.scrollArea.setMaximumHeight(160) self.scrollArea.setWidget(self.scrollChildArea) # self.scrollArea.setFrameShape(QFrame().NoFrame) self.scrollArea.setStatusTip("Preview") # --------------------------------------------------- self.scrollArea2 = QScrollArea() # self.scrollArea2.setContentsMargins(0, 0, 0, 0) self.scrollArea2.setStyleSheet("Border: none") # --------------------------------------------------- self.right_content = QVBoxLayout(self.scrollArea2) self.right_content.setContentsMargins(0, 0, 0, 0) # self.right_content.setAlignment(Qt.AlignCenter) # --------------------------------------------------- self.scrollChildArea2 = QWidget() self.scrollChildArea2.setLayout(self.right_content) self.scrollArea2.setWidgetResizable(True) self.scrollArea2.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scrollArea2.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) # self.scrollArea2.setMinimumHeight(160) # self.scrollArea2.setMaximumHeight(160) self.scrollArea2.setWidget(self.scrollChildArea2) # self.scrollArea2.setFrameShape(QFrame().NoFrame) self.scrollArea2.setStatusTip("Preview") bar = self.scrollArea2.verticalScrollBar() bar.rangeChanged.connect(lambda: bar.setValue(bar.maximum())) # --------------------------------------------------- bill = QLabel() bill.setText("Bill") bill.setAlignment(Qt.AlignCenter) bill.setFixedWidth(450) bill.setStyleSheet("font: 75 20pt \"MS Shell Dlg 2\";") self.msg = QLabel("") self.msg.setFixedHeight(50) print_bill = QPushButton("Send") print_bill.setFixedWidth(100) print_bill.setFixedHeight(50) print_bill.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") print_bill.clicked.connect(self.send_bill) hl2 = QHBoxLayout() hl2.addWidget(self.msg, alignment=Qt.AlignCenter) hl2.addWidget(print_bill, alignment=Qt.AlignRight) self.total = 0.00 self.food_order = [] self.total_amount = QLabel("Total : " + str(self.total)) self.total_amount.setAlignment(Qt.AlignRight) self.right_content.addWidget(bill) self.right_content.addStretch() self.right_content.addWidget(self.total_amount) self.right_content.addLayout(hl2) self.right_content.addStretch() content = QGridLayout() content.setContentsMargins(0, 0, 0, 0) content.setSpacing(0) content.addWidget(self.scrollArea, 0, 0) content.addWidget(self.scrollArea2, 0, 1) layout = QVBoxLayout() layout.addWidget(header) layout.addLayout(content) layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) self.setWindowTitle("Settings") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: self.hide() view = sidebar.Table(self) elif value == 4: self.hide() view = sidebar.Reservations(self) elif value == 5: self.hide() view = sidebar.Category(self) elif value == 6: self.hide() view = sidebar.Settings(self) elif value == 7: pass elif value == 8: self.hide() view = sidebar.Menu(self) elif value == 9: self.hide() view = sidebar.Bill(self) def settle_bill(self): if not self.food_order: self.msg.setText("Food not ordered") self.msg.setStyleSheet("color: red") else: ''' Update the database with the order details. ''' query = "select id from tables where table_number=%s" values = (self.table_no.currentText(),) data = self.db.fetch(query, values) for (id) in data: table_id = id[0] query = "update orders set paid = 'yes' where id = %s" values = (table_id,) data = self.db.execute(query, values) self.msg.setText("Bill Settled") self.msg.setStyleSheet("color: green") def send_bill(self): print(self.food_order) if not self.food_order: print("Food not ordered") self.msg.setText("Food not ordered") self.msg.setStyleSheet("color: red") else: # print(self.table_no.currentText()) # # print(int(self.table_no.currentText()[7:8])) # print(type(self.table_no.currentText())) ''' Update the database with the order details. ''' query = "select id from tables where table_number=%s" values = (self.table_no.currentText(),) data = self.db.fetch(query, values) for (id) in data: table_id = id[0] query = "insert into orders (table_id, food_list, total_price) " \ "values (%s, %s, %s)" values = (table_id, ', '.join(self.food_order), str(self.total)) data = self.db.execute(query, values) self.msg.setText("Saved") self.msg.setStyleSheet("color: green") # print(int(self.table_no.currentText())) # print(', '.join(self.food_order)) # print(type(self.food_order)) # print(self.total) def get_tables(self): query = "select table_number, covers from tables " \ "where id != ifnull((select table_id from orders where paid = 'no'), 0);" values = () data = self.db.fetch(query, values) tables = [] # for (table_number, covers) in data: # tables.append("Table: " + str(table_number) + " Cover: (" + str(covers) + ")") for (table_number, covers) in data: tables.append(table_number) return tables def get_menu_items(self): query = "select category_name from category" values = () data = self.db.fetch(query, values) menu = {} for (category_name) in data: menu[category_name[0]] = [] print(menu) query = "select food_name, price, category_name from menu " \ "join category on category.id = menu.category_id" values = () data = self.db.fetch(query, values) for (food_name, price, category_name) in data: menu[category_name].append([food_name, price]) print("\nHere is the list\n") for key, value in menu.items(): print(str(key) + ": " + str(value)) return menu def mouse_moved(self, event, source_object=None): # print("Moved") source_object.setStyleSheet("background-color: black; color: white") def mouse_left(self, event, source_object=None): # print("Left") source_object.setStyleSheet("background-color: grey; color: black") def mouse_pressed(self, event, source_object=None): print("Pressed") # print(source_object) # print(type(source_object)) # # print(source_object.widget()) # print(source_object[0].text()) # print(source_object[1].food_label.text()) # print(source_object[1].food_price_label.text()) quantity = QLabel(source_object[0].text()) if quantity.text() == "": quantity.setText("1") xtimes = QLabel(" X ") food_label = QLabel(source_object[1].food_label.text()) food_price_label = QLabel(source_object[1].food_price_label.text()) delete = QLabel("X") delete.setStyleSheet("color: red") # widget2 = MenuItems(x) # widget2.setMouseTracking(True) # widget2.mouseMoveEvent = functools.partial(self.mouse_moved, source_object=widget2) # widget2.leaveEvent = functools.partial(self.mouse_left, source_object=widget2) # widget2.mousePressEvent = functools.partial(self.mouse_pressed, # source_object=[quantity, widget2]) # widget2.setStyleSheet("background-color: grey; color: black") hlayout2 = QHBoxLayout() hlayout2.setContentsMargins(10, 10, 0, 0) hlayout2.addStretch() hlayout2.addWidget(quantity) hlayout2.addStretch() hlayout2.addWidget(xtimes) hlayout2.addStretch() hlayout2.addWidget(food_label) hlayout2.addStretch() hlayout2.addWidget(food_price_label) hlayout2.addStretch() hlayout2.addWidget(delete) hlayout2.addStretch() widget = QWidget() widget.setObjectName(str(int(quantity.text()) * round(float(food_price_label.text()), 2))) widget.setLayout(hlayout2) delete.mousePressEvent = functools.partial(self.delete_bill_item, source_object=widget) # widget2.mousePressEvent = functools.partial(self.mouse_pressed, source_object=hlayout2) # self.right_content.addWidget(widget) self.right_content.insertWidget(self.right_content.count() - 3, widget) # self.right_content.addStretch() self.total += int(quantity.text()) * round(float(food_price_label.text()), 2) self.total_amount.setText("Total: " + str(self.total)) self.food_order.append(quantity.text() + " X " + food_label.text() + " = " + food_price_label.text()) print("\nAdded") print(self.food_order) # print(widget.findChildren(QLabel)[0].text()) # print(widget.findChildren(QLabel)[2].text()) def delete_bill_item(self, event, source_object=None): print("Delete here") print(source_object.objectName()) self.total -= float(source_object.objectName()) self.food_order.remove(source_object.findChildren(QLabel)[0].text() + " X " + source_object.findChildren(QLabel)[2].text() + " = " + source_object.findChildren(QLabel)[3].text()) print("\nDeleted") print(self.food_order) self.total_amount.setText("Total: " + str(self.total)) source_object.setParent(None)
class AddBillDetails(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setMinimumWidth(430) # frame.setFixedHeight(395) frame.setStyleSheet("border: none") add_employee_button = QLabel(frame) add_employee_button.setAlignment(Qt.AlignCenter) add_employee_button.setGeometry(QRect(110, 30, 210, 41)) add_employee_button.setStyleSheet( "font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") add_employee_button.setText("Add Bill Details") foodname = QLabel(frame) foodname.setText("Food Name") foodname.setGeometry(QRect(50, 100, 75, 13)) self.nametextbox = QLineEdit(frame) self.nametextbox.setGeometry(QRect(160, 90, 181, 31)) self.nametextbox.setFixedWidth(180) foodcategory = QLabel(frame) foodcategory.setText("Category") foodcategory.setGeometry(QRect(50, 140, 61, 16)) categories = self.get_all_category() self.category_list = QComboBox(frame) self.category_list.setGeometry(QRect(160, 130, 181, 31)) self.category_list.setFixedWidth(180) self.category_list.addItems(categories) pricelabel = QLabel(frame) pricelabel.setText("Price") pricelabel.setGeometry(QRect(50, 180, 47, 13)) self.pricetextbox = QLineEdit(frame) self.pricetextbox.setGeometry(QRect(160, 170, 181, 31)) self.pricetextbox.setFixedWidth(180) self.pricetextbox.setValidator(QDoubleValidator()) joindatelabel = QLabel(frame) joindatelabel.setText("Start Date") joindatelabel.setGeometry(QRect(80, 260, 71, 16)) self.addbutton = QPushButton(frame) self.addbutton.setText("Add Item") self.addbutton.setGeometry(QRect(160, 300, 111, 31)) self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") self.addbutton.clicked.connect(self.add_button_click) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(frame) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) # self.setLayout(layout) self.setWindowTitle("Add Employee Details") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def add_button_click(self): print("Button Clicked") print(self.nametextbox.text()) print(self.category_list.currentText()) print(self.pricetextbox.text()) food_name = self.nametextbox.text() price = self.pricetextbox.text() query = "select id from category where category_name=%s limit 1" values = (self.category_list.currentText(), ) result = self.db.fetch(query, values) for (id) in result: category_id = id[0] ''' All set up.. Now query to add the item in the database. Also format the decimal place. ''' query = "insert into menu (food_name, price, category_id)" \ "values (%s, %s, %s);" values = (food_name, price, category_id) result = self.db.execute(query, values) self.closeEvent = self.message() def message(self): self.closing.emit(1) self.close()
class Bill(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "bills" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() add_and_search = AddSearchFrame(in_class) add_and_search.add_button.clicked.connect( lambda: self.add_bill(in_class)) add_and_search.search_button.clicked.connect( lambda: self.search_bill(add_and_search.search_box)) self.table = QTableWidget() self.table.setColumnCount(7) # self.table.setStyleSheet("border: none") # self.table.setStyleSheet( # "background-color: rgb(255, 255, 255);\n" # 'font: 10pt "MS Shell Dlg 2";\n' # "color: rgb(30, 45, 66);" # ) # self.table.setHorizontalHeaderItem(0, QTableWidgetItem("ID")) self.table.setHorizontalHeaderItem(0, QTableWidgetItem("Table Number")) self.table.setHorizontalHeaderItem(1, QTableWidgetItem("Food List")) self.table.setHorizontalHeaderItem(2, QTableWidgetItem("total_price")) self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Paid")) self.table.setHorizontalHeaderItem(4, QTableWidgetItem("Edit")) self.table.setHorizontalHeaderItem(5, QTableWidgetItem("Delete")) self.table.setHorizontalHeaderItem(6, QTableWidgetItem("Paid")) data = self.load_bill_data() print(data) for x in data: print(x) self.populate_table(data) self.table.resizeColumnsToContents() layout = QVBoxLayout() layout.addWidget(header) layout.addWidget(add_and_search) layout.addWidget(self.table) # layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) # self.resize(800, 600) self.setWindowTitle("Login") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: self.hide() view = sidebar.Table(self) elif value == 4: self.hide() view = sidebar.Reservations(self) elif value == 5: pass elif value == 6: self.hide() view = sidebar.Settings(self) elif value == 7: self.hide() view = sidebar.Orders(self) elif value == 8: self.hide() view = sidebar.Menu(self) def load_bill_data(self): query = "select orders.id, table_number, food_list, total_price, paid from orders " \ "join tables on tables.id = orders.table_id" result = self.db.fetch(query) return result ''' This function is called after an employee has been added and returns only the last row. ''' def add_update_bill_data(self): query = "select orders.id, table_number, food_list, total_price, paid from orders " \ "join tables on tables.id = orders.table_id " \ "order by id desc limit 1;" result = self.db.fetch(query) return result def edit_bill(self): emp_row = self.table.indexAt(self.sender().pos()) print(emp_row.row()) def delete_bill(self): emp_row = self.table.indexAt(self.sender().pos()) # print(emp_row.row()) # print(emp_row.column()) # print(self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) # print(id) # print(emp_row.child(emp_row.row(), emp_row.column())) query = "DELETE FROM orders WHERE id=%s" values = (id, ) result = self.db.execute(query, values) self.table.clearContents() self.table.setRowCount(0) data = self.load_bill_data() self.populate_table(data) def add_bill(self, where): if where == "category": print("Category Button Clicked from category") view = AddCategoryDetails(self) view.closing.connect(self.update_bill) elif where == "stocks": print("Stock Button Clicked") def search_bill(self, search_obj): search = search_obj.text() search_obj.setText("") print("Search") if search != "": query = "select orders.id, table_number, food_list, total_price, paid " \ "from orders join tables on tables.id = orders.table_id " \ "and tables.table_number like %s;" values = ("%" + search + "%", ) else: query = "SELECT orders.id, table_number, food_list, total_price, paid FROM orders " \ "join tables on tables.id = orders.table_id" values = () self.table.clearContents() self.table.setRowCount(0) data = self.db.fetch(query, values) self.populate_table(data) self.table.resizeColumnsToContents() def paid_bill(self): emp_row = self.table.indexAt(self.sender().pos()) # print(emp_row.row()) # print(emp_row.column()) # print(self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) id = int( self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) print(emp_row) print(id) query = "update orders set paid = 'yes' where id = %s;" values = (id, ) result = self.db.execute(query, values) self.table.clearContents() self.table.setRowCount(0) data = self.load_bill_data() self.populate_table(data) self.table.resizeColumnsToContents() ''' Repopulates the employee table with the updated data. ''' def update_bill(self, check): print("I am here") print(check) data = self.add_update_bill_data() self.populate_table(data) self.table.resizeColumnsToContents() ''' This function populates the employee table with data. ''' def populate_table(self, data): for (id, table_number, food_list, total_price, paid) in data: self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem(str(table_number))) self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(str(food_list))) self.table.setItem(self.table.rowCount() - 1, 2, QTableWidgetItem(str(total_price))) self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(paid))) edit = QPushButton(self.table) edit.setStyleSheet("background-color: rgb(50,205,50);") edit.setText("Edit") edit.adjustSize() edit.clicked.connect(self.edit_bill) self.table.setCellWidget(self.table.rowCount() - 1, 4, edit) delete = QPushButton(self.table) delete.setObjectName(str(id)) delete.setStyleSheet("background-color: #d63447;") delete.setText("Delete") delete.adjustSize() delete.clicked.connect(self.delete_bill) # delete.mousePressEvent = functools.partial(self.delete_emp, source_object=delete) self.table.setCellWidget(self.table.rowCount() - 1, 5, delete) paid = QPushButton(self.table) paid.setObjectName(str(id)) paid.setStyleSheet("background-color: grey;") paid.setText("Paid") paid.adjustSize() paid.clicked.connect(self.paid_bill) # paid.mousePressEvent = functools.partial(self.paid_emp, source_object=paid) self.table.setCellWidget(self.table.rowCount() - 1, 6, paid)
class AddUser(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setFixedWidth(200) # frame.setFixedHeight(150) main_label = QLabel(frame) main_label.setAlignment(Qt.AlignCenter) main_label.setGeometry(QRect(120, 40, 211, 41)) main_label.setStyleSheet("background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);\n" "font: 75 14pt \"MS Shell Dlg 2\";") main_label.setText("Add User Privileges") user_label = QLabel(frame) user_label.setText("User") user_label.setGeometry(QRect(50, 100, 101, 41)) user_label.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") getuserlist = self.get_all_user() self.user_list = QComboBox(frame) self.user_list.addItems(getuserlist) self.user_list.setGeometry(QRect(180, 100, 191, 46)) user_name = QLabel(frame) user_name.setText("Add Username") user_name.setGeometry(QRect(50, 140, 101, 41)) user_name.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.username = QLineEdit(frame) self.username.setGeometry(QRect(180, 140, 191, 35)) user_password = QLabel(frame) user_password.setText("Add Password") user_password.setGeometry(QRect(50, 180, 101, 41)) user_password.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.password = QLineEdit(frame) self.password.setGeometry(QRect(180, 180, 191, 35)) privileges = QLabel(frame) privileges.setText("Privileges") privileges.setGeometry(QRect(50, 210, 101, 41)) privileges.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_1 = QCheckBox(frame) self.option_1.setText("Dashboard") self.option_1.setGeometry(QRect(180, 210, 101, 41)) self.option_1.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_2 = QCheckBox(frame) self.option_2.setText("Employees") self.option_2.setGeometry(QRect(280, 210, 101, 41)) self.option_2.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_3 = QCheckBox(frame) self.option_3.setText("Bill") self.option_3.setGeometry(QRect(180, 235, 101, 41)) self.option_3.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_4 = QCheckBox(frame) self.option_4.setText("Tables") self.option_4.setGeometry(QRect(280, 235, 101, 41)) self.option_4.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_5 = QCheckBox(frame) self.option_5.setText("Reservations") self.option_5.setGeometry(QRect(180, 260, 101, 41)) self.option_5.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_6 = QCheckBox(frame) self.option_6.setText("Category") self.option_6.setGeometry(QRect(280, 260, 101, 41)) self.option_6.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_7 = QCheckBox(frame) self.option_7.setText("Orders") self.option_7.setGeometry(QRect(180, 285, 101, 41)) self.option_7.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_8 = QCheckBox(frame) self.option_8.setText("Settings") self.option_8.setGeometry(QRect(280, 285, 101, 41)) self.option_8.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_9 = QCheckBox(frame) self.option_9.setText("Menu") self.option_9.setGeometry(QRect(180, 310, 101, 41)) self.option_9.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.option_10 = QCheckBox(frame) self.option_10.setText("Users") self.option_10.setGeometry(QRect(280, 310, 101, 41)) self.option_10.setStyleSheet("font: 75 14pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") submit_btn = QPushButton(frame) submit_btn.setText("Submit") submit_btn.setGeometry(QRect(170, 360, 111, 31)) submit_btn.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") submit_btn.clicked.connect(self.add_privileges) layout = QVBoxLayout() layout.addWidget(frame) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setWindowTitle("Add User Privileges") self.resize(430, 450) self.show() self.center() def center(self): ''' centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def add_privileges(self): print("List the selected privileges.") selected_privileges = [] if self.option_1.isChecked(): selected_privileges.append(self.option_1.text()) if self.option_2.isChecked(): selected_privileges.append(self.option_2.text()) if self.option_3.isChecked(): selected_privileges.append(self.option_3.text()) if self.option_4.isChecked(): selected_privileges.append(self.option_4.text()) if self.option_5.isChecked(): selected_privileges.append(self.option_5.text()) if self.option_6.isChecked(): selected_privileges.append(self.option_6.text()) if self.option_7.isChecked(): selected_privileges.append(self.option_7.text()) if self.option_8.isChecked(): selected_privileges.append(self.option_8.text()) print(self.user_list.currentText()) print(self.username.text()) print(self.password.text()) print(selected_privileges) ''' All ready here.. Add the query to the database. ''' query = "insert into admin (admin_name, password, roles) " \ "values (%s, %s, %s)" values = (self.username.text(), self.password.text(), ', '.join(selected_privileges)) data = self.db.execute(query, values) self.closeEvent = self.message() def message(self): # self.closing.emit(1) self.close() def get_all_user(self): query = "select employee_name, job_title from employee" values = () data = self.db.fetch(query, values) list = [] for (employee_name, job_title) in data: print(employee_name + " (" + job_title + ")") list.append(employee_name + " (" + job_title + ")") return list
class ChangePassword(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setFixedWidth(200) # frame.setFixedHeight(150) main_label = QLabel(frame) main_label.setAlignment(Qt.AlignCenter) main_label.setGeometry(QRect(120, 40, 211, 41)) main_label.setStyleSheet("background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);\n" "font: 75 14pt \"MS Shell Dlg 2\";") main_label.setText("Change Password") old_passwordlabel = QLabel(frame) old_passwordlabel.setText("Old Password") old_passwordlabel.setGeometry(QRect(50, 140, 101, 41)) old_passwordlabel.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.old_passwordtextbox = QLineEdit(frame) self.old_passwordtextbox.setGeometry(QRect(180, 140, 191, 41)) new_passwordlabel = QLabel(frame) new_passwordlabel.setText("New Password") new_passwordlabel.setGeometry(QRect(50, 190, 101, 41)) new_passwordlabel.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") self.new_passwordtextbox = QLineEdit(frame) self.new_passwordtextbox.setGeometry(QRect(180, 190, 191, 41)) self.error_msg = QLabel(frame) self.error_msg.setText("") self.error_msg.setGeometry(QRect(170, 250, 121, 41)) self.error_msg.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "color: rgb(30, 45, 66);") submit_btn = QPushButton(frame) submit_btn.setText("Submit") submit_btn.setGeometry(QRect(170, 310, 111, 31)) submit_btn.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") submit_btn.clicked.connect(self.update_password) layout = QVBoxLayout() layout.addWidget(frame) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setWindowTitle("Change Password") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def update_password(self): print("Update password") ''' 1. Check which user is logged in. 2. Change the password of the logged in user. ''' old_password = self.old_passwordtextbox.text() new_password = self.new_passwordtextbox.text() if old_password != '' and new_password != '': query = "select admin_name, password from admin where logged_in='yes'" values = () data = self.db.fetch(query, values) for (admin_name, password) in data: match_password = password if match_password == old_password: query = "update admin set password=%s where logged_in='yes'" values = (new_password, ) data = self.db.execute(query, values) self.error_msg.setText("Password updated") else: ''' Update the label here with the error message. ''' self.error_msg.setText("Password Wrong")
class RestaurantDetails(QFrame): def __init__(self): super().__init__() self.db = DB() self.initUI() def initUI(self): frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) frame.setMinimumWidth(200) frame.setFixedHeight(150) frame.setStyleSheet("border: none") details = self.get_restaurant_details() restname = QLabel(frame) # restname.setAlignment(Qt.AlignCenter) restname.setGeometry(QRect(100, 0, 300, 41)) restname.setStyleSheet("color: rgb(30, 45, 66);" 'font: 75 16pt "MS Shell Dlg 2";') restname.setText(details[0]) address = QLabel(frame) # address.setAlignment(Qt.AlignCenter) address.setGeometry(QRect(100, 40, 300, 41)) address.setStyleSheet("color: rgb(30, 45, 66);" 'font: 75 16pt "MS Shell Dlg 2";') address.setText(details[1]) number = QLabel(frame) # number.setAlignment(Qt.AlignCenter) number.setGeometry(QRect(100, 80, 300, 41)) number.setStyleSheet("color: rgb(30, 45, 66);" 'font: 75 16pt "MS Shell Dlg 2";') number.setText(details[2]) layout = QVBoxLayout() layout.addWidget(frame) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) # self.setGeometry(QRect(30, 5, 200, 150)) # self.setStyleSheet("border: none") def get_restaurant_details(self): query = "select restaurant_name, address, contact from rest_info" values = () data = self.db.fetch(query, values) for (restaurant_name, address, contact) in data: restaurant_name = restaurant_name address = address contact = contact return [restaurant_name, address, contact]
def __init__(self): super().__init__() self.db = DB() self.initUI()
class Menu(QMainWindow): def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI() def initUI(self): in_class = "menu" self.sidebar = sidebar.Sidebar(self) self.sidebar.window.connect(self.getvalue) self.addDockWidget(Qt.LeftDockWidgetArea, self.sidebar) header = AppName(in_class) footer = Footer() add_and_search = AddSearchFrame(in_class) add_and_search.add_button.clicked.connect(lambda: self.add_menu(in_class)) add_and_search.search_button.clicked.connect( lambda: self.search_menu(add_and_search.search_box)) self.table = QTableWidget() self.table.setColumnCount(5) # self.table.setStyleSheet("border: none") # self.table.setStyleSheet( # "background-color: rgb(255, 255, 255);\n" # 'font: 10pt "MS Shell Dlg 2";\n' # "color: rgb(30, 45, 66);" # ) # self.table.setHorizontalHeaderItem(0, QTableWidgetItem("ID")) self.table.setHorizontalHeaderItem(0, QTableWidgetItem("Food")) self.table.setHorizontalHeaderItem(1, QTableWidgetItem("Category")) self.table.setHorizontalHeaderItem(2, QTableWidgetItem("Price")) # self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Bonus")) # self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Joining Date")) # self.table.setHorizontalHeaderItem(6, QTableWidgetItem("Total Salary")) self.table.setHorizontalHeaderItem(3, QTableWidgetItem("Edit")) self.table.setHorizontalHeaderItem(4, QTableWidgetItem("Delete")) data = self.load_menu_data() print(data) for x in data: print(x) self.populate_table(data) self.table.resizeColumnsToContents() layout = QVBoxLayout() layout.addWidget(header) layout.addWidget(add_and_search) layout.addWidget(self.table) # layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) # self.resize(800, 600) self.setWindowTitle("Employee") self.resize(1160, 605) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def getvalue(self, value): print(value) print(type(value)) if value == 1: self.hide() view = sidebar.Dashboard(self) elif value == 2: self.hide() view = sidebar.Employee(self) elif value == 3: self.hide() view = sidebar.Table(self) elif value == 4: self.hide() view = sidebar.Reservations(self) elif value == 5: pass elif value == 6: self.hide() view = sidebar.Settings(self) elif value == 7: self.hide() view = sidebar.Orders(self) elif value == 8: self.hide() view = sidebar.Menu(self) elif value == 9: self.hide() view = sidebar.Bill(self) def load_menu_data(self): query = "SELECT food_name, price, category_name FROM menu " \ "join category on menu.category_id = category.id order by category_name" result = self.db.fetch(query) return result ''' This function is called after an employee has been added and returns only the last row. ''' def add_update_menu_data(self): query = "SELECT food_name, price, category_name FROM menu " \ "join category on menu.category_id = category.id " \ "order by id desc limit 1;" result = self.db.fetch(query) return result def edit_menu(self): emp_row = self.table.indexAt(self.sender().pos()) id = self.table.cellWidget(emp_row.row(), emp_row.column()).objectName() print(emp_row.row()) print(id) print(type(id)) ''' Get the data from the database for that user. ''' data = self.get_data(id) print("Data") print(data) # print(type(data[4])) view = AddMenuDetails(self, "update", data[0]) view.nametextbox.setText(data[0]) view.pricetextbox.setText(str(data[1])) category = self.get_category(data[2]) view.category_list.setCurrentText(category) view.closing.connect(self.editupdate_emp) def get_category(self, category): query = "SELECT category_name FROM category " \ "where id=%s" values = (category,) result = self.db.fetch(query, values) for (category) in result: category = category[0] return category def editupdate_emp(self, check): print("I am here") print(check) self.table.clearContents() self.table.setRowCount(0) data = self.load_menu_data() self.populate_table(data) self.table.resizeColumnsToContents() # self.table.resizeColumnsToContents() def get_data(self, id): query = "SELECT food_name, price, category_id FROM menu " \ "where food_name=%s" values = (id,) result = self.db.fetch(query, values) for (food_name, price, category) in result: food_name = food_name price = price category = category return [food_name, price, category] def delete_menu(self): emp_row = self.table.indexAt(self.sender().pos()) # print(emp_row.row()) # print(emp_row.column()) # print(self.table.cellWidget(emp_row.row(), emp_row.column()).objectName()) id = self.table.cellWidget(emp_row.row(), emp_row.column()).objectName() # print(id) # print(emp_row.child(emp_row.row(), emp_row.column())) query = "DELETE FROM menu WHERE food_name=%s" values = (id,) result = self.db.execute(query, values) self.table.clearContents() self.table.setRowCount(0) data = self.load_menu_data() self.populate_table(data) def add_menu(self, where): if where == "menu": print("Employee Button Clicked from Menu") view = AddMenuDetails(self, "add") view.closing.connect(self.update_menu) elif where == "stocks": print("Stock Button Clicked") def search_menu(self, search_obj): search = search_obj.text() search_obj.setText("") print("Search") if search != "": query = "SELECT * FROM menu WHERE food_name like %s" values = ("%" + search + "%",) else: query = "SELECT * FROM menu" values = () self.table.clearContents() self.table.setRowCount(0) data = self.db.fetch(query, values) self.populate_table(data) ''' Repopulates the employee table with the updated data. ''' def update_menu(self, check): print("I am here") print(check) self.table.clearContents() self.table.setRowCount(0) data = self.load_menu_data() self.populate_table(data) ''' This function populates the employee table with data. ''' def populate_table(self, data): for (food_name, price, category_name) in data: self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount() - 1, 0, QTableWidgetItem(str(food_name))) self.table.setItem(self.table.rowCount() - 1, 1, QTableWidgetItem(str(category_name))) self.table.setItem(self.table.rowCount() - 1, 2, QTableWidgetItem(str(price))) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(bonus))) # self.table.setItem(self.table.rowCount() - 1, 3, QTableWidgetItem(str(joining_date.strftime("%d-%m-%Y")))) edit = QPushButton(self.table) edit.setObjectName(str(food_name)) edit.setStyleSheet("background-color: rgb(50,205,50);") edit.setText("Edit") edit.adjustSize() edit.clicked.connect(self.edit_menu) self.table.setCellWidget(self.table.rowCount() - 1, 3, edit) delete = QPushButton(self.table) delete.setObjectName(str(food_name)) delete.setStyleSheet("background-color: #d63447;") delete.setText("Delete") delete.adjustSize() delete.clicked.connect(self.delete_menu) # delete.mousePressEvent = functools.partial(self.delete_menu, source_object=delete) self.table.setCellWidget(self.table.rowCount() - 1, 4, delete)
class AddTableDetails(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent, update, id=None): super().__init__(parent) self.db = DB() self.initUI(update, id) def initUI(self, update, id): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setMinimumWidth(430) # frame.setFixedHeight(395) frame.setStyleSheet("border: none") add_employee_button = QLabel(frame) add_employee_button.setAlignment(Qt.AlignCenter) add_employee_button.setGeometry(QRect(110, 30, 210, 41)) add_employee_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") add_employee_button.setText("Add Table Details") tablenolabel = QLabel(frame) tablenolabel.setText("Table No.") tablenolabel.setGeometry(QRect(80, 170, 60, 13)) self.tablenotextbox = QLineEdit(frame) self.tablenotextbox.setGeometry(QRect(170, 160, 181, 31)) self.tablenotextbox.setFixedWidth(180) coverlabel = QLabel(frame) coverlabel.setText("Cover") coverlabel.setGeometry(QRect(80, 220, 47, 13)) self.covertextbox = QLineEdit(frame) self.covertextbox.setGeometry(QRect(170, 210, 181, 31)) self.covertextbox.setFixedWidth(180) self.covertextbox.setValidator(QIntValidator()) self.addbutton = QPushButton(frame) self.addbutton.setGeometry(QRect(160, 300, 111, 31)) self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") # self.addbutton.clicked.connect(lambda: self.add_button_click("tables")) if update == 'add': print("Add") print(id) self.addbutton.setText("Add Table") self.addbutton.clicked.connect(lambda: self.add_button_click("tables")) else: print("Update") print(id) self.addbutton.setText("Update Table") self.addbutton.clicked.connect(lambda: self.update_button_click("tables", id)) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(frame) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) # self.setLayout(layout) self.setWindowTitle("Add Table Details") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def update_button_click(self, where, id): if where == "tables": print("Tables Finally here") table_number = self.tablenotextbox.text() covers = self.covertextbox.text() print(type(table_number)) print(type(covers)) print(table_number) print(covers) if table_number != "" and covers != "": query = "update tables set `table_number`=%s, `covers`=%s" \ "where id=%s;" values = (table_number, covers, id) result = self.db.execute(query, values) self.closeEvent = self.message() def add_button_click(self, where): if where == "tables": print("Tables Finally here") table_number = self.tablenotextbox.text() covers = self.covertextbox.text() print(type(table_number)) print(type(covers)) print(table_number) print(covers) if table_number != "" and covers != "": query = "insert into tables (`table_number`, `covers`)" \ "values (%s, %s);" values = (table_number, covers) result = self.db.execute(query, values) self.closeEvent = self.message() def message(self): self.closing.emit(1) self.close()
def __init__(self, parent): super().__init__(parent) self.db = DB() self.initUI()
class Admin: # Admin class constructor for initalizaing the object def __init__(self, id=None, name=None, password=None): # Database Class object for communication with database; will be used down in the function self._db = DB() # Id of admin used for database primary key self.id = id # name of admin self.name = name # password of admin self.password = password # login function for the admin class; It true if name and password matches otherwise returns false def login(self): query = "SELECT * FROM admin where admin_name=%s and password=%s" db = DB() values = (self.name, self.password) result = db.fetch(query, values) if result: self.id = result[0][0] self.name = result[0][1] self.password = result[0][2] return True return False def login(self, name, password): query = "update admin set logged_in='no' where logged_in='yes'" db = DB() values = (self.name, self.password) self.name = name self.password = password query = "SELECT * FROM admin where admin_name=%s and password=%s" db = DB() values = (self.name, self.password) result = db.fetch(query, values) if result: self.id = result[0][0] self.name = result[0][1] self.password = result[0][2] return True return False # Change password function for admin; It returns nothing def changePwd(self, newPwd): query = """UPDATE `admin` SET `password`= %s WHERE id = %s;""" values = (newPwd, self.id) self._db.execute(query, values) # Function that updates the restaurent information in the database; It returns nothing def updateRestaurentDetail(self, name, address, contact): query = """UPDATE `rest_info` SET `name`= %s, `address`= %s, `contact`= %s WHERE id = %s;""" values = (name, address, contact, 1) self._db.execute(query, values) # It is a static function of admin class that is use get the Restaurent # information from the database; It returns the restaurent information @staticmethod def getRestDetails(): query = "SELECT * FROM rest_info where id=%s" db = DB() values = (1, ) result = db.fetch(query, values) return result # It is a static function that Counts the Number of order from the database; It returns the value of orders count @staticmethod def getOrdersCounts(): query = "SELECT Count(id) FROM `order`" db = DB() result = db.fetch(query) return result[0][0] # It is a static function that calculate the sum of total sales; It returns the value of total sale @staticmethod def getTotalSale(): query = "SELECT SUM(product.selling_price*product_order.quantity) FROM product_order JOIN product ON product_order.product_id=product.id;" db = DB() result = db.fetch(query) if result: return result[0][0] return None # It is a static function that calculate the sum of profit i.e. # For each order calculate the profit for individual product and then sum it; It returns the value of total profit @staticmethod def getTotalProfit(): query = "SELECT SUM((product.selling_price-product.price)*product_order.quantity) FROM product_order JOIN product ON product_order.product_id=product.id;" db = DB() result = db.fetch(query) if result: return result[0][0] return None
class Login(QMainWindow): def __init__(self): super().__init__() self.db = DB() self.initUI() def initUI(self): # sidebar = Sidebar(self) # self.addDockWidget(Qt.LeftDockWidgetArea, sidebar) header = AppName("login") footer = Footer() layout = QVBoxLayout() username_row = QHBoxLayout() password_row = QHBoxLayout() login_btn = QHBoxLayout() errorMsg = QHBoxLayout() self.labelUsername = QLabel("Username") self.usernameInput = QLineEdit() self.usernameInput.setFixedWidth(300) self.labelPassword = QLabel("Password") self.passwordInput = QLineEdit() self.passwordInput.setEchoMode(QLineEdit.Password) self.passwordInput.setFixedWidth(300) self.loginBtn = QPushButton("Login") self.loginBtn.setFixedWidth(200) self.loginBtn.setFocusPolicy(Qt.StrongFocus) self.loginBtn.setShortcut("Return") self.loginBtn.clicked.connect(self.loginBtnClicked) self.loginErrorMsg = QLabel("") username_row.addStretch() username_row.addWidget(self.labelUsername) username_row.addWidget(self.usernameInput) username_row.addStretch() password_row.addStretch() password_row.addWidget(self.labelPassword) password_row.addWidget(self.passwordInput) password_row.addStretch() login_btn.addStretch() login_btn.addWidget(self.loginBtn) login_btn.addStretch() errorMsg.addStretch() errorMsg.addWidget(self.loginErrorMsg) errorMsg.addStretch() layout.addWidget(header) # layout.addWidget(frame) layout.addStretch() layout.addLayout(username_row) layout.addLayout(password_row) layout.addLayout(login_btn) layout.addLayout(errorMsg) layout.addStretch() layout.addWidget(footer) layout.setContentsMargins(0, 0, 0, 0) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) self.setContentsMargins(0, 0, 0, 0) self.resize(800, 600) self.setWindowTitle("Login") self.show() self.center() def loginBtnClicked(self): admin = Admin() checkLogin = admin.login(self.usernameInput.text(), self.passwordInput.text()) if checkLogin: # self.loginErrorMsg.setText("Logged In") query = "update admin set logged_in='yes' where admin_name=%s" values = (self.usernameInput.text(), ) data = self.db.execute(query, values) self.hide() loggedin = sidebar.Dashboard(self) else: self.loginErrorMsg.setText("Incorrect Combination") def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
def getRestDetails(): query = "SELECT * FROM rest_info where id=%s" db = DB() values = (1, ) result = db.fetch(query, values) return result
class AddCategoryDetails(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent, update, id=None): super().__init__(parent) self.db = DB() self.initUI(update, id) def initUI(self, update, id): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setMinimumWidth(430) # frame.setFixedHeight(395) frame.setStyleSheet("border: none") add_employee_button = QLabel(frame) add_employee_button.setAlignment(Qt.AlignCenter) add_employee_button.setGeometry(QRect(110, 30, 210, 41)) add_employee_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") add_employee_button.setText("Add Category Details") # name = QHBoxLayout() # jobtitle = QHBoxLayout() # salary = QHBoxLayout() # bonus = QHBoxLayout() # joindate = QHBoxLayout() category_name = QLabel(frame) category_name.setText("Category Name") category_name.setGeometry(QRect(45, 100, 95, 13)) self.categorytextbox = QLineEdit(frame) self.categorytextbox.setGeometry(QRect(160, 90, 181, 31)) self.categorytextbox.setFixedWidth(180) self.addbutton = QPushButton(frame) self.addbutton.setText("Add Category") self.addbutton.setGeometry(QRect(160, 300, 151, 31)) self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") # self.addbutton.clicked.connect(lambda: self.add_button_click("tables")) if update == 'add': print("Add") print(id) self.addbutton.setText("Add Category") self.addbutton.clicked.connect(lambda: self.add_button_click("category")) else: print("Update") print(id) self.addbutton.setText("Update Category") self.addbutton.clicked.connect(lambda: self.update_button_click("category", id)) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(frame) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) # self.setLayout(layout) self.setWindowTitle("Add Category Details") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def update_button_click(self, where, id): if where == "category": print("Tables Finally here") category_name = self.categorytextbox.text() if category_name != "": query = "update category set `category_name`=%s" \ "where id=%s;" values = (category_name, id) result = self.db.execute(query, values) self.closeEvent = self.message() def add_button_click(self, where): if where == "category": print("Category Finally here") category_name = self.categorytextbox.text() if category_name != "": query = "insert into category (`category_name`)" \ "values (%s);" values = (category_name,) result = self.db.execute(query, values) self.closeEvent = self.message() def message(self): self.closing.emit(1) self.close() # def closeEvent(self, event): # print("Closed") # self.closing.emit() # # self.parent.update()
class AddEmployeeDetails(QMainWindow): closing = pyqtSignal(int) def __init__(self, parent, update, id=None): super().__init__(parent) self.parent = parent self.db = DB() self.initUI(update, id) def initUI(self, update, id): self.setWindowModality(Qt.ApplicationModal) frame = QFrame() # frame.setStyleSheet("background-color: rgb(30, 45, 66);") frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) # frame.setMinimumWidth(430) # frame.setFixedHeight(395) frame.setStyleSheet("border: none") add_employee_button = QLabel(frame) add_employee_button.setAlignment(Qt.AlignCenter) add_employee_button.setGeometry(QRect(110, 30, 210, 41)) add_employee_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") add_employee_button.setText("Add Employee Details") # name = QHBoxLayout() # jobtitle = QHBoxLayout() # salary = QHBoxLayout() # bonus = QHBoxLayout() # joindate = QHBoxLayout() namelabel = QLabel(frame) namelabel.setText("Name") namelabel.setGeometry(QRect(80, 100, 47, 13)) self.nametextbox = QLineEdit(frame) self.nametextbox.setGeometry(QRect(160, 90, 181, 31)) self.nametextbox.setFixedWidth(180) jobtitlelabel = QLabel(frame) jobtitlelabel.setText("Job Title") jobtitlelabel.setGeometry(QRect(80, 140, 61, 16)) self.jobtitletextbox = QComboBox(frame) self.jobtitletextbox.setGeometry(QRect(160, 130, 181, 31)) self.jobtitletextbox.setFixedWidth(180) self.jobtitletextbox.addItems(["Manager", "Waiter", "Chef", "Security"]) salarylabel = QLabel(frame) salarylabel.setText("Salary") salarylabel.setGeometry(QRect(80, 180, 47, 13)) self.salarytextbox = QLineEdit(frame) self.salarytextbox.setGeometry(QRect(160, 170, 181, 31)) self.salarytextbox.setFixedWidth(180) self.salarytextbox.setValidator(QIntValidator()) # bonuslabel = QLabel(frame) # bonuslabel.setText("Bonus") # bonuslabel.setGeometry(QRect(80, 220, 47, 13)) # bonustextbox = QLineEdit(frame) # bonustextbox.setGeometry(QRect(160, 210, 181, 31)) # bonustextbox.setFixedWidth(180) joindatelabel = QLabel(frame) joindatelabel.setText("Start Date") joindatelabel.setGeometry(QRect(80, 260, 71, 16)) self.joindatetextbox = QDateEdit(frame) self.joindatetextbox.setGeometry(QRect(160, 250, 181, 31)) self.joindatetextbox.setFixedWidth(180) self.joindatetextbox.setDate(QDate.currentDate()) self.joindatetextbox.setMinimumDate(QDate.currentDate()) self.joindatetextbox.setDisplayFormat("dd-MM-yyyy") self.addbutton = QPushButton(frame) self.addbutton.setGeometry(QRect(160, 300, 111, 31)) self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n" "background-color: rgb(30, 45, 66);\n" "color: rgb(255, 255, 255);") if update == 'add': print("Add") print(id) self.addbutton.setText("Add Employee") self.addbutton.clicked.connect(lambda: self.add_button_click("employee")) else: print("Update") print(id) self.addbutton.setText("Update Employee") self.addbutton.clicked.connect(lambda: self.update_button_click("employee", id)) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(frame) centralWidget = QWidget() centralWidget.setLayout(layout) self.setCentralWidget(centralWidget) # self.setLayout(layout) self.setWindowTitle("Add Employee Details") self.resize(430, 395) self.show() self.center() def center(self): '''centers the window on the screen''' screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def update_button_click(self, where, id): if where == "employee": print("Employees Finally here") print(self.nametextbox.text()) print(self.jobtitletextbox.currentText()) print(self.salarytextbox.text()) print(self.joindatetextbox.text()) employee_name = self.nametextbox.text() job_title = self.jobtitletextbox.currentText() salary = self.salarytextbox.text() try: date = datetime.datetime.strptime(self.joindatetextbox.text(), "%d-%m-%Y") joining_date = datetime.datetime.strftime(date, "%Y-%m-%d") except: ''' Make sure to add an error message. ''' return if employee_name != "" and salary != "": query = "update employee set `employee_name`=%s, `job_title`=%s, `salary`=%s, " \ "`joining_date`=%s where id=%s" values = (employee_name, job_title, salary, joining_date, id) result = self.db.execute(query, values) self.closeEvent = self.message() def add_button_click(self, where): if where == "employee": print("Employees Finally here") print(self.nametextbox.text()) print(self.jobtitletextbox.currentText()) print(self.salarytextbox.text()) print(self.joindatetextbox.text()) employee_name = self.nametextbox.text() job_title = self.jobtitletextbox.currentText() salary = self.salarytextbox.text() try: date = datetime.datetime.strptime(self.joindatetextbox.text(), "%d-%m-%Y") joining_date = datetime.datetime.strftime(date, "%Y-%m-%d") except: ''' Make sure to add an error message. ''' return if employee_name != "" and salary != "": query = "insert into employee (`employee_name`, `job_title`,`salary`, `joining_date`)" \ "values (%s, %s, %s, %s);" values = (employee_name, job_title, salary, joining_date) result = self.db.execute(query, values) self.closeEvent = self.message() def message(self): self.closing.emit(1) self.close() # def closeEvent(self, event): # print("Closed") # self.closing.emit() # # self.parent.update()