Ejemplo n.º 1
0
 private void gMap_MouseDown(object sender, MouseEventArgs e)
 {
     /* if there's any project marker clicked while a green push-pin marker is clicked
      * green push-pin marker should be disappeared
      * */
     if (currMarker is GMarkerGoogle && !(currMarker is ProjectMarker))
     {
         foreach (GMapMarker marker in mouseOveredMarkers)
         {
             if (marker is ProjectMarker)
             {
                 // remove current marker
                 mouseOveredMarkers.Remove(currMarker);
                 markersOverlay.Markers.Remove(currMarker);
                 currMarker.Dispose();
                 currMarker = null;
                 // refresh gMap
                 gMap.Refresh();
                 break;
             }
         }
     }
     // determine current marker
     if (mouseOveredMarkers.Count > 0)
     {
         currMarker = mouseOveredMarkers.Last();
     }
     // add new marker while right mouse button downed
     else if (e.Button == MouseButtons.Right && GPLC.AuthVerify(GPLCAuthority.Administrator))
     {
         setCurrMarker(gMap.FromLocalToLatLng(e.X, e.Y));
     }
     gMap.Refresh();
 }
Ejemplo n.º 2
0
        private void InputButton_Click(object sender, EventArgs e)
        {
            try
            {
                // check authentication
                GPLC.Auth(GPLCAuthority.Administrator);

                // parse textBox contents
                long   id   = long.Parse(textBox_project_id.Text);
                string name = textBox_project_name.Text;
                string addr = richTextBox_project_addr.Text;
                double lat  = double.Parse(textBox_latlng_lat.Text);
                double lng  = double.Parse(textBox_latlng_lng.Text);
                // check data range
                if (lat > 90 || lat < -90 || lng > 180 || lat < -180)
                {
                    // out of range
                    throw new FormatException("Latlng value out of bound");
                }

                // update database
                try
                {
                    // modify a project or add a project
                    if (InputButton.Text.Equals("Modify"))
                    {
                        // original id
                        long oid = (currMarker as ProjectMarker).ProjectData.id;
                        ModelUtil.updateProject(id, name, addr, lat, lng, oid);
                    }
                    else
                    {
                        // insert a new project
                        ModelUtil.insertProject(id, name, addr, lat, lng);
                        // remove green push-pin marker
                        markersOverlay.Markers.Remove(currMarker);
                        if (currMarker != null)
                        {
                            currMarker.Dispose();
                        }
                    }
                }
                catch (DbException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                // update marker overlay and current marker
                loadProjects();
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (UnauthorizedException ex)
            {
                MessageBox.Show(ex.Message, "Fatal Error");
                Application.Exit();
            }
        }
Ejemplo n.º 3
0
        private void gMap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
        {
            //
            GMapMarker marker = (mouseOveredMarkers.Count > 0) ? mouseOveredMarkers.Last() : item;

            // display clicked latlng on textbox
            textBox_latlng_lat.Text = string.Format("{0:0.00000}", marker.Position.Lat);
            textBox_latlng_lng.Text = string.Format("{0:0.00000}", marker.Position.Lng);
            // double check to avoid inconsistency : check if clicked item really in mouseOvered marker list
            if (mouseOveredMarkers.Contains(item))
            {
                // left mouse button clicked : add a project or view a project
                if (e.Button == MouseButtons.Left)
                {
                    // view a project
                    if (item is ProjectMarker)
                    {
                        ProjectData pd = (marker as ProjectMarker).ProjectData;
                        // set text box
                        textBox_project_id.Text       = pd.id.ToString();
                        textBox_project_name.Text     = pd.name;
                        richTextBox_project_addr.Text = pd.addr;
                        // get marker local position
                        GPoint pos = gMap.FromLatLngToLocal(item.Position);
                        // set map center
                        //this.gMap.Position = gMap.FromLocalToLatLng((int)pos.X, (int)pos.Y + gMap.Height / 4);

                        viewProject(item);
                    }
                    // add a project
                    else if (GPLC.AuthVerify(GPLCAuthority.Administrator))
                    {
                        inputProject(item);
                    }
                }
                // modify a project
                else if (e.Button == MouseButtons.Right && GPLC.AuthVerify(GPLCAuthority.Administrator))
                {
                    if (item is ProjectMarker)
                    {
                        inputProject(marker);
                    }
                }
            }
        }