Exemple #1
0
        // 把新旧芯片内容合并。即,新芯片中不应修改旧芯片中已经锁定的元素
        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);
        }
Exemple #2
0
        // 把新旧芯片内容合并。即,新芯片中不应修改旧芯片中已经锁定的元素
        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);
        }
Exemple #3
0
        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);
        }