Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.24 KB | None | 0 0
  1. -- PROGRAMME CAISSE --
  2.  
  3. -- PARTIE 1 --
  4. -- INSTALLATION DES APIS/HARDWARE --
  5.  
  6. local args = {...}
  7.  
  8. local monX, monY = term.getSize()
  9. local PASSWORD = nil
  10. local USERNAME = nil
  11. local NAME = nil
  12. local FIRSTNAME = nil
  13.  
  14. if not fs.exists("BSAPI") or args[1] == "true" then
  15. shell.run("pastebin get 1CFqeP11 BSAPI")
  16. end
  17.  
  18. if not fs.exists("json") or args[1] == "true" then
  19. shell.run("pastebin get 4nRg9CHU json")
  20. end
  21. os.loadAPI("BSAPI")
  22. os.loadAPI("json")
  23.  
  24. for a,b in pairs(rs.getSides()) do
  25. if peripheral.getType(b) == 'modem' then
  26. rednet.open(b)
  27. break
  28. end
  29. end
  30. for a,b in pairs(rs.getSides()) do
  31. if peripheral.getType(b) == 'printer' then
  32. printer = peripheral.wrap(b)
  33. break
  34. end
  35. end
  36.  
  37.  
  38. -- PARTIE 2 --
  39. -- LAUNCHER --
  40.  
  41. function launchercaisse(monX, monY)
  42. local monX, monY = term.getSize()
  43. BSAPI.drawWindow("Création d'un nouveau compte caisse ",false)
  44.  
  45. BSAPI.drawLabel('Name',2,3,"Nom",colors.grey)
  46. BSAPI.drawTextbox('NAME',2,4,monX / 2 - 9 ,"ex:Michelin")
  47.  
  48. BSAPI.drawLabel('Firstname',30,3,"Prénom",colors.grey)
  49. BSAPI.drawTextbox('FIRSTNAME',30,4,40,"ex:Pascal")
  50.  
  51. BSAPI.drawLabel('PASS',2,6,"Définir un code PIN",colors.grey)
  52. BSAPI.drawTextbox('PASSWORD',2,7,monX / 2 - 9 ,"ex:1234")
  53.  
  54. BSAPI.drawLabel('PASSCONFIRM',2,9,"Confirmer le code PIN",colors.grey)
  55. BSAPI.drawTextbox('PASSWORDCONFIRM',2,10,monX / 2 - 9 ,"ex:1234")
  56.  
  57. BSAPI.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, "Valider le compte")
  58. end
  59.  
  60. function launchercaisse2()
  61. while true do
  62. event, a1, a2, a3 = os.pullEvent()
  63.  
  64. if a1 == "PASSWORD" then
  65. if a2 == "" then
  66. --Do nothing
  67. elseif not tonumber(a2) then
  68. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  69. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  70. BSAPI.changeValue("PASSWORD", "value", "")
  71. elseif #a2 ~= 4 then
  72. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit faire 4 chiffres !")
  73. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  74. BSAPI.changeValue("PASSWORD", "value", "")
  75. else
  76. PASSWORD = tonumber(a2)
  77. end
  78.  
  79. elseif a1 == "PASSWORDCONFIRM" then
  80. if a2 == "" then
  81. --Do nothing
  82. elseif not tonumber(a2) then
  83. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  84. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  85. BSAPI.changeValue("PASSWORD", "value", "")
  86. else
  87. PASSWORDCONFIRM = tonumber(a2)
  88. end
  89.  
  90. elseif a1 == "NAME" then
  91. if a2 == "" then
  92. --Do nothing
  93. elseif #a2 <= 4 then
  94. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit faire plus de 4 lettres.")
  95. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  96. BSAPI.changeValue("NAME", "value", "")
  97. elseif tonumber(a2) then
  98. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit être composé de lettres")
  99. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  100. BSAPI.changeValue("NAME", "value", "")
  101. else
  102. NAME = a2
  103. end
  104.  
  105. elseif a1 == "FIRSTNAME" then
  106. if a2 == "" then
  107. --Do nothing
  108. elseif #a2 <= 4 then
  109. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit faire plus de 4 lettres.")
  110. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  111. BSAPI.changeValue("FIRSTNAME", "value", "")
  112. elseif tonumber(a2) then
  113. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit être composé de lettres")
  114. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  115. BSAPI.changeValue("FIRSTNAME", "value", "")
  116. else
  117. FIRSTNAME = a2
  118. end
  119.  
  120. elseif event == "button_clicked" then
  121. if a1 == "confirm_btn" then
  122. if not PASSWORD then
  123. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un code PIN !")
  124. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  125. elseif not NAME then
  126. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un nom !")
  127. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  128. elseif not FIRSTNAME then
  129. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un prénom !")
  130. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  131. elseif PASSWORDCONFIRM ~= PASSWORD then
  132. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer le même code PIN !")
  133. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  134. else
  135. rep = BSAPI.openDialog("confirm_dialog", "Sauvegarder le compte", " Voulez-vous vraiment enregistrer ce compte ?")
  136. if rep == true then
  137. BSAPI.closeWindow()
  138. vente()
  139. else
  140. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  141. end
  142. end
  143. end
  144. end
  145. end
  146. end
  147.  
  148. -- PARTIE 3 --
  149. -- VENTE --
  150.  
  151. function vente(monX, monY)
  152. local monX, monY = term.getSize()
  153. BSAPI.drawWindow("Caisse de "..FIRSTNAME.." "..NAME ,false)
  154.  
  155. BSAPI.drawLabel('vente1',2,3,"Nom",colors.grey)
  156. BSAPI.drawTextbox('VENTE1',2,4,monX / 2 - 9 ,"ex:Michelin")
  157.  
  158. BSAPI.drawLabel('vente2',30,3,"Prénom",colors.grey)
  159. BSAPI.drawTextbox('VENTE2',30,4,40,"ex:Pascal")
  160.  
  161. BSAPI.drawLabel('vente3',2,6,"Définir un code PIN",colors.grey)
  162. BSAPI.drawTextbox('VENTE3',2,7,monX / 2 - 9 ,"ex:1234")
  163.  
  164. BSAPI.drawLabel('vente4',30,6,"Prénom",colors.grey)
  165. BSAPI.drawTextbox('VENTE4',30,7,40,"ex:Pascal")
  166.  
  167. BSAPI.drawLabel('vente5',2,9,"Confirmer le code PIN",colors.grey)
  168. BSAPI.drawTextbox('VENTE5',2,10,monX / 2 - 9 ,"ex:1234")
  169.  
  170. BSAPI.drawLabel('vente6',30,9,"Prénom",colors.grey)
  171. BSAPI.drawTextbox('VENTE6',30,10,40,"ex:Pascal")
  172.  
  173. BSAPI.drawLabel('vente7',2,12,"Confirmer le code PIN",colors.grey)
  174. BSAPI.drawTextbox('VENTE7',2,13,monX / 2 - 9 ,"ex:1234")
  175.  
  176. BSAPI.drawLabel('vente8',30,12,"Prénom",colors.grey)
  177. BSAPI.drawTextbox('VENTE8',30,13,40,"ex:Pascal")
  178.  
  179. BSAPI.drawLabel('modifvente1',2,15,"Nom xQté",colors.blue)
  180. BSAPI.drawTextbox('MODIFVENTE1',2,16,monX / 2 - 9 ,"ex:Bread x20")
  181.  
  182. BSAPI.drawLabel('modifvente2',30,15,"Prix",colors.blue)
  183. BSAPI.drawTextbox('MODIFVENTE2',30,16,40,"ex:15E")
  184.  
  185. BSAPI.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, "Modifier la vente")
  186. end
  187.  
  188. function vente2()
  189. while true do
  190. event, a1, a2, a3 = os.pullEvent()
  191.  
  192. if a1 == "PASSWORD" then
  193. if a2 == "" then
  194. --Do nothing
  195. elseif not tonumber(a2) then
  196. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  197. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  198. BSAPI.changeValue("PASSWORD", "value", "")
  199. elseif #a2 ~= 4 then
  200. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit faire 4 chiffres !")
  201. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  202. BSAPI.changeValue("PASSWORD", "value", "")
  203. else
  204. PASSWORD = tonumber(a2)
  205. end
  206.  
  207. elseif a1 == "PASSWORDCONFIRM" then
  208. if a2 == "" then
  209. --Do nothing
  210. elseif not tonumber(a2) then
  211. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  212. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  213. BSAPI.changeValue("PASSWORD", "value", "")
  214. else
  215. PASSWORDCONFIRM = tonumber(a2)
  216. end
  217.  
  218. elseif a1 == "NAME" then
  219. if a2 == "" then
  220. --Do nothing
  221. elseif #a2 <= 4 then
  222. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit faire plus de 4 lettres.")
  223. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  224. BSAPI.changeValue("NAME", "value", "")
  225. elseif tonumber(a2) then
  226. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit être composé de lettres")
  227. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  228. BSAPI.changeValue("NAME", "value", "")
  229. else
  230. NAME = a2
  231. end
  232.  
  233. elseif a1 == "FIRSTNAME" then
  234. if a2 == "" then
  235. --Do nothing
  236. elseif #a2 <= 4 then
  237. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit faire plus de 4 lettres.")
  238. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  239. BSAPI.changeValue("FIRSTNAME", "value", "")
  240. elseif tonumber(a2) then
  241. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit être composé de lettres")
  242. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  243. BSAPI.changeValue("FIRSTNAME", "value", "")
  244. else
  245. FIRSTNAME = a2
  246. end
  247.  
  248. elseif event == "button_clicked" then
  249. if a1 == "confirm_btn" then
  250. if not PASSWORD then
  251. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un code PIN !")
  252. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  253. elseif not NAME then
  254. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un nom !")
  255. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  256. elseif not FIRSTNAME then
  257. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un prénom !")
  258. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  259. elseif PASSWORDCONFIRM ~= PASSWORD then
  260. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer le même code PIN !")
  261. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  262. else
  263. rep = BSAPI.openDialog("confirm_dialog", "Sauvegarder le compte", " Voulez-vous vraiment enregistrer ce compte ?")
  264. if rep == true then
  265. BSAPI.closeWindow()
  266. else
  267. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  268. end
  269. end
  270. end
  271. end
  272. end
  273. end
  274.  
  275. parallel.waitForAll(launchercaisse, launchercaisse2, vente, vente2, BSAPI.eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement