Advertisement
pepeknamornik

elektromer_App_V2

Aug 21st, 2023
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.16 KB | None | 0 0
  1. local verze = "20.0904.R1"
  2. local anim = 0.1
  3. local RamCesta = ("/C/system/RAM/elektro")
  4. local dataPath = "/C/system/Users/Administrator/Desktop/database/"
  5. local w, h = term.getSize()
  6. ----------------------------------------------------
  7. local f=fs.open("/C/system/RAM/user","r")
  8. user=f.readLine()
  9. f.close()
  10.  
  11.     if fs.exists("/C/system/.core/defmodem") then
  12.         local data = fs.open ("/C/system/.core/defmodem","r")
  13.         modemPos = data.readLine()
  14.         data.close()
  15.         MyID = os.getComputerID()
  16.         modem = peripheral.wrap("top")
  17.         modem.open(MyID)
  18.         if not modemPos then
  19.         fs.delete("/C/system/.core/defmodem")
  20.         modemPos = "offline"
  21.         end
  22.     else
  23.         modemPos = "offline"
  24.     end
  25.  
  26.  
  27. local function bgc(barvaP) term.setBackgroundColor(barvaP) end
  28. local function txc(barvaP) term.setTextColor(barvaP) end
  29. local function curs(xi,yi) term.setCursorPos(xi,yi) end
  30.  
  31. local function Barvy()
  32.     if fs.exists ("/C/system/Users/"..user.."/.Registry/colors") then
  33.     local data = fs.open("/C/system/Users/"..user.."/.Registry/colors", "r")
  34.     BarPoz = tonumber(data.readLine())
  35.     BarTxt = tonumber(data.readLine())
  36.     data.close()
  37.     end
  38.     if BarPoz == nil or BarTxt == nil then BarPoz = 2048 BarTxt = 1 end
  39.        
  40. end
  41.  
  42.  
  43.  
  44. local function prc(text, y)
  45.   local w = term.getSize()
  46.   local _, cy = term.getCursorPos()
  47.   curs(math.ceil((w-#text)/2), y or cy)
  48.   write(text)
  49. end
  50.  
  51.  
  52. function ukonceni ()
  53.     fs.delete (RamCesta)
  54.     error()
  55. end
  56.  
  57. function cbarva()
  58. lista.setTextColor(colors.black)
  59. lista.setBackgroundColor(colors.gray)
  60. end
  61.  
  62. function defaultvalue()
  63. end
  64.  
  65. function start()
  66. defaultvalue()
  67. Barvy()
  68. local myWindow = window.create(term.current(),w/2-11,h/2-5,25,9)
  69. myWindow.setBackgroundColor(colors.green)
  70. myWindow.setTextColor(colors.white)
  71. myWindow.clear()
  72. myWindow.setCursorPos (5, 5)
  73. myWindow.write"Spravce Elektra"
  74. myWindow.setCursorPos (1, 1)
  75. myWindow.write"Pepek@Soft"
  76. myWindow.setCursorPos (22, 9)
  77. myWindow.write"2023"
  78. sleep(1)
  79. menu()
  80. end
  81.  
  82. function plocha()
  83. w, h = term.getSize()
  84. paintutils.drawLine(1, 1, 51, 1, BarPoz)
  85. paintutils.drawPixel (51,1, colors.red)
  86. term.setCursorPos (51,1)
  87. term.setTextColor(BarTxt)
  88. write "X"
  89. barW = window.create(term.current(),1,2,w,1)
  90. barW.setBackgroundColor(colors.gray)
  91. barW.clear()
  92. barW.setTextColor(colors.white)
  93. barW.setCursorPos(2,1)
  94. barW.write"Mereni spotreby >"
  95. pozadi = window.create(term.current(),13,3,w,h-2)
  96. pozadi.setBackgroundColor(colors.white)
  97. pozadi.setTextColor(colors.black)
  98. pozadi.clear()
  99. lista = window.create(term.current(),1,3,12,h-2)
  100. lista.setBackgroundColor(BarPoz)
  101. lista.setTextColor(BarTxt)
  102. lista.clear()
  103. lista.setCursorPos(2,3)
  104. lista.write"Prehled"
  105. lista.setCursorPos(2,5)
  106. lista.write"Fakturace"
  107. lista.setCursorPos(2,h-2)
  108. lista.setTextColor(colors.white)
  109. lista.write("Pepek@Soft")
  110. term.setBackgroundColor(colors.lightGray)
  111. end
  112. -----------------------------------------------------------------------------
  113. local page = "main"
  114.  
  115. function main()
  116. barW.setCursorPos(21,1)
  117. barW.write"Prehled"
  118. barW.setCursorPos(19,1)
  119.     barW.setCursorPos(w-7,1)
  120.     barW.write"Refresh"
  121.     SerT = window.create(term.current(),14,6,w-14,h-6)
  122.     ww, hh = SerT.getSize()
  123.     SerT.setBackgroundColor(colors.lightBlue)
  124.     SerT.setTextColor(colors.black)
  125.     SerT.clear()
  126.    
  127.     if fs.exists("/database/") then
  128.     cUsr = fs.list("/database/")
  129.     local a=1
  130.     for i = 1, #cUsr do
  131.         if tonumber(cUsr[i]) ~= nil then
  132.             name = tostring(cUsr[i])
  133.             SerT.setBackgroundColor(colors.lightBlue)
  134.             SerT.setCursorPos(2,a)
  135.             SerT.write(cUsr[i])
  136.             SerT.write(",")
  137.             if fs.exists ("/database/"..cUsr[i].."/info.txt") then
  138.             local data = fs.open("/database/"..cUsr[i].."/info.txt", "r")
  139.             SerT.setCursorPos(8,a)
  140.             SerT.write(data.readLine())
  141.             SerT.write(",")
  142.            
  143.             SerT.setBackgroundColor(colors.lightGray)
  144.             SerT.setCursorPos(ww-3,a)
  145.             SerT.write("Read")
  146.             SerT.setCursorPos(ww-8,a)
  147.             SerT.write("Null")
  148.             end
  149.            
  150.            
  151.             a = a+1
  152.         end
  153.     end
  154. end
  155.    
  156. end
  157.  
  158. function menu()
  159.     plocha()
  160.     if (page == "main") then
  161.         main ()
  162.     end
  163.  
  164.     while true do
  165.         local event, button, x, y = os.pullEvent("mouse_click")
  166.         xy = x..","..y
  167.        
  168.         if event == "mouse_click" and x >= 2 and x <= 12 and y == 5 then
  169.         cbarva()
  170.         lista.setCursorPos(1,3)--
  171.         lista.write" Prehled    "
  172.         sleep(anim)
  173.         page = "main"
  174.         menu()
  175.         elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 7 then
  176.         cbarva()
  177.         lista.setCursorPos(1,5)--
  178.         lista.write" Fakturace  "
  179.         sleep(anim)
  180.         modem.transmit(132,8083,"test")
  181.         page = "main"
  182.         menu()
  183.         elseif event == "mouse_click" and x >= w-10 and x <= w-1 and y >= 6 then
  184.        
  185.         if x>= w-10 and x <= w-6 then  
  186.         modem.transmit(tonumber(cUsr[y-5]),8083,"Nulovat")
  187.             SerT.setBackgroundColor(colors.gray)
  188.             SerT.setCursorPos(ww-8,y-5)
  189.             SerT.write("Null")
  190.         end
  191.        
  192.         if x>= w-5 and x <= w-1 then   
  193.         modem.transmit(tonumber(cUsr[y-5]),8082,"Precist")
  194.             SerT.setBackgroundColor(colors.gray)
  195.             SerT.setCursorPos(ww-3,y-5)
  196.             SerT.write("Read")
  197.         end
  198.  
  199.         sleep(anim)
  200.         page = "main"
  201.         menu()
  202.         end
  203.  
  204.        
  205.        
  206.         if x == 51 and y == 1 then
  207.             ukonceni ()
  208.         else
  209.             menu() -------- stejne jako nazev funkce
  210.         end
  211.     end
  212. end
  213.  
  214. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement