Beispiel #1
0
    def __init__(self):
        self.listIDCom = []
        self.listNameCom = []
        fC = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
        fS = ReadnWriteF.ReadnWrite_File_Sales(self, 'rt')
        fI = ReadnWriteF.ReadnWrite_File_Import_Commodity(self, 'rt')
        for lineCom in fC:
            lineCom = lineCom.split()
            self.listIDCom.append(lineCom[0])
            self.listNameCom.append(lineCom[1])
        fC.close()
        self.sumDataSale = [0 for i in range(len(self.listIDCom))]
        self.sumDataImport = [0 for i in range(len(self.listIDCom))]

        for line in fS:
            lineSal = line.replace('\n', '').strip()
            lineSal = lineSal.split()
            for i in range(len(self.listIDCom)):
                if len(lineSal) > 0:
                    if self.listIDCom[i] == lineSal[0]:
                        self.sumDataSale[i] = self.sumDataSale[i] + int(
                            lineSal[2])
        fS.close()
        for line in fI:
            lineImp = line.replace('\n', '').strip()
            lineImp = lineImp.split()
            for i in range(len(self.listIDCom)):
                if len(lineImp) > 0:
                    if self.listIDCom[i] == lineImp[0]:
                        self.sumDataImport[i] = self.sumDataImport[i] + int(
                            lineImp[2])
        fS.close()

        plt.figure(figsize=(10, 7))
        plt.gcf().canvas.set_window_title('window title')
        x = np.arange(len(self.sumDataSale))
        plt.bar(x,
                self.sumDataImport,
                width=0.3,
                color='green',
                label='Import Commodity')
        plt.bar(x + 0.3,
                self.sumDataSale,
                width=0.3,
                color='blue',
                label='Sale Commodity')
        plt.title('Chào học trò thầy Huấn')
        plt.ylabel('QuantilySales of Commodity', color='red')
        plt.xlabel('Name of Commodity', color='red')
        plt.xticks(x + 0.3 / 2, self.listNameCom)
        plt.legend(loc='best')
        plt.show()
Beispiel #2
0
    def submit(self):
        self.Commodity=self.creatObject()
        if self.Commodity.getCID().isdigit() and self.Commodity.getCQuantily().isdigit() and self.Commodity.getCPrice().isdigit():
            if len(self.Commodity.getCID()) < 3:
                messagebox.showerror('Error', 'ID must have 3 or more numbers')
            elif self.Commodity.getCName() == '' or self.Commodity.getCUnit() == '':
                messagebox.showerror('Error', 'Please enter the full information')
            elif self.checkID(self.Commodity.getCID()) == False:
                messagebox.showerror('Error', 'This ID is available')
                self.outputData()
                self.updateNum()

            else:
                # Add to file
                Write_File = ReadnWriteF.ReadnWrite_File_Commodity(self, 'a')
                Write_File.write(self.Commodity.getCID() + " " + self.Commodity.getCName() + " " + self.Commodity.getCQuantily() + ' ' + self.Commodity.getCUnit() + ' ' + self.Commodity.getCPrice())
                Write_File.write('\n')
                Write_File.close()

                self.outputData()
                # Delete all the entry content
                self.SearchID_Entry.delete(0, 'end')
                self.ID_Entry.delete(0, 'end')
                self.Name_Entry.delete(0, 'end')
                self.Quantily_Entry.delete(0, 'end')
                self.Price_Entry.delete(0, 'end')
                self.Unit_Entry.delete(0, 'end')
        else:
            messagebox.showerror("Error", 'ID, Quantily and Price are number')
Beispiel #3
0
    def update(self):
        self.Commodity=self.creatObject()
        if self.checkclickshow:
            f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'r+')
            d = f.readlines()
            listE = []
            f.seek(0)
            self.creatObject()

            for w in d:
                line = w.split()
                listE.append(line)
            for i in range(len(d)):
                if self.SearchID_Entry.get() == listE[i][0]:
                    d[i] = d[i].replace(listE[i][0], self.Commodity.getCID(), 1)
                    d[i] = d[i].replace(listE[i][1], self.Commodity.getCName(), 1)
                    d[i] = d[i].replace(listE[i][3], self.Commodity.getCUnit(), 1)
                    d[i] = d[i].replace(listE[i][4], self.Commodity.getCPrice(), 1)
                f.write(d[i])
            f.truncate()
            f.close()

            # Delete all the entry content
            self.ID_Entry.delete(0, 'end')
            self.Name_Entry.delete(0, 'end')
            self.Quantily_Entry.delete(0, 'end')
            self.Price_Entry.delete(0, 'end')
            self.SearchID_Entry.delete(0, 'end')
            self.listbox.delete(0, 'end')
            self.Unit_Entry.delete(0, 'end')

            messagebox.showinfo("Done", "You have successfully updated")
            self.checkclickshow = False
        else:
            messagebox.showerror('Error', 'You need to click on ''SHOW'' first')
Beispiel #4
0
 def checkID(self, CID):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
     for line in f:
         line = line.split()
         if len(line) >0:
             if CID == line[0]:
                 return False
     return True
Beispiel #5
0
 def outputData(self):
     self.Commodity = self.creatObject()
     f = ReadnWriteF.ReadnWrite_File_Import_Commodity(self, 'a')
     now = datetime.now()
     f.write(str(now.strftime("%d/%m/%Y %H:%M:%S")) + '\n\n')
     if int(self.Commodity.getCQuantily())>0:
         line=self.Commodity.getCID()+' '+self.Commodity.getCName()+' '+self.Commodity.getCQuantily()+' '+self.Commodity.getCUnit()+' '+self.Commodity.getCPrice()
         f.write(line+'\n')
     f.write('-'*30+'\n')
     f.close()
 def update(self):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
     for i in self.listBox.get_children():
         self.listBox.delete(i)
     for line in f:
         file2 = []
         line = line.split()
         file2.append(line)
         self.show(file2)
     f.close()
     self.ID_Commodity_Entry.delete(0, 'end')
Beispiel #7
0
 def outputData(self):
     f = ReadnWriteF.ReadnWrite_File_Sales(self, 'a')
     now = datetime.now()
     f.write(str(now.strftime("%d/%m/%Y %H:%M:%S")) + '\n\n')
     for i in range(len(self.listName)):
         if int(self.ListQuantily_Entry[i].get()) > 0:
             line = self.listID[i] + ' ' + self.listName[
                 i] + ' ' + self.ListQuantily_Entry[i].get(
                 ) + ' ' + self.listUnit[i] + ' ' + self.listPrice[i]
             f.write(line + '\n')
     f.write('-' * 30 + '\n')
     f.close()
Beispiel #8
0
 def readData(self):
     self.listName = []
     self.listQuantily = []
     self.listPrice = []
     self.listID = []
     self.listUnit = []
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
     for line in f:
         listData = line.split()
         self.listID.append(listData[0])
         self.listName.append(listData[1])
         self.listQuantily.append(listData[2])
         self.listUnit.append(listData[3])
         self.listPrice.append(listData[4])
Beispiel #9
0
 def show(self):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
     listC = []
     self.listbox.delete(0, END)
     for line in f:
         line = line.split()
         listC.append(line)
     flag = False
     for i in range(len(listC)):
         if self.SearchID_Entry.get() == listC[i][0]:
             self.listbox.insert(END, listC[i])
             flag=True
     if flag == False:
         messagebox.showinfo('dsdsd', 'ID chưa có, bạn muốn thêm vào cửa hàng không?')
     f.close()
Beispiel #10
0
 def updateNum(self):
     self.Commodity = self.creatObject()
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'r+')
     d = f.readlines()
     listE=[]
     f.seek(0)
     for w in d:
         line = w.split()
         listE.append(line)
     for i in range(len(d)):
         if self.Commodity.getCID() == listE[i][0]:
             d[i] = d[i].replace(listE[i][2], str(int(listE[i][2])+int(self.Commodity.getCQuantily())), 1)
         f.write(d[i])
     f.truncate()
     f.close()
 def delete(self):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'r+')
     self.cid = self.ID_Commodity_Entry.get()
     if self.cid == '':
         messagebox.showerror('Error', "Please enter ID")
     else:
         d = f.readlines()
         f.seek(0)
         for i in d:
             a = i.split()
             if a[0] != self.cid:
                 f.write(i)
         f.truncate()
     f.close()
     self.ID_Commodity_Entry.delete(0, END)
     self.update()
Beispiel #12
0
 def updateNum(self):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'r+')
     d = f.readlines()
     listE = []
     f.seek(0)
     for w in d:
         line = w.split()
         listE.append(line)
     for i in range(len(d)):
         if self.listID[i] == listE[i][0]:
             d[i] = d[i].replace(
                 listE[i][2],
                 str(
                     int(listE[i][2]) -
                     int(self.ListQuantily_Entry[i].get())), 1)
         f.write(d[i])
     f.truncate()
     f.close()
 def search(self):
     f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
     self.cid = self.ID_Commodity_Entry.get()
     if self.cid == '':
         messagebox.showerror('Error', "Please enter ID")
     else:
         found = False
         for i in self.listBox.get_children():
             self.listBox.delete(i)
         for line in f:
             file2 = []
             line = line.split()
             if (self.cid in line[0]):
                 found = True
                 file2.append(line)
                 self.show(file2)
         if found == False:
             messagebox.showerror('Error', "This ID was not found")
     f.close()
    def __init__(self, master):
        self.master = master
        '''
        Design Heading View
        '''
        self.Heading_View = Frame(
            master,
            bg="#fff5b5",
            bd=4,
        )
        self.Heading_View.place(relx=0.1,
                                rely=0.05,
                                relwidth=0.5,
                                relheight=0.13)

        self.View_Label = Label(self.Heading_View,
                                text="View Commodity",
                                bg='#6b81ff',
                                fg='black',
                                font=('arial bold', 15))
        self.View_Label.place(relx=0, rely=0, relwidth=1, relheight=1)
        '''
        Design ID Commodity
        '''
        self.ID_Commodity_Frame = Frame(master, bg='#6b81ff')
        self.ID_Commodity_Frame.place(relx=0.62,
                                      rely=0.065,
                                      relwidth=0.28,
                                      relheight=0.1)

        self.ID_Commodity_Label = Label(self.ID_Commodity_Frame,
                                        text="ID Commodity: ",
                                        bg='#6b81ff',
                                        fg='white')
        self.ID_Commodity_Label.place(relx=0.05, rely=0.31)

        self.ID_Commodity_Entry = Entry(self.ID_Commodity_Frame)
        self.ID_Commodity_Entry.place(relx=0.4, rely=0.31, relwidth=0.50)
        '''
        Create TreeView
        '''
        #Create list data tempList
        f = ReadnWriteF.ReadnWrite_File_Commodity(self, 'rt')
        tempList = []
        for line in f:
            if len(line) > 0:
                line = line.split()
                tempList.append(line)

        # Create Treeview with 6 columns
        self.cols = ('ID', 'Name', 'Quantily', 'Unit', 'Price')
        self.listBox = ttk.Treeview(master, columns=self.cols, show='headings')
        # set column headings
        for col in self.cols:
            self.listBox.heading(col, text=col)
        self.listBox.place(relx=0.1, rely=0.25, relwidth=0.8, relheight=0.55)
        self.show(tempList)
        '''
        Design Button
        '''
        # Update Button
        self.UpdateBtn = Button(master,
                                text="Update",
                                fg='Green',
                                command=self.update)
        self.UpdateBtn.place(relx=0.44, rely=0.9, relwidth=0.1, relheight=0.08)

        # Delete Button
        self.DelBtn = Button(master,
                             text="Delete",
                             fg='#ffa200',
                             command=self.delete)
        self.DelBtn.place(relx=0.56, rely=0.9, relwidth=0.1, relheight=0.08)

        # Search Button
        self.SearchBtn = Button(master,
                                text="Search",
                                fg='#1900ff',
                                command=self.search)
        self.SearchBtn.place(relx=0.68, rely=0.9, relwidth=0.1, relheight=0.08)

        # Quit Button
        self.QuitBtn = Button(master,
                              text="Quit",
                              fg="Red",
                              command=master.destroy)
        self.QuitBtn.place(relx=0.8, rely=0.9, relwidth=0.1, relheight=0.08)