Esempio n. 1
0
        /// <summary>
        /// 新增一个图书馆
        /// </summary>
        /// <param name="entity"></param>
        public void AddLib(LibEntity entity)
        {
            // 到期的图书馆不加入到内存集合中
            if (entity != null && entity.state == "到期")
            {
                return;
            }

            Library library = new Library();

            library.Entity = entity;

            //// 获取绑定的读者数量
            //List<WxUserItem> patrons = WxUserDatabase.Current.GetPatron("", entity.id, "");
            //library.PatronCount = patrons.Count;

            //// 获取绑定的工作人员数量
            //List<WxUserItem> workers = WxUserDatabase.Current.Get("", entity.id, WxUserDatabase.C_Type_Worker);
            //library.WorkerCount = workers.Count;

            // 获取版本号
            string version = this.GetVersion(entity);

            library.SetVersion(entity, version);


            // 加到内存中
            this.Librarys.Add(library);
        }
Esempio n. 2
0
        public void SaveLib(LibEntity entity)
        {
            // 先将已经对应的删除
            DelLib(entity.id, entity.libName);


            // 先查一下有没有对应的地区
            Area area = this.GetArea(entity.area);

            if (area == null)
            {
                area      = new Area();
                area.name = entity.area;
                this.areas.Add(area);
            }

            libModel lib = area.GetLib(entity.id, entity.libName);

            if (lib == null)
            {
                lib       = new libModel();
                lib.libId = entity.id;
                lib.name  = entity.libName;
                area.libs.Add(lib);

                this.Save2Xml();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 新增一个图书馆
        /// </summary>
        /// <param name="entity"></param>
        public void AddLib(LibEntity entity)
        {
            int    nRet     = 0;
            string strError = "";

            // 到期的图书馆不加入到内存集合中
            if (entity != null &&
                entity.state == dp2WeiXinService.C_State_Expire)
            {
                return;
            }

            Library library = new Library();

            library.Entity = entity;

            // 加到内存中
            this.Librarys.Add(library);

            // 检查版本号和是否连接成功
            this.CheckIsHangup(library);

            // 获取数据库
            if (library.IsHangup == false)
            {
                this.GetDbs(library);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 更新一个图书馆
        /// </summary>
        /// <param name="libId"></param>
        public void UpdateLib(string libId)
        {
            LibEntity entity = LibDatabase.Current.GetLibById1(libId);


            this.DeleteLib(libId);

            //LibEntity entity = LibDatabase.Current.GetLibById1(libId);
            this.AddLib(entity);
        }
Esempio n. 5
0
        public LibEntity Add(LibEntity item)
        {
            item.OperTime       = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            item.wxPasswordView = "*".PadRight(item.wxPassword.Length, '*');

            string encryptPassword = Cryptography.Encrypt(item.wxPassword, dp2WeiXinService.Instance.EncryptKey);

            item.wxPassword = encryptPassword;

            this.LibCollection.InsertOne(item);
            return(item);
        }
Esempio n. 6
0
        public LibEntity GetLibByName(string libName)
        {
            var filter = Builders <LibEntity> .Filter.Eq("libName", libName);

            List <LibEntity> list = this.LibCollection.Find(filter).ToList();

            if (list.Count > 0)
            {
                LibEntity item = list[0];
                return(item);
            }
            return(null);
        }
Esempio n. 7
0
        private string GetVersion(LibEntity lib)
        {
            string version = "";

            // 获取版本号
            string        strError = "";
            List <string> dataList = new List <string>();
            //int nRet = dp2WeiXinService.Instance.GetSystemParameter(lib,
            //    "system",
            //    "version",
            //    out dataList,
            //    out strError);

            //(较早的dp2Capo在上述功能被调用时会返回ErrorInfo=未知的 category '_clock' 和 name '',ErrorCode=NotFound)
            int nRet = dp2WeiXinService.Instance.GetSystemParameter(lib,
                                                                    "_capoVersion",
                                                                    "",
                                                                    out dataList,
                                                                    out strError);

            Thread.Sleep(500);//2016/11/9 延尽半秒

            if (nRet == -1)
            {
                // 设为-1,表示获取时出错,工作线程会自动重新获取
                version = "-1";

                // 记到日志里
                dp2WeiXinService.Instance.WriteErrorLog1("获取 " + lib.libName + " 版本出错:" + strError);
                return(version);
            }
            else if (nRet == 0)
            {
                // 未命中的情况,当空处理
                version = "";
            }
            else
            {
                version = dataList[0];
            }

            if (version == "")
            {
                version = "0.0";//dp2library 本身如果太旧,这个获得版本号的过程会返回空字符串,把空字符串当作 0.0 版看待即可。
            }
            return(version);
        }
Esempio n. 8
0
        // 更新
        public long Update(string id, LibEntity item)
        {
            item.OperTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

            if (String.IsNullOrEmpty(item.wxPassword) == false)
            {
                item.wxPasswordView = "*".PadRight(item.wxPassword.Length, '*');

                string encryptPassword = Cryptography.Encrypt(item.wxPassword, dp2WeiXinService.Instance.EncryptKey);
                item.wxPassword = encryptPassword;
            }

            var filter = Builders <LibEntity> .Filter.Eq("id", id);

            var update = Builders <LibEntity> .Update
                         //.Set("libCode", item.libCode)
                         .Set("libName", item.libName)
                         .Set("capoUserName", item.capoUserName)
                         .Set("capoContactPhone", item.capoContactPhone)
                         .Set("area", item.area)

                         .Set("wxUserName", item.wxUserName)
                         .Set("wxPassword", item.wxPassword)
                         .Set("wxPasswordView", item.wxPasswordView)
                         .Set("wxContactPhone", item.wxContactPhone)

                         .Set("comment", item.comment)
                         .Set("OperTime", item.OperTime)
                         .Set("noShareBiblio", item.noShareBiblio) //
                                                                   //.Set("verifyBarcode", item.verifyBarcode) //借还时校验条码 2016-11-16,20170419注释
                         .Set("searchDbs", item.searchDbs)
                         .Set("match", item.match)
                         .Set("state", item.state)
                         .Set("biblioFilter", item.biblioFilter)
                         .Set("ReserveScope", item.ReserveScope)
                         .Set("NoReserveLocation", item.NoReserveLocation)
                         .Set("IsSendArrivedNotice", item.IsSendArrivedNotice)
                         .Set("NoViewLocation", item.NoViewLocation)
                         //NoViewLocation 2020/3/25 不允许显示册记录的馆藏地
            ;

            UpdateResult ret = this.LibCollection.UpdateOneAsync(filter, update).Result;

            return(ret.ModifiedCount);
        }
Esempio n. 9
0
        public LibEntity GetLibByCapoUserName(string capoUserName)
        {
            var filter = Builders <LibEntity> .Filter.Eq("capoUserName", capoUserName);

            List <LibEntity> list = this.LibCollection.Find(filter).ToList();

            if (list.Count > 0)
            {
                LibEntity item = list[0];
                //解密
                if (String.IsNullOrEmpty(item.wxPassword) == false)
                {
                    item.wxPassword = Cryptography.Decrypt(item.wxPassword, dp2WeiXinService.Instance.EncryptKey);
                }

                return(item);
            }
            return(null);
        }
Esempio n. 10
0
        public void SetVersion(LibEntity libEntity, string version)
        {
            string strError = "";

            // 设置版本
            this._version = version;

            // 更新状态
            this.UpdateState();


            // 获取数据库信息
            if (this.State != LibraryManager.C_State_Hangup ||
                (this.State == LibraryManager.C_State_Hangup && this.Version != "-1"))
            {
                // 得到期库
                //用点对点的 getSystemParameter 功能。category 为 "system", name 为 "biblioDbGroup",
                //可以获得一段 XML 字符串,格式和 library.xml 中的 itemdbgroup 元素相仿,
                //但每个 database 元素的 name 属性名字变为 itemDbName。
                // item.IssueDbName = DomUtil.GetAttr(node, "issueDbName");
                List <string> dataList = new List <string>();
                //(较早的dp2Capo在上述功能被调用时会返回ErrorInfo=未知的 category '_clock' 和 name '',ErrorCode=NotFound)
                int nRet = dp2WeiXinService.Instance.GetSystemParameter(libEntity,
                                                                        "system",
                                                                        "biblioDbGroup",
                                                                        out dataList,
                                                                        out strError);
                if (nRet == -1 || nRet == 0)
                {
                    goto ERROR1;
                }

                // 取出数据库配置xml
                this.BiblioDbGroup = "<root>" + dataList[0] + "</root>";

                XmlDocument dom = new XmlDocument();
                dom.LoadXml(this.BiblioDbGroup);
                XmlNodeList databaseList = dom.DocumentElement.SelectNodes("database");
                foreach (XmlNode node in databaseList)
                {
                    DbCfg db = new DbCfg();

                    db.DbName         = DomUtil.GetAttr(node, "itemDbName");
                    db.BiblioDbName   = DomUtil.GetAttr(node, "biblioDbName");
                    db.BiblioDbSyntax = DomUtil.GetAttr(node, "syntax");
                    db.IssueDbName    = DomUtil.GetAttr(node, "issueDbName");

                    db.OrderDbName       = DomUtil.GetAttr(node, "orderDbName");
                    db.CommentDbName     = DomUtil.GetAttr(node, "commentDbName");
                    db.UnionCatalogStyle = DomUtil.GetAttr(node, "unionCatalogStyle");

                    // 2008/6/4
                    bool bValue = true;
                    nRet = DomUtil.GetBooleanParam(node,
                                                   "inCirculation",
                                                   true,
                                                   out bValue,
                                                   out strError);
                    if (nRet == -1)
                    {
                        throw new Exception("元素<//biblioDbGroup/database>属性inCirculation读入时发生错误: " + strError);
                    }
                    db.InCirculation = bValue;

                    db.Role = DomUtil.GetAttr(node, "role");

                    this.DbList.Add(db);
                }
            }

            return;

ERROR1:
            dp2WeiXinService.Instance.WriteErrorLog1("获取库信息出错:" + strError);
        }
Esempio n. 11
0
        public ChargeCommand AddCmd(//WxUserItem activeUser,
            string weixinId,
            string libId,
            string libraryCode,
            int needTransfrom,
            ChargeCommand cmd)
        {
            //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-1");

            Debug.Assert(cmd != null, "AddCmd传进的cmd不能为空。");
            Debug.Assert(String.IsNullOrEmpty(cmd.type) == false, "命令类型不能为空。");

            if (string.IsNullOrEmpty(libId) == true)
            {
                cmd.state     = -1;
                cmd.errorInfo = "libId参数不能为空";
                return(cmd);
            }

            //string libId = libId;//activeUser.libId;

            // 册list,用于ISBN借书
            cmd.itemList = new List <BiblioItem>();

            // 读者对象
            Patron patron = null;


            // 一般传进来只有3个值 type,patron,item
            cmd.patronBarcode = cmd.patronInput;
            cmd.itemBarcode   = cmd.itemInput;

            // 补充命令信息
            cmd.id                = this.Count + 1;
            cmd.operTime          = DateTimeUtil.DateTimeToString(DateTime.Now);
            cmd.resultInfoWavText = "";

            // 其它错误信息
            string otherError = "";

            // 书目名称
            string biblioName = "";

            // 输出真正的读者条码,有可能是传来的是姓名
            string outPatronBarcode = cmd.patronBarcode;

            // 读者xml
            string patronXml = "";
            // 读者路径
            string patronRecPath = "";
            // 获取读者记录的时间戳
            string timestamp = "";

            // 本函数返回信息
            ReturnInfo resultInfo = null;
            int        cmdRet     = -1;
            string     cmdError   = "";

            // 登录dp2身份
            //前端传来的userName有可能为null,这里兼职一下,防止报错
            if (cmd.userName == null)
            {
                cmd.userName = "";
            }
            LoginInfo loginInfo = new LoginInfo(cmd.userName,
                                                cmd.isPatron == 1?true:false);

            //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-2");

            #region 分馆的自动加前缀功能
            // 当是分馆时,检查是否需要自动加前缀,以及自动加前缀
            if (string.IsNullOrEmpty(libraryCode) == false && needTransfrom == 1) //20171029,当分馆,且明确指定的需要转换时前缀时再转换
            {
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-3");

                // 根据命令类型,判断转哪个条码
                string tempBarcode = "";
                if (cmd.type == ChargeCommand.C_Command_LoadPatron)
                {
                    tempBarcode = cmd.patronBarcode;
                }
                else
                {
                    tempBarcode = cmd.itemBarcode;
                }

                string resultBarcode = "";
                cmdRet = dp2WeiXinService.Instance.GetTransformBarcode(loginInfo,
                                                                       libId,
                                                                       libraryCode,
                                                                       tempBarcode,
                                                                       out resultBarcode,
                                                                       out cmdError);
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-31-[" + cmdError+"]");
                if (cmdRet == -1)
                {
                    //cmdError = cmdError.Replace("<script>", "");
                    goto END1;
                }
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-4");
                // 转换过的
                if (cmdRet == 1)
                {
                    if (cmd.type == ChargeCommand.C_Command_LoadPatron)
                    {
                        cmd.patronBarcode = resultBarcode;
                    }
                    else
                    {
                        cmd.itemBarcode = resultBarcode;
                    }
                }
            }
            #endregion

            #region 查询册的功能
            // 20170413 查询册
            if (cmd.type == ChargeCommand.C_Command_SearchItem)
            {
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-5");

                string    summary = "";
                string    recPath = "";
                LibEntity lib     = dp2WeiXinService.Instance.GetLibById(libId);
                int       nRet    = dp2WeiXinService.Instance.GetBiblioSummary(lib,
                                                                               cmd.itemBarcode,
                                                                               "",
                                                                               out summary,
                                                                               out recPath,
                                                                               out otherError);
                if (nRet == -1)
                {
                    //出错信息会加起来
                }
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-51");

                // 截图path
                int tempIndex = recPath.IndexOf("@");
                if (tempIndex > 0)
                {
                    recPath = recPath.Substring(0, tempIndex);
                }

                //if (string.IsNullOrEmpty(summary) == false)
                //{
                //    biblioName = dp2WeiXinService.Instance.GetShortSummary(summary);
                //}

                // 取item
                List <BiblioItem> itemList = null;
                nRet = (int)dp2WeiXinService.Instance.GetItemInfo(weixinId,
                                                                  lib,
                                                                  loginInfo,
                                                                  "",//patronBarcode
                                                                  recPath,
                                                                  cmd.type,
                                                                  out itemList,
                                                                  out cmdError);
                if (nRet == -1) //0的情况表示没有册,不是错误
                {
                    cmdError += " 传入的册条码号为[" + cmd.itemBarcode + "]";
                    cmdRet    = -1;
                }
                else if (nRet == 0)
                {
                    cmdError             = "未命中";
                    cmd.resultInfo       = cmdError;
                    cmd.simpleResultInfo = cmdError;
                    cmdRet = -1;
                }
                //dp2WeiXinService.Instance.WriteErrorLog1("AddCmd-6");


                BiblioItem item = null;
                foreach (BiblioItem one in itemList)
                {
                    if (one.barcode == cmd.itemBarcode)
                    {
                        item = one;
                        break;
                    }
                }

                if (item != null)
                {
                    cmd.resultInfo = summary
                                     + this.getItemHtml(item);

                    string shortSummary = dp2WeiXinService.Instance.GetShortSummary(summary);

                    cmd.simpleResultInfo = shortSummary
                                           + "<br>册条码:" + item.barcode + "&nbsp;&nbsp;馆藏地:" + item.location
                                           + "<br>索取号:" + item.accessNo + "&nbsp;&nbsp;价格:" + item.price;

                    // 成员册 不显示在借情况
                    if (String.IsNullOrEmpty(item.borrower) == false)
                    {
                        cmd.simpleResultInfo += "<br>借阅者:" + item.borrower;
                    }
                    if (String.IsNullOrEmpty(item.state) == false)
                    {
                        if (String.IsNullOrEmpty(item.borrowInfo) == false)
                        {
                            cmd.simpleResultInfo += "&nbsp;&nbsp;";
                        }
                        else
                        {
                            cmd.simpleResultInfo += "<br/>";
                        }
                        cmd.simpleResultInfo += "状态:" + item.state;
                    }



                    // 语音返回 书名
                    cmd.resultInfoWavText = shortSummary;
                    cmdRet = 0;
                }


                // 设返回值
                cmd.state      = cmdRet;
                cmd.errorInfo  = cmdError;
                cmd.typeString = cmd.getTypeString(cmd.type);
                goto END2;
            }

            #endregion

            #region 加载读者
            //加载读者
            if (cmd.type == ChargeCommand.C_Command_LoadPatron)
            {
                //dp2WeiXinService.Instance.WriteErrorLog1("走进-加载读者-1");

                cmdRet = dp2WeiXinService.Instance.GetPatronXml(libId,
                                                                loginInfo,
                                                                cmd.patronBarcode,
                                                                "advancexml",
                                                                out patronRecPath,
                                                                out timestamp,
                                                                out patronXml,
                                                                out cmdError);
                if (cmdRet == -1 || cmdRet == 0)  //未找到认为出错
                {
                    //dp2WeiXinService.Instance.WriteErrorLog1("走进-加载读者-2");
                    cmdError += ",传入的条码为[" + cmd.patronBarcode + "]";
                    cmdRet    = -1;
                }

                //dp2WeiXinService.Instance.WriteErrorLog1("走进-加载读者-3");
                goto END1;
            }

            #endregion


            #region 检查item是否为isbn

            //检查item是否为isbn
            string strTemp = cmd.itemBarcode;

            /*
             * if (IsbnSplitter.IsISBN(ref strTemp) == true)
             * {
             *  // 根据isbn检索item
             *  List<BiblioItem> items=null;
             *  string error="";
             *  long lRet= dp2WeiXinService.Instance.SearchItem(activeUser,
             *      loginInfo,
             *      "ISBN",
             *      strTemp,
             *      "left",
             *      cmd.type,
             *      out items,
             *      out  error);
             *  if (lRet == -1 || lRet == 0)
             *  {
             *      cmdError = "根据ISBN检索书目出错:" + error;
             *      cmd.state = -1;
             *  }
             *  else
             *  {
             *      cmd.itemList = items;
             *      cmdRet = -3;
             *  }
             *
             *  goto END1;
             * }
             */
            #endregion

            #region 借书、还书

#if NO
            // 借书
            if (cmd.type == ChargeCommand.C_Command_Borrow)
            {
                cmdRet = dp2WeiXinService.Instance.Circulation(libId,
                                                               loginInfo,
                                                               "borrow",
                                                               cmd.patronBarcode,
                                                               cmd.itemBarcode,
                                                               out outPatronBarcode,
                                                               out patronXml,
                                                               out resultInfo,
                                                               out cmdError);


                // 借书失败时,也要取一下读者记录,因为读者信息还是要显示的
                if (string.IsNullOrEmpty(patronXml) == true)
                {
                    // 取读者记录
                    int nRet = dp2WeiXinService.Instance.GetPatronXml(libId,
                                                                      loginInfo,
                                                                      outPatronBarcode,
                                                                      "xml",
                                                                      out patronRecPath,
                                                                      out timestamp,
                                                                      out patronXml,
                                                                      out otherError);
                    if (nRet == -1 || nRet == 0)
                    {
                        //命令成功的,但加载读者不成功,一般这种情况不可能有
                    }
                }
            }
            else if (cmd.type == ChargeCommand.C_Command_Return) // 还书
            {
                cmdRet = dp2WeiXinService.Instance.Circulation(libId,
                                                               loginInfo,
                                                               "return",
                                                               cmd.patronBarcode,
                                                               cmd.itemBarcode,
                                                               out outPatronBarcode,
                                                               out patronXml,
                                                               out resultInfo,
                                                               out cmdError);
            }
#endif
            // 调借还书命令
            cmdRet = dp2WeiXinService.Instance.Circulation(libId,
                                                           loginInfo,
                                                           cmd.type,
                                                           cmd.patronBarcode,
                                                           cmd.itemBarcode,
                                                           out outPatronBarcode,
                                                           out patronXml,
                                                           out resultInfo,
                                                           out cmdError);
            if (cmd.state != -1)
            {
                // 根据item barcode取书名
                string    summary = "";
                string    recPath = "";
                LibEntity lib     = dp2WeiXinService.Instance.GetLibById(libId);
                int       nRet    = dp2WeiXinService.Instance.GetBiblioSummary(lib,
                                                                               cmd.itemBarcode,
                                                                               "",
                                                                               out summary,
                                                                               out recPath,
                                                                               out otherError);
                if (nRet == -1)
                {
                    //出错信息会加起来
                }

                if (string.IsNullOrEmpty(summary) == false)
                {
                    biblioName = dp2WeiXinService.Instance.GetShortSummary(summary);
                }
            }

            #endregion

END1:
            // 设返回值
            cmd.state      = cmdRet;
            cmd.errorInfo  = cmdError;  //20171028
            cmd.typeString = cmd.getTypeString(cmd.type);

            //========以下两种情况直接返回,不加到操作历史中===
            // 读者姓名重复的情况
            if (cmdRet == -2)
            {
                return(cmd);
            }
            // isbn的情况
            if (cmdRet == -3)
            {
                return(cmd);
            }
            //=================


            // 设上实际的读者证条码,还书时用到
            cmd.patronBarcode = outPatronBarcode;

            // 解析读者信息
            if (string.IsNullOrEmpty(patronXml) == false)
            {
                int showPhoto = 0;//todo
                patron = dp2WeiXinService.Instance.ParsePatronXml(libId,
                                                                  patronXml,
                                                                  patronRecPath,
                                                                  showPhoto);
                cmd.patronBarcode = patron.barcode;
            }

            string simpleInfo = "";
            cmd.resultInfo       = cmd.GetResultInfo(out simpleInfo);
            cmd.simpleResultInfo = simpleInfo; // 简单结果信息
            if (cmd.type == ChargeCommand.C_Command_LoadPatron && patron != null)
            {
                // 语音返回  读者姓名
                cmd.resultInfoWavText = patron.name;

                cmd.resultInfo = "<span style='font-size:20pt'>" + patron.name + "</span>";
                if (String.IsNullOrEmpty(patron.department) == false)
                {
                    cmd.resultInfo += "(" + patron.department + ")";
                }

                cmd.simpleResultInfo = cmd.resultInfo;
            }
            else
            {
                if (cmd.state != -1)
                {
                    if (cmd.type == ChargeCommand.C_Command_Borrow)
                    {
                        // 语音返回  书名
                        cmd.resultInfoWavText = biblioName;
                        // 简单结果信息
                        cmd.simpleResultInfo = biblioName;

                        cmd.resultInfo += "<br/>" + biblioName; //用+=是因为前面有了 借书成功
                    }
                    else if (cmd.type == ChargeCommand.C_Command_Return)
                    {
                        // 语音返回  书名
                        cmd.resultInfoWavText = biblioName;

                        // 简单结果信息
                        cmd.simpleResultInfo = biblioName;

                        cmd.resultInfo += "<br/>" + biblioName; //用+=是因为前面有了 还书成功
                        if (patron != null)
                        {
                            cmd.resultInfo       += "<br/>借阅者:" + patron.name;
                            cmd.simpleResultInfo += "<br/>借阅者:" + patron.name;
                        }
                    }

                    //有提示信息
                    if (String.IsNullOrEmpty(cmd.errorInfo) == false &&
                        cmd.errorInfo != ChargeCommand.C_ReturnSucces_FromApi)
                    {
                        cmd.resultInfo       += "<br/>" + cmd.errorInfo;
                        cmd.simpleResultInfo += "<br/>" + cmd.errorInfo;
                    }
                }
            }

END2:

            // 得到命令html
            string cmdHtml = this.GetCmdHtml3(libId, cmd, patron);//.GetCmdHtml(libId, cmd, patron, otherError);
            cmd.cmdHtml    = cmdHtml;


            // 加到集合里
            this.Add(cmd); //this.Insert(0, cmd); //

            return(cmd);
        }