public void KhFegyverHozzaad(KozelharciF fegyver) { if (!_khfegyverek.Contains(fegyver)) { khfegyverek.Add(fegyver); } }
public List <KozelharciF> KhFegyverLekerdez() { FegyverRaktar fer = FegyverRaktar.getInstance(); List <string> khf = new List <string>(); List <int> seb = new List <int>(); string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" + "DBQ=" + Environment.CurrentDirectory + @"\Fajlok\DB\adatbazis.xlsx" + ";ReadOnly=0;"; string queryString = "SELECT * FROM [KozelharciF$]"; using (OdbcConnection connection = new OdbcConnection(connectionString)) { OdbcCommand command = new OdbcCommand(queryString, connection); try { connection.Open(); OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { khf.Add((string)reader[0]); seb.Add(int.Parse(reader[1].ToString())); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } for (int i = 0; i < khf.Count; i++) { KozelharciF ujf = new KozelharciF(); ujf.nev = khf[i]; ujf.sebzes = seb[i]; fer.KhFegyverHozzaad(ujf); } return(fer.khfegyverek); } }
public void KhFegyverLekerdezTest() { FegyverAdatbazis fegy = FegyverAdatbazis.getInstance(); List <KozelharciF> elvartfegyv = new List <KozelharciF>(); List <string> elvartkhfegyverek = new List <string>(); List <int> elvartsebzesek = new List <int>(); elvartkhfegyverek.Add("tőr"); elvartkhfegyverek.Add("kés"); elvartkhfegyverek.Add("szablya"); elvartkhfegyverek.Add("katana"); elvartkhfegyverek.Add("láncos buzogány"); elvartkhfegyverek.Add("tüskés buzogány"); elvartkhfegyverek.Add("csatabárd"); elvartkhfegyverek.Add("lándzsa"); elvartkhfegyverek.Add("rövid kard"); elvartkhfegyverek.Add("hosszú kard"); elvartsebzesek.Add(90); elvartsebzesek.Add(70); elvartsebzesek.Add(120); elvartsebzesek.Add(450); elvartsebzesek.Add(400); elvartsebzesek.Add(350); elvartsebzesek.Add(380); elvartsebzesek.Add(300); elvartsebzesek.Add(240); elvartsebzesek.Add(280); for (int i = 0; i < elvartkhfegyverek.Count; i++) { KozelharciF khf = new KozelharciF(); khf.nev = elvartkhfegyverek[i]; khf.sebzes = elvartsebzesek[i]; elvartfegyv.Add(khf); } List <KozelharciF> lekerdezettfv = new List <KozelharciF>(); List <string> lekerdezettkhf = new List <string>(); List <int> lekerdezettseb = new List <int>(); string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" + "DBQ=" + Environment.CurrentDirectory + @"\Fajlok\DB\adatbazis.xlsx" + ";ReadOnly=0;"; string queryString = "SELECT * FROM [KozelharciF$]"; using (OdbcConnection connection = new OdbcConnection(connectionString)) { OdbcCommand command = new OdbcCommand(queryString, connection); try { connection.Open(); OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { lekerdezettkhf.Add((string)reader[0]); lekerdezettseb.Add(int.Parse(reader[1].ToString())); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } for (int i = 0; i < lekerdezettkhf.Count; i++) { KozelharciF ujf = new KozelharciF(); ujf.nev = lekerdezettkhf[i]; ujf.sebzes = lekerdezettseb[i]; lekerdezettfv.Add(ujf); } Assert.AreEqual(elvartfegyv.Count, lekerdezettfv.Count); for (int i = 0; i < elvartfegyv.Count; i++) { Assert.AreEqual(elvartfegyv[i].nev, lekerdezettfv[i].nev); Assert.AreEqual(elvartfegyv[i].sebzes, lekerdezettfv[i].sebzes); } } }