https://bsi.uniriotec.br/tcc/textos/201512Franca.pdf (2015 ?)
Adeus e permanece saudável.

Moderator: Gio
Code: Select all
/*
script de arquivo pdf também precisa de outros arquivos
*/
#NoEnv
#KeyHistory, 0
ListLines, Off
SetBatchLines, -1
DetectHiddenWindows, Off
#SingleInstance, IGNORE
#WinActivateForce
CoordMode, Mouse, Client
SetTitleMatchMode, RegEx
SetTitleMatchMode, Slow
DetectHiddenText, On
SetWorkingDir, %A_ScriptDir%
;---- for test not correct ----
x1=%A_scriptdir%\Turmas.txt
ifnotexist,%x1%
{
e1=
(
ABC123
XYZ789
ABC123
XYZ789
ABC123
)
fileappend,%e1%,%x1%
e1=
}
x2=%A_scriptdir%\Matriculas.txt
ifnotexist,%x2%
{
e2=
(
20132585641
20142585642
20152585643
20162585644
20132585645
)
fileappend,%e2%,%x2%
e2=
}
;---------------------
;############################################
;######### CONFIGURAÇÃO DE ARQUIVOS #########
;############################################
cfg_ArquivoMatriculas := "MATRICULAS.txt"
cfg_ArquivoTurmas := "TURMAS.txt"
;############################################
glob_MsgEntrada := "O script para cadastrar alunos em turmas esta prestes a ser executado."
glob_MsgEntrada .= "`n" . "`n" . "Antes de prosseguir, certifique-se de que os arquivos '" cfg_ArquivoMatriculas
glob_MsgEntrada .= "' e '" cfg_ArquivoTurmas "' estão presentes no mesmo local do script e preenchidos devidamente."
glob_MsgEntrada .= "`n" . "`n" . "Para abortar o script, basta apertar ESC a qualquer momento."
glob_MsgEntrada .= "`n" . "`n" . "Deseja executar o script agora?"
MsgBox(glob_MsgEntrada,4096+32+4)
IfMsgBox, No
ExitApp
glob_AtualMatricula := ""
glob_AtualTurma := ""
glob_Start := A_TickCount
glob_Matriculas := ""
glob_Turmas := ""
glob_ContagemMatriculas := 0
glob_ContagemTurmas := 0
try {
glob_Matriculas :=
CarregarArquivoDeMatriculas(A_WorkingDir,cfg_ArquivoMatriculas)
glob_Turmas := CarregarArquivoDeTurmas(A_WorkingDir,cfg_ArquivoTurmas)
Loop, Parse, glob_Matriculas, % "`n", % "`r"
{
glob_AtualMatricula := Trim(A_LoopField)
if ( glob_AtualMatricula = "" )
continue
SelecionarAluno(glob_AtualMatricula)
Loop, Parse, glob_Turmas, % "`n", % "`r"
{
glob_AtualTurma := Trim(A_LoopField)
if ( glob_AtualTurma = "" )
continue
Sleep, 20
SelecionarTurma(glob_AtualTurma)
glob_HWND := AtivarTela("Matrícula por Aluno")
GetClientSize(glob_HWND,glob_W,glob_H)
;; COORDENADAS (CLIENT) BOTAO SALVAR: W-125, H-35
;; COORDENADAS (CLIENT) BOTAO CANCELAR: W-50 , H-35
; Graças ao comando "SetTitleMatchMode, Slow" no início do script,
; podemos verificar se a lista de disciplinas na tela principal foi
; alterada depois do clique, indicando que a operação foi executada
; com sucesso (no caso de SALVAR).
glob_Texto01 := ObterTextoDaListaDeMatriculas()
glob_Texto02 := glob_Texto01
Clicar( glob_W-125 , glob_H-35 )
While ( glob_Texto01 = glob_Texto02 ) {
if ( A_Index >= 10 )
{
; Entretanto, a rotina de obter o texto da janela principal não é
; 100% confiável. Então, ao invés de assumir que ocorreu um erro,
; simplesmente paramos o loop, mas verificamos antes se uma
; mensagem de erro do SIE foi exibida.
VerificarTelaDeErro()
break
}
Sleep, 50 + ((A_Index-1)*10)
glob_Texto02 := ObterTextoDaListaDeMatriculas()
}
;FUNCAO_EXCLUIR() ;; <-- comentada: rotina apenas para testes finais
glob_ContagemTurmas += 1
}
glob_ContagemMatriculas += 1
glob_AtualTurma := ""
}
} catch glob_Excecao {
Abortar(glob_Excecao,glob_AtualMatricula,glob_AtualTurma)
}
glob_AtualMatricula := ""
glob_End := A_TickCount
glob_TempoSegundos := (glob_End-glob_Start)/1000
glob_TempoMinutos := glob_TempoSegundos/60
glob_MsgSaida := "O script foi executado com sucesso!"
glob_MsgSaida .= "`n`nProcessadas:"
glob_MsgSaida .= "`n`t" glob_ContagemMatriculas " matrículas"
glob_MsgSaida .= "`n`t" glob_ContagemTurmas " turmas"
glob_MsgSaida .= "`n`nTempo:"
glob_MsgSaida .= "`n`t" glob_TempoSegundos " segundos"
glob_MsgSaida .= "`n`t" glob_TempoMinutos " minutos"
MsgBox(glob_MsgSaida,4096+64)
ExitApp
;==================================================================
*$ESC::
Abortar("Abortado pelo usuário.",glob_AtualMatricula,glob_AtualTurma)
ExitApp
;==================================================================
Abortar(exc="",matricula="",turma="") {
txt := ""
if ( IsObject(exc) ) {
txt .= "Exception:"
txt .= "`n" . "Msg:`t" exc.Message
txt .= "`n" . "What:`t" exc.What
txt .= "`n" . "Extra:`t" exc.Extra
txt .= "`n" . "Line:`t" exc.Line
} else {
txt .= exc
}
txt .= "`n"
txt .= "`n" . "Matrícula: " matricula
txt .= "`n" . "Turma: " turma
if ( !matricula OR !turma ) {
txt .= "`n"
txt .= "`n" . "Por favor corrija o problema "
txt .= "antes de executar novamente."
} else {
txt .= "`n"
txt .= "`n" . "Execute os seguintes passos manualmente:"
txt .= "`n"
txt .= "`n" . "* Cadastre o aluno " matricula " na turma " turma
txt .= "`n" . "* Cadastre-o também nas turmas que aparecem "
txt .= "DEPOIS de " turma " no arquivo"
txt .= "`n" . "* Remova do arquivo de matrículas o aluno " matricula
txt .= "`n" . "* Remova também as matrículas que aparecem "
txt .= "ANTES de " matricula " no arquivo"
txt .= "`n" . "* Execute o script novamente"
}
MsgBox(txt,4096+16)
ExitApp
}
;------------------------------------------------------------------
VerificarTelaDeErro() {
if ( WinExist("Atenção! ahk_class TfrCpErrorsVisual") )
throw { message: "Tela de Erro do SIE detectada!", what: "Erro_SIE",file: A_LineFile, line: A_LineNumber }
}
;------------------------------------------------------------------
CarregarArquivoDeMatriculas(p_Pasta,p_Arquivo) {
l_Caminho := p_Pasta "\" p_Arquivo
try {
FileRead, l_Conteudo, %l_Caminho%
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead", file: A_LineFile, line: A_LineNumber }
l_Conteudo := RegExReplace(l_Conteudo, "m)#[^\r\n]*" )
l_Conteudo := RegExReplace(l_Conteudo, "[^\d\r\n]" )
l_Conteudo := RegExReplace(l_Conteudo, "[\r\n]+","`n" )
l_Conteudo := RegExReplace(l_Conteudo, "(^\s*|\s*$)" )
return Trim(l_Conteudo)
} catch e {
e.extra := l_Caminho
throw e
}
}
;------------------------------------------------------------------
CarregarArquivoDeTurmas(p_Pasta,p_Arquivo) {
l_Caminho := p_Pasta "\" p_Arquivo
try {
FileRead, l_Conteudo, %l_Caminho%
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead",file: A_LineFile, line: A_LineNumber }
l_Conteudo := RegExReplace(l_Conteudo, "m)#[^\r\n]*" )
l_Conteudo := RegExReplace(l_Conteudo, "[^\w\r\n]" ) ; lembrete: "\w" inclui dígitos e "_"
StringReplace, l_Conteudo, l_Conteudo, % "_", % "", All
l_Conteudo := RegExReplace(l_Conteudo, "[\r\n]+","`n" )
l_Conteudo := RegExReplace(l_Conteudo, "(^\s*|\s*$)" )
StringUpper, l_Conteudo, l_Conteudo
return Trim(l_Conteudo)
} catch e {
e.extra := l_Caminho
throw e
}
}
;------------------------------------------------------------------
AtivarTela(p_Titulo,p_Class="Tfr.*") {
if ( p_Class )
p_Titulo .= " ahk_class " p_Class
try {
VerificarTelaDeErro()
WinWait, %p_Titulo%,, 4
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead", file: A_LineFile, line: A_LineNumber }
l_hwnd := WinExist(p_Titulo)
WinActivate, ahk_id %l_hwnd%
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead",file: A_LineFile, line: A_LineNumber }
WinWaitActive, ahk_id %l_hwnd%,, 1
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead", file: A_LineFile, line: A_LineNumber }
Sleep, 10
} catch e {
e.extra := p_Titulo
throw e
}
return l_hwnd
}
;------------------------------------------------------------------
EsperarTelaFechar(p_Titulo) {
p_Titulo .= " ahk_class Tfr.*"
try {
WinWaitClose, %p_Titulo%,, 5
if ( ErrorLevel )
throw { message: "ErrorLevel = " ErrorLevel, what: "FileRead", file: A_LineFile, line: A_LineNumber }
} catch e {
e.extra := p_Titulo
throw e
}
}
;------------------------------------------------------------------
Clicar(p_X,p_Y,p_Vezes=1) {
try {
VerificarTelaDeErro()
BlockInput, On
MouseClick, Left, %p_X%, %p_Y%, %p_Vezes%
BlockInput, Off
} catch e {
BlockInput, Off
e.extra := "(" p_X "," p_Y ") x" p_Vezes
throw e
}
}
;------------------------------------------------------------------
SelecionarAluno(id_matricula) {
; Clicar na lupa do aluno e esperar a próxima tela
AtivarTela("Matrícula por Aluno")
err := 1
While ( err )
{
VerificarTelaDeErro()
Clicar(142,122)
WinWait, % "Localizar Dados do Aluno ahk_class Tfr.*",, 0.5
err := ErrorLevel
if ( A_Index >= 10 )
{
eMsg := "Aguardando tela de Localizar Aluno"
throw { message: eMsg, what: A_ThisFunc, file: A_LineFile, line: A_LineNumber, extra: id_matricula }
}
}
; Digitar a matrícula do aluno e apertar ENTER
AtivarTela("Localizar Dados do Aluno")
Sendraw, %id_matricula%
Sleep, 50
Send, {ENTER}
EsperarTelaFechar("Localizar Dados do Aluno")
}
;------------------------------------------------------------------
SelecionarTurma(id_turma) {
AtivarTela("Matrícula por Aluno")
; O botão "Novo" fica na coordenada 60,40.
; A lupa da turma fica na coordenada 214,254.
; Enquanto a janela "Localizar Turma" não existir,
; tentar clicar em "Novo" e na Lupa.
err := 1
While ( err )
{
VerificarTelaDeErro()
BlockInput, On
MouseClick, Left, 60, 40
MouseClick, Left, 214, 254
BlockInput, Off
WinWait, % "Localizar Turma ahk_class Tfr.*",, 0.5
err := ErrorLevel
if ( A_Index >= 10 )
{
eMsg := "Aguardando tela de Localizar Turma"
throw { message: eMsg, what: A_ThisFunc, file: A_LineFile, line: A_LineNumber, extra: id_turma }
}
}
; Clicar no local onde digitamos o código da turma
; e garantir que não existe nada digitado SelecionarELimparBuscaDeTurma()
; Se necessário, digitar um código inválido para limpar o texto
; de "registros encontrados" e apertar ENTER
texto_status := ObterStatusSemEspacosDaTelaDeTurmas()
if InStr(texto_status,"registro(s)encontrado(s)")
{
Sendraw, xxxxx
Sleep, 20
Send, {ENTER}
While ( !InStr(texto_status,"Nenhumregistroencontrado") ) {
VerificarTelaDeErro()
texto_status := ObterStatusSemEspacosDaTelaDeTurmas()
}
}
SelecionarELimparBuscaDeTurma()
Sendraw, %id_turma%
Sleep, 10
Send, {ENTER}
While ( !InStr(texto_status,"registro(s)encontrado(s)") ) {
Sleep, 50 + ((A_Index-1)*10)
VerificarTelaDeErro()
if ( A_Index >= 25 )
throw { message: "Turma não encontrada", what: A_ThisFunc, line: A_LineNumber, extra: id_turma }
texto_status := ObterStatusSemEspacosDaTelaDeTurmas()
}
;// Clicar duas vezes na primeira turma para seleciona-la
AtivarTela("Localizar Turma")
Clicar(30,200,2)
EsperarTelaFechar("Localizar Turma")
}
;------------------------------------------------------------------
SelecionarELimparBuscaDeTurma() {
AtivarTela("Localizar Turma")
Clicar(60,40,2)
Sleep, 50
Send, {END}
Loop, 10
Send, {BACKSPACE}
Sleep, 10
}
;------------------------------------------------------------------
ObterStatusSemEspacosDaTelaDeTurmas() {
ControlGetText, l_Texto, % "TStatusBar1", % "Localizar Turma ahk_class Tfr.*"
StringReplace, l_Texto, l_Texto, % " ", % "", All
return l_Texto
}
;------------------------------------------------------------------
ObterTextoDaListaDeMatriculas() {
WinGetText, l_Texto, % "Matrícula por Aluno ahk_class Tfr.*"
l_Saida := ""
Loop, Parse, l_Texto, % "`n", % "`r"
if ( RegExMatch(A_LoopField,"^[A-Z]{3}\d+$") )
l_Saida .= A_LoopField
return l_Saida
}
;------------------------------------------------------------------
MsgBox(p_Texto="",p_Opcoes=0,p_Titulo="",p_Timeout=0) {
BlockInput, Off
MsgBox, % p_Opcoes, % p_Titulo, % p_Texto, % p_Timeout
}
;------------------------------------------------------------------
; autohotkey.com/board/topic/91733-command-to-get-gui-client-areas-sizes/?p=578581
GetClientSize(hwnd, ByRef w, ByRef h)
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rc)
w := NumGet(rc, 8, "int")
h := NumGet(rc, 12, "int")
}
;------------------------------------------------------------------
/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; função excluir (apenas para testes finais!)
FUNCAO_EXCLUIR() {
AtivarTela("Matrícula por Aluno")
Sleep, 600
Clicar(333,355,2)
Sleep, 100
Clicar(150,45)
Sleep, 10
AtivarTela("Confirmação","TMensagemCPDForm")
Sleep, 10
Send, {ENTER}
Sleep, 10
AtivarTela("Informação","TMensagemCPDForm")
Sleep, 10
Send, {ENTER}
Sleep, 10
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
*/
Users browsing this forum: No registered users and 1 guest