Ejemplo n.º 1
0
        public Command AddCmd(Command item)
        {
            Debug.Assert(item != null, "AddCmd传进的item不能为空。");
            Debug.Assert(String.IsNullOrEmpty(item.type) == false, "命令类型不能为空。");
            string strError = "";

            // 补充命令信息
            item.id          = this.cmdList.Count + 1;
            item.description = item.readerBarcode + "-" + item.type + "-" + item.itemBarcode;
            item.operTime    = DateTimeToString(DateTime.Now);
            item.typeString  = Command.getTypeString(item.type);

            if (item.type == Command.C_Command_Borrow ||
                item.type == Command.C_Command_VerifyRenew ||
                item.type == Command.C_Command_VerifyReturn)
            {
                if (String.IsNullOrEmpty(item.readerBarcode) == true)
                {
                    item.state      = -1;
                    item.resultInfo = "读者证条码号不能为空。";
                }
            }

            if (String.IsNullOrEmpty(item.itemBarcode) == true)
            {
                item.state      = -1;
                item.resultInfo = "册条码号不能为空。";
            }

            // 执行这个命令
            LibraryChannel channel = ilovelibraryServer.Instance.ChannelPool.GetChannel(ilovelibraryServer.Instance.dp2LibraryUrl, this.UserName);

            channel.Password   = this.Password;
            channel.Parameters = this.Parameters;
            try
            {
                long   lRet = -1;
                string strOutputReaderBarcode = "";
                string strReaderXml           = "";
                // 借书或续借
                if (item.type == Command.C_Command_Borrow ||
                    item.type == Command.C_Command_Renew ||
                    item.type == Command.C_Command_VerifyRenew)
                {
                    bool bRenew = false;
                    if (item.type == Command.C_Command_Renew ||
                        item.type == Command.C_Command_VerifyRenew)
                    {
                        bRenew = true;
                    }
                    DigitalPlatform.LibraryRestClient.BorrowInfo borrowInfo = null;
                    lRet = channel.Borrow(bRenew,
                                          item.readerBarcode,
                                          item.itemBarcode,
                                          out strOutputReaderBarcode,
                                          out strReaderXml,
                                          out borrowInfo,
                                          out strError);
                }
                else if (item.type == Command.C_Command_Return ||
                         item.type == Command.C_Command_VerifyReturn ||
                         item.type == Command.C_Command_Read)
                {
                    string strAction = "";
                    if (item.type == Command.C_Command_Return ||
                        item.type == Command.C_Command_VerifyReturn)
                    {
                        strAction = "return";
                    }
                    else
                    {
                        strAction = "read";
                    }


                    ReturnInfo returnInfo = null;
                    lRet = channel.Return(strAction,
                                          item.readerBarcode,
                                          item.itemBarcode,
                                          out strOutputReaderBarcode,
                                          out strReaderXml,
                                          out returnInfo,
                                          out strError);
                }



                // 设上实际的读者证条码
                item.readerBarcode = strOutputReaderBarcode;

                // 读者重复
                if (lRet == 2)
                {
                    item.state      = (int)lRet;
                    item.resultInfo = item.typeString + "书操作失败:" + strError;

                    //直接返回了,因为不会加到操作历史里
                    return(item);
                }

                // 册重复
                if (lRet == 3)
                {
                    item.state      = (int)lRet;
                    item.resultInfo = strError;//item.typeString + "书操作失败:" + strError;

                    //直接返回了,因为不会加到操作历史里
                    return(item);
                }


                if (lRet == -1)
                {
                    item.state      = -1;
                    item.resultInfo = item.typeString + "书操作失败:" + strError;
                }
                else if (lRet == 0)
                {
                    item.state      = 0;
                    item.resultInfo = item.typeString + "书操作成功。";
                }
                else
                {
                    item.state      = 1;
                    item.resultInfo = strError;
                }

                // 检索是否与前面同一个读者,不加要加线
                if (this.cmdList.Count > 0)
                {
                    Command firstCmd = this.cmdList[0];
                    if (firstCmd.readerBarcode != item.readerBarcode &&
                        String.IsNullOrEmpty(item.readerBarcode) == false &&
                        String.IsNullOrEmpty(firstCmd.readerBarcode) == false)
                    {
                        item.isAddLine = 1;
                    }
                }
                // 设链接地址
                if (item.itemBarcode.Contains("@biblioRecPath") == false && string.IsNullOrEmpty(ilovelibraryServer.Instance.dp2OpacUrl) == false)
                {
                    item.itemBarcodeUrl = ilovelibraryServer.Instance.dp2OpacUrl + "/book.aspx?barcode=" + HttpUtility.UrlEncode(item.itemBarcode) + "&borrower=" + item.readerBarcode;

                    item.itemBarcodeUrl = "<a href='" + item.itemBarcodeUrl + "' target='_blank'>" + item.itemBarcode + "</a>";
                }
                else
                {
                    item.itemBarcodeUrl = item.itemBarcode;
                }
                // 解析读者信息
                //PatronResult patronResult = ilovelibraryServer.Instance.GetPatronInfo(this, item.readerBarcode);
                //item.patronResult = patronResult;

                PatronResult patronResult = new PatronResult();
                patronResult.patron    = null;
                patronResult.apiResult = new ApiResult();
                if (String.IsNullOrEmpty(strReaderXml) == true)
                {
                    patronResult.apiResult.errorCode = -1;
                    patronResult.apiResult.errorInfo = "dp2服务端操作api返回的读者xml为空。";
                }
                else
                {
                    //解析返回的读者xml
                    ilovelibraryServer.Instance.ParseReaderXml(strReaderXml, patronResult);
                }
                item.patronResult = patronResult;


                // 加到集合里
                this.cmdList.Insert(0, item);

                return(item);
            }
            finally
            {
                ilovelibraryServer.Instance.ChannelPool.ReturnChannel(channel);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 续借
        /// </summary>
        /// <param name="strItemBarcode">册条码号</param>
        /// <returns></returns>
        public int Renew(string strReaderBarcode, string strItemBarcode, out BorrowInfo borrowInfo, out string strError)
        {
            borrowInfo = null;
            strError = "";

            if (strItemBarcode == null)
                strItemBarcode = "";
            strItemBarcode = strItemBarcode.Trim();
            if (strItemBarcode == "")
            {
                strError = "续借失败:您输入的续借图书编号或者册条码号为空。";
                return -1;
            }

            if (String.IsNullOrEmpty(strReaderBarcode )==true)
            {
                strError = "续借失败:内部错误,读者证条码号为空。";
                return -1;
            }

            /*
            // 优先从序号字典中找下
            if (this.CurrentMessageContext.BorrowDict.ContainsKey(strItemBarcode))
            {
                string temp = this.CurrentMessageContext.BorrowDict[strItemBarcode];
                if (temp != null && temp != "")
                    strItemBarcode = temp;
            }
            */

            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
            channel.Password = this.dp2Password;
            try
            {
                long lRet = channel.Borrow(true,
                    strReaderBarcode,
                    strItemBarcode,
                    out borrowInfo,
                    out strError);
                if (lRet == -1)
                    return -1;

                return 1;

            }
            finally
            {
                this.ChannelPool.ReturnChannel(channel);
            }
        }