private void buttonShowMap_Click(object sender, EventArgs e)
        {
            float actualLatitude = 0;
            float actualLongitude = 0;
            try
            {
                actualLatitude = float.Parse(StaticGPS.position.Latitude.ToString());
                actualLongitude = float.Parse(StaticGPS.position.Longitude.ToString());
            }
            catch (Exception)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show("GPS-Data couldn`t be read. Data will be set to default values.");
            }
            SelectMapForm form = new SelectMapForm((float)this._ceLoc.AverageLatitudeCache, (float)this._ceLoc.AverageLongitudeCache,actualLatitude,actualLongitude);
            form.ShowDialog();

            if (this._ceLoc != null)
            {
                this._ceLoc.AverageLatitudeCache = form.GPSLat;
                this.labelLatitude.Text = form.GPSLat.ToString("F");
                this._ceLoc.AverageLongitudeCache = form.GPSLong;
                this.labelLongitude.Text = form.GPSLong.ToString("F");

                this._ceLoc.Location2 = form.GPSLat.ToString();
                this.textBoxLocation2.Text = this._ceLoc.Location2;
                this._ceLoc.Location1 = form.GPSLong.ToString();
                this.textBoxLocation1.Text = this._ceLoc.Location1;
            }
        }
Exemplo n.º 2
0
        private void menuItemShowMap_Click(object sender, EventArgs e)
        {
            if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null || this.treeViewFieldData.SelectedNode.Tag == null)
                return;

            // Maps durchsuchen nach passenden Karten
            TreeNode node = this.treeViewFieldData.SelectedNode;
            TreeViewNodeData data = node.Tag as TreeViewNodeData;
            SelectMapForm form;
            float actualLatitude = 0;
            float actualLongitude = 0;
            if (StaticGPS.isOpened())
            {
                if (StaticGPS.position != null)
                {
                    try
                    {
                        actualLatitude = float.Parse(StaticGPS.position.Latitude.ToString());
                        actualLongitude = float.Parse(StaticGPS.position.Longitude.ToString());
                    }
                    catch(Exception)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("GPS-Data couldn`t be read. Data will be set to default values.");
                    }
                }
            }
            if (data.NodeType == TreeViewNodeTypes.LocalisationNode && data.ID==8)
            {
                try
                {
                    TreeNode parentNode = node.Parent;
                    TreeViewNodeData parentData = parentNode.Tag as TreeViewNodeData;
                    CollectionEventLocalisation loc = null;
                    if (parentData.NodeType == TreeViewNodeTypes.EventNode)
                        loc = DataFunctions.Instance.RetrieveCollectionEventLocalisation((int)data.ID, (int)parentData.ID);
                    else
                    {
                        CollectionSpecimen spec = DataFunctions.Instance.RetrieveCollectionSpecimen((int)data.CollectionSpecimenID);
                        if (spec != null)
                            loc = DataFunctions.Instance.RetrieveCollectionEventLocalisation((int)data.ID, (int)spec.CollectionEventID);
                    }

                    if (loc != null)
                    {
                        if (loc.AverageAltitudeCache == null)
                            loc.AverageAltitudeCache = 0;
                        if (loc.AverageLatitudeCache == null)
                            loc.AverageLatitudeCache = 0;
                        if (loc.AverageLongitudeCache == null)
                            loc.AverageLongitudeCache = 0;
                        form = new SelectMapForm((float)loc.AverageLatitudeCache, (float)loc.AverageLongitudeCache, actualLatitude, actualLongitude);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            loc.AverageLongitudeCache = form.GPSLong;
                            loc.Location1 = form.GPSLong.ToString("00.00000000");
                            loc.AverageLatitudeCache = form.GPSLat;
                            loc.Location2 = form.GPSLat.ToString("00.00000000");
                            loc.LocationNotes = "GPS Coordinates manually changed via Google Map";

                            try
                            {
                                DataFunctions.Instance.Update(loc);
                                this._tvOperations.parameterizeCollectionEventLocalisationNode(loc, node);
                            }
                            catch (DataFunctionsException ex)
                            {
                                Cursor.Current = Cursors.Default;
                                MessageBox.Show("Changed Data couldn't be saved. " + ex.Message + " (Type: GPS)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                this.afterSelect(this.treeViewFieldData.SelectedNode);
                                return;
                            }

                            this.treeViewFieldData.SelectedNode = node;
                            this.treeViewFieldData.Focus();
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Not Enough Memory");
                    //StaticGPS.updatePositionDataHandler = new EventHandler(UpdatePositionData);
                    //StaticGPS.updateDeviceDataHandler = new EventHandler(UpdateDeviceData);
                    return;
                }
                catch (ConnectionCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.afterSelect(this.treeViewFieldData.SelectedNode);
                    return;
                }
            }
            else if (data.NodeType == TreeViewNodeTypes.EventNode)
            {
                try
                {
                    TreeNode eventNode = node;
                    TreeViewNodeData eventData = eventNode.Tag as TreeViewNodeData;
                    CollectionEventLocalisation loc = null;
                    if (eventData.NodeType == TreeViewNodeTypes.EventNode)
                        loc = DataFunctions.Instance.RetrieveCollectionEventLocalisation(8, (int)eventData.ID);
                    else
                    {
                        CollectionEvent ev=DataFunctions.Instance.RetrieveCollectionEvent((int) eventData.ID);
                        loc = DataFunctions.Instance.CreateCollectionEventLocalisation(8, ev);
                    }

                    if (loc != null)
                    {
                        if (loc.AverageAltitudeCache == null)
                            loc.AverageAltitudeCache = 0;
                        if (loc.AverageLatitudeCache == null)
                            loc.AverageLatitudeCache = 0;
                        if (loc.AverageLongitudeCache == null)
                            loc.AverageLongitudeCache = 0;
                        form = new SelectMapForm((float)loc.AverageLatitudeCache, (float)loc.AverageLongitudeCache, actualLatitude, actualLongitude);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            loc.AverageLongitudeCache = form.GPSLong;
                            loc.Location1 = form.GPSLong.ToString("00.00000000");
                            loc.AverageLatitudeCache = form.GPSLat;
                            loc.Location2 = form.GPSLat.ToString("00.00000000");
                            loc.LocationNotes = "GPS Coordinates manually changed via DiversityMobile";

                            try
                            {
                                DataFunctions.Instance.Update(loc);
                                this._tvOperations.parameterizeCollectionEventLocalisationNode(loc, node);
                            }
                            catch (DataFunctionsException ex)
                            {
                                Cursor.Current = Cursors.Default;
                                MessageBox.Show("Changed Data couldn't be saved. " + ex.Message + " (Type: GPS)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                this.afterSelect(this.treeViewFieldData.SelectedNode);
                                return;
                            }

                            this.treeViewFieldData.SelectedNode = node;
                            this.treeViewFieldData.Focus();
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Not Enough Memory");
                    //StaticGPS.updatePositionDataHandler = new EventHandler(UpdatePositionData);
                    //StaticGPS.updateDeviceDataHandler = new EventHandler(UpdateDeviceData);
                    return;
                }
                catch (ConnectionCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.afterSelect(this.treeViewFieldData.SelectedNode);
                    return;
                }
            }
            else if (data.NodeType == TreeViewNodeTypes.GeographyNode)
            {
                try
                {
                    TreeNode iuNode = this.treeViewFieldData.SelectedNode.Parent;
                    TreeViewNodeData iuData=iuNode.Tag as TreeViewNodeData;
                    IdentificationUnit iu = DataFunctions.Instance.RetrieveIdentificationUnit((int)iuData.ID);
                    IdentificationUnitGeoAnalysis iuGeoAnalysis = iu.IdentificationUnitGeoAnalysis.First();
                    if (iuGeoAnalysis != null)
                    {
                        form = new SelectMapForm((float)iuGeoAnalysis.GeoLatitude, (float)iuGeoAnalysis.GeoLongitude, actualLatitude, actualLongitude);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            double? altitude = iuGeoAnalysis.GeoAltitude;
                            iuGeoAnalysis.setGeography(form.GPSLat, form.GPSLong, altitude);

                            //iuGeoAnalysis.Notes = "GPS Coordinates manually changed via Google Map";

                            try
                            {
                                DataFunctions.Instance.Update(iuGeoAnalysis);
                                this._tvOperations.parameterizeIUGeoANode(iuGeoAnalysis, node);
                            }
                            catch (DataFunctionsException ex)
                            {
                                Cursor.Current = Cursors.Default;
                                MessageBox.Show("Changed Data couldn't be saved. " + ex.Message + " (Type: Geography)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                this.afterSelect(this.treeViewFieldData.SelectedNode);
                                return;
                            }

                            this.treeViewFieldData.SelectedNode = node;
                            this.treeViewFieldData.Focus();
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Not Enough Memory");
                    //StaticGPS.updatePositionDataHandler = new EventHandler(UpdatePositionData);
                    //StaticGPS.updateDeviceDataHandler = new EventHandler(UpdateDeviceData);
                }
                catch (ConnectionCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.afterSelect(this.treeViewFieldData.SelectedNode);
                    return;
                }
            }
            else
            {
                try
                {
                    //if (actualLatitude == 0)//zum testen im büro
                    //    actualLatitude = 48;
                    //if (actualLongitude == 0)
                    //    actualLongitude = 11;
                    form = new SelectMapForm(actualLatitude, actualLongitude);
                    form.ShowDialog();
                }
                catch (OutOfMemoryException)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Not Enough Memory");
                    //StaticGPS.updatePositionDataHandler = new EventHandler(UpdatePositionData);
                    //StaticGPS.updateDeviceDataHandler = new EventHandler(UpdateDeviceData);
                }
            }
            //StaticGPS.updatePositionDataHandler = new EventHandler(UpdatePositionData);
            //StaticGPS.updateDeviceDataHandler = new EventHandler(UpdateDeviceData);
        }