async Task <NormalResult> Update( BaseChannel <IRfid> channel_param, List <Entity> update_entities, CancellationToken token) { if (update_entities.Count > 0) { try { BaseChannel <IRfid> channel = channel_param; if (channel == null) { channel = RfidManager.GetChannel(); } try { await FillBookFields(channel, update_entities, token); } finally { if (channel_param == null) { RfidManager.ReturnChannel(channel); } } } catch (Exception ex) { string error = $"填充图书信息时出现异常: {ex.Message}"; SetGlobalError("rfid", error); return(new NormalResult { Value = -1, ErrorInfo = error }); } // 自动检查 EAS 状态 // CheckEAS(update_entities); } return(new NormalResult()); }
// 填充读者信息的其他字段(第二阶段) async Task <NormalResult> FillPatronDetail(bool force = false) { // 已经填充过了 if (_patron.PatronName != null && force == false) { return(new NormalResult()); } string pii = _patron.PII; if (string.IsNullOrEmpty(pii)) { pii = _patron.UID; } if (string.IsNullOrEmpty(pii)) { return(new NormalResult()); } // return.Value: // -1 出错 // 0 读者记录没有找到 // 1 成功 GetReaderInfoResult result = await Task <GetReaderInfoResult> .Run(() => { return(GetReaderInfo(pii)); }); if (result.Value != 1) { string error = $"读者 '{pii}': {result.ErrorInfo}"; SetPatronError("getreaderinfo", error); return(new NormalResult { Value = -1, ErrorInfo = error }); } SetPatronError("getreaderinfo", ""); if (string.IsNullOrEmpty(_patron.State) == true) { OpenDoor(); } if (force) { _patron.PhotoPath = ""; } // string old_photopath = _patron.PhotoPath; Application.Current.Dispatcher.Invoke(new Action(() => { _patron.SetPatronXml(result.RecPath, result.ReaderXml, result.Timestamp); this.patronControl.SetBorrowed(result.ReaderXml); })); // 显示在借图书列表 List <Entity> entities = new List <Entity>(); foreach (Entity entity in this.patronControl.BorrowedEntities) { entities.Add(entity); } if (entities.Count > 0) { try { BaseChannel <IRfid> channel = RfidManager.GetChannel(); try { await FillBookFields(channel, entities, new CancellationToken()); } finally { RfidManager.ReturnChannel(channel); } } catch (Exception ex) { string error = $"填充读者信息时出现异常: {ex.Message}"; SetGlobalError("rfid", error); return(new NormalResult { Value = -1, ErrorInfo = error }); } } #if NO // 装载图象 if (old_photopath != _patron.PhotoPath) { Task.Run(() => { LoadPhoto(_patron.PhotoPath); }); } #endif return(new NormalResult()); }