private void _chipDialog_RefreshTriggerd(object sender, EventArgs e) { ChipDialog dialog = (ChipDialog)sender; Reload(dialog, true); #if NO LogicChipItem chip = dialog.LogicChipItem; ItemInfo item_info = FindItemInfo(chip, out ListViewItem item); if (item_info == null) { this.ShowMessage("cant find item_info", "red", true); _chipDialog.ShowMessage("cant find item_info", "red", true); return; } string uid = Element.GetHexString(item_info.OldInfo.uid); if (LoadChipData(uid, item) == true) { this.ShowMessage("重新装载成功", "green", true); _chipDialog.ShowMessage("重新装载成功", "green", true); } else { this.ShowMessage("重新装载失败", "red", true); _chipDialog.ShowMessage("重新装载失败", "red", true); } #endif }
void GetTagInfo(ListViewItem item) { ItemInfo item_info = (ItemInfo)item.Tag; OneTag tag = item_info.OneTag; RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out string strError); if (channel == null) { strError = "StartRfidChannel() error"; goto ERROR1; } try { GetTagInfoResult result = channel.Object.GetTagInfo("*", tag.UID); if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } tag.TagInfo = result.TagInfo; string hex_string = Element.GetHexString(result.TagInfo.Bytes, "4"); item_info.LogicChipItem = LogicChipItem.FromTagInfo(result.TagInfo); item_info.LogicChipItem.PropertyChanged += LogicChipItem_PropertyChanged; this.Invoke((Action)(() => { string pii = item_info.LogicChipItem.PrimaryItemIdentifier; // .FindElement(ElementOID.PII)?.Text; ListViewUtil.ChangeItemText(item, COLUMN_PII, pii); if (this.SelectedPII != null && pii == this.SelectedPII) { item.Font = new Font(item.Font, FontStyle.Bold); } })); return; } catch (Exception ex) { strError = "ListTags() 出现异常: " + ex.Message; goto ERROR1; } finally { EndRfidChannel(channel); } ERROR1: this.Invoke((Action)(() => { ListViewUtil.ChangeItemText(item, COLUMN_PII, "error:" + strError); // 把 item 修改为红色背景,表示出错的状态 SetItemColor(item, "error"); })); }
// 把新旧芯片内容合并。即,新芯片中不应修改旧芯片中已经锁定的元素 public static int Merge(LogicChipItem old_chip, LogicChipItem new_chip, out string strError) { strError = ""; // 首先检查 typeOfUsage 是否为 8X if (old_chip.IsBlank() == false && IsPatronUsage(old_chip) == false) { strError = "当前 RFID 标签是图书类型,不是读者卡类型。请小心不要弄混这两种类型"; return(-1); } List <string> errors = new List <string>(); // 检查一遍 foreach (Element element in old_chip.Elements) { if (element.Locked == false) { continue; } Element new_element = new_chip.FindElement(element.OID); if (new_element != null) { if (new_element.Text != element.Text) { errors.Add($"当前读者卡中元素 {element.OID} 已经被锁定,无法进行内容合并(从 '{element.Text}' 修改为 '{new_element.Text}')。"); } } } if (errors.Count > 0) { strError = StringUtil.MakePathList(errors, ";"); strError += "\r\n\r\n强烈建议废弃此读者卡,启用一个新(空白)读者卡"; return(-1); } foreach (Element element in old_chip.Elements) { if (element.Locked == false) { continue; } Element new_element = new_chip.FindElement(element.OID); if (new_element != null) { // 修改新元素 int index = new_chip.Elements.IndexOf(new_element); Debug.Assert(index != -1); new_chip.Elements.RemoveAt(index); new_chip.Elements.Insert(index, element.Clone()); } } return(0); }
// 根据 BookItem 对象构造一个 LogicChipItem 对象 public static LogicChipItem BuildChip(ReaderEditControl patron, string library_code, out string strWarning) { strWarning = ""; if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "3.11") < 0) { throw new Exception("当前连接的 dp2library 必须为 3.11 或以上版本,才能使用 RFID 有关功能"); } LogicChipItem result = new LogicChipItem(); result.AFI = LogicChipItem.DefaultPatronAFI; result.DSFID = LogicChipItem.DefaultDSFID; result.EAS = LogicChipItem.DefaultPatronEAS; // barcode --> PII result.NewElement(ElementOID.PII, patron.Barcode); // location --> OwnerInstitution 要配置映射关系 // 定义一系列前缀对应的 ISIL 编码。如果 location 和前缀前方一致比对成功,则得到 ISIL 编码 var ret = MainForm.GetOwnerInstitution( Program.MainForm.RfidCfgDom, library_code + "/", // 2020/7/17 增加 "/" out string isil, out string alternative); if (string.IsNullOrEmpty(isil) == false) { result.NewElement(ElementOID.OwnerInstitution, isil); } else if (string.IsNullOrEmpty(alternative) == false) { result.NewElement(ElementOID.AlternativeOwnerInstitution, alternative); } else { strWarning = $"当前 library.xml 中没有为馆代码 '{library_code}' 配置机构代码,这样创建的(没有包含机构代码的) 读者卡容易和其他机构的发生混淆"; } // TypeOfUsage? // (十六进制两位数字) { string typeOfUsage = "80"; result.NewElement(ElementOID.TypeOfUsage, typeOfUsage); } // TODO: 验证码,用扩展元素 return(result); }
// 把新旧芯片内容合并。即,新芯片中不应修改旧芯片中已经锁定的元素 public static int Merge(LogicChipItem old_chip, LogicChipItem new_chip, out string strError) { strError = ""; List <string> errors = new List <string>(); // 检查一遍 foreach (Element element in old_chip.Elements) { if (element.Locked == false) { continue; } Element new_element = new_chip.FindElement(element.OID); if (new_element != null) { if (new_element.Text != element.Text) { errors.Add($"当前标签中元素 {element.OID} 已经被锁定,无法进行内容合并(从 '{element.Text}' 修改为 '{new_element.Text}')。"); } } } if (errors.Count > 0) { strError = StringUtil.MakePathList(errors, ";"); strError += "\r\n\r\n强烈建议从图书上撕掉和废弃此标签,然后重新贴一个空白标签才能进行写入"; return(-1); } foreach (Element element in old_chip.Elements) { if (element.Locked == false) { continue; } Element new_element = new_chip.FindElement(element.OID); if (new_element != null) { // 修改新元素 int index = new_chip.Elements.IndexOf(new_element); Debug.Assert(index != -1); new_chip.Elements.RemoveAt(index); new_chip.Elements.Insert(index, element.Clone()); } } return(0); }
int SaveNewChip(out string strError) { strError = ""; #if OLD_CODE RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } #endif try { TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); #if OLD_CODE NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); #else NormalResult result = RfidManager.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); TagList.ClearTagTable(_tagExisting.UID); #endif if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { #if OLD_CODE EndRfidChannel(channel); #endif } }
static bool IsPatronUsage(LogicChipItem chip) { var typeOfUsage = chip.FindElement(ElementOID.TypeOfUsage); if (typeOfUsage == null || string.IsNullOrEmpty(typeOfUsage.Text)) { return(false); } if (typeOfUsage.Text.StartsWith("8")) { return(true); } return(false); }
int SaveNewChip(out string strError) { strError = ""; RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } try { #if NO TagInfo new_tag_info = _tagExisting.TagInfo.Clone(); new_tag_info.Bytes = this.chipEditor_editing.LogicChipItem.GetBytes( (int)(new_tag_info.MaxBlockCount * new_tag_info.BlockSize), (int)new_tag_info.BlockSize, LogicChip.GetBytesStyle.None, out string block_map); new_tag_info.LockStatus = block_map; #endif TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { EndRfidChannel(channel); } }
void Reload(ChipDialog dialog, bool show_message) { string strError = ""; string reader_name = GetCurrentReaderName(); if (string.IsNullOrEmpty(reader_name)) { strError = "尚未选定当前读卡器"; goto ERROR1; } LogicChipItem chip = dialog.LogicChipItem; ItemInfo item_info = FindItemInfo(chip, out ListViewItem item); if (item_info == null) { if (show_message) { strError = "cant find item_info"; goto ERROR1; } return; } string uid = item_info.OldInfo.UID; if (LoadChipData(uid, item) == true) { if (show_message) { this.ShowMessage("重新装载成功", "green", true); _chipDialog.ShowMessage("重新装载成功", "green", true); } } else { if (show_message) { strError = "重新装载失败"; goto ERROR1; } } return; ERROR1: this.ShowMessage(strError, "red", true); _chipDialog.ShowMessage(strError, "red", true); }
// 装载芯片数据 bool LoadChipData(string uid, ListViewItem item) { InventoryInfo info = new InventoryInfo { UID = uid, }; GetTagInfoResult result = _driver.GetTagInfo(GetCurrentReaderName(), info); if (result.Value == -1) { this.Invoke((Action)(() => { SetItemColor(item, "error"); ListViewUtil.ChangeItemText(item, 1, $"error:{result.ErrorInfo},error_code:{result.ErrorCode}"); })); return(false); } // 刷新 item 行 ItemInfo tag_info = new ItemInfo { OldInfo = result.TagInfo, LogicChip = LogicChipItem.FromTagInfo(result.TagInfo) }; item.Tag = tag_info; tag_info.LogicChip.DSFID = tag_info.OldInfo.DSFID; tag_info.LogicChip.AFI = tag_info.OldInfo.AFI; tag_info.LogicChip.EAS = tag_info.OldInfo.EAS; tag_info.LogicChip.PropertyChanged += LogicChip_PropertyChanged; string pii = tag_info.LogicChip.FindElement(ElementOID.PII)?.Text; this.Invoke((Action)(() => { ListViewUtil.ChangeItemText(item, 1, pii); ListViewUtil.ChangeItemText(item, 0, uid); SetItemColor(item, "normal"); })); // 如果当前打开的 ChipDialog 正好是这个 UID,则更新它 this.Invoke((Action)(() => { SetChipDialogContent(item, uid); })); return(true); }
static TagInfo BuildNewTagInfo(TagInfo old_tag_info, LogicChipItem chip) { TagInfo new_tag_info = old_tag_info.Clone(); new_tag_info.Bytes = chip.GetBytes( (int)new_tag_info.MaxBlockCount * (int)new_tag_info.BlockSize, (int)new_tag_info.BlockSize, LogicChip.GetBytesStyle.None, out string block_map); new_tag_info.LockStatus = block_map; new_tag_info.DSFID = chip.DSFID; new_tag_info.AFI = chip.AFI; new_tag_info.EAS = chip.EAS; return(new_tag_info); }
// TODO: 如何显示保存成功?注意 ChipDialog 可能会遮挡后面显示的文字 private void _chipDialog_SaveTriggerd(object sender, EventArgs e) { string strError = ""; string reader_name = GetCurrentReaderName(); if (string.IsNullOrEmpty(reader_name)) { strError = "尚未选定当前读卡器"; goto ERROR1; } ChipDialog dialog = (ChipDialog)sender; LogicChipItem chip = dialog.LogicChipItem; ItemInfo item_info = FindItemInfo(chip, out ListViewItem item); if (item_info == null) { strError = "cant find item_info"; goto ERROR1; } TagInfo new_tag_info = BuildNewTagInfo( item_info.OldInfo, chip); NormalResult result = _driver.WriteTagInfo(GetCurrentReaderName(), item_info.OldInfo, new_tag_info); if (result.Value == 0) { this.ShowMessage("保存成功", "green", true); _chipDialog.ShowMessage("保存成功", "green", true); Reload(dialog, false); } else { strError = $"保存失败:{result.ErrorInfo}"; goto ERROR1; } return; ERROR1: this.ShowMessage(strError, "red", true); _chipDialog.ShowMessage(strError, "red", true); }
void UpdateChanged(LogicChipItem chip) { this.Invoke((Action)(() => { foreach (ListViewItem item in this.listView_tags.Items) { ItemInfo tag_info = (ItemInfo)item.Tag; if (tag_info.LogicChipItem == chip) { #if NO // 更新 column 0 string uid = ListViewUtil.GetItemText(item, 0); if (uid.StartsWith("*")) { uid = uid.Substring(1); } if (tag_info.LogicChip.Changed) { uid = "*" + uid; } ListViewUtil.ChangeItemText(item, 0, uid); #endif if (tag_info.LogicChipItem.Changed) { item.BackColor = Color.DarkGreen; item.ForeColor = Color.White; } else { item.BackColor = this.listView_tags.BackColor; item.ForeColor = this.listView_tags.ForeColor; } // 更新 PII string pii = tag_info.LogicChipItem.FindElement(ElementOID.PII)?.Text; // ListViewUtil.ChangeItemText(item, COLUMN_PII, pii); SetItemPIIColumn(item, pii); return; } } })); }
ItemInfo FindItemInfo(LogicChipItem chip, out ListViewItem output_item) { ListViewItem temp = null; var result = (ItemInfo)this.Invoke((Func <ItemInfo>)(() => { foreach (ListViewItem item in this.listView_chips.Items) { ItemInfo tag_info = (ItemInfo)item.Tag; if (tag_info.LogicChip == chip) { temp = item; return(tag_info); } } return(null); })); output_item = temp; return(result); }
int SaveNewChip(out string strError) { strError = ""; RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } try { TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { EndRfidChannel(channel); } }
void UpdateChanged(LogicChipItem chip) { this.Invoke((Action)(() => { foreach (ListViewItem item in this.listView_chips.Items) { ItemInfo tag_info = (ItemInfo)item.Tag; if (tag_info.LogicChip == chip) { // 更新 column 0 string uid = ListViewUtil.GetItemText(item, 0); if (uid.StartsWith("*")) { uid = uid.Substring(1); } if (tag_info.LogicChip.Changed) { uid = "*" + uid; } ListViewUtil.ChangeItemText(item, 0, uid); if (tag_info.LogicChip.Changed) { item.BackColor = SystemColors.Info; } else { item.BackColor = SystemColors.Control; } // 更新 column 1 string pii = tag_info.LogicChip.FindElement(ElementOID.PII)?.Text; ListViewUtil.ChangeItemText(item, 1, pii); return; } } })); }
// 装入以前的标签信息 // 如果读卡器上有多个标签,则出现对话框让从中选择一个。列表中和右侧 PII 相同的,优先被选定 // parameters: // strStyle 操作方式 // auto_close_dialog 是否要自动关闭选择对话框。条件是选中了 auto_select_pii 事项 // adjust_right 是否自动调整右侧元素。即,把左侧的锁定状态元素覆盖到右侧。调整前要询问。如果不同意调整,可以放弃,然后改为放一个空白标签并装载保存 // saving 是否为了保存而装载?如果是,有些提示要改变 // return: // -1 出错 // 0 放弃装载 // 1 成功装载 int LoadOldChip( string auto_select_pii, string strStyle, #if NO bool auto_close_dialog, bool adjust_right, #endif out string strError) { strError = ""; bool auto_close_dialog = StringUtil.IsInList("auto_close_dialog", strStyle); bool adjust_right = StringUtil.IsInList("adjust_right", strStyle); bool saving = StringUtil.IsInList("saving", strStyle); try { REDO: // 出现对话框让选择一个 // SelectTagDialog dialog = new SelectTagDialog(); RfidToolForm dialog = new RfidToolForm(); dialog.Text = "选择 RFID 标签"; dialog.OkCancelVisible = true; dialog.LayoutVertical = false; dialog.AutoCloseDialog = auto_close_dialog; dialog.SelectedPII = auto_select_pii; dialog.AutoSelectCondition = "auto_or_blankPII"; // 2019/1/30 Program.MainForm.AppInfo.LinkFormState(dialog, "selectTagDialog_formstate"); dialog.ShowDialog(this); if (dialog.DialogResult == DialogResult.Cancel) { strError = "放弃装载 RFID 标签内容"; return(0); } if (auto_close_dialog == false // && string.IsNullOrEmpty(auto_select_pii) == false && dialog.SelectedPII != auto_select_pii && string.IsNullOrEmpty(dialog.SelectedPII) == false ) { string message = $"您所选择的标签其 PII 为 '{dialog.SelectedPII}',和期待的 '{auto_select_pii}' 不吻合。请小心检查是否正确。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 标签;\r\n[否]将这一种不吻合的 RFID 标签装载进来\r\n[取消]放弃装载"; if (saving) { message = $"您所选择的标签其 PII 为 '{dialog.SelectedPII}',和期待的 '{auto_select_pii}' 不吻合。请小心检查是否正确。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 标签;\r\n[否]将信息覆盖保存到这一种不吻合的 RFID 标签中(危险)\r\n[取消]放弃保存"; } DialogResult temp_result = MessageBox.Show(this, message, "EntityEditForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Yes) { goto REDO; } if (temp_result == DialogResult.Cancel) { strError = "放弃装载 RFID 标签内容"; return(0); } if (saving == false) { MessageBox.Show(this, "警告:您刚装入了一个可疑的标签,极有可能不是当前册对应的标签。待会儿保存标签内容的时候,有可能会张冠李戴覆盖了它。保存标签内容前,请务必反复仔细检查"); } } var tag_info = dialog.SelectedTag.TagInfo; _tagExisting = dialog.SelectedTag; var chip = LogicChipItem.FromTagInfo(tag_info); this.chipEditor_existing.LogicChipItem = chip; if (adjust_right) { int nRet = Merge(this.chipEditor_existing.LogicChipItem, this.chipEditor_editing.LogicChipItem, out strError); if (nRet == -1) { return(-1); } // 让右侧编辑器感受到 readonly 和 text 的变化 var save = this.chipEditor_editing.LogicChipItem; this.chipEditor_editing.LogicChipItem = null; this.chipEditor_editing.LogicChipItem = save; } return(1); } catch (Exception ex) { strError = "出现异常: " + ex.Message; return(-1); } }
int SaveNewChip(out string strError) { strError = ""; #if OLD_CODE RfidChannel channel = StartRfidChannel( Program.MainForm.RfidCenterUrl, out strError); if (channel == null) { strError = "StartRfidChannel() error"; return(-1); } #endif try { #if NO TagInfo new_tag_info = _tagExisting.TagInfo.Clone(); new_tag_info.Bytes = this.chipEditor_editing.LogicChipItem.GetBytes( (int)(new_tag_info.MaxBlockCount * new_tag_info.BlockSize), (int)new_tag_info.BlockSize, LogicChip.GetBytesStyle.None, out string block_map); new_tag_info.LockStatus = block_map; #endif Debug.Assert(_tagExisting != null, ""); Debug.WriteLine("333 " + (_tagExisting.TagInfo != null ? "!=null" : "==null")); Debug.Assert(_tagExisting.TagInfo != null, ""); TagInfo new_tag_info = LogicChipItem.ToTagInfo( _tagExisting.TagInfo, this.chipEditor_editing.LogicChipItem); #if OLD_CODE NormalResult result = channel.Object.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); #else Debug.Assert(_tagExisting != null, ""); Debug.WriteLine("111 " + (_tagExisting.TagInfo != null ? "!=null" : "==null")); Debug.Assert(_tagExisting.TagInfo != null, ""); // 2019/9/30 Debug.Assert(_tagExisting.AntennaID == _tagExisting.TagInfo.AntennaID, $"2 _tagExisting.AntennaID({_tagExisting.AntennaID}) 应该 == _tagExisting.TagInfo.AntennaID({_tagExisting.TagInfo.AntennaID})"); NormalResult result = RfidManager.WriteTagInfo( _tagExisting.ReaderName, _tagExisting.TagInfo, new_tag_info); TagList.ClearTagTable(_tagExisting.UID); #endif if (result.Value == -1) { strError = result.ErrorInfo; return(-1); } return(0); } catch (Exception ex) { strError = "SaveNewChip() 出现异常: " + ex.Message; return(-1); } finally { #if OLD_CODE EndRfidChannel(channel); #endif } }
// 装入以前的标签信息 // 如果读卡器上有多个标签,则出现对话框让从中选择一个。列表中和右侧 PII 相同的,优先被选定 // parameters: // strStyle 操作方式 // auto_close_dialog 是否要自动关闭选择对话框。条件是选中了 auto_select_pii 事项 // adjust_right 是否自动调整右侧元素。即,把左侧的锁定状态元素覆盖到右侧。调整前要询问。如果不同意调整,可以放弃,然后改为放一个空白标签并装载保存 // saving 是否为了保存而装载?如果是,有些提示要改变 // return: // -1 出错 // 0 放弃装载 // 1 成功装载 int LoadOldChip( string auto_select_pii, string strStyle, out string strError) { strError = ""; bool auto_close_dialog = StringUtil.IsInList("auto_close_dialog", strStyle); bool adjust_right = StringUtil.IsInList("adjust_right", strStyle); bool saving = StringUtil.IsInList("saving", strStyle); try { REDO: // 出现对话框让选择一个 // SelectTagDialog dialog = new SelectTagDialog(); using (RfidToolForm dialog = new RfidToolForm()) { dialog.Text = "选择 RFID 读者卡"; dialog.OkCancelVisible = true; dialog.LayoutVertical = false; dialog.AutoCloseDialog = auto_close_dialog; dialog.SelectedPII = auto_select_pii; dialog.AutoSelectCondition = "auto_or_blankPII"; // 2019/1/30 dialog.ProtocolFilter = InventoryInfo.ISO15693; Program.MainForm.AppInfo.LinkFormState(dialog, "selectTagDialog_formstate"); dialog.ShowDialog(this); if (dialog.DialogResult == DialogResult.Cancel) { strError = "放弃装载 RFID 读者卡内容"; return(0); } { var old_chip = LogicChipItem.FromTagInfo(dialog.SelectedTag.TagInfo); // 首先检查 typeOfUsage 是否为 8X if (old_chip.IsBlank() == false && IsPatronUsage(old_chip) == false) { strError = "当前 RFID 标签是图书类型,不是读者卡类型。请小心不要弄混这两种类型"; string message = $"您所选择的 RFID 标签是图书类型,不是读者卡类型。请小心不要弄混这两种类型。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 读者卡;\r\n[否]将这一种不吻合的 RFID 标签装载进来\r\n[取消]放弃装载"; if (saving) { message = $"您所选择的 RFID 标签是图书类型,不是读者卡类型。请小心不要弄混这两种类型。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 读者卡;\r\n[否]将信息覆盖保存到这一种不吻合的 RFID 标签中(危险)\r\n[取消]放弃保存"; } DialogResult temp_result = MessageBox.Show(this, message, "RfidPatronCardDialog", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Yes) { goto REDO; } if (temp_result == DialogResult.Cancel) { strError = "放弃装载 RFID 读者卡内容"; return(0); } if (saving == false) { MessageBox.Show(this, "警告:您刚装入了一个可疑的读者卡,极有可能不是读者卡而是图书 RFID 标签。待会儿保存读者卡内容的时候,有可能会张冠李戴覆盖了它。保存读者卡内容前,请务必反复仔细检查"); } } } if (auto_close_dialog == false // && string.IsNullOrEmpty(auto_select_pii) == false && dialog.SelectedPII != auto_select_pii && string.IsNullOrEmpty(dialog.SelectedPII) == false ) { string message = $"您所选择的读者卡其 PII 为 '{dialog.SelectedPII}',和期待的 '{auto_select_pii}' 不吻合。请小心检查是否正确。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 读者卡;\r\n[否]将这一种不吻合的 RFID 读者卡装载进来\r\n[取消]放弃装载"; if (saving) { message = $"您所选择的读者卡其 PII 为 '{dialog.SelectedPII}',和期待的 '{auto_select_pii}' 不吻合。请小心检查是否正确。\r\n\r\n是否重新选择?\r\n\r\n[是]重新选择 RFID 读者卡;\r\n[否]将信息覆盖保存到这一种不吻合的 RFID 读者卡中(危险)\r\n[取消]放弃保存"; } DialogResult temp_result = MessageBox.Show(this, message, "RfidPatronCardDialog", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Yes) { goto REDO; } if (temp_result == DialogResult.Cancel) { strError = "放弃装载 RFID 读者卡内容"; return(0); } if (saving == false) { MessageBox.Show(this, "警告:您刚装入了一个可疑的读者卡,极有可能不是当前读者记录对应的读者卡。待会儿保存读者卡内容的时候,有可能会张冠李戴覆盖了它。保存读者卡内容前,请务必反复仔细检查"); } } var tag_info = dialog.SelectedTag.TagInfo; _tagExisting = dialog.SelectedTag; var chip = LogicChipItem.FromTagInfo(tag_info); this.chipEditor_existing.LogicChipItem = chip; if (adjust_right) { int nRet = Merge(this.chipEditor_existing.LogicChipItem, this.chipEditor_editing.LogicChipItem, out strError); if (nRet == -1) { return(-1); } // 让右侧编辑器感受到 readonly 和 text 的变化 var save = this.chipEditor_editing.LogicChipItem; this.chipEditor_editing.LogicChipItem = null; this.chipEditor_editing.LogicChipItem = save; } return(1); } } catch (Exception ex) { strError = "出现异常: " + ex.Message; return(-1); } }
private void toolStripButton_saveRfid_Click(object sender, EventArgs e) { // 写入以前,装载标签内容到左侧,然后调整右侧(中间可能会警告)。然后再保存 string strError = ""; string pii = this._barcode; // 从修改前的 // 看左侧是否装载过。如果没有装载过则自动装载 if (_leftLoaded == false) { // return: // -1 出错 // 0 放弃装载 // 1 成功装载 int nRet = LoadOldChip(pii, "adjust_right,saving", out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "已放弃保存 RFID 读者卡内容"; goto ERROR1; } } // 然后保存 { int nRet = SaveNewChip(out strError); if (nRet == -1) { goto ERROR1; } } MessageBox.Show(this, "保存成功"); // 刷新左侧显示 { // 用保存后的确定了的 UID 重新装载 int nRet = LoadChipByUID( _tagExisting.ReaderName, _tagExisting.TagInfo.UID, out TagInfo tag_info, out strError); if (nRet == -1) { _leftLoaded = false; strError = "保存 RFID 读者卡内容已经成功。但刷新左侧显示时候出错: " + strError; goto ERROR1; } _tagExisting.TagInfo = tag_info; var chip = LogicChipItem.FromTagInfo(tag_info); this.chipEditor_existing.LogicChipItem = chip; } return; ERROR1: MessageBox.Show(this, strError); }
// 写入右侧的信息到标签 private void toolStripButton_saveRfid_Click(object sender, EventArgs e) { { BookItem item = this.Item.Clone(); item.RecordDom = this._editing.DataDom; EnsureCreateAccessNo(item); } // 写入以前,装载标签内容到左侧,然后调整右侧(中间可能会警告)。然后再保存 string strError = ""; // string pii = this.chipEditor_editing.LogicChipItem.FindElement(ElementOID.PII).Text; string pii = GetPII(this.Item.OldRecord); // 从修改前的册记录中获得册条码号 // 看左侧是否装载过。如果没有装载过则自动装载 if (_leftLoaded == false) { // return: // -1 出错 // 0 放弃装载 // 1 成功装载 int nRet = LoadOldChip(pii, "adjust_right,saving", // false, true, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "已放弃保存 RFID 标签内容"; goto ERROR1; } } // 然后保存 { int nRet = SaveNewChip(out strError); if (nRet == -1) { goto ERROR1; } } // TODO: 改成类似 ShowMessage() 效果 MessageBox.Show(this, "保存成功"); // 刷新左侧显示 { Debug.Assert(_tagExisting != null, ""); Debug.WriteLine("222 " + (_tagExisting.TagInfo != null ? "!=null" : "==null")); Debug.Assert(_tagExisting.TagInfo != null, ""); // 2019/9/30 Debug.Assert(_tagExisting.AntennaID == _tagExisting.TagInfo.AntennaID, $"1 _tagExisting.AntennaID({_tagExisting.AntennaID}) 应该 == _tagExisting.TagInfo.AntennaID({_tagExisting.TagInfo.AntennaID})"); // 用保存后的确定了的 UID 重新装载 int nRet = LoadChipByUID( _tagExisting.ReaderName, _tagExisting.TagInfo.UID, _tagExisting.AntennaID, out TagInfo tag_info, out strError); if (nRet == -1) { _leftLoaded = false; strError = "保存 RFID 标签内容已经成功。但刷新左侧显示时候出错: " + strError; goto ERROR1; } Debug.Assert(tag_info != null, ""); _tagExisting.TagInfo = tag_info; _tagExisting.AntennaID = tag_info.AntennaID; // 2019/9/30 Debug.WriteLine("set taginfo"); var chip = LogicChipItem.FromTagInfo(tag_info); this.chipEditor_existing.LogicChipItem = chip; #if NO string new_pii = this.chipEditor_editing.LogicChipItem.FindElement(ElementOID.PII)?.Text; // return: // -1 出错 // 0 放弃装载 // 1 成功装载 int nRet = LoadOldChip(new_pii, "auto_close_dialog", // true, false, out strError); if (nRet != 1) { // this.chipEditor_existing.LogicChipItem = null; _leftLoaded = false; strError = "保存 RFID 标签内容已经成功。但刷新左侧显示时候出错: " + strError; goto ERROR1; } #endif } return; ERROR1: MessageBox.Show(this, strError); }
// 根据 BookItem 对象构造一个 LogicChipItem 对象 public static LogicChipItem BuildChip(BookItem book_item) { if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "3.11") < 0) { throw new Exception("当前连接的 dp2library 必须为 3.11 或以上版本,才能使用 RFID 有关功能"); } LogicChipItem result = new LogicChipItem(); result.AFI = LogicChipItem.DefaultBookAFI; result.DSFID = LogicChipItem.DefaultDSFID; result.EAS = LogicChipItem.DefaultBookEAS; // barcode --> PII result.NewElement(ElementOID.PII, book_item.Barcode); // location --> OwnerInstitution 要配置映射关系 // 定义一系列前缀对应的 ISIL 编码。如果 location 和前缀前方一致比对成功,则得到 ISIL 编码 MainForm.GetOwnerInstitution( Program.MainForm.RfidCfgDom, StringUtil.GetPureLocation(book_item.Location), out string isil, out string alternative); if (string.IsNullOrEmpty(isil) == false) { result.NewElement(ElementOID.OwnerInstitution, isil); } else if (string.IsNullOrEmpty(alternative) == false) { result.NewElement(ElementOID.AlternativeOwnerInstitution, alternative); } // SetInformation? // 可以考虑用 volume 元素映射过来。假设 volume 元素内容符合 (xx,xx) 格式 string value = MainForm.GetSetInformation(book_item.Volume); if (value != null) { result.NewElement(ElementOID.SetInformation, value); } // TypeOfUsage? // (十六进制两位数字) // 10 一般流通馆藏 // 20 非流通馆藏。保存本库? 加工中? // 70 被剔旧的馆藏。和 state 元素应该有某种对应关系,比如“注销” { string typeOfUsage = ""; if (StringUtil.IsInList("注销", book_item.State) == true || StringUtil.IsInList("丢失", book_item.State) == true) { typeOfUsage = "70"; } else if (string.IsNullOrEmpty(book_item.State) == false && StringUtil.IsInList("加工中", book_item.State) == true) { typeOfUsage = "20"; } else { typeOfUsage = "10"; } result.NewElement(ElementOID.TypeOfUsage, typeOfUsage); } // AccessNo --> ShelfLocation // 注意去掉 {ns} 部分 result.NewElement(ElementOID.ShelfLocation, StringUtil.GetPlainTextCallNumber(book_item.AccessNo) ); return(result); }