/// <summary> /// Called to add Place to the tracking window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddPlace_Click(object sender, EventArgs e) { AddPlace ap_dlg = new AddPlace(); while (ap_dlg.ShowDialog() == DialogResult.OK) { if (m_Places.ContainsKey(ap_dlg.m_PlaceData.Name)) { MessageBox.Show("The Place name entered is already in the list.\nPlease re-enter", "Incorrect data"); continue; } else { PlaceData pd = ap_dlg.m_PlaceData; ListViewItem lvi = new ListViewItem(); lvi.Group = StatusView.Groups["Places"]; lvi.Name = pd.Name; lvi.Text = "*****"; lvi.SubItems.Add(pd.Name); lvi.SubItems.Add(pd.Coordinates.MGRS + " / " + pd.Coordinates.Latitude.ToString("N6") + ", " + pd.Coordinates.Longitude.ToString("N6")); DateTime add_time = DateTime.Now; pd.Coordinates.Time = add_time; lvi.SubItems.Add(add_time.ToShortTimeString() + add_time.ToUniversalTime().ToString(" (HH:mm:ssZ)")); m_Places.Add(pd.Name, pd); UpdateTrackingHistory(pd); StatusView.Items.Add(lvi); break; } } }
private void UpdateTrackingHistory(PlaceData pd) { try { string Geo = pd.Coordinates.Longitude.ToString("N6") + "," + pd.Coordinates.Latitude.ToString("N6"); m_historyTableAdapter.Insert(pd.Name, pd.Name, pd.Coordinates.MGRS, Geo, pd.Coordinates.Altitude.ToString(), pd.Coordinates.Direction.ToString(), pd.Coordinates.Speed.ToString(), pd.Coordinates.Time, pd.Description, null, null); m_statusStrip.Items[2].Text = String.Format("History writing :{0}({1}).", m_historyTableAdapter.Connection.DataSource, ++m_RecordsAdded); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.InnerException + ex.ToString()); m_statusStrip.Items[2].Text = String.Format("History writing error: {0}.", ex.Message); } }
/// <summary> /// Called when user double-clicks on the Team/Place - bring appropriate dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StatusView_DoubleClick(object sender, EventArgs e) { if (StatusView.SelectedItems.Count != 0) { ListViewItem lvi = StatusView.SelectedItems[0]; String lvigs = lvi.Group.Name; if (lvigs.Equals("Places")) { AddPlace ap_dlg = new AddPlace(); if (m_Places.ContainsKey(lvi.Name)) { ap_dlg.m_PlaceData = m_Places[lvi.Name]; } else { PlaceData pd = new PlaceData(); pd.Name = lvi.SubItems[1].Text; pd.Coordinates.MGRS = lvi.SubItems[2].Text; ap_dlg.m_PlaceData = pd; } ap_dlg.Text = "Change/View Place"; if (ap_dlg.ShowDialog() == DialogResult.OK) { PlaceData pd = ap_dlg.m_PlaceData; m_Places[pd.Name] = pd; UpdateTrackingHistory(pd); lvi.SubItems.Clear(); lvi.Name = pd.Name; lvi.Text = "*****"; lvi.SubItems.Add(pd.Name); lvi.SubItems.Add(pd.Coordinates.MGRS + " / " + pd.Coordinates.Latitude.ToString("N6") + ", " + pd.Coordinates.Longitude.ToString("N6")); DateTime add_time = DateTime.Now; lvi.SubItems.Add(add_time.ToShortTimeString() + add_time.ToUniversalTime().ToString(" (HH:mm:ssZ)")); } } else { AddTeam at_dlg = new AddTeam(); at_dlg.m_PlaceData = m_Places; if (m_Teams.ContainsKey(lvi.Text)) { at_dlg.m_TeamData = m_Teams[lvi.Text]; } else { TeamData td = new TeamData(); td.CID = lvi.Text; td.Name = lvi.SubItems[1].Text; td.Coordinates.MGRS = lvi.SubItems[2].Text; at_dlg.m_TeamData = td; } at_dlg.Text = "Change/View Team"; if (at_dlg.ShowDialog() == DialogResult.OK) { TeamData td = at_dlg.m_TeamData; td.Coordinates.Time = DateTime.Now; m_Teams[td.CID] = td; UpdateTrackingHistory(td); lvi.SubItems.Clear(); lvi.Name = td.CID; lvi.Text = td.CID; lvi.SubItems.Add(td.Name); lvi.SubItems.Add(td.Coordinates.MGRS + " / " + td.Coordinates.Latitude.ToString("N6") + ", " + td.Coordinates.Longitude.ToString("N6")); DateTime add_time = td.Coordinates.Time; lvi.SubItems.Add(add_time.ToShortTimeString() + add_time.ToUniversalTime().ToString(" (HH:mm:ssZ)")); } } } }