Advertisement
Guest User

Untitled

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