Advertisement
Guest User

Untitled

a guest
May 28th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. public struct Login
  12. {
  13. public string username;
  14. public string nome;
  15. public int tipo;
  16. public string password;
  17. public int id;
  18. }
  19. public struct Data
  20. {
  21. public int dia;
  22. public int mes;
  23. public int ano;
  24. public int hora;
  25. public int minutos;
  26. public int fimhora;
  27. public int fimminutos;
  28. }
  29.  
  30. public struct Sala
  31. {
  32. public int capacidade;
  33. public int numsala;
  34. public int tipo;
  35. }
  36.  
  37. public struct Sessao
  38. {
  39. public string nome;
  40. public Data data;
  41. public string local;
  42. public int idsessao;
  43. public Sala sala;
  44. }
  45.  
  46. public struct Conferencia
  47. {
  48. public string nome;
  49. public Data data;
  50. public string local;
  51. public int idsessao;
  52. public Sala sala;
  53. public string artigo;
  54. public Login login;
  55.  
  56. }
  57. public struct BilheteSessao
  58. {
  59. public Login login;
  60. public Sessao sessao;
  61. public Data data;
  62. public Sala sala;
  63. public int quantidade;
  64. }
  65.  
  66. public struct BilheteConferencia
  67. {
  68. public Conferencia conferencia;
  69. public Data data;
  70. public Login login;
  71. public Sala sala;
  72. public int quantidade;
  73. }
  74.  
  75. static int TestarInt(string pergunta)
  76. {
  77.  
  78. int num = 0;
  79. lol:
  80. try
  81. {
  82. Console.WriteLine(pergunta);
  83. num = Convert.ToInt32(Console.ReadLine());
  84. }
  85. catch (Exception)
  86. {
  87. Console.ForegroundColor = ConsoleColor.Red;
  88. Console.WriteLine("Dados introduzidos inválidos");
  89. Console.ForegroundColor = ConsoleColor.White;
  90. goto lol;
  91. }
  92.  
  93. return num;
  94. }
  95.  
  96. static void CarregarClientes(List<Login> a)
  97. {
  98. Login b = new Login();
  99. b.nome = "Jose";
  100. b.tipo = 1;
  101. b.id = 1;
  102. b.password = "12345";
  103. b.username = "Jose";
  104. a.Add(b);
  105.  
  106. Login d = new Login();
  107. d.nome = "Rui";
  108. d.tipo = 1;
  109. d.id = 2;
  110. d.password = "12345";
  111. d.username = "Rui";
  112. a.Add(d);
  113.  
  114. Login c = new Login();
  115. c.nome = "Antonio";
  116. c.id = 3;
  117. c.tipo = 1;
  118. c.password = "12345";
  119. c.username = "Antonio";
  120. a.Add(c);
  121. }
  122.  
  123. static void CarregarSalas(List<Sala> b)
  124. {
  125. Sala s = new Sala();
  126. s.numsala = 1;
  127. s.capacidade = 50;
  128. s.tipo = 1;
  129. b.Add(s);
  130. Sala a = new Sala();
  131. a.numsala = 2;
  132. a.capacidade = 75;
  133. a.tipo = 1;
  134. b.Add(a);
  135. Sala c = new Sala();
  136. c.numsala = 3;
  137. c.capacidade = 300;
  138. c.tipo = 2;
  139. b.Add(c);
  140. }
  141.  
  142. static void CarregarOrganizadores(List<Login> a)
  143. {
  144. Login e = new Login();
  145. e.username = "Jose1";
  146. e.nome = "Jose";
  147. e.id = 4;
  148. e.tipo = 2;
  149. e.password = "12345";
  150. a.Add(e);
  151. }
  152.  
  153. static void CarregarAutor(List<Login> a)
  154. {
  155. Login e = new Login();
  156. e.id = 5;
  157. e.username = "Jorge";
  158. e.nome = "Jorge";
  159. e.tipo = 3;
  160. e.password = "12345";
  161. a.Add(e);
  162. }
  163.  
  164. static void CarregarAdmin(List<Login> a)
  165. {
  166.  
  167. Login e = new Login();
  168. e.id = 6;
  169. e.username = "admin";
  170. e.nome = "admin";
  171. e.tipo = 4;
  172. e.password = "admin";
  173. a.Add(e);
  174. }
  175.  
  176. static void CarregarSessao(List<Sessao> c)
  177. {
  178. /* Sessao s = new Sessao();
  179. s.nome = "Os 3 Mosqueteiros";
  180. s.local = "Teatro Gil Vicente";
  181. s.data.ano = 2016;
  182. s.data.mes = 3;
  183. s.data.dia = 21;
  184. s.data.hora = 15;
  185. s.data.minutos = 30;
  186. s.data.fimhora = 18;
  187. s.data.fimminutos = 30;
  188. s.idsessao = 1;
  189. s.sala.numsala = 1;
  190. s.sala.capacidade = 50;
  191. c.Add(s);
  192.  
  193. string nome = "Teste";
  194. string local = "Teste";
  195. int ano =2016;
  196. int mes = 7;
  197. int dia = 23;
  198. int hora= 18;
  199. int minutos=45;
  200. int fimhora=20;
  201. int fimminutos=30;
  202. int idsessao=3;
  203. int numsala=2;
  204. int capacidade=75;
  205.  
  206. FileStream fs = new FileStream("Espetaculos.txt", FileMode.Append, FileAccess.Write);
  207. StreamWriter sw = new StreamWriter(fs);
  208. sw.WriteLine("{0, -4}{1, -40}{2, -30}{3, -4}{4, -2}{5, -2}{6, -2}{7, -2}{8, -2}{9, -2}{10, -3}{11, -4}", idsessao, nome, local, ano, mes, dia, hora, minutos, fimhora, fimminutos, numsala, capacidade);
  209. sw.Close();
  210. fs.Close();
  211. */
  212. string line;
  213. StreamReader sr = new StreamReader("Espetaculos.txt");
  214. while((line = sr.ReadLine()) != null)
  215. {
  216. int idsessao1 = Convert.ToInt32(line.Substring(0,4).Trim());
  217. string nome1 = line.Substring(4,40).Trim();
  218. string local1 = line.Substring(44,30).Trim();
  219. int ano1 = Convert.ToInt32(line.Substring(74, 4).Trim());
  220. int mes1 = Convert.ToInt32(line.Substring(78, 2).Trim());
  221. int dia1 = Convert.ToInt32(line.Substring(80, 2).Trim());
  222. int hora1 = Convert.ToInt32(line.Substring(82, 2).Trim());
  223. int minutos1 = Convert.ToInt32(line.Substring(84, 2).Trim());
  224. int fimhora1 = Convert.ToInt32(line.Substring(86, 2).Trim());
  225. int fimminutos1 = Convert.ToInt32(line.Substring(88, 2).Trim());
  226. int numsala1 = Convert.ToInt32(line.Substring(90, 3).Trim());
  227. int capacidade1 = Convert.ToInt32(line.Substring(93, 4).Trim());
  228.  
  229. Sessao f = new Sessao();
  230. f.idsessao = idsessao1;
  231. f.nome = nome1;
  232. f.local = local1;
  233. f.data.ano = ano1;
  234. f.data.mes = mes1;
  235. f.data.dia = dia1;
  236. f.data.hora = hora1;
  237. f.data.minutos = minutos1;
  238. f.data.fimhora = fimhora1;
  239. f.data.fimminutos = fimminutos1;
  240. f.sala.numsala = numsala1;
  241. f.sala.capacidade = capacidade1;
  242. c.Add(f);
  243. }
  244. /*
  245.  
  246. Sessao b = new Sessao();
  247. b.nome = "Os 3 Vilões";
  248. b.sala.capacidade = 75;
  249. b.sala.numsala = 2;
  250. b.local = "Teatro Gil Vicente";
  251. b.data.ano = 2016;
  252. b.data.mes = 3;
  253. b.data.dia = 21;
  254. b.data.hora = 15;
  255. b.data.minutos = 30;
  256. b.data.fimhora = 18;
  257. b.data.fimminutos = 30;
  258. b.idsessao = 2;
  259. c.Add(b);
  260. */
  261. }
  262.  
  263. static void CarregarConferencias(List<Conferencia> d)
  264. {
  265. Conferencia b = new Conferencia();
  266. b.sala.capacidade = 300;
  267. b.sala.numsala = 3;
  268. b.local = "Teatro Gil Vicente";
  269. b.nome = "Afinal a Terra gira";
  270. b.idsessao = 1;
  271. b.login.id = 5;
  272. b.data.dia = 15;
  273. b.data.mes = 08;
  274. b.data.ano = 2016;
  275. b.data.hora = 15;
  276. b.data.minutos = 00;
  277. b.data.fimhora = 17;
  278. b.data.fimminutos = 00;
  279. b.artigo = "Terra Redonda";
  280. b.login.nome = "Jorge";
  281. b.login.username = "Jorge";
  282. d.Add(b);
  283.  
  284.  
  285.  
  286. }
  287.  
  288. static Login CriarCliente(List<Login> a)
  289. {
  290. Login c = new Login();
  291. int contador = 0;
  292. string username;
  293.  
  294. Console.WriteLine("Nome?");
  295. c.nome = Console.ReadLine();
  296. do
  297. {
  298. Console.WriteLine("Username?");
  299. username = Console.ReadLine();
  300. for (int i = 0; i < a.Count; i++)
  301. {
  302. contador++;
  303. if (username == a[i].username)
  304. {
  305. Console.ForegroundColor = ConsoleColor.Red;
  306. Console.WriteLine("Username já existe.");
  307. Console.ForegroundColor = ConsoleColor.White;
  308. contador--;
  309. }
  310.  
  311. }
  312. } while (contador == a.Count - 1);
  313. c.username = username;
  314. Console.WriteLine("Password?");
  315. c.password = Console.ReadLine();
  316. c.tipo = 1;
  317. c.id = c.id + 1;
  318. Console.ForegroundColor = ConsoleColor.Green;
  319. Console.WriteLine("Utilizador criado com sucesso.");
  320. Console.ForegroundColor = ConsoleColor.White;
  321. return c;
  322. }
  323.  
  324. static void Ver(Sessao c)
  325. {
  326.  
  327. Console.WriteLine();
  328. Console.WriteLine("Espectáculo");
  329. Console.WriteLine("--------------------------------------------------");
  330. Console.WriteLine("{10} - {0}\nLocal: {2} Sala: {11}\nLugares Disponíves: {1} \nDia: {3:D2}/{4:D2}/{5} Duração: {6:D2}:{7:D2} - {8:D2}:{9:D2}", c.nome, c.sala.capacidade, c.local, c.data.dia, c.data.mes, c.data.ano, c.data.hora, c.data.minutos, c.data.fimhora, c.data.fimminutos, c.idsessao, c.sala.numsala);
  331. Console.WriteLine("--------------------------------------------------");
  332. }
  333.  
  334. static void VerSessao(List<Sessao> c)
  335. {
  336. if (c.Count == 0)
  337. {
  338. Console.ForegroundColor = ConsoleColor.Red;
  339. Console.WriteLine("Não existem Sessões");
  340. Console.ForegroundColor = ConsoleColor.White;
  341. }
  342. else
  343. {
  344. for (int i = 0; i < c.Count; i++)
  345. {
  346. Ver(c[i]);
  347. }
  348. }
  349. }
  350.  
  351. static void MostrarConferencia(Conferencia d)
  352. {
  353. Console.WriteLine();
  354. Console.WriteLine("Conferência Científica");
  355. Console.WriteLine("--------------------------------------------------");
  356. Console.WriteLine("{0} - {1}\nAutor: {12} Artigo: {13} \nLocal: {2} Sala: {3}\nLugares Disponíveis {4}\nDia: {5:D2}/{6:D2}/{7} Duração: {8:D2}:{9:D2} - {10:D2}:{11:D2}", d.idsessao, d.nome, d.local, d.sala.numsala, d.sala.capacidade, d.data.dia, d.data.mes, d.data.ano, d.data.hora, d.data.minutos, d.data.fimhora, d.data.fimminutos, d.login.nome, d.artigo);
  357. Console.WriteLine("--------------------------------------------------");
  358. }
  359.  
  360. static void VerConferencia(List<Conferencia> d)
  361. {
  362. if (d.Count == 0)
  363. {
  364. Console.ForegroundColor = ConsoleColor.Red;
  365. Console.WriteLine("Não existem Conferências");
  366. Console.ForegroundColor = ConsoleColor.White;
  367. }
  368. else
  369. {
  370. for (int i = 0; i < d.Count; i++)
  371. {
  372. MostrarConferencia(d[i]);
  373. }
  374. }
  375. }
  376.  
  377. static void Apagar(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d)
  378. {
  379. string pergunta;
  380. pergunta = ("Apagar (1 - Espectáculo --- 2 - Conferência --- 0 - Sair)");
  381. int num = TestarInt(pergunta);
  382.  
  383. if (num == 1)
  384. {
  385. VerSessao(c);
  386. pergunta = ("Qual deseja apagar? (Use os números para escolher)");
  387. int num3 = TestarInt(pergunta);
  388. for (int i = 0; i < c.Count; i++)
  389. {
  390. if (num3 == c[i].idsessao)
  391. {
  392. c.RemoveAt(i);
  393. Console.ForegroundColor = ConsoleColor.Green;
  394. Console.WriteLine("Apagado com sucesso");
  395. Console.ForegroundColor = ConsoleColor.White;
  396. break;
  397. }
  398. }
  399. }
  400.  
  401. if (num == 2)
  402. {
  403. VerConferencia(d);
  404. pergunta = ("Qual deseja apagar? (Use os números para escolher)");
  405. int num3 = TestarInt(pergunta);
  406. for (int i = 0; i < d.Count; i++)
  407. {
  408. if (num3 == d[i].idsessao)
  409. {
  410. d.RemoveAt(i);
  411. Console.ForegroundColor = ConsoleColor.Green;
  412. Console.WriteLine("Apagado com sucesso");
  413. Console.ForegroundColor = ConsoleColor.White;
  414. break;
  415. }
  416. }
  417. }
  418.  
  419. }
  420.  
  421. static void VerConferenciaAutor(List<Conferencia> d, ref int id)
  422. {
  423. for (int i = 0; i < d.Count; i++)
  424. {
  425. if (id == d[i].login.id)
  426. {
  427. VerConferencia(d);
  428. }
  429. }
  430. }
  431.  
  432. static void InserirConferenciaAutor(List<Conferencia> d, ref int id)
  433. {
  434. string pergunta;
  435. VerConferenciaAutor(d, ref id);
  436. pergunta = ("Escolha a conferencia onde deseja por um artigo");
  437. int num = TestarInt(pergunta);
  438. for (int i = 0; i < d.Count; i++)
  439. {
  440. if (num == d[i].idsessao)
  441. {
  442. Console.WriteLine("Artigo a introduzir");
  443. string artigo = Console.ReadLine();
  444. Conferencia conferencia = d[i];
  445. conferencia.artigo = artigo;
  446. d[i] = conferencia;
  447.  
  448. }
  449. }
  450. }
  451.  
  452. static Login CriarOrganizador(List<Login> a)
  453. {
  454. Login c = new Login();
  455. int contador = 0;
  456. string username;
  457.  
  458. Console.WriteLine("Nome?");
  459. c.nome = Console.ReadLine();
  460. do
  461. {
  462. Console.WriteLine("Username?");
  463. username = Console.ReadLine();
  464. for (int i = 0; i < a.Count; i++)
  465. {
  466. contador++;
  467. if (username == a[i].username)
  468. {
  469. Console.ForegroundColor = ConsoleColor.Red;
  470. Console.WriteLine("Username já existe.");
  471. Console.ForegroundColor = ConsoleColor.White;
  472. contador--;
  473. }
  474.  
  475. }
  476. } while (contador == a.Count - 1);
  477. c.username = username;
  478. Console.WriteLine("Password?");
  479. c.password = Console.ReadLine();
  480. c.tipo = 2;
  481. c.id = c.id + 1;
  482. Console.ForegroundColor = ConsoleColor.Green;
  483. Console.WriteLine("Organizador criado com sucesso.");
  484. Console.ForegroundColor = ConsoleColor.White;
  485. return c;
  486. }
  487. static Login CriarAutor(List<Login> a)
  488. {
  489. Login c = new Login();
  490. int contador = 0;
  491. string username;
  492.  
  493. Console.WriteLine("Nome?");
  494. c.nome = Console.ReadLine();
  495. do
  496. {
  497. Console.WriteLine("Username?");
  498. username = Console.ReadLine();
  499. for (int i = 0; i < a.Count; i++)
  500. {
  501. contador++;
  502. if (username == a[i].username)
  503. {
  504. Console.ForegroundColor = ConsoleColor.Red;
  505. Console.WriteLine("Username já existe.");
  506. Console.ForegroundColor = ConsoleColor.White;
  507. contador--;
  508. }
  509. }
  510. } while (contador == a.Count - 1);
  511. c.username = username;
  512. Console.WriteLine("Password?");
  513. c.password = Console.ReadLine();
  514. c.tipo = 3;
  515. c.id = c.id + 1;
  516. Console.ForegroundColor = ConsoleColor.Green;
  517. Console.WriteLine("Autor criado com sucesso.");
  518. Console.ForegroundColor = ConsoleColor.White;
  519. return c;
  520. }
  521.  
  522. static void CriarSalas(List<Sala> b)
  523. {
  524. Sala s = new Sala();
  525. string pergunta;
  526. chu:
  527. pergunta = "Tamanho da sala?";
  528. int num = TestarInt(pergunta);
  529. if (num >= 50)
  530. {
  531. s.capacidade = num;
  532. chu2:
  533. pergunta = ("Tipo de sala? (1 - Espectáculos / 2 - Conferencias");
  534. int num2 = TestarInt(pergunta);
  535. if (num2 == 1 || num2 == 2)
  536. {
  537. s.tipo = num2;
  538. for (int p = 0; p < b.Count; p++)
  539. {
  540. if (p == b.Count - 1)
  541. {
  542. s.numsala = b[p].numsala + 1;
  543. }
  544. }
  545. b.Add(s);
  546. Console.ForegroundColor = ConsoleColor.Green;
  547. Console.WriteLine("Sala criada com sucesso.");
  548. Console.ForegroundColor = ConsoleColor.White;
  549. }
  550. else {
  551. Console.ForegroundColor = ConsoleColor.Red;
  552. Console.WriteLine("Tipo de sala não existe");
  553. Console.ForegroundColor = ConsoleColor.White;
  554. goto chu2;
  555. }
  556. }
  557. if (num < 50)
  558. {
  559. Console.ForegroundColor = ConsoleColor.Red;
  560. Console.WriteLine("A sala tem que ter pelo menos 50 lugares");
  561. Console.ForegroundColor = ConsoleColor.White;
  562. goto chu;
  563. }
  564.  
  565. }
  566.  
  567. static void MenuAdmin(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int[] fa)
  568. {
  569. int num;
  570. string pergunta;
  571. do
  572. {
  573. Console.WriteLine("//////////////////////////////////");
  574. Console.WriteLine("/ 1 - Criar Organizador /");
  575. Console.WriteLine("/ 2 - Criar Autor /");
  576. Console.WriteLine("/ 3 - Adicionar Sala /");
  577. Console.WriteLine("/ 4 - Ver Salas /");
  578. Console.WriteLine("/ 9 - Logout /");
  579. Console.WriteLine("//////////////////////////////////");
  580. pergunta = ("");
  581. num = TestarInt(pergunta);
  582. switch (num)
  583. {
  584. case 1:
  585. Console.Clear();
  586. Console.WriteLine();
  587. Console.WriteLine();
  588. a.Add(CriarOrganizador(a));
  589. break;
  590. case 2:
  591. Console.Clear();
  592. Console.WriteLine();
  593. Console.WriteLine();
  594. a.Add(CriarAutor(a));
  595. break;
  596. case 3:
  597. Console.Clear();
  598. Console.WriteLine();
  599. Console.WriteLine();
  600. CriarSalas(b);
  601. break;
  602. case 4:
  603. Console.Clear();
  604. Console.WriteLine();
  605. Console.WriteLine();
  606. MostrarSalas(b);
  607. Console.WriteLine();
  608. Console.WriteLine();
  609. break;
  610. case 9:
  611. Console.Clear();
  612. Log(a, b, c, d, ref fa, e, f);
  613. break;
  614.  
  615. default:
  616. Console.ForegroundColor = ConsoleColor.Red;
  617. Console.WriteLine("Introduza um valor válido");
  618. Console.ForegroundColor = ConsoleColor.White;
  619. break;
  620. }
  621. } while (num != 9);
  622. }
  623.  
  624. static void MenuAutor(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int id, ref int[] fa)
  625. {
  626. int num;
  627. string pergunta;
  628. do
  629. {
  630. Console.WriteLine("//////////////////////////////////");
  631. Console.WriteLine("/ 1 - Ver as suas Conferencias /");
  632. Console.WriteLine("/ 2 - Inserir Artigo /");
  633. Console.WriteLine("/ 9 - Logout /");
  634. Console.WriteLine("//////////////////////////////////");
  635. pergunta = ("");
  636. num = TestarInt(pergunta);
  637. switch (num)
  638. {
  639. case 1:
  640. Console.Clear();
  641. Console.WriteLine();
  642. Console.WriteLine();
  643. VerConferenciaAutor(d, ref id);
  644.  
  645. break;
  646. case 2:
  647. Console.Clear();
  648. Console.WriteLine();
  649. Console.WriteLine();
  650. InserirConferenciaAutor(d, ref id);
  651. break;
  652. case 9:
  653. Console.Clear();
  654.  
  655. Log(a, b, c, d, ref fa, e, f);
  656. break;
  657.  
  658. default:
  659. Console.ForegroundColor = ConsoleColor.Red;
  660. Console.WriteLine("Introduza um valor válido");
  661. Console.ForegroundColor = ConsoleColor.White;
  662. break;
  663. }
  664. } while (num != 9);
  665. }
  666.  
  667. static void ComprarSessao(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int id)
  668. {
  669. string pergunta;
  670. VerSessao(c);
  671. pergunta = ("Qual a Sessão que gostaria de assistir?(Use os números para escolher)");
  672. int num1 = TestarInt(pergunta);
  673.  
  674. for (int i = 0; i < c.Count; i++)
  675. {
  676.  
  677. if (num1 == c[i].idsessao)
  678. {
  679. for (int n = 0; n < c.Count; n++)
  680. {
  681. if (num1 == c[n].idsessao)
  682. {
  683. bilh:
  684. Console.WriteLine("Escolheu a Conferencia " + c[n].nome);
  685. pergunta = ("Quantos bilhetes deseja comprar?");
  686. int num2 = TestarInt(pergunta);
  687. if (num2 > 10)
  688. {
  689. Console.ForegroundColor = ConsoleColor.Red;
  690. Console.WriteLine("Só pode comprar 10 bilhetes no máximo");
  691. Console.ForegroundColor = ConsoleColor.White;
  692. goto bilh;
  693. }
  694. if (num2 > c[n].sala.capacidade)
  695. {
  696. Console.ForegroundColor = ConsoleColor.Red;
  697. Console.WriteLine("Só existem " + c[n].sala.capacidade + " bilhetes disponíveis, para o espectáculo: " + c[n].nome);
  698. Console.ForegroundColor = ConsoleColor.White;
  699. goto bilh;
  700. }
  701. int total = c[n].sala.capacidade - num2;
  702. Sessao sessao = c[n];
  703. sessao.sala.capacidade = total;
  704. c[n] = sessao;
  705.  
  706. BilheteSessao h = new BilheteSessao();
  707. h.login.id = id;
  708. h.quantidade = num2;
  709. h.sessao.idsessao = c[n].idsessao;
  710. h.sessao.nome = c[n].nome;
  711. h.sala.numsala = c[n].sala.numsala;
  712. h.data.hora = c[n].data.hora;
  713. h.data.minutos = c[n].data.minutos;
  714. h.data.fimhora = c[n].data.fimhora;
  715. h.data.fimminutos = c[n].data.fimminutos;
  716. h.data.ano = c[n].data.ano;
  717. h.data.mes = c[n].data.mes;
  718. h.data.dia = c[n].data.dia;
  719. f.Add(h);
  720. Console.ForegroundColor = ConsoleColor.Green;
  721. Console.WriteLine(num2 + " bilhetes comprados com sucesso");
  722. Console.ForegroundColor = ConsoleColor.White;
  723. break;
  724. }
  725. }
  726. }
  727. if (num1 != c[i].idsessao && i == c.Count)
  728. {
  729. Console.ForegroundColor = ConsoleColor.Red;
  730. Console.WriteLine("Sessão não existe");
  731. Console.ForegroundColor = ConsoleColor.White;
  732. }
  733. }
  734. }
  735.  
  736. static void Comprar(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int id)
  737. {
  738. int resposta;
  739.  
  740. string pergunta;
  741. bili:
  742. pergunta = ("Tipo de Bilhete a comprar (1 - Espéctaculo normal 2 - Conferencia 0 - Sair)");
  743. resposta = TestarInt(pergunta);
  744. if (resposta == 2)
  745. {
  746. VerConferencia(d);
  747. pergunta = ("Qual a Sessão que gostaria de assistir?(Use os números para escolher)");
  748. int num1 = TestarInt(pergunta);
  749.  
  750. for (int n = 0; n < d.Count; n++)
  751. {
  752. if (num1 == d[n].idsessao)
  753. {
  754. bilh:
  755. Console.WriteLine("Escolheu a Conferencia " + d[n].nome);
  756. pergunta = ("Quantos bilhetes deseja comprar?");
  757. int num2 = TestarInt(pergunta);
  758. if (num2 < 0)
  759. {
  760. Console.WriteLine("Tem que comprar pelo menos 1 bilhete.");
  761. goto bilh;
  762. }
  763. if (num2 > 10)
  764. {
  765. Console.ForegroundColor = ConsoleColor.Red;
  766. Console.WriteLine("Só pode comprar 10 bilhetes no máximo");
  767. Console.ForegroundColor = ConsoleColor.White;
  768. goto bilh;
  769. }
  770. if (num2 > d[n].sala.capacidade)
  771. {
  772. Console.ForegroundColor = ConsoleColor.Red;
  773. Console.WriteLine("Só existem " + d[n].sala.capacidade + " bilhetes disponíveis");
  774. Console.ForegroundColor = ConsoleColor.White;
  775. goto bilh;
  776. }
  777. int total = d[n].sala.capacidade - num2;
  778. Conferencia sessao = d[n];
  779. sessao.sala.capacidade = total;
  780. d[n] = sessao;
  781.  
  782. BilheteConferencia y = new BilheteConferencia();
  783. y.login.id = id;
  784. y.quantidade = num2;
  785. y.conferencia.idsessao = d[n].idsessao;
  786. y.conferencia.nome = d[n].nome;
  787. y.sala.numsala = d[n].sala.numsala;
  788. y.data.hora = d[n].data.hora;
  789. y.data.minutos = d[n].data.minutos;
  790. y.data.fimhora = d[n].data.fimhora;
  791. y.data.fimminutos = d[n].data.fimminutos;
  792. y.data.ano = c[n].data.ano;
  793. y.data.mes = c[n].data.mes;
  794. y.data.dia = c[n].data.dia;
  795. e.Add(y);
  796. Console.ForegroundColor = ConsoleColor.Green;
  797. Console.WriteLine(num2 + " bilhetes comprados com sucesso");
  798. Console.ForegroundColor = ConsoleColor.White;
  799. break;
  800. }
  801. if (num1 != d[n].idsessao && n == d.Count)
  802. {
  803. Console.ForegroundColor = ConsoleColor.Red;
  804. Console.WriteLine("Conferência não existe");
  805. Console.ForegroundColor = ConsoleColor.White;
  806. }
  807. }
  808.  
  809. }
  810. if (resposta == 1)
  811. {
  812. ComprarSessao(a, b, c, d, e, f, ref id);
  813. }
  814. else
  815. {
  816. Console.ForegroundColor = ConsoleColor.Red;
  817. Console.WriteLine("Opção não existe");
  818. Console.ForegroundColor = ConsoleColor.White;
  819. goto bili;
  820. }
  821. }
  822. static void MostrarBilheteConferencia(BilheteConferencia e)
  823. {
  824. Console.WriteLine("Nome: {0} Quantidade:{1} Sala:{2} \nData: {3:D2}/{4:D2}/{5} Horário: {6:D2}:{7:D2} - {8:D2}:{9:D2}", e.conferencia.nome, e.quantidade, e.sala.numsala, e.data.dia, e.data.mes, e.data.ano, e.data.hora, e.data.minutos, e.data.fimhora, e.data.fimminutos);
  825. Console.WriteLine();
  826. }
  827. static void MostrarBilheteSessao(BilheteSessao f)
  828. {
  829. Console.WriteLine("Nome: {0} Quantidade: {1} Sala:{2} \nData: {3:D2}/{4:D2}/{5} Horário: {6:D2}:{7:D2} - {8:D2}:{9:D2}", f.sessao.nome, f.quantidade, f.sala.numsala, f.data.dia, f.data.mes, f.data.ano, f.data.hora, f.data.minutos, f.data.fimhora, f.data.fimminutos);
  830. Console.WriteLine();
  831. }
  832. static void VerBilhetesCliente(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int id)
  833. {
  834. int contar = 0;
  835. for (int i = 0; i < a.Count; i++)
  836. {
  837. if (id == a[i].id)
  838. {
  839. for (int k = 0; k < e.Count-1; k++)
  840. {
  841. if (e[k].login.id == id)
  842. {
  843. MostrarBilheteConferencia(e[k]);
  844. contar++;
  845. }
  846.  
  847. }
  848.  
  849. for (int p = 0; p < f.Count-1; p++)
  850. {
  851. if (f[p].login.id == id)
  852. {
  853. MostrarBilheteSessao(f[p]);
  854. contar++;
  855. }
  856. }
  857. }
  858. if (contar == 0 && i == a.Count - 1)
  859. {
  860. Console.ForegroundColor = ConsoleColor.Red;
  861. Console.WriteLine("Não comprou bilhetes");
  862. Console.ForegroundColor = ConsoleColor.White;
  863. }
  864. }
  865.  
  866. }
  867. static void MenuCliente(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int id, ref int[] fa)
  868. {
  869. int num;
  870. string pergunta;
  871. do
  872. {
  873. Console.WriteLine();
  874. Console.WriteLine("//////////////////////////////////");
  875. Console.WriteLine("/ 1 - Ver Espectáculos /");
  876. Console.WriteLine("/ 2 - Ver Conferencia /");
  877. Console.WriteLine("/ 3 - Comprar bilhete /");
  878. Console.WriteLine("/ 4 - Ver bilhetes comprados /");
  879. Console.WriteLine("/ 9 - Logout /");
  880. Console.WriteLine("//////////////////////////////////");
  881. pergunta = ("");
  882. num = TestarInt(pergunta);
  883. switch (num)
  884. {
  885. case 1:
  886. Console.Clear();
  887. Console.WriteLine();
  888. Console.WriteLine();
  889. VerSessao(c);
  890. break;
  891. case 2:
  892. Console.Clear();
  893. Console.WriteLine();
  894. Console.WriteLine();
  895. VerConferencia(d);
  896. break;
  897. case 3:
  898. Console.Clear();
  899. Console.WriteLine();
  900. Console.WriteLine();
  901. Comprar(a, b, c, d, e, f, ref id);
  902. break;
  903. case 4:
  904. Console.Clear();
  905. Console.WriteLine();
  906. Console.WriteLine();
  907. VerBilhetesCliente(a, b, c, d, e, f, ref id);
  908. break;
  909. case 9:
  910. Console.Clear();
  911.  
  912. Log(a, b, c, d, ref fa, e, f);
  913. break;
  914. default:
  915. Console.ForegroundColor = ConsoleColor.Red;
  916. Console.WriteLine("Introduza um valor válido");
  917. Console.ForegroundColor = ConsoleColor.White;
  918. break;
  919. }
  920. } while (num != 9);
  921. }
  922.  
  923. static void Log(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, ref int[] fa, List<BilheteConferencia> e, List<BilheteSessao> f)
  924. {
  925. string pergunta;
  926. int num;
  927. int i;
  928. string user, pass;
  929. int id;
  930. do
  931. {
  932. pergunta = ("");
  933. Console.WriteLine();
  934. Console.WriteLine("//////////////////////////////////");
  935. Console.WriteLine("/ BEM VINDO! /");
  936. Console.WriteLine("//////////////////////////////////");
  937. Console.WriteLine("/ 1 - Registar-se /");
  938. Console.WriteLine("/ 2 - Login /");
  939. Console.WriteLine("/ 9 - Sair /");
  940. Console.WriteLine("//////////////////////////////////");
  941.  
  942. num = TestarInt(pergunta);
  943. switch (num)
  944. {
  945. case 1:
  946. a.Add(CriarCliente(a));
  947. break;
  948. case 2:
  949.  
  950. Console.Clear();
  951.  
  952. do
  953. {
  954. Console.WriteLine("//////////////////////////////////");
  955. Console.WriteLine("/ LOGIN /");
  956. Console.WriteLine("//////////////////////////////////");
  957. Console.WriteLine("/ 0 - SAIR /");
  958. Console.WriteLine("//////////////////////////////////");
  959. tua:
  960. Console.Write("Username: ");
  961. user = Console.ReadLine();
  962. int tipo;
  963. for (i = 0; i < a.Count; i++)
  964. {
  965. if (user != a[i].username && i == a.Count - 1)
  966. {
  967. Console.ForegroundColor = ConsoleColor.Red;
  968. Console.WriteLine("Username não existe");
  969. Console.ForegroundColor = ConsoleColor.White;
  970. }
  971.  
  972.  
  973. if (user == a[i].username)
  974. {
  975. Console.WriteLine();
  976. tipo = a[i].tipo;
  977. Console.Write("Password: ");
  978. pass = Console.ReadLine();
  979. if (pass != a[i].password)
  980. {
  981. Console.ForegroundColor = ConsoleColor.Red;
  982. Console.WriteLine("Password Errada. Tente de novo.");
  983. Console.ForegroundColor = ConsoleColor.White;
  984. goto tua;
  985. }
  986. else
  987. {
  988. if (tipo == 1)
  989. {
  990. id = a[i].id;
  991. Console.Clear();
  992. MenuCliente(a, b, c, d, e, f, ref id, ref fa);
  993. }
  994.  
  995. if (tipo == 2)
  996. {
  997. Console.Clear();
  998. MenuOrganizador(a, b, c, d, e, f, ref fa);
  999. }
  1000. if (tipo == 3)
  1001. {
  1002. id = a[i].id;
  1003. Console.Clear();
  1004. MenuAutor(a, b, c, d, e, f, ref id, ref fa);
  1005. }
  1006. if (tipo == 4)
  1007. {
  1008. Console.Clear();
  1009. MenuAdmin(a, b, c, d, e, f, ref fa);
  1010. }
  1011. }
  1012. }
  1013. }
  1014. } while (user != "0");
  1015. break;
  1016. case 9:
  1017. System.Environment.Exit(1);
  1018. break;
  1019. default:
  1020. Console.ForegroundColor = ConsoleColor.Red;
  1021. Console.WriteLine("Opção não existe");
  1022. Console.ForegroundColor = ConsoleColor.White;
  1023. break;
  1024.  
  1025. }
  1026. } while (num != 9);
  1027.  
  1028.  
  1029. }
  1030.  
  1031. static void MenuOrganizador(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int[] fa)
  1032. {
  1033. int num;
  1034. string pergunta;
  1035.  
  1036. do
  1037. {
  1038. Console.WriteLine();
  1039. Console.WriteLine("///////////////////////////////////////////");
  1040. Console.WriteLine("/ 1 - Ver Espectáculos /");
  1041. Console.WriteLine("/ 2 - Ver Conferencias /");
  1042. Console.WriteLine("/ 3 - Criar Espectáculos / Conferencias /");
  1043. Console.WriteLine("/ 4 - Apagar Espectáculos / Conferências /");
  1044. Console.WriteLine("/ 9 - Logout /");
  1045. Console.WriteLine("///////////////////////////////////////////");
  1046.  
  1047. pergunta = ("");
  1048. num = TestarInt(pergunta);
  1049. switch (num)
  1050. {
  1051. case 1:
  1052. Console.Clear();
  1053. Console.WriteLine();
  1054. Console.WriteLine();
  1055. VerSessao(c);
  1056. break;
  1057. case 2:
  1058. Console.Clear();
  1059. Console.WriteLine();
  1060. Console.WriteLine();
  1061. VerConferencia(d);
  1062. break;
  1063. case 3:
  1064. Console.Clear();
  1065. Console.WriteLine();
  1066. Console.WriteLine();
  1067. CriarEspectaculo(a, b, c, d, e, f, ref fa);
  1068. break;
  1069. case 4:
  1070. Console.Clear();
  1071. Console.WriteLine();
  1072. Console.WriteLine();
  1073. Apagar(a, b, c, d);
  1074. break;
  1075. case 9:
  1076. Console.Clear();
  1077.  
  1078. Log(a, b, c, d, ref fa, e, f);
  1079. break;
  1080. default:
  1081. Console.ForegroundColor = ConsoleColor.Red;
  1082. Console.WriteLine("Introduza um valor válido");
  1083. Console.ForegroundColor = ConsoleColor.White;
  1084. break;
  1085.  
  1086. }
  1087. } while (num != 9);
  1088. }
  1089.  
  1090. static void VerSalas(Sala b)
  1091. {
  1092. Console.Write("Sala - {0} Lugares: {1} ", b.numsala, b.capacidade);
  1093. }
  1094.  
  1095. static void MostrarSalas(List<Sala> b)
  1096. {
  1097. for (int i = 0; i < b.Count; i++)
  1098. {
  1099. VerSalas(b[i]);
  1100. }
  1101. }
  1102.  
  1103. static void VerAutor(Login a)
  1104. {
  1105. Console.Write("{1} - {0}", a.nome, a.id);
  1106. }
  1107.  
  1108. static void MostrarAutor(List<Login> a)
  1109. {
  1110. for (int i = 0; i < a.Count; i++)
  1111. {
  1112. if (a[i].tipo == 3)
  1113. {
  1114. VerAutor(a[i]);
  1115. }
  1116. }
  1117. }
  1118.  
  1119. static void VerificarHoras(ref int[] fa, int contare, int hora1, int hora2, int min1, int min2, int tipo, List<Sessao> c, ref int ok)
  1120. {
  1121. int contar = 0;
  1122. int conta = 0;
  1123. ok = 0;
  1124.  
  1125. if (contare == 1)
  1126. {
  1127.  
  1128. for (int k = 0; k < c.Count; k++)
  1129. {
  1130. if (fa[0] == c[k].idsessao)
  1131. {
  1132. if (c[k].data.fimhora < hora1)
  1133. {
  1134. conta++;
  1135. }
  1136. if (c[k].data.hora > hora1)
  1137. {
  1138. if (c[k].data.hora > hora2)
  1139. {
  1140. conta++;
  1141. }
  1142. }
  1143. else
  1144. {
  1145. contar++;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. if (conta == contare)
  1151. {
  1152. ok = 1;
  1153. }
  1154.  
  1155.  
  1156. conta = 0;
  1157. if (contare > 1)
  1158. {
  1159.  
  1160. for (int i = 0; i < fa.Length; i++)
  1161. {
  1162. for (int k = 0; k < c.Count; k++)
  1163. {
  1164. if (fa[i] == c[k].idsessao)
  1165. {
  1166. if (c[k].data.hora > hora1 && c[k].data.hora > hora2)
  1167. {
  1168. if (c[k].data.hora > hora2)
  1169. {
  1170. conta++;
  1171.  
  1172. }
  1173. else
  1174. {
  1175. break;
  1176. }
  1177. }
  1178. if (c[k].data.fimhora < hora1)
  1179. {
  1180. conta++;
  1181.  
  1182. }
  1183.  
  1184. else
  1185. {
  1186. break;
  1187. }
  1188. }
  1189.  
  1190.  
  1191. }
  1192. }
  1193. if (conta == contare)
  1194. {
  1195. ok = 1;
  1196. }
  1197. }
  1198. }
  1199.  
  1200. static void VerificaHorasConferencia(ref int[] fa, int contare, int hora1, int hora2, int min1, int min2, int tipo, List<Conferencia> d, ref int ok)
  1201. {
  1202. int contar = 0;
  1203. int conta = 0;
  1204. ok = 0;
  1205.  
  1206. if (contare == 1)
  1207. {
  1208.  
  1209. for (int k = 0; k < d.Count; k++)
  1210. {
  1211. if (fa[0] == d[k].idsessao)
  1212. {
  1213. if (d[k].data.fimhora < hora1)
  1214. {
  1215. conta++;
  1216. }
  1217. if (d[k].data.hora > hora1)
  1218. {
  1219. if (d[k].data.hora > hora2)
  1220. {
  1221. conta++;
  1222. }
  1223. }
  1224. else
  1225. {
  1226. contar++;
  1227. }
  1228. }
  1229. }
  1230. }
  1231. if (conta == contare)
  1232. {
  1233. ok = 1;
  1234. }
  1235.  
  1236.  
  1237. conta = 0;
  1238. if (contare > 1)
  1239. {
  1240.  
  1241. for (int i = 0; i < fa.Length; i++)
  1242. {
  1243. for (int k = 0; k < d.Count; k++)
  1244. {
  1245. if (fa[i] == d[k].idsessao)
  1246. {
  1247. if (d[k].data.hora > hora1 && d[k].data.hora > hora2)
  1248. {
  1249. if (d[k].data.hora > hora2)
  1250. {
  1251. conta++;
  1252.  
  1253. }
  1254. else
  1255. {
  1256. break;
  1257. }
  1258. }
  1259. if (d[k].data.fimhora < hora1)
  1260. {
  1261. conta++;
  1262.  
  1263. }
  1264.  
  1265. else
  1266. {
  1267. break;
  1268. }
  1269. }
  1270.  
  1271.  
  1272. }
  1273. }
  1274. if (conta == contare)
  1275. {
  1276. ok = 1;
  1277. }
  1278. }
  1279. }
  1280.  
  1281.  
  1282.  
  1283. static void CriarConferencia(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int[] fa)
  1284. {
  1285.  
  1286. string pergunta;
  1287.  
  1288. int ano, mes, dia;
  1289. int contador = 0;
  1290. pergunta = ("Sessões a criar?");
  1291. int num = TestarInt(pergunta);
  1292. for (int i = 0; i < num; i++)
  1293. {
  1294. for (int o = 0; o < b.Count; o++)
  1295. {
  1296. if (b[o].tipo == 2)
  1297. VerSalas(b[o]);
  1298.  
  1299. }
  1300. Conferencia s = new Conferencia();
  1301. sui:
  1302. pergunta = ("\nSala a ocupar");
  1303. int num2 = TestarInt(pergunta);
  1304. // Ver se sala introduzida existe
  1305. for (int u = 0; u < b.Count; u++)
  1306. {
  1307. if (num2 != b[u].numsala)
  1308. {
  1309. contador++;
  1310. }
  1311.  
  1312. if (num2 != b[u].numsala && contador == b.Count)
  1313. {
  1314. contador = 0;
  1315. Console.ForegroundColor = ConsoleColor.Red;
  1316. Console.WriteLine("Sala não existe.");
  1317. Console.ForegroundColor = ConsoleColor.White;
  1318. goto sui;
  1319. }
  1320. if (num2 == b[u].numsala)
  1321. {
  1322. if (b[u].tipo == 2)
  1323. {
  1324. s.sala.numsala = num2;
  1325. s.sala.capacidade = b[u].capacidade;
  1326. }
  1327. else
  1328. {
  1329. contador = 0;
  1330. Console.ForegroundColor = ConsoleColor.Red;
  1331. Console.WriteLine("Sala escolhida não serve.");
  1332. Console.ForegroundColor = ConsoleColor.White;
  1333. goto sui;
  1334. }
  1335. lol:
  1336. Console.WriteLine("Dia do Espectáculo? (dd-mm-AAAA ou dd/mm/AAAA)");
  1337. string[] dataa = Console.ReadLine().Split('-', '/');
  1338. ano = Convert.ToInt32(dataa[2]);
  1339. if (ano < 2016)
  1340. {
  1341. Console.ForegroundColor = ConsoleColor.Red;
  1342. Console.Write("Só pode marcar espectáculos no ano de 2016 ou mais\n");
  1343. Console.ForegroundColor = ConsoleColor.White;
  1344. goto lol;
  1345. }
  1346. mes = Convert.ToInt32(dataa[1]);
  1347. if (mes > 12 || mes < 1)
  1348. {
  1349. Console.ForegroundColor = ConsoleColor.Red;
  1350. Console.WriteLine("Só existem 12 meses");
  1351. Console.ForegroundColor = ConsoleColor.White;
  1352. goto lol;
  1353. }
  1354.  
  1355. dia = Convert.ToInt32(dataa[0]);
  1356.  
  1357. if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12)
  1358. {
  1359. if (dia > 31 || dia < 1)
  1360. {
  1361. Console.ForegroundColor = ConsoleColor.Red;
  1362. Console.WriteLine("O mês escolhido tem apenas 31 dias.");
  1363. Console.ForegroundColor = ConsoleColor.White;
  1364. goto lol;
  1365. }
  1366. }
  1367. if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
  1368. {
  1369. if (dia > 30 || dia < 1)
  1370. {
  1371. Console.ForegroundColor = ConsoleColor.Red;
  1372. Console.WriteLine("O mês escolhido tem apenas 30 dias.");
  1373. Console.ForegroundColor = ConsoleColor.White;
  1374. goto lol;
  1375. }
  1376. }
  1377. if (mes == 2)
  1378. {
  1379. if (dia > 28 || dia < 1)
  1380. {
  1381. Console.ForegroundColor = ConsoleColor.Red;
  1382. Console.WriteLine("O mês escolhido tem apenas 28 dias.");
  1383. Console.ForegroundColor = ConsoleColor.White;
  1384. goto lol;
  1385. }
  1386. }
  1387.  
  1388. s.data.dia = dia;
  1389. s.data.mes = mes;
  1390. s.data.ano = ano;
  1391.  
  1392. tui:
  1393. int ok = 0;
  1394. int contar = 0;
  1395. int contare = 0;
  1396. int o;
  1397. int tipo = 0;
  1398.  
  1399.  
  1400.  
  1401. Console.WriteLine("Hora de começo? (hh:mm)");
  1402. string[] horaa = Console.ReadLine().Split(':');
  1403. int hora1 = Convert.ToInt32(horaa[0]);
  1404. int min1 = Convert.ToInt32(horaa[1]);
  1405. Console.WriteLine("Hora de finalização? (hh:mm)");
  1406. string[] horaa2 = Console.ReadLine().Split(':');
  1407. int hora2 = Convert.ToInt32(horaa2[0]);
  1408. int min2 = Convert.ToInt32(horaa2[1]);
  1409. if (min2 < 0 || min2 > 59 || min1 < 0 || min1 > 59)
  1410. {
  1411. Console.ForegroundColor = ConsoleColor.Red;
  1412. Console.WriteLine("Minutos mal introduzidos");
  1413. Console.ForegroundColor = ConsoleColor.White;
  1414. goto tui;
  1415. }
  1416. if (hora1 < 9 || hora2 < 9 || hora1 > 24 || hora2 > 24)
  1417. {
  1418. Console.ForegroundColor = ConsoleColor.Red;
  1419. Console.WriteLine("Os espéctaculos só podem durar até às 24:00 e começar às 9:00");
  1420. Console.ForegroundColor = ConsoleColor.White;
  1421. goto tui;
  1422. }
  1423. if (hora1 == 24 || hora2 == 24)
  1424. {
  1425. if (min1 > 0 || min2 > 0)
  1426. {
  1427. Console.ForegroundColor = ConsoleColor.Red;
  1428. Console.WriteLine("O establecimento fecha às 24.00");
  1429. Console.ForegroundColor = ConsoleColor.White;
  1430. goto tui;
  1431. }
  1432. }
  1433. if (hora1 + 1 > hora2)
  1434. {
  1435. Console.ForegroundColor = ConsoleColor.Red;
  1436. Console.WriteLine("Os espectáculos têm que durar pelo menos uma hora");
  1437. Console.ForegroundColor = ConsoleColor.White;
  1438. goto tui;
  1439. }
  1440. if (hora1 > hora2)
  1441. {
  1442. Console.ForegroundColor = ConsoleColor.Red;
  1443. Console.WriteLine("A hora de início tem que ser menor que a hora final");
  1444. Console.ForegroundColor = ConsoleColor.White;
  1445. goto tui;
  1446. }
  1447.  
  1448. //show de uma hora
  1449. if (hora1 + 1 == hora2)
  1450. {
  1451. if (min1 > min2)
  1452. {
  1453. Console.ForegroundColor = ConsoleColor.Red;
  1454. Console.WriteLine("Os espectáculos têm de durar pelo menos uma hora");
  1455. Console.ForegroundColor = ConsoleColor.White;
  1456. goto tui;
  1457. }
  1458. if (min1 <= min2)
  1459. {
  1460. tipo = 1;
  1461. }
  1462. }
  1463.  
  1464. if (fa.Length >= 1)
  1465. {
  1466. Array.Clear(fa, 0, fa.Length);
  1467. }
  1468.  
  1469. for (o = 0; o < d.Count; o++)
  1470. {
  1471. if (d[o].data.mes != s.data.mes && s.data.ano != d[o].data.ano && d[o].data.dia != s.data.dia)
  1472. {
  1473. contar++;
  1474. }
  1475.  
  1476. if (mes == d[o].data.mes && dia == d[o].data.dia && ano == d[o].data.ano && d[o].sala.numsala == s.sala.numsala)
  1477. {
  1478. Array.Resize(ref fa, fa.Length + 1);
  1479. fa[contare] = d[o].idsessao;
  1480. contare++;
  1481. }
  1482. }
  1483. if (contare >= 1)
  1484. {
  1485. VerificaHorasConferencia(ref fa, contare, hora1, hora2, min1, min2, tipo, d, ref ok);
  1486.  
  1487.  
  1488. if (ok == 1)
  1489. {
  1490. s.data.hora = hora1;
  1491. s.data.minutos = min1;
  1492. s.data.fimhora = hora2;
  1493. s.data.fimminutos = min2;
  1494. }
  1495. if (ok != 1)
  1496. {
  1497. Console.ForegroundColor = ConsoleColor.Red;
  1498. Console.WriteLine("Hora indisponível.");
  1499. Console.ForegroundColor = ConsoleColor.White;
  1500. goto tui;
  1501. }
  1502.  
  1503. Console.WriteLine("Nome");
  1504. s.nome = Console.ReadLine();
  1505. for (int p = 0; p < d.Count; p++)
  1506. {
  1507. if (p == d.Count - 1)
  1508. {
  1509. s.idsessao = d[p].idsessao + 1;
  1510. }
  1511. }
  1512.  
  1513.  
  1514.  
  1515. s.local = "Teatro Gil Vicente";
  1516. d.Add(s);
  1517. Console.ForegroundColor = ConsoleColor.Green;
  1518. Console.WriteLine("Conferência criada com sucesso.");
  1519. Console.ForegroundColor = ConsoleColor.White;
  1520. MenuOrganizador(a, b, c, d, e, f, ref fa);
  1521. }
  1522.  
  1523. //////////////////////////////////////////////////////////////////////////////NÃO HÁ DATAS REPETIDAS/////////////////////////////////////////////////////////////////////////////////////////////////////
  1524. if (contare < 1)
  1525. {
  1526. s.data.hora = hora1;
  1527. s.data.minutos = min1;
  1528. s.data.fimhora = hora2;
  1529. s.data.fimminutos = min2;
  1530. Console.WriteLine("Nome");
  1531. s.nome = Console.ReadLine();
  1532. for (int p = 0; p < d.Count; p++)
  1533. {
  1534. if (p == d.Count - 1)
  1535. {
  1536. s.idsessao = d[p].idsessao + 1;
  1537. }
  1538. }
  1539. s.local = "Teatro Gil Vicente";
  1540. d.Add(s);
  1541. Console.ForegroundColor = ConsoleColor.Green;
  1542. Console.WriteLine("Conferência criada com sucesso.");
  1543. Console.ForegroundColor = ConsoleColor.White;
  1544. MenuOrganizador(a, b, c, d, e, f, ref fa);
  1545. }
  1546. }
  1547.  
  1548. }
  1549. }
  1550. }
  1551.  
  1552.  
  1553. static void CriarEspectaculo(List<Login> a, List<Sala> b, List<Sessao> c, List<Conferencia> d, List<BilheteConferencia> e, List<BilheteSessao> f, ref int[] fa)
  1554. {
  1555. string pergunta;
  1556. int resposta;
  1557. int ano, mes, dia;
  1558. int contador = 0;
  1559.  
  1560. sar:
  1561.  
  1562. pergunta = ("Tipo de espectáculo (1 - Espéctaculo normal 2 - Conferencia 0 - Sair");
  1563. resposta = TestarInt(pergunta);
  1564.  
  1565. if (resposta == 1)
  1566. {
  1567. pergunta = ("Sessões a criar?");
  1568. int num = TestarInt(pergunta);
  1569. for (int i = 0; i < num; i++)
  1570. {
  1571. for (int o = 0; o < b.Count; o++)
  1572. {
  1573. if (b[o].tipo == 1)
  1574. VerSalas(b[o]);
  1575.  
  1576. }
  1577. Sessao s = new Sessao();
  1578. sui:
  1579. pergunta = ("\nSala a ocupar");
  1580. int num2 = TestarInt(pergunta);
  1581. // Ver se sala introduzida existe
  1582. for (int u = 0; u < b.Count; u++)
  1583. {
  1584. if (num2 != b[u].numsala)
  1585. {
  1586. contador++;
  1587. }
  1588.  
  1589. if (num2 != b[u].numsala && contador == b.Count)
  1590. {
  1591. contador = 0;
  1592. Console.ForegroundColor = ConsoleColor.Red;
  1593. Console.WriteLine("Sala não existe.");
  1594. Console.ForegroundColor = ConsoleColor.White;
  1595. goto sui;
  1596. }
  1597. if (num2 == b[u].numsala)
  1598. {
  1599. if (b[u].tipo == 1)
  1600. {
  1601. s.sala.numsala = num2;
  1602. s.sala.capacidade = b[u].capacidade;
  1603. }
  1604. else
  1605. {
  1606. contador = 0;
  1607. Console.ForegroundColor = ConsoleColor.Red;
  1608. Console.WriteLine("Sala escolhida não serve.");
  1609. Console.ForegroundColor = ConsoleColor.White;
  1610. goto sui;
  1611. }
  1612. lol:
  1613. Console.WriteLine("Dia do Espectáculo? (dd-mm-AAAA ou dd/mm/AAAA)");
  1614. string[] dataa = Console.ReadLine().Split('-', '/');
  1615. ano = Convert.ToInt32(dataa[2]);
  1616. if (ano < 2016)
  1617. {
  1618. Console.Write("Só pode marcar espectáculos no ano de 2016 ou mais\n");
  1619. goto lol;
  1620. }
  1621. mes = Convert.ToInt32(dataa[1]);
  1622. if (mes > 12 || mes < 1)
  1623. {
  1624. Console.WriteLine("Só existem 12 meses");
  1625. goto lol;
  1626. }
  1627.  
  1628. dia = Convert.ToInt32(dataa[0]);
  1629.  
  1630. if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12)
  1631. {
  1632. if (dia > 31 || dia < 1)
  1633. {
  1634. Console.ForegroundColor = ConsoleColor.Red;
  1635. Console.WriteLine("O mês escolhido tem apenas 31 dias.");
  1636. Console.ForegroundColor = ConsoleColor.White;
  1637. goto lol;
  1638. }
  1639. }
  1640. if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
  1641. {
  1642. if (dia > 30 || dia < 1)
  1643. {
  1644. Console.ForegroundColor = ConsoleColor.Red;
  1645. Console.WriteLine("O mês escolhido tem apenas 30 dias.");
  1646. Console.ForegroundColor = ConsoleColor.White;
  1647. goto lol;
  1648. }
  1649. }
  1650. if (mes == 2)
  1651. {
  1652. if (dia > 28 || dia < 1)
  1653. {
  1654. Console.ForegroundColor = ConsoleColor.Red;
  1655. Console.WriteLine("O mês escolhido tem apenas 2 dias.");
  1656. Console.ForegroundColor = ConsoleColor.White;
  1657. goto lol;
  1658. }
  1659. }
  1660.  
  1661. s.data.dia = dia;
  1662. s.data.mes = mes;
  1663. s.data.ano = ano;
  1664.  
  1665. tui:
  1666. int ok = 0;
  1667. int contar = 0;
  1668. int contare = 0;
  1669. int o;
  1670. int tipo = 0;
  1671.  
  1672.  
  1673.  
  1674. Console.WriteLine("Hora de começo? (hh:mm)");
  1675. string[] horaa = Console.ReadLine().Split(':');
  1676. int hora1 = Convert.ToInt32(horaa[0]);
  1677. int min1 = Convert.ToInt32(horaa[1]);
  1678. Console.WriteLine("Hora de finalização? (hh:mm)");
  1679. string[] horaa2 = Console.ReadLine().Split(':');
  1680. int hora2 = Convert.ToInt32(horaa2[0]);
  1681. int min2 = Convert.ToInt32(horaa2[1]);
  1682. if (min2 < 0 || min2 > 59 || min1 < 0 || min1 > 59)
  1683. {
  1684. Console.ForegroundColor = ConsoleColor.Red;
  1685. Console.WriteLine("Minutos mal introduzidos");
  1686. Console.ForegroundColor = ConsoleColor.White;
  1687. goto tui;
  1688. }
  1689. if (hora1 < 9 || hora2 < 9 || hora1 > 24 || hora2 > 24)
  1690. {
  1691. Console.ForegroundColor = ConsoleColor.Red;
  1692. Console.WriteLine("Os espéctaculos só podem durar até às 24:00 e começar às 9:00");
  1693. Console.ForegroundColor = ConsoleColor.White;
  1694. goto tui;
  1695. }
  1696. if (hora1 == 24 || hora2 == 24)
  1697. {
  1698. if (min1 > 0 || min2 > 0)
  1699. {
  1700. Console.ForegroundColor = ConsoleColor.Red;
  1701. Console.WriteLine("O establecimento fecha às 24.00");
  1702. Console.ForegroundColor = ConsoleColor.White;
  1703. goto tui;
  1704. }
  1705. }
  1706. if (hora1 + 1 > hora2)
  1707. {
  1708. Console.ForegroundColor = ConsoleColor.Red;
  1709. Console.WriteLine("Os espectáculos têm que durar pelo menos uma hora");
  1710. Console.ForegroundColor = ConsoleColor.White;
  1711. goto tui;
  1712. }
  1713. if (hora1 > hora2)
  1714. {
  1715. Console.ForegroundColor = ConsoleColor.Red;
  1716. Console.WriteLine("A hora de início tem que ser menor que a hora final");
  1717. Console.ForegroundColor = ConsoleColor.White;
  1718. goto tui;
  1719. }
  1720.  
  1721. //show de uma hora
  1722. if (hora1 + 1 == hora2)
  1723. {
  1724. if (min1 > min2)
  1725. {
  1726. Console.ForegroundColor = ConsoleColor.Red;
  1727. Console.WriteLine("Os espectáculos têm de durar pelo menos uma hora");
  1728. Console.ForegroundColor = ConsoleColor.White;
  1729. goto tui;
  1730. }
  1731. if (min1 <= min2)
  1732. {
  1733. tipo = 1;
  1734. }
  1735. }
  1736.  
  1737. if (fa.Length >= 1)
  1738. {
  1739. Array.Clear(fa, 0, fa.Length);
  1740. }
  1741.  
  1742. for (o = 0; o < c.Count; o++)
  1743. {
  1744. if (c[o].data.mes != s.data.mes && s.data.ano != c[o].data.ano && c[o].data.dia != s.data.dia)
  1745. {
  1746. contar++;
  1747. }
  1748.  
  1749. if (mes == c[o].data.mes && dia == c[o].data.dia && ano == c[o].data.ano && c[o].sala.numsala == s.sala.numsala)
  1750. {
  1751. Array.Resize(ref fa, fa.Length + 1);
  1752. fa[contare] = c[o].idsessao;
  1753. contare++;
  1754. }
  1755. }
  1756. if (contare >= 1)
  1757. {
  1758. VerificarHoras(ref fa, contare, hora1, hora2, min1, min2, tipo, c, ref ok);
  1759.  
  1760.  
  1761. if (ok == 1)
  1762. {
  1763. s.data.hora = hora1;
  1764. s.data.minutos = min1;
  1765. s.data.fimhora = hora2;
  1766. s.data.fimminutos = min2;
  1767. }
  1768. if (ok != 1)
  1769. {
  1770. Console.ForegroundColor = ConsoleColor.Red;
  1771. Console.WriteLine("Hora indisponível.");
  1772. Console.ForegroundColor = ConsoleColor.White;
  1773. goto tui;
  1774. }
  1775.  
  1776. Console.WriteLine("Nome");
  1777. s.nome = Console.ReadLine();
  1778. for (int p = 0; p < c.Count; p++)
  1779. {
  1780. if (p == c.Count - 1)
  1781. {
  1782. s.idsessao = c[p].idsessao + 1;
  1783. }
  1784. }
  1785. s.local = "Teatro Gil Vicente";
  1786. c.Add(s);
  1787. Console.ForegroundColor = ConsoleColor.Green;
  1788. Console.WriteLine("Espectáculo criado com sucesso.");
  1789. Console.ForegroundColor = ConsoleColor.White;
  1790. MenuOrganizador(a, b, c, d, e, f, ref fa);
  1791. }
  1792.  
  1793. //////////////////////////////////////////////////////////////////////////////NÃO HÁ DATAS REPETIDAS/////////////////////////////////////////////////////////////////////////////////////////////////////
  1794. if (contare < 1)
  1795. {
  1796. s.data.hora = hora1;
  1797. s.data.minutos = min1;
  1798. s.data.fimhora = hora2;
  1799. s.data.fimminutos = min2;
  1800. Console.WriteLine("Nome");
  1801. s.nome = Console.ReadLine();
  1802. for (int p = 0; p < c.Count; p++)
  1803. {
  1804. if (p == c.Count - 1)
  1805. {
  1806. s.idsessao = c[p].idsessao + 1;
  1807. }
  1808. }
  1809. s.local = "Teatro Gil Vicente";
  1810. c.Add(s);
  1811. Console.ForegroundColor = ConsoleColor.Green;
  1812. Console.WriteLine("Espectáculo criado com sucesso.");
  1813. Console.ForegroundColor = ConsoleColor.White;
  1814. MenuOrganizador(a, b, c, d, e, f, ref fa);
  1815. }
  1816. }
  1817.  
  1818. }
  1819. }
  1820. }
  1821.  
  1822.  
  1823. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1824. //Criar Conferencia
  1825. if (resposta == 2)
  1826. {
  1827. CriarConferencia(a, b, c, d, e, f, ref fa);
  1828. }
  1829.  
  1830.  
  1831.  
  1832.  
  1833. else
  1834. {
  1835. Console.ForegroundColor = ConsoleColor.Red;
  1836. Console.WriteLine("Opção escolhida não é válida");
  1837. Console.ForegroundColor = ConsoleColor.White;
  1838. goto sar;
  1839. }
  1840.  
  1841.  
  1842. }
  1843.  
  1844.  
  1845.  
  1846. static void Main(string[] args)
  1847. {
  1848. int[] fa = new int[0] { };
  1849.  
  1850. List<Login> a = new List<Login>();
  1851. List<Sala> b = new List<Sala>();
  1852. List<Sessao> c = new List<Sessao>();
  1853. List<Conferencia> d = new List<Conferencia>();
  1854. List<BilheteConferencia> e = new List<BilheteConferencia>();
  1855. List<BilheteSessao> f = new List<BilheteSessao>();
  1856. CarregarClientes(a);
  1857. CarregarOrganizadores(a);
  1858. CarregarAutor(a);
  1859. CarregarAdmin(a);
  1860. CarregarSalas(b);
  1861. CarregarSessao(c);
  1862. CarregarConferencias(d);
  1863. Log(a, b, c, d, ref fa, e, f);
  1864.  
  1865.  
  1866. }
  1867. }
  1868. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement