예제 #1
0
 public Segment(int segmentID, Knoop beginKnoop, Knoop eindknoop, List <Punt> vertices)
 {
     BeginKnoop = beginKnoop;
     EindKnoop  = eindknoop;
     SegmentID  = segmentID;
     Vertices   = vertices;
 }
예제 #2
0
        public Segment GeefSegment(int segmentId)
        {
            SqlConnection connection = GetConnection();
            string        query      = "SELECT * FROM segment WHERE id=@segmentId";

            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = query;
                command.Parameters.Add(new SqlParameter("@segmentId", SqlDbType.Int));
                command.Parameters["@segmentId"].Value = segmentId;
                connection.Open();
                try
                {
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    int beginKnoopId = (int)reader["beginknoopid"];
                    int eindKnoopId  = (int)reader["eindknoopid"];
                    reader.Close();

                    if (!_knopen.ContainsKey(beginKnoopId))
                    {
                        _knopen.Add(beginKnoopId, GeefKnoop(beginKnoopId));
                    }
                    if (!_knopen.ContainsKey(eindKnoopId))
                    {
                        _knopen.Add(eindKnoopId, GeefKnoop(eindKnoopId));
                    }

                    Knoop       beginKnoop = _knopen[beginKnoopId];
                    Knoop       eindKnoop  = _knopen[eindKnoopId];
                    List <Punt> vertice    = GeefVertice(segmentId, beginKnoop.Punt.Id, eindKnoop.Punt.Id);
                    vertice.Insert(0, beginKnoop.Punt);
                    vertice.Add(eindKnoop.Punt);

                    return(new Segment(segmentId, beginKnoop, eindKnoop, vertice));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(null);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
예제 #3
0
        public void AddKnoop(Knoop knoop)
        {
            SqlConnection connection = GetConnection();
            string        queryPunt  = "INSERT INTO punt(x, y) output INSERTED.ID VALUES(@x, @y)";
            string        queryKnoop = "INSERT INTO knoop(puntid) output INSERTED.ID VALUES(@puntid)";

            using (SqlCommand command1 = connection.CreateCommand())
                using (SqlCommand command2 = connection.CreateCommand())
                {
                    connection.Open();
                    SqlTransaction transaction = connection.BeginTransaction();
                    command1.Transaction = transaction;
                    command2.Transaction = transaction;
                    try
                    {
                        // punt toevoegen
                        command1.Parameters.Add(new SqlParameter("@x", SqlDbType.Float));
                        command1.Parameters.Add(new SqlParameter("@y", SqlDbType.Float));
                        command1.CommandText            = queryPunt;
                        command1.Parameters["@x"].Value = knoop.Punt.X;
                        command1.Parameters["@y"].Value = knoop.Punt.Y;
                        int puntId = (int)command1.ExecuteScalar();

                        // knoop toevoegen
                        command2.Parameters.Add(new SqlParameter("@puntid", SqlDbType.Int));
                        command2.CommandText = queryKnoop;
                        command2.Parameters["@puntid"].Value = puntId;
                        int knoopId = (int)command2.ExecuteScalar();

                        transaction.Commit();
                        _knopen.Add(knoop.KnoopId, new Knoop(knoopId, new Punt(puntId, knoop.Punt.X, knoop.Punt.Y)));
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Console.WriteLine(ex);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
        }