示例#1
0
class ShowDataWindow(Toplevel):
    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 linkAccelerator(self):
        self.bind_all("<Control-n>", self.onAddItem)
        self.bind_all("<Control-r>", self.onRefresh)

    def drawDialog(self):
        listItem = self.data.getItemList()
        self.table = Notebook(self)

        for item in listItem:
            self.onAddToTab(item)

        self.table.pack(side=LEFT, fill=BOTH, expand=True, padx=5, pady=5)

    def onAddToTab(self, item):
        treeType = TreeType(self.table, item, self)
        self.table.add(treeType, text=item.name)
        self.table.pack()

    def quitDialog(self):
        self.parent.linkAccelerator()
        self.destroy()

    def onRefresh(self, event=None):
        self.table.destroy()
        self.drawDialog()

    def onAddItem(self, event=None):
        if event != None:
            print("Ctrl+N")
        NewItemDialog(self)
示例#2
0
    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)
示例#3
0
class AddBillDialog:
    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 drawDialog(self, dialog):
        layoutSetInfo = Frame(dialog)

        layoutMakeBill = Frame(layoutSetInfo, bd=0, highlightthickness=1)

        self.setBillInfo(layoutMakeBill)

        layoutMakeBill.pack(side=TOP, fill=BOTH, expand=True, pady=10)

        layoutButton = Frame(layoutSetInfo)
        btnAddBill = Button(layoutButton,
                            text="Thêm hóa đơn",
                            command=self.onAddBill)
        btnCancel = Button(layoutButton, text="Hủy", command=self.onCancel)

        btnAddBill.grid(row=0, column=0, columnspan=1)
        btnCancel.grid(row=0, column=1, columnspan=2)
        layoutButton.pack(side=TOP, fill=X, expand=True, pady=10)

        layoutSetInfo.pack(side=LEFT, expand=True, padx=10)

    def setBillInfo(self, parent):
        # Choose Object
        listNameItem = []
        for item in self.listItem:
            listNameItem.append(item.name)

        lblObject = Label(parent, text="Mặt hàng: ")
        self.comboObject = Combobox(parent, values=listNameItem)
        self.comboObject.bind(sequence="<<ComboboxSelected>>",
                              func=self.onChangeComboObjectValues)

        # Choose type of Object
        lblType = Label(parent, text="Loại hàng: ")
        self.comboType = Combobox(parent)
        self.comboType.bind(sequence="<<ComboboxSelected>>",
                            func=self.onChangeComboTypeValues)

        # Input amount of object
        lblAmount = Label(parent, text="Số lượng xuất: ")
        self.entryAmount = Spinbox(parent, textvariable=self.tempPrice)
        self.tempPrice.trace("w", self.onEntryChanged)

        # View The Id of Object
        lblIdTitle = Label(parent, text="ID: ")
        self.lblIdObject = Label(parent, text="##-##")

        # View The Price of one object
        lblPriceTitle = Label(parent, text="Thành giá: ")
        self.lblPrice = Label(parent, text=0)
        lblPriceUnit = Label(parent, text="VND")

        # Choose Date Make Bill
        lblChooseDateTitle = Label(parent, text="Ngày tạo: ")
        self.lblChooseDate = Label(
            parent,
            text=str(datetime.datetime.now().date().strftime("%d-%m-%Y")))

        # Add widgets into grid layout

        lblObject.grid(row=0, column=0, sticky="w", pady=5)
        self.comboObject.grid(row=0, column=1, columnspan=3, pady=5)
        self.comboObject.focus_set()

        lblType.grid(row=1, column=0, sticky="w", pady=5)
        self.comboType.grid(row=1, column=1, columnspan=3, pady=5)

        lblAmount.grid(row=2, column=0, sticky="w", pady=5)
        self.entryAmount.grid(row=2, column=1, columnspan=3, pady=5)

        lblIdTitle.grid(row=3, column=0, sticky="w", pady=5)
        self.lblIdObject.grid(row=3, column=1, sticky="w", pady=5)

        lblPriceTitle.grid(row=4, column=0, sticky="w", pady=5)
        self.lblPrice.grid(row=4, column=1, sticky="w", pady=5)
        lblPriceUnit.grid(row=4, column=3, sticky="w", pady=5)

        lblChooseDateTitle.grid(row=5, column=0, sticky="w", pady=5)
        self.lblChooseDate.grid(row=5, column=1, sticky="w", pady=5)

    def onAddBill(self):
        # sqlite3.IntegrityError
        if self.comboObject.current() == -1:
            messagebox.showwarning("Empty !!!!",
                                   message="Xin hãy chọn một mặt hàng")
            return

        if self.comboType.current() == -1:
            messagebox.showwarning("Empty !!!!",
                                   message="Xin hãy chọn một loại hàng")
            return

        if int(self.entryAmount.get()) > self.amountOfType:
            messagebox.showwarning("Too Large !!!!",
                                   message="Vượt quá số lượng còn lại")
            self.entryAmount.delete(0, END)
            self.entryAmount.insert(0, self.amountOfType)
            return

        if self.amountOfType == 0:
            messagebox.showwarning(
                "Empty !!!!",
                message="Loại hàng này đã hết!!! Xin hãy chọn loại hàng khác")
            return

        if int(self.entryAmount.get()) <= 0 and self.amountOfType != 0:
            messagebox.showwarning("Too Small !!!!",
                                   message="Số lượng xuất quá nhỏ")
            self.entryAmount.delete(0, END)
            self.entryAmount.insert(0, 0)
            return

        bill = BillInfoModel()
        bill.name = self.comboObject.get()
        bill.type = self.comboType.get()
        bill.id = self.lblIdObject["text"]
        bill.amount = int(self.entryAmount.get())
        bill.price = int(self.lblPrice["text"])
        bill.CreatedDate = self.lblChooseDate["text"]
        bill.CreatedTime = datetime.datetime.now().time().strftime("%H:%M:%S")
        bill.CreatedUser = self.master.userCreate

        self.data.insertBill(bill)
        if bill.amount == self.amountOfType:
            answer = messagebox.askquestion(
                "Empty",
                "Loại hàng hiện tại sẽ hết khi bạn xuất hóa đơn \nBạn có muốn xóa luôn loại hàng này không ?"
            )
            if answer == True:
                self.data.deleteType(self.footerID)
            elif answer == False:
                self.data.updateAmountOfType(self.footerID, 0)

        else:
            self.data.updateAmountOfType(self.footerID,
                                         self.amountOfType - bill.amount)

        self.master.addBillIntoTree(bill)
        self.master.treeBill.focus_set()
        self.dialog.destroy()

    def onCancel(self, event=None):
        self.dialog.destroy()

    def onChangeComboObjectValues(self, event=None):
        pos = self.comboObject.current()
        listNameType = []
        self.listType = self.listItem[pos].type
        for typeItem in self.listType:
            listNameType.append(typeItem.name)
        self.comboType.config(values=listNameType)
        self.headerID = self.listItem[pos].id
        self.onChangeID()

    def onChangeComboTypeValues(self, event=None):
        pos = self.comboType.current()
        self.footerID = self.listType[pos].idType
        amount = self.listType[pos].amount
        self.unitPrice = int(self.listType[pos].unitPrice)
        self.amountOfType = amount
        self.lblPrice["text"] = self.unitPrice
        self.onChangeID()

    def onEntryChanged(self, *args):
        temp = int(self.tempPrice.get() * self.unitPrice)
        self.lblPrice['text'] = temp
        # print(self.lblPrice['text'])

    def onChangeID(self):
        temp = self.headerID + "-" + self.footerID
        self.lblIdObject['text'] = temp
示例#4
0
class NewTypeDialog:
    def __init__(self, master):
        self.dialog = Toplevel(master)
        self.dialog.resizable(0, 0)
        self.master = master
        self.data = Database()
        self.itemList = self.data.getItemList()
        self.typeItem = TypeItem()
        self.drawDialog(self.dialog)
        self.linkAccelerator()
        self.dialog.protocol("WM_DELETE_WINDOW", self.onCancel)

    def linkAccelerator(self):
        self.dialog.bind_all("<Escape>", self.onCancel)

    def drawDialog(self, dialog):
        layoutDialog = Frame(dialog)
        listParent = []
        for item in self.itemList:
            listParent.append(item.name)
        # Parent of Type
        lblParentTitle = Label(layoutDialog, text="Thuộc Mặt hàng")
        self.comboParent = Combobox(layoutDialog, values=listParent)
        self.comboParent.bind(sequence="<<ComboboxSelected>>",
                              func=self.onParentSelect)

        # Name Of Type
        lblNameTitle = Label(layoutDialog, text="Tên loại hàng")
        self.entryName = Entry(layoutDialog)

        # ID of Type
        lblIDTitle = Label(layoutDialog, text="Tạo ID")
        self.entryID = Entry(layoutDialog)

        # Amount of Type
        lblAmountTitle = Label(layoutDialog, text="Số lượng nhập")
        self.entryAmount = Entry(layoutDialog)

        # Unit Price of Type
        lblUnitTitle = Label(layoutDialog, text="Đơn giá")
        self.entryUnit = Entry(layoutDialog)

        # Button Create Account and Cancel
        btnAdd = Button(layoutDialog, text="Thêm", command=self.onAddNewType)
        btnCancel = Button(layoutDialog, text="Hủy", command=self.onCancel)

        # Add Widget to Dialog
        lblParentTitle.grid(row=0, column=0, sticky="w", pady=5)
        self.comboParent.grid(row=0, column=1, columnspan=2, pady=5)
        self.comboParent.focus_set()

        lblNameTitle.grid(row=1, column=0, sticky="w", pady=5)
        self.entryName.grid(row=1, column=1, columnspan=2, pady=5)

        lblIDTitle.grid(row=2, column=0, sticky="w", pady=5)
        self.entryID.grid(row=2, column=1, columnspan=2, pady=5)

        lblAmountTitle.grid(row=3, column=0, sticky="w", pady=5)
        self.entryAmount.grid(row=3, column=1, columnspan=2, pady=5)

        lblUnitTitle.grid(row=4, column=0, sticky="w", pady=5)
        self.entryUnit.grid(row=4, column=1, columnspan=2, pady=5)

        btnAdd.grid(row=5, column=0, columnspan=1, pady=10)
        btnCancel.grid(row=5, column=1, columnspan=2, pady=10)

        layoutDialog.pack(fill=BOTH, expand=True, padx=10, pady=10)

    def onAddNewType(self, event=None):
        # sqlite3.IntegrityError
        if not self.entryName.get():
            messagebox.showwarning("Empty !!!!",
                                   message="Tên loại hàng không thể để trống")
            return
        if not self.entryID.get():
            messagebox.showwarning("Empty !!!!",
                                   message="ID không thể để trống")
            return

        self.typeItem.idType = self.entryID.get()
        self.typeItem.unitPrice = self.entryUnit.get()
        self.typeItem.amount = self.entryAmount.get()
        self.typeItem.name = self.entryName.get()
        try:
            self.data.insertTypeItem(self.typeItem)
        except sqlite3.IntegrityError:
            messagebox.showwarning("Opps !!!!",
                                   message="ID bạn nhập đã tồn tại !!!!")
            return

        # listItem = self.data.getItemList()
        # listName = []
        # for item in listItem:
        #     listName.append(item.name)
        # self.master.comboObject.config(values = listName)
        # self.master.listItem = listItem
        self.dialog.destroy()

    def onCancel(self, event=None):
        self.dialog.unbind_all("<Escape>")
        self.dialog.destroy()

    def onParentSelect(self, event=None):
        pos = self.comboParent.current()
        self.typeItem.idParent = self.itemList[pos].id