def validar_consulta_2(nome_colab, lab):
    try:
        colab = retorna_colab(nome_colab, lab)
        return True
    except:
        inter.pop_up("ERROR", "Consulta Inválida")
        return False
def atualizar_cadastro_colaborador(nome, DtNasc, Lab, Funcao, CH, DtIngresso,
                                   status, senha, confirma_senha, foto,
                                   cpf_colab):
    if senha.get() != confirma_senha.get():
        inter.pop_up("ERROR", "Confirme sua Senha!")
    else:
        cursor = con.cursor
        conexao = con.conexao

        try:
            if foto.get() != "":
                file_type = ImageMethods.get_file_type(foto.get())
                file_binary = ImageMethods.get_binary(foto.get())
                cursor.execute(
                    '''UPDATE Colaborador 
					SET Nome = (?), DtNasc = (?), Lab = (?), Funcao=(?), CH=(?), DtIngresso=(?), Status=(?), Foto=(?), Image_type = (?), Senha=(?) WHERE cpf = (?) ''',
                    (nome.get(), DtNasc.get(), Lab.get(), Funcao.get(),
                     CH.get(), DtIngresso.get(), status.get(), file_binary,
                     file_type, senha.get(), cpf_colab))
            else:
                cursor.execute(
                    '''UPDATE Colaborador 
					SET Nome=(?), DtNasc=(?), Lab=(?), Funcao=(?), CH=(?), DtIngresso=(?), Status=(?), Senha=(?) WHERE cpf = (?) ''',
                    (nome.get(), DtNasc.get(), Lab.get(),
                     Funcao.get(), CH.get(), DtIngresso.get(), status.get(),
                     senha.get(), cpf_colab))
            conexao.commit()
            return True
        except:
            inter.pop_up("ERROR", "Cadastro Inválido")
            return False
    return False
def cadastrar_colaborador(nome,
                          DtNasc,
                          Lab,
                          Funcao,
                          CH,
                          DtIngresso,
                          status,
                          cpf,
                          senha,
                          confirma_senha,
                          foto,
                          event=None):
    if senha.get() != confirma_senha.get():
        inter.pop_up("ERROR", "Confirme sua Senha!")
    elif (not (validar_cpf(cpf.get()))):
        inter.pop_up("ERROR", "CPF inválido")
    elif (not (validar_data(DtNasc.get()))
          or not (validar_data(DtIngresso.get()))):
        inter.pop_up("ERROR", "Data inválida")
    else:
        cursor = con.cursor
        conexao = con.conexao

        try:
            if (Lab.get() != "*Selecione o laboratório*") or (Funcao.get() in [
                    'ADM', 'Coordenador Geral'
            ]):

                lab = ""
                if (Funcao.get() in ['ADM', 'Coordenador Geral']):
                    lab = "Administração"
                else:
                    lab = Lab.get()

                if foto.get() != "":
                    file_type = ImageMethods.get_file_type(foto.get())
                    file_binary = ImageMethods.get_binary(foto.get())
                    cursor.execute(
                        "INSERT INTO Colaborador (Nome, DtNasc, Lab, Funcao, CH, DtIngresso, Status, cpf, Foto, Image_type, Senha) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                        (nome.get(), DtNasc.get(), lab, Funcao.get(), CH.get(),
                         DtIngresso.get(), status.get(), cpf.get(),
                         file_binary, file_type, senha.get()))
                else:
                    cursor.execute(
                        "INSERT INTO Colaborador (Nome, DtNasc, Lab, Funcao, CH, DtIngresso, Status, cpf, Foto, Image_type, Senha) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                        (nome.get(), DtNasc.get(), lab, Funcao.get(), CH.get(),
                         DtIngresso.get(), status.get(), cpf.get(), None, None,
                         senha.get()))
                conexao.commit()
                return True
            else:
                inter.pop_up("ERROR", "Cadastro Inválido!")
                return False
        except Exception:
            inter.pop_up("ERROR", "Cadastro Inválido")
            return False
    return False
def excluir_lab(nome, sigla):
    lista_colab = retorna_lista_colab(nome)
    if len(lista_colab) == 0:
        try:
            cursor = con.cursor
            cursor.execute("DELETE FROM Laboratorio WHERE Nome = '%s'" % nome)
            con.conexao.commit()
            return True
        except:
            inter.pop_up("ERROR", "Não foi possível remover o laboratório")
    else:
        inter.pop_up("Error",
                     "O laboratório deve estar vazio para ser removido")
        return False
def excluir_colaborador(cpf, lab):
    try:
        cursor = con.cursor
        #Seleciona idDigital
        cursor.execute("SELECT idDigital FROM Digital WHERE cpf='%s'" % cpf)

        idDigital = cursor.fetchone()

        if idDigital != None:
            idDigital = idDigital[0]
            #Apaga digital do banco
            cursor.execute("DELETE FROM Digital WHERE cpf= '%s'" % cpf)
            #Desativa o Colaborador
            cursor.execute(
                "UPDATE Colaborador SET Status = (?) WHERE cpf = (?)",
                ("Não Ativo", cpf))
            #Setta data de Desligamento
            cursor.execute(
                "UPDATE Colaborador SET DtDesligamento = (?) WHERE cpf = (?)",
                (retorna_data(), cpf))
            try:
                #Disponibiliza id do colaborador apagado
                cursor.execute(
                    '''UPDATE IdDisponivel SET disponivel = (?) WHERE idDigital = (?)''',
                    (0, idDigital))
            except:
                pass

            con.conexao.commit()

        else:
            #Desativa o Colaborador
            cursor.execute(
                "UPDATE Colaborador SET Status = 'Não Ativo' WHERE cpf = (?)",
                (cpf, ))
            con.conexao.commit()
        return True
    except Exception as e:
        print(e)
        inter.pop_up("ERROR", "Não foi possível remover o colaborador.")
        return False
def cadastrar_laboratorio(nome, sigla, logo):
    cursor = con.cursor
    conexao = con.conexao
    if nome.get() != "" and sigla.get() != "":
        try:
            if logo.get() != "":
                file_type = ImageMethods.get_file_type(logo.get())
                file_binary = ImageMethods.get_binary(logo.get())
                cursor.execute(
                    "INSERT INTO Laboratorio VALUES (?, ?, ?, ?)",
                    (nome.get(), sigla.get(), file_binary, file_type))
            else:
                cursor.execute("INSERT INTO Laboratorio VALUES (?, ?, ?, ?)",
                               (nome.get(), sigla.get(), None, None))

            conexao.commit()
            return True
        except:
            inter.pop_up("ERROR", "Cadastro Inválido")
    else:
        inter.pop_up("ERROR", "Cadastro Inválido")
    return False
def atualizar_cadastro_laboratorio(nome, sigla, logo_path):
    if logo_path.get() != "":
        cursor = con.cursor
        conexao = con.conexao
        try:
            file_type = ImageMethods.get_file_type(logo_path.get())
            file_binary = ImageMethods.get_binary(logo_path.get())
            cursor.execute(
                '''UPDATE Laboratorio 
					SET Logo = (?), Image_type = (?) WHERE Nome = (?) and Sigla = (?)''',
                (file_binary, file_type, nome.get(), sigla.get()))
            conexao.commit()

            inter.pop_up("Sucesso", "Dados Atualizados")
            return True

        except Exception as e:
            print(e)
            inter.pop_up("ERROR", "O caminho informado é inválido")
            return False
    else:
        return False
def validar_login(login, senha, event=None):

    if (login.get() != "") and (senha.get() != ""):
        try:
            colab = retorna_user(login.get())

            if (colab.senha == senha.get()) and (colab.status == "Ativo") and (
                    colab.funcao != "Pesquisador"):
                return colab

            else:
                inter.pop_up("ERROR", "Login ou Senha Inválida")
                return None

        except Exception as e:
            inter.pop_up("ERROR", "Login ou Senha Inválida")
            return None

    else:
        inter.pop_up("ERROR", "Login ou Senha Inválida")
        return None
def validar_consulta(lab):
    if lab.get() != "" and lab.get() != "*Selecione o laboratório*":
        return True
    else:
        inter.pop_up("ERROR", "Consulta Inválida")
        return False
def validar_chamada_historico(lab, mes, ano, tipo):
    laboratorio, mes, ano = lab.get(), mes.get(), ano.get()

    if laboratorio != "*Selecione o laboratório*":
        try:
            cursor = con.cursor
            dict_mes = {
                'Janeiro': '01',
                'Fevereiro': '02',
                'Março': '03',
                'Abril': '04',
                'Maio': '05',
                'Junho': '06',
                'Julho': '07',
                'Agosto': '08',
                'Setembro': '09',
                'Outubro': '10',
                'Novembro': '11',
                'Dezembro': '12'
            }

            date = ano + "/" + dict_mes[mes]

            if laboratorio == "Não Ativos":
                cursor.execute(
                    "SELECT cpf,Nome From Colaborador WHERE Status = 'Não Ativo'"
                )
            else:
                cursor.execute(
                    "SELECT cpf,Nome From Colaborador WHERE Lab = '%s' ORDER BY Nome"
                    % laboratorio)

            lista_tuplas = []
            cpf_nome_colab = cursor.fetchall()

            if len(cpf_nome_colab) == 0:
                inter.pop_up("Atenção", "Não há membros neste laboratório")
                return False

            if tipo == 'r':
                for colab in cpf_nome_colab:
                    counter = timedelta()
                    cursor.execute(
                        "SELECT entrada, saida FROM Frequencia WHERE entrada LIKE ? and cpf = ? and saida IS NOT NULL",
                        ((date + '%', colab[0])))
                    for frequencia in cursor.fetchall():
                        entrada = retorna_objeto_date(frequencia[0])
                        saida = retorna_objeto_date(frequencia[1])
                        counter += (saida - entrada)

                    tupla = (colab[1], str(counter))
                    lista_tuplas.append(tupla)

            elif tipo == 'd':
                dias = [
                    "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
                    "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
                    "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
                    "31"
                ]

                for dia in dias:
                    data_com_dia = date + "/" + dia
                    linha = dia + " de " + mes + " de " + ano
                    if laboratorio != "Não Ativos":
                        cursor.execute(
                            '''SELECT Nome, entrada, saida
										  FROM Colaborador as C, Frequencia as F
										  WHERE C.Lab = ? and C.cpf == F.cpf and  C.Status != "Não Ativo" and F.entrada LIKE ? and F.saida IS NOT NULL 
										  ORDER BY Nome''', (laboratorio, data_com_dia + "%"))
                    else:
                        cursor.execute(
                            '''SELECT Nome, entrada, saida
										  FROM Colaborador as C, Frequencia as F
										  WHERE C.cpf == F.cpf and C.Status = "Não Ativo" and F.entrada LIKE ? and F.saida IS NOT NULL 
										  ORDER BY Nome''', (data_com_dia + "%", ))
                    frequencias = cursor.fetchall()

                    if frequencias:
                        lista_tuplas.append(("__________________", linha,
                                             "__________________"))

                        for frequencia in frequencias:
                            tupla = (frequencia[0], frequencia[1],
                                     frequencia[2])
                            lista_tuplas.append(tupla)

            return lista_tuplas
        except:
            return False

    else:
        inter.pop_up("ERROR", "Laboratorio inválido!")
        return False
Пример #11
0
import SCF_interface as interface
import sqlite3
import SCF_backend as back

if __name__ == "__main__":
    back.criar_conexao()
    app = interface.SCFapp()
    app.mainloop()