Esempio n. 1
0
        public EditZoneForm(PolyZone zone)
        {
            InitializeComponent();
            _zone = zone;

            Client.Instance.OnCityListAck += OnCityListAck;
        }
Esempio n. 2
0
        /// <summary>
        /// Load polygon data from the database
        /// </summary>
        /// <returns>Data transfer object that holds the data</returns>
        public void LoadZones(Func <PolyZone, bool> callback, int limit)
        {
            const string strCmd = "SELECT * FROM zones INNER JOIN cities ON cities.id = zones.cityid LIMIT @lim";

            using (var connection = GetConnection())
            {
                using (var cmd = new MySqlCommand(strCmd)
                {
                    Connection = connection
                })
                {
                    cmd.Parameters.AddWithValue("@lim", limit);
                    using (var geometryConnection = GetConnection())
                    {
                        var rd = cmd.ExecuteReader();
                        while (rd.Read())
                        {
                            var zone = new PolyZone()
                            {
                                Geometry    = new List <Geometry>(),
                                Id          = rd["id"].ToString(),
                                Color       = rd["color"].ToString(),
                                Description = rd["description"].ToString(),
                                ServiceNa   = rd["service_na"].ToString(),
                                Timetable   = rd["timetable"].ToString(),
                                Fee         = long.Parse(rd["fee"].ToString()),
                                Zoneid      = rd["common_name"].ToString(),
                                Telepules   = rd["city"].ToString()
                            };

                            using (var cmd1 = new MySqlCommand($"SELECT * FROM geometry WHERE zoneid = {rd["id"]} ORDER BY polyindex")
                            {
                                Connection = geometryConnection
                            })
                            {
                                var rd1 = cmd1.ExecuteReader();
                                while (rd1.Read())
                                {
                                    zone.Geometry.Add(new Geometry((int)rd1["id"])
                                    {
                                        Lat = (double)rd1["lat"], Lng = (double)rd1["lng"], IsModified = false
                                    });
                                }
                                rd1.Close();
                            }

                            callback(zone);
                        }
                        geometryConnection.Close();
                        rd.Close();
                    }
                }
            }
        }
Esempio n. 3
0
        public void BoardLink1()
        {
            Logger.Open(1);
            var input = new StringReader(
                @"(include ""testincl.poly"")" +
                @"(game (gamestub1)" +
                @"(board (boardlink1)) )");
            var game = PolyGame.CreateInner("bt2", input);

            Assert.AreEqual(1, game.Menu.Count());
            Assert.AreEqual("stub1", game.Title);
            Assert.AreEqual("board1.png", game.BoardImages[0]);

            var positions = new PolyPosition[] {
                new PolyPosition {
                    Name = "a1", Location = Rect.Create(11, 12, 13, 14), IsDummy = false,
                },
                new PolyPosition {
                    Name = "a2", Location = Rect.Create(21, 22, 23, 24), IsDummy = false,
                },
                new PolyPosition {
                    Name = "b1", Location = Rect.Create(31, 32, 33, 34), IsDummy = false,
                },
                new PolyPosition {
                    Name = "b2", Location = Rect.Create(41, 42, 43, 44), IsDummy = false,
                },
            };

            CollectionAssert.AreEquivalent(positions, game.Positions.ToArray());

            var links = new PolyLink[] {
                new PolyLink {
                    Direction = "n", From = "a2", To = "a1"
                },
                new PolyLink {
                    Direction = "e", From = "a1", To = "b1"
                },
            };

            CollectionAssert.AreEquivalent(links, game.Links.ToArray());

            var zones = new PolyZone[] {
                new PolyZone {
                    Name = "zone1", Player = "X", Positions = "a1 a2"
                },
            };

            CollectionAssert.AreEquivalent(zones, game.Zones.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        ///  Update a zone in the database
        /// </summary>
        /// <param name="zone"></param>
        public async void UpdateZoneInfo(PolyZone zone)
        {
            using (var connection = GetConnection())
            {
                using (var cmd = new MySqlCommand(
                           @"UPDATE zones SET cityid = @cityid, color = @color, fee = @fee, timetable = @timetable, common_name = @common_name, service_na = @service_na WHERE id = @id")
                {
                    Connection = connection
                })
                {
                    cmd.Parameters.AddRange(new[]
                    {
                        new MySqlParameter("@cityid", MySqlDbType.String),
                        new MySqlParameter("@color", MySqlDbType.String),
                        new MySqlParameter("@fee", MySqlDbType.String),
                        new MySqlParameter("@service_na", MySqlDbType.String),
                        new MySqlParameter("@description", MySqlDbType.String),
                        new MySqlParameter("@timetable", MySqlDbType.String),
                        new MySqlParameter("@common_name", MySqlDbType.String),
                        new MySqlParameter("@id", MySqlDbType.String)
                    });


                    var city = City.FromString(zone.Telepules);
                    cmd.Parameters[0].Value = !IsDuplicateCity(city) ? InsertCity(city) : GetCityId(city);

                    cmd.Parameters[1].Value = zone.Color;
                    cmd.Parameters[2].Value = zone.Fee;
                    cmd.Parameters[3].Value = zone.ServiceNa;
                    cmd.Parameters[4].Value = zone.Description;
                    cmd.Parameters[5].Value = zone.Timetable;
                    cmd.Parameters[6].Value = zone.Zoneid;
                    cmd.Parameters[7].Value = zone.Id;

                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Insert a zone into the database
        /// </summary>
        /// <param name="zone">The zone to be inserted</param>
        /// <param name="geometryCallback">Used to return new point Ids</param>
        public async Task <int> InsertZone(PolyZone zone, Func <int, bool> geometryCallback)
        {
            using (var connection = GetConnection())
            {
                using (var cmd = new MySqlCommand(
                           "INSERT INTO zones (cityid, color, fee, service_na, description, timetable, common_name) VALUES" +
                           "(@cityid, @color, @fee, @service_na, @description, @timetable, @common_name)")
                {
                    Connection = connection
                })
                {
                    cmd.Parameters.AddRange(new[]
                    {
                        new MySqlParameter("@cityid", MySqlDbType.String), new MySqlParameter("@color", MySqlDbType.String),
                        new MySqlParameter("@fee", MySqlDbType.String), new MySqlParameter("@service_na", MySqlDbType.String),
                        new MySqlParameter("@description", MySqlDbType.String), new MySqlParameter("@timetable", MySqlDbType.String),
                        new MySqlParameter("@common_name", MySqlDbType.String)
                    });

                    var city = City.FromString(zone.Telepules);
                    cmd.Parameters[0].Value = !IsDuplicateCity(city) ? InsertCity(city) : GetCityId(city);
                    cmd.Parameters[1].Value = zone.Color;
                    cmd.Parameters[2].Value = zone.Fee;
                    cmd.Parameters[3].Value = zone.ServiceNa;
                    cmd.Parameters[4].Value = zone.Description;
                    cmd.Parameters[5].Value = zone.Timetable;
                    cmd.Parameters[6].Value = zone.Zoneid;

                    await cmd.ExecuteNonQueryAsync();

                    var zoneId = cmd.LastInsertedId;

                    var polyIndex = 0;
                    var lastId    = 0L;
                    foreach (var geometry in zone.Geometry)
                    {
                        if (lastId != zoneId)
                        {
                            polyIndex = 0;
                            lastId    = zoneId;
                        }

                        using (var connection1 = GetConnection())
                        {
                            using (var cmd1 =
                                       new MySqlCommand(
                                           "INSERT INTO geometry (zoneid, lat, lng, polyindex) VALUES (@zoneid, @lat, @lng, @polyIndex)")
                            {
                                Connection = connection1
                            })
                            {
                                cmd1.Parameters.AddRange(new[]
                                {
                                    new MySqlParameter("@zoneid", MySqlDbType.String),
                                    new MySqlParameter("@lat", MySqlDbType.Double),
                                    new MySqlParameter("@lng", MySqlDbType.Double),
                                    new MySqlParameter("@polyIndex", polyIndex)
                                });

                                cmd1.Parameters[0].Value = zoneId;
                                cmd1.Parameters[1].Value = geometry.Lat;
                                cmd1.Parameters[2].Value = geometry.Lng;
                                await cmd1.ExecuteNonQueryAsync();

                                var id = (int)cmd1.LastInsertedId;
                                // Send back the inserted points' IDs
                                geometryCallback(id);
                                geometry.Id = id;

                                cmd1.Connection.Close();
                            }
                        }
                        polyIndex++;
                    }

                    zone.Id = zoneId.ToString();
                    return((int)zoneId);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets called when a new polygon has been drawn or discarded
        /// Aka. Draw mode end
        /// <param name="save">Indicates whether to save or discard the current drawing polygon</param>
        /// </summary>
        private void EndDrawPolygonAsync(bool save)
        {
            IsDrawingPolygon = false;

            if (save && _currentDrawingPolygon.LocalPoints.Count - 1 > 1 && _currentDrawingPolygon.GetArea(true) > 0d)
            {
                // Remove "ghost" point marker
                _currentDrawingPolygon.Points.Remove(_currentNewRectMaker.Position);
                UpdatePolygonLocalPosition(_currentDrawingPolygon);

                var newZone = new PolyZone
                {
                    Geometry    = new List <Geometry>(),
                    Id          = "",
                    Zoneid      = "",
                    ServiceNa   = "Service provider",
                    Description = "New zone",
                    Timetable   = "",
                    Color       = ColorTranslator.ToHtml((_currentDrawingPolygon.Fill as SolidBrush)?.Color ?? Color.Black)
                };

                var editZoneForm = new EditZoneForm(newZone);
                if (editZoneForm.ShowDialog() == DialogResult.OK)
                {
                    newZone = editZoneForm.GetZone();
                    newZone.Geometry.AddRange(
                        _currentDrawingPolygon.Points.Select(x => x.ToGeometry(0))
                        );

                    var zoneSeriliazed = JsonConvert.SerializeObject(newZone, Converter.Settings);
                    Client.Instance.Send(new InsertZoneReq()
                    {
                        Zone = zoneSeriliazed
                    });
                    StartWaiting();

                    Client.Instance.OnZoneInsertAck += (ack) => {
                        newZone.Id = ack.ZoneId.ToString();

                        // Set newly inserted zone's point ids
                        for (var i = 0; i < newZone.Geometry.Count; i++)
                        {
                            newZone.Geometry[i].Id = ack.PointIds[i];
                        }

                        StopWaiting();
                    };

                    _currentDrawingPolygon.Tag = newZone;
                    _dtoObject.Zones.Add(newZone);
                }
                else
                {
                    _polygons.Polygons.Remove(_currentDrawingPolygon);
                }

                Map_OnPolygonClick(_polygons.Polygons.FirstOrDefault(polygon => polygon == _currentDrawingPolygon), null);
            }
            else
            {
                _polygons.Polygons.Remove(_currentDrawingPolygon);
            }

            OnDrawPolygonEnd?.Invoke(_currentDrawingPolygon);

            _currentDrawingPolygon = null;

            _topLayer.Markers.Remove(_currentNewRectMaker);
            _currentNewRectMaker = null;

            UpdateVerticlesCount();
        }