private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi == null) { textBox1.Text = ""; textBox8.Text = ""; textBox2.Text = ""; textBox3.Text = ""; button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; button5.Enabled = false; textBox2.ReadOnly = true; } else { textBox1.Text = wpi.WP.ID > 0 ? wpi.WP.ID.ToString() : ""; textBox8.Text = Utils.Conversion.GetCoordinatesPresentation(wpi.WP.Lat, wpi.WP.Lon); textBox2.Text = wpi.WP.Description ?? ""; textBox3.Text = wpi.WP.Date.ToString(); button2.Enabled = true; button3.Enabled = true; button4.Enabled = wpi.WP.ID <= 0; button5.Enabled = wpi.WP.ID <= 0; textBox2.ReadOnly = wpi.WP.ID > 0; } }
private void button1_Click(object sender, EventArgs e) { if (Core.ActiveGeocache != null) { int index = 1; string code = string.Format("{0:00}{1}", index, Core.ActiveGeocache.Code.Substring(2)); while (Utils.DataAccess.GetWaypoint(Core.Waypoints, code) != null) { index++; code = string.Format("{0:00}{1}", index, Core.ActiveGeocache.Code.Substring(2)); } WaypointListItem wpi = new WaypointListItem(); wpi.WP = new Framework.Data.Waypoint(); wpi.WP.Code = code; wpi.WP.Comment = ""; wpi.WP.DataFromDate = DateTime.Now; wpi.WP.Description = ""; wpi.WP.GeocacheCode = Core.ActiveGeocache.Code; wpi.WP.ID = code; wpi.WP.Lat = null; wpi.WP.Lon = null; wpi.WP.Name = ""; wpi.WP.Saved = false; wpi.WP.Time = DateTime.Now; wpi.WP.Url = ""; wpi.WP.UrlName = ""; wpi.WP.WPType = Core.WaypointTypes[1]; Core.Waypoints.Add(wpi.WP); listBox1.Items.Add(wpi); listBox1.SelectedIndex = listBox1.Items.Count - 1; } }
private void button3_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { Framework.Data.Waypoint wp = wpi.WP; Framework.Data.Location l; if (wp.Lat != null && wp.Lon != null) { l = new Framework.Data.Location((double)wp.Lat, (double)wp.Lon); } else { l = new Framework.Data.Location(Core.ActiveGeocache.Lat, Core.ActiveGeocache.Lon); } using (Utils.Dialogs.GetLocationForm dlg = new Utils.Dialogs.GetLocationForm(Core, l)) { if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox8.Text = Utils.Conversion.GetCoordinatesPresentation(dlg.Result); } } } }
public void UpdateView() { if (Visible) { listBox1.Items.Clear(); if (Core.ActiveGeocache == null) { button1.Enabled = false; } else { button1.Enabled = true; Framework.Data.Geocache gc = Core.ActiveGeocache; List <Framework.Data.Waypoint> wpList = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code); foreach (Framework.Data.Waypoint wp in wpList) { WaypointListItem wpi = new WaypointListItem(); wpi.WP = wp; listBox1.Items.Add(wpi); } } listBox1_SelectedIndexChanged(this, EventArgs.Empty); } }
private void button4_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox8.Text); if (Core.ActiveGeocache != null && wpi != null && wpi.WP.ID <= 0) { if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true)) { try { Utils.API.LiveV6.SaveUserWaypointResponse resp = null; Cursor = Cursors.WaitCursor; try { using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core)) { var req = new Utils.API.LiveV6.SaveUserWaypointRequest(); req.AccessToken = api.Token; req.CacheCode = Core.ActiveGeocache.Code; req.Description = textBox2.Text; req.Latitude = ll.Lat; req.Longitude = ll.Lon; resp = api.Client.SaveUserWaypoint(req); } } finally { Cursor = Cursors.Default; } if (resp != null) { if (resp.Status.StatusCode == 0) { Framework.Data.UserWaypoint wp = Utils.API.Convert.UserWaypoint(Core, resp.NewWaypoint); wp.Saved = false; wpi.WP = wp; Core.UserWaypoints.Add(wp); } else { MessageBox.Show(resp.Status.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } else { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } catch { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } } }
private void button2_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { Core.Waypoints.Remove(wpi.WP); listBox1.Items.Remove(wpi); } }
private void button3_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { if (wpi.WP.ID <= 0) { listBox1.Items.Remove(wpi); button1.Enabled = true; } else { if (Utils.API.GeocachingLiveV6.CheckAPIAccessAvailable(Core, true)) { try { Utils.API.LiveV6.StatusResponse resp = null; Cursor = Cursors.WaitCursor; try { using (Utils.API.GeocachingLiveV6 api = new Utils.API.GeocachingLiveV6(Core)) { resp = api.Client.DeleteUserWaypoint(api.Token, wpi.WP.ID); } } finally { Cursor = Cursors.Default; } if (resp != null) { if (resp.StatusCode == 0) { Core.UserWaypoints.Remove(wpi.WP); } else { MessageBox.Show(resp.StatusMessage ?? "", Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } else { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } catch { MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILED), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } } } } }
private void button2_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (Core.ActiveGeocache != null && wpi != null) { Core.Geocaches.BeginUpdate(); Core.ActiveGeocache.CustomLat = wpi.WP.Lat; Core.ActiveGeocache.CustomLon = wpi.WP.Lon; Core.Geocaches.EndUpdate(); } }
private void button1_Click(object sender, EventArgs e) { if (Core.ActiveGeocache != null) { WaypointListItem wpi = new WaypointListItem(); wpi.WP = new Framework.Data.UserWaypoint(); wpi.WP.ID = -1; wpi.WP.Description = "Coordinate Override"; wpi.WP.Lat = Core.ActiveGeocache.Lat; wpi.WP.Lon = Core.ActiveGeocache.Lon; wpi.WP.Date = DateTime.Now; listBox1.Items.Add(wpi); listBox1.SelectedItem = wpi; button1.Enabled = false; } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { Framework.Data.Waypoint wp = wpi.WP; button2.Enabled = true; button5.Enabled = true; button3.Enabled = true; button4.Enabled = true; textBox1.Text = wp.ID ?? ""; textBox2.Text = wp.Code ?? ""; textBox3.Text = wp.Name ?? ""; textBox4.Text = wp.Comment ?? ""; textBox5.Text = wp.Description ?? ""; textBox6.Text = wp.Url ?? ""; textBox7.Text = wp.UrlName ?? ""; if (wp.Lat != null && wp.Lon != null) { textBox8.Text = Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat, (double)wp.Lon); } else { textBox8.Text = ""; } comboBoxWaypointType1.SelectedItem = wp.WPType; } else { button2.Enabled = false; button5.Enabled = false; button3.Enabled = false; button4.Enabled = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; } }
private void button5_Click(object sender, EventArgs e) { WaypointListItem wpi = listBox1.SelectedItem as WaypointListItem; if (wpi != null) { Framework.Data.Waypoint wp = wpi.WP; wp.BeginUpdate(); wp.Name = textBox3.Text; wp.Comment = textBox4.Text; wp.Description = textBox5.Text; wp.Url = textBox6.Text; wp.UrlName = textBox7.Text; Framework.Data.Location l = Utils.Conversion.StringToLocation(textBox8.Text); if (l == null) { wp.Lat = null; wp.Lon = null; } else { wp.Lat = l.Lat; wp.Lon = l.Lon; } wp.WPType = comboBoxWaypointType1.SelectedItem as Framework.Data.WaypointType; if (wp.WPType == null) { wp.WPType = Core.WaypointTypes[0]; } wp.EndUpdate(); typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, listBox1, new object[] { }); } }
public void UpdateView() { if (Visible) { listBox1.Items.Clear(); if (Core.ActiveGeocache == null) { button1.Enabled = false; } else { button1.Enabled = true; List<Framework.Data.UserWaypoint> wpList = Utils.DataAccess.GetUserWaypointsFromGeocache(Core.UserWaypoints, Core.ActiveGeocache.Code); foreach (Framework.Data.UserWaypoint wp in wpList) { WaypointListItem wpi = new WaypointListItem(); wpi.WP = wp; listBox1.Items.Add(wpi); } } listBox1_SelectedIndexChanged(this, EventArgs.Empty); } }