Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.27 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 ,false)
  157.  
  158. BSAPI.drawLabel('vente1',2,3,PRODUCT1,colors.grey)
  159. BSAPI.drawTextbox('VENTE1',2,4,12 ,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,12 ,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,12 ,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,12 ,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,12 ,PRICE9)
  184.  
  185. BSAPI.drawLabel('modifvente',30,15,"Code Vendeur ?",colors.grey)
  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. --Do nothing
  198. elseif ADMIN == 1 then
  199. if not tonumber(a2) then
  200. PRODUCT1 = a2
  201. else
  202. PRICE1 = tonumber(a2)
  203. else
  204.  
  205. end
  206.  
  207. elseif a1 == "MODIFVENTE" 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("Caisse de "..FIRSTNAME.." "..NAME,false)
  213. BSAPI.changeValue("MODIFVENTE", "value", "")
  214. els
  215. if PASSWORD == a2 then
  216. BSAPI.openDialog("USERNAME_dialog", "ADMIN MODE", "Pour modifier un prix, rentrez un nombre - un nom, rentrez des lettres")
  217. BSAPI.redrawWindow("ADMIN - Caisse de "..FIRSTNAME.." "..NAME,false)
  218. BSAPI.changeValue("MODIFVENTE", "value", "")
  219. ADMIN = 1
  220. else
  221. BSAPI.openDialog("USERNAME_dialog", "Code invalide", " Veuillez réessayer")
  222. BSAPI.redrawWindow("Caisse de "..FIRSTNAME.." "..NAME,false)
  223. BSAPI.changeValue("MODIFVENTE", "value", "")
  224. end
  225. end
  226. end
  227. end
  228. end
  229.  
  230. parallel.waitForAll(launchercaisse, launchercaisse2, vente2, BSAPI.eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement