Hayden_Almeida

Registrar Caixa.exe

May 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. --[[
  2. ================================ CONFIGS ====================================
  3. CRIADO POR: HAYDEN ALMEIDA
  4. Canal no youTube: https://www.youtube.com/channel/UCUZCQ1q0ZOHpqABIvpxB32g
  5. local data = "06/05/2016 as 2331" data de atualizaçao
  6. Caso encontre um erro e quiser entrar em contato: haydenalmeida@hotmail.com
  7. Ou Skype: haydenalmeida
  8. --]]
  9. local ver = "1.0"  -- versao atual do programa
  10. local Tog_Debug = false -- if Tog_Debug == true then print("Debug 1") end -- DEBUG
  11. PC_ID = os.getComputerID()
  12. --======================== FIM DAS CONFIGS ===================================
  13. local file = fs.open("//configs/start", "r")
  14. local ler1 = file.readLine()
  15. local ler2 = file.readLine()
  16. file.close()
  17. diskDriveSide = tostring(ler1)
  18. NetSide = tostring(ler2)
  19.  
  20.  
  21. local function Tela()
  22.     term.setBackgroundColor(colors.blue)
  23.     term.clear()
  24.     term.setCursorPos(1, 1)
  25.     term.setTextColor(colors.black)
  26. end
  27.  
  28. Tela()
  29. print("Insira o Cartao do Gerente para continuar e aperte ENTER.")
  30. local ENTER = read("#")
  31.  
  32. if disk.isPresent(diskDriveSide) == true then
  33.     if fs.exists("disk/usuario") then
  34.         local ab = fs.open("disk/usuario", "r")
  35.         Gerente = ab.readLine()
  36.         ab.close()
  37.         if Tog_Debug == true then print("Debug 1") end -- DEBUG
  38.         local Disco_ID = tostring(disk.getID(diskDriveSide))
  39.         local passou = false
  40.         local passou2 = false
  41.  
  42.         print("Gerente:"..Gerente)
  43.  
  44.         local lines = {}
  45.         local hFile = fs.open("//configs/gerentes", "r")
  46.         for lines in hFile.readLine do         
  47.             if Tog_Debug == true then print(lines) end -- DEBUG
  48.             if lines == Gerente then passou = true end
  49.         end
  50.         hFile.close()
  51.         if Tog_Debug == true then print("Debug 2") end -- DEBUG
  52.  
  53.         local lines = {}
  54.         local hFile = fs.open("//configs/gerentes_id", "r")
  55.         for lines in hFile.readLine do
  56.             if lines == Disco_ID then passou2 = true end
  57.         end
  58.         hFile.close()
  59.         if Tog_Debug == true then print("Debug 3") end -- DEBUG
  60.  
  61.         if passou == true and passou2 == true then
  62.             disk.eject(diskDriveSide)
  63.             print("Acesso aceito.")
  64.             sleep(1.2)
  65.             Tela()
  66.  
  67.             local passou1 = false
  68.             repeat
  69.                 print("=== REGISTRO DE CAIXA ===")
  70.                 print("Digite o ID do Computador para ser Registrado como Caixa:")
  71.                 local ID_Caixa = read()
  72.  
  73.                 if peripheral.isPresent(ler2) == true then
  74.                     if peripheral.getType(ler2) == "modem" then
  75.                         local passou_Caixa = false
  76.                         if fs.exists("//configs/caixas_registrados") == true then
  77.                             local lines = {}
  78.                             local hFile = fs.open("//configs/caixas_registrados", "r")
  79.                             for lines in hFile.readLine do
  80.                                 if Tog_Debug == true then print(lines) end -- DEBUG
  81.                                 if lines ~= ID_Caixa then passou_Caixa = true end
  82.                             end
  83.                             hFile.close()
  84.                         else passou_Caixa = true
  85.                         end
  86.                         if passou_Caixa == false then
  87.                             print("Caixa ja existe!")
  88.                         else
  89.                             print("Caixa nao registrado ainda. Deseja registar este ID: "..ID_Caixa.."  ?(s/n)")
  90.                             local confirma = read()
  91.                             if confirma == "s" then
  92.                                 passou1 = true
  93.                                 print("Registrando...")
  94.                                 local file = fs.open("//configs/caixas_registrados", "a")
  95.                                 file.writeLine(ID_Caixa)
  96.                                 file.close()
  97.  
  98.                                 timenow = os.time()
  99.                                 timenow = textutils.formatTime(timenow, true)
  100.                                 dianow = os.day()
  101.  
  102.                                 local file2 = fs.open("//Logs/Caixa_Reg_"..ID_Caixa, "w")
  103.                                 file2.writeLine("Caixa Registrado")
  104.                                 file2.writeLine("ID do Caixa: "..ID_Caixa)
  105.                                 file2.writeLine("Registrado em:")
  106.                                 file2.writeLine("Dia: "..dianow)
  107.                                 file2.writeLine("Hora: "..timenow)
  108.                                 file2.writeLine("Pelo Server ID: "..PC_ID)
  109.                                 file2.writeLine("Pelo Gerente: "..Gerente)
  110.                                 file2.close()
  111.  
  112.                                 print("ID: "..ID_Caixa.." registrado com sucesso!")
  113.                                 sleep(2)
  114.                                 shell.run("//startup")
  115.                             end
  116.                         end
  117.                     else
  118.                         print("Modem de internet nao encontrado no lado '"..ler2.."'.")
  119.                         sleep(2)
  120.                     end
  121.                 else
  122.                     print("Nenhum periferico encontrado!")
  123.                     sleep(1.2)
  124.                 end
  125.             until passou1 == true
  126.         end
  127.     else
  128.         print("Acesso rejeitado.")
  129.         sleep(1.2)
  130.     end
  131. else
  132.     print("Nao tem nenhum disquete no Driver!")
  133.     return
  134. end
Add Comment
Please, Sign In to add comment