Guest User

Untitled

a guest
Jun 30th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.29 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. sleep(1)
  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. parallel.waitForAll(launchercaisse, launchercaisse2, BSAPI.eventHandler)
  149.  
  150.  
  151. -- PARTIE 3 --
  152. -- VENTE --
  153.  
  154. function vente(monX, monY)
  155. local monX, monY = term.getSize()
  156. BSAPI.drawWindow("Caisse de "..FIRSTNAME.." "..NAME ,false)
  157.  
  158. BSAPI.drawLabel('vente1',2,3,"Nom",colors.grey)
  159. BSAPI.drawTextbox('VENTE1',2,4,monX / 2 - 9 ,"ex:Michelin")
  160.  
  161. BSAPI.drawLabel('vente2',30,3,"Prénom",colors.grey)
  162. BSAPI.drawTextbox('VENTE2',30,4,40,"ex:Pascal")
  163.  
  164. BSAPI.drawLabel('vente3',2,6,"Définir un code PIN",colors.grey)
  165. BSAPI.drawTextbox('VENTE3',2,7,monX / 2 - 9 ,"ex:1234")
  166.  
  167. BSAPI.drawLabel('vente4',30,6,"Prénom",colors.grey)
  168. BSAPI.drawTextbox('VENTE4',30,7,40,"ex:Pascal")
  169.  
  170. BSAPI.drawLabel('vente5',2,9,"Confirmer le code PIN",colors.grey)
  171. BSAPI.drawTextbox('VENTE5',2,10,monX / 2 - 9 ,"ex:1234")
  172.  
  173. BSAPI.drawLabel('vente6',30,9,"Prénom",colors.grey)
  174. BSAPI.drawTextbox('VENTE6',30,10,40,"ex:Pascal")
  175.  
  176. BSAPI.drawLabel('vente7',2,12,"Confirmer le code PIN",colors.grey)
  177. BSAPI.drawTextbox('VENTE7',2,13,monX / 2 - 9 ,"ex:1234")
  178.  
  179. BSAPI.drawLabel('vente8',30,12,"Prénom",colors.grey)
  180. BSAPI.drawTextbox('VENTE8',30,13,40,"ex:Pascal")
  181.  
  182. BSAPI.drawLabel('modifvente1',2,15,"Nom xQté",colors.blue)
  183. BSAPI.drawTextbox('MODIFVENTE1',2,16,monX / 2 - 9 ,"ex:Bread x20")
  184.  
  185. BSAPI.drawLabel('modifvente2',30,15,"Prix",colors.blue)
  186. BSAPI.drawTextbox('MODIFVENTE2',30,16,40,"ex:15E")
  187.  
  188. BSAPI.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, "Modifier la vente")
  189. end
  190.  
  191. function vente2()
  192. while true do
  193. event, a1, a2, a3 = os.pullEvent()
  194.  
  195. if a1 == "PASSWORD" then
  196. if a2 == "" then
  197. --Do nothing
  198. elseif not tonumber(a2) then
  199. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  200. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  201. BSAPI.changeValue("PASSWORD", "value", "")
  202. elseif #a2 ~= 4 then
  203. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit faire 4 chiffres !")
  204. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  205. BSAPI.changeValue("PASSWORD", "value", "")
  206. else
  207. PASSWORD = tonumber(a2)
  208. end
  209.  
  210. elseif a1 == "PASSWORDCONFIRM" then
  211. if a2 == "" then
  212. --Do nothing
  213. elseif not tonumber(a2) then
  214. BSAPI.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  215. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  216. BSAPI.changeValue("PASSWORD", "value", "")
  217. else
  218. PASSWORDCONFIRM = tonumber(a2)
  219. end
  220.  
  221. elseif a1 == "NAME" then
  222. if a2 == "" then
  223. --Do nothing
  224. elseif #a2 <= 4 then
  225. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit faire plus de 4 lettres.")
  226. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  227. BSAPI.changeValue("NAME", "value", "")
  228. elseif tonumber(a2) then
  229. BSAPI.openDialog("USERNAME_dialog", "Nom invalide", " Le nom doit être composé de lettres")
  230. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  231. BSAPI.changeValue("NAME", "value", "")
  232. else
  233. NAME = a2
  234. end
  235.  
  236. elseif a1 == "FIRSTNAME" then
  237. if a2 == "" then
  238. --Do nothing
  239. elseif #a2 <= 4 then
  240. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit faire plus de 4 lettres.")
  241. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  242. BSAPI.changeValue("FIRSTNAME", "value", "")
  243. elseif tonumber(a2) then
  244. BSAPI.openDialog("USERNAME_dialog", "Prénom invalide", " Le prénom doit être composé de lettres")
  245. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  246. BSAPI.changeValue("FIRSTNAME", "value", "")
  247. else
  248. FIRSTNAME = a2
  249. end
  250.  
  251. elseif event == "button_clicked" then
  252. if a1 == "confirm_btn" then
  253. if not PASSWORD then
  254. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un code PIN !")
  255. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  256. elseif not NAME then
  257. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un nom !")
  258. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  259. elseif not FIRSTNAME then
  260. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un prénom !")
  261. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  262. elseif PASSWORDCONFIRM ~= PASSWORD then
  263. BSAPI.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer le même code PIN !")
  264. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  265. else
  266. rep = BSAPI.openDialog("confirm_dialog", "Sauvegarder le compte", " Voulez-vous vraiment enregistrer ce compte ?")
  267. if rep == true then
  268. BSAPI.closeWindow()
  269. else
  270. BSAPI.redrawWindow("Création d'un nouveau compte bancaire ",false)
  271. end
  272. end
  273. end
  274. end
  275. end
  276. end
  277.  
  278. parallel.waitForAll(vente, vente2, BSAPI.eventHandler)
Add Comment
Please, Sign In to add comment