def verificar(self): obrigatorio = True if self.varList[0].get() == '': self.labelList[0]['fg'] = 'red' obrigatorio = False if obrigatorio == True: path = os.path.abspath(os.path.join(get_secret("MAIN_PATH"), "Aberto", self.varList[0].get())) pasta = [path, os.listdir(path)] if len(pasta[1]) == 0: tk.messagebox.showinfo(title="Filial em Dia!", message="A filial %s está em dia.\n Envio de pedidos autorizado." % ( self.varList[0].get())) self.clearEntry(False) else: tk.messagebox.showwarning(title="Filial Não Está em Dia!", message="A filial %s está devendo %d CIs.\n Clique em 'OK' para ver quais são." % (self.varList[0].get(), len(pasta[1]))) columns = ["CIs Em Aberto", "Solicitante", "Data de Envio"] popUP(self, instance='VC').montarTree(columns, pasta) self.clearEntry(False) else: tk.messagebox.showwarning(title="Campo Invalido!", message="O campo 'Filial' não esta preenchido.\nFavor preencher e tentar novamente.", parent=self)
def buscaPecas(self): column = [ "Número do Chamado", "NF de Entrada", "Data de Envio", "NF de Saída", "Data de Recebimento" ] busca = 'SELECT * FROM pecas WHERE ' buscaVazia = True if self.variableList[0].get() != '': busca += "num_chamado LIKE '%%%s%%'" % (self.variableList[0].get()) buscaVazia = False if self.variableList[1].get() != '': if buscaVazia == False: busca += ' AND ' busca += "nf_entrada LIKE '%%%s%%'" % (self.variableList[1].get()) buscaVazia = False if self.variableList[2].get() != ' / / ': if buscaVazia == False: busca += ' AND ' data = self.variableList[2].get() data = self.adaptaData('search', data) if isinstance(data, tuple): busca += "data_envio LIKE '%%%s%%' AND data LIKE '%%%s%%'" % ( data[0], data[1]) else: busca += "data_envio LIKE '%%%s%%'" % (data) buscaVazia = False if self.variableList[3].get() != '': if buscaVazia == False: busca += ' AND ' busca += "nf_saida LIKE '%%%s%%'" % (self.variableList[3].get()) buscaVazia = False if self.variableList[4].get() != ' / / ': if buscaVazia == False: busca += ' AND ' data = self.variableList[4].get() data = self.adaptaData('search', data) if isinstance(data, tuple): busca += "data_recebimento LIKE '%%%s%%' AND data LIKE '%%%s%%'" % ( data[0], data[1]) else: busca += "data_recebimento LIKE '%%%s%%'" % (data) buscaVazia = False if self.tudoVar.get() == 1: busca = busca[:22] else: if len(busca) <= 29: tk.messagebox.showerror(title="Campos em branco", message= \ "Ao menos 1 campo deve ser preenchido para executar a busca.", parent=self) return cursor = self.DB.cursor() try: cursor.execute(busca) except Exception as exp: with open('log.txt', 'w', encoding=ENCODING) as file: file.write(exp) file.close() tmp = list(cursor.fetchall()) select = [] for resultado in tmp: resultado = list(resultado) resultado[2] = self.adaptaData('select', resultado[2]) select.append(resultado) del tmp popUP(parent=self.master, instance='CP').montarTree(column, select) cursor.close() self.destroy()
def buscaVisitas(self): column = ["Número do Chamado", "Data", "Horario", "Resolvido"] busca = 'SELECT num_chamado, data_visita, hora_visita, observacao,\ resolvido FROM visitas WHERE ' buscaVazia = True if self.variableList[0].get() != '': busca += "num_chamado LIKE '%%%s%%'" % (self.variableList[0].get()) buscaVazia = False if self.variableList[1].get() != ' / / ': if buscaVazia == False: busca += ' AND ' data = self.variableList[1].get() data = self.adaptaData('search', data) if isinstance(data, tuple): busca += "data LIKE '%%%s%%' AND data LIKE '%%%s%%'" % ( data[0], data[1]) else: busca += "data LIKE '%%%s%%'" % (data) buscaVazia = False if self.variableList[2].get() != '': if buscaVazia == False: busca += ' AND ' resolvido = self.variableList[2].get() if resolvido == 'Sim': resolvido = 1 elif resolvido == 'Não': resolvido = 0 elif resolvido == 'Todos': resolvido = "1' OR resolvido = '0" busca += "resolvido = '%s'" % (resolvido) buscaVazia = False if self.tudoVar.get() == 1: busca = busca[:87] else: if len(busca) <= 94: tk.messagebox.showerror(title="Campos em branco", message= \ "Ao menos 1 campo deve ser preenchido para executar a busca.", parent=self) return cursor = self.DB.cursor() try: cursor.execute(busca) except Exception as exp: tk.messagebox.showerror(title="Erro na busca", message=exp, parent=self) tmp = list(cursor.fetchall()) select = [] for resultado in tmp: resultado = list(resultado) resultado[1] = self.adaptaData('select', resultado[1]) select.append(resultado) del tmp popUP(parent=self.master, instance='CV').montarTree(column, select) cursor.close() self.destroy()
def proximo(self, evt=None): if isinstance(evt, tk.Event): w = evt.widget else: w = self.entryVisitas[evt] column = ["Número do Chamado", "Data", "Horario", "Resolvido"] # ------------------------Descricao-------------------------------------- if w is self.entryVisitas[3]: w.tk_focusNext().focus() return 'break' # ------------------------NUMERO DO CHAMADO-------------------------------------- if w is self.entryVisitas[0] and self.variaveisVisitas[0].get() != "": cursor = self.DB.cursor() cursor.execute( f"SELECT num_chamado FROM chamadas WHERE num_chamado like '%{w.get()}%'" ) chamada = cursor.fetchall() cursor.close() if (len(chamada) <= 0 and self.new.get()) \ or \ (len(chamada) == 1 and chamada[0][0] != w.get()): yesorno = tk.messagebox.askyesno( title="Chamado Não Encontrado.", message= "Não foi possivel localizar este número de chamado.\n\ Caso deseje adicionar um novo chamado clique em 'Sim'.", parent=self) if yesorno == True: tmp = tk.Toplevel(self) tmp.bind('<Escape>', lambda _: tmp.destroy()) tmp.transient(self.master) tmp2 = ControleChamadas(tmp, self.DB, flag=True) tmp2.pack() tmp2.entradas[0].focus() tk.Button(tmp, text="Sair", command=tmp.destroy).pack() else: self.clearEntry() return else: tmp = list(chamada) select = [] for s in tmp: select.append(list(s)) del tmp if len(select) > 1: popUP(parent=self, instance='CV').montarTreeColunaUnica( select, "Número do Chamado", 0) if self.err is True: self.clearEntry() self.err = False return 'break' elif len(select) <= 0: tk.messagebox.showerror( title="Chamado Não Encontrado.", message= "Não foi possivel localizar este número de chamado.", parent=self) self.clearEntry() self.entryVisitas[0].focus() return 'break' else: w.delete(0, 'end') w.insert(0, chamada) if self.new.get() == False: chamada = w.get() cursor = self.DB.cursor() cursor.execute( "SELECT num_chamado, data_visita, hora_visita, observacao,\ resolvido FROM visitas WHERE %s = '%s' " % (self.dicLabels[w], chamada)) tmp = list(cursor.fetchall()) cursor.close() if len(tmp) == 0: tk.messagebox.showwarning( title="Visita Não Encontrada!", message= "Nenhuma visita registrada para este número de chamado.", parent=self) self.new.set(True) else: select = [] for s in tmp: s = list(s) s[1] = self.adaptaData('select', s[1]) s[4] = "Sim" if s[4] == 1 else "Não" select.append(s) del tmp popUP(parent=self, instance='CV').montarTree(column, select) if self.err is True: self.clearEntry() self.err = False return 'break' # ------------------------Restante---------------------------------------- elif w.get() != "": if self.new.get() == False: cursor = self.DB.cursor() if self.dicLabels[w] == 'data_visita': if len(w.get()) < 10: tk.messagebox.showwarning(title="Data Invalida", message="Data Invalida", parent=self) return select = self.adaptaData('insert', w.get()) else: select = "%" + w.get() + "%" cursor.execute( "SELECT num_chamado, data_visita, hora_visita, observacao,\ resolvido FROM Visitas WHERE %s LIKE '%s'" % (self.dicLabels[w], select)) tmp = list(cursor.fetchall()) select = [] for s in tmp: s = list(s) s[1] = self.adaptaData('select', s[1]) select.append(s) del tmp w.delete(0, 'end') popUP(parent=self, instance='CV').montarTree(column, select) if self.err is True: self.clearEntry() self.err = False return 'break' cursor.close() w.tk_focusNext().focus() return
def proximo(self, evt=None): if isinstance(evt, tk.Event): w = evt.widget else: w = self.entryPecas[evt] column = [ "Número do Chamado", "NF de Entrada", "Data de Envio", "NF de Saída", "Data de Recebimento" ] # ------------------------NUMERO DO CHAMADO-------------------------------------- if self.preenchido is False: if w is self.entryPecas[0] and self.variaveisPecas[0].get() != "": cursor = self.DB.cursor() cursor.execute( f"SELECT num_chamado FROM chamadas WHERE num_chamado like '%{w.get()}%'" ) chamada = cursor.fetchall() cursor.close() if (len(chamada) <= 0) \ or \ (len(chamada) == 1 and chamada[0][0] != w.get()): yesorno = tk.messagebox.askyesno( title="Chamado Não Encontrado.", message= "Não foi possivel localizar este número de chamado.\n\ Caso deseje adicionar um novo chamado clique em 'Sim'.", parent=self) if yesorno == True: tmp = tk.Toplevel(self) tmp.bind('<Escape>', lambda _: tmp.destroy()) tmp.transient(self.master) tmp2 = ControleChamadas(tmp, self.DB, flag=True) tmp2.pack() tmp2.entradas[0].focus() tk.Button(tmp, text="Sair", command=tmp.destroy).pack() else: self.clearEntry() return else: tmp = list(chamada) select = [] for s in tmp: select.append(list(s)) del tmp if len(select) > 1: popUP(parent=self, instance='CP').montarTreeColunaUnica( select, "Número do Chamado", 0) if self.err is True: self.clearEntry() self.err = False return 'break' elif len(select) == 1: w.delete(0, 'end') w.insert(0, chamada) if self.new.get() is False: chamada = w.get() cursor = self.DB.cursor() cursor.execute("SELECT * FROM pecas WHERE %s = '%s' " % (self.dicLabels[w], chamada)) tmp = list(cursor.fetchall()) cursor.close() if len(tmp) == 0: tk.messagebox.showwarning( title="Nota Fiscal Não Encontrada!", message= "Nenhuma Nota Fiscal foi registrada para este número de chamado.", parent=self) self.new.set(True) self.changeNew() else: select = [] for s in tmp: s = list(s) s[2] = self.adaptaData('select', s[2]) if s[3] == None: s[3] = '' select.append(s) del tmp popUP(parent=self, instance='CP').montarTree(column, select) if self.err is True: self.clearEntry() self.err = False return 'break' self.preenchido = True # if self.variaveisPecas[3].get() != '': # self.new.set(True) # ------------------------NF de Entrada-------------------------------------- elif w is self.entryPecas[1] and self.variaveisPecas[1].get( ) != "": cursor = self.DB.cursor() cursor.execute( "SELECT nf_entrada FROM pecas WHERE nf_entrada LIKE '%%%d%%'" % int(w.get())) nf_entrada = list(cursor.fetchall()) if len(nf_entrada) == 0: self.new.set(True) self.changeNew() tk.messagebox.showwarning( title="Resultado não encontrado!", message= "NF digitada não encontrada, adicione uma nova NF de Entrada\nou pesquise outro número." ) else: if len(nf_entrada) == 1: # Caso new == True e a NF digitada esteje entre o retorno do select: if self.new.get() is True and int( w.get()) == nf_entrada[0][0]: tk.messagebox.showerror( title="NF Existente!", message= "A Nota Fiscal digitada já foi adicionada anteriormente.", parent=self) self.clearEntry() return 'break' else: if self.new.get() is False: w.delete(0, 'end') w.insert(0, nf_entrada[0][0]) else: if self.new.get() is True: if True in [w.get() in nf for nf in nf_entrada]: tk.messagebox.showerror( title="NF Existente!", message= "A Nota Fiscal digitada já foi adicionada anteriormente.", parent=self) self.clearEntry() return 'break' else: tmp = [] for s in nf_entrada: tmp.append(list(s)) nf_entrada = tmp del tmp popUP(parent=self, instance='CP').montarTreeColunaUnica( nf_entrada, "NF de Entrada", 1) if self.err is True: self.clearEntry() self.err = False return 'break' if self.new.get() is False: cursor = self.DB.cursor() cursor.execute( "SELECT * FROM pecas WHERE nf_entrada = '%d'" % int(w.get())) nf_entrada = list(cursor.fetchall()) tmp = [] for s in nf_entrada: s = list(s) s[2] = self.adaptaData('select', s[2]) if s[3] == None: s[3] = '' tmp.append(s) nf_entrada = tmp del tmp popUP(parent=self, instance='CP').montarTree(column, nf_entrada) if self.err is True: self.clearEntry() self.err = False return 'break' else: self.preenchido = True # ------------------------NF de Saida---------------------------------------- elif w is self.entryPecas[3] and self.variaveisPecas[3].get( ) != "": cursor = self.DB.cursor() cursor.execute( "SELECT nf_saida FROM pecas WHERE nf_saida LIKE '%%%d%%'" % int(w.get())) nf_saida = list(cursor.fetchall()) if len(nf_saida) == 1: if int(w.get()) == nf_saida[0][0]: w.delete(0, 'end') w.insert(0, nf_saida[0][0]) elif len(nf_saida) > 1: tmp = [] for s in nf_saida: tmp.append(list(s)) nf_saida = tmp del tmp popUP(parent=self, instance='CP').montarTreeColunaUnica( nf_saida, "NF de Saida", 3) if self.err is True: self.clearEntry() self.err = False return 'break' cursor = self.DB.cursor() cursor.execute("SELECT * FROM pecas WHERE nf_saida = '%d'" % int(w.get())) nf_saida = list(cursor.fetchall()) tmp = [] for s in nf_saida: s = list(s) s[2] = self.adaptaData('select', s[2]) s[4] = self.adaptaData('select', s[4]) if s[3] == None: s[3] = '' tmp.append(list(s)) nf_saida = tmp del tmp popUP(parent=self, instance='CP').montarTree(column, nf_saida) if self.err is True: self.clearEntry() self.err = False return 'break' else: self.preenchido = True # ------------------------Restante---------------------------------------- elif w.get() != "": if self.preenchido == False: cursor = self.DB.cursor() if len(w.get()) < 10: tk.messagebox.showwarning(title="Data Invalida", message="Data Invalida", parent=self) return select = self.adaptaData('insert', w.get()) cursor.execute("SELECT * FROM pecas WHERE %s LIKE '%s'" % (self.dicLabels[w], select)) tmp = list(cursor.fetchall()) select = [] for s in tmp: s = list(s) s[2] = self.adaptaData('select', s[2]) s[4] = self.adaptaData('select', s[4]) if s[3] == None: s[3] = '' select.append(s) del tmp w.delete(0, 'end') popUP(parent=self, instance='CP').montarTree(column, select) if self.err is True: self.clearEntry() self.err = False return 'break' cursor.close() w.tk_focusNext().focus() return
def proximo(self, evt=None): if isinstance(evt, tk.Event): w = evt.widget else: w = self.entryChamadas[evt] column = ["Número do Chamado", "Número de Série", "Data", "Horario", "Filial", "Responsavel"] # ------------------------Descricao-------------------------------------- if w is self.entryChamadas[6]: w.tk_focusNext().focus() return 'break' # ------------------------NUMERO DO CHAMADO-------------------------------------- if w is self.entryChamadas[0] and self.variaveisChamadas[0].get() != "": if not self.new: cursor = self.DB.cursor() cursor.execute(f"SELECT * FROM chamadas WHERE num_chamado = '{w.get()}'") chamada = cursor.fetchone() cursor.close() if chamada == None: self.new = True tk.messagebox.showinfo(title="Chamado Não Encontrado.", message="Não foi possivel localizar este número de chamado.\n\ Caso deseje, preencha os campos e adicione o novo chamado.", parent=self ) self.clearEntry(1) else: for index in range(1, len(chamada) - 1): if index == 2: data = self.adaptaData("select", chamada[index]) self.variaveisChamadas[index].set(data) else: self.variaveisChamadas[index].set(chamada[index]) self.entryChamadas[6].delete(0.0, 'end') self.entryChamadas[6].insert('end', chamada[6]) # ------------------------Restante---------------------------------------- elif w.get() != "": if self.new == False: cursor = self.DB.cursor() if self.dicLabels[w] == 'data': if len(w.get()) < 10: tk.messagebox.showwarning(title="Data Invalida", message="Data Invalida", parent=self) return select = self.adaptaData('insert', w.get()) else: select = "%" + w.get() + "%" cursor.execute( "SELECT * FROM chamadas WHERE %s LIKE '%s'" % (self.dicLabels[w], select) ) tmp = list(cursor.fetchall()) select = [] for s in tmp: s = list(s) s[2] = self.adaptaData('select', s[2]) select.append(list(s)) del tmp w.delete(0, 'end') popUP(parent=self, instance='CC').montarTree(column, select) if self.err is True: self.clearEntry() self.err = False return 'break' cursor.close() w.tk_focusNext().focus() return