/* * Preuzima rekorde iz baze * br - broj rekorda, ili null za sve * d */ public List <Rekord> PreuzmiRekorde(int?br, ETipSortiranja tipSortiranja) { List <Rekord> rekordi = new List <Rekord> (); MySqlCommand cmd; MySqlDataReader reader; string query; switch (tipSortiranja) { case ETipSortiranja.NajboljiPoBrojuSlova: query = "SELECT * FROM rekordi ORDER BY broj_pogresnih_slova ASC"; break; case ETipSortiranja.NajboljiPoVremenu: query = "SELECT * FROM rekordi ORDER BY broj_sekundi ASC"; break; default: query = "SELECT * FROM rekordi ORDER BY broj_pogresnih_slova+broj_sekundi ASC"; break; } using (cmd = new MySqlCommand(query, conn)) { try { reader = cmd.ExecuteReader(); while (reader.Read() && (br != null ? br-- > 0 : true)) { int id = reader.GetInt32(0); int brojPogresnihSlova = reader.GetInt32(1); long vreme = reader.GetInt64(2); string ime = reader.GetString(3); rekordi.Add(new Rekord(id, brojPogresnihSlova, vreme, ime)); } } catch (Exception ex) { throw ex; } } return(rekordi); }
/* * Preuzima rekorde iz baze * br - broj rekorda, ili null za sve * d */ public List<Rekord> PreuzmiRekorde(int? br, ETipSortiranja tipSortiranja) { List <Rekord> rekordi = new List<Rekord> (); MySqlCommand cmd; MySqlDataReader reader; string query; switch (tipSortiranja) { case ETipSortiranja.NajboljiPoBrojuSlova: query = "SELECT * FROM rekordi ORDER BY broj_pogresnih_slova ASC"; break; case ETipSortiranja.NajboljiPoVremenu: query = "SELECT * FROM rekordi ORDER BY broj_sekundi ASC"; break; default: query = "SELECT * FROM rekordi ORDER BY broj_pogresnih_slova+broj_sekundi ASC"; break; } using (cmd = new MySqlCommand (query, conn)) { try { reader = cmd.ExecuteReader (); while (reader.Read () && (br != null ? br-- > 0 : true)) { int id = reader.GetInt32 (0); int brojPogresnihSlova = reader.GetInt32 (1); long vreme = reader.GetInt64 (2); string ime = reader.GetString (3); rekordi.Add (new Rekord(id, brojPogresnihSlova, vreme, ime)); } } catch (Exception ex) { throw ex; } } return rekordi; }
/* * Rekordi */ /** * Metoda vraca listu Rekordas \n * prima dva argumenta \n * br (int) - koji predstavlja broj * rekorda koje treba preuzeti, ako je null (default) * vraca sve rekorde \n * tipSortiranja (ETipSortiranja) - enumeracija * predstavlja tip sortiranja (default - NajboljiUkupno) */ public List<Rekord> PreuzmiRekorde (int? br = null, ETipSortiranja tipSortiranja = ETipSortiranja.NajboljiUkupno) { List<Rekord> rekordi; using (DataBase data = new DataBase ()) { try { data.Open (); rekordi = data.PreuzmiRekorde (br, tipSortiranja); } catch (Exception ex) { ServiceFault fault = new ServiceFault ("Greska prilikom preuzimanja rekorda!"); throw new FaultException<ServiceFault> (fault); } } return rekordi; }
/* * Rekordi */ public List <Rekord> PreuzmiRekorde(int?br = null, ETipSortiranja tipSortiranja = ETipSortiranja.NajboljiUkupno) { return(Channel.PreuzmiRekorde(br, tipSortiranja)); }