Esempio n. 1
0
 private void TheMap_OnRouteClick(GMapRoute item, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         wObject = _Dh.getObjectByRoute(item); ctxMnuObjects.Show(MousePosition);
     }
 }
Esempio n. 2
0
        //ALways load AFTER ObGroups!
        public static void loadObjects()
        {
            using (MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(_Dh.connectionString()))
            {
                try
                {
                    using (StreamWriter sw = new StreamWriter("errors.txt", true))
                    {
                        sw.WriteLine(DateTime.Now);
                        sw.WriteLine("============================================");
                        connection.Open();
                        MySql.Data.MySqlClient.MySqlDataReader reader;
                        var cmd = new MySqlCommand("SELECT * from `objects`", connection);
                        reader = cmd.ExecuteReader();

                        _Dh.myObjects = new List <xObject>();
                        while (reader.Read())
                        {
                            xObject x = new xObject();

                            x.Id = sfIntReader(reader, "Id");
                            sw.WriteLine("Id: " + x.Id);

                            x.Uid = sfIntReader(reader, "Uid");
                            sw.WriteLine("Uid: " + x.Uid);

                            x.ObGroupId = sfIntReader(reader, "obgroupid");
                            sw.WriteLine("obgroupid: " + x.ObGroupId);

                            x.Name = sfStringReader(reader, "name");
                            sw.WriteLine("name: " + x.Name);

                            x.Description = sfStringReader(reader, "description");
                            sw.WriteLine("description: " + x.Description);

                            x.C_Date = sfStringReader(reader, "c_date");
                            sw.WriteLine("c_date: " + x.C_Date);


                            String s = sfStringReader(reader, "coordinates");
                            sw.WriteLine("s: " + s);

                            x.Coordinates = crdsFromDBString(s);
                            sw.WriteLine("coordinates: .. ok");

                            _Dh.myObjects.Add(x);

                            sw.WriteLine("obj_added");
                            sw.WriteLine();
                        }

                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    err_processor(ex);
                }
            }
        }
Esempio n. 3
0
        private void TheMap_OnPolygonLeave(GMapPolygon item)
        {
            xObject x = _Dh.getObjectByPolygon(item);

            if (x != null)
            {
                x.Marker.IsVisible = false;
            }
        }
Esempio n. 4
0
        private void TheMap_OnRouteLeave(GMapRoute item)
        {
            xObject x = _Dh.getObjectByRoute(item);

            if (x != null)
            {
                x.Marker.IsVisible = false;
            }
        }
Esempio n. 5
0
        private void TheMap_OnRouteEnter(GMapRoute item)
        {
            xObject x = _Dh.getObjectByRoute(item);

            if (x != null)
            {
                x.Marker.IsVisible = true;
            }
        }
Esempio n. 6
0
        private void TheMap_OnPolygonEnter(GMapPolygon item)
        {
            xObject x = _Dh.getObjectByPolygon(item);

            if (x != null)
            {
                x.Marker.IsVisible = true;
            }
        }
Esempio n. 7
0
        private void editObject(xObject obj)
        {
            // Check if user has Edit permissions for this group of objects
            if (_Dh.getGroupAccessLevel(_Dh.getGroupById(obj.ObGroupId)).CompareTo(_Dh.AccessLevel.Edit) < 0)
            {
                _Dh.msgExclamation("У вас на достаточно привилегий");
                return;
            }

            // Show markers of polygons
            if (wObject.Polygon != null && _Dh.getGroupById(obj.ObGroupId).GroupType == ObjectType.POLYGON)
            {
                for (int i = 0; i < wObject.Polygon.Points.Count; i++)
                {
                    GMapMarker m = new GMarkerGoogle(wObject.Polygon.Points[i], GMarkerGoogleType.green_pushpin)
                    {
                        Tag = (i) + "", IsVisible = true, ToolTipMode = MarkerTooltipMode.Always
                    };
                    wObject.Polygon.Overlay.Markers.Add(m);

                    TheMap.UpdateMarkerLocalPosition(m);
                }

                TheMap.UpdatePolygonLocalPosition(wObject.Polygon);
            }

            // Show markers of route
            if (wObject.Route != null && _Dh.getGroupById(obj.ObGroupId).GroupType == ObjectType.ROUTE)
            {
                for (int i = 0; i < wObject.Route.Points.Count; i++)
                {
                    GMapMarker m = new GMarkerGoogle(wObject.Route.Points[i], GMarkerGoogleType.green_pushpin)
                    {
                        Tag = (i) + "", IsVisible = true, ToolTipMode = MarkerTooltipMode.Always
                    };
                    wObject.Route.Overlay.Markers.Add(m);

                    TheMap.UpdateMarkerLocalPosition(m);
                }

                TheMap.UpdateRouteLocalPosition(wObject.Route);
            }

            var fObjInfo = new FrmObjInfo(obj);

            fObjInfo.Show();
            if (_Dh.myAccount.IsModerator)
            {
                isEditMode = true;
            }

            //    RefreshUI();
        }
Esempio n. 8
0
        public static GMapOverlay getOverlay(GMapControl gmc, xObject x)
        {
            xObGroup obGr = getGroupById((int)x.ObGroupId);

            foreach (GMapOverlay overlay in gmc.Overlays)
            {
                if (overlay.Id == obGr.Name)
                {
                    return(overlay);
                }
            }
            return(null);
        }
Esempio n. 9
0
        public FrmObjInfo(xObject wo)
        {
            InitializeComponent();
            Program.SendMessage(txtObjName.Handle, Program.EM_SETCUEBANNER, 1, "Название Объекта");
            Program.SendMessage(txtObjDescription.Handle, Program.EM_SETCUEBANNER, 1, "Описание");

            // Save original object data to a new object
            this.preservedObj             = new xObject();
            this.preservedObj.Name        = new String(wo.Name.ToCharArray());
            this.preservedObj.Description = new String(wo.Description.ToCharArray());
            this.preservedObj.Coordinates = new List <PointLatLng>(wo.Coordinates);

            wObject = wo;
        }
Esempio n. 10
0
        private void trvObGroups_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (e.Action == TreeViewAction.ByMouse)
            {
                if (e.Node.Name.Contains("obgr"))
                {
                    xObGroup obGr = _Dh.getGroupById(Convert.ToInt64(e.Node.Name.Substring(5)));

                    if (e.Node.Checked)
                    {
                        foreach (TreeNode tn in e.Node.Nodes)
                        {
                            tn.Checked = true;
                        }
                        foreach (xObject x in _Dh.getObjectsByGroupId(obGr.Id))
                        {
                            drawObject(x);
                        }
                    }
                    else
                    {
                        foreach (TreeNode tn in e.Node.Nodes)
                        {
                            tn.Checked = false;
                        }
                        _Dh.getOverlay(TheMap, obGr).Clear();
                    }
                }
                else if (e.Node.Name.Contains("obj"))
                {
                    xObGroup obGr = _Dh.getGroupById(Convert.ToInt64(e.Node.Parent.Name.Substring(5)));
                    xObject  xObj = _Dh.getObjectById(Convert.ToInt64(e.Node.Name.Substring(4)));
                    if (e.Node.Checked)
                    {
                        drawObject(xObj);
                    }
                    else
                    {
                        removeObjFromMap(xObj);
                    }
                }
            }
        }
Esempio n. 11
0
        private void removeObjFromMap(xObject obj)
        {
            xObGroup    obGr = _Dh.getGroupById(obj.ObGroupId);
            GMapOverlay ov   = _Dh.getOverlay(TheMap, obGr);

            switch (obGr.GroupType)
            {
            case ObjectType.DOT:
                ov.Markers.Remove(obj.Marker);
                break;

            case ObjectType.ROUTE:
                obj.Route.Overlay.Markers.Remove(obj.Marker);
                ov.Routes.Remove(obj.Route);
                break;

            case ObjectType.POLYGON:
                obj.Polygon.Overlay.Markers.Remove(obj.Marker);
                ov.Polygons.Remove(obj.Polygon);
                break;
            }
        }
Esempio n. 12
0
        private void rmObject(xObject x, bool FromDB)
        {
            //Remove from map
            using (GMapMarker currentMarker = x.Marker)
            {
                int?mID = null;
                if (currentMarker != null)
                {
                    mID = Convert.ToInt32(currentMarker.Tag);
                    _Dh.getOverlay(TheMap, x).Markers.Remove(currentMarker);
                }
            }

            using (GMapRoute currentRoute = x.Route)
            {
                int?rID = null;
                if (currentRoute != null)
                {
                    rID = Convert.ToInt32(currentRoute.Tag);
                    _Dh.getOverlay(TheMap, x).Routes.Remove(currentRoute);
                }
            }

            using (GMapPolygon currentPolygons = x.Polygon)
            {
                int?rID = null;
                if (currentPolygons != null)
                {
                    rID = Convert.ToInt32(currentPolygons.Tag);
                    _Dh.getOverlay(TheMap, x).Polygons.Remove(currentPolygons);
                }
            }

            //Remove from collection
            _Dh.myObjects.Remove(x);
        }
Esempio n. 13
0
        private void drawObject(xObject x)
        {
            xObGroup    obGr = _Dh.getGroupById(x.ObGroupId);
            GMapOverlay ov   = _Dh.getOverlay(TheMap, obGr);


            switch (obGr.GroupType)
            {
            case ObjectType.DOT:
                GMarkerGoogle marker = null;
                PointLatLng   point  = x.Coordinates[0];

                if (obGr.Appendix.Length > 5)
                {
                    Bitmap bmp;
                    using (var ms = new MemoryStream(Convert.FromBase64String(obGr.Appendix)))
                    {
                        bmp = new Bitmap(ms);
                    }
                    marker = new GMarkerGoogle(point, bmp);
                }
                else
                {
                    marker = new GMarkerGoogle(point, GMarkerGoogleType.green);
                }


                MarkerTooltipMode mode = MarkerTooltipMode.Always;
                marker.ToolTip     = new GMapBaloonToolTip(marker);
                marker.ToolTipMode = mode;
                Brush ToolTipBackColor = new SolidBrush(Color.Transparent);
                marker.ToolTipText = x.Name;

                x.Marker = marker;
                ov.Markers.Add(x.Marker);
                TheMap.UpdateMarkerLocalPosition(x.Marker);
                break;

            case ObjectType.ROUTE:
                GMapRoute route = new GMapRoute(x.Coordinates, x.Name);

                route.Stroke = obGr.Pen;

                route.IsHitTestVisible = true;
                x.Marker = new GMarkerGoogle(route.Points[0], new Bitmap(1, 1))
                {
                    Tag = x.Name, IsVisible = false, ToolTipMode = MarkerTooltipMode.Always, ToolTipText = x.Name
                };

                x.Route = route;
                ov.Routes.Add(x.Route);
                x.Route.Overlay.Markers.Add(x.Marker);
                break;

            case ObjectType.POLYGON:
                var polygon = new GMapPolygon(x.Coordinates, x.Name);
                polygon.Fill             = new SolidBrush(Color.FromArgb(50, obGr.Pen.Color));
                polygon.Stroke           = obGr.Pen;
                polygon.IsHitTestVisible = true;


                x.Marker = new GMarkerGoogle(polygon.Points[0], new Bitmap(1, 1))
                {
                    Tag = x.Name, IsVisible = false, ToolTipMode = MarkerTooltipMode.Always, ToolTipText = x.Name
                };


                x.Polygon = polygon;
                ov.Polygons.Add(x.Polygon);
                x.Polygon.Overlay.Markers.Add(x.Marker);
                break;
            }
        }
Esempio n. 14
0
        public void RefreshUI()
        {
            saveState();
            isEditMode = false;

            trvObGroups.Nodes.Clear();
            foreach (GMapOverlay x in TheMap.Overlays)
            {
                x.Clear();
            }

            if (_Dh.myObGroups.Count > 0)
            {
                cmbObGroups.Items.Clear();

                foreach (xObGroup xobgroup in _Dh.myObGroups)
                {
                    cmbObGroups.Items.Add(xobgroup.Name);
                }
                cmbObGroups.Items.Add(strNewObGroup);
                cmbObGroups.SelectedIndex = cmbObGroups.Items.Count - 1;
            }



            // Populate TreeView and draw objects on the map
            foreach (xObGroup x in _Dh.myObGroups)
            {
                // Check access to this objects group for this user
                if (_Dh.getGroupAccessLevel(x).CompareTo(_Dh.AccessLevel.Read) < 0)
                {
                    continue;
                }

                List <xObject> childs = _Dh.getObjectsByGroupId(x.Id);
                if (childs != null && childs.Count > 0)
                {
                    trvObGroups.Nodes.Add("obgr_" + x.Id, x.Name).Checked = true;
                    foreach (xObject child in childs)
                    {
                        trvObGroups.Nodes["obgr_" + x.Id].Nodes.Add("obj_" + child.Id, child.Name).Checked = true;
                    }
                    foreach (xObject o in _Dh.getObjectsByGroupId(x.Id))
                    {
                        drawObject(o);
                    }
                }
            }

            // Restoring TreeView from saved state
            foreach (DictionaryEntry dictionaryEntry in stgList.pdArray)
            {
                bool       b     = (bool)dictionaryEntry.Value;
                TreeNode[] nodes = trvObGroups.Nodes.Find(dictionaryEntry.Key.ToString(), true);
                if (nodes.Length > 0)
                {
                    string[] keyparts = dictionaryEntry.Key.ToString().Split(new char[] { '_' });

                    xObGroup xgr = null;
                    xObject  xob = null;
                    if (keyparts[0].Equals("obgr"))
                    {
                        xgr = _Dh.getGroupById(Convert.ToInt32(keyparts[1]));
                    }
                    else
                    {
                        xob = _Dh.getObjectById(Convert.ToInt32(keyparts[1]));
                        xgr = _Dh.getGroupById(xob.ObGroupId);
                    }
                    GMapOverlay overlay = _Dh.getOverlay(TheMap, xgr);

                    // Check or uncheck current node
                    TreeNode itemNode = trvObGroups.Nodes.Find(dictionaryEntry.Key.ToString(), true)[0];
                    itemNode.Checked = b;
                    if (!b)
                    {
                        // Hide objects if they are not selected in the TreeView
                        if (keyparts[0].Equals("obj"))
                        {
                            removeObjFromMap(_Dh.getObjById(Convert.ToInt64(keyparts[1])));
                        }
                        else
                        {
                            overlay.Clear();
                        }
                    }
                }
            }
            trvObGroups.ExpandAll();



            if (_Dh.myObGroups.Count == 0)
            {
                // For the first start
                spcMain.Panel1MinSize    = 1;
                spcMain.SplitterDistance = 1;

                cmbObGroups.Visible = false;
            }
        }