コード例 #1
0
ファイル: BiblioControl.cs プロジェクト: zhangandding/dp2
        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);
        }
コード例 #2
0
        int BuildBiblioRecord(
            string strMarcSyntax,
            string strTitle,
            string strAuthor,
            string strPublisher,
            string strIsbnIssn,
            string strPrice,
            string strSummary,
            string strOperator,
            out string strMARC,
            out string strError)
        {
            strError = "";

            // strMARC = "012345678901234567890123";
            strMARC = "00892nam0 2200277   45  ";

            string strField = "";
            int    nRet     = 0;

            if (strMarcSyntax.ToLower() == "unimarc")
            {
                // 010
                strField = "010  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strIsbnIssn
                           + new string(MarcDocument.SUBFLD, 1) + "d"
                           + strPrice;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "010",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 010 error";
                    return(-1);
                }

                // 200
                strField = "20010"
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strTitle
                           + new string(MarcDocument.SUBFLD, 1) + "f"
                           + strAuthor
                ;

                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "200",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 200 error";
                    return(-1);
                }

                // 210
                strField = "210  "
                           + new string(MarcDocument.SUBFLD, 1) + "c"
                           + strPublisher;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "210",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 210 error";
                    return(-1);
                }

                // 330
                strField = "330  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strSummary;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "330",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 330 error";
                    return(-1);
                }


                // 701
                strField = "701  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strAuthor
                ;

                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "701",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 701 error";
                    return(-1);
                }
            }
            else if (strMarcSyntax.ToLower() == "usmarc")
            {
                // 020
                strField = "020  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strIsbnIssn
                           + new string(MarcDocument.SUBFLD, 1) + "c"
                           + strPrice;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "020",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 020 error";
                    return(-1);
                }

                // 245
                strField = "24510"
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strTitle
                           + new string(MarcDocument.SUBFLD, 1) + "c"
                           + strAuthor
                ;

                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "245",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 245 error";
                    return(-1);
                }

                // 260
                strField = "260  "
                           + new string(MarcDocument.SUBFLD, 1) + "b"
                           + strPublisher;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "260",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 260 error";
                    return(-1);
                }

                // 520
                strField = "520  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strSummary;
                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "520",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 520 error";
                    return(-1);
                }


                // 701
                strField = "700  "
                           + new string(MarcDocument.SUBFLD, 1) + "a"
                           + strAuthor
                ;

                nRet = MarcDocument.ReplaceField(
                    ref strMARC,
                    "700",
                    0,
                    strField);
                if (nRet == -1)
                {
                    strError = "ReplaceField 700 error";
                    return(-1);
                }
            }

            // 998
            strField = "998  "
                       + new string(MarcDocument.SUBFLD, 1) + "s"
                       + "订购征询,读者创建"
                       + new string(MarcDocument.SUBFLD, 1) + "u"
                       + DateTime.Now.ToString("u")
                       + new string(MarcDocument.SUBFLD, 1) + "z"
                       + strOperator
            ;

            nRet = MarcDocument.ReplaceField(
                ref strMARC,
                "998",
                0,
                strField);
            if (nRet == -1)
            {
                strError = "ReplaceField 998 error";
                return(-1);
            }

            return(0);
        }
コード例 #3
0
ファイル: BiblioControl.cs プロジェクト: zhangandding/dp2
        void submit_button_Click(object sender, EventArgs e)
        {
            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;
            }

            if (bManager == false)
            {
                strError = "当前帐户不具备 managecomment 权限, 不能进行修改书目状态的操作";
                goto ERROR1;
            }

            LibraryChannel channel = sessioninfo.GetChannel(true);

            try
            {
                string strBiblioRecPath = this.BiblioRecPath;

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

                string[] results = null;
                lRet = // sessioninfo.Channel.
                       channel.GetBiblioInfos(
                    null,
                    strBiblioRecPath,
                    "",
                    formats,
                    out results,
                    out timestamp,
                    out strError);
                if (lRet == -1)
                {
                    strError = "获得书目记录 '" + strBiblioRecPath + "' 时出错: " + strError;
                    goto ERROR1;
                }
                if (lRet == 0)
                {
                    strError = "书目记录 '" + strBiblioRecPath + "' 不存在";
                    goto ERROR1;
                }
                if (results == null || results.Length < 1)
                {
                    strError = "results error {11AD709F-2DBC-41DE-8129-184FFAD59815}";
                    goto ERROR1;
                }
                strBiblioXml = results[0];

                byte[] old_timestamp = ByteArray.GetTimeStampByteArray(this.Timestamp);
                if (ByteArray.Compare(timestamp, old_timestamp) != 0)
                {
                    strError = "修改被拒绝。因为记录 '" + strBiblioRecPath + "' 在保存前已经被其他人修改过。请重新装载";
                    goto ERROR1;
                }

                string strOutMarcSyntax = "";
                string strMarc          = "";
                // 将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;
                }

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

                // 修改998字段
                string strOldBiblioState = strBiblioState;

                this.GetStateValueFromControls(ref strBiblioState);

                if (strOldBiblioState == strBiblioState)
                {
                    // 也退出编辑态
                    cancel_button_Click(this, new EventArgs());
                    strError = "状态没有发生变化,放弃保存书目记录";
                    goto ERROR1;
                }

                MarcUtil.SetFirstSubfield(ref strMarc,
                                          "998",
                                          "s",
                                          strBiblioState);

                // 保存
                // 将MARC格式转换为XML格式
                // 2015/10/12 从 Marc2Xml() 修改为 Marc2XmlEx()
                string strXml = strBiblioXml;
                nRet = MarcUtil.Marc2XmlEx(
                    strMarc,
                    strOutMarcSyntax,
                    ref strXml,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                string strOutputBiblioRecPath = "";
                byte[] baOutputTimestamp      = null;

                lRet = // sessioninfo.Channel.
                       channel.SetBiblioInfo(
                    null,
                    "change",
                    strBiblioRecPath,
                    "xml",
                    strXml,
                    timestamp,
                    "",
                    out strOutputBiblioRecPath,
                    out baOutputTimestamp,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                this.Timestamp = ByteArray.GetHexTimeStampString(baOutputTimestamp);
                return;
            }
            finally
            {
                sessioninfo.ReturnChannel(channel);
            }
ERROR1:
            this.SetDebugInfo("errorinfo", strError);
        }