Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Alex_K

Consultas

Recommended Posts

0i colegas,

 

Venho a este forum pedir-lhes uma grande ajuda !!!

 

Abaixo vao um código que estou trabalhando ... comecei agora a trabalhar com ASP ... portanto esta um pouco meio bagunçado ... este códigos tem várias ordenações e na linha 255 ele abre um Recorset para a consulta ordenada pela lotação ( ou turma ) ... mas ele da erro ... peço para vocês me ajudarem !!!

 

Obrigado

ASP
<%

 

mes=request.form("mes")

if mes = "Janeiro" then

        mes=1

end if

if mes = "Fevereiro" then

        mes=2

end if

if mes = "Março" then

        mes=3

end if

if mes = "Abril" then

        mes=4

end if

if mes = "Maio" then

        mes=5

end if

if mes = "Junho" then

        mes=6

end if

if mes = "Julho" then

        mes=7

end if

if mes = "Agosto" then

        mes=8

end if

if mes = "Setembro" then

        mes=9

end if

if mes = "Outubro" then

        mes=10

end if

if mes = "Novembro" then

        mes=11

end if

if mes = "Dezembro" then

        mes=12

end if

ano=request.form("ano")

 

 

if request.form("checkbox12") = "checkbox" then

        soma_custo = true

end if

if request.form("checkbox") = "checkbox" then

        soma_duracao = true

end if

 

if request.form("checkbox13") = "checkbox" then

        lotacao = true

end if

if request.form("checkbox1") = "checkbox" then

        data = true

end if

if request.form("checkbox2") = "checkbox" then

        hora_ligacao = true

end if

if request.form("checkbox3") = "checkbox" then

        numero = true

end if

if request.form("checkbox4") = "checkbox" then

        duracao = true

end if

if request.form("checkbox5") = "checkbox" then

        custo = true

end if

if request.form("checkbox6") = "checkbox" then

        localidade = true

end if

if request.form("checkbox7") = "checkbox" then

        usuario = true

end if

if request.form("checkbox11") = "checkbox" then

        ramal = true

end if

 

ordem = request.form("radiobutton")

 

set conexao = server.createobject("adodb.connection")

conexao.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("/ligacoes/ligacoes.mdb")

 

 

if request.form("ramal")<>"" then

        consulta_ramal="ramal>='"&request.form("ramal")&"' "

else

        consulta_ramal=""

end if

 

if request.form("ramal2")<>"" then

        consulta_ramal2="ramal<='"&request.form("ramal2")&"' "

        a1="and"

else

        consulta_ramal2=""

        a1=""

end if

 

 

if request.form("mes")<>"" then

        consulta_mes="month(data)="&mes

        a2="and"

else

        consulta_mes=""

        a2=""

end if

 

if request.form("ano")<>"" then

        consulta_ano="year(data)="&ano

        a3="and"

else

        consulta_ano=""

        a3=""

end if

 

if request.form("numero")<>"" then

        consulta_numero="ndisc='"&request.form("numero")&"' "

        a4="and"

else

        consulta_numero=""

        a4=""

end if

 

if request.form("duracao")<>"" and request.form("duracaotempo")<>"" then

        if request.form("custo") <> "" and request.form("custovalor")<>"" then

                consulta_duracao="(duracao"&request.form("duracao")&request.form("duracaotempo")

        else

                consulta_duracao="duracao"&request.form("duracao")&request.form("duracaotempo")

                response.write ("&duracao")

        end if

        a5="and"

else

        consulta_duracao=""

        a5=""

end if

 

if request.form("custo")<>"" and request.form("custovalor")<>"" then

        if consulta_duracao <> "" then

                consulta_custo="custo"&request.form("custo")&request.form("custovalor")&")"

                a6="or"

        else

                consulta_custo="custo"&request.form("custo")&request.form("custovalor")

                a6="and"

        end if

else

        consulta_custo=""

        a6=""

end if

 

if request.form("localidade")<>"" then

        consulta_localidade="localidade='"&request.form("localidade")&"' "

        a7="and"

else

        consulta_localidade=""

        a7=""

end if

 

 

if request.form("lotacao")<>"" then

        a8="and"

       

        'pegando os ramais da lotação escolhida, excluindo o ramal da recepção(pois as pessoas que estão trabalhando em casa estão definidos com o ramal da recepção)

        sql = "select distinct ramal,nome from funcionarios where lotacao='"&request.form("lotacao")&"' and inativo=false and ramal<>'' order by nome"

       

        set rslotacao = server.createobject("adodb.recordset")

        rslotacao.open sql,conexao,1,1

       

        primeiro_registro = true

       

        do while not rslotacao.eof

               

                ramal2 = rslotacao("ramal")

                if not primeiro_registro then

                        consulta_ramal3 = consulta_ramal3&" or ramal='"&ramal2&"' "

                else

                        consulta_ramal3 = "ramal='"&ramal2&"'"

                end if

               

                if ordem = "nome" then

                        if not primeiro_registro then   

                                ordem2 = ordem2&",ramal='"&ramal2&"' "         

                        else

                                ordem2 = "ramal='"&ramal2&"' "

                        end if

                end if

               

                rslotacao.movenext

                primeiro_registro = false

        loop

        consulta_ramal3 = "("&consulta_ramal3&")"

       

       

        rslotacao.close

        set rslotacao = nothing

else

        a8=""

       

        'pegando a ordem dos ramais para ordenar por usuário(pois o campo de usuário não está na tabela das ligações)

        if ordem = "nome" then

                sql = "select distinct ramal,nome_destaque from funcionarios where "&consulta_ramal&" "&a1&" "&consulta_ramal2&" and inativo=false and ramal<>'' order by nome_destaque "

       

                set rsordemnome = server.createobject("adodb.recordset")

                rsordemnome.open sql,conexao,1,1

 

                primeiro_registro_2 = true

       

                do while not rsordemnome.eof

                        ramal2 = rsordemnome("ramal")

                        if not primeiro_registro_2 then 

                                ordem2 = ordem2&",ramal='"&ramal2&"' "         

                        else

                                ordem2 = "ramal='"&ramal2&"' "

                        end if

                        rsordemnome.movenext

                        primeiro_registro_2 = false

                loop

       

        end if

       

end if

 

 

'consultas sql de acordo com os parâmetros escolhidos

 

if request.form("lotacao")<>"" or request.form("ramal")<>"" or request.form("ramal2")<>"" or request.form("numero")<>"" or request.form("mes")<>"" or request.form("ano")<>"" or request.form("localidade")<>"" or request.form("duracao")<>"" or request.form("custo")<>"" then

       

        'response.write consulta_ramal&" "&a1&" "&consulta_ramal2&" "&consulta_ramal3&" "&a2&" "&consulta_mes&" "&a3&" "&consulta_ano&" "&a4&" "&consulta_numero&" "&a5&" "&consulta_duracao&" "&a6&" "&consulta_custo&" "&a7&" "&consulta_localidade&" ordenado por "&ordem&ordem2

       

        if ordem <> "nome" then

                sql = "select * from ligacoes where "&consulta_ramal&" "&a1&" "&consulta_ramal2&" "&consulta_ramal3&" "&a2&" "&consulta_mes&" "&a3&" "&consulta_ano&" "&a4&" "&consulta_numero&" "&a5&" "&consulta_duracao&" "&a6&" "&consulta_custo&" "&a7&" "&consulta_localidade&" order by "&ordem&" "

        else

                'response.write "test2"

                sql = "select * from ligacoes where "&consulta_ramal&" "&a1&" "&consulta_ramal2&" "&consulta_ramal3&" "&a2&" "&consulta_mes&" "&a3&" "&consulta_ano&" "&a4&" "&consulta_numero&" "&a5&" "&consulta_duracao&" "&a6&" "&consulta_custo&" "&a7&" "&consulta_localidade&" order by "&ordem2&" "

        end if

 

end if

 

set rs = server.createobject("adodb.recordset")

rs.open sql,conexao,1,1

 

response.write "Quantidade de registros: "&rs.recordcount

%>

 

<br /><strong>Relatório de Telefonia DRJ Salvador </strong>

<table border="1" class="bordasimples" id="alter">

 

     <%if lotacao then%><td width="70"><div align="center" class="style2"><strong>Lotação</strong></div></td><%end if%>

        <%if usuario then%><td><div align="center" class="style2"><strong>Usuário</strong></div></td><%end if%>

        <%if ramal then%><td><div align="center" class="style2"><strong>Ramal</strong></div></td><%end if%>

        <%if numero then%><td width="90"><div align="center" class="style2"><strong>Número</strong></div></td><%end if%>

     <%if data then%><td><div align="center" class="style2"><strong>Data</strong></div></td><%end if%>                 <%if hora_ligacao then%><td ><div align="center" class="style2"><strong>Hora</strong></div></td><%end if%>

        <%if localidade then%><td width="150"><div align="center" class="style2"><strong>Localidade</strong></div></td><%end if%>

        <%if duracao then%><td width="75"><div align="center" class="style2"><strong>Duração</strong></div></td><%end if%>

        <%if custo then%><td width="70"><div align="center" class="style2"><strong>Custo</strong></div></td><%end if%>

       

  </tr>

 

<%

 

alterna_cor = 0

 

do while not rs.eof

       

        'convertendo a duracao de segundos para minutos

        duracao_total = rs("duracao")

        duracao_min = int(duracao_total/60)

        duracao_hr = int(duracao_mim/60)

        duracao_seg = duracao_total mod 60

       

        'formatar o número discado

        ndisc = rs("ndisc")

        if len(ndisc) > 8 then

                num = right(ndisc,8)

                opddd = left(ndisc,4)

                ddd = right(opddd,2)

                op = left(opddd,2)

                ndisc = op&")-("&ddd&")-"&num

        end if

       

        'formatando data

               

        data = rs("data")

       

                if len(data) <=8 then

                        mm = left(ano,2)

                        dd = left(mm,2)

                        ano = right(mm,2)

                       

                                'if mm <= 9 then

                                '       mm = "0"&mm

                                'end if

                                'if dd <= 9 then

                        '            dd = "0"&dd

                        '       end if

                               

                end if

               

        'formatando a hora

       

        if len(rs("hora")) = 4 then

                hora = left(rs("hora"),2)

                min = right(rs("hora"),2)

        else

                hora = left(rs("hora"),1)

                min = right(rs("hora"),2)

        end if

       

        'calculando a soma total do custo

        if soma_custo then

                soma_custo_total = soma_custo_total + rs("custo")

        end if

       

        'calculando a soma total da duração

        if soma_duracao then

                soma_duracao_total = soma_duracao_total + rs("duracao")

        end if

 

       

        if (alterna_cor mod 2) = 0 then

                response.write"<tr class=dif>"

        else

                response.write"<tr>"

        end if

       

        if lotacao then

                sql = "select lotacao from funcionarios where ramal='"&rs("ramal")&"' "

               

                set rslotacao = server.createobject("adodb.recordset")

                rslotacao.open sql,conexao,1,1

               

                if rslotacao.recordcount > 0 then

                        response.write "<td>"&rslotacao("lotacao")&"</td>"

                else

                        response.write "<td> </td>"

                end if

        end if

       

        if usuario then

                sql="select nome_destaque from funcionarios where ramal='"&rs("ramal")&"' and inativo=false order by nome "

               

                set rsusuario = server.createobject("adodb.recordset")

                rsusuario.open sql,conexao,1,1

               

                if rsusuario.recordcount > 0 then

                        response.write "<td>"&rsusuario("nome_destaque")&"</td>"

                else

                        response.write "<td> </td>"

                end if

 

        end if

       

        if ramal = true then

                response.write "<td>"&rs("ramal")&"</td>"

        end if

       

        if numero then

                response.write "<td align=right>"&rs("ndisc")&"</td>"

        end if

       

        if data then

                response.write "<td>"&rs("data")&"</td>"

        end if

       

        if hora_ligacao then

                if hora < 10 then

                        response.write "<td>0"&hora&":"&min&"</td>"

                else

                        response.write "<td>"&hora&":"&min&"</td>"

                end if

        end if

       

        if localidade then

                response.write "<td align=center>"&rs("localidade")&"</td>"

        end if

       

        if duracao then

       

                if duracao_seg < 10 then

                        duracao_seg = "0"&duracao_seg

                end if

                if duracao_min < 10 then

                        duracao_min = "0"&duracao_min   

                end if

       

                response.write "<td align=center>"&duracao_hr&":"&duracao_min&":"&duracao_seg&"</td>"

               

        end if

       

        if custo then

                response.write "<td align=center>"&rs("custo")&"</td>"

        end if

       

        response.write "</tr>"

        rs.movenext

        alterna_cor = alterna_cor + 1

loop

response.write "</table>"

 

if soma_custo or soma_duracao then

       

        'convertendo a duracao total de segundos para minutos

        duracao_min_total = int(soma_duracao_total/60)

        duracao_seg_total = soma_duracao_total mod 60

        duracao_hora_total = int(duracao_min_total/60)

        duracao_min_total = duracao_min_total mod 60

 

        'colocando o 0 na frente se for menos que 10

        if duracao_hora_total < 10 then

                duracao_hora_total = "0"&duracao_hora_total

        end if

        if duracao_min_total < 10 then

                duracao_min_total = "0"&duracao_min_total

        end if

        if duracao_seg_total < 10 then

                duracao_seg_total = "0"&duracao_seg_total

        end if

       

        response.write "<br><table border=1 class=bordasimples id=alter>"

 

        if soma_custo then

                response.write "<tr><td width=130>Custo :</td><td> R$"&soma_custo_total&"</td></tr>"

        end if

 

        if soma_duracao then

                response.write "<tr class=dif><td width=130>Duração hh/mm/ss):</td><td>"&duracao_hora_total&":"&duracao_min_total&":"&duracao_seg_total&"</td></tr>"

        end if

       

        response.write "</table>"

end if

 

if lotacao then

        rslotacao.close

        set rslotacao = nothing

end if

 

'rs.close

'set rs = nothing

 

conexao.close

set conexao = nothing

 

%>

 

 

Espero que vocês possam me ajudar !!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Que erro que é apresentado?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.