Ejemplo n.º 1
0
 public void addPolygonToDB(Polygon polygon) {
     String query = "INSERT INTO polygons(polygon_guid, polygon_name)"
                 + " VALUES (:polygon_guid, :polygon_name)";
     NpgsqlCommand command = new NpgsqlCommand(query, connection);
     command.Parameters.Add(new NpgsqlParameter("polygon_guid", polygon.guid));
     command.Parameters.Add(new NpgsqlParameter("polygon_name", polygon.name));
     command.ExecuteNonQuery();
 }
Ejemplo n.º 2
0
 public void addPolygonPoints(Polygon polygon, List<PolygonPoint> points) {
     foreach (PolygonPoint point in points)
     {
         String query = "INSERT INTO polygon_points(polygon_guid, point_num, pointx, pointy)"
     + " VALUES (:polygon_guid, :point_num, :pointx, :pointy)";
         NpgsqlCommand command = new NpgsqlCommand(query, connection);
         command.Parameters.Add(new NpgsqlParameter("polygon_guid", polygon.guid));
         command.Parameters.Add(new NpgsqlParameter("point_num", point.pointNum));
         command.Parameters.Add(new NpgsqlParameter("pointx", point.x));
         command.Parameters.Add(new NpgsqlParameter("pointy", point.y));
         command.ExecuteNonQuery();
     }
 }
Ejemplo n.º 3
0
        public Polygon getPolygonByName(String name)
        {
            NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM polygons WHERE polygon_name=:name", connection);
            command.Parameters.Add(new NpgsqlParameter("name", name));

            NpgsqlDataReader reader = command.ExecuteReader();

            if (!reader.Read())
            {
                reader.Close();
                return null;
            }

            Polygon polygon = new Polygon((String)reader[0], (String)reader[1]);
            reader.Close();
            return polygon;
        }
Ejemplo n.º 4
0
        static void addMalamPolygon(String connectionParams)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionParams);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();

            try
            {
                Polygon polygon = new Polygon(Guid.NewGuid().ToString(), "Malam");
                List<PolygonPoint> points = new List<PolygonPoint>();
                points.Add(new PolygonPoint(polygon.guid, 0, 34.850942194461823, 32.098860770959512));
                points.Add(new PolygonPoint(polygon.guid, 1, 34.85137939453125, 32.098815327220322));
                points.Add(new PolygonPoint(polygon.guid, 2, 34.851290881633759, 32.098213195541732));
                points.Add(new PolygonPoint(polygon.guid, 3, 34.850845634937286, 32.098260911781828));
                points.Add(new PolygonPoint(polygon.guid, 4, 34.85086977481842, 32.098408604747945));
                points.Add(new PolygonPoint(polygon.guid, 5, 34.851129949092865, 32.098381338372178));
                points.Add(new PolygonPoint(polygon.guid, 6, 34.8511728644371, 32.098667634911841));
                points.Add(new PolygonPoint(polygon.guid, 7, 34.850918054580688, 32.098697173392637));


                PolygonDB db = new PolygonDB(connection);

                db.addPolygonToDB(polygon);
                db.addPolygonPoints(polygon, points);

                int[] edgesToAdd = new int[] { 1 };

                foreach (int i in edgesToAdd)
                {
                    double openingX = (points[i].x + points[(i + 1) % points.Count()].x) / 2;
                    double openingY = (points[i].y + points[(i + 1) % points.Count()].y) / 2;
                    PolygonOpening opening = new PolygonOpening(polygon.guid, i, openingX, openingY, 3);
                    db.addPolygonOpeningToPolygon(opening);
                }

                transaction.Commit();
            }
            catch (Exception exception)
            {
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollbackException)
                {
                    Console.WriteLine("Rollback failed :(");
                }
            }

            connection.Close();
        }