Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 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.Data.SqlClient;
  7.  
  8. namespace TCPserver
  9. {
  10.     class UpitZaBazu
  11.     {
  12.         private string identitetPoruke;
  13.         private string poruka;
  14.         private string[] elementiPoruke;
  15.         private string upit;
  16.         SqlDataReader reader;
  17.        
  18.  
  19.         public UpitZaBazu(string item, string poruka)
  20.         {
  21.             identitetPoruke = item;
  22.             this.poruka = poruka;
  23.         }
  24.  
  25.         public List<string> dohvatiElementeIzPoruke()
  26.  
  27.         {
  28.             List<string> result = new List<string>();
  29.             if (identitetPoruke == "LOGIN")
  30.             {
  31.                 result = StvoriLoginUpit();
  32.                 return result;
  33.             }
  34.  
  35.             if (identitetPoruke == "REGISTER")
  36.             {
  37.                 result = StvoriRegisterUpit();
  38.                 return result;
  39.             }
  40.             return result;
  41.         }
  42.  
  43.         private List<string> StvoriLoginUpit()
  44.         {
  45.             List<string> podaciKorisnik = new List<string>();
  46.             elementiPoruke = poruka.Split(',');
  47.             upit = "Select * from Korisnici where username = '" + elementiPoruke[1] + "' and password = '" + elementiPoruke[2] + "'";
  48.             Baza.OtvaranjeKonekcijeSBazom();
  49.             reader = Baza.IzvrsavanjeUpita(upit);
  50.             if (reader.HasRows)
  51.             {
  52.                 while (reader.Read())
  53.                 {
  54.                     Console.WriteLine("Podaci o uspjesnoj prijavi: ");
  55.                     Console.WriteLine("{0}\t{1}", reader.GetString(0),
  56.                         reader.GetString(1));
  57.                     for (int i = 0; i < reader.FieldCount; i++)
  58.                     {
  59.                         podaciKorisnik.Add(reader[i].ToString());
  60.                     }
  61.                 }
  62.             }
  63.             else
  64.             {
  65.                 Console.WriteLine("Neuspjesna prijava");
  66.             }
  67.  
  68.             return podaciKorisnik;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement