Esempio n. 1
0
        protected override void Render(HtmlTextWriter output)
        {
            if (this.RecPath == "")
            {
                output.Write("尚未指定记录路径");
                return;
            }

            int    nRet     = 0;
            long   lRet     = 0;
            string strError = "";
            // string strOutputPath = "";

            OpacApplication app         = (OpacApplication)this.Page.Application["app"];
            SessionInfo     sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            bool bManager = false;

            if (string.IsNullOrEmpty(sessioninfo.UserID) == true ||
                StringUtil.IsInList("managecomment", sessioninfo.RightsOrigin) == false)
            {
                bManager = false;
            }
            else
            {
                bManager = true;
            }

            PlaceHolder inputline = (PlaceHolder)this.FindControl("inputline");
            PlaceHolder cmdline   = (PlaceHolder)this.FindControl("cmdline");


            if (bManager == false)
            {
                cmdline.Visible = false;
            }

            string strBiblioState = "";

#if NO
            string strBiblioXml = "";

            // 获得书目XML
            {
                byte[] timestamp = null;

                string[] formats = new string[1];
                formats[0] = "xml";

                string[] results = null;
                lRet = sessioninfo.Channel.GetBiblioInfos(
                    null,
                    this.RecPath,
                    formats,
                    out results,
                    out timestamp,
                    out strError);
                if (lRet == -1)
                {
                    strError = "获得种记录 '" + this.RecPath + "' 时出错: " + strError;
                    goto ERROR1;
                }
                if (results == null || results.Length < 1)
                {
                    strError = "results error ";
                    goto ERROR1;
                }
                strBiblioXml = results[0];

                this.Timestamp     = ByteArray.GetHexTimeStampString(timestamp);
                this.BiblioRecPath = this.RecPath;
            }

            string strMarc = "";

            // 转换为MARC
            {
                string strOutMarcSyntax = "";

                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
#endif


            bool bAjax = true;
            if (this.DisableAjax == true)
            {
                bAjax = false;
            }
            else
            {
                if (app != null &&
                    app.WebUiDom != null &&
                    app.WebUiDom.DocumentElement != null)
                {
                    XmlNode nodeBiblioControl = app.WebUiDom.DocumentElement.SelectSingleNode(
                        "biblioControl");
                    if (nodeBiblioControl != null)
                    {
                        DomUtil.GetBooleanParam(nodeBiblioControl,
                                                "ajax",
                                                true,
                                                out bAjax,
                                                out strError);
                    }
                }
            }

            string strMarc = "";
            if (string.IsNullOrEmpty(this.m_strMARC) == true)
            {
                nRet = PrepareBiblioRecord(out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
                strMarc = this.m_strMARC;
            }

            strBiblioState = MarcDocument.GetFirstSubfield(strMarc,
                                                           "998",
                                                           "s"); // 状态
            string strOriginCreator = MarcDocument.GetFirstSubfield(strMarc,
                                                                    "998",
                                                                    "z");

            bool bReaderCreate = false;
            if (StringUtil.IsInList("读者创建", strBiblioState) == true)
            {
                bReaderCreate = true;
            }

            // 不是读者创建的记录,就不让在这里修改状态
            if (bReaderCreate == false)
            {
                cmdline.Visible = false;
            }


            bool bDisplayOriginContent = false;
            if (StringUtil.IsInList("审查", strBiblioState) == false &&
                StringUtil.IsInList("屏蔽", strBiblioState) == false)
            {
                bDisplayOriginContent = true;
            }

            // 管理员和作者本人都能看到被屏蔽的内容
            if (bManager == true || strOriginCreator == sessioninfo.UserID)
            {
                bDisplayOriginContent = true;
            }



            string strBiblio = "";
            if (bDisplayOriginContent == true)
            {
                if (bAjax == true)
                {
                    strBiblio = "<div class='pending'>biblio_html:" + HttpUtility.HtmlEncode(this.RecPath) + "</div>";
                }
                else
                {
                    strBiblio = this.m_strOpacBiblio;
#if NO
                    string strBiblioDbName = ResPath.GetDbName(this.RecPath);

                    // 需要从内核映射过来文件
                    string strLocalPath = "";
                    nRet = app.MapKernelScriptFile(
                        null,                      // sessioninfo,
                        strBiblioDbName,
                        "./cfgs/opac_biblio.fltx", // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件
                        out strLocalPath,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }


                    // 将种记录数据从XML格式转换为HTML格式
                    Hashtable result_params = null;

                    // 2006/11/28 changed
                    string strFilterFileName = strLocalPath;    // app.CfgDir + "\\biblio.fltx";
                    nRet = app.ConvertBiblioXmlToHtml(
                        strFilterFileName,
                        strBiblioXml,
                        this.RecPath,
                        out strBiblio,
                        out result_params,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }

                    // TODO: Render的时候设置,已经晚了半拍
                    // 要想办法在全部Render前得到题名和进行设置
                    if (this.AutoSetPageTitle == true &&
                        result_params != null)
                    {
                        string strTitle = (string)result_params["title"];
                        if (string.IsNullOrEmpty(strTitle) == false)
                        {
                            this.Page.Title = strTitle;
                        }
                    }

                    /*
                     * string strPrefix = "";
                     * if (this.Wrapper == true)
                     *  strPrefix = this.GetPrefixString("书目信息", "content_wrapper")
                     + "<div class='biblio_wrapper'>";
                     +
                     + string strPostfix = "";
                     + if (this.Wrapper == true)
                     +  strPostfix = "</div>" + this.GetPostfixString();
                     * */


                    /*
                     * LiteralControl literal = (LiteralControl)FindControl("biblio");
                     * literal.Text = strPrefix + strBiblio + strPostfix;
                     * */

                    // strBiblio = strPrefix + strBiblio + strPostfix;
#endif
                }
            }


            // 屏蔽等状态显示
            string strResult = "";
            string strImage  = "";
            if (StringUtil.IsInList("精品", strBiblioState) == true)
            {
                strImage   = "<img src='" + MyWebPage.GetStylePath(app, "valuable.gif") + "'/>";
                strResult += "<div class='valuable' title='精品'>"
                             + strImage
                             + this.GetString("精品")
                             + "</div>";
            }
            if (StringUtil.IsInList("锁定", strBiblioState) == true)
            {
                strImage   = "<img src='" + MyWebPage.GetStylePath(app, "locked.gif") + "'/>";
                strResult += "<div class='locked' title='锁定'>"
                             + strImage
                             + this.GetString("锁定")
                             + "</div>";
            }

            string strDisplayState = "";
            if (StringUtil.IsInList("审查", strBiblioState) == true)
            {
                strImage        = "<img src='" + MyWebPage.GetStylePath(app, "censor.gif") + "'/>";
                strDisplayState = this.GetString("审查");
            }
            if (StringUtil.IsInList("屏蔽", strBiblioState) == true)
            {
                strImage = "<img src='" + MyWebPage.GetStylePath(app, "disable.gif") + "'/>";
                if (String.IsNullOrEmpty(strDisplayState) == false)
                {
                    strDisplayState += ",";
                }
                strDisplayState += this.GetString("屏蔽");
            }

            if (String.IsNullOrEmpty(strDisplayState) == false)
            {
                strResult += "<div class='forbidden' title='" + this.GetString("屏蔽原因") + "'>"
                             + strImage
                             + string.Format(this.GetString("本书目记录目前为X状态"), strDisplayState)
                             + (strOriginCreator == sessioninfo.UserID ? "," + this.GetString("其他人(非管理员)看不到下列内容") : "")
                             + "</div>";
            }

            if (String.IsNullOrEmpty(strResult) == false)
            {
                strResult = "<div class='biblio_state'>" + strResult + "</div>";
            }

            if (this.EditAction == "changestate")
            {
                inputline.Visible = true;
                SetStateValueToControls(strBiblioState);
                cmdline.Visible = false;    // 在编辑态,命令条就不要出现了
            }
            else
            {
                inputline.Visible = false;
            }

            if (this.Active == false)
            {
                cmdline.Visible   = false;
                inputline.Visible = false;  // 即便在编辑态也要加以压抑
            }


            string strClass = "biblio";
            if ((String.IsNullOrEmpty(strResult) == false ||
                 inputline.Visible == true) &&
                this.Wrapper == false)
            {
                strClass += " frame-border";
            }

            LiteralControl outer_class = (LiteralControl)this.FindControl("outer_class");
            outer_class.Text = strClass;

            // output.Write(strBiblio);
            LiteralControl literal = (LiteralControl)FindControl("biblio");
            // literal.Text = "<div class='"+strClass+"'>" + strResult + strBiblio + "</biblio>";
            literal.Text = strResult + strBiblio;


            base.Render(output);
            return;

ERROR1:
            output.Write(strError);
        }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

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

        string strError = "";
        int    nRet     = 0;

        string strBarcode = this.Request["barcode"];

        if (string.IsNullOrEmpty(strBarcode) == true)
        {
            strError = "需要指定barcode参数";
            goto ERROR1;
        }

        string strLang = this.Request["lang"];

        if (string.IsNullOrEmpty(strLang) == false)
        {
            //this.UICulture = strLang;
            //this.Culture = strLang;
            try
            {
                Thread.CurrentThread.CurrentCulture =
                    CultureInfo.CreateSpecificCulture(strLang);
                Thread.CurrentThread.CurrentUICulture = new
                                                        CultureInfo(strLang);
            }
            catch
            {
            }

            //this.Session["lang"] = Thread.CurrentThread.CurrentUICulture.Name;
        }

#if NO
        // test
        this.Response.Write("test");
        this.Response.End();
        return;
#endif

        if (StringUtil.HasHead(strBarcode, "biblio_html:") == true)
        {
            string strBiblioRecPath = strBarcode.Substring("biblio_html:".Length);

            // 获得书目记录XML
            string[] formats = new string[1];
            formats[0] = "xml";
            byte[] timestamp = null;

            string[] results = null;

            // 2016/1/24
            if (string.IsNullOrEmpty(sessioninfo.UserID) == true)
            {
                strError = "sessioninfo.UserID 为空 (sessioninfo.Parameters='" + sessioninfo.Parameters + "') {F548F93A-3ED7-4F7A-8729-CD65E375D360}";
                goto ERROR1;
            }

            LibraryChannel channel = null;
#if CHANNEL_POOL
            channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/);
#else
            channel = sessioninfo.GetChannel(false);
#endif
            long lRet = channel.GetBiblioInfos(
                null,
                strBiblioRecPath,
                "",
                formats,
                out results,
                out timestamp,
                out strError);
#if CHANNEL_POOL
            sessioninfo.ReturnChannel(channel);
#endif
            if (lRet == -1)
            {
                strError = "获得书目记录 '" + strBiblioRecPath + "' 时出错: " + strError;
                goto ERROR1;
            }
            if (lRet == 0)
            {
                strError = "书目记录 '" + strBiblioRecPath + "' 不存在";
                goto ERROR1;
            }
            if (results == null || results.Length < 1)
            {
                strError = "results error {87C72690-662D-48E3-920D-B0E0C5D53726}";
                goto ERROR1;
            }
            string strBiblioXml = results[0];

            // 创建HTML
            string strBiblioDbName = StringUtil.GetDbName(strBiblioRecPath);

            // 需要从内核映射过来文件
            string strLocalPath = "";
            nRet = app.MapKernelScriptFile(
                // null,   // sessioninfo,
                strBiblioDbName,
                "./cfgs/opac_biblio.fltx",  // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件
                out strLocalPath,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            // 将种记录数据从XML格式转换为HTML格式
            string strResult = "";

            KeyValueCollection result_params     = null;
            string             strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx";
            nRet = app.ConvertBiblioXmlToHtml(
                strFilterFileName,
                strBiblioXml,
                strBiblioRecPath,
                out strResult,
                out result_params,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
            this.Response.Write(strResult);
            this.Response.End();
            return;
        }
        else if (StringUtil.HasHead(strBarcode, "formated:") == true)
        {
            strBarcode = strBarcode.Substring("formated:".Length);
            string strArrivedItemBarcode = "";

            string[] barcodes = strBarcode.Split(new char[] { ',' });
            string   strTemp  = "";
            foreach (string barcode in barcodes)
            {
                if (string.IsNullOrEmpty(barcode) == true)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(strTemp) == false)
                {
                    strTemp += ",";
                }

                if (barcode[0] == '!')
                {
                    strArrivedItemBarcode = barcode.Substring(1);
                    strTemp += strArrivedItemBarcode;
                }
                else
                {
                    strTemp += barcode;
                }
            }

            strBarcode = strTemp;

            string strStyle       = "html"; // this.Request["style"];
            string strOtherParams = "";     // this.Request["otherparams"];

            LibraryChannel channel = null;
#if CHANNEL_POOL
            channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/); // 2016/1/25 增加第二参数
#else
            channel = sessioninfo.GetChannel(false);
#endif

            // 获得一系列册的摘要字符串
            //
            // paramters:
            //      strStyle    风格。逗号间隔的列表。如果包含html text表示格式。forcelogin
            //      strOtherParams  <a>命令中其余的参数。例如" target='_blank' "可以用来打开新窗口
            string strResult = ReservationInfoControl.GetBarcodesSummary(
                app,
                channel,
                strBarcode,
                strArrivedItemBarcode,
                strStyle,
                strOtherParams);

#if CHANNEL_POOL
            sessioninfo.ReturnChannel(channel);
#endif
            this.Response.Write(strResult);
            this.Response.End();
            return;
        }
        else
        {
            // 2016/1/25
            if (string.IsNullOrEmpty(sessioninfo.UserID) == true)
            {
                strError = "sessioninfo.UserID 为空 (sessioninfo.Parameters='" + sessioninfo.Parameters + "') {9A54CD5B-B1CF-43D2-8AE3-1969B5873055}";
                goto ERROR1;
            }

            // 获得摘要
            string strSummary       = "";
            string strBiblioRecPath = "";

            LibraryChannel channel = null;
#if CHANNEL_POOL
            channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/); // 2016/1/25 增加第二参数
#else
            channel = sessioninfo.GetChannel(false);
#endif

            long lRet = channel.GetBiblioSummary(
                null,
                strBarcode,
                null,
                null,
                out strBiblioRecPath,
                out strSummary,
                out strError);
#if CHANNEL_POOL
            sessioninfo.ReturnChannel(channel);
#endif
            if (lRet == -1 || lRet == 0)
            {
                strSummary = strError;
            }

            this.Response.Write(strSummary);
            this.Response.End();
        }
        return;

ERROR1:
        this.Response.Write(strError);
        this.Response.End();
    }
Esempio n. 3
0
        int PrepareBiblioRecord(
            out string strError)
        {
            strError = "";
            int  nRet = 0;
            long lRet = 0;

            // string strOutputPath = "";

            if (string.IsNullOrEmpty(this.RecPath) == true)
            {
                return(0);   // 此时无法进行初始化
            }
            OpacApplication app         = (OpacApplication)this.Page.Application["app"];
            SessionInfo     sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            string         strBiblioXml = "";
            LibraryChannel channel      = sessioninfo.GetChannel(true);

            try
            {
                // string strBiblioState = "";

                byte[]   timestamp = null;
                string[] formats   = new string[1];
                formats[0] = "xml";

                string[] results = null;
                lRet = // sessioninfo.Channel.
                       channel.GetBiblioInfos(
                    null,
                    this.RecPath,
                    "",
                    formats,
                    out results,
                    out timestamp,
                    out strError);
                if (lRet == -1)
                {
                    strError = "获得书目记录 '" + this.RecPath + "' 时出错: " + strError;
                    goto ERROR1;
                }
                if (lRet == 0)
                {
                    strError = "书目记录 '" + this.RecPath + "' 不存在";
                    goto ERROR1;
                }
                if (results == null || results.Length < 1)
                {
                    strError = "results error {A9217775-645E-42F1-8307-22B26C0E1D69}";
                    goto ERROR1;
                }

                strBiblioXml  = results[0];
                this.m_strXml = strBiblioXml;

                this.Timestamp     = ByteArray.GetHexTimeStampString(timestamp);
                this.BiblioRecPath = this.RecPath;
            }
            finally
            {
                sessioninfo.ReturnChannel(channel);
            }

            if (app.SearchLog != null)
            {
                SearchLogItem log = new SearchLogItem();
                log.IP       = this.Page.Request.UserHostAddress.ToString();
                log.Query    = "";
                log.Time     = DateTime.UtcNow;
                log.HitCount = 1;
                log.Format   = "biblio";
                log.RecPath  = this.RecPath;
                app.SearchLog.AddLogItem(log);
            }

            string strMarc = "";

            // 转换为MARC
            {
                string strOutMarcSyntax = "";

                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                this.m_strMARC = strMarc;
            }

            bool bAjax = true;

            if (this.DisableAjax == true)
            {
                bAjax = false;
            }
            else
            {
                if (app != null &&
                    app.WebUiDom != null &&
                    app.WebUiDom.DocumentElement != null)
                {
                    XmlNode nodeBiblioControl = app.WebUiDom.DocumentElement.SelectSingleNode(
                        "biblioControl");
                    if (nodeBiblioControl != null)
                    {
                        DomUtil.GetBooleanParam(nodeBiblioControl,
                                                "ajax",
                                                true,
                                                out bAjax,
                                                out strError);
                    }
                }
            }

            if (bAjax == false)
            {
                string strBiblio       = "";
                string strBiblioDbName = StringUtil.GetDbName(this.RecPath);

                // 需要从内核映射过来文件
                string strLocalPath = "";
                nRet = app.MapKernelScriptFile(
                    // null,   // sessioninfo,
                    strBiblioDbName,
                    "./cfgs/opac_biblio.fltx",  // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件
                    out strLocalPath,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // 将种记录数据从XML格式转换为HTML格式
                KeyValueCollection result_params = null;

                // 2006/11/28 changed
                string strFilterFileName = strLocalPath;    // app.CfgDir + "\\biblio.fltx";
                nRet = app.ConvertBiblioXmlToHtml(
                    strFilterFileName,
                    strBiblioXml,
                    this.RecPath,
                    out strBiblio,
                    out result_params,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                // TODO: Render的时候设置,已经晚了半拍
                // 要想办法在全部Render前得到题名和进行设置
                if (this.AutoSetPageTitle == true &&
                    result_params != null && result_params.Count > 0)
                {
                    string strTitle = result_params["title"].Value;
                    if (string.IsNullOrEmpty(strTitle) == false)
                    {
                        this.Page.Title = strTitle;
                    }

                    bool bHasDC = false;
                    // 探测一下,是否有至少一个DC.开头的 key ?
                    foreach (KeyValue item in result_params)
                    {
                        if (StringUtil.HasHead(item.Key, "DC.") == true)
                        {
                            bHasDC = true;
                            break;
                        }
                    }

                    if (bHasDC == true)
                    {
                        // <header profile="http://dublincore.org/documents/2008/08/04/dc-html/">
                        this.Page.Header.Attributes.Add("profile", "http://dublincore.org/documents/2008/08/04/dc-html/");

                        // DC rel
                        //
                        HtmlLink link = new HtmlLink();
                        link.Href = "http://purl.org/dc/elements/1.1/";
                        link.Attributes.Add("rel", "schema.DC");
                        this.Page.Header.Controls.Add(link);

                        // <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" >
                        link      = new HtmlLink();
                        link.Href = "http://purl.org/dc/terms/";
                        link.Attributes.Add("rel", "schema.DCTERMS");
                        this.Page.Header.Controls.Add(link);

                        foreach (KeyValue item in result_params)
                        {
                            if (StringUtil.HasHead(item.Key, "DC.") == false &&
                                StringUtil.HasHead(item.Key, "DCTERMS.") == false)
                            {
                                continue;
                            }
                            HtmlMeta meta = new HtmlMeta();
                            meta.Name    = item.Key;
                            meta.Content = item.Value;
                            if (StringUtil.HasHead(item.Value, "urn:") == true ||
                                StringUtil.IsHttpUrl(item.Value) == true ||
                                StringUtil.HasHead(item.Value, "info:") == true
                                )
                            {
                                meta.Attributes.Add("scheme", "DCTERMS.URI");
                            }

                            this.Page.Header.Controls.Add(meta);
                        }
                    }
                }

                this.m_strOpacBiblio = strBiblio;
            }
            return(0);

ERROR1:
            return(-1);
        }