private bool SaveCurrentRoute() { string newrtname = textBoxRouteName.Text?.Trim(); string oldrtname = currentroute.Name; var newrt = new SavedRouteClass(); var oldrt = currentroute; bool ret = false; UpdateRouteInfo(newrt); SavedRouteClass foundedsm = savedroute.Find(x => x.Name.Equals(newrtname, StringComparison.InvariantCultureIgnoreCase) && x.EDSM); if (string.IsNullOrEmpty(newrtname)) { ExtendedControls.MessageBoxTheme.Show(FindForm(), "Please specify a name for the route.".T(EDTx.UserControlExpedition_Specify), "Warning".T(EDTx.Warning), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxRouteName.Select(); } else if (foundedsm != null) { ExtendedControls.MessageBoxTheme.Show(FindForm(), ("The current route name conflicts with a well-known expedition." + Environment.NewLine + "Please specify a new name to save your changes.").T(EDTx.UserControlExpedition_Conflict), "Warning".T(EDTx.Warning), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxRouteName.Select(); textBoxRouteName.SelectAll(); } else { var overwriteroute = savedroute.Where(r => r.Name.Equals(newrtname) && r.Id != currentroute.Id).FirstOrDefault(); if (overwriteroute != null) { if (MessageBoxTheme.Show(FindForm(), "Warning: route already exists. Would you like to overwrite it?".T(EDTx.UserControlExpedition_Overwrite), "Warning".T(EDTx.Warning), MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false); } overwriteroute.Delete(); savedroute.Remove(overwriteroute); } if (currentroute.Id < 0) { ret = newrt.Add(); } else { newrt.Id = currentroute.Id; ret = newrt.Update(); savedroute.Remove(oldrt); } currentroute = newrt; savedroute.Add(newrt); savedroute = savedroute.Where(r => !r.Deleted).OrderBy(r => r.Name).ToList(); UpdateComboBox(); } return(ret); }
private bool SaveCurrentRoute() { bool ret = false; string newrtname = textBoxRouteName.Text?.Trim(); string oldrtname = _currentRoute.Name; var newrt = new SavedRouteClass(); var oldrt = _currentRoute; UpdateRouteInfo(newrt); if (string.IsNullOrEmpty(newrtname)) { ExtendedControls.MessageBoxTheme.Show(ParentForm, "Please specify a name for the route.", "Unsaved Route", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxRouteName.Select(); } else if (EDSMClass.Expeditions.Any(r => r.Name.Equals(newrtname))) { ExtendedControls.MessageBoxTheme.Show(ParentForm, "The current route name conflicts with a well-known expedition." + Environment.NewLine + "Please specify a new name to save your changes.", "Unsaved Route", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxRouteName.Select(); textBoxRouteName.SelectAll(); } else { var overwriteroute = _savedRoutes.Where(r => r.Name.Equals(newrtname) && r.Id != _currentRoute.Id).FirstOrDefault(); if (overwriteroute != null) { if (MessageBoxTheme.Show(ParentForm, "Warning: route already exists. Would you like to overwrite it?", "Route Exists", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false); } overwriteroute.Delete(); _savedRoutes.Remove(overwriteroute); } if (_currentRoute.Id < 0) { ret = newrt.Add(); } else { newrt.Id = _currentRoute.Id; ret = newrt.Update(); _savedRoutes.Remove(oldrt); } _currentRoute = newrt; _savedRoutes.Add(newrt); _savedRoutes = _savedRoutes.Where(r => !r.Name.StartsWith("\x7F")).OrderBy(r => r.Name).ToList(); UpdateComboBox(); } return(ret); }
private void toolStripButtonSave_Click(object sender, EventArgs e) { UpdateRouteInfo(_currentRoute); if (_currentRoute.Id == -1) { _currentRoute.Add(); _savedRoutes.Add(_currentRoute); UpdateComboBox(); } else { _currentRoute.Update(); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { UpdateRouteInfo(_currentRoute); if (String.IsNullOrEmpty(_currentRoute.Name)) { var result = EDDiscovery.Forms.MessageBoxTheme.Show(_discoveryForm, "Please specify a name for the route.", "Unsaved route", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxRouteName.Select(); return; } if (_currentRoute.Id == -1) { _currentRoute.Add(); _savedRoutes.Add(_currentRoute); } else { _currentRoute.Update(); } UpdateComboBox(); toolStripComboBoxRouteSelection.Text = _currentRoute.Name; }