Ejemplo n.º 1
0
 def __init__(self, slave, nameFirm):
     self.slave = slave
     self.nameFirm = nameFirm
     self.data = Data(self.slave, 'seller', self.nameFirm)
     self.balans = '----'
     self.db = Base('seller')
     self.format = Format()
Ejemplo n.º 2
0
    def __init__(self, slave, name):

        self.name = name
        self.slave = slave
        self.db = Base(name)
        self.format = Format()
        self.var = IntVar()
        self.var.set(1)
        self.sortType = 1
Ejemplo n.º 3
0
    def __init__(self, root):

        #self.loggerFactory = LoggerFactory()
        #self.logger = self.loggerFactory.getLoggers("customer")
        name = 'customer'
        self.root = root
        self.addFirm = Add(name)
        self.db = Base(name)
        self.format = Format()
        self.var = IntVar()
        self.var.set(1)
        self.sortType = 1
Ejemplo n.º 4
0
 def __init__(self, nameParam):
     self.pathdb = os.getcwd()
     self.nameParam = nameParam
     #self.checkDB = self.checkBase()
     self.format = Format()
Ejemplo n.º 5
0
    def __init__(self, paramName):

        self.paramName = paramName
        self.format = Format()
Ejemplo n.º 6
0
class Base():
    def __init__(self, nameParam):
        self.pathdb = os.getcwd()
        self.nameParam = nameParam
        #self.checkDB = self.checkBase()
        self.format = Format()

    def selectData(self, sortType):
        checkDB = self.checkBase()
        if checkDB == False:
            db = Database(self.nameParam)
            conn, curs = db.connect()
            db.createBase(conn, curs)
            resault = db.selectBase(conn, curs, sortType)
            return resault
        if checkDB == True:
            db = Database(self.nameParam)
            conn, curs = db.connect()
            resault = db.selectBase(conn, curs, sortType)
            return resault

    def insertData(self, nameFirm, inn, dateAct, comment):
        dbInsert = Database(self.nameParam)
        conn, curs = dbInsert.connect()
        checkFirm = dbInsert.selectBase(conn, curs, 1)
        listFirm = []
        for a, b, c, d in checkFirm:
            listFirm.append(self.format.formatCode(a))
        if nameFirm not in listFirm:
            conn, curs = dbInsert.connect()
            dbInsert.insert(conn, curs, nameFirm, inn, dateAct, comment)
            return True
        else:
            return False

    def updateData(self, listOldParam, newNmeFirm, newInn, newComment):
        dbUpdate = Database(self.nameParam)
        conn, curs = dbUpdate.connect()
        checkFirm = dbUpdate.selectBase(conn, curs, 1)
        listFirm = []
        if newNmeFirm != listOldParam[1]:
            #print listOldParam[1]
            for a, b, c, d in checkFirm:
                listFirm.append(self.format.formatCode(a))
        if newNmeFirm not in listFirm:
            conn, curs = dbUpdate.connect()
            dbUpdate.update(conn, curs, listOldParam, newNmeFirm, newInn,
                            newComment)
            return True
        else:
            return False

    def statFirm(self, nameFirm, startDate, endDate):
        dbStat = Database(self.nameParam)
        #print self.nameParam
        conn, curs = dbStat.connect()
        resault, balansStart, balansSum, balansEnd, payCurr, depayCurr = dbStat.selectStat(
            conn, curs, nameFirm, startDate, endDate)
        return resault, balansStart, balansSum, balansEnd, payCurr, depayCurr

    def deleteFirm(self, listParam):
        dbdelete = Database(self.nameParam)
        conn, curs = dbdelete.connect()
        dbdelete.delete(conn, curs, listParam)
        return

    def checkBase(self):
        checkPath = os.path.exists(self.pathdb + '/datafiles/' +
                                   self.nameParam + '.db')
        return checkPath

    def insertDataFirm(self, nameFirm, valueDate, valueOpl, valuePol, comment):
        dbInsertDataFirm = Database(self.nameParam)
        conn, curs = dbInsertDataFirm.connect()
        dbInsertDataFirm.insertDataSel(conn, curs, nameFirm, valueDate,
                                       valueOpl, valuePol, comment)

    def updateDataFirm(self, nameFirm, oldListParam, newDateParam, newoplParam,
                       newpolParam, newComment):
        dbUpdateDataFirm = Database(self.nameParam)
        conn, curs = dbUpdateDataFirm.connect()
        dbUpdateDataFirm.updateDataSel(conn, curs, nameFirm, oldListParam,
                                       newDateParam, newoplParam, newpolParam,
                                       newComment)

    def deleteDataFirm(self, nameFirm, listParam):
        dbDeleteDataFirm = Database(self.nameParam)
        conn, curs = dbDeleteDataFirm.connect()
        dbDeleteDataFirm.deleteDataSel(conn, curs, nameFirm, listParam)

    def infoStat(self, startDate, endDate, sortType):
        infoStat = Database(self.nameParam)
        conn, curs = infoStat.connect()
        resaultInfo = infoStat.info(conn, curs, startDate, endDate, sortType)
        return resaultInfo
Ejemplo n.º 7
0
 def __init__(self,slave,nameParam,nameFirm):
     self.slaves = slave
     self.nameParam = nameParam
     self.nameFirm = nameFirm
     self.format = Format()
Ejemplo n.º 8
0
class Data():

    def __init__(self,slave,nameParam,nameFirm):
        self.slaves = slave
        self.nameParam = nameParam
        self.nameFirm = nameFirm
        self.format = Format()


    def formAddData(self):
        self.dataCus = Toplevel(self.slaves)
        self.dataCus.title('Заведение данных по %s' % (self.nameFirm))
        self.dataCus.geometry('620x225+240+220')
        self.dataCus.grab_set()
        # Label
        Label(self.dataCus, text="Дата операции:",font="Arial 12 bold").grid(row=1,sticky=E,pady=10,padx=8)
        Label(self.dataCus, text="Отгрузили на сумму:",font="Arial 12 bold").grid(row=2,sticky=E,pady=10,padx=8)
        Label(self.dataCus, text="Получена сумма:",font="Arial 12 bold").grid(row=3,sticky=E,pady=10,padx=8)
        Label(self.dataCus, text="Примечание:",font="Arial 12 bold").grid(row=4,sticky=E,pady=10,padx=8)
        Label(self.dataCus, text="рублей. (12344,00 или 232.90)",font="Arial 12 bold").grid(row=2,column=1,sticky=W,pady=10,padx=125)
        Label(self.dataCus, text="рублей. (12344,00 или 232.90)",font="Arial 12 bold").grid(row=3,column=1,sticky=W,pady=10,padx=125)

        #Label(self.dataCus, text="-",font="Arial 11 bold").grid(row=1,column=1,sticky=W,pady=10,padx=47)
        #Label(self.dataCus, text="-",font="Arial 11 bold").grid(row=1,column=1,sticky=W,pady=10,padx=80)
        #Label(self.dataCus, text="YYYY-MM-DD",font="Arial 11 bold").grid(row=1,column=1,sticky=W,pady=10,padx=113)
        Label(self.dataCus, text="YYYY-MM-DD",font="Arial 11 bold").grid(row=1,column=1,sticky=W,pady=10,padx=125)
        # Entry
        self.date = Entry(self.dataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        #self.dateYYYY = Entry(self.dataCus,width=4,background = '#CAE9C8',font="Arial 11 bold")
        #self.dateMM = Entry(self.dataCus,width=2,background = '#CAE9C8',font="Arial 11 bold")
        #self.dateDay = Entry(self.dataCus,width=2,background = '#CAE9C8',font="Arial 11 bold")

        self.opl = Entry(self.dataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        self.pol = Entry(self.dataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        self.comment = Entry(self.dataCus,width=42,background = '#CAE9C8',font="Arial 11 bold")
        self.date.grid(row=1,column=1,padx=10,pady=10,sticky=W)
        #self.dateYYYY.grid(row=1,column=1,padx=10,pady=10,sticky=W)
        #self.dateMM.grid(row=1,column=1,padx=60,pady=10,sticky=W)
        #self.dateDay.grid(row=1,column=1,padx=93,pady=10,sticky=W)

        self.opl.grid(row=2,column=1,padx=10,pady=10, sticky=W)
        self.pol.grid(row=3,column=1,padx=10,pady=10,sticky=W)
        self.comment.grid(row=4,column=1,padx=10,pady=10,sticky=W)
        # Button
        butSave = Button(self.dataCus,text="Сохранить",width=10,font='Arial 11 bold')
        butSave.grid(row=13,column=1,sticky=W,padx=250)
        butSave.bind("<Button-1>",self.newData)
        butCancel = Button(self.dataCus,text="Выход",width=10,font='Arial 11 bold',command=self.cancelAdd)
        butCancel.grid(row=13,column=1,sticky=W,padx=140)


    def editFormCustomerData(self,slavs,listParam):
        self.oldListParam = listParam
        self.editDataCus = Toplevel(slavs)
        self.editDataCus.title('Редактирование данных по %s' % (self.nameFirm))
        self.editDataCus.geometry('620x225+240+220')
        self.editDataCus.grab_set()

        Label(self.editDataCus, text="Дата операции:",font="Arial 12 bold").grid(row=1,sticky=E,pady=10,padx=8)
        Label(self.editDataCus, text="Отгрузили на сумму:",font="Arial 12 bold").grid(row=2,sticky=E,pady=10,padx=8)
        Label(self.editDataCus, text="Получена сумма:",font="Arial 12 bold").grid(row=3,sticky=E,pady=10,padx=8)
        Label(self.editDataCus, text="Примечание:",font="Arial 12 bold").grid(row=4,sticky=E,pady=10,padx=8)
        Label(self.editDataCus, text="рублей.",font="Arial 12 bold").grid(row=2,column=1,sticky=W,pady=10,padx=125)
        Label(self.editDataCus, text="рублей.",font="Arial 12 bold").grid(row=3,column=1,sticky=W,pady=10,padx=125)

        self.date = Entry(self.editDataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        self.date.insert(0, listParam[0][1:])
        self.opl = Entry(self.editDataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        self.opl.insert(0, listParam[1])
        self.pol = Entry(self.editDataCus,width=13,background = '#CAE9C8',font="Arial 11 bold")
        self.pol.insert(0, listParam[2])
        self.comment = Entry(self.editDataCus,width=42,background = '#CAE9C8',font="Arial 11 bold")
        self.comment.insert(0, listParam[3])
        self.date.grid(row=1,column=1,padx=10,pady=10,sticky=W)
        self.opl.grid(row=2,column=1,padx=10,pady=10, sticky=W)
        self.pol.grid(row=3,column=1,padx=10,pady=10, sticky=W)
        self.comment.grid(row=4,column=1,padx=10,pady=10,sticky=W)

        butSave = Button(self.editDataCus,text="Сохранить",width=10,font='Arial 11 bold')
        butSave.grid(row=13,column=1,sticky=W,padx=250)
        butSave.bind("<Button-1>",self.editData)
        butCancel = Button(self.editDataCus,text="Выход",width=10,font='Arial 11 bold',command=self.cancelEdit)
        butCancel.grid(row=13,column=1,sticky=W,padx=140)


    def newData(self,event):
        dateParam = self.date.get()
        checkDate = self.format.formatDate(dateParam)
        if checkDate != False:
            otgParam = self.opl.get()
            prhParam = self.pol.get()
            otgParam = otgParam.replace(',','.')
            prhParam = prhParam.replace(',','.')
            checkOpl = self.format.formatMany(otgParam)
            checkPol = self.format.formatMany(prhParam)
            if checkOpl != False and checkPol != False:
                if prhParam == None: prhParam = ''
                if otgParam == None: otgParam = ''
                comment = self.comment.get()
                comment = comment.replace('\"','')
                comment = comment.replace('\'','')
                comment = self.format.formatCode(comment)
                dataInsert = Base(self.nameParam)
                dataInsert.insertDataFirm(self.nameFirm,dateParam,otgParam,prhParam,comment)
                self.cancelAdd()
            else:
                self.error(self.dataCus,2)
        else:
            self.error(self.dataCus,1)

    def editData(self,event):
        newDateParam = self.date.get()
        checkDate = self.format.formatDate(newDateParam)
        if checkDate != False:
            newOtgParam = self.opl.get()
            newPrhParam = self.pol.get()
            newOtgParam = newOtgParam.replace(',','.')
            newPrhParam = newPrhParam.replace(',','.')
            checkNewOtgParam = self.format.formatMany(newOtgParam)
            checkNewPrhParam = self.format.formatMany(newPrhParam)
            if checkNewOtgParam != False and checkNewPrhParam != False:
                if newPrhParam == None: newprhParam = ''
                if newOtgParam == None: newotgParam = ''
                newComment = self.comment.get()
                newComment = newComment.replace('\"','')
                newComment = newComment.replace('\'','')
                newComment =self.format.formatCode(newComment)
                dataUpdate = Base(self.nameParam)
                dataUpdate.updateDataFirm(self.nameFirm,self.oldListParam,newDateParam,newOtgParam,newPrhParam,newComment)
                self.cancelEdit()
            else:
                self.error(self.editDataCus,2)
        else:
            self.error(self.editDataCus,1)

    def cancelAdd(self):
        self.dataCus.destroy()

    def cancelEdit(self):
        self.editDataCus.destroy()

    def error(self,slave,flag):
        self.err = Toplevel(slave)
        self.err.title('Ошибка ввода данных')
        self.err.geometry('400x110+350+290')
        self.err.grab_set()
        if flag == 1:
            Label(self.err, text='Дата введена неверно',font="Arial 12 bold").pack(side=TOP,pady=15)
        elif flag == 2:
            Label(self.err, text='Сумма введена неверно',font="Arial 12 bold").pack(side=TOP,pady=15)
        buttonExit = Button(self.err,font="Arial 12 bold",width=8,height=1,text="Ok",bd=10,command=self.quitOk).pack(side=BOTTOM,pady=5)

    def quitOk(self):
        self.err.destroy()
Ejemplo n.º 9
0
class Seller():

    def __init__(self,root):

        #self.loggerFactory = LoggerFactory()
        #self.logger = self.loggerFactory.getLoggers("seller")

        name = 'seller'
        self.root = root
        self.addFirm = Add(name)
        self.db = Base(name)
        self.format = Format()
        self.var=IntVar()
        self.var.set(1)
        self.sortType = 1

    def pageSeller(self):
        Grid.rowconfigure(self.root, 0, weight=1)
        Grid.columnconfigure(self.root, 0, weight=1)
        self.seller = Toplevel(self.root,bg = '#59CCE9')
        self.seller.title('Поставщики')
        self.seller.geometry('1160x550+50+50')
        #self.seller.grab_set()

        Grid.rowconfigure(self.seller, 1, weight=1)
        Grid.columnconfigure(self.seller, 1, weight=1)
        framSel1 = Frame(self.seller,width=230,height=550,bg = '#59AAE9')

        self.selFrame2()
        framSel1.grid(row=1,column=1, rowspan=1, columnspan=1, sticky=N + S + E + W)

        framSel1ButtonAdd = Button(framSel1,font="Arial 12 bold",width=20,height=1,text="Добавить поставщика",bg='#EAEEEE',command=self.addSeller)
        framSel1ButtonAdd.place(x = 10, y = 45)
        #framSel1ButtonAdd.bind('<Button-1>', lambda _: self.addFirm.formAdd(self.seller))
        framSel1ButtonEdit = Button(framSel1,font="Arial 12 bold",width=20,height=1,text="Редактировать",bg='#EAEEEE',command=self.editSeller)
        framSel1ButtonEdit.place(x = 10, y = 90)
        framSel1ButtonDelete = Button(framSel1,font="Arial 12 bold",width=20,height=1,text="Удалить",bg='#EAEEEE',command=self.deleteSeller)
        framSel1ButtonDelete.place(x = 10, y = 135)
        framSel1ButtonReload = Button(framSel1,font="Arial 12 bold",width=20,height=1,text="Обновить",bg='#EAEEEE',command=self.update)
        framSel1ButtonReload.place(x = 10, y = 180)
        framSel1ButtonExit = Button(framSel1,font="Arial 12 bold",width=8,height=1,text="Выход",bg='#EAEEEE',command=self.cancel)
        framSel1ButtonExit.place(x = 70, y = 470)

        Label(framSel1, text="Сортировать:",font="Arial 12 bold",bg='#59CCE9').place(x=10,y=240)
        rbutton1=Radiobutton(framSel1,text='по организации',font="Arial 11 bold",bg='#59CCE9',variable=self.var,value=1,command=self.radio_change)
        rbutton2=Radiobutton(framSel1,text='по менеджеру',font="Arial 11 bold",bg='#59CCE9',variable=self.var,value=2,command=self.radio_change)
        rbutton3=Radiobutton(framSel1,text='по дате',font="Arial 11 bold",bg='#59CCE9',variable=self.var,value=3,command=self.radio_change)
        rbutton1.place(x = 12, y = 270)
        rbutton2.place(x = 12, y = 300)
        rbutton3.place(x = 12, y = 330)


    def radio_change(self):
        if self.var.get() == 1:
            self.sortType = 1
        elif self.var.get() == 2:
            self.sortType = 2
        elif self.var.get() == 3:
            self.sortType = 3

    def selFrame2(self):
        self.lists = []
        Grid.rowconfigure(self.seller, 1, weight=100)
        Grid.columnconfigure(self.seller, 2, weight=100)
        framSel2 = Frame(self.seller,width=930,height=550)
        framSel2.grid(row=1,column=2, rowspan=1, columnspan=1, sticky=N + S + E + W)
        Label(framSel2, text='Поставщики',font="Arial 15 bold",bg="#59CCE9",bd=10).pack(fill=BOTH)

        frameb1 = Frame(framSel2); frameb1.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb1, text='№\n',borderwidth=1, relief=RAISED, font="Arial 12 bold", bg = '#59CCE9').pack(fill=X)
        lb1 = Listbox(frameb1, width=5, height=23, borderwidth=0, selectborderwidth=0,
                      relief=FLAT, exportselection=FALSE,font="Arial 13 bold", bg = '#D3E9E6')
        lb1.pack(expand=YES, fill=BOTH)
        lb1.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        lb1.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        lb1.bind('<Leave>', lambda e: 'break')
        lb1.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        lb1.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        #lb1.bind('<MouseWheel>', lambda e, s=self: s._whell(e.x, e.y))


        frameb2 = Frame(framSel2); frameb2.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb2, text='Организация\n', borderwidth=1, relief=RAISED, font="Arial 12 bold", bg = '#59CCE9').pack(fill=X)
        self.lb2 = Listbox(frameb2, width=40, height=23, borderwidth=0, selectborderwidth=0,
                      relief=FLAT, exportselection=FALSE,font="Arial 13 bold", bg = '#D3E9E6')
        self.lb2.pack(expand=YES, fill=BOTH)
        self.lb2.bind('<Double-Button-1>', self.curSelect)
        self.lb2.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        self.lb2.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        self.lb2.bind('<Leave>', lambda e: 'break')
        self.lb2.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        self.lb2.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        #self.lb2.bind('<MouseWheel>', lambda e, s=self: s._whell(e.x, e.y))
        self.menu = Menu(self.lb2, font="Arial 12 bold", bg = 'lightblue', bd=10, tearoff=0)
        self.menu.add_command(label="Редактировать", command=self.editSeller)
        self.menu.add_command(label="Удалить", command=self.deleteSeller)
        self.lb2.bind("<Button-3>", lambda e, s=self: s.showMenu(e))

        frameb3 = Frame(framSel2); frameb3.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb3, text='ИНН\n', borderwidth=1, relief=RAISED, font="Arial 12 bold", bg = '#59CCE9').pack(fill=X)
        lb3 = Listbox(frameb3, width=15, height=23, borderwidth=0, selectborderwidth=0,
                      relief=FLAT, exportselection=FALSE,font="Arial 13 bold", bg = '#D3E9E6')
        lb3.pack(expand=YES, fill=BOTH)
        lb3.bind('<Double-Button-1>', self.curSelect)
        lb3.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        lb3.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        lb3.bind('<Leave>', lambda e: 'break')
        lb3.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        lb3.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        #lb3.bind('<MouseWheel>', lambda e, s=self: s._whell(e.x, e.y))
        #lb3.bind('<Button-3>', lambda e, s=self: s._select(e.y))
        self.menu = Menu(lb3, font="Arial 12 bold", bg = 'lightblue', bd=10, tearoff=0)
        self.menu.add_command(label="Редактировать", command=self.editSeller)
        self.menu.add_command(label="Удалить", command=self.deleteSeller)
        lb3.bind("<Button-3>", lambda e, s=self: s.showMenu(e))

        frameb4 = Frame(framSel2); frameb4.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb4, text='Дата\nактуальлности', borderwidth=1, relief=RAISED, font="Arial 12 bold", bg = '#59CCE9').pack(fill=X)
        lb4 = Listbox(frameb4, width=15, height=23, borderwidth=0, selectborderwidth=0,
                      relief=FLAT, exportselection=FALSE,font="Arial 13 bold", bg = '#D3E9E6')
        lb4.pack(expand=YES, fill=BOTH)
        lb4.bind('<Double-Button-1>', self.curSelect)
        lb4.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        lb4.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        lb4.bind('<Leave>', lambda e: 'break')
        lb4.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        lb4.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        #lb4.bind('<MouseWheel>', lambda e, s=self: s._whell(e.x, e.y))
        #lb4.bind('<Button-3>', lambda e, s=self: s._select(e.y))
        self.menu = Menu(lb4, font="Arial 12 bold", bg = 'lightblue', bd=10, tearoff=0)
        self.menu.add_command(label="Редактировать", command=self.editSeller)
        self.menu.add_command(label="Удалить", command=self.deleteSeller)
        lb4.bind("<Button-3>", lambda e, s=self: s.showMenu(e))


        frameb5 = Frame(framSel2); frameb5.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb5, text='Менеджер\n', borderwidth=1, relief=RAISED, font="Arial 12 bold", bg = '#59CCE9').pack(fill=X)
        lb5 = Listbox(frameb5, width=25, height=23, borderwidth=0, selectborderwidth=0,
                      relief=FLAT, exportselection=FALSE,font="Arial 13 bold", bg = '#D3E9E6')
        lb5.pack(expand=YES, fill=BOTH)
        lb5.bind('<Double-Button-1>', self.curSelect)
        lb5.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        lb5.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        lb5.bind('<Leave>', lambda e: 'break')
        lb5.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        lb5.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        #lb5.bind('<MouseWheel>', lambda e, s=self: s._whell(e.x, e.y))
        #lb5.bind('<Button-3>', lambda e, s=self: s._select(e.y))
        self.menu = Menu(lb5, font="Arial 12 bold", bg = 'lightblue', bd=10, tearoff=0)
        self.menu.add_command(label="Редактировать", command=self.editSeller)
        self.menu.add_command(label="Удалить", command=self.deleteSeller)
        lb5.bind("<Button-3>", lambda e, s=self: s.showMenu(e))

        self.lists.append(lb1)
        self.lists.append(self.lb2)
        self.lists.append(lb3)
        self.lists.append(lb4)
        self.lists.append(lb5)
        sb = Scrollbar(framSel2, orient=VERTICAL, command=self._scroll)
        sb.pack(expand=YES, fill=Y)

        self.lists[0]['yscrollcommand']=sb.set
        #self.lists[0].config(yscrollcommand=sb.set)
        #sb.config(command=self.lists.yview)
        #self.lists[0]['yview']=sb.set

        resault = self.db.selectData(self.sortType)

        iter = 1
        for name,inn,date_act,comment in resault:
            name = self.format.formatCode(name)
            comment = self.format.formatCode(comment)
            if str(name) == '' or str(name) == '-':
                break
            else:
                lb1.insert(END, ' %s' % str(iter))
                self.lb2.insert(END, '%s' % str(name))
                lb3.insert(END, '%s' % str(inn))
                lb4.insert(END, '%s' % str(date_act))
                lb5.insert(END, '%s' % str(comment))
                iter = iter + 1


    def showMenu(self,e):
        self._select2(e.y)
        self.curSelectAll(e)
        self.menu.post(e.x_root, e.y_root)

    def curSelect(self,evt):
        try:
            self.lb2.get(self.lb2.curselection())
            values = [self.lb2.get(idx) for idx in self.lb2.curselection()]
            #print (', '.join(values))
            self.doubleClick(', '.join(values))
            #print '%s' % ', '.join(values)
        except Exception:
            pass

    def curSelectAll(self,evt):
        try:
            self.listParameter = []
            for lb in self.lists:
                lb.get(lb.curselection())
                values = [lb.get(idx) for idx in lb.curselection()]
                self.listParameter.append(str(self.format.formatCode(', '.join(values))))    #(str((', '.join(values)).encode('utf-8')))
                #print '%s' % ', '.join(values)
        except Exception:
            pass

    def addSeller(self):
        self.addFirm.formAdd(self.seller)


    def editSeller(self):
        try:
            self.addFirm.formEdit(self.seller, self.listParameter)
        except Exception:
            pass


    def deleteSeller(self):
        self.delWindow = Toplevel(self.seller,bg = '#59CCE9')
        self.delWindow.title('Удаление покупателя')
        self.delWindow.geometry('280x150+450+180')
        self.delWindow.grab_set()
        Label(self.delWindow, text="",font="Arial 12 bold",bg = '#59CCE9').pack(side=TOP)
        Label(self.delWindow, text="Удалить все данные",font="Arial 12 bold",bg = '#59CCE9').pack(side=TOP)
        Label(self.delWindow, text="по выбранной организации?",font="Arial 12 bold",bg = '#59CCE9').pack(side=TOP)

        Button1 = Button(self.delWindow,font="Arial 12 bold",width=8,height=1,bg ='#EAEEEE',text="Нет",command=self.quitDel).pack(side=LEFT,padx=33)
        Button2 = Button(self.delWindow,font="Arial 12 bold",width=8,height=1,bg ='#EAEEEE',text="Да",command=self.deleteFirm).pack(side=LEFT)


    def deleteFirm(self):
        try:
            self.db.deleteFirm(self.listParameter)
        except Exception:
            pass
        self.quitDel()
        self.update()

    def quitDel(self):
        self.delWindow.destroy()



    def _select2(self, y):
        try:
            row = self.lists[0].nearest(y)
            self.selection_clear(0, END)
            self.selection_set(row)
            return 'break'
        except Exception:
            pass


    def _select(self, y):
        row = self.lists[0].nearest(y)
        self.selection_clear(0, END)
        self.selection_set(row)
        self.curSelectAll(y)
        return 'break'

    def _button2(self, x, y):
        for l in self.lists: l.scan_mark(x, y)
        return 'break'

    def _whell(self, x, y):
        for l in self.lists:
            l.scan_mark(x, y)
        #return 'break'

    def _b2motion(self, x, y):
        for l in self.lists: l.scan_dragto(x, y)
        return 'break'

    def _scroll(self, *args):
        for l in self.lists:
            apply(l.yview, args)

    def curselection(self):
        #print str(self.lists[0].curselection())
        return self.lists[0].curselection()

    def delete(self, first, last=None):
        for l in self.lists:
            l.delete(first, last)

    def get(self, first, last=None):
        result = []
        for l in self.lists:
            result.append(l.get(first,last))
        if last: return apply(map, [None] + result)
        return result

    def index(self, index):
        self.lists[0].index(index)

    def insert(self, index, *elements):
        for e in elements:
            i = 0
            for l in self.lists:
                l.insert(index, e[i])
                i = i + 1

    def size(self):
        return self.lists[0].size()

    def see(self, index):
        for l in self.lists:
            l.see(index)

    def selection_anchor(self, index):
        for l in self.lists:
            l.selection_anchor(index)

    def selection_clear(self, first, last=None):
        for l in self.lists:
            l.selection_clear(first, last)

    def selection_includes(self, index):
        return self.lists[0].selection_includes(index)

    def selection_set(self, first, last=None):
        for l in self.lists:
            l.selection_set(first, last)

    def update(self):
        self.selFrame2()

    def cancel(self):
        self.seller.destroy()


    def doubleClick(self,nameFirm):
        nameFirm = str(self.format.formatCode(nameFirm))
        addData = AddDataSeller(self.seller, nameFirm)
        addData.addForm()
    '''
Ejemplo n.º 10
0
class Info():
    def __init__(self, slave, name):

        self.name = name
        self.slave = slave
        self.db = Base(name)
        self.format = Format()
        self.var = IntVar()
        self.var.set(1)
        self.sortType = 1

    def tableInfo(self):

        Grid.rowconfigure(self.slave, 0, weight=1)
        Grid.columnconfigure(self.slave, 0, weight=1)
        self.text, self.oneColumn, self.twoColumn = self.param()
        self.slave.title(self.text)
        self.slave.geometry('1300x555+100+100')

        self.info = Toplevel(self.slave)
        ###self.info.title(self.text)
        ###self.info.geometry('1300x555+100+100')
        self.info.grab_set()

        self.frameDialog()
        self.frameBox()

    def frameDialog(self):
        Grid.rowconfigure(self.info, 1, weight=1)
        Grid.columnconfigure(self.info, 0, weight=1)
        frame2 = Frame(self.info, width=1300, height=95, bg='#20BAB5')
        frame2.grid(row=1,
                    column=0,
                    rowspan=1,
                    columnspan=1,
                    sticky=N + S + E + W)
        # Label
        Label(frame2,
              text="Начало периода:",
              font="Arial 12 bold",
              bg='#20BAB5').place(x=10, y=20)
        Label(frame2,
              text="Окончание периода:",
              font="Arial 12 bold",
              bg='#20BAB5').place(x=270, y=20)
        # Entry
        self.startDate = Entry(frame2,
                               width=9,
                               background='#CCEBEE',
                               font="Arial 11 bold")
        self.startDate.insert(0, '2016-01-01')
        self.startDate.place(x=160, y=20)
        self.endDate = Entry(frame2,
                             width=9,
                             background='#CCEBEE',
                             font="Arial 11 bold")
        self.endDate.insert(0, self.currentDate())
        self.endDate.place(x=450, y=20)
        # Button
        buttonAdd = Button(frame2,
                           font="Arial 12 bold",
                           width=15,
                           height=1,
                           text="Сохранить в файл",
                           bg='#E1E9E8',
                           command=self.printToFile).place(x=11, y=55)
        buttonEdit = Button(frame2,
                            font="Arial 12 bold",
                            width=15,
                            height=1,
                            text="Обновить",
                            bg='#E1E9E8',
                            command=self.replace).place(x=180, y=55)
        buttonDel = Button(frame2,
                           font="Arial 12 bold",
                           width=15,
                           height=1,
                           text="Выход",
                           bg='#E1E9E8',
                           command=self.quit).place(x=350, y=55)

        Label(frame2, text="Сортировать:", font="Arial 12 bold",
              bg='#20BAB5').place(x=850, y=66)
        rbutton1 = Radiobutton(frame2,
                               text='по организации',
                               font="Arial 11 bold",
                               bg='#20BAB5',
                               variable=self.var,
                               value=1,
                               command=self.radio_change)
        rbutton2 = Radiobutton(frame2,
                               text='по менеджеру',
                               font="Arial 11 bold",
                               bg='#20BAB5',
                               variable=self.var,
                               value=2,
                               command=self.radio_change)
        rbutton1.place(x=980, y=66)
        rbutton2.place(x=1130, y=66)

    def frameBox(self):
        self.lists = []
        Grid.rowconfigure(self.info, 2, weight=100)
        Grid.columnconfigure(self.info, 0, weight=100)
        frame1 = Frame(self.info, width=1300, height=450)
        frame1.grid(row=2,
                    column=0,
                    rowspan=1,
                    columnspan=1,
                    sticky=N + S + E + W)
        Label(frame1,
              text=self.text,
              font="Arial 14 bold",
              bd=15,
              bg='#20BAB5').pack(side=TOP, fill=X)

        frameb = Frame(frame1)
        frameb.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb,
              text='ID\n',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb = Listbox(frameb,
                     width=5,
                     height=18,
                     borderwidth=0,
                     selectborderwidth=0,
                     relief=FLAT,
                     exportselection=FALSE,
                     font="Arial 13 bold",
                     bg='#D3E9E6')
        lb.pack(expand=YES, fill=BOTH)
        self.serv(lb)

        frameb1 = Frame(frame1)
        frameb1.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb1,
              text='Наименование\n',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        self.lb1 = Listbox(frameb1,
                           width=58,
                           height=18,
                           borderwidth=0,
                           selectborderwidth=0,
                           relief=FLAT,
                           exportselection=FALSE,
                           font="Arial 13 bold",
                           bg='#D3E9E6')
        self.lb1.pack(expand=YES, fill=BOTH)
        self.serv(self.lb1)

        frameb2 = Frame(frame1)
        frameb2.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb2,
              text=self.oneColumn,
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb2 = Listbox(frameb2,
                      width=14,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb2.pack(expand=YES, fill=BOTH)
        self.serv(lb2)

        frameb3 = Frame(frame1)
        frameb3.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb3,
              text=self.twoColumn,
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb3 = Listbox(frameb3,
                      width=14,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb3.pack(expand=YES, fill=BOTH)
        self.serv(lb3)

        frameb5 = Frame(frame1)
        frameb5.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb5,
              text='Остаток на\nначало периода',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb5 = Listbox(frameb5,
                      width=16,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb5.pack(expand=YES, fill=BOTH)
        self.serv(lb5)

        frameb4 = Frame(frame1)
        frameb4.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb4,
              text='Остаток на\nконец периода',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb4 = Listbox(frameb4,
                      width=16,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb4.pack(expand=YES, fill=BOTH)
        self.serv(lb4)

        frameb6 = Frame(frame1)
        frameb6.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb6,
              text='Менеджер\n',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#20BAB5').pack(fill=X)
        lb6 = Listbox(frameb6,
                      width=18,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb6.pack(expand=YES, fill=BOTH)
        self.serv(lb6)

        self.lists.append(lb)
        self.lists.append(self.lb1)
        self.lists.append(lb2)
        self.lists.append(lb3)
        self.lists.append(lb5)
        self.lists.append(lb4)
        self.lists.append(lb6)
        sb = Scrollbar(frame1, orient=VERTICAL, command=self._scroll)
        sb.pack(expand=YES, fill=Y)
        self.lists[0]['yscrollcommand'] = sb.set

        valueStartDate, valueEndDate = self.getDates()
        self.resault = self.db.infoStat(valueStartDate, valueEndDate,
                                        self.sortType)
        iter = 1
        for param in self.resault:
            if str(param) == '' or str(param) == '-':
                break
            else:
                #iter = 1
                #for rec xrange (0,len(param)): #name, plus, minus, balans in param:
                lb.insert(END, ' %s' % str(iter))
                self.lb1.insert(END, ' %s' % param[0])
                lb2.insert(END, '%s' % str(param[1]))
                lb3.insert(END, '%s' % str(param[2]))
                lb5.insert(END, '%s' % str(param[3]))
                lb4.insert(END, '%s' % str(param[4]))
                lb6.insert(END, '%s' % str(param[5]))
                iter = iter + 1

    def param(self):

        if self.name == 'seller':
            text = 'Сводная таблица по поставщикам'
            oneColumn = 'Оплатили\nна сумму'
            twoColumn = 'Получили\nна сумму'
        elif self.name == 'customer':
            text = 'Сводная таблица по покупателям'
            oneColumn = 'Отгрузили\nна сумму'
            twoColumn = 'Оплата\n на сумму'
        return text, oneColumn, twoColumn

    def radio_change(self):
        if self.var.get() == 1:
            self.sortType = 1
        elif self.var.get() == 2:
            self.sortType = 2

    def quit(self):
        self.info.destroy()

    def replace(self):
        self.frameBox()

    def serv(self, slave):
        #slave.bind('<Button-3>', self.curseleсt())
        slave.bind('<Double-Button-1>', self.curSelect)
        slave.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        slave.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        slave.bind('<Leave>', lambda e: 'break')
        slave.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        slave.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))

        return

    def curSelect(self, evt):
        try:
            self.lb1.get(self.lb1.curselection())
            values = [self.lb1.get(idx) for idx in self.lb1.curselection()]
            #print (', '.join(values))
            self.doubleClick(', '.join(values))
            #print '%s' % ', '.join(values)
        except Exception:
            pass

    def curSelectAll(self, evt):
        try:
            self.listParameter = []
            for lb in self.lists:
                lb.get(lb.curselection())
                values = [lb.get(idx) for idx in lb.curselection()]
                self.listParameter.append(
                    str(self.format.formatCode(', '.join(values))))
        except Exception:
            pass

    def _select2(self, y):
        row = self.lists[0].nearest(y)
        self.selection_clear(0, END)
        self.selection_set(row)
        return 'break'

    def _select(self, y):
        try:
            row = self.lists[0].nearest(y)
            self.selection_clear(0, END)
            self.selection_set(row)
            self.curSelectAll(y)
            return 'break'
        except Exception:
            pass

    def _button2(self, x, y):
        for l in self.lists:
            l.scan_mark(x, y)
        return 'break'

    def _b2motion(self, x, y):
        for l in self.lists:
            l.scan_dragto(x, y)
        return 'break'

    def _scroll(self, *args):
        for l in self.lists:
            apply(l.yview, args)

    def curselection(self):
        return self.lists[0].curselection()

    def delete(self, first, last=None):
        for l in self.lists:
            l.delete(first, last)

    def get(self, first, last=None):
        result = []
        for l in self.lists:
            result.append(l.get(first, last))
        if last: return apply(map, [None] + result)
        return result

    def index(self, index):
        self.lists[0].index(index)

    def insert(self, index, *elements):
        for e in elements:
            i = 0
            for l in self.lists:
                l.insert(index, e[i])
                i = i + 1

    def size(self):
        return self.lists[0].size()

    def see(self, index):
        for l in self.lists:
            l.see(index)

    def selection_anchor(self, index):
        for l in self.lists:
            l.selection_anchor(index)

    def selection_clear(self, first, last=None):
        for l in self.lists:
            l.selection_clear(first, last)

    def selection_includes(self, index):
        return self.lists[0].selection_includes(index)

    def selection_set(self, first, last=None):
        for l in self.lists:
            l.selection_set(first, last)

    '''
    def editCustomerData(self):
        try:
            self.data.editFormCustomerData(self.cus, self.listParameter)
        except Exception:
            pass


    def deleteCustomerData(self):
        try:
            self.db.deleteDataFirm(self.nameFirm,self.listParameter)
        except Exception:
            pass
    '''

    def currentDate(self):
        curDate = datetime.date.today()
        return str(curDate)

    def currentTime(self):
        curTime = datetime.datetime.now()
        strCurTime = str(curTime).replace(' ', '_').replace(':', '')[:17]
        return strCurTime

    def currentDate(self):
        curDate = datetime.date.today()
        return str(curDate)

    def getDates(self):
        sDate = self.startDate.get()
        eDate = self.endDate.get()
        return sDate, eDate

    def doubleClick(self, nameFirm):
        nameFirm = nameFirm.strip()
        nameFirm = str(self.format.formatCode(nameFirm))
        if self.name == 'seller':
            addData = AddDataSeller(self.info, nameFirm)
        elif self.name == 'customer':
            addData = AddDataCustomer(self.info, nameFirm)
        addData.addForm()

    def printToFile(self):
        res = self.resault
        name = self.name
        if name == 'seller':
            nameRus = 'ПОСТАВЩИКИ'
            columnOne = ' Оплачено  '
            columnTwo = '  Получено  '
        elif name == 'customer':
            nameRus = 'ПОКУПАТЕЛИ'
            columnOne = '  Отгружено'
            columnTwo = '   Оплата   '
        sDate = self.startDate.get()
        eDate = self.endDate.get()
        try:
            dirApp = (os.getcwd()).decode('cp1251')
            self.pathDir = '%s/savefile' % (dirApp)
            nameDecode = name.decode('UTF-8')
            self.nameFile = '%s.txt' % (nameRus.decode('UTF-8'))
            #self.nameFile = '%s_%s.txt' % (self.currentTime(),nameDecode)
            self.pathFile = os.path.join(self.pathDir, self.nameFile)
            with open(self.pathFile, 'w') as file:
                file.write(nameRus + '\n')
                file.write('Период с %s по %s%s' %
                           (str(sDate), str(eDate), '\n'))
                file.write('\n')
                file.write('%s%s' % (
                    '************************************************************************************************************************',
                    '\n'))
                file.write('%s %-2s %s %-48s %s %11s %s %11s%s %11s %s%s' %
                           ('|', 'N', '|', 'НАИМЕНОВАНИЕ', '|', columnOne, '|',
                            columnTwo, '|',
                            ' Остаток на |  Остаток на |     Менеджер    ',
                            '|', '\n'))
                file.write('%s%s' % (
                    '|    |                                      |             |             | нач.периода |оконч.периода|                  |',
                    '\n'))
                file.write('%s%s' % (
                    '************************************************************************************************************************',
                    '\n'))
                iter = 1
                for param in res:
                    if iter > 1:
                        file.write('%s%s' % (
                            '|----|--------------------------------------|-------------|-------------|-------------|-------------|------------------|',
                            '\n'))
                    #line = '%s %-10s %s %-15s %s %-15s %s %-40s %s%s' % ('|',a,'|',b,'|',c,'|',d,'|','\n')
                    #line = '%s %-2s %s %-30s %s %13s %s %13s %s %13s %s%s' % ('|',str(iter),'|',self.formating(param[0]),'|',param[1],'|',param[2],'|',param[3],'|','\n')
                    names = self.formating(param[0], 1)
                    manag = self.formating(param[5], 2)
                    line = '%s %-2s %s %-19s %s %11s %s %11s %s %11s %s %11s %s %8s %s%s' % (
                        '|', str(iter), '|', names, '|', param[1], '|',
                        param[2], '|', param[3], '|', param[4], '|', manag,
                        '|', '\n')
                    #print line
                    file.write(line)
                    iter = iter + 1
                file.write('%s%s' % (
                    '************************************************************************************************************************',
                    '\n'))
                file.write('%s%s' % ('', '\n'))
                #file.write('Баланс : %s%s' % (balans,'\n'))
            file.close()
            self.ok()

        #except Exception:
        except Exception as error:
            traceback.print_exc()
            self.error()

    def ok(self):
        self.saveWind = Toplevel(self.info)
        self.saveWind.title('Выгразка данных в файл')
        #self.saveWind["bg"] = "green"
        self.saveWind.geometry('600x200+300+220')
        #self.saveWind.state("zoomed")
        self.saveWind.grab_set()

        Label(self.saveWind, text="Файл:", font="Arial 12 bold").pack(side=TOP,
                                                                      pady=10)
        Label(self.saveWind, text=self.nameFile,
              font="Arial 12 bold").pack(side=TOP)
        Label(self.saveWind,
              text="успешно сохранен по пути:",
              font="Arial 12 bold").pack(side=TOP)
        Label(self.saveWind, text=self.pathDir, font="Arial 12 bold").pack()
        buttonExit = Button(self.saveWind,
                            font="Arial 12 bold",
                            width=8,
                            height=1,
                            text="Ok",
                            bd=10,
                            command=self.quitOk).pack(side=BOTTOM, pady=10)

    def error(self):
        self.saveWind = Toplevel(self.info)
        self.saveWind.title('Ошибка сохранения файла')
        self.saveWind.geometry('400x110+300+200')
        self.saveWind.grab_set()

        Label(self.saveWind,
              text='Возникла ошибка при выгрузке данных в файл',
              font="Arial 12 bold").pack(side=TOP, pady=15)
        buttonExit = Button(self.saveWind,
                            font="Arial 12 bold",
                            width=8,
                            height=1,
                            text="Ok",
                            bd=10,
                            command=self.quitOk).pack(side=BOTTOM, pady=5)

    def quitOk(self):
        self.saveWind.destroy()

    def formating(self, valueString, flag):
        space = ' '
        if flag == 1:
            if len(valueString.decode('utf-8')) > 36:
                splitValue = list(valueString.decode('utf-8'))
                newSplitValue = splitValue[0:36]
                valueString = ''
                for symb in newSplitValue:
                    valueString = valueString + symb
                valueString = valueString.encode('utf-8')
            elif len(valueString.decode('utf-8')) < 36:
                while len(valueString.decode('utf-8')) < 36:
                    valueString = '%s%s' % (valueString, space)

        elif flag == 2:
            if len(valueString.decode('utf-8')) > 16:
                splitValue = list(valueString.decode('utf-8'))
                newSplitValue = splitValue[0:16]
                valueString = ''
                for symb in newSplitValue:
                    valueString = valueString + symb
                valueString = valueString.encode('utf-8')
            elif len(valueString.decode('utf-8')) < 16:
                while len(valueString.decode('utf-8')) < 16:
                    valueString = '%s%s' % (valueString, space)

        return valueString
Ejemplo n.º 11
0
class AddDataSeller():
    def __init__(self, slave, nameFirm):
        self.slave = slave
        self.nameFirm = nameFirm
        self.data = Data(self.slave, 'seller', self.nameFirm)
        self.balans = '----'
        self.db = Base('seller')
        self.format = Format()

    def addForm(self):
        Grid.rowconfigure(self.slave, 0, weight=1)
        Grid.columnconfigure(self.slave, 0, weight=1)
        self.sel = Toplevel(self.slave, bg='#59CCE9')
        self.sel.title('Данные по %s' % (self.nameFirm))
        self.sel.geometry('1000x650+120+100')
        self.sel.grab_set()

        #self.frameBox()
        self.frameDialog()
        self.frameBox()
        self.frameBal()

    def frameDialog(self):
        Grid.rowconfigure(self.sel, 1, weight=1)
        Grid.columnconfigure(self.sel, 0, weight=1)
        frame2 = Frame(self.sel, width=1000, height=95, bg='#59CCE9')
        frame2.grid(row=1,
                    column=0,
                    rowspan=1,
                    columnspan=1,
                    sticky=N + S + E + W)
        # Label
        Label(frame2,
              text="Начало периода:",
              font="Arial 12 bold",
              bg='#59CCE9').place(x=10, y=20)
        Label(frame2,
              text="Окончание периода:",
              font="Arial 12 bold",
              bg='#59CCE9').place(x=270, y=20)
        # Entry
        self.startDate = Entry(frame2,
                               width=9,
                               background='#CCEBEE',
                               font="Arial 11 bold")
        self.startDate.insert(0, '2016-01-01')
        self.startDate.place(x=160, y=20)
        self.endDate = Entry(frame2,
                             width=9,
                             background='#CCEBEE',
                             font="Arial 11 bold")
        self.endDate.insert(0, self.currentDate())
        self.endDate.place(x=450, y=20)
        # Button
        buttonAdd = Button(frame2,
                           font="Arial 12 bold",
                           width=15,
                           height=1,
                           text="Завести данные",
                           bg='#EAEEEE')
        buttonAdd.place(x=11, y=55)
        buttonAdd.bind('<Button-1>', lambda _: self.data.formAddData())
        buttonEdit = Button(frame2,
                            font="Arial 12 bold",
                            width=15,
                            height=1,
                            text="Редактировать",
                            bg='#EAEEEE',
                            command=self.editSellerData).place(x=180, y=55)
        buttonDel = Button(frame2,
                           font="Arial 12 bold",
                           width=12,
                           height=1,
                           text="Удалить",
                           bg='#EAEEEE',
                           command=self.deleteSellerData).place(x=350, y=55)
        buttonPrint = Button(frame2,
                             font="Arial 12 bold",
                             width=16,
                             height=1,
                             text="Сохранить в файл",
                             bg='#EAEEEE',
                             command=self.printToFile).place(x=490, y=55)
        buttonExit = Button(frame2,
                            font="Arial 12 bold",
                            width=12,
                            height=1,
                            text="Выход",
                            bg='#EAEEEE',
                            command=self.quit).place(x=670, y=55)
        buttonReload = Button(frame2,
                              font="Arial 12 bold",
                              width=12,
                              height=1,
                              text="Обновить",
                              bg='#EAEEEE',
                              command=self.replace).place(x=810, y=55)

    def frameBox(self):
        self.lists = []
        Grid.rowconfigure(self.sel, 2, weight=100)
        Grid.columnconfigure(self.sel, 0, weight=100)
        frame1 = Frame(self.sel, width=1000, height=450)
        frame1.grid(row=2,
                    column=0,
                    rowspan=1,
                    columnspan=1,
                    sticky=N + S + E + W)
        Label(frame1,
              text=self.nameFirm,
              font="Arial 13 bold",
              bd=15,
              bg='#59CCE9').pack(side=TOP, fill=X)

        frameb1 = Frame(frame1)
        frameb1.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb1,
              text='Дата\nоперации',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#59CCE9').pack(fill=X)
        lb1 = Listbox(frameb1,
                      width=18,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb1.pack(expand=YES, fill=BOTH)
        self.serv(lb1)

        frameb2 = Frame(frame1)
        frameb2.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb2,
              text='Оплатили\n(в рублях)',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#59CCE9').pack(fill=X)
        lb2 = Listbox(frameb2,
                      width=25,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb2.pack(expand=YES, fill=BOTH)
        self.serv(lb2)

        frameb3 = Frame(frame1)
        frameb3.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb3,
              text='Получили товара\nна сумму (в рублях)',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#59CCE9').pack(fill=X)
        lb3 = Listbox(frameb3,
                      width=25,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb3.pack(expand=YES, fill=BOTH)
        self.serv(lb3)

        frameb4 = Frame(frame1)
        frameb4.pack(side=LEFT, expand=YES, fill=BOTH)
        Label(frameb4,
              text='Примечание\n',
              borderwidth=1,
              relief=RAISED,
              font="Arial 12 bold",
              bg='#59CCE9').pack(fill=X)
        lb4 = Listbox(frameb4,
                      width=40,
                      height=18,
                      borderwidth=0,
                      selectborderwidth=0,
                      relief=FLAT,
                      exportselection=FALSE,
                      font="Arial 13 bold",
                      bg='#D3E9E6')
        lb4.pack(expand=YES, fill=BOTH)
        self.serv(lb4)

        self.lists.append(lb1)
        self.lists.append(lb2)
        self.lists.append(lb3)
        self.lists.append(lb4)
        sb = Scrollbar(frame1, orient=VERTICAL, command=self._scroll)
        sb.pack(expand=YES, fill=Y)
        self.lists[0]['yscrollcommand'] = sb.set

        valueStartDate, valueEndDate = self.getDates()
        self.resault, self.balansStart, self.balansSum, self.balansEnd, self.payCurr, self.depayCurr = self.db.statFirm(
            self.nameFirm, valueStartDate, valueEndDate)

        for datePaym, oplata, prichod, comment in self.resault:
            #if str(datePaym.encode('utf-8')) == '' or str(datePaym.encode('utf-8')) == '-':
            if str(datePaym) == '' or str(datePaym) == '-':
                break
            else:
                lb1.insert(END, ' %s' % datePaym)
                lb2.insert(END, '%s' % str(oplata))
                lb3.insert(END, '%s' % str(prichod))
                comment = comment.encode('utf-8')
                lb4.insert(END, '%s' % str(comment))

    def frameBal(self):
        Grid.rowconfigure(self.sel, 3, weight=1)
        Grid.columnconfigure(self.sel, 0, weight=1)
        frameB = Frame(self.sel, width=1000, height=105, bg='#59CCE9')
        frameB.grid(row=3,
                    column=0,
                    rowspan=1,
                    columnspan=1,
                    sticky=N + S + E + W)
        #Label(frameB, text='Остаток на начало периода : ' + str(self.balansStart), width=47, bd=14, font="Arial 12 bold",bg='#59CCE9').pack(fill=X,side=LEFT)#grid(row = 1, column = 1)
        #Label(frameB, text='Остаток на окончание периода : ' + str(self.balansEnd), width=47, bd=14, font="Arial 12 bold",bg='#59CCE9').pack(fill=X,side=RIGHT)#grid(row = 1, column = 1)
        Label(frameB, text="", font="Arial 3 bold",
              bg='#59CCE9').grid(row=0, column=0, padx=15, sticky=W)
        Label(frameB,
              text="Остаток на начало периода:   ",
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=1, column=0, padx=15, sticky=W)
        Label(frameB,
              text="Остаток на окончание периода:   ",
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=2, column=0, padx=15, sticky=W)
        Label(frameB,
              text=str(self.balansStart),
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=1, column=1, sticky=E)
        Label(frameB,
              text=str(self.balansEnd),
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=2, column=1, sticky=E)
        Label(frameB,
              text="Оплатили товара за период на сумму:  ",
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=1, column=2, padx=50, sticky=W)
        Label(frameB,
              text="Получили товара за период на сумму:  ",
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=2, column=2, padx=50, sticky=W)
        Label(frameB,
              text=str(self.payCurr),
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=1, column=3, sticky=E)
        Label(frameB,
              text=str(self.depayCurr),
              font="Arial 12 bold",
              bg='#59CCE9').grid(row=2, column=3, sticky=E)
        Label(frameB, text="", font="Arial 12 bold",
              bg='#59CCE9').grid(row=1, column=4, padx=40, sticky=W)

    def quit(self):
        self.sel.destroy()

    def replace(self):
        self.frameBox()
        self.frameBal()

    def serv(self, slave):
        #slave.bind('<Button-3>', self.curseleсt())
        slave.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
        slave.bind('<Button-1>', lambda e, s=self: s._select(e.y))
        slave.bind('<Leave>', lambda e: 'break')
        slave.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
        slave.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
        self.menu = Menu(slave,
                         font="Arial 12 bold",
                         bg='lightblue',
                         bd=10,
                         tearoff=0)
        self.menu.add_command(label="Редактировать",
                              command=self.editSellerData)
        self.menu.add_command(label="Удалить", command=self.deleteSellerData)
        slave.bind("<Button-3>", lambda e, s=self: s.showMenu(e))
        return

    def showMenu(self, e):
        self._select2(e.y)
        self.curSelectAll(e)
        self.menu.post(e.x_root, e.y_root)

    def curSelectAll(self, evt):
        try:
            self.listParameter = []
            for lb in self.lists:
                lb.get(lb.curselection())
                values = [lb.get(idx) for idx in lb.curselection()]
                self.listParameter.append(
                    str(self.format.formatCode(', '.join(values))))
        except Exception:
            pass

    def _select2(self, y):
        row = self.lists[0].nearest(y)
        self.selection_clear(0, END)
        self.selection_set(row)
        return 'break'

    def _select(self, y):
        try:
            row = self.lists[0].nearest(y)
            self.selection_clear(0, END)
            self.selection_set(row)
            self.curSelectAll(y)
            return 'break'
        except Exception:
            pass

    def _button2(self, x, y):
        for l in self.lists:
            l.scan_mark(x, y)
        return 'break'

    def _b2motion(self, x, y):
        for l in self.lists:
            l.scan_dragto(x, y)
        return 'break'

    def _scroll(self, *args):
        for l in self.lists:
            apply(l.yview, args)

    def curselection(self):
        return self.lists[0].curselection()

    def delete(self, first, last=None):
        for l in self.lists:
            l.delete(first, last)

    def get(self, first, last=None):
        result = []
        for l in self.lists:
            result.append(l.get(first, last))
        if last: return apply(map, [None] + result)
        return result

    def index(self, index):
        self.lists[0].index(index)

    def insert(self, index, *elements):
        for e in elements:
            i = 0
            for l in self.lists:
                l.insert(index, e[i])
                i = i + 1

    def size(self):
        return self.lists[0].size()

    def see(self, index):
        for l in self.lists:
            l.see(index)

    def selection_anchor(self, index):
        for l in self.lists:
            l.selection_anchor(index)

    def selection_clear(self, first, last=None):
        for l in self.lists:
            l.selection_clear(first, last)

    def selection_includes(self, index):
        return self.lists[0].selection_includes(index)

    def selection_set(self, first, last=None):
        for l in self.lists:
            l.selection_set(first, last)

    def editSellerData(self):
        try:
            self.data.editFormSellerData(self.sel, self.listParameter)
        except Exception:
            pass

    def deleteSellerData(self):
        try:
            self.db.deleteDataFirm(self.nameFirm, self.listParameter)
        except Exception:
            pass

    def currentDate(self):
        curDate = datetime.date.today()
        return str(curDate)

    def currentTime(self):
        curTime = datetime.datetime.now()
        strCurTime = str(curTime).replace(' ', '_').replace(':', '')[:17]
        return strCurTime

    def getDates(self):
        sDate = self.startDate.get()
        eDate = self.endDate.get()
        return sDate, eDate

    def printToFile(self):
        res = self.resault
        name = self.nameFirm
        balansStart = self.balansStart
        balansEnd = self.balansEnd
        sDate = self.startDate.get()
        eDate = self.endDate.get()
        try:
            dirApp = (os.getcwd()).decode('cp1251')
            self.pathDir = '%s/savefile' % (dirApp)
            nameDecode = name.decode('UTF-8')
            self.nameFile = '%s.txt' % (nameDecode)
            #self.nameFile = '%s_%s.txt' % (self.currentTime(),nameDecode)
            self.pathFile = os.path.join(self.pathDir, self.nameFile)
            iter = 1
            with open(self.pathFile, 'w') as file:
                file.write('Поставщик: ' + name + '\n')
                file.write('Период с %s по %s%s' %
                           (str(sDate), str(eDate), '\n'))
                file.write('\n')
                file.write('Остаток на начало периода : %s%s' %
                           (balansStart, '\n'))
                file.write('\n')
                file.write('%s%s' % (
                    '***********************************************************************************************************************',
                    '\n'))
                file.write('%s %10s %s %18s %s %18s %s %25s %s%s' % (
                    '|', '   Дата   ', '|', '     Оплачено     ', '|',
                    '     Получено     ', '|',
                    '                         Примечание                         ',
                    '|', '\n'))
                file.write('%s%s' % (
                    '***********************************************************************************************************************',
                    '\n'))

                for a, b, c, d in res:
                    if len(d) > 60:
                        d = d[0:60]
                    elif len(d) < 60:
                        d = d.ljust(60)
                    if iter > 1:
                        file.write('%s%s' % (
                            '|------------|--------------------|--------------------|--------------------------------------------------------------|',
                            '\n'))
                    #line = '%s %-10s %s %-15s %s %-15s %s %-40s %s%s' % ('|',a,'|',b,'|',c,'|',d,'|','\n')
                    line = '%s %-10s %s %18s %s %18s %s %s %s%s' % (
                        '|', a, '|', b, '|', c, '|', d, '|', '\n')
                    file.write(self.format.formatCode(line))
                    iter = iter + 1
                file.write('%s%s' % (
                    '***********************************************************************************************************************',
                    '\n'))
                file.write('%s%s' % ('', '\n'))
                #file.write('Остаток на начало периода : %s%s' % (balansStart,'\n'))
                file.write('Остаток на окончание периода : %s%s' %
                           (balansEnd, '\n'))
                file.write('Оплатили товара за период на сумму : %s%s' %
                           (self.payCurr, '\n'))
                file.write('Получили товара за период на сумму : %s%s' %
                           (self.depayCurr, '\n'))
            file.close()
            self.ok()

        #except Exception:
        except Exception as error:
            traceback.print_exc()
            self.error()

    def ok(self):
        self.saveWind = Toplevel(self.sel)
        self.saveWind.title('Выгразка данных в файл')
        #self.saveWind["bg"] = "green"
        self.saveWind.geometry('600x200+300+220')
        #self.saveWind.state("zoomed")
        self.saveWind.grab_set()

        Label(self.saveWind, text="Файл:", font="Arial 12 bold").pack(side=TOP,
                                                                      pady=10)
        Label(self.saveWind, text=self.nameFile,
              font="Arial 12 bold").pack(side=TOP)
        Label(self.saveWind,
              text="успешно сохранен по пути:",
              font="Arial 12 bold").pack(side=TOP)
        Label(self.saveWind, text=self.pathDir, font="Arial 12 bold").pack()
        buttonExit = Button(self.saveWind,
                            font="Arial 12 bold",
                            width=8,
                            height=1,
                            text="Ok",
                            bd=10,
                            command=self.quitOk).pack(side=BOTTOM, pady=10)

    def error(self):
        self.saveWind = Toplevel(self.sel)
        self.saveWind.title('Ошибка сохранения файла')
        self.saveWind.geometry('400x110+300+200')
        self.saveWind.grab_set()

        Label(self.saveWind,
              text='Возникла ошибка при выгрузке данных в файл',
              font="Arial 12 bold").pack(side=TOP, pady=15)
        buttonExit = Button(self.saveWind,
                            font="Arial 12 bold",
                            width=8,
                            height=1,
                            text="Ok",
                            bd=10,
                            command=self.quitOk).pack(side=BOTTOM, pady=5)

    def quitOk(self):
        self.saveWind.destroy()
Ejemplo n.º 12
0
 def __init__(self, name):
     self.name = name
     self.format = Format()
Ejemplo n.º 13
0
class Add():
    def __init__(self, name):
        self.name = name
        self.format = Format()

    def formAdd(self, nameParam):
        #print  nameParam
        self.firm = Toplevel(nameParam, bg='#E3EED8')
        if self.name == 'seller':
            self.firm.title('Добавить поставщика')
        elif self.name == 'customer':
            self.firm.title('Добавить покупателя')
        self.firm.geometry('650x250+290+195')
        self.firm.grab_set()

        Label(self.firm,
              text="Наименование:",
              font="Arial 12 bold",
              bg='#E3EED8').grid(row=1, sticky=E, pady=10)
        Label(self.firm, text="ИНН:", font="Arial 12 bold",
              bg='#E3EED8').grid(row=2, sticky=E, pady=10)
        Label(self.firm, text="Менеджер:", font="Arial 12 bold",
              bg='#E3EED8').grid(row=3, sticky=E, pady=10)

        self.entName = Entry(self.firm,
                             width=60,
                             background='#CCEBEE',
                             font="Arial 11 bold")
        self.entInn = Entry(self.firm,
                            width=20,
                            background='#CCEBEE',
                            font="Arial 11 bold")
        self.entComment = Entry(self.firm,
                                width=60,
                                background='#CCEBEE',
                                font="Arial 11 bold")
        self.entName.grid(row=1, column=1, padx=10, pady=10, sticky=W)
        self.entInn.grid(row=2, column=1, padx=10, pady=10, sticky=W)
        self.entComment.grid(row=3, column=1, padx=10, pady=10, sticky=W)

        butSave = Button(self.firm,
                         text="Сохранить",
                         width=10,
                         font='Arial 11 bold',
                         bg='#E3EED8')
        butSave.grid(row=10, column=1, sticky=E, pady=50, padx=150)
        butSave.bind("<Button-1>", self.newData)

        butCancel = Button(self.firm,
                           text="Отмена",
                           width=10,
                           font='Arial 11 bold',
                           bg='#E3EED8',
                           command=self.cancelAdd)
        butCancel.grid(row=10, column=1, sticky=W, pady=50, padx=260)

    def formEdit(self, nameParam, listParam):
        self.listParam = listParam
        self.edit = Toplevel(nameParam, bg='#E3EED8')
        if self.name == 'seller':
            self.edit.title('Редактирование поставщика')
        elif self.name == 'customer':
            #print '2'
            self.edit.title('Редактирование покупателя')
        self.edit.geometry('650x250+290+195')
        self.edit.grab_set()

        Label(self.edit,
              text="Наименование:",
              font="Arial 12 bold",
              bg='#E3EED8').grid(row=1, sticky=E, pady=10)
        Label(self.edit, text="ИНН:", font="Arial 12 bold",
              bg='#E3EED8').grid(row=2, sticky=E, pady=10)
        #Label(self.edit, text="Дата актуальности:",font="Arial 12 bold",bg = '#E3EED8').grid(row=3,sticky=E,pady=10)
        Label(self.edit, text="Менеджер:", font="Arial 12 bold",
              bg='#E3EED8').grid(row=4, sticky=E, pady=10)
        #print '3'
        self.entName = Entry(self.edit,
                             width=60,
                             background='#CCEBEE',
                             font="Arial 11 bold")
        self.entName.insert(0, listParam[1])
        self.entInn = Entry(self.edit,
                            width=20,
                            background='#CCEBEE',
                            font="Arial 11 bold")
        self.entInn.insert(0, listParam[2])
        #self.entDate = Entry(self.edit,width=20,background = '#CCEBEE',font="Arial 11 bold")
        #self.entDate.insert(0, listParam[3])
        self.entComment = Entry(self.edit,
                                width=60,
                                background='#CCEBEE',
                                font="Arial 11 bold")
        self.entComment.insert(0, listParam[4])

        self.entName.grid(row=1, column=1, padx=10, pady=10, sticky=W)
        self.entInn.grid(row=2, column=1, padx=10, pady=10, sticky=W)
        #self.entDate.grid(row=3,column=1,padx=10,pady=10, sticky=W)
        self.entComment.grid(row=4, column=1, padx=10, pady=10, sticky=W)

        butSave = Button(self.edit,
                         text="Сохранить",
                         width=10,
                         font='Arial 11 bold',
                         bg='#E3EED8')
        butSave.grid(row=10, column=1, sticky=E, pady=50, padx=150)
        butSave.bind("<Button-1>", self.editData)
        butCancel = Button(self.edit,
                           text="Отмена",
                           width=10,
                           font='Arial 11 bold',
                           bg='#E3EED8',
                           command=self.cancelEdit)
        butCancel.grid(row=10, column=1, sticky=W, pady=50, padx=260)

    def newData(self, event):
        nameFirm = self.entName.get()
        nameFirm = nameFirm.replace('\"', '').replace('\'', '')
        nameFirm = nameFirm.strip()
        nameFirm = self.format.formatCode(nameFirm)
        inn = self.entInn.get()
        dateAct = ''
        comment = self.entComment.get()
        comment = comment.replace('\"', '').replace('\'', '')
        comment = self.format.formatCode(comment)
        if nameFirm == '' or nameFirm == None:
            self.cancelAdd()
        else:
            dataInsert = Base(self.name)
            check = dataInsert.insertData(nameFirm.strip(), inn, dateAct,
                                          comment)
            if check == False:
                self.error(self.firm)
            else:
                self.cancelAdd()

    def editData(self, event):
        #print '1'
        newNameFirm = self.entName.get()
        newNameFirm = newNameFirm.replace('\"', '').replace('\'', '')
        newNameFirm = self.format.formatCode(newNameFirm)
        newInn = self.entInn.get()
        #newDateAct = self.entDate.get()
        newComment = self.entComment.get()
        newComment = newComment.replace('\"', '').replace('\'', '')
        newComment = self.format.formatCode(newComment)
        dataUpdate = Base(self.name)
        check = dataUpdate.updateData(self.listParam, newNameFirm.strip(),
                                      newInn, newComment)
        if check == False:
            self.error(self.edit)
        else:
            self.cancelEdit()

    def error(self, slave):
        self.err = Toplevel(slave)
        self.err.title('Ошибка заведения поставщика')
        self.err.geometry('400x110+400+260')
        self.err.grab_set()
        Label(self.err, text='Поставщик уже существует',
              font="Arial 12 bold").pack(side=TOP, pady=15)
        buttonExit = Button(self.err,
                            font="Arial 12 bold",
                            width=8,
                            height=1,
                            text="Ok",
                            bd=10,
                            command=self.quitOk).pack(side=BOTTOM, pady=5)

    def quitOk(self):
        self.err.destroy()

    def cancelAdd(self):
        self.firm.destroy()

    def cancelEdit(self):
        self.edit.destroy()