private void btnLogin_Click(object sender, RoutedEventArgs e) { try { using (DataBaseConnection db = new DataBaseConnection(this.ConnectionString)) { using (IDataReader reader = db.ExecuteSqlCommand("select decode(count(uname),0,'false','true'), passwd_hash from spieler where uname = '" + txtUser.Text + "' group by passwd_hash")) { reader.Read(); if (((String)reader[0]).Equals("false")) { throw new Exception("Login falsch: Name existiert nicht!"); } else { String pw_hashed = ((String)reader["passwd_hash"]); if (!pw_hashed.Equals(MD5hash.GetHashString(txtPassowrd.Password))) { throw new Exception("Login falsch: Passwort falsch!"); } MainWindow mw = new MainWindow(txtUser.Text); mw.Show(); this.Close(); } } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private List<Dorf> getDoerferNames() { List<Dorf> doerfer = new List<Dorf>(); using (DataBaseConnection db = new DataBaseConnection(this.ConnectionString)) { using (IDataReader readerDorf = db.ExecuteSqlCommand("select name from dorf where owner = '" + spieler.name + "'")) { while (readerDorf.Read()) { doerfer.Add(new Dorf((String)readerDorf["name"])); } } } return doerfer; }
private Rohstoffe getDorfRes(String _dname) { Rohstoffe rohstoffe; using (DataBaseConnection db = new DataBaseConnection(this.ConnectionString)) { System.Diagnostics.Debug.WriteLine("select r.holz, r.stein, r.lehm from resgruppe r inner join movable m on m.id = r.id inner join dorf d on d.id = m.did where d.name='" + _dname +"'"); using (IDataReader reader = db.ExecuteSqlCommand("select r.holz, r.stein, r.lehm from resgruppe r inner join movable m on m.id = r.id inner join dorf d on d.id = m.did where d.name='" + _dname + "'")) { reader.Read(); rohstoffe = new Rohstoffe(Int16.Parse(reader["holz"].ToString()), Int16.Parse(reader["stein"].ToString()), Int16.Parse(reader["lehm"].ToString())); } } return rohstoffe; }
private List<Gebaeude> getDorfGebaeude(String _dname) { List<Gebaeude> gebaeude = new List<Gebaeude>(); using (DataBaseConnection db = new DataBaseConnection(this.ConnectionString)) { using (IDataReader reader = db.ExecuteSqlCommand("select gt.name, b.lvl from dorf d inner join bau b on b.did=d.id inner join geb_typ gt on b.tid = gt.id where d.name='" + _dname +"'")) { while (reader.Read()) { gebaeude.Add(new Gebaeude((String)reader["name"], Int16.Parse(reader["lvl"].ToString()))); } } } return gebaeude; }
private Truppen getDorfTruppen(String _dname) { Truppen truppen; using (DataBaseConnection db = new DataBaseConnection(this.ConnectionString)) { using (IDataReader reader = db.ExecuteSqlCommand("select t.schwert, t.reiter, t.bogen, t.lanze from truppe t inner join movable m on m.id = t.id inner join dorf d on d.id = m.did inner join spieler s on s.uname = d.owner where s.uname = '" + spieler.name + "' and d.name='" + _dname + "'")) { reader.Read(); truppen = new Truppen(Int16.Parse(reader["schwert"].ToString()), Int16.Parse(reader["reiter"].ToString()), Int16.Parse(reader["bogen"].ToString()), Int16.Parse(reader["lanze"].ToString())); } } return truppen; }