Пример #1
0
        public static NormalResult DeleteLocalPatronRecord(string strXml)
        {
            using (BiblioCacheContext context = new BiblioCacheContext())
            {
                if (_cacheDbCreated == false)
                {
                    context.Database.EnsureCreated();
                    _cacheDbCreated = true;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strXml);
                }
                catch (Exception ex)
                {
                    return(new NormalResult
                    {
                        Value = -1,
                        ErrorInfo = $"读者记录装载进入 XMLDOM 时出错:{ex.Message}",
                        ErrorCode = "loadXmlError"
                    });
                }

                /*
                 * string pii = DomUtil.GetElementText(dom.DocumentElement, "barcode");
                 * if (string.IsNullOrEmpty(pii))
                 *  pii = "@refID:" + DomUtil.GetElementText(dom.DocumentElement, "refID");
                 */
                string pii    = GetPii(dom);
                var    patron = context.Patrons
                                .Where(o => o.PII == pii)
                                .FirstOrDefault();
                if (patron != null)
                {
                    context.Patrons.Remove(patron);
                    context.SaveChanges();
                }

                return(new NormalResult {
                    Value = 0
                });
            }
        }
Пример #2
0
        // 把读者记录保存(更新)到本地数据库
        // result.Value
        //      -1  出错
        //      0   没有发生修改
        //      1   发生了创建或者修改
        public static NormalResult UpdateLocalPatronRecord(
            GetReaderInfoResult get_result,
            DateTime lastWriteTime)
        {
            using (BiblioCacheContext context = new BiblioCacheContext())
            {
                if (_cacheDbCreated == false)
                {
                    context.Database.EnsureCreated();
                    _cacheDbCreated = true;
                }

                XmlDocument dom = new XmlDocument();

                try
                {
                    dom.LoadXml(get_result.ReaderXml);
                }
                catch (Exception ex)
                {
                    return(new NormalResult
                    {
                        Value = -1,
                        ErrorInfo = $"读者记录装载进入 XMLDOM 时出错:{ex.Message}",
                        ErrorCode = "loadXmlError"
                    });
                }

                /*
                 * string pii = DomUtil.GetElementText(dom.DocumentElement, "barcode");
                 * if (string.IsNullOrEmpty(pii))
                 *  pii = "@refID:" + DomUtil.GetElementText(dom.DocumentElement, "refID");
                 */
                string pii    = GetPii(dom);
                var    patron = context.Patrons
                                .Where(o => o.PII == pii)
                                .FirstOrDefault();
                if (patron != null)
                {
                    // 如果已经存在的读者记录比打算写入的要新,则放弃写入
                    if (patron.LastWriteTime > lastWriteTime)
                    {
                        return new NormalResult {
                                   Value = 0
                        }
                    }
                    ;
                    Set(patron, dom);
                    context.Patrons.Update(patron);
                }
                else
                {
                    patron = new PatronItem
                    {
                        PII = pii?.ToUpper(),
                    };
                    Set(patron, dom);
                    context.Patrons.Add(patron);
                }

                context.SaveChanges();
                return(new NormalResult {
                    Value = 1
                });
            }

            void Set(PatronItem patron, XmlDocument dom)
            {
                string cardNumber = DomUtil.GetElementText(dom.DocumentElement, "cardNumber");

                cardNumber = cardNumber.ToUpper();
                if (string.IsNullOrEmpty(cardNumber) == false)
                {
                    cardNumber = "," + cardNumber + ",";
                }

                if (get_result.RecPath != null)
                {
                    patron.RecPath = get_result.RecPath;
                }
                patron.Bindings      = cardNumber;
                patron.Xml           = get_result.ReaderXml;
                patron.Timestamp     = get_result.Timestamp;
                patron.LastWriteTime = lastWriteTime;
            }
        }