async void MenuItem_modifyState_Click(object sender, EventArgs e) { string strError = ""; string new_state = InputDlg.GetInput(this, "修改状态", "新状态值", "dontsync", this.Font); if (new_state == null) { return; } try { SetInfoRequest request = new SetInfoRequest(); request.Operation = "setHistory"; request.Entities = new List <Entity>(); foreach (ListViewItem item in this.listView_records.SelectedItems) { RequestItem tag = item.Tag as RequestItem; tag.State = new_state; Record record = new Record { Data = JsonConvert.SerializeObject(tag) }; request.Entities.Add(new Entity { Action = "change:state", NewRecord = record }); } var connection = await ConnectionPool.GetConnectionAsync(this.comboBox_query_myAccount.Text); var result = await connection.SetInfoAsyncLite(this.comboBox_query_shelfAccount.Text, request, TimeSpan.FromSeconds(10), default); if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } // 报错 List <string> errors = new List <string>(); List <string> succeed_records = new List <string>(); if (result.Entities != null) { foreach (var entity in result.Entities) { if (string.IsNullOrEmpty(entity.ErrorInfo) == false) { errors.Add(entity.ErrorInfo); } else { succeed_records.Add(entity.NewRecord?.Data); } } } // 刷新成功修改了的行 foreach (var record in succeed_records) { if (string.IsNullOrEmpty(record)) { continue; } var item = JsonConvert.DeserializeObject <RequestItem>(record); RefreshLine(item.ID, item); } if (errors.Count > 0) { MessageDialog.Show(this, $"出错:\r\n{StringUtil.MakePathList(errors, "\r\n")}"); } return; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } ERROR1: MessageBox.Show(this, strError); }
private async void button_search_Click(object sender, EventArgs e) { string strError = ""; _cancelSearch = new CancellationTokenSource(); CancellationToken token = _cancelSearch.Token; EnableSearchButtons(false); try { this.listView_records.Items.Clear(); var get_result = await ConnectionPool.OpenConnectionAsync(this.comboBox_query_myAccount.Text); if (get_result.Value == -1) { strError = get_result.ErrorInfo; goto ERROR1; } var connection = get_result.Connection; string resultsetName = "default"; string remoteUserName = this.comboBox_query_shelfAccount.Text; SearchRequest request = new SearchRequest(Guid.NewGuid().ToString(), null, // loginInfo, "searchHistory", // "searchBiblio", "dbNameList", this.textBox_query_word.Text, this.comboBox_query_from.Text, this.comboBox_query_matchStyle.Text, resultsetName, "json", -1, 0, 10); var result = await connection.SearchAsyncLite(remoteUserName, request, TimeSpan.FromSeconds(60), token); if (result.ResultCount == -1) { strError = result.ErrorInfo; goto ERROR1; } if (result.ResultCount == 0) { strError = "没有命中"; goto ERROR1; } FillRecords(result.Records, true, token); if (result.Records.Count < result.ResultCount) { var fill_result = await FillRestRecordsAsync( connection, remoteUserName, resultsetName, result.Records.Count, token); } return; } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ExceptionUtil.GetDebugText(ex); // ex.Message; goto ERROR1; } finally { EnableSearchButtons(true); } ERROR1: MessageBox.Show(this, strError); }