Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

        // 是否登录?
        if (sessioninfo.UserID == "")
        {
            sessioninfo.LoginCallStack.Push(Request.RawUrl);
            Response.Redirect("login.aspx", true);
            return;
        }

        string strSenderName = "";

        if (sessioninfo.ReaderInfo != null &&
            sessioninfo.IsReader == true)
        {
            string strDisplayName = "";
            string strBarcode     = "";

            strDisplayName = sessioninfo.ReaderInfo.DisplayName;
            strBarcode     = sessioninfo.ReaderInfo.Barcode;

            strSenderName = BoxesInfo.BuildOneAddress(strDisplayName, strBarcode);
        }
        else
        {
            strSenderName = sessioninfo.UserID;
        }

        this.MessageControl1.UserID = strSenderName;

        string strMessageID  = this.Request["id"];
        string strMessageIDs = this.Request["ids"];

        if (this.IsPostBack == false)
        {
            // ids参数不为空
            if (String.IsNullOrEmpty(strMessageIDs) == false)
            {
                string[]      ids    = strMessageIDs.Split(new char[] { ',' });
                List <string> idlist = new List <string>();
                for (int i = 0; i < ids.Length; i++)
                {
                    idlist.Add(ids[i]);
                }

                this.MessageControl1.MessageData    = null;
                this.MessageControl1.RecordID       = null;
                this.MessageControl1.TimeStamp      = null;
                this.MessageControl1.RecordIDs      = idlist;
                this.MessageControl1.RecordIDsIndex = 0;
                return;
            }

            // id参数不为空
            if (String.IsNullOrEmpty(strMessageID) == false)
            {
                LibraryChannel channel = sessioninfo.GetChannel(true);
                try
                {
                    string        strError = "";
                    MessageData[] messages = null;
                    string[]      ids      = new string[1];
                    ids[0] = strMessageID;
                    // 根据消息记录id获得消息详细内容
                    // 本函数还将检查消息是否属于strUserID指明的用户
                    // parameters:
                    //      strUserID   如果==null,表示不检查消息属于何用户
                    long nRet = // sessioninfo.Channel.
                                channel.GetMessage(
                        ids,
                        MessageLevel.Full,
                        out messages,
                        out strError);
                    if (nRet == -1)
                    {
                        this.Response.Write(strError);
                        this.Response.End();
                    }
                    if (messages == null || messages.Length < 1)
                    {
                        strError = "messages error";
                        this.Response.Write(strError);
                        this.Response.End();
                    }
                    this.MessageControl1.MessageData = messages[0];
                }
                finally
                {
                    sessioninfo.ReturnChannel(channel);
                }
            }
            else
            {
                string strRecipient = this.Request.QueryString["recipient"];
                if (String.IsNullOrEmpty(strRecipient) == false)
                {
                    this.MessageControl1.Recipient = strRecipient;
                }

                // 新创建的消息
                this.MessageControl1.MessageData = null;
                this.MessageControl1.RecordID    = null;
                this.MessageControl1.TimeStamp   = null;
            }
        }
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

        // 是否登录?
        if (sessioninfo.UserID == "")
        {
            sessioninfo.UserID   = "public";
            sessioninfo.IsReader = false;
        }

        string strError = "";
        int    nRet     = 0;

#if NO
        SessionInfo temp_sessioninfo = new SessionInfo(app);
        temp_sessioninfo.UserID   = app.ManagerUserName;
        temp_sessioninfo.Password = app.ManagerPassword;
        temp_sessioninfo.IsReader = false;
#endif
        LibraryChannel channel = app.GetChannel();

        try
        {
            bool   bHintDisplayName = false; // []暗示为显示名
            string strDisplayName   = this.Request["displayName"];
            string strBarcode       = this.Request["barcode"];
            string strEncyptBarcode = Request.QueryString["encrypt_barcode"];

            string strText = "";

            // 如果为加密的条码形态
            if (String.IsNullOrEmpty(strEncyptBarcode) == false)
            {
                strBarcode = OpacApplication.DecryptPassword(strEncyptBarcode);
                if (strBarcode == null)
                {
                    strError = "encrypt_barcode参数值格式错误";
                    goto ERROR1;
                }
                bHintDisplayName = true;
                goto SEARCH_COMMENT;
            }

            {
                if (String.IsNullOrEmpty(strDisplayName) == false)
                {
                    if (strDisplayName.IndexOfAny(new char[] { '[', ']' }) != -1)
                    {
                        bHintDisplayName = true;
                    }
                    strDisplayName = strDisplayName.Replace("[", "").Trim();
                    strDisplayName = strDisplayName.Replace("]", "").Trim();
                }

                nRet = 0;
                string strReaderXml        = "";
                string strOutputReaderPath = "";

                if (String.IsNullOrEmpty(strDisplayName) == false)
                {
                    byte[] timestamp = null;

                    string[] results = null;
                    long     lRet    = // temp_sessioninfo.Channel.
                                       channel.GetReaderInfo(
                        null,
                        "@displayName:" + strDisplayName,
                        "xml",
                        out results,
                        out strOutputReaderPath,
                        out timestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (lRet == 0 && bHintDisplayName == true)
                    {
                        strBarcode = "";
                        goto SEARCH_COMMENT;
                    }
                    strReaderXml = results[0];

                    // CONTINUE1:
                    if (nRet == 0)
                    {
                        strBarcode = strDisplayName;
                    }
                }

                // SEARCH_BARCODE:
                if (nRet == 0 && String.IsNullOrEmpty(strBarcode) == false)
                {
                    strReaderXml = "";
                    byte[] timestamp = null;

                    string[] results = null;
                    long     lRet    = // temp_sessioninfo.Channel.
                                       channel.GetReaderInfo(
                        null,
                        strBarcode,
                        "xml",
                        out results,
                        out strOutputReaderPath,
                        out timestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (lRet == 0)
                    {
                        goto SEARCH_COMMENT;
                    }
                    strReaderXml = results[0];
                }

                if (nRet == 0)
                {
                    /*
                     * strError = "读者显示名或者证条码号 '" + strDisplayName + "' 不存在";
                     * goto ERROR1;
                     * */
                    if (String.IsNullOrEmpty(strBarcode) == true)
                    {
                        strBarcode = strDisplayName;
                    }
                    goto SEARCH_COMMENT;
                }

                XmlDocument readerdom = null;
                nRet = OpacApplication.LoadToDom(strReaderXml,
                                                 out readerdom,
                                                 out strError);
                if (nRet == -1)
                {
                    strError = "装载读者记录 '" + strOutputReaderPath + "' 进入XML DOM时发生错误: " + strError;
                    goto ERROR1;
                }

                strDisplayName = DomUtil.GetElementText(readerdom.DocumentElement,
                                                        "displayName");

                strBarcode = DomUtil.GetElementInnerXml(readerdom.DocumentElement,
                                                        "barcode");
            }
SEARCH_COMMENT:
            strText = strDisplayName;
            if (String.IsNullOrEmpty(strText) == true)
            {
                strText = strBarcode;
            }

            this.Label_name.Text = strText;

            string strRecipient = "";

            /*
             * if (String.IsNullOrEmpty(strDisplayName) == false)
             * {
             *  if (strDisplayName.IndexOf("[") == -1)
             *      strRecipient = "[" + strDisplayName + "]";
             *  else
             *      strRecipient = strDisplayName;
             *  if (String.IsNullOrEmpty(strEncyptBarcode) == false)
             *      strRecipient += " encrypt_barcode:" + strEncyptBarcode;
             * }
             * else
             *  strRecipient = strBarcode;
             * */
            strRecipient = BoxesInfo.BuildOneAddress(strDisplayName, strBarcode);

            string strSendMessageUrl = "./message.aspx?recipient=" + HttpUtility.UrlEncode(strRecipient);
            this.Button_sendMessage.OnClientClick = "window.open('" + strSendMessageUrl + "','_blank'); return cancelClick();";

            LoginState loginstate = GlobalUtil.GetLoginState(this.Page);
            if (loginstate == LoginState.NotLogin || loginstate == LoginState.Public)
            {
                this.Button_sendMessage.Enabled = false;
            }

            this.BrowseSearchResultControl1.Title = strText + " 所发表的书评";

            if (String.IsNullOrEmpty(strEncyptBarcode) == false)
            {
                this.Image_photo.ImageUrl = "./getphoto.aspx?encrypt_barcode=" + HttpUtility.UrlEncode(strEncyptBarcode) + "&displayName=" + HttpUtility.UrlEncode(strDisplayName);
            }
            else
            {
                this.Image_photo.ImageUrl = "./getphoto.aspx?barcode=" + HttpUtility.UrlEncode(strBarcode);
            }

            this.Image_photo.Width  = 128;
            this.Image_photo.Height = 128;

            if (this.IsPostBack == false)
            {
                string strXml = "";
                if (String.IsNullOrEmpty(strDisplayName) == false &&
                    String.IsNullOrEmpty(strBarcode) == false)
                {
                    // 创建评注记录XML检索式
                    // 用作者和作者显示名共同限定检索
                    nRet = ItemSearchControl.BuildCommentQueryXml(
                        app,
                        strDisplayName,
                        strBarcode,
                        "<全部>",
                        15000,   // app.SearchMaxResultCount
                        true,
                        out strXml,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else if (String.IsNullOrEmpty(strBarcode) == false)
                {
                    // 创建XML检索式
                    nRet = ItemSearchControl.BuildQueryXml(
                        this.app,
                        "comment",
                        strBarcode,
                        "<全部>",
                        "作者",
                        "exact",
                        15000,   // app.SearchMaxResultCount
                        true,
                        out strXml,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else if (String.IsNullOrEmpty(strDisplayName) == false)
                {
                    // 创建XML检索式
                    nRet = ItemSearchControl.BuildQueryXml(
                        this.app,
                        "comment",
                        strDisplayName,
                        "<全部>",
                        "作者显示名",
                        "exact",
                        15000,   // app.SearchMaxResultCount
                        true,
                        out strXml,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strError = "strBarcode和strDisplayName均为空,无法进行检索";
                    goto ERROR1;
                }

                string strResultSetName = "opac_userinfo";

                // sessioninfo.Channel.
                channel.Idle += new IdleEventHandler(channel_Idle);
                try
                {
                    long lRet = //sessioninfo.Channel.
                                channel.Search(
                        null,
                        strXml,
                        strResultSetName,
                        "", // strOutputStyle
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    // not found
                    if (lRet == 0)
                    {
                        this.BrowseSearchResultControl1.Title = strText + " 没有发表过任何书评";
                    }
                    else
                    {
                        this.BrowseSearchResultControl1.ResultSetName = strResultSetName;
                        this.BrowseSearchResultControl1.ResultCount   = (int)lRet;
                        this.BrowseSearchResultControl1.StartIndex    = 0;
                    }
                    return;
                }
                finally
                {
                    //sessioninfo.Channel.
                    channel.Idle -= new IdleEventHandler(channel_Idle);
                }
            }
            return;

ERROR1:
            Response.Write(HttpUtility.HtmlEncode(strError));
            Response.End();
        }
        finally
        {
#if NO
            temp_sessioninfo.CloseSession();
#endif
            app.ReturnChannel(channel);
        }
    }