Advertisement
gtdany7

Untitled

May 30th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1.       public void comunicate()
  2.         {
  3.             lerFicheiro();
  4.             int count = 0; // para contar o numero de votos recebidos!!!!
  5.             byte[] user = new byte[1024];
  6.             int k = socket.Receive(user);
  7.             response = Encoding.ASCII.GetString(user, 0, k);
  8.  
  9.             Console.WriteLine("Numero do eleitor: ->" + response); // NAO Γ‰ PRECISO MOSTRAR PORQUE È UMA VOTAΓ‡AO ANONIMA!!!
  10.  
  11.             byte[] data = new byte[1024];
  12.             int j = socket.Receive(data);
  13.             Console.Write("-> ");
  14.             s = Encoding.ASCII.GetString(data, 0, j); // AQUI RECEBE O VOTO DO UTILIZADOR
  15.             Console.WriteLine(s);
  16.             canVote(s);
  17.  
  18.  
  19.         }
  20.      
  21.  
  22.  
  23.  
  24.   public string canVote(string s)
  25.         {
  26.             string aux = "";
  27.  
  28.             string[] lines = System.IO.File.ReadAllLines(@"C:\Users\DC\Documents\HighSchool\arc\eleitores.txt");
  29.  
  30.             foreach (string line in lines)
  31.             {
  32.                 if (s == line.Split(';')[0])
  33.                 {
  34.                     if (line.Split(';')[2] == "0")
  35.                     {
  36.                         aux = "0";
  37.                         byte[] user = Encoding.ASCII.GetBytes(s); // transforma a msg em codigo e envia-o
  38.                         socket.Send(user);
  39.                     }
  40.                     else if (line.Split(';')[2] == "1")
  41.                     {
  42.                         aux = "1";
  43.                         byte[] user2 = Encoding.ASCII.GetBytes("Nao PODE VOTAR"); // transforma a msg em codigo e envia-o
  44.                         socket.Send(user2);
  45.                     }
  46.                 }
  47.             }
  48.             return aux;
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement