public static Adres getAdres(int id) { DatabaseUtil database = new DatabaseUtil(Program.mysql_host, Program.mysql_user, Program.mysql_pass, Program.mysql_data); MySqlConnection con = database.connection; using var cmd = database.CommandExecutor("SELECT * FROM adres WHERE id = @id"); cmd.Parameters.AddWithValue("@id", id); con.Open(); using MySqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { int streetID = rdr.GetInt32("straatnaamID"); String number = rdr.GetString("huisnummer"); String appNumber = rdr.GetString("appnummer"); String busNumber = rdr.GetString("busnummer"); String numberLabel = rdr.GetString("huisnummerlabel"); int locationID = rdr.GetInt32("adreslocatieID"); Straatnaam straatnaam = Program.streets[streetID]; AdresLocatie location = Program.locations[locationID]; Adres adres = new Adres(id, straatnaam, appNumber, busNumber, number, number, straatnaam.Gemeente, 0, location.X, location.Y); return(adres); } return(null); }
public static void addLocation(DatabaseUtil util, AdresLocatie location) { MySqlConnection con = util.connection; using var cmd = util.CommandExecutor("SELECT * FROM adreslocatie WHERE id = @id"); cmd.Parameters.AddWithValue("@id", location.ID); con.Open(); using MySqlDataReader rdr = cmd.ExecuteReader(); if (!rdr.Read()) { con.Close(); using var cmd2 = util.CommandExecutor("INSERT INTO adreslocatie (id, x, y) VALUES (@id, @x, @y)"); cmd2.Parameters.AddWithValue("@id", location.ID); cmd2.Parameters.AddWithValue("@x", location.X); cmd2.Parameters.AddWithValue("@y", location.Y); con.Open(); cmd2.Prepare(); cmd2.ExecuteNonQuery(); con.Close(); } con.Close(); }
public Adres(int id, Straatnaam straat, string appartementnummer, string busnummer, string huisnummer, string huisnummerlabel, Gemeente gemeente, int postcode, double x, double y) { ID = id; Straat = straat; Appartementnummer = appartementnummer; Busnummer = busnummer; Huisnummer = huisnummer; Huisnummerlabel = huisnummerlabel; //Gemeente = gemeente; Postcode = postcode; Locatie = new AdresLocatie(x, y); }
public override bool Equals(object obj) { if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return(false); } AdresLocatie location = (AdresLocatie)obj; if (this.X == location.X && this.Y == location.Y) { return(true); } return(false); }
public void addLocation(double x, double y) { AdresLocatie location = new AdresLocatie(x, y); //foreach (AdresLocatie loc in Program.locations.Values) //{ // if(loc.Equals(location)) // { // this.Locatie = loc; // break; //} int key = 1; if (Program.locations.Count > 0) { key = Program.locations.Keys.Last() + 1; } location.ID = key; this.Locatie = location; Program.locations.Add(key, location); }