private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(NameBox.Text)) { MessageBox.Show("You must enter a server name."); return; } if (string.IsNullOrEmpty(AddressBox.Text) || !IPAddress.TryParse(AddressBox.Text, out IPAddress ipAddress)) { MessageBox.Show("You must enter a (valid) IP address."); return; } if (string.IsNullOrEmpty(PasswordBox.Text)) { MessageBox.Show("You must enter a password."); return; } var serverItem = new ServerModel(NameBox.Text, ipAddress.ToString(), (int)ServerPort.Value, (int)RCONPort.Value, PasswordBox.Text, ConnectOnStartupCheck.Checked, LegacyServer.Checked); var search = DataFileManager.Data.AllServers.Where(x => x.Name == serverItem.Name); if (search.Any()) { DataFileManager.Data.AllServers.Remove(search.First()); } DataFileManager.Data.AllServers.Add(serverItem); DataFileManager.SaveData(); RefreshServerList(); }
private void DeleteButton_Click(object sender, EventArgs e) { var currentItem = ServerList.Text; if (string.IsNullOrEmpty(currentItem)) { MessageBox.Show("There is no server to delete."); return; } var item = DataFileManager.Data.AllServers.FirstOrDefault(x => x.Name == currentItem); if (item == null) { RefreshServerList(); return; } DataFileManager.Data.AllServers.Remove(item); DataFileManager.SaveData(); RefreshServerList(); }