def onAccept(self): if len(self.editUsername.text()) != 0 and " " not in list( self.editUsername.text()): self.user = User() self.user.name = self.editName.text() self.user.username = self.editUsername.text() self.user.passWord = self.editPass.text() data = Database() try: data.insertUser(self.user) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("Your username has already existed !!!") msg.setInformativeText("Please choose another username !!!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1 return self.isAccept = 1 else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText( "Your username cannot be empty or has space in there !!!") msg.setInformativeText("Please choose another username !!!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1
def onItemCellContentChange(self, row, col): if self.isAddItem: return cell = self.tableItem.item(row, col) print(cell.text()) data = Database() if col == 0: data.updateItemName( self.tableItem.item(row, 1).text(), cell.text()) elif col == 1: try: data.updateItemID(self.beforeItemChange, cell.text()) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID này đã tồn tại !!") msg.setInformativeText( "Xin hãy chọn một ID khác và thử lại !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() data.closeDatabase() return else: data.updateAllTypeHasIDParent(cell.text()) self.onCurrentItemCellChange(row, col, None, None) data.closeDatabase()
def onAccept(self): if len(self.editID.text()) and " " not in list(self.editID.text()): item = Item() item.name = self.editName.text() item.idItem = self.editID.text() data = Database() try: data.insertItem(item) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID này đã tồn tại !!") msg.setInformativeText("Xin hãy chọn một ID khác và thử lại !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1 return self.isAccept = 1 else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID này đã tồn tại !!") msg.setInformativeText("Xin hãy chọn một ID khác và thử lại !!") msg.setStandardButton(QtWidgets.QMessageBox.Ok) exec() self.isAccept = -1
def onAddUser(self): data = Database() user = User() user.name = self.editName.text() user.username = self.editUsername.text() user.passWord = self.editPass.text() try: data.insertUser(user) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("Your username has already existed !!!") msg.setInformativeText("Please choose another username !!!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() return self.addUserIntoTable(user) data.closeDatabase() self.editName.clear() self.editPass.clear() self.editUsername.clear()
def onAccept(self): idBill = self.editID.text() if len(idBill) != 0 and " " not in list(idBill): # Create a new Type Item self.bill = Bill() self.bill.nameItem = self.comboItem.currentText() self.bill.nameType = self.comboType.currentText() self.bill.idBill = idBill self.bill.amount = self.spinAmount.text() if self.radioCustom.isChecked(): self.bill.saleType = self.radioCustom.text() elif self.radioUnit.isChecked(): self.bill.saleType = self.radioUnit.text() elif self.radioWhole.isChecked(): self.bill.saleType = self.radioWhole.text() self.bill.price = self.editPrice.text() date = self.dateTimeEdit.date() time = self.dateTimeEdit.time() date = date.toString("dd/MM/yyyy") time = time.toString("hh:mm:ss") self.bill.createdDate = date self.bill.createdTime = time self.bill.createdUser = self.userCreate self.bill.notice = self.textNotice.toPlainText() # Add new Bill into database data = Database() try: data.insertBill(self.bill) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID này đã được một tài khoản khác sử dụng !!") msg.setText("Xin hãy chọn một ID khác !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1 return maxAmount = self.spinAmount.maximum() existedAmount = int(maxAmount) - int(self.spinAmount.text()) print(existedAmount) data.updateTypeAmount(self.footerID, existedAmount) self.isAccept = 1 else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID Không thể để trống hoặc có chứa khoảng trắng !!!") msg.setInformativeText( "Xin hãy thêm một ID hoặc xóa dấu khoảng trắng !!!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1
def onExportExcelBillFile(self): self.filePath = filedialog.asksaveasfile( title="Choose where you want to save File", filetypes=(("Microsoft Excel", "*.xlsx"), ("All Files", "*.*"))) if self.filePath == None: return wb = Workbook() ws = wb.active data = Database() listBill = data.getBillList() listDate = [listBill[0].CreatedDate] for bill in listBill: if bill.CreatedDate not in listDate: listDate.append(bill.CreatedDate) for date in listDate: listBillAtDate = data.getListBillAtDate(date) ws = createSheetAsDate(wb, date) createTitleBillInDate(ws, date) adjustColumn(ws) addBillIntoSheet(ws, listBillAtDate) wb.remove_sheet(wb.active) wb.save(self.filePath.name)
def setupWidget(self): style = """ QTreeWidget::item:!selected{ border-bottom: 1px solid black; border-left: 1px solid black; border-top: 1px solid black; padding: 5px; } QTreeWidget::item:selected{} """ self.treeBill.setStyleSheet(style) listAttribute = [ "Item Name", "Type Name", "ID", "Amount", "Sale Type", "Price", "Created Date", "Created Time", "Notice" ] for attribute in listAttribute: self.comboFilter.addItem(attribute) data = Database() listBill = data.getAllListBill() for bill in listBill: self.addBillIntoTree(bill) data.closeDatabase() self.comboFilter.setCurrentIndex(0) self.listHistories = self.loadHistories() self.completer = QtWidgets.QCompleter(self.listHistories) self.editFind.setCompleter(self.completer)
def loadDataForHomePage(self): data = Database() date = datetime.datetime.now().date().strftime("%d/%m/%Y") listBill = data.getListBillAtDate(str(date)) for bill in listBill: self.addItemIntoTree(bill) data.closeDatabase()
def __init__(self, *args, **kwargs): Tk.__init__(self, *args, **kwargs) self.title("Managing Selling App") self.frame = [] self.data = Database() frame = LoginScreen(self) self.showFrame(frame)
def onAccept(self): data = Database() if self.nameEditted: nameChanged = self.editName.text() data.updateNameOfUser(self.username, nameChanged) if self.passEditted: passChanged = self.editPass.text() data.updatePassOfUser(self.username, passChanged)
def __init__(self, parent): self.parent = parent self.data = Database() self.listBill = self.data.getBillList() self.dialog = Toplevel(parent) self.dialog.title("Bảng thống kê Hóa đơn") self.dialog.geometry("1000x400") self.drawDialog(self.dialog)
def __init__(self, master): self.dialog = Toplevel(master) self.dialog.resizable(0, 0) self.master = master self.data = Database() self.user = None self.drawDialog(self.dialog) self.dialog.bind_all("<Escape>", self.onCancel) self.dialog.bind_all("<Return>", self.onCreateAccount)
def __init__(self, master): self.dialog = Toplevel(master) self.dialog.resizable(0, 0) self.master = master self.data = Database() self.drawDialog(self.dialog) self.linkAccelerator() self.dialog.protocol("WM_DELETE_WINDOW", self.onCancel)
def __init__(self, parent, **kw): Toplevel.__init__(self, parent, **kw) self.parent = parent self.title("Bảng thống kê mặt hàng") self.geometry("600x400") self.data = Database() self.drawDialog() self.linkAccelerator() self.protocol("WM_DELETE_WINDOW", self.quitDialog)
def startFinding(self, index, newHis): data = Database() self.treeBill.clear() # Filter is Item name if index == 0: listResult = data.getListBillWithItemName(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Type name if index == 1: listResult = data.getListBillWithTypeName(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is ID if index == 2: listResult = data.getListBillWithIDBill(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Amount if index == 3: listResult = data.getListBillWithAmount(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Sale Type if index == 4: listResult = data.getListBillWithSaleType(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Price if index == 5: listResult = data.getListBillWithPrice(newHis) for bill in listResult: self.addBillIntoTree(bill) # # Filter is Created User # if index == 6: # listResult = data.getListBillWithUserCreate(newHis) # for bill in listResult: # self.addBillIntoTree(bill) # Filter is Created Date if index == 6: listResult = data.getListBillAtDate(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Created Time if index == 7: listResult = data.getListBillAtTime(newHis) for bill in listResult: self.addBillIntoTree(bill) # Filter is Notice if index == 8: listResult = data.getListBillWithNotice(newHis) for bill in listResult: self.addBillIntoTree(bill) data.closeDatabase()
def checkAccount(self): username = self.editUsername.text() passWord = self.editPassword.text() data = Database() user = data.getUserInfo(username) if user.username == username and user.passWord == passWord: data.closeDatabase() return True else: data.closeDatabase() return False
def __init__(self, parent, username): Frame.__init__(self, parent) self.parent = parent self.data = Database() self.userCreate = username self.drawScreen() self.linkAccelerator() date = datetime.datetime.now().date().strftime("%d-%m-%Y") self.listBill = self.data.getListBillAtDate(date) for bill in self.listBill: self.addBillIntoTree(bill)
def __init__(self, parent, item, dialog): Frame.__init__(self, parent) self.parent = parent self.item = item self.numTypeAdded = 0 self.dialogParent = dialog self.listType = item.type self.data = Database() self.drawScreen() self.linkAccelerator() for typeItem in self.listType: self.addTypeIntoTree(typeItem)
def __init__(self, master): self.dialog = Toplevel(master) self.dialog.resizable(0, 0) self.dialog.title("Thêm hóa đơn") self.master = master self.headerID = "##" self.footerID = "##" self.tempPrice = IntVar() self.unitPrice = 0 self.amountOfType = 0 self.data = Database() self.listItem = self.data.getItemList() self.drawDialog(self.dialog) self.dialog.bind_all("<Escape>", self.onCancel) self.dialog.bind_all("<Return>", self.onAddBill)
def onDeleteUser(self): rowDelete = self.tableUser.currentRow() print(rowDelete) if rowDelete == 0: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Critical) msg.setWindowTitle("Delete This User ??") msg.setText("You can not delete Root user ") msg.setInformativeText("Please try again with the other user !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() return if rowDelete == -1: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Critical) msg.setWindowTitle("Which User ??") msg.setText("You have not choose user you wanna delete ") msg.setInformativeText("Please choose one user to delete!!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() return def message(i): if i.text() == "&Cancel": self.isAcceptDelete = False elif i.text() == "&OK": self.isAcceptDelete = True msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Question) msg.setWindowTitle("Delete This User ??") msg.setText("You really want to delete this user ??") msg.setInformativeText( "You can not undo this process!! Really want to do this ???") msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) msg.buttonClicked.connect(message) msg.exec() if self.isAcceptDelete: print(rowDelete) data = Database() username = self.tableUser.item(rowDelete, 1).text() print(username) data.deleteUser(username) self.tableUser.removeRow(rowDelete) else: return
def setupWidget(self): data = Database() user = data.getUserInfo(self.username) self.btnEditName.setIcon(QtGui.QIcon("./Icon/icons8-pencil-26.png")) self.btnEditName.setIconSize(QtCore.QSize(16, 16)) self.btnEditPass.setIcon(QtGui.QIcon("./Icon/icons8-pencil-26.png")) self.btnEditPass.setIconSize(QtCore.QSize(16, 16)) self.editName.setText(user.name) self.editUsername.setText(user.username) self.editPass.setText(user.passWord) self.editName.setReadOnly(True) self.editUsername.setReadOnly(True) self.editPass.setReadOnly(True)
def __init__(self,parent,**kw): Toplevel.__init__(self,parent,**kw) self.parent = parent self.numberTempUserAdd = 0 self.data = Database() self.listUser = self.data.getUserList() self.menu = Menu(self) self.config(menu = self.menu) self.drawMenu(self.menu) self.drawDialog() for user in self.listUser: self.addUserIntoTree(user) self.linkAccelerator()
def onAddType(self): if self.comboFilter.currentIndex() > 1: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Critical) msg.setText("Bạn hiện đang ở chế độ tìm kiếm !!") msg.setInformativeText( "Thoát khỏi chế độ tìm kiếm để thực hiện chức năng này !!") msg.setDetailedText( "Chọn tìm kiếm với 'Tên mặt hàng' hoặc 'ID mặt hàng' và chọn mặt hàng muốn thêm để thoát khỏi chế độ tìm kiếm!!" ) msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() return row = self.tableItem.currentRow() if row >= 0: idParent = self.tableItem.item(row, 1).text() date = datetime.datetime.now() newId = "TY-" + date.strftime("%d%m%Y%H%M%S") newType = TypeItem(idType=newId, idParent=idParent, amount=0, unitPrice=0, wholePrice=0, originPrice=0) data = Database() while True: try: data.insertTypeItem(newType) except sqlite3.IntegrityError: date = date + datetime.timedelta(0, 1) newId = "TY-" + date.strftime("%d%m%Y%H%M%S") newType.idType = newId else: break data.closeDatabase() self.addTypeIntoTable(newType) else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("Bạn muốn thực hiện điều này trong mặt hàng nào !!") msg.setInformativeText( "Xin hãy chọn một mặt hàng trước khi thực hiện !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() return
def exportFileItem(pathFile): if len(pathFile) == 0: return wb = Workbook() ws = wb.active data = Database() listItem = data.getListItem() for item in listItem: ws = createSheetAsItem(wb,item) createTitleTypeItem(ws, item) addTypeIntoSheet(ws,item.listType) adjustColumn(ws) wb.remove_sheet(wb.active) wb.save(pathFile)
def SetupWidget(self): data = Database() self.listItem = data.getListItemWithoutType() for item in self.listItem: self.comboItem.addItem(item.name) data.closeDatabase() self.spinAmount.setMinimum(0) self.spinAmount.setMaximum(10**9) self.btnBrowse.setIcon( QtGui.QIcon("Image/icons8-browse-folder-50.png")) self.btnBrowse.setIconSize(QtCore.QSize(16, 16)) date = datetime.datetime.now().strftime("TY-%d%m%Y%H%M%S") self.editID.setText(date)
def onCurrentItemCellChange(self, row, col, prerow, precol): if row != prerow: self.tableType.clearSelection() self.tableType.clearContents() self.tableType.setRowCount(0) if self.tableItem.item(row, 1) == None: return idItem = self.tableItem.item(row, 1).text() data = Database() listType = data.getListTypeHasIDParent(idItem) for typeItem in listType: self.addTypeIntoTable(typeItem) if row == 1: self.beforeItemChange = self.tableItem.item(row, col).text()
def onAddItem(self): date = datetime.datetime.now() newId = "IT-" + date.strftime("%d%m%Y%H%M%S") newItem = Item(idItem=newId) data = Database() while True: try: data.insertItem(newItem) except sqlite3.IntegrityError: date = date + datetime.timedelta(0, 1) newId = "IT-" + date.strftime("%d%m%Y%H%M%S") newItem.idItem = newId else: break data.closeDatabase() self.addItemIntoTable(newItem)
def onExportExcelFile(self): self.filePath = filedialog.asksaveasfile( title="Choose where you want to save File", filetypes=(("Microsoft Excel", "*.xlsx"), ("All Files", "*.*"))) if self.filePath == None: return wb = Workbook() ws = wb.active data = Database() listItem = data.getItemList() for item in listItem: ws = createSheetAsItem(wb, item) createTitleTypeItem(ws, item) adjustColumn(ws) addTypeIntoSheet(ws, item.type) wb.remove_sheet(wb.active) wb.save(self.filePath.name)
def onAccept(self): idType = self.editID.text() if len(idType) != 0 and " " not in list(idType): # Create a new Type Item typeItem = TypeItem() typeItem.name = self.editName.text() typeItem.idType = idType typeItem.idParent = self.listItem[ self.comboItem.currentIndex()].idItem typeItem.amount = self.spinAmount.text() typeItem.unitPrice = self.editUnit.text() typeItem.wholePrice = self.editWhole.text() typeItem.originPrice = self.editOrigin.text() typeItem.imagePath = self.editPath.text() typeItem.notice = self.textNotice.toPlainText() # Add new Type Item into database data = Database() try: data.insertTypeItem(typeItem) except sqlite3.IntegrityError: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID này đã tồn tại !!") msg.setInformativeText( "Xin hãy chọn một ID khác và thử lại !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1 return self.isAccept = 1 else: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("ID Không thể để trống hoặc có chứa khoảng trắng !!") msg.setInformativeText("Xin hãy chọn một ID khác và thử lại !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.isAccept = -1
def onCellChange(self, row, col): dataChange = self.tableUser.item(row, col).text() if col == 1: if dataChange != self.beforeChange: msg = QtWidgets.QMessageBox() msg.setIcon(QtWidgets.QMessageBox.Warning) msg.setText("Không thể sửa Username !!") msg.setInformativeText("Vui lòng thử lại !!") msg.setStandardButtons(QtWidgets.QMessageBox.Ok) msg.exec() self.tableUser.item(row, col).setText(self.beforeChange) return else: return username = self.tableUser.item(row, 1).text() data = Database() if col == 0: data.updateNameOfUser(username, dataChange) if col == 2: data.updatePassOfUser(username, dataChange) data.closeDatabase()