private void toolStripButtonImportRoute_Click(object sender, EventArgs e) { if (_discoveryForm.RouteControl.RouteSystems == null || _discoveryForm.RouteControl.RouteSystems.Count == 0) { EDDiscovery.Forms.MessageBoxTheme.Show(String.Format("Please create a route on the route tab"), "Import from route tab"); return; } SavedRouteClass newroute = new SavedRouteClass(); UpdateRouteInfo(newroute); if (!newroute.Equals(_currentRoute)) { var result = EDDiscovery.Forms.MessageBoxTheme.Show(_discoveryForm, "There are unsaved changes to the current route.\r\n" + "Are you sure you want to import a route without saving?", "Unsaved route", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return; } } ClearRoute(); toolStripComboBoxRouteSelection.SelectedItem = null; foreach (SystemClass s in _discoveryForm.RouteControl.RouteSystems) { dataGridViewRouteSystems.Rows.Add(s.name, "", ""); } UpdateSystemRows(); }
// If the route has any unsaved changes, prompt the user to save them. // Returns true if the caller is allowed to continue; false if caller should abort. private bool PromptAndSaveIfNeeded() { var rt = new SavedRouteClass(); UpdateRouteInfo(rt); if (rt.Equals(currentroute)) // No changes have been made. { return(true); } else { // here get scanner to complain var result = ExtendedControls.MessageBoxTheme.Show(FindForm(), ("There are unsaved changes to the current route." + Environment.NewLine + "Would you like to save the current route before proceeding?").T(EDTx.UserControlExpedition_Unsaved), "Warning".T(EDTx.Warning), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); switch (result) { case DialogResult.Yes: return(SaveCurrentRoute()); case DialogResult.No: return(true); case DialogResult.Cancel: default: return(false); } } }
// If the route has any unsaved changes, prompt the user to save them. // Returns true if the caller is allowed to continue; false if caller should abort. private bool PromptAndSaveIfNeeded() { var rt = new SavedRouteClass(); UpdateRouteInfo(rt); if (rt.Equals(_currentRoute)) // No changes have been made. { return(true); } else { var result = ExtendedControls.MessageBoxTheme.Show(ParentForm, "There are unsaved changes to the current route." + Environment.NewLine + "Would you like to save the current route before proceeding?", "Unsaved route", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); switch (result) { case DialogResult.Yes: return(SaveCurrentRoute()); case DialogResult.No: return(true); case DialogResult.Cancel: default: return(false); } } }
private void toolStripButtonNew_Click(object sender, EventArgs e) { SavedRouteClass newroute = new SavedRouteClass(); UpdateRouteInfo(newroute); if (!newroute.Equals(_currentRoute)) { var result = MessageBox.Show(_discoveryForm, "There are unsaved changes to the current route.\r\nAre you sure you want to select another route without saving?", "Unsaved route", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { toolStripComboBoxRouteSelection.SelectedIndex = _currentRouteIndex; return; } } ClearRoute(); }
public override bool AllowClose() { var rt = new SavedRouteClass(); SaveGridIntoRoute(rt); if (rt.Equals(currentroute)) // No changes have been made. { return(true); } var result = ExtendedControls.MessageBoxTheme.Show(FindForm(), ("There are unsaved changes to the current route." + Environment.NewLine + "Would you like to save the current route before proceeding?").T(EDTx.UserControlExpedition_Unsaved), "Warning".T(EDTx.Warning), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { return(SaveCurrentRoute()); // only allow close if route ok } return(true); }
private void toolStripButtonImportFile_Click(object sender, EventArgs e) { SavedRouteClass newroute = new SavedRouteClass(); UpdateRouteInfo(newroute); if (!newroute.Equals(_currentRoute)) { var result = EDDiscovery.Forms.MessageBoxTheme.Show(_discoveryForm, "There are unsaved changes to the current route.\r\n" + "Are you sure you want to import a route without saving?", "Unsaved route", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return; } } ClearRoute(); toolStripComboBoxRouteSelection.SelectedItem = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Text Files|*.txt"; ofd.Title = "Select a route file"; if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string[] sysnames; try { sysnames = System.IO.File.ReadAllLines(ofd.FileName); } catch (IOException) { EDDiscovery.Forms.MessageBoxTheme.Show(String.Format("There was an error reading {0}", ofd.FileName), "Import route", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List <String> systems = new List <String>(); foreach (String name in sysnames) { String sysname = name; if (sysname.Contains(",")) { String[] values = sysname.Split(','); sysname = values[0]; } if (!String.IsNullOrWhiteSpace(sysname)) { systems.Add(sysname.Trim()); } } if (systems.Count == 0) { EDDiscovery.Forms.MessageBoxTheme.Show(_discoveryForm, String.Format("The imported file contains no known system names"), "Import route", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } foreach (var sysname in systems) { dataGridViewRouteSystems.Rows.Add(sysname, "", ""); } UpdateSystemRows(); }
private void toolStripComboBoxRouteSelection_SelectedIndexChanged(object sender, EventArgs e) { SavedRouteClass newroute = new SavedRouteClass(); UpdateRouteInfo(newroute); if (!newroute.Equals(_currentRoute)) { var result = EDDiscovery.Forms.MessageBoxTheme.Show(_discoveryForm, "There are unsaved changes to the current route.\r\nAre you sure you want to select another route without saving?", "Unsaved route", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { toolStripComboBoxRouteSelection.SelectedIndex = _currentRouteIndex; return; } } _currentRouteIndex = toolStripComboBoxRouteSelection.SelectedIndex; if (_currentRouteIndex == -1) { return; } _currentRoute = _savedRoutes[toolStripComboBoxRouteSelection.SelectedIndex]; dataGridViewRouteSystems.Rows.Clear(); textBoxRouteName.Text = _currentRoute.Name; if (_currentRoute.StartDate == null) { dateTimePickerStartDate.Value = DateTime.Now; dateTimePickerStartDate.Checked = false; dateTimePickerStartTime.Value = DateTime.Now; dateTimePickerStartTime.Checked = false; } else { dateTimePickerStartDate.Checked = true; dateTimePickerStartDate.Value = (DateTime)_currentRoute.StartDate; dateTimePickerStartTime.Value = (DateTime)_currentRoute.StartDate; if (((DateTime)_currentRoute.StartDate).TimeOfDay == new TimeSpan(0, 0, 0)) { dateTimePickerStartTime.Checked = false; } else { dateTimePickerStartTime.Checked = true; } } if (_currentRoute.EndDate == null) { dateTimePickerEndDate.Value = DateTime.Now; dateTimePickerEndDate.Checked = false; dateTimePickerEndTime.Value = DateTime.Now; dateTimePickerEndTime.Checked = false; } else { dateTimePickerEndDate.Checked = true; dateTimePickerEndDate.Value = (DateTime)_currentRoute.EndDate; dateTimePickerEndTime.Value = (DateTime)_currentRoute.EndDate; if (((DateTime)_currentRoute.EndDate).TimeOfDay == new TimeSpan(23, 59, 59)) { dateTimePickerEndTime.Checked = false; } else { dateTimePickerEndTime.Checked = true; } } foreach (string sysname in _currentRoute.Systems) { var rowobj = new object[] { sysname, "", "" }; dataGridViewRouteSystems.Rows.Add(rowobj); } UpdateSystemRows(); }