private void comboBoxSteps_Validating(object sender, System.ComponentModel.CancelEventArgs e) { try { int value = int.Parse(textBoxPorts.Text); if (value < 0) { throw new LocalizedException("ValueMustGreaterThanZero"); } } catch (Exception ex) { e.Cancel = true; textBoxPorts.Focus(); LocalizedException.ShowMessage(this, ex); } }
private void buttonOk_Click(object sender, System.EventArgs e) { Control control = null; try { control = textBoxName; string name = textBoxName.Text; if (name == "") { throw new LocalizedException("EnterAName"); } if (ServerConnection.ServerConnections.Contains(name)) { if (DialogResult.No == MessageBox.Show(this, LocalizedString.Format("NameAlreadyExist", name), null, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { textBoxName.Focus(); return; } } control = textBoxServer; string server = textBoxServer.Text; if (server == "") { throw new LocalizedException("EnterAServer"); } control = textBoxPort; int port; try { port = int.Parse(textBoxPort.Text); if (port < 1 || port > 65535) { throw new LocalizedException("PortMustBetween1And65535"); } } catch { throw new LocalizedException("PortMustBetween1And65535"); } control = textBoxSrcpServerPath; string srcpServerPath = string.Empty; if (checkBoxAutoStartSRCPServer.Checked) { srcpServerPath = textBoxSrcpServerPath.Text; if (srcpServerPath == "") { throw new LocalizedException("EnterLocalPathToSRCPServer"); } if (!File.Exists(srcpServerPath)) { throw new LocalizedException("SRCPServerDoesNotExist", srcpServerPath); } } control = null; if (Connection != null) { ServerConnection.ServerConnections.Remove(Connection.Name); } Connection = new ServerConnection(name, server, port, checkBoxAutoStartSRCPServer.Checked, checkBoxAutostopSRCPServer.Checked, srcpServerPath, start); DialogResult = DialogResult.OK; } catch (Exception ex) { if (control != null) { control.Focus(); } LocalizedException.ShowMessage(this, ex); return; } }