Пример #1
0
        // 删除用户
        public int DeleteUser(
            string strLibraryCodeList,
            string strUserName,
            string strOperator,
            string strClientAddress,
            out string strError)
        {
            strError = "";

            if (String.IsNullOrEmpty(strUserName) == true)
            {
                strError = "strUserName参数值不能为空";
                return(-1);
            }

            XmlNode nodeAccount    = null;
            string  strOldOuterXml = "";

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                // 查重
                nodeAccount = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//accounts/account[@name='" + strUserName + "']");
                if (nodeAccount == null)
                {
                    strError = "用户 '" + strUserName + "' 不存在";
                    return(-1);
                }
                strOldOuterXml = nodeAccount.OuterXml;

                string strExistLibraryCodeList = DomUtil.GetAttr(nodeAccount, "libraryCode");

                // 2012/9/9
                // 分馆用户只允许删除馆代码属于管辖分馆的帐户
                if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
                {
                    if (string.IsNullOrEmpty(strExistLibraryCodeList) == true ||
                        IsListInList(strExistLibraryCodeList, strLibraryCodeList) == false)
                    {
                        strError = "当前用户只能删除 图书馆代码完全属于 '" + strLibraryCodeList + "' 范围的用户";
                        return(-1);
                    }
                }

                nodeAccount.ParentNode.RemoveChild(nodeAccount);

                this.Changed = true;

                // 2014/9/16
                if (strUserName == "reader")
                {
                    this.ClearLoginCache("");
                }
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }

            {
                XmlDocument domOperLog = PrepareOperlogDom("delete", strOperator);

                if (string.IsNullOrEmpty(strOldOuterXml) == false)
                {
                    XmlNode node_old = domOperLog.CreateElement("oldAccount");
                    domOperLog.DocumentElement.AppendChild(node_old);
                    node_old = DomUtil.SetElementOuterXml(node_old, strOldOuterXml);
                    DomUtil.RenameNode(node_old,
                                       null,
                                       "oldAccount");
                }

                // 写入日志
                int nRet = this.OperLog.WriteOperLog(domOperLog,
                                                     strClientAddress,
                                                     out strError);
                if (nRet == -1)
                {
                    strError = "SetUser() API 写入日志时发生错误: " + strError;
                    return(-1);
                }
            }

            return(0);
        }
Пример #2
0
    protected void TreeView1_GetNodeData(object sender, GetNodeDataEventArgs e)
    {
        /*
         * if (e.Node == e.Node.OwnerDocument.DocumentElement)
         *  return;
         * */
        if (e.Node.Name[0] == '_')
        {
            return;
        }

        string strName = DomUtil.GetAttr(e.Node, "name");

        if (string.IsNullOrEmpty(strName) == true)
        {
            return;
        }

        bool   bCommand   = true;
        string strCommand = DomUtil.GetAttr(e.Node, "command");

        if (string.IsNullOrEmpty(strCommand) == false &&
            strCommand[0] == '~')
        {
            bCommand = false;
        }

        ///
        string strSideBarFileName = Path.GetFileName(this.SideBarControl1.CfgFile).ToLower();
        string strDataFile        = Path.GetFileName(this.TreeView1.XmlFileName).ToLower();
        string strNodePath        = CacheBuilder.MakeNodePath(e.Node);

        string strCount = "";

        if (bCommand == true)
        {
            strCount = app.GetBrowseNodeCount(strDataFile, strNodePath);
            if (string.IsNullOrEmpty(strCount) == true &&
                app.CacheBuilder != null)
            {
                long lCount = app.CacheBuilder.GetCountByNodePath(strDataFile,
                                                                  strNodePath,
                                                                  false);
                if (lCount == -1)
                {
                    strCount = "?";
                }
                else
                {
                    strCount = lCount.ToString();
                }

                app.SetBrowseNodeCount(strDataFile, strNodePath, strCount);
            }
        }

        if (string.IsNullOrEmpty(strCount) == false)
        {
            // e.Name = strName + " (" + strCount + ")";
            e.Name  = strName;
            e.Count = strCount;
        }
        else
        {
            e.Name = strName;
        }

        if (strNodePath == this.SelectingNodePath)
        {
            e.Seletected = true;

            /*
             * // 如果有更适合的标题文字
             * if (string.IsNullOrEmpty(this.SelectedNodeCaption) == false)
             *  e.Name = this.SelectedNodeCaption;
             * */
        }

        // TODO: 是否可以给每个节点都显示包含记录的数字? 为了提高速度,是否可以用一个hashtable来存储这个数字对照关系?
        string strSideBarParam = "";

        if (string.IsNullOrEmpty(strSideBarFileName) == false)
        {
            strSideBarParam = "&sidebar=" + HttpUtility.UrlEncode(strSideBarFileName);
        }

        string strFormatParam = "";

        if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.CurrentFormat) == false)
        {
            strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.CurrentFormat);
        }
        else if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.FormatName) == false)
        {
            strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.FormatName);
        }

        e.Url = "./browse.aspx?datafile=" + HttpUtility.UrlEncode(strDataFile) + strSideBarParam + "&node=" + strNodePath + strFormatParam;

        if (e.Node == e.Node.OwnerDocument.DocumentElement ||
            IsParentPath(strNodePath, this.SelectingNodePath) == true)
        {
            e.Closed = false;
        }
    }
Пример #3
0
    int BuildRssOutput(
        string strDataFile,
        string strNode,
        out string strError)
    {
        int nRet = 0;

        strError = "";

        // 2018/1/27
        if (strNode == null)
        {
            strError = "BuildRssOutput() 失败。strNode 参数值不应为 null";
            return(-1);
        }

        string strDataFilePath = app.DataDir + "/browse/" + strDataFile;

        XmlDocument dom = new XmlDocument();

        try
        {
            dom.Load(strDataFilePath);
        }
        catch (Exception ex)
        {
            strError = "装载文件 '" + strDataFilePath + "' 时出错: " + ex.Message;
            return(-1);
        }

        // 2014/12/2
        // 兑现宏
        nRet = CacheBuilder.MacroDom(dom,
                                     new List <string> {
            "name", "command"
        },
                                     out strError);
        if (nRet == -1)
        {
            return(-1);
        }

        XmlNode node = null;

        try
        {
            node = CacheBuilder.GetDataNode(dom.DocumentElement, strNode);
        }
        catch (Exception ex)
        {
            throw new Exception("CacheBuilder.GetDataNode() 出现异常,strNode=[" + strNode + "]", ex);
        }

        if (node == null)
        {
            strError = "路径 '" + strNode + "' 在文件 '" + strDataFile + "' 中没有找到对应的节点";
            return(-1);
        }

        bool   bRss         = false;
        long   nMaxCount    = -1;
        string strDirection = "";

        // parameters:
        //      nMaxCount   -1表示无穷多
        //      strDirection    head/tail
        CacheBuilder.GetRssParam(node,
                                 out bRss,
                                 out nMaxCount,
                                 out strDirection);

        if (bRss == false)
        {
            strError = "此节点不允许输出RSS";
            return(-1);
        }
        string strCommand     = DomUtil.GetAttr(node, "command");
        string strPureCaption = DomUtil.GetAttr(node, "name");
        string strDescription = DomUtil.GetAttr(node, "description");

        if (strCommand == "~hidelist~")
        {
            strError = "此节点 ~hidelist~ 不允许输出RSS";
            return(-1);
        }

        if (strCommand == "~none~")
        {
            strError = "此节点 ~none~ 不允许输出RSS";
            return(-1);
        }

        // strDataFile 中为纯文件名
        string strPrefix   = strNode;
        string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile;

        PathUtil.TryCreateDir(strCacheDir);
        string strResultsetFilename = strCacheDir + "/" + strPrefix;

        // 如果RSS文件已经存在,就不要从 dp2library 获取了
        if (File.Exists(strResultsetFilename + ".rss") == true)
        {
            // return:
            //      -1  出错
            //      0   成功
            //      1   暂时不能访问
            nRet = DumpRssFile(strResultsetFilename + ".rss",
                               out strError);
            if (nRet == -1)
            {
                return(-1);
            }
            return(0);
        }


        // 加入列表,要求创建RSS文件

        /*
         * lock (app.PendingCacheFiles)
         * {
         *  string strLine = strDataFile + ":" + strNode + ":rss";  // 仅仅要求创建RSS文件
         *  if (app.PendingCacheFiles.IndexOf(strLine) == -1)
         *      app.PendingCacheFiles.Add(strLine);
         * }
         * app.ActivateCacheBuilder();
         * */
        CacheBuilder.AddToPendingList(app,
                                      strDataFile,
                                      strNode,
                                      "rss");

        // "相关缓存正在被创建,请稍后重新访问";
        strError = "RSS file is building, please retry soon later... 相关缓存正在被创建,请稍后重新访问";
        this.Response.ContentType       = "text/plain; charset=utf-8";
        this.Response.StatusCode        = 503;
        this.Response.StatusDescription = strError;
        this.Response.Write(strError);
        return(0);
    }
Пример #4
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            // output.Write(Text);

            string strError = "";


            // return:
            //      -1  出错
            //      0   成功
            //      1   尚未登录
            int nRet = this.LoadReaderXml(out strError);

            if (nRet == -1)
            {
                output.Write(strError);
                return;
            }

            if (nRet == 1)
            {
                sessioninfo.LoginCallStack.Push(this.Page.Request.RawUrl);
                this.Page.Response.Redirect("login.aspx", true);
                return;
            }

            // 读者类别
            string strReaderType = DomUtil.GetElementText(ReaderDom.DocumentElement, "readerType");

            string strResult = "";

            // 超期记录
            XmlNodeList nodes = ReaderDom.DocumentElement.SelectNodes("overdues/overdue");

            strResult += this.GetPrefixString(
                this.GetString("违约交费信息"),    // "违约/交费信息"
                null);
            strResult += "<table class='fellbackinfo'>";
            strResult += "<tr class='columntitle'><td>"
                         + this.GetString("册条码号")
                         + "</td><td>"
                         + this.GetString("书目摘要")
                         + "</td><td>"
                         + this.GetString("说明")
                         + "</td><td>"
                         + this.GetString("金额")
                         + "</td><td>"
                         + this.GetString("借阅情况")
                         + "</td><td>"
                         + this.GetString("ID")
                         + "</td></tr>";

            if (nodes.Count == 0)
            {
                strResult += "<tr class='dark' >";
                strResult += "<td class='comment' colspan='6'>"
                             + this.GetString("无违约交费信息") // "(无违约/交费信息)"
                             + "</td>";
                strResult += "</tr>";
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node             = nodes[i];
                string  strBarcode       = DomUtil.GetAttr(node, "barcode");
                string  strReason        = DomUtil.GetAttr(node, "reason");
                string  strBorrowDate    = DateTimeUtil.LocalTime(DomUtil.GetAttr(node, "borrowDate"));
                string  strBorrowPeriod  = DomUtil.GetAttr(node, "borrowPeriod");
                string  strReturnDate    = DateTimeUtil.LocalTime(DomUtil.GetAttr(node, "returnDate"));
                string  strID            = DomUtil.GetAttr(node, "id");
                string  strPrice         = DomUtil.GetAttr(node, "price");
                string  strOverduePeriod = DomUtil.GetAttr(node, "overduePeriod");

                string strPriceString = DomUtil.GetAttr(node, "priceString");

                string strBarcodeLink = "<a href='" + app.LibraryServerUrl + "/book.aspx?barcode=" + strBarcode + "&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";

#if NO
                // 获得摘要
                string strSummary = "";

                if (String.IsNullOrEmpty(strBarcode) == false)  // 2009/4/16
                {
                    string strBiblioRecPath = "";
                    long   lRet             = sessioninfo.Channel.GetBiblioSummary(
                        null,
                        strBarcode,
                        null,
                        null,
                        out strBiblioRecPath,
                        out strSummary,
                        out strError);
                    if (lRet == -1 || lRet == 0)
                    {
                        strSummary = strError;
                    }

                    /*
                     * LibraryServerResult result = app.GetBiblioSummary(
                     *  sessioninfo,
                     *  strBarcode,
                     *  null,
                     *  null,
                     *  out strBiblioRecPath,
                     *  out strSummary);
                     * if (result.Value == -1 || result.Value == 0)
                     *  strSummary = result.ErrorInfo;
                     * */
                }
#endif

                if (String.IsNullOrEmpty(strPriceString) == false)
                {
                    strPrice = strPriceString;
                }

                string strTrClass = " class='dark' ";

                if ((i % 2) == 1)
                {
                    strTrClass = " class='light' ";
                }

                strResult += "<tr " + strTrClass + ">";
                strResult += "<td class='barcode' nowrap>" + strBarcodeLink + "</td>";
                strResult += "<td class='summary pending' >" + strBarcode + "</td>";
                strResult += "<td class='reason' >" + strReason + "</td>";
                strResult += "<td class='price'>" + strPrice + "</td>";
                strResult += "<td class='borrowinfo'>"
                             + "<div class='borrowdate'>"
                             + this.GetString("借阅日期")
                             + ":" + strBorrowDate + "</div>"
                             + "<div class='borrowperiod'>"
                             + this.GetString("期限")
                             + ":    " + strBorrowPeriod + "</div>"
                             + "<div class='returndate'>"
                             + this.GetString("还书日期")
                             + ":" + strReturnDate + "</div>"
                             + "</td>";
                strResult += "<td class='id'>" + strID + "</td>";
                strResult += "</tr>";
            }

            XmlNode nodeOverdues    = ReaderDom.DocumentElement.SelectSingleNode("overdues");
            string  strPauseMessage = "";
            if (nodeOverdues != null)
            {
                strPauseMessage = DomUtil.GetAttr(nodeOverdues, "pauseMessage");
            }

            if (string.IsNullOrEmpty(strPauseMessage) == false)
            {
                // 汇报以停代金情况
                strResult += "<td class='price' colspan='6'>"
                             + strPauseMessage
                             + " ("
                             + this.GetString("什么叫以停代金") // "什么叫“<a href='./pauseBorrowing.html'>以停代金</a>”?"
                             + ")</td>";
            }

            strResult += "</table>";

            strResult += this.GetPostfixString();

            output.Write(strResult);
        }
Пример #5
0
        /// <summary>
        /// 详细借阅信息
        /// </summary>
        /// <param name="strXml"></param>
        /// <param name="strBorrowInfo"></param>
        /// <returns></returns>
        public int GetBorrowsInfoInternal(string strXml, out string strBorrowInfo)
        {
            strBorrowInfo = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(strXml);

            /*
             *  <info>
             * <item name="可借总册数" value="10" />
             * <item name="日历名">
             * <value>基本日历</value>
             * </item>
             * <item name="当前还可借" value="9" />
             * </info>
             * ''
             */
            string  maxBorrowCount = "";
            string  curBorrowCount = "";
            XmlNode nodeMax        = dom.DocumentElement.SelectSingleNode("info/item[@name='可借总册数']");

            if (nodeMax == null)
            {
                maxBorrowCount = "获取当前读者可借总册数出错:未找到对应节点。";
            }
            else
            {
                string maxCount = DomUtil.GetAttr(nodeMax, "value");
                if (maxCount == "")
                {
                    maxBorrowCount = "获取当前读者可借总册数出错:未设置对应值。";
                }
                else
                {
                    maxBorrowCount = "最多可借:" + maxCount;;
                    XmlNode nodeCurrent = dom.DocumentElement.SelectSingleNode("info/item[@name='当前还可借']");
                    if (nodeCurrent == null)
                    {
                        curBorrowCount = "获取当前还可借出错:未找到对应节点。";
                    }
                    else
                    {
                        curBorrowCount = "当前可借:" + DomUtil.GetAttr(nodeCurrent, "value");
                    }
                }
            }

            strBorrowInfo = maxBorrowCount + " " + curBorrowCount + "\n";

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("borrows/borrow");

            if (nodes.Count == 0)
            {
                strBorrowInfo += "无借阅记录";
                return(0);
            }

            Dictionary <string, string> borrowLit = new Dictionary <string, string>();
            int    index = 1;
            string books = "";

            foreach (XmlElement borrow in nodes)
            {
                if (books != "")
                {
                    books += "===============\n";
                }

                string overdueText  = "";
                string strIsOverdue = DomUtil.GetAttr(borrow, "isOverdue");
                if (strIsOverdue == "yes")
                {
                    overdueText = DomUtil.GetAttr(borrow, "overdueInfo1");
                }
                else
                {
                    overdueText = "未超期";
                }


                string itemBarcode = DomUtil.GetAttr(borrow, "barcode");
                borrowLit[index.ToString()] = itemBarcode; // 设到字典点,已变续借

                /*
                 * string bookName = DomUtil.GetAttr(borrow, "summary");//borrow.GetAttribute("summary")
                 * int tempIndex = bookName.IndexOf('/');
                 * if (tempIndex > 0)
                 * {
                 *  bookName = bookName.Substring(0, tempIndex);
                 * }
                 */
                string summary = DomUtil.GetAttr(borrow, "summary");
                books += "编号:" + index.ToString() + "\n"
                         + "册条码号:" + itemBarcode + "\n"
                         + "摘       要:" + summary + "\n"
                         + "借阅时间:" + DateTimeUtil.ToLocalTime(borrow.GetAttribute("borrowDate"), "yyyy-MM-dd HH:mm") + "\n"
                         + "借       期:" + DateTimeUtil.GetDisplayTimePeriodString(borrow.GetAttribute("borrowPeriod")) + "\n"
                         + "应还时间:" + DateTimeUtil.ToLocalTime(borrow.GetAttribute("returningDate"), "yyyy-MM-dd") + "\n"
                         + "是否超期:" + overdueText + "\n";


                index++; //编号+1
            }

            strBorrowInfo += books;

            // 设到用户上下文
            //this.CurrentMessageContext.BorrowDict = borrowLit;

            return(nodes.Count);
        }
Пример #6
0
        private void button_beginSearch_Click(object sender, EventArgs e)
        {
            string      strError = "";
            XmlDocument dom      = new XmlDocument();

            try
            {
                dom.Load(this.textBox_biblioSearch_queryFilename.Text);
            }
            catch (Exception ex)
            {
                strError = "检索式文件装入XMLDOM发生错误: " + ex.Message;
                goto ERROR1;
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在检索...");
            stop.BeginLoop();

            this.EnableControlsInSearching(false);
            try
            {
                ClearWebBrowser(this.webBrowser1);

                int    nStart  = -1;
                int    nEnd    = -1;
                Random randObj = new Random();
                int    nRet    = this.textBox_searchBiblio_beforeAbort.Text.IndexOf("-");
                if (nRet == -1 || this.textBox_searchBiblio_beforeAbort.Text == "-1")
                {
                    this.m_nBeforeAbort = Convert.ToInt32(this.textBox_searchBiblio_beforeAbort.Text);
                }
                else
                {
                    string strStart = this.textBox_searchBiblio_beforeAbort.Text.Substring(0, nRet).Trim();
                    string strEnd   = this.textBox_searchBiblio_beforeAbort.Text.Substring(nRet + 1).Trim();
                    nStart = Convert.ToInt32(strStart);
                    nEnd   = Convert.ToInt32(strEnd);
                }



                int nLoopTimes = Convert.ToInt32(this.textBox_searchBiblio_loopTimes.Text);

                XmlNodeList nodes = dom.DocumentElement.SelectNodes("query");
                for (int j = 0; j < nLoopTimes; j++)
                {
                    stop.SetMessage("循环 " + (j + 1).ToString() + "...");
                    Global.WriteHtml(this.webBrowser1,
                                     "\r\n循环 " + (j + 1).ToString() + "...\r\n");

                    for (int i = 0; i < nodes.Count; i++)
                    {
                        Application.DoEvents(); // 出让界面控制权

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "中断";
                                goto ERROR1;
                            }
                        }

                        XmlNode node = nodes[i];

                        string strWord       = DomUtil.GetAttr(node, "word");
                        string strDbName     = DomUtil.GetAttr(node, "dbname");
                        string strFromStyle  = DomUtil.GetAttr(node, "fromstyle");
                        string strMatchStyle = DomUtil.GetAttr(node, "matchstyle");
                        string strComment    = DomUtil.GetAttr(node, "comment");

                        int nTimeLimit = -2;
                        if (node.Attributes["timelimit"] != null)
                        {
                            nTimeLimit = Convert.ToInt32(DomUtil.GetAttr(node, "timelimit"));
                        }

                        // timelimit属性优先起作用
                        if (nTimeLimit != -2)
                        {
                            this.m_nBeforeAbort = nTimeLimit;
                        }
                        else
                        {
                            if (nStart != -1 && nEnd != -1)
                            {
                                this.m_nBeforeAbort = randObj.Next(nStart, nEnd);
                            }
                            else
                            {
                                this.m_nBeforeAbort = Convert.ToInt32(this.textBox_searchBiblio_beforeAbort.Text);
                            }
                        }

                        stop.SetMessage("正在检索 '" + strWord + "' ...");
                        Global.WriteHtml(this.webBrowser1,
                                         "正在检索 '" + strWord + "' 中断前毫秒数=" + this.m_nBeforeAbort.ToString() + "; " + strComment + "...\r\n");

                        this.eventActive.Set();

                        DateTime timeStart = DateTime.Now;

                        string strQueryXml = "";
                        long   lRet        = Channel.SearchBiblio(stop,
                                                                  strDbName,
                                                                  strWord,
                                                                  -1,
                                                                  strFromStyle,
                                                                  strMatchStyle,
                                                                  this.Lang,
                                                                  null, // strResultSetName
                                                                  "",   // strSearchStyle
                                                                  "",   // strOutputStyle,
                                                                  "",
                                                                  out strQueryXml,
                                                                  out strError);

                        TimeSpan delta = DateTime.Now - timeStart;

                        Global.WriteHtml(this.webBrowser1,
                                         "    返回 lRet='" + lRet.ToString() + "' strError='" + strError + "' 用时= " + delta.TotalSeconds.ToString() + " 秒\r\n");

                        if (lRet == -1)
                        {
                            if (this.Channel.ErrorCode != ErrorCode.RequestCanceled)
                            {
                                goto ERROR1;
                            }
                        }

                        long lHitCount = lRet;
                    }
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                this.EnableControlsInSearching(true);
            }

            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Пример #7
0
        // 根据虚拟的From名获得真实的From名。这个From是工作语言下的名字
        // 如果匹配多个From名,将在字符串中以逗号分隔
        // parameters:
        //      strVirtualFromName  虚拟库的from名列表。或者style列表
        public string GetRealFromName(
            string strRealDbName,
            string strVirtualFromName,
            bool bOutputDebugInfo,
            out string strDebugInfo)
        {
            List <string> styles = new List <string>();

            strDebugInfo = "";

            // 2012/11/20
            // 得到纯粹的style列表。不包含那些 _ 打头的style
            string strPureStyles = StringUtil.MakePathList(MakeStyleList(strVirtualFromName));

            if (bOutputDebugInfo == true)
            {
                strDebugInfo += " begin GetRealFromName()\r\nstrRealDbName='" + strRealDbName + "' strVirtualFromName='" + strVirtualFromName + "'\r\n";
                strDebugInfo += "this.nodeDatabase: " + this.nodeDatabase.OuterXml + "\r\n";
            }

            if (String.IsNullOrEmpty(strVirtualFromName) == true ||
                strVirtualFromName == "<全部>" ||
                strVirtualFromName.ToLower() == "<all>")
            {
                XmlNodeList nodes = this.nodeDatabase.SelectNodes("from");
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "是 全部, nodes.Count=" + nodes.Count.ToString() + "\r\n";
                }
                for (int i = 0; i < nodes.Count; i++)
                {
                    string strStyle = DomUtil.GetAttr(nodes[i], "style");
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "加入styles '" + strStyle + "'\r\n";
                    }
                    styles.Add(strStyle);
                }
            }
            else
            {
                XmlNode     node  = null;
                XmlNodeList nodes = this.nodeDatabase.SelectNodes("from/caption");
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "选定全部 from/caption 元素, nodes.Count=" + nodes.Count.ToString() + "\r\n";
                }
                for (int i = 0; i < nodes.Count; i++)
                {
                    node = nodes[i];
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "node.InnerText.Trim()='" + node.InnerText.Trim() + "'\r\n";
                    }
                    if (strVirtualFromName == node.InnerText.Trim())
                    {
                        if (bOutputDebugInfo == true)
                        {
                            strDebugInfo += "匹配上了\r\n";
                        }
                        string strStyle = DomUtil.GetAttr(node.ParentNode, "style");
                        if (bOutputDebugInfo == true)
                        {
                            strDebugInfo += "取匹配节点的ParentNode的style属性加入styles数组。ParentNode.OuterXml=" + node.ParentNode.OuterXml + "\r\n";
                        }
                        styles.Add(strStyle);
                        goto FOUND;
                    }
                }

                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "没有匹配的Caption字符串\r\n继续试探匹配style字符串";
                }

                nodes = this.nodeDatabase.SelectNodes("from");
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "选定全部 from 元素, nodes.Count=" + nodes.Count.ToString() + "\r\n";
                }
                foreach (XmlNode temp in nodes)
                {
                    string strStyles = DomUtil.GetAttr(temp, "style");
                    if (StringUtil.IsInList(strPureStyles, strStyles) == true)
                    {
                        styles.Add(strPureStyles);
                        goto FOUND;
                    }
                }

                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "没有匹配的\r\nend GetRealFromName(), 返回null";
                }
                return(null);    // not found
            }

FOUND:

            List <string> results = new List <string>();

            {
                XmlNode root = this.nodeDatabase.ParentNode;
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "this.nodeDatabase.ParentNode.OuterXml=" + this.nodeDatabase.ParentNode.OuterXml + "\r\n";
                }
                XmlNode nodeDatabase = root.SelectSingleNode("database[@name='" + strRealDbName + "']");
                if (nodeDatabase == null)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "找不到name为'" + strRealDbName + "'的<database>元素\r\n\r\nend GetRealFromName(), 返回null";
                    }
                    return(null);
                }

                XmlNodeList from_nodes = nodeDatabase.SelectNodes("from");
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "选定name为'" + strRealDbName + "'的<database>元素下级的全部<From>元素, nodes.Count=" + from_nodes.Count.ToString() + "\r\n";
                }

                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "遍历styles。\r\n";
                }
                for (int i = 0; i < styles.Count; i++)
                {
                    string strStyle = styles[i];
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "strStyle='" + strStyle + "'\r\n";
                    }

                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "遍历<from>元素。\r\n";
                    }
                    for (int j = 0; j < from_nodes.Count; j++)
                    {
                        XmlNode node = from_nodes[j];

                        string strStyles = DomUtil.GetAttr(node, "style");
                        if (bOutputDebugInfo == true)
                        {
                            strDebugInfo += "<from>元素的style属性值为'" + strStyles + "'\r\n";
                        }
                        if (StringUtil.IsInList(strStyle, strStyles) == true)
                        {
                            if (bOutputDebugInfo == true)
                            {
                                strDebugInfo += "strStyle'" + strStyle + "' 包含于 刚取出的 '" + strStyles + "' 之中,因此将name属性值 '" + DomUtil.GetAttr(node, "name") + "' 加入到结果数组\r\n";
                            }
                            results.Add(DomUtil.GetAttr(node, "name"));
                        }
                        else
                        {
                            if (bOutputDebugInfo == true)
                            {
                                strDebugInfo += "strStyle'" + strStyle + "' 不包含于 刚取出的 '" + strStyles + "' 之中,因此被忽略\r\n";
                            }
                        }
                    }
                }
            }

            if (results.Count == 0)
            {
                if (bOutputDebugInfo == true)
                {
                    strDebugInfo += "没有发现任何匹配的style属性值\r\nend GetRealFromName(), 返回null";
                }
                return(null);    // style没有发现匹配的
            }

            string[] list = new string[results.Count];
            results.CopyTo(list);
            string strResult = String.Join(",", list);

            if (bOutputDebugInfo == true)
            {
                strDebugInfo += "结果数量 " + results.Count + ", '" + strResult + "'\r\nend GetRealFromName()";
            }
            return(strResult);
        }
Пример #8
0
        // 本轮是不是逢上了每日启动时间(以后)?
        // TODO: 如果上次记载的时间,大大超过当前日期,则一直会屏蔽启动。是否可以在这种情况下强制启动,以便达到促使覆盖上次操作时间的目的?
        // parameters:
        //      strLastTime 最后一次执行过的时间 RFC1123格式
        //      strStartTimeDef 返回定义的每日启动时间
        //      bRet    是否到了每日启动时间
        // return:
        //      -2  strLastTime 格式错误
        //      -1  一般错误
        //      0   没有找到startTime配置参数
        //      1   找到了startTime配置参数
        public int IsNowAfterPerDayStart(
            string strMonitorName,
            ref string strLastTime,
            out bool bRet,
            out string strStartTimeDef,
            out string strError)
        {
            strError        = "";
            strStartTimeDef = "";

            XmlNode node = this.App.LibraryCfgDom.DocumentElement.SelectSingleNode("monitors/" + strMonitorName);

            if (node == null)
            {
                bRet = false;
                return(0);
            }

            string strStartTime = DomUtil.GetAttr(node, "startTime");

            if (String.IsNullOrEmpty(strStartTime) == true)
            {
                bRet = false;
                return(0);
            }

            strStartTimeDef = strStartTime;

            string strHour   = "";
            string strMinute = "";

            int nRet = strStartTime.IndexOf(":");

            if (nRet == -1)
            {
                strHour   = strStartTime.Trim();
                strMinute = "00";
            }
            else
            {
                strHour   = strStartTime.Substring(0, nRet).Trim();
                strMinute = strStartTime.Substring(nRet + 1).Trim();
            }

            int nHour   = 0;
            int nMinute = 0;

            try
            {
                nHour   = Convert.ToInt32(strHour);
                nMinute = Convert.ToInt32(strMinute);
            }
            catch
            {
                bRet     = false;
                strError = "时间值 " + strStartTime + " 格式不正确。应为 hh:mm";
                return(-1);   // 格式不正确
            }

            // 当前时间
            DateTime now1 = DateTime.Now;

            // 观察本日是否已经做过了
            if (String.IsNullOrEmpty(strLastTime) == false)
            {
                DateTime lasttime;

                try
                {
                    lasttime = DateTimeUtil.FromRfc1123DateTimeString(strLastTime);

                    if (lasttime.Year == now1.Year &&
                        lasttime.Month == now1.Month &&
                        lasttime.Day == now1.Day)
                    {
                        bRet = false;   // 今天已经做过了
                        return(1);
                    }
                }
                catch
                {
                    bRet     = false;
                    strError = "strLastTime '" + strLastTime + "' 格式错误";
                    return(-2);
                }

                // 2014/3/22
                TimeSpan delta = new DateTime(now1.Year, now1.Month, now1.Day)
                                 - new DateTime(lasttime.Year, lasttime.Month, lasttime.Day);
                // 上次做过的已经是昨天以前
                if (delta.TotalDays > 1)
                {
                    bRet = true;
                    return(1);
                }
            }
            else
            {
                // strLastTime 为空
                // 把当前时间作为上次处理的时间。这样可以避免以后永远轮不到处理时间
                strLastTime = DateTimeUtil.Rfc1123DateTimeStringEx(this.App.Clock.UtcNow.ToLocalTime());
            }

            // 今天的定点时刻
            DateTime now2 = new DateTime(now1.Year,
                                         now1.Month,
                                         now1.Day,
                                         nHour,
                                         nMinute,
                                         0);

            if (now1 >= now2)
            {
                bRet = true;
            }
            else
            {
                bRet = false;
            }
            return(1);
        }
Пример #9
0
        // 检查检索式内有没有超越当前用户管辖的读者库范围的读者库
        // return:
        //      -1  error
        //      0   没有超越要求
        //      1   超越了要求
        public int CheckReaderDbXmlQuery(string strSourceQueryXml,
                                         string strLibraryCodeList,
                                         out string strError)
        {
            strError = "";
            // int nRet = 0;

#if NO
            if (this.vdbs == null)
            {
                this.ActivateManagerThreadForLoad();
                strError = "app.vdbs == null。故障原因请检查dp2Library日志";
                return(-1);
            }

            Debug.Assert(this.vdbs != null, "");
#endif

            XmlDocument dom = new XmlDocument();
            try
            {
                dom.LoadXml(strSourceQueryXml);
            }
            catch (Exception ex)
            {
                strError = "XML检索式装入XMLDOM时出错: " + ex.Message;
                return(-1);
            }

            // 遍历所有<target>元素
            XmlNodeList nodes = dom.DocumentElement.SelectNodes("//target");
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node    = nodes[i];
                string  strList = DomUtil.GetAttr(node, "list");

                if (String.IsNullOrEmpty(strList) == true)
                {
                    continue;
                }

                DbCollection dbs = new DbCollection();

                dbs.Build(strList);

                for (int j = 0; j < dbs.Count; j++)
                {
                    Db db = dbs[j];

                    // 需要限制检索读者库为当前管辖的范围
                    {
                        string strLibraryCode         = "";
                        bool   bReaderDbInCirculation = true;
                        if (this.IsReaderDbName(db.DbName,
                                                out bReaderDbInCirculation,
                                                out strLibraryCode) == true)
                        {
                            // 检查当前操作者是否管辖这个读者库
                            // 观察一个读者记录路径,看看是不是在当前用户管辖的读者库范围内?
                            if (this.IsCurrentChangeableReaderPath(db.DbName + "/?",
                                                                   strLibraryCodeList) == false)
                            {
                                strError = "读者库 '" + db.DbName + "' 不在当前用户管辖范围内";
                                return(1);
                            }
                        }
                    }
                }
            }

            return(0);
        }
Пример #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);
        }
Пример #11
0
        // 从 XML 记录变换
        // parameters:
        //      strLogCreateTime    日志操作记载的创建时间。若不是创建动作的其他时间,不要放在这里
        public static int FromXml(XmlDocument dom,
                                  string strItemRecPath,
                                  string strBiblioRecPath,
                                  string strLogCreateTime,
                                  ref Item line,
                                  out string strError)
        {
            strError = "";
            int nRet = 0;

            if (line == null)
            {
                line = new Item();
            }

            line.ItemRecPath = strItemRecPath;
            line.ItemBarcode = DomUtil.GetElementText(dom.DocumentElement,
                                                      "barcode");

            if (string.IsNullOrEmpty(line.ItemBarcode))
            {
                string strRefID = DomUtil.GetElementText(dom.DocumentElement, "refID");
                line.ItemBarcode = "@refID:" + strRefID;
            }

            string location = StringUtil.GetPureLocationString(
                DomUtil.GetElementText(dom.DocumentElement,
                                       "location")); // 要变为纯净的地点信息,即不包含 #reservation 之类

            line.Location = Item.CanonicalizeLocationString(location);

            line.AccessNo = DomUtil.GetElementText(dom.DocumentElement,
                                                   "accessNo");
            line.BiblioRecPath = strBiblioRecPath;
            line.State         = DomUtil.GetElementText(dom.DocumentElement,
                                                        "state");

            line.Borrower = DomUtil.GetElementText(dom.DocumentElement,
                                                   "borrower");
            line.BorrowTime = Replication.GetLocalTime(DomUtil.GetElementText(dom.DocumentElement,
                                                                              "borrowDate"));
            line.BorrowPeriod = DomUtil.GetElementText(dom.DocumentElement,
                                                       "borrowPeriod");
            // line.ReturningTime = GetLocalTime(DomUtil.GetElementText(dom.DocumentElement, "returningDate"));

            if (line.BorrowTime != DateTime.MinValue)
            {
                // parameters:
                //      strBorrowTime   借阅起点时间。u 格式
                //      strReturningTime    返回应还时间。 u 格式
                nRet = Replication.BuildReturingTimeString(line.BorrowTime,
                                                           line.BorrowPeriod,
                                                           out DateTime returningTime,
                                                           out strError);
                if (nRet == -1)
                {
                    line.ReturningTime = DateTime.MinValue;
                }
                else
                {
                    line.ReturningTime = returningTime;
                }
            }
            else
            {
                line.ReturningTime = DateTime.MinValue;
            }

            string strPrice = DomUtil.GetElementText(dom.DocumentElement,
                                                     "price");

            nRet = Replication.ParsePriceString(strPrice,
                                                out decimal value,
                                                out string strUnit,
                                                out strError);
            if (nRet == -1)
            {
                line.Price = 0;
                line.Unit  = "";
            }
            else
            {
                line.Price = value;
                line.Unit  = strUnit;
            }

            string  strTime = "";
            XmlNode node    = dom.DocumentElement.SelectSingleNode("operations/operation[@name='create']");

            if (node != null)
            {
                strTime = DomUtil.GetAttr(node, "time");
                try
                {
                    // TODO: Replication 里是否已经有特定函数?
                    strTime = DateTimeUtil.Rfc1123DateTimeStringToLocal(strTime, "u");
                }
                catch
                {
                }
            }
            if (string.IsNullOrEmpty(strTime) == true)
            {
                // 如果 operations 里面没有信息
                // 采用日志记录的时间
                try
                {
                    strTime = DateTimeUtil.Rfc1123DateTimeStringToLocal(strLogCreateTime, "u");
                }
                catch
                {
                }
            }

            if (DateTime.TryParse(strTime, out DateTime createTime) == true)
            {
                line.CreateTime = createTime;
            }
            return(0);
        }
Пример #12
0
        public static List <XmlNode> GetNodes(XmlNode root,
                                              string strCfgItemPath)
        {
            Debug.Assert(root != null, "GetNodes()调用错误,root参数值不能为null。");
            Debug.Assert(strCfgItemPath != null && strCfgItemPath != "", "GetNodes()调用错误,strCfgItemPath不能为null。");


            List <XmlNode> nodes = new List <XmlNode>();

            //把strpath用'/'分开
            string[] paths = strCfgItemPath.Split(new char[] { '/' });
            if (paths.Length == 0)
            {
                return(nodes);
            }

            int i = 0;

            if (paths[0] == "")
            {
                i = 1;
            }
            XmlNode nodeCurrent = root;

            for (; i < paths.Length; i++)
            {
                string strName = paths[i];

                bool bFound = false;
                foreach (XmlNode child in nodeCurrent.ChildNodes)
                {
                    if (child.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    bool bThisFound = false;

                    if (String.Compare(child.Name, "database", true) == 0)
                    {
                        string strAllCaption = DatabaseUtil.GetAllCaption(child);
                        if (StringUtil.IsInList(strName, strAllCaption) == true)
                        {
                            bFound     = true;
                            bThisFound = true;
                        }
                        else
                        {
                            bThisFound = false;
                        }
                    }
                    else
                    {
                        string strChildName = DomUtil.GetAttr(child, "name");
                        if (String.Compare(strName, strChildName, true) == 0)
                        {
                            bFound     = true;
                            bThisFound = true;
                        }
                        else
                        {
                            bThisFound = false;
                        }
                    }

                    if (bThisFound == true)
                    {
                        if (i == paths.Length - 1)
                        {
                            nodes.Add(child);
                        }
                        else
                        {
                            nodeCurrent = child;
                            break;
                        }
                    }
                }

                // 本级未找到,跳出循环
                if (bFound == false)
                {
                    break;
                }
            }

            return(nodes);
        }
Пример #13
0
        // 修改用户密码。这是指用户修改自己帐户的密码,需提供旧密码
        // return:
        //      -1  error
        //      0   succeed
        public int ChangeUserPassword(
            string strLibraryCodeList,
            string strUserName,
            string strOldPassword,
            string strNewPassword,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (String.IsNullOrEmpty(strUserName) == true)
            {
                strError = "strUserName参数值不能为空";
                return(-1);
            }

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                // 查重
                XmlNode node = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//accounts/account[@name='" + strUserName + "']");
                if (node == null)
                {
                    strError = "用户 '" + strUserName + "' 不存在";
                    return(-1);
                }

                string strExistLibraryCodeList = DomUtil.GetAttr(node, "libraryCode");

                // 2012/9/9
                // 分馆用户只允许修改馆代码属于管辖分馆的帐户
                if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
                {
                    if (string.IsNullOrEmpty(strExistLibraryCodeList) == true ||
                        IsListInList(strExistLibraryCodeList, strLibraryCodeList) == false)
                    {
                        strError = "当前用户只能修改图书馆代码完全完全属于 '" + strLibraryCodeList + "' 范围的用户的密码";
                        return(-1);
                    }
                }

                // 验证旧密码
#if NO
                // 以前的做法
                string strExistPassword = DomUtil.GetAttr(node, "password");
                if (String.IsNullOrEmpty(strExistPassword) == false)
                {
                    try
                    {
                        strExistPassword = Cryptography.Decrypt(strExistPassword,
                                                                EncryptKey);
                    }
                    catch
                    {
                        strError = "已经存在的(加密后)密码格式不正确";
                        return(-1);
                    }
                }

                if (strExistPassword != strOldPassword)
                {
                    strError = "所提供的旧密码经验证不匹配";
                    return(-1);
                }
#endif
                string strExistPassword = DomUtil.GetAttr(node, "password");
                nRet = LibraryServerUtil.MatchUserPassword(strOldPassword, strExistPassword, out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                if (nRet == 0)
                {
                    strError = "所提供的旧密码经验证不匹配";
                    return(-1);
                }

                // 设置新密码
#if NO
                // 以前的做法
                strNewPassword = Cryptography.Encrypt(strNewPassword,
                                                      EncryptKey);
                DomUtil.SetAttr(node, "password", strNewPassword);
#endif
                string strHashed = "";
                nRet = LibraryServerUtil.SetUserPassword(strNewPassword, out strHashed, out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                DomUtil.SetAttr(node, "password", strHashed);

                this.Changed = true;

                return(0);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }

            // return 0;
        }
Пример #14
0
        // 列出指定的用户
        // parameters:
        //      strUserName 用户名。如果为空,表示列出全部用户名
        // return:
        //      -1  出错
        //      其他    用户总数(不是本批的个数)
        public int ListUsers(
            string strLibraryCodeList,
            string strUserName,
            int nStart,
            int nCount,
            out UserInfo[] userinfos,
            out string strError)
        {
            this.m_lock.AcquireReaderLock(m_nLockTimeout);
            try
            {
                strError  = "";
                userinfos = null;

                string strXPath = "";

                if (String.IsNullOrEmpty(strUserName) == true)
                {
                    strXPath = "//accounts/account";
                }
                else
                {
                    strXPath = "//accounts/account[@name='" + strUserName + "']";
                }

                List <UserInfo> userList = new List <UserInfo>();

                XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes(strXPath);

                // 过滤为当前能管辖的小范围node数组
                List <XmlNode> smallerlist = new List <XmlNode>();
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node = nodes[i];

                    // 2012/9/9
                    // 分馆用户只允许列出管辖分馆的所有用户
                    if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
                    {
                        string strCurrentLibraryCodeList = DomUtil.GetAttr(node, "libraryCode");
                        // TODO: 帐户定义中的馆代码列表中不允许 ,, 这样的情况
                        if (IsListInList(strCurrentLibraryCodeList, strLibraryCodeList) == false)
                        {
                            continue;
                        }
                    }

                    smallerlist.Add(node);
                }

                if (nCount == -1)
                {
                    nCount = Math.Max(0, smallerlist.Count - nStart);
                }
                nCount = Math.Min(100, nCount);                                             // 限制每批最多100个

                for (int i = nStart; i < Math.Min(nStart + nCount, smallerlist.Count); i++) //
                {
                    XmlNode node = smallerlist[i];

                    string strCurrentLibraryCodeList = DomUtil.GetAttr(node, "libraryCode");

                    UserInfo userinfo = new UserInfo();
                    userinfo.UserName    = DomUtil.GetAttr(node, "name");
                    userinfo.Type        = DomUtil.GetAttr(node, "type");
                    userinfo.Rights      = DomUtil.GetAttr(node, "rights");
                    userinfo.LibraryCode = strCurrentLibraryCodeList;
                    userinfo.Access      = DomUtil.GetAttr(node, "access");
                    userinfo.Comment     = DomUtil.GetAttr(node, "comment");

                    userList.Add(userinfo);
                }

                userinfos = new UserInfo[userList.Count];
                userList.CopyTo(userinfos);

                return(smallerlist.Count);
            }
            finally
            {
                this.m_lock.ReleaseReaderLock();
            }
        }
Пример #15
0
        // 检索同类记录
        public LibraryServerResult SearchUsedZhongcihao(
            SessionInfo sessioninfo,
            string strZhongcihaoGroupName,
            string strClass,
            string strResultSetName,
            out string strQueryXml)
        {
            strQueryXml = "";

            string strError = "";

            LibraryServerResult result = new LibraryServerResult();

            if (String.IsNullOrEmpty(strZhongcihaoGroupName) == true)
            {
                strError = "strZhongcihaoGroupName参数值不能为空";
                goto ERROR1;
            }

            if (strZhongcihaoGroupName[0] == '!')
            {
                string strTemp = GetZhongcihaoGroupName(strZhongcihaoGroupName.Substring(1));

                if (strTemp == null)
                {
                    strError = "书目库名 " + strZhongcihaoGroupName.Substring(1) + " 没有找到对应的种次号组名";
                    goto ERROR1;
                }
                strZhongcihaoGroupName = strTemp;
            }


            XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes("//zhongcihao/group[@name='" + strZhongcihaoGroupName + "']/database");

            if (nodes.Count == 0)
            {
                strError = "library.xml中尚未配置有关 '" + strZhongcihaoGroupName + "'的<zhongcihao>/<group>/<database>相关参数";
                goto ERROR1;
            }

            // 构造检索式
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node      = nodes[i];
                string  strDbName = DomUtil.GetAttr(node, "name");

                if (string.IsNullOrEmpty(strDbName) == true)
                {
                    strError = "<database>元素必须有非空的name属性值";
                    goto ERROR1;
                }

                Debug.Assert(String.IsNullOrEmpty(strDbName) == false, "");

                if (i > 0)
                {
                    Debug.Assert(String.IsNullOrEmpty(strQueryXml) == false, "");
                    strQueryXml += "<operator value='OR'/>";
                }

                strQueryXml += "<target list='"
                               + StringUtil.GetXmlStringSimple(strDbName + ":" + "索取号") // 2007/9/14
                               + "'><item><word>"
                               + StringUtil.GetXmlStringSimple(strClass) + "/"
                               + "</word><match>left</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang></target>";
            }

            if (nodes.Count > 0)
            {
                strQueryXml = "<group>" + strQueryXml + "</group>";
            }

            RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);

            if (channel == null)
            {
                strError = "get channel error";
                goto ERROR1;
            }

            long lRet = channel.DoSearch(strQueryXml,
                                         strResultSetName, // "default",
                                         "keyid",          // strOuputStyle
                                         out strError);

            if (lRet == -1)
            {
                goto ERROR1;
            }

            if (lRet == 0)
            {
                result.Value     = 0;
                result.ErrorInfo = "not found";
                result.ErrorCode = ErrorCode.NotFound;
                return(result);
            }


            result.Value = lRet;
            return(result);

ERROR1:
            result.Value     = -1;
            result.ErrorCode = ErrorCode.SystemError;
            result.ErrorInfo = strError;
            return(result);
        }
Пример #16
0
        // 将包含虚拟库要求的XML检索式变换为内核能够理解的实在库XML检索式
        // return:
        //      -1  error
        //      0   没有发生变化
        //      1   发生了变化
        public int KernelizeXmlQuery(string strSourceQueryXml,
                                     out string strTargetQueryXml,
                                     out string strError)
        {
            strTargetQueryXml = "";
            strError          = "";
            int nRet = 0;

            Debug.Assert(this.vdbs != null, "");

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strSourceQueryXml);
            }
            catch (Exception ex)
            {
                strError = "XML检索式装入XMLDOM时出错: " + ex.Message;
                return(-1);
            }

            bool bChanged = false;

            // 遍历所有<target>元素

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("//target");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node    = nodes[i];
                string  strList = DomUtil.GetAttr(node, "list");

                if (String.IsNullOrEmpty(strList) == true)
                {
                    continue;
                }

                string strOutputList = "";
                // 变换list参数值,将其中的虚拟库(连带途径)变换为物理库和途径
                // parameters:
                // return:
                //      -1  error
                //      0   没有发生变化
                //      1   发生了变化
                nRet = ConvertList(strList,
                                   out strOutputList,
                                   out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                if (nRet == 0)
                {
                    continue;
                }

                bChanged = true;
                DomUtil.SetAttr(node, "list", strOutputList);
            }

            if (bChanged == false)
            {
                strTargetQueryXml = strSourceQueryXml;
                return(0);
            }

            strTargetQueryXml = dom.OuterXml;
            return(1);
        }
Пример #17
0
        // ????目前不支持数据库的多语言版本
        // 为CheckRights()服务的底层函数
        // 根据资源路径创建权限数组
        // parameters:
        //      strPath     资源路径
        //      aRights     out参数,返回权限数组成
        //      strError    out参数,返回出错信息
        // return:
        //      -1  出错
        //      0   成功
        private int BuildRightArray(
            string strPath,
            List <string> aOwnerDbName,
            string strUserName,
            out List <string> aRights,
            out string strError)
        {
            strError = "";

            aRights = new List <string>();

            string strRights = "";

            // 把根定义的权限加到数组里
            strRights = DomUtil.GetAttr(this.nodeRoot, "rights");
            aRights.Add(strRights);

            if (strPath == "")
            {
                return(0);
            }

            string[] paths = strPath.Split(new char[] { '/' });
            Debug.Assert(paths.Length > 0, "此时数组长度不可能为0。");
            if (paths[0] == "" || paths[paths.Length - 1] == "")
            {
                strError = "路径'" + strPath + "'不合法,首尾不能为'/'。";
                return(-1);
            }

            XmlNode nodeCurrent = this.nodeRoot;

            // 循环下级
            for (int i = 0; i < paths.Length; i++)
            {
                string strName = paths[i];
                bool   bFound  = false;

                if (nodeCurrent == null)
                {
                    aRights.Add("");
                    continue;
                }

                foreach (XmlNode child in nodeCurrent.ChildNodes)
                {
                    if (child.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    string strChildName = DomUtil.GetAttr(child, "name");

                    if (String.Compare(strName, strChildName, true) == 0)
                    {
                        bFound      = true;
                        nodeCurrent = child;
                        break;
                    }
                }

                bool bDbo = false;
                if (i == 0)   // 数据库层次
                {
                    if (aOwnerDbName.IndexOf(strName) != -1)
                    {
                        bDbo = true;
                    }
                }

                strRights = "";

                // 为dbo增加特殊权限
                if (bDbo == true)
                {
                    strRights += "this:management;children_database:management;children_directory:management;children_leaf:management;descendant_directory:management;descendant_record:management;descendant_leaf:management";
                }

                if (bFound == false)
                {
                    aRights.Add(strRights);
                    nodeCurrent = null;
                    continue;
                }

                // 实际定义的权限
                if (nodeCurrent != null)
                {
                    string strTemp = DomUtil.GetAttr(nodeCurrent, "rights");
                    if (String.IsNullOrEmpty(strTemp) == false)
                    {
                        if (strRights != "")
                        {
                            strRights += ";";
                        }
                        strRights += strTemp;
                    }
                }

                aRights.Add(strRights);
            }
            return(0);
        }
Пример #18
0
        // 检查检索式内有没有超越规定读者检索的数据库
        // return:
        //      -1  error
        //      0   没有超越要求
        //      1   超越了要求
        public int CheckReaderOnlyXmlQuery(string strSourceQueryXml,
                                           out string strError)
        {
            strError = "";
            // int nRet = 0;

#if NO
            if (this.vdbs == null)
            {
                this.ActivateManagerThreadForLoad();
                strError = "app.vdbs == null。故障原因请检查dp2Library日志";
                return(-1);
            }

            Debug.Assert(this.vdbs != null, "");
#endif

            XmlDocument dom = new XmlDocument();
            try
            {
                dom.LoadXml(strSourceQueryXml);
            }
            catch (Exception ex)
            {
                strError = "XML检索式装入XMLDOM时出错: " + ex.Message;
                return(-1);
            }

            // 遍历所有<target>元素
            XmlNodeList nodes = dom.DocumentElement.SelectNodes("//target");
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node    = nodes[i];
                string  strList = DomUtil.GetAttr(node, "list");

                if (String.IsNullOrEmpty(strList) == true)
                {
                    continue;
                }

                DbCollection dbs = new DbCollection();

                dbs.Build(strList);

                for (int j = 0; j < dbs.Count; j++)
                {
                    Db db = dbs[j];

                    // 允许预约到书库 2015/6/14
                    if (db.DbName == this.ArrivedDbName)
                    {
                        continue;
                    }

                    string strBiblioDbName = "";
                    string strDbType       = this.GetDbType(db.DbName,
                                                            out strBiblioDbName);
                    if (String.IsNullOrEmpty(strDbType) == true)
                    {
                        strError = "数据库 '" + db.DbName + "' 超出了读者可检索的数据库范围";
                        return(1);
                    }
                }
            }

            return(0);
        }
Пример #19
0
        // 初始化数据库和From的一些属性, 以便将来运行起来快速方便
        // 在<database>元素下要插入若干<from>元素
        // 这些信息属于软件初始化的范畴, 避免人工去配置
        public int InitialAllProperty(
            ResInfoItem[] root_dir_results,
            Hashtable db_dir_results,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (nodeDatabase == null)
            {
                strError = "nodeDatabase尚未设置值";
                return(-1);
            }

            if (this.IsVirtual != false)
            {
                strError = "该函数只适用于<database>元素的初始化";
                return(-1);
            }

            string strDbName = DomUtil.GetAttr(nodeDatabase, "name");

            RemoveChildren(nodeDatabase);

            ResInfoItem dbitem = KernelDbInfo.GetDbItem(
                root_dir_results,
                strDbName);

            if (dbitem == null)
            {
                strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项";
                return(-1);
            }

            // 在下级加入<caption>元素
            for (int i = 0; i < dbitem.Names.Length; i++)
            {
                string strText = dbitem.Names[i];
                nRet = strText.IndexOf(":");
                if (nRet == -1)
                {
                    strError = "names字符串 '" + strText + "' 格式不正确。";
                    return(-1);
                }
                string strLang = strText.Substring(0, nRet);
                string strName = strText.Substring(nRet + 1);

                XmlNode newnode = nodeDatabase.OwnerDocument.CreateElement("caption");
                newnode = nodeDatabase.AppendChild(newnode);
                DomUtil.SetAttr(newnode, "lang", strLang);
                DomUtil.SetNodeText(newnode, strName);
            }

            //
            ResInfoItem[] fromitems = (ResInfoItem[])db_dir_results[strDbName];
            if (fromitems == null)
            {
                strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项";
                return(-1);
            }

            for (int i = 0; i < fromitems.Length; i++)
            {
                ResInfoItem item = fromitems[i];
                if (item.Type != ResTree.RESTYPE_FROM)
                {
                    continue;
                }

                // 插入<from>元素
                XmlNode fromnode = nodeDatabase.OwnerDocument.CreateElement("from");
                fromnode = nodeDatabase.AppendChild(fromnode);
                DomUtil.SetAttr(fromnode, "name", item.Name);    // 当前工作语言下的名字

                if (item.Names == null)
                {
                    continue;
                }

                // 插入caption
                for (int j = 0; j < item.Names.Length; j++)
                {
                    string strText = item.Names[j];
                    nRet = strText.IndexOf(":");
                    if (nRet == -1)
                    {
                        strError = "names字符串 '" + strText + "' 格式不正确。";
                        return(-1);
                    }

                    string strLang = strText.Substring(0, nRet);
                    string strName = strText.Substring(nRet + 1);

                    XmlNode newnode = fromnode.OwnerDocument.CreateElement("caption");
                    newnode = fromnode.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

            return(0);
        }
Пример #20
0
        // 将 XML 检索式变化为简明格式检索式
        public static int GetQueryString(
            FromCollection Froms,
            string strQueryXml,
            IsbnConvertInfo isbnconvertinfo,
            out string strQueryString,
            out string strError)
        {
            strError       = "";
            strQueryString = "";

            if (String.IsNullOrEmpty(strQueryXml) == true)
            {
                return(0);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strQueryXml);
            }
            catch (Exception ex)
            {
                strError = "strQueryXml装入XMLDOM时出错: " + ex.Message;
                return(-1);
            }

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("line");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node     = nodes[i];
                string  strLogic = DomUtil.GetAttr(node, "logic");
                string  strWord  = DomUtil.GetAttr(node, "word");
                string  strFrom  = DomUtil.GetAttr(node, "from");

                if (strWord == "")
                {
                    continue;
                }

                strLogic = GetLogicString(strLogic);    // 2011/8/30

                if (strQueryString != "")
                {
                    strQueryString += " " + strLogic + " ";
                }

                int nRet = strFrom.IndexOf("-");
                if (nRet != -1)
                {
                    strFrom = strFrom.Substring(0, nRet).Trim();
                }

                string strValue = Froms.GetValue(strFrom);
                if (strValue == null)
                {
                    strError = "名称 '" + strFrom + "' 在use表中没有找到对应的编号";
                    return(-1);
                }

                // 对ISBN检索词进行预处理
                if (strFrom == "ISBN" &&
                    isbnconvertinfo != null)
                {
                    /*
                     * // return:
                     * //      -1  出错
                     * //      0   没有必要转换
                     * //      1   已经转换
                     * nRet = isbnconvertinfo.ConvertISBN(ref strWord,
                     * out strError);
                     * if (nRet == -1)
                     * {
                     *  strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                     *  return -1;
                     * }
                     * */
                    List <string> isbns = null;
                    // return:
                    //      -1  出错
                    //      0   没有必要转换
                    //      1   已经转换
                    nRet = isbnconvertinfo.ConvertISBN(strWord,
                                                       out isbns,
                                                       out strError);
                    if (nRet == -1)
                    {
                        strError = "在处理ISBN字符串 '" + strWord + "' 过程中出错: " + strError;
                        return(-1);
                    }

                    int j = 0;
                    foreach (string isbn in isbns)
                    {
                        if (j > 0)
                        {
                            strQueryString += " OR ";
                        }
                        // string strIsbn = isbn.Replace("\"", "\\\"");    // 字符 " 替换为 \"
                        string strIsbn = StringUtil.EscapeString(isbn, "\"/=");    // eacape 特殊字符
                        strQueryString += "\""
                                          + strIsbn + "\"" + "/1="
                                          + strValue;
                        j++;
                    }
                    continue;
                }

                // strWord = strWord.Replace("\"", "\\\""); // 字符 " 替换为 \"
                strWord         = StringUtil.EscapeString(strWord, "\"/="); // eacape 特殊字符
                strQueryString += "\""
                                  + strWord + "\"" + "/1="
                                  + strValue;
            }

            return(1);
        }
Пример #21
0
        // 从特定的数据库中, 匹配出满足特定风格列表的from列表
        // parameters:
        //      strFromStyle    from style的列表, 以逗号分割。
        //                      如果为空,表示全部途径(2007/9/13)
        // return:
        //      null    没有找到
        //      以逗号分割的from名列表
        public string BuildCaptionListByStyleList(
            string strFromStyles,
            string strLang)
        {
            if (String.IsNullOrEmpty(strFromStyles) == true ||
                strFromStyles == "<全部>" || strFromStyles.ToLower() == "<all>")
            {
                return("<all>");
                // strFromStyles = "<all>";
            }

            XmlNodeList nodes = null;

            string strResult = "";

            // 拆分出单独的style字符串
            string[] styles = strFromStyles.Split(new char[] { ',' });

            for (int i = 0; i < styles.Length; i++)
            {
                string strStyle = styles[i].Trim();
                if (String.IsNullOrEmpty(strStyle) == true)
                {
                    continue;
                }

                // 忽略 _time/_freetime,_rfc1123time/_utime等表示检索特性的style
                if (StringUtil.HasHead(strStyle, "_") == true &&
                    StringUtil.HasHead(strStyle, "__") == false)
                {
                    continue;
                }

                if (nodes == null)  // 滞后获取
                {
                    nodes = this.nodeDatabase.SelectNodes("from");
                }

                foreach (XmlNode node in nodes)
                {
                    string strStyles = DomUtil.GetAttr(node, "style");
                    if (StringUtil.IsInList(strStyle, strStyles) == true ||
                        strStyle == "<all>") // 注:后来发现内核本来就支持<all>的from后,这里就没有必要了,但是代码仍保留
                    {
                        // 从一个元素的下级<caption>元素中, 提取语言符合的文字值
                        string strValue = DomUtil.GetCaption(strLang,
                                                             node);
                        if (strValue == null)
                        {
                            // 只好用中立语言的名字
                            string strName = DomUtil.GetAttr(node, "name");
                            if (string.IsNullOrEmpty(strName) == false)
                            {
                                return(strName);
                            }

                            throw new Exception("数据库 '" + this.GetName(strLang) + "' 中没有找到style为 " + strStyles + " 的From事项的任何Caption");
                        }

                        // 全部路径情况下,要不包含"__id"途径
                        if (strStyle == "<all>" &&
                            strValue == "__id")
                        {
                            continue;
                        }

                        if (strResult != "")
                        {
                            strResult += ",";
                        }

                        strResult += strValue;
                    }
                }
            }

            return(strResult);
        }
Пример #22
0
        public static int Build(XmlDocument dom,
                                out LabelParam label_param,
                                out string strError)
        {
            strError = "";
            int nRet = 0;

            label_param = new LabelParam();

            XmlNode label = dom.DocumentElement.SelectSingleNode("label");

            if (label != null)
            {
                // int nValue = 0;
                double fValue = 0;

                // width
                nRet = DomUtil.GetDoubleParam(label,
                                              "width",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LabelWidth = fValue;

                // height
                nRet = DomUtil.GetDoubleParam(label,
                                              "height",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LabelHeight = fValue;

                // lineSep
                nRet = DomUtil.GetDoubleParam(label,
                                              "lineSep",
                                              0,
                                              out fValue,
                                              out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                label_param.LineSep = fValue;

                {
                    DecimalPadding margins;
                    string         strPaddings = DomUtil.GetAttr(label, "paddings");
                    nRet = GetMarginValue(
                        strPaddings,
                        out margins,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "<label>元素paddings属性值格式错误: " + strError;
                        return(-1);
                    }
                    label_param.LabelPaddings = margins;
                }
#if NO
                try
                {
                    string strPaddings = DomUtil.GetAttr(label, "paddings");

                    string[] parts = strPaddings.Split(new char[] { ',' });
                    if (parts.Length > 0)
                    {
                        label_param.LabelPaddings.Left = Convert.ToInt32(parts[0]);
                    }
                    if (parts.Length > 1)
                    {
                        label_param.LabelPaddings.Top = Convert.ToInt32(parts[1]);
                    }
                    if (parts.Length > 2)
                    {
                        label_param.LabelPaddings.Right = Convert.ToInt32(parts[2]);
                    }
                    if (parts.Length > 3)
                    {
                        label_param.LabelPaddings.Bottom = Convert.ToInt32(parts[3]);
                    }
                }
                catch (Exception ex)
                {
                    strError = "<label>元素paddings属性值格式错误: " + ex.Message;
                    return(-1);
                }
#endif

                string strFont = DomUtil.GetAttr(label, "font");
                if (String.IsNullOrEmpty(strFont) == false)
                {
                    if (Global.IsVirtualBarcodeFont(ref strFont) == true)
                    {
                        label_param.IsBarcodeFont = true;
                    }

                    try
                    {
                        label_param.Font = Global.BuildFont(strFont);
                    }
                    catch (Exception ex)
                    {
                        strError = "<label>元素 font 属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }
            }


            XmlNode page = dom.DocumentElement.SelectSingleNode("page");
            if (page != null)
            {
                {
                    // int nValue = 0;
                    double fValue = 0;

                    // width
                    nRet = DomUtil.GetDoubleParam(page,
                                                  "width",
                                                  0,
                                                  out fValue,
                                                  out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    label_param.PageWidth = fValue;

                    // height
                    nRet = DomUtil.GetDoubleParam(page,
                                                  "height",
                                                  0,
                                                  out fValue,
                                                  out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    label_param.PageHeight = fValue;
                }

                {
                    DecimalPadding margins;
                    string         strMargins = DomUtil.GetAttr(page, "margins");
                    nRet = GetMarginValue(
                        strMargins,
                        out margins,
                        out strError);
                    if (nRet == -1)
                    {
                        strError = "<page>元素margins属性值格式错误: " + strError;
                        return(-1);
                    }
                    label_param.PageMargins = margins;
                }
#if NO
                try
                {
                    string   strMargins = DomUtil.GetAttr(page, "margins");
                    string[] parts      = strMargins.Split(new char[] { ',' });
                    if (parts.Length > 0)
                    {
                        label_param.PageMargins.Left = Convert.ToInt32(parts[0]);
                    }
                    if (parts.Length > 1)
                    {
                        label_param.PageMargins.Top = Convert.ToInt32(parts[1]);
                    }
                    if (parts.Length > 2)
                    {
                        label_param.PageMargins.Right = Convert.ToInt32(parts[2]);
                    }
                    if (parts.Length > 3)
                    {
                        label_param.PageMargins.Bottom = Convert.ToInt32(parts[3]);
                    }
                }
                catch (Exception ex)
                {
                    strError = "<page>元素margins属性值格式错误: " + ex.Message;
                    return(-1);
                }
#endif

                label_param.DefaultPrinter = DomUtil.GetAttr(page, "defaultPrinter");

#if NO
                bool bValue = false;
                nRet = DomUtil.GetBooleanParam(page,
                                               "landscape",
                                               false,
                                               out bValue,
                                               out strError);
                if (nRet == -1)
                {
                    strError = "<page> 元素的 landscape 属性错误: " + strError;
                    return(-1);
                }
                label_param.Landscape = bValue;
#endif
                int nValue = 0;
                DomUtil.GetIntegerParam(page,
                                        "rotate",
                                        0,
                                        out nValue,
                                        out strError);
                if (nRet == -1)
                {
                    strError = "<page> 元素的 rotate 属性错误: " + strError;
                    return(-1);
                }
                label_param.RotateDegree = nValue;
            }

            XmlNodeList nodes = dom.DocumentElement.SelectNodes("lineFormats/line");
            label_param.LineFormats = new List <LineFormat>();
            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node    = nodes[i];
                string  strFont = DomUtil.GetAttr(node, "font");

                LineFormat format = new LineFormat();

                if (Global.IsVirtualBarcodeFont(ref strFont) == true)
                {
                    format.IsBarcodeFont = true;
                }

                if (string.IsNullOrEmpty(strFont) == false)
                {
                    try
                    {
                        format.Font = Global.BuildFont(strFont);
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素font属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }
                else
                {
                    format.Font = null; // 继承页面的字体
                }
                format.Align = DomUtil.GetAttr(node, "align");
                format.Style = DomUtil.GetAttr(node, "style");

                string strOffset = DomUtil.GetAttr(node, "offset");
                if (string.IsNullOrEmpty(strOffset) == false)
                {
                    try
                    {
                        double left  = 0;
                        double right = 0;
                        ParsetTwoDouble(strOffset,
                                        false,
                                        out left,
                                        out right);
                        format.OffsetX = left;
                        format.OffsetY = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素offset属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                string strStart = DomUtil.GetAttr(node, "start");
                if (string.IsNullOrEmpty(strStart) == false)
                {
                    try
                    {
                        double left  = double.NaN;
                        double right = double.NaN;
                        ParsetTwoDouble(strStart,
                                        true,
                                        out left,
                                        out right);
                        format.StartX = left;
                        format.StartY = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素start属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                string strSize = DomUtil.GetAttr(node, "size");
                if (string.IsNullOrEmpty(strSize) == false)
                {
                    try
                    {
                        double left  = double.NaN;
                        double right = double.NaN;
                        ParsetTwoDouble(strSize,
                                        true,
                                        out left,
                                        out right);
                        format.Width  = left;
                        format.Height = right;
                    }
                    catch (Exception ex)
                    {
                        strError = "<line>元素size属性值格式错误: " + ex.Message;
                        return(-1);
                    }
                }

                format.ForeColor = DomUtil.GetAttr(node, "foreColor");
                format.BackColor = DomUtil.GetAttr(node, "backColor");

                label_param.LineFormats.Add(format);
            }

            return(0);
        }
Пример #23
0
        public int Initial(ManagerForm managerform,
                           bool bCreateMode,
                           string strXml,
                           out string strError)
        {
            strError = "";

            this.ManagerForm = managerform;
            this.CreateMode  = bCreateMode;

            this.Xml = strXml;

            // 填充窗口内容
            if (String.IsNullOrEmpty(strXml) == false)
            {
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strXml);
                }
                catch (Exception ex)
                {
                    strError = "XML装载到DOM时出错: " + ex.Message;
                    return(-1);
                }

                // 虚拟库名captions
                XmlNodeList nodes          = dom.DocumentElement.SelectNodes("caption");
                string      strCaptionsXml = "";
                for (int i = 0; i < nodes.Count; i++)
                {
                    strCaptionsXml += nodes[i].OuterXml;
                }

                if (String.IsNullOrEmpty(strCaptionsXml) == false)
                {
                    this.captionEditControl_virtualDatabaseName.Xml = strCaptionsXml;
                }

                // 成员库
                nodes = dom.DocumentElement.SelectNodes("database");
                string strMemberDatabaseNames = "";
                for (int i = 0; i < nodes.Count; i++)
                {
                    strMemberDatabaseNames += DomUtil.GetAttr(nodes[i], "name") + "\r\n";
                }
                this.textBox_memberDatabases.Text = strMemberDatabaseNames;

                // froms定义
                nodes = dom.DocumentElement.SelectNodes("from");
                string strFromsXml = "";
                for (int i = 0; i < nodes.Count; i++)
                {
                    strFromsXml += nodes[i].OuterXml;
                }
                if (String.IsNullOrEmpty(strFromsXml) == false)
                {
                    this.fromEditControl1.Xml = strFromsXml;
                }
            }

            return(0);
        }
Пример #24
0
        // 根据册条码号在一系列可能的实体库中检索出册信息,
        // 然后提取出有关种的信息
        int GetLinkInfoFromBarcode(string strBarcode,
                                   bool bDetectDup,
                                   out List <DoublePath> paths,
                                   out string strError)
        {
            strError = "";
            // strBiblioRecPath = "";
            // strItemRecPath = "";

            paths = new List <DoublePath>();

            string strBiblioRecPath = "";
            string strItemRecPath   = "";

            // 获得cfgs/global配置文件
            int nRet = GetGlobalCfgFile(out strError);

            if (nRet == -1)
            {
                return(-1);
            }

            // 列出所有<dblink>配置事项
            XmlNodeList nodes = this.dom.DocumentElement.SelectNodes("//dblink");

            if (nodes.Count == 0)
            {
                strError = "cfgs/global配置文件中,尚未配置任何<dblink>元素。";
                return(-1);
            }


            this.SearchPanel.BeginLoop("正在检索 " + strBarcode + " 所对应的册信息...");
            try
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node            = nodes[i];
                    string  strBiblioDbName = DomUtil.GetAttr(node, "bibliodb");
                    string  strItemDbName   = DomUtil.GetAttr(node, "itemdb");

                    // 2007/4/5 改造 加上了 GetXmlStringSimple()
                    string strQueryXml = "<target list='"
                                         + StringUtil.GetXmlStringSimple(strItemDbName + ":" + "册条码") // 2007/9/14
                                         + "'><item><word>"
                                         + StringUtil.GetXmlStringSimple(strBarcode)
                                         + "</word><match>exact</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>" + this.Lang + "</lang></target>";

                    // strItemRecPath = "";

                    nRet = this.SearchPanel.SearchMultiPath(
                        this.ServerUrl,
                        strQueryXml,
                        1000,
                        out List <string> aPath,
                        out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }
                    if (nRet == 0)
                    {
                        continue;
                    }

                    for (int j = 0; j < aPath.Count; j++)
                    {
                        strItemRecPath = aPath[j];

                        XmlDocument tempdom     = null;
                        byte[]      baTimestamp = null;
                        // 提取册记录
                        nRet = this.SearchPanel.GetRecord(
                            this.ServerUrl,
                            strItemRecPath,
                            out tempdom,
                            out baTimestamp,
                            out strError);
                        if (nRet == -1)
                        {
                            strError = "提取册记录 " + strItemRecPath + " 时发生错误:" + strError;
                            return(-1);
                        }

                        strBiblioRecPath = strBiblioDbName + "/" + DomUtil.GetElementText(tempdom.DocumentElement, "parent");

                        DoublePath dpath = new DoublePath();
                        dpath.ItemRecPath   = strItemRecPath;
                        dpath.BiblioRecPath = strBiblioRecPath;

                        paths.Add(dpath);
                    }

                    // 如果不需要查重,则遇到命中后尽快退出循环
                    if (bDetectDup == false && paths.Count >= 1)
                    {
                        return(paths.Count);
                    }
                }

                return(paths.Count);
            }
            finally
            {
                this.SearchPanel.EndLoop();
            }
        }
Пример #25
0
        // 读入<biblioDbGroup>相关配置
        // return:
        //      <biblioDbGroup>元素下<database>元素的个数。如果==0,表示配置不正常
        public int LoadBiblioDbGroupParam(
            out string strError)
        {
            strError = "";

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                XmlDocument dom = this.OpacCfgDom;

                this.ItemDbs = new List <ItemDbCfg>();

                XmlNodeList nodes = dom.DocumentElement.SelectNodes("//biblioDbGroup/database");

                if (nodes.Count == 0)
                {
                    return(0);
                }

                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node = nodes[i];

                    ItemDbCfg item = new ItemDbCfg();

                    item.DbName = DomUtil.GetAttr(node, "itemDbName");

                    item.BiblioDbName = DomUtil.GetAttr(node, "biblioDbName");

                    item.BiblioDbSyntax = DomUtil.GetAttr(node, "syntax");

                    item.IssueDbName = DomUtil.GetAttr(node, "issueDbName");

                    item.OrderDbName = DomUtil.GetAttr(node, "orderDbName");

                    item.CommentDbName = DomUtil.GetAttr(node, "commentDbName");

                    item.UnionCatalogStyle = DomUtil.GetAttr(node, "unionCatalogStyle");

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

                    item.InCirculation = bValue;

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

                    this.ItemDbs.Add(item);
                }

                return(nodes.Count);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }
Пример #26
0
        // 获得种次号尾号
        public LibraryServerResult GetZhongcihaoTailNumber(
            SessionInfo sessioninfo,
            string strZhongcihaoGroupName,
            string strClass,
            out string strTailNumber)
        {
            strTailNumber = "";

            string strError = "";

            LibraryServerResult result = new LibraryServerResult();

            if (String.IsNullOrEmpty(strZhongcihaoGroupName) == true)
            {
                strError = "种次号组名参数值不能为空";
                goto ERROR1;
            }

            RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);

            if (channel == null)
            {
                strError = "get channel error";
                goto ERROR1;
            }

            string strPath = "";
            string strXml  = "";

            byte[] timestamp = null;
            // 检索尾号记录的路径和记录体
            // return:
            //      -1  error
            //      0   not found
            //      1   found
            int nRet = SearchTailNumberPathAndRecord(
                // sessioninfo.Channels,
                channel,
                strZhongcihaoGroupName,
                strClass,
                out strPath,
                out strXml,
                out timestamp,
                out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }

            if (nRet == 0)
            {
                result.ErrorCode = ErrorCode.NotFound;
                result.ErrorInfo = strError;
                result.Value     = 0;
                return(result);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "尾号记录 '" + strPath + "' XML装入DOM时发生错误: " + ex.Message;
                goto ERROR1;
            }

            strTailNumber = DomUtil.GetAttr(dom.DocumentElement, "v");

            result.Value = 1;
            return(result);

ERROR1:
            result.Value     = -1;
            result.ErrorCode = ErrorCode.SystemError;
            result.ErrorInfo = strError;
            return(result);
        }
Пример #27
0
    void DisplayNode(string strDataFileName, string strNodePath)
    {
        int    nRet     = 0;
        string strError = "";

        this.BrowseSearchResultControl1.SelectAll(false);

        string      strXmlFilePath = app.DataDir + "/browse/" + strDataFileName;
        XmlDocument dom            = new XmlDocument();

        dom.Load(strXmlFilePath);

        // 2014/12/2
        // 兑现宏
        nRet = CacheBuilder.MacroDom(dom,
                                     new List <string> {
            "name", "command"
        },
                                     out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        XmlNode node = null;

        if (string.IsNullOrEmpty(strNodePath) == true)
        {
            // 找到第一个节点
            node = GetFirstNode(dom.DocumentElement);
            if (node == null)
            {
                return;
            }
            strNodePath = CacheBuilder.MakeNodePath(node);
        }
        else
        {
            // TODO: 也可以用节点文字名字来选定
            node = CacheBuilder.GetDataNode(dom.DocumentElement, strNodePath);
            if (node == null)
            {
                return;
            }
        }

        this.TreeView1.SelectedNodePath = "";

        this.SelectingNodePath = strNodePath;
        string strPureCaption = DomUtil.GetAttr(node, "name");

        string strDescription = DomUtil.GetAttr(node, "description");

        if (String.IsNullOrEmpty(strDescription) == true)
        {
            this.Description1.Text = "";
        }
        else
        {
            this.Description1.Text = "<div class='text'>" + strDescription + "</div>";
        }

        string strCommand = DomUtil.GetAttr(node, "command");

        bool   bRss         = false;
        long   nMaxCount    = -1;
        string strDirection = "";

        // parameters:
        //      nMaxCount   -1表示无穷多
        //      strDirection    head/tail
        CacheBuilder.GetRssParam(node,
                                 out bRss,
                                 out nMaxCount,
                                 out strDirection);

        // this.HyperLink_rss.Visible = bRss;

        if (strCommand == "~hidelist~")
        {
            //
            this.BrowseSearchResultControl1.ResultSetName     = "";
            this.BrowseSearchResultControl1.ResultsetFilename = "";
            this.BrowseSearchResultControl1.ResultCount       = 0;
            this.BrowseSearchResultControl1.StartIndex        = 0;
            this.BrowseSearchResultControl1.Visible           = false;
            return;
        }

        this.BrowseSearchResultControl1.Visible = true;

        if (strCommand == "~none~")
        {
            //
            this.BrowseSearchResultControl1.ResultSetName     = "";
            this.BrowseSearchResultControl1.ResultsetFilename = "";
            this.BrowseSearchResultControl1.ResultCount       = 0;
            this.BrowseSearchResultControl1.StartIndex        = 0;
            return;
        }

#if NO
        string strPureCaption = this.TreeView1.SelectedNode.Text;
        nRet = strPureCaption.IndexOf("(");
        if (nRet != -1)
        {
            strPureCaption = strPureCaption.Substring(0, nRet).Trim();
        }
#endif

        string strDataFile = strDataFileName;  //  PathUtil.PureName(strDataFile);

        string strPrefix   = CacheBuilder.MakeNodePath(node);
        string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile;

        PathUtil.TryCreateDir(strCacheDir);
        string strResultsetFilename = strCacheDir + "/" + strPrefix;

        string strRssString = "datafile=" + strDataFile + "&node=" + strPrefix;
        // this.HyperLink_rss.NavigateUrl = "browse.aspx?action=rss&" + strRssString;
        string strRssNavigateUrl = "browse.aspx?action=rss&" + strRssString;

        bool bRedo = false;

REDO:
        // 如果文件已经存在,就不要从 dp2library 获取了
        try
        {
            app.ResultsetLocks.LockForRead(strResultsetFilename, 500);
            try
            {
                if (this.Response.IsClientConnected == false)
                {
                    return;
                }

                if (File.Exists(strResultsetFilename) == true)
                {
                    // 2010/12/21
                    // 看看是否为每日强制更新的节点
                    // 获得Build相关参数
                    // parameters:
                    //      strBuildStyle    创建风格 perday / perhour
                    CacheBuilder.GetBuildParam(node,
                                               out string strBuildStyle);
                    if (String.IsNullOrEmpty(strBuildStyle) == false &&
                        strBuildStyle.ToLower() != "disable")
                    {
                        // 比较文件创建时间和当前时间,看看是否超过重建周期
                        if (CacheBuilder.HasExpired(strResultsetFilename,
                                                    strBuildStyle) == true)
                        {
                            goto DO_REBUILD;
                        }
                    }

                    long lHitCount = CacheBuilder.GetCount(app, strResultsetFilename, false);

                    // 记忆下来
                    app.SetBrowseNodeCount(strDataFile, strNodePath, lHitCount.ToString());

                    this.BrowseSearchResultControl1.ResultsetFilename = strResultsetFilename;
                    this.BrowseSearchResultControl1.ResultCount       = (int)lHitCount;
                    this.BrowseSearchResultControl1.StartIndex        = 0;
                    this.CreateRssLink(strPureCaption, strRssNavigateUrl);
                    this.Page.Title = strPureCaption;
                    // this.SelectedNodeCaption = strPureCaption + "(" + lHitCount.ToString() + ")";
                    this.TreeView1.SelectedNodePath = strNodePath;
                    return;
                }
            }
            finally
            {
                app.ResultsetLocks.UnlockForRead(strResultsetFilename);
            }
        }
        catch (System.ApplicationException /*ex*/)
        {
            this.SetErrorInfo(strPureCaption + " 相关缓存文件暂时被占用,请稍后重新访问");
            goto END1;
        }

DO_REBUILD:

        if (bRedo == false)
        {
            /*
             * // 加入列表
             * lock (app.PendingCacheFiles)
             * {
             *  string strLine = strDataFile + ":" + strPrefix;
             *  if (app.PendingCacheFiles.IndexOf(strLine) == -1)
             *      app.PendingCacheFiles.Add(strLine);
             * }
             * app.ActivateCacheBuilder();
             * */
            CacheBuilder.AddToPendingList(app,
                                          strDataFile,
                                          strPrefix,
                                          "");


            bRedo = true;
            if (Wait() == true)
            {
                return;
            }
            goto REDO;
        }
        else
        {
            this.SetErrorInfo(strPureCaption + " 相关缓存正在建立,请稍后重新访问");
            // this.SelectedNodeCaption = strPureCaption;
        }

END1:
        this.CreateRssLink(strPureCaption, strRssNavigateUrl);
        this.Page.Title = strPureCaption;

        this.BrowseSearchResultControl1.ResultSetName     = "";
        this.BrowseSearchResultControl1.ResultsetFilename = "";

        this.BrowseSearchResultControl1.ResultCount = 0;
        this.BrowseSearchResultControl1.StartIndex  = 0;
        this.TreeView1.SelectedNodePath             = strNodePath;

        return;

ERROR1:
        Response.Write(HttpUtility.HtmlEncode(strError));
        Response.End();
    }
Пример #28
0
        public LibraryServerResult GetZhongcihaoSearchResult(
            SessionInfo sessioninfo,
            string strZhongcihaoGroupName,
            string strResultSetName,
            long lStart,
            long lCount,
            string strBrowseInfoStyle,
            string strLang,
            out ZhongcihaoSearchResult[] searchresults)
        {
            string strError = "";

            searchresults = null;

            LibraryServerResult result = new LibraryServerResult();
            int  nRet = 0;
            long lRet = 0;

            if (String.IsNullOrEmpty(strZhongcihaoGroupName) == true)
            {
                strError = "strZhongcihaoGroupName参数值不能为空";
                goto ERROR1;
            }

            if (strZhongcihaoGroupName[0] == '!')
            {
                string strTemp = GetZhongcihaoGroupName(strZhongcihaoGroupName.Substring(1));

                if (strTemp == null)
                {
                    strError = "书目库名 " + strZhongcihaoGroupName.Substring(1) + " 没有找到对应的种次号组名";
                    goto ERROR1;
                }
                strZhongcihaoGroupName = strTemp;
            }

            RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);

            if (channel == null)
            {
                result.Value     = -1;
                result.ErrorInfo = "get channel error";
                result.ErrorCode = ErrorCode.SystemError;
                return(result);
            }

            //
            XmlNode nodeNsTable = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//zhongcihao/nstable");

            XmlNamespaceManager mngr = null;

            if (nodeNsTable != null)
            {
                // 准备名字空间环境
                nRet = PrepareNs(
                    nodeNsTable,
                    out mngr,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }

            // 构造数据库定义和库名的对照表
            XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes("//zhongcihao/group[@name='" + strZhongcihaoGroupName + "']/database");

            if (nodes.Count == 0)
            {
                strError = "library.xml中尚未配置有关 '" + strZhongcihaoGroupName + "'的<zhongcihao>/<group>/<database>相关参数";
                goto ERROR1;
            }

            Hashtable db_prop_table = new Hashtable();

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                DbZhongcihaoProperty prop = new DbZhongcihaoProperty();
                prop.DbName      = DomUtil.GetAttr(node, "name");
                prop.NumberXPath = DomUtil.GetAttr(node, "rightxpath");
                prop.TitleXPath  = DomUtil.GetAttr(node, "titlexpath");
                prop.AuthorXPath = DomUtil.GetAttr(node, "authorxpath");

                db_prop_table[prop.DbName] = prop;
            }

            if (String.IsNullOrEmpty(strResultSetName) == true)
            {
                strResultSetName = "default";
            }

            Record[] origin_searchresults = null; //

            lRet = channel.DoGetSearchResult(
                strResultSetName,
                lStart,
                lCount,
                "id",
                strLang,
                null,
                out origin_searchresults,
                out strError);
            if (lRet == -1)
            {
                goto ERROR1;
            }

            long lResultCount = lRet;

            searchresults = new ZhongcihaoSearchResult[origin_searchresults.Length];

            for (int i = 0; i < origin_searchresults.Length; i++)
            {
                ZhongcihaoSearchResult item = new ZhongcihaoSearchResult();

                item.Path        = origin_searchresults[i].Path;
                searchresults[i] = item;

                // 继续填充其余成员
                string strXml        = "";
                string strMetaData   = "";
                byte[] timestamp     = null;
                string strOutputPath = "";

                lRet = channel.GetRes(item.Path,
                                      out strXml,
                                      out strMetaData,
                                      out timestamp,
                                      out strOutputPath,
                                      out strError);
                if (lRet == -1)
                {
                    item.Zhongcihao = "获取记录 '" + item.Path + "' 出错: " + strError;
                    continue;
                }

                string strDbName = ResPath.GetDbName(item.Path);

                DbZhongcihaoProperty prop = (DbZhongcihaoProperty)db_prop_table[strDbName];
                if (prop == null)
                {
                    item.Zhongcihao = "数据库名 '" + strDbName + "' 不在定义的种次号特性(<zhongcihao>/<group>/<database>)中";
                    continue;
                }

                string strNumber = "";
                string strTitle  = "";
                string strAuthor = "";

                nRet = GetRecordProperties(
                    strXml,
                    prop,
                    mngr,
                    out strNumber,
                    out strTitle,
                    out strAuthor,
                    out strError);
                if (nRet == -1)
                {
                    item.Zhongcihao = strError;
                    continue;
                }

                item.Zhongcihao = strNumber;
                item.Cols       = new string[2];
                item.Cols[0]    = strTitle;
                item.Cols[1]    = strAuthor;
            }


            result.Value = lResultCount;
            return(result);

ERROR1:
            result.Value     = -1;
            result.ErrorCode = ErrorCode.SystemError;
            result.ErrorInfo = strError;
            return(result);
        }
Пример #29
0
        // 本轮是不是逢上了每日启动时间(以后)?
        // parameters:
        //      strLastTime 最后一次执行过的时间 RFC1123格式
        //      strStartTimeDef 返回定义的每日启动时间
        // return:
        //      -1  error
        //      0   没有找到startTime配置参数
        //      1   找到了startTime配置参数
        public int IsNowAfterPerDayStart(
            string strMonitorName,
            string strLastTime,
            out bool bRet,
            out string strStartTimeDef,
            out string strError)
        {
            strError        = "";
            strStartTimeDef = "";

            XmlNode node = this.App.Dbs.CfgDom.DocumentElement.SelectSingleNode("monitors/" + strMonitorName);

            if (node == null)
            {
                bRet = false;
                return(0);
            }

            string strStartTime = DomUtil.GetAttr(node, "startTime");

            if (String.IsNullOrEmpty(strStartTime) == true)
            {
                bRet = false;
                return(0);
            }

            strStartTimeDef = strStartTime;

            string strHour   = "";
            string strMinute = "";

            int nRet = strStartTime.IndexOf(":");

            if (nRet == -1)
            {
                strHour   = strStartTime.Trim();
                strMinute = "00";
            }
            else
            {
                strHour   = strStartTime.Substring(0, nRet).Trim();
                strMinute = strStartTime.Substring(nRet + 1).Trim();
            }

            int nHour   = 0;
            int nMinute = 0;

            try
            {
                nHour   = Convert.ToInt32(strHour);
                nMinute = Convert.ToInt32(strMinute);
            }
            catch
            {
                bRet     = false;
                strError = "时间值 '" + strStartTime + "' 格式不正确。应为 hh:mm";
                return(-1);   // 格式不正确
            }

            DateTime now1 = DateTime.Now;

            // 观察本日是否已经做过了
            if (String.IsNullOrEmpty(strLastTime) == false)
            {
                try
                {
                    DateTime lasttime = DateTimeUtil.FromRfc1123DateTimeString(strLastTime);

                    if (lasttime.Year == now1.Year &&
                        lasttime.Month == now1.Month &&
                        lasttime.Day == now1.Day)
                    {
                        bRet = false;   // 今天已经做过了
                        return(1);
                    }
                }
                catch
                {
                    bRet     = false;
                    strError = "strLastTime '" + strLastTime + "' 格式错误";
                    return(-1);
                }
            }

            DateTime now2 = new DateTime(now1.Year,
                                         now1.Month,
                                         now1.Day,
                                         nHour,
                                         nMinute,
                                         0);

            if (now1 >= now2)
            {
                bRet = true;
            }
            else
            {
                bRet = false;
            }

            return(1);
        }
Пример #30
0
        // 强制修改用户密码。不修改其他信息。
        public int ResetUserPassword(
            string strLibraryCodeList,
            string strUserName,
            string strOperator,
            string strNewPassword,
            string strClientAddress,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (String.IsNullOrEmpty(strUserName) == true)
            {
                strError = "strUserName参数值不能为空";
                return(-1);
            }

            XmlNode nodeAccount       = null;
            string  strHashedPassword = "";

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                // 查重
                nodeAccount = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//accounts/account[@name='" + strUserName + "']");
                if (nodeAccount == null)
                {
                    strError = "用户 '" + strUserName + "' 不存在";
                    return(-1);
                }

                string strExistLibraryCodeList = DomUtil.GetAttr(nodeAccount, "libraryCode");

                // 2012/9/9
                // 分馆用户只允许修改馆代码属于管辖分馆的帐户
                if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false)
                {
                    if (string.IsNullOrEmpty(strExistLibraryCodeList) == true ||
                        IsListInList(strExistLibraryCodeList, strLibraryCodeList) == false)
                    {
                        strError = "当前用户只能重设 图书馆代码完全属于 '" + strLibraryCodeList + "' 范围的用户的密码";
                        return(-1);
                    }
                }

                // 强制修改密码。无需验证旧密码
#if NO
                // 以前的做法
                strHashedPassword = Cryptography.Encrypt(strNewPassword,
                                                         EncryptKey);
                DomUtil.SetAttr(nodeAccount, "password", strHashedPassword);
#endif
                nRet = LibraryServerUtil.SetUserPassword(strNewPassword, out strHashedPassword, out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                DomUtil.SetAttr(nodeAccount, "password", strHashedPassword);

                this.Changed = true;
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }

            {
                XmlDocument domOperLog = PrepareOperlogDom("resetpassword", strOperator);

                // 2015/10/17 新增加的元素。此前缺这个元素。建议日志恢复的时候,忽略没有 userName 元素的日志记录
                DomUtil.SetElementText(domOperLog.DocumentElement,
                                       "userName",
                                       strUserName);
#if NO
                XmlNode node = domOperLog.CreateElement("newPassword");
                domOperLog.DocumentElement.AppendChild(node);

                node.InnerText = strHashedPassword;
#endif
                DomUtil.SetElementText(domOperLog.DocumentElement,
                                       "newPassword",
                                       strHashedPassword);

                // 写入日志
                nRet = this.OperLog.WriteOperLog(domOperLog,
                                                 strClientAddress,
                                                 out strError);
                if (nRet == -1)
                {
                    strError = "SetUser() API 写入日志时发生错误: " + strError;
                    return(-1);
                }
            }

            return(0);
        }