public void SaveCorrectPwd() { var hosts = JsonConvert.DeserializeObject <ObservableCollection <IpModel> >(Settings.Default.Hosts) ?? new ObservableCollection <IpModel>(); var new_host = new IpModel { Password = Password, Host = Host, Remark = txtRemark.Text, }; try { var hhh = hosts.FirstOrDefault(h => h.Host == Host); if (hhh != null) { hosts.Remove(hhh); } hosts.Insert(0, new_host); Settings.Default.Hosts = JsonConvert.SerializeObject(hosts); Settings.Default.Save(); } catch (Exception) { } }
private void btnAddIp_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtNewIp.Text)) { MessageBox.Show("主机名不能为空"); return; } var hosts = JsonConvert.DeserializeObject <ObservableCollection <IpModel> >(Settings.Default.Hosts) ?? new ObservableCollection <IpModel>(); var new_host = new IpModel { Host = txtNewIp.Text, Remark = txtNewRemark.Text, }; hosts.Add(new_host); Settings.Default.Hosts = JsonConvert.SerializeObject(hosts); Settings.Default.Save(); cbIps.ItemsSource = hosts; cbIps.SelectedItem = new_host; }