public Punt AddPunt(Punt punt) { SqlConnection connection = GetConnection(); string query = "INSERT INTO punt(x, y) output INSERTED.ID VALUES(@x, @y)"; using (SqlCommand command = connection.CreateCommand()) { connection.Open(); try { command.Parameters.Add(new SqlParameter("@x", SqlDbType.Float)); command.Parameters.Add(new SqlParameter("@y", SqlDbType.Float)); command.CommandText = query; command.Parameters["@x"].Value = punt.X; command.Parameters["@y"].Value = punt.Y; int puntId = (int)command.ExecuteScalar(); return(new Punt(puntId, punt.X, punt.Y)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } finally { connection.Close(); } } }
private void MaakSegment(int segmentId, List <string> segment) { int beginKnoopId = int.Parse(Isoleer(segment[2])); if (!_knopen.ContainsKey(beginKnoopId)) { AddKnoop(new Knoop(beginKnoopId, MaakPunt(segment[6]))); } int eindKnoopId = int.Parse(Isoleer(segment[3])); if (!_knopen.ContainsKey(eindKnoopId)) { AddKnoop(new Knoop(eindKnoopId, MaakPunt(segment[segment.Count - 1]))); } List <Punt> vertices = new List <Punt>(); vertices.Add(_knopen[beginKnoopId].Punt); for (int i = 7; i < segment.Count - 1; i++) { Punt p = MaakPunt(segment[i]); Punt punt = AddPunt(p); vertices.Add(punt); } vertices.Add(_knopen[eindKnoopId].Punt); AddSegment(new Segment(segmentId, _knopen[beginKnoopId], _knopen[eindKnoopId], vertices)); }
private Punt MaakPunt(string value) { string[] punten = Isoleer(value).Split(" "); Punt punt = new Punt(double.Parse(punten[0]), double.Parse(punten[1])); return(punt); }
public Punt GeefPunt(int puntId) { SqlConnection connection = GetConnection(); string query = "SELECT x,y FROM punt WHERE id=@puntId"; using (SqlCommand command = connection.CreateCommand()) { command.CommandText = query; command.Parameters.Add(new SqlParameter("@puntId", SqlDbType.Int)); command.Parameters["@puntId"].Value = puntId; connection.Open(); try { SqlDataReader reader = command.ExecuteReader(); reader.Read(); Punt p = new Punt(puntId, (double)reader["x"], (double)reader["y"]); reader.Close(); return(p); } catch (Exception ex) { Console.WriteLine(ex); return(null); } finally { connection.Close(); } } }
public Knoop(int id, Punt punt) { this.KnoopId = id; this.Punt = punt; }