// 从 Windows 剪贴板中粘贴 JSON 格式 void menu_pasteFromJSONClipboard(object sender, System.EventArgs e) { string strError; try { // 插入位置 int index = this.listView1.Items.IndexOf(this.listView1.FocusedItem); if (index == -1 && this.listView1.SelectedIndices.Count > 0) { index = this.listView1.SelectedIndices[0]; } List <int> indices = new List <int>(); string value = Clipboard.GetText(); // Newtonsoft.Json.JsonReaderException var servers = JsonConvert.DeserializeObject <List <CopyServer> >(value); foreach (var source in servers) { dp2Server server = Servers.NewServer(index); source.CopyTo(server); indices.Add(index); index++; } if (indices.Count > 0) { Servers.Changed = true; FillList(); foreach (int i in indices) { var item = this.listView1.Items[i]; item.Selected = true; item.EnsureVisible(); } } return; } catch (Newtonsoft.Json.JsonReaderException) { strError = "剪贴板中的内容不是特定格式"; goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } ERROR1: MessageBox.Show(this, strError); }
void menu_newServer(object sender, System.EventArgs e) { int nActiveLine = -1; if (listView1.SelectedIndices.Count != 0) { nActiveLine = listView1.SelectedIndices[0]; } ServerDlg dlg = new ServerDlg(); // GuiUtil.AutoSetDefaultFont(dlg); GuiUtil.SetControlFont(dlg, this.Font); dlg.Text = "新增服务器地址和缺省帐户"; if (nActiveLine == -1) { // 无参考事项情形的新增 dlg.ServerName = "社科院联合编目中心"; dlg.ServerUrl = "http://ssucs.org/dp2library"; dlg.UserName = "******"; } else { dlg.ServerName = ((dp2Server)Servers[nActiveLine]).Name; dlg.Password = ((dp2Server)Servers[nActiveLine]).DefaultPassword; dlg.ServerUrl = ((dp2Server)Servers[nActiveLine]).Url; dlg.UserName = ((dp2Server)Servers[nActiveLine]).DefaultUserName; dlg.SavePassword = ((dp2Server)Servers[nActiveLine]).SavePassword; } dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) { return; } dp2Server server = Servers.NewServer(nActiveLine); server.Name = dlg.ServerName; server.DefaultPassword = dlg.Password; server.Url = dlg.ServerUrl; server.DefaultUserName = dlg.UserName; server.SavePassword = dlg.SavePassword; Servers.Changed = true; FillList(); // 选择一行 // parameters: // nIndex 要设置选择标记的行。如果==-1,表示清除全部选择标记但不选择。 // bMoveFocus 是否同时移动focus标志到所选择行 ListViewUtil.SelectLine(listView1, Servers.Count - 1, true); m_bChanged = true; }