Ejemplo n.º 1
0
        void FillProjectNameList(XmlDocument dom)
        {
            this.listView_dup_projects.Items.Clear();

            if (dom == null)
            {
                return;
            }

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

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

                string strName    = DomUtil.GetAttr(node, "name");
                string strComment = DomUtil.GetAttr(node, "comment");

                ListViewItem item = new ListViewItem(strName, 0);
                item.SubItems.Add(strComment);
                this.listView_dup_projects.Items.Add(item);
            }
        }
Ejemplo n.º 2
0
        // 在配置文件中找带有加减号的名字
        static XmlNode FindMacroItem(XmlNode root,
                                     string strName)
        {
            string strPureName = strName.Replace("+", "").Replace("-", "");

            XmlNodeList nodes = root.SelectNodes("item");

            if (nodes.Count == 0)
            {
                return(null);
            }
            foreach (XmlNode node in nodes)
            {
                string strCurrentName = DomUtil.GetAttr(node, "name");
                strCurrentName = strCurrentName.Replace("+", "").Replace("-", "");
                if (strCurrentName == strPureName)
                {
                    return(node);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        // 设置一个浮点数
        // parameters:
        //		strPath	参数路径
        //		strName	参数名
        //		fValue	要设置的字符串
        public void SetFloat(string strPath,
                             string strName,
                             float fValue)
        {
#if NO
            strPath = GetSectionPath(strPath);

            string[] aPath = strPath.Split(new char[] { '/' });
            XmlNode  node  = DomUtil.CreateNode(dom, aPath);

            if (node == null)
            {
                throw (new Exception("SetString() error ..."));
            }

            DomUtil.SetAttr(node,
                            strName,
                            fValue.ToString());
#endif
            SetString(strPath,
                      strName,
                      fValue.ToString());
        }
Ejemplo n.º 4
0
        // 写入一个布尔值
        // parameters:
        //		strPath	参数路径
        //		strName	参数名
        //		bValue	要写入的布尔值
        public void SetBoolean(string strPath,
                               string strName,
                               bool bValue)
        {
#if NO
            strPath = GetSectionPath(strPath);

            string[] aPath = strPath.Split(new char[] { '/' });
            XmlNode  node  = DomUtil.CreateNode(dom, aPath);

            if (node == null)
            {
                throw (new Exception("SetInt() set error ..."));
            }

            DomUtil.SetAttr(node,
                            strName,
                            (bValue == true ? "true" : "false"));
#endif
            SetString(strPath,
                      strName,
                      (bValue == true ? "true" : "false"));
        }
Ejemplo n.º 5
0
        public GzhCfg(XmlNode node)
        {
            this._node = node;

            this.appName   = DomUtil.GetAttr(node, "appName");
            this.appNameCN = DomUtil.GetAttr(node, "appNameCN");

            this.appId          = DomUtil.GetAttr(node, "appId");
            this.secret         = DomUtil.GetAttr(node, "secret");
            this.token          = DomUtil.GetAttr(node, "token");
            this.encodingAESKey = DomUtil.GetAttr(node, "encodingAESKey");
            if (this.appName == "")
            {
                throw new Exception("尚未定义公众号名称");
            }

            string isDefaultText = DomUtil.GetAttr(node, "isDefault").ToLower();

            if (isDefaultText == "true")
            {
                isDefault = true;
            }

            //// 模板id,todo 模板名称有空变成常量,与配置文件对应
            //this.Template_Bind_Id = this.GetTemplateId(node, "Bind");
            //this.Template_UnBind_Id = this.GetTemplateId(node, "UnBind");
            //this.Template_Borrow_Id = this.GetTemplateId(node, "Borrow");
            //this.Template_Return_Id = this.GetTemplateId(node, "Return");
            //this.Template_Pay_Id = this.GetTemplateId(node, "Pay");
            //this.Template_CancelPay_Id = this.GetTemplateId(node, "CancelPay");
            //this.Template_Message_Id = this.GetTemplateId(node, "Message");
            //this.Template_Arrived_Id = this.GetTemplateId(node, "Arrived");
            //this.Template_CaoQi_Id = this.GetTemplateId(node, "CaoQi");

            //全局只需注册一次
            AccessTokenContainer.Register(this.appId, this.secret);
        }
Ejemplo n.º 6
0
        int Initial(string strXml,
                    out string strError)
        {
            strError = "";
            this.Clear();

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

            XmlDocument dom = new XmlDocument();

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

            this.textBox_width.Text      = DomUtil.GetAttr(dom.DocumentElement, "width");
            this.textBox_padding.Text    = DomUtil.GetAttr(dom.DocumentElement, "padding");
            this.textBox_background.Text = DomUtil.GetAttr(dom.DocumentElement, "background");
            this.comboBox_position.Text  = DomUtil.GetAttr(dom.DocumentElement, "position");
            this.textBox_margin.Text     = DomUtil.GetAttr(dom.DocumentElement, "margin");

            this.textBox_borderBrush.Text        = DomUtil.GetAttr(dom.DocumentElement, "borderBrush");
            this.textBox_borderCornerRadius.Text = DomUtil.GetAttr(dom.DocumentElement, "borderCornerRadius");
            this.textBox_borderThickness.Text    = DomUtil.GetAttr(dom.DocumentElement, "borderThickness");

            this.textBox_def.Text = dom.DocumentElement.InnerXml;

            return(0);
        }
Ejemplo n.º 7
0
        // 可能会抛出异常
        public string GetData(string dataElement)
        {
            // 一般 XML 元素 content
            if (dataElement.IndexOf(":") == -1)
            {
                return(DomUtil.GetElementText(this.RecordDom.DocumentElement, dataElement));
            }

            var    parts = StringUtil.ParseTwoPart(dataElement, ":");
            string name  = parts[0];
            string type  = parts[1];

            if (type == "innerXml")
            {
                return(DomUtil.GetElementInnerXml(this.RecordDom.DocumentElement, name));
            }
            if (type == "this")
            {
                {
                    var info = this.GetType().GetProperty(name);
                    if (info != null)
                    {
                        return((string)info.GetValue(this));
                    }
                }
                {
                    var info = this.GetType().GetField(name);
                    if (info == null)
                    {
                        throw new Exception($"BookItem 对象中没有 {name} 成员");
                    }
                    return((string)info.GetValue(this));
                }
            }

            throw new Exception($"未知的类型 '{type}'");
        }
Ejemplo n.º 8
0
        void FillList(bool bAutoSelect)
        {
            // 2015/6/14
            string strExistName = this.textBox_name.Text;

            listView1.Items.Clear();
            listView1_SelectedIndexChanged(null, null);

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

            for (int i = 0; i < nodes.Count; i++)
            {
                string strName    = DomUtil.GetAttr(nodes[i], "name");
                string strComment = DomUtil.GetAttr(nodes[i], "comment");

                ListViewItem item = new ListViewItem(strName, 0);
                item.SubItems.Add(strComment);

                listView1.Items.Add(item);

                if (bAutoSelect == true &&
                    string.IsNullOrEmpty(strExistName) == false &&
                    strName == strExistName)
                {
                    item.Selected = true;
                }
            }

            if (bAutoSelect == true && listView1.SelectedItems.Count == 0)
            {
                // 选择第一项
                if (listView1.Items.Count != 0)
                {
                    listView1.Items[0].Selected = true;
                }
            }
        }
Ejemplo n.º 9
0
        // 从控件到 CfgDom
        bool SaveToCfgDom()
        {
            XmlDocument dom = this.CfgDom;

            XmlElement root = dom.DocumentElement.SelectSingleNode("zServer") as XmlElement;

            if (root == null)
            {
                root = dom.CreateElement("zServer");
                dom.DocumentElement.AppendChild(root);
            }

            {
                XmlElement element = root.SelectSingleNode("dp2library") as XmlElement;
                if (element == null)
                {
                    element = dom.CreateElement("dp2library");
                    root.AppendChild(element);
                }

                element.SetAttribute("anonymousUserName", this.AnonymousUserName);
                element.SetAttribute("anonymousPassword", EncryptPassword(this.AnonymousPassword));
            }

            {
                XmlElement element = root.SelectSingleNode("databases") as XmlElement;
                if (element == null)
                {
                    element = dom.CreateElement("databases");
                    root.AppendChild(element);
                }

                DomUtil.SetElementOuterXml(element, this.DatabasesXml);
            }

            return(true);
        }
Ejemplo n.º 10
0
        // 获得 XML 检索式
        // paramers:
        //      bOptimize   是否优化?
        public string GetContent(bool bOptimize)
        {
            bool bAllEmpty = true;  // 是否每行检索词都为空?

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<root />");
            for (int i = 0; i < this.Lines.Count; i++)
            {
                Line line = this.Lines[i];

                XmlNode node = dom.CreateElement("line");
                dom.DocumentElement.AppendChild(node);

                string strLogic = line.comboBox_logicOperator.Text;
                string strWord  = line.textBox_word.Text;
                string strFrom  = line.comboBox_from.Text;

                DomUtil.SetAttr(node, "logic", strLogic);
                DomUtil.SetAttr(node, "word", strWord);
                DomUtil.SetAttr(node, "from", strFrom);

                if (String.IsNullOrEmpty(strWord) == false)
                {
                    bAllEmpty = false;
                }
            }

            if (bOptimize == true &&
                bAllEmpty == true)
            {
                return(null);
            }

            return(dom.OuterXml);
        }
Ejemplo n.º 11
0
        public void CreateNSOfCfg(XmlDocument domData,
                                  XmlDocument domCfg)
        {
            XmlNodeList nsitemList = domCfg.DocumentElement.SelectNodes("/root/nstable/item");

            foreach (XmlNode nsitemNode in nsitemList)
            {
                XmlNode nsNode     = nsitemNode.SelectSingleNode("nameSpace");
                XmlNode prefixNode = nsitemNode.SelectSingleNode("prefix");

                PrefixURI prefixUri = new PrefixURI();
                if (prefixNode != null)
                {
                    prefixUri.strPrefix = DomUtil.GetNodeText(prefixNode);
                }
                if (nsNode != null)
                {
                    prefixUri.strURI = DomUtil.GetNodeText(nsNode);
                }

                if (prefixUri.strPrefix != "" &&
                    prefixUri.strURI != "")                         //在配置文件里不允许前缀为空
                {
                    this.Add(prefixUri);
                }
            }

            this.Sort();
            this.DumpRep();

            //if (this.Count > 0)
            //{
            this.nsmgr = new XmlNamespaceManager(domData.NameTable);
            Add2nsmgr();
            //}
        }
Ejemplo n.º 12
0
        public static void SetXml(ItemEditControlBase control,
                                  string strXml,
                                  string strPublicationType)
        {
            string strError = "";

            // 去掉记录里面的 issueCount 和 range 元素
            if (string.IsNullOrEmpty(strXml) == false &&
                strPublicationType == "book")
            {
                XmlDocument dom = new XmlDocument();
                DomUtil.SafeLoadXml(dom, strXml);
                DomUtil.DeleteElement(dom.DocumentElement, "range");
                DomUtil.DeleteElement(dom.DocumentElement, "issueCount");
                strXml = dom.DocumentElement.OuterXml;
            }

            int nRet = control.SetData(strXml, "", null, out strError);

            if (nRet == -1)
            {
                throw new Exception(strError);
            }
        }
Ejemplo n.º 13
0
        private void toolStripButton_export_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "尚未选定需要导出的服务器");
                return;
            }
            // 询问文件名
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Title           = "请指定要保存的 XML 文件名";
                dlg.CreatePrompt    = false;
                dlg.OverwritePrompt = true;
                // dlg.FileName = this.ExportTextFilename;
                dlg.Filter           = "XML文件 (*.xml)|*.xml|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                XmlDocument dom = new XmlDocument();
                dom.LoadXml("<root />");
                foreach (ListViewItem item in this.listView1.SelectedItems)
                {
                    XmlElement server        = (XmlElement)item.Tag;
                    XmlElement export_server = dom.CreateElement("server");
                    dom.DocumentElement.AppendChild(export_server);
                    export_server = DomUtil.SetElementOuterXml(export_server, server.OuterXml);
                    export_server.RemoveAttribute("enabled");
                }

                dom.Save(dlg.FileName);
            }
        }
Ejemplo n.º 14
0
        // 解析 开始 参数
        // parameters:
        //      strStart    启动字符串。格式为XML
        //                  如果自动字符串为"!breakpoint",表示从服务器记忆的断点信息开始
        int ParseArriveMonitorStart(string strStart,
                                    out string strRecordID,
                                    out string strError)
        {
            strError    = "";
            strRecordID = "";

            // int nRet = 0;

            if (String.IsNullOrEmpty(strStart) == true)
            {
                strRecordID = "1";
                return(0);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strStart);
            }
            catch (Exception ex)
            {
                strError = "装载XML字符串进入DOM时发生错误: " + ex.Message;
                return(-1);
            }

            XmlNode nodeLoop = dom.DocumentElement.SelectSingleNode("loop");

            if (nodeLoop != null)
            {
                strRecordID = DomUtil.GetAttr(nodeLoop, "recordid");
            }

            return(0);
        }
Ejemplo n.º 15
0
        // 获得一个字符串
        // parameters:
        //		strPath	参数路径
        //		strName	参数名
        //		strDefalt	缺省值
        // return:
        //		要获得的字符串
        public string GetString(string strPath,
                                string strName,
                                string strDefault)
        {
            strPath = GetSectionPath(strPath);

            XmlNode node = null;

            try
            {
                node = dom.SelectSingleNode(strPath);
            }
            catch (Exception ex)
            {
                throw new Exception("strPath 名称 '" + strPath + "' 不合法。应符合 XML 元素命名规则", ex);
            }

            if (node == null)
            {
                return(strDefault);
            }

            return(DomUtil.GetAttrOrDefault(node, strName, strDefault));
        }
Ejemplo n.º 16
0
        public void BuildASCIiTables(string strXmlFileName)
        {
            XmlDocument dom = new XmlDocument();

            dom.Load(strXmlFileName);

            // <characterSet name="Basic Arabic" ISOcode="33">
            XmlNodeList nodes = dom.DocumentElement.SelectNodes("//characterSet");

            this.CodePages = new List <CodePage>();

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

                CodePage page = new CodePage();
                page.Name = DomUtil.GetAttr(node, "name");
                page.Code = System.Convert.ToInt32(DomUtil.GetAttr(node, "ISOcode"), 16);

                LoadOneTable(node, ref page);

                this.CodePages.Add(page);
            }
        }
Ejemplo n.º 17
0
        int _nDepartmentHeight = 0;        // 单位文字高度

        // 装入数据
        public int SetData(
            string strPatronXml,
            out string strError)
        {
            strError = "";

            XmlDocument dom = new XmlDocument();

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

            this.Name       = DomUtil.GetElementText(dom.DocumentElement, "name");
            this.Barcode    = DomUtil.GetElementText(dom.DocumentElement, "barcode");
            this.Department = DomUtil.GetElementText(dom.DocumentElement, "department");

            return(0);
        }
Ejemplo n.º 18
0
        // 获得栏目的XML定义
        public int GetDef(
            out string strXml,
            out string strError)
        {
            strXml   = "";
            strError = "";

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<chatRoomDef />");

            m_lock.EnterReadLock();
            try
            {
                foreach (ChatRoom room in this)
                {
                    XmlNode node = dom.CreateElement("chatRoom");
                    dom.DocumentElement.AppendChild(node);
                    DomUtil.SetAttr(node, "name", room.Name);
                    DomUtil.SetAttr(node, "editors", StringUtil.MakePathList(room.EditorList));
                    DomUtil.SetAttr(node, "groups", StringUtil.MakePathList(room.GroupList));
                }

                DomUtil.SetAttr(dom.DocumentElement, "picMaxWidth", this.PicMaxWidth.ToString());
                DomUtil.SetAttr(dom.DocumentElement, "picMaxHeight", this.PicMaxHeight.ToString());
            }
            finally
            {
                m_lock.ExitReadLock();
            }

            // strXml = dom.DocumentElement.OuterXml;
            strXml = DomUtil.GetIndentXml(dom.DocumentElement);

            return(0);
        }
Ejemplo n.º 19
0
        public void RefreshDom()
        {
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "zipcode", this.Zipcode);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "address", this.Address);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "department", this.Department);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "name", this.PersonName);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "tel", this.Tel);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "email", this.Email);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "bank", this.Bank);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "accounts", this.Accounts);
            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "payStyle", this.PayStyle);

            DomUtil.SetElementText(this.RecordDom.DocumentElement,
                                   "comment", this.Comment);
        }
Ejemplo n.º 20
0
        // 2011/1/2
        static string GetBrowseFormatName(
            XmlNodeList format_nodes,
            string strName,
            string strLang)
        {
            for (int j = 0; j < format_nodes.Count; j++)
            {
                XmlNode node = format_nodes[j];

                List <string> captions = GetAllNames(node);
                if (captions.IndexOf(strName) == -1)
                {
                    continue;
                }

                string strFormatName = DomUtil.GetCaption(strLang, node);
                if (String.IsNullOrEmpty(strFormatName) == false)
                {
                    return(strFormatName);
                }
            }

            return(null);    // not found
        }
Ejemplo n.º 21
0
        // 记录是否允许删除?
        // return:
        //      -1  出错。不允许删除。
        //      0   不允许删除,因为权限不够等原因。原因在strError中
        //      1   可以删除
        public override int CanDelete(
            SessionInfo sessioninfo,
            XmlDocument domExist,
            out string strError)
        {
            strError = "";
            if (sessioninfo == null)
            {
                strError = "sessioninfo == null";
                return(-1);
            }

            if (sessioninfo.GlobalUser == false)
            {
                // 再看已经存在的内容是不是全部在管辖之下
                string strDistribute = DomUtil.GetElementText(domExist.DocumentElement, "distribute");
                // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内
                // return:
                //      -1  出错
                //      0   超过管辖范围。strError中有解释
                //      1   在管辖范围内
                int nRet = DistributeInControlled(strDistribute,
                                                  sessioninfo.LibraryCodeList,
                                                  out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
                if (nRet == 0)
                {
                    strError = "因出现了超越当前用户管辖范围的分馆馆藏信息,删除订购记录的操作被拒绝:" + strError;
                    return(0);
                }
            }
            return(1);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 创建好适合于保存的记录 XML 字符串
        /// </summary>
        /// <param name="bVerifyParent">是否要验证 parent 成员</param>
        /// <param name="strXml">返回 XML 字符串</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 成功</returns>
        public int BuildRecord(
            bool bVerifyParent,
            out string strXml,
            out string strError)
        {
            strError = "";
            strXml   = "";

            if (bVerifyParent == true)
            {
                if (string.IsNullOrEmpty(this.Parent) == true)
                {
                    strError = "Parent 成员尚未定义";
                    return(-1);
                }
            }

            // 要考虑 dprms:file 元素的变化
            if (this._objects != null)
            {
                int nRet = this._objects.AddFileFragments(ref this.RecordDom,
                                                          true,
                                                          out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
            }

            // 2020/9/17
            // 把 XML 中多余的元素删除
            DomUtil.RemoveEmptyElements(this.RecordDom.DocumentElement);

            strXml = this.RecordDom.OuterXml;
            return(0);
        }
Ejemplo n.º 23
0
        int BuildUserRecord(out string strXml,
                            out string strError)
        {
            strXml   = "";
            strError = "";

            XmlDocument UserRecDom = new XmlDocument();

            UserRecDom.LoadXml("<record><name /><password /><server /></record>");


            // 设置用户名
            DomUtil.SetElementText(UserRecDom.DocumentElement,
                                   "name",
                                   this.textBox_manageUserName.Text);


            // 密码
            DomUtil.SetElementText(UserRecDom.DocumentElement,
                                   "password",
                                   Cryptography.GetSHA1(this.textBox_managePassword.Text));

            XmlNode nodeServer = UserRecDom.DocumentElement.SelectSingleNode("server");

            if (nodeServer == null)
            {
                Debug.Assert(false, "不可能的情况");
                return(-1);
            }

            DomUtil.SetAttr(nodeServer, "rights", "children_database:create,list");

            strXml = UserRecDom.OuterXml;

            return(0);
        }
Ejemplo n.º 24
0
        // 将MARCXML格式的xml记录转换为marc机内格式字符串
        // 注意,如果strXml内容为空,本函数会报错。最好在进入函数前进行判断。
        // parameters:
        //		bWarning	        ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
        //		strMarcSyntax	    指示marc语法,如果=="",则自动识别
        //		strOutMarcSyntax	[out] 返回记录的 MARC 格式。如果 strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
        //      strFragmentXml      [out] 返回删除 <leader> <controlfield> <datafield> 以后的 XML 代码。注意,包含 <record> 元素
        public static int Xml2Marc(string strXml,
                                   Xml2MarcStyle style,
                                   string strMarcSyntax,
                                   out string strOutMarcSyntax,
                                   out string strMARC,
                                   out string strFragmentXml,
                                   out string strError)
        {
            strMARC          = "";
            strError         = "";
            strOutMarcSyntax = "";
            strFragmentXml   = "";

            // 2013/9/25
            if (string.IsNullOrEmpty(strXml) == true)
            {
                return(0);
            }

            Debug.Assert(string.IsNullOrEmpty(strXml) == false, "");

            bool bWarning           = (style & Xml2MarcStyle.Warning) != 0;
            bool bOutputFragmentXml = (style & Xml2MarcStyle.OutputFragmentXml) != 0;

            XmlDocument dom = new XmlDocument();

            dom.PreserveWhitespace = true;  // 在意空白符号
            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "Xml2Marc() strXml 加载 XML 到 DOM 时出错: " + ex.Message;
                return(-1);
            }

            // 取MARC根
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("unimarc", Ns.unimarcxml);
            nsmgr.AddNamespace("usmarc", Ns.usmarcxml);

            XmlNode root = null;

            if (string.IsNullOrEmpty(strMarcSyntax) == true)
            {
                // '//'保证了无论MARC的根在何处,都可以正常取出。
                root = dom.DocumentElement.SelectSingleNode("//unimarc:record", nsmgr);
                if (root == null)
                {
                    root = dom.DocumentElement.SelectSingleNode("//usmarc:record", nsmgr);

                    if (root == null)
                    {
                        // TODO: 是否要去除所有 MARC 相关元素
                        if (bOutputFragmentXml)
                        {
                            strFragmentXml = dom.DocumentElement.OuterXml;
                        }
                        return(0);
                    }

                    strMarcSyntax = "usmarc";
                }
                else
                {
                    strMarcSyntax = "unimarc";
                }
            }
            else
            {
                // 2012/1/8
                if (strMarcSyntax != null)
                {
                    strMarcSyntax = strMarcSyntax.ToLower();
                }

                if (strMarcSyntax != "unimarc" &&
                    strMarcSyntax != "usmarc")
                {
                    strError = "无法识别 MARC格式 '" + strMarcSyntax + "' 。目前仅支持 unimarc 和 usmarc 两种格式";
                    return(-1);
                }

                root = dom.DocumentElement.SelectSingleNode("//" + strMarcSyntax + ":record", nsmgr);
                if (root == null)
                {
                    // TODO: 是否要去除所有 MARC 相关元素
                    if (bOutputFragmentXml)
                    {
                        strFragmentXml = dom.DocumentElement.OuterXml;
                    }
                    return(0);
                }
            }

            StringBuilder strMarc = new StringBuilder(4096);

            strOutMarcSyntax = strMarcSyntax;

            XmlNode leader = root.SelectSingleNode(strMarcSyntax + ":leader", nsmgr);

            if (leader == null)
            {
                strError += "缺<" + strMarcSyntax + ":leader>元素\r\n";
                if (bWarning == false)
                {
                    return(-1);
                }
                else
                {
                    strMarc.Append("012345678901234567890123");
                }
            }
            else // 正常情况
            {
                // string strLeader = DomUtil.GetNodeText(leader);
                // GetNodeText()会自动Trim(),会导致头标区内容末尾丢失字符
                string strLeader = leader.InnerText;
                if (strLeader.Length != 24)
                {
                    strError += "<" + strMarcSyntax + ":leader>元素内容应为24字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strLeader.Length < 24)
                        {
                            strLeader = strLeader.PadRight(24, ' ');
                        }
                        else
                        {
                            strLeader = strLeader.Substring(0, 24);
                        }
                    }
                }

                strMarc.Append(strLeader);

                // 从 DOM 中删除 leader 元素
                if (bOutputFragmentXml)
                {
                    leader.ParentNode.RemoveChild(leader);
                }
            }

            int i = 0;

            // 固定长字段
            XmlNodeList controlfields = root.SelectNodes(strMarcSyntax + ":controlfield", nsmgr);

            for (i = 0; i < controlfields.Count; i++)
            {
                XmlNode field  = controlfields[i];
                string  strTag = DomUtil.GetAttr(field, "tag");
                if (strTag.Length != 3)
                {
                    strError += "<" + strMarcSyntax + ":controlfield>元素的tag属性值'" + strTag + "'应当为3字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strTag.Length < 3)
                        {
                            strTag = strTag.PadRight(3, '*');
                        }
                        else
                        {
                            strTag = strTag.Substring(0, 3);
                        }
                    }
                }

                string strContent = DomUtil.GetNodeText(field);

                strMarc.Append(strTag + strContent + new string(MarcUtil.FLDEND, 1));

                // 从 DOM 中删除
                if (bOutputFragmentXml)
                {
                    field.ParentNode.RemoveChild(field);
                }
            }

            // 可变长字段
            XmlNodeList datafields = root.SelectNodes(strMarcSyntax + ":datafield", nsmgr);

            for (i = 0; i < datafields.Count; i++)
            {
                XmlNode field  = datafields[i];
                string  strTag = DomUtil.GetAttr(field, "tag");
                if (strTag.Length != 3)
                {
                    strError += "<" + strMarcSyntax + ":datafield>元素的tag属性值'" + strTag + "'应当为3字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strTag.Length < 3)
                        {
                            strTag = strTag.PadRight(3, '*');
                        }
                        else
                        {
                            strTag = strTag.Substring(0, 3);
                        }
                    }
                }

                string strInd1 = DomUtil.GetAttr(field, "ind1");
                if (strInd1.Length != 1)
                {
                    strError += "<" + strMarcSyntax + ":datalfield>元素的ind1属性值'" + strInd1 + "'应当为1字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strInd1.Length < 1)
                        {
                            strInd1 = '*'.ToString();
                        }
                        else
                        {
                            strInd1 = strInd1[0].ToString();
                        }
                    }
                }

                string strInd2 = DomUtil.GetAttr(field, "ind2");
                if (strInd2.Length != 1)
                {
                    strError += "<" + strMarcSyntax + ":datalfield>元素的indi2属性值'" + strInd2 + "'应当为1字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strInd2.Length < 1)
                        {
                            strInd2 = '*'.ToString();
                        }
                        else
                        {
                            strInd2 = strInd2[0].ToString();
                        }
                    }
                }

                // string strContent = DomUtil.GetNodeText(field);
                XmlNodeList   subfields  = field.SelectNodes(strMarcSyntax + ":subfield", nsmgr);
                StringBuilder strContent = new StringBuilder(4096);
                for (int j = 0; j < subfields.Count; j++)
                {
                    XmlNode subfield = subfields[j];

                    XmlAttribute attr = subfield.Attributes["code"];
#if NO
                    string strCode = DomUtil.GetAttr(subfield, "code");
                    if (strCode.Length != 1)
                    {
                        strError += "<" + strMarcSyntax + ":subfield>元素的code属性值'" + strCode + "'应当为1字符\r\n";
                        if (bWarning == false)
                        {
                            return(-1);
                        }
                        else
                        {
                            if (strCode.Length < 1)
                            {
                                strCode = '*'.ToString();
                            }
                            else
                            {
                                strCode = strCode[0].ToString();
                            }
                        }
                    }

                    string strSubfieldContent = DomUtil.GetNodeText(subfield);

                    strContent += new string(MarcUtil.SUBFLD, 1) + strCode + strSubfieldContent;
#endif
                    if (attr == null)
                    {
                        // 前导纯文本
                        strContent.Append(DomUtil.GetNodeText(subfield));
                        continue;   //  goto CONTINUE; BUG!!!
                    }

                    string strCode = attr.Value;
                    if (strCode.Length != 1)
                    {
                        strError += "<" + strMarcSyntax + ":subfield>元素的 code 属性值 '" + strCode + "' 应当为1字符\r\n";
                        if (bWarning == false)
                        {
                            return(-1);
                        }
                        else
                        {
                            if (strCode.Length < 1)
                            {
                                strCode = "";   // '*'.ToString();
                            }
                            else
                            {
                                strCode = strCode[0].ToString();
                            }
                        }
                    }

                    string strSubfieldContent = DomUtil.GetNodeText(subfield);
                    strContent.Append(new string(MarcUtil.SUBFLD, 1) + strCode + strSubfieldContent);
                }

                strMarc.Append(strTag + strInd1 + strInd2 + strContent + new string(MarcUtil.FLDEND, 1));

CONTINUE:
                // 从 DOM 中删除
                if (bOutputFragmentXml)
                {
                    field.ParentNode.RemoveChild(field);
                }
            }

            strMARC = strMarc.ToString();
            if (bOutputFragmentXml)
            {
                strFragmentXml = dom.DocumentElement.OuterXml;
            }
            return(0);
        }
Ejemplo n.º 25
0
        int LoadFieldNames(out string strError)
        {
            strError = "";

            this.listView_fieldNameList.Items.Clear();

            if (this.MarcDefDom == null)
            {
                return(0);
            }

            XmlNodeList nodes = this.MarcDefDom.DocumentElement.SelectNodes("Field");

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

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

                if (strName == "###")
                {
                    continue;   // 跳过头标区
                }
                string strLabel = "";

                XmlNode nodeProperty = node.SelectSingleNode("Property");
                if (nodeProperty != null)
                {
                    // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
                    // parameters:
                    //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
                    strLabel = DomUtil.GetXmlLangedNodeText(
                        this.Lang,
                        nodeProperty,
                        "Label",
                        true);
                }

#if NO
                XmlNode nodeLabel = null;
                try
                {
                    if (this.Lang == "")
                    {
                        nodeLabel = node.SelectSingleNode("Property/Label");
                    }
                    else
                    {
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
                        nsmgr.AddNamespace("xml", Ns.xml);
                        nodeLabel = node.SelectSingleNode("Property/Label[@xml:lang='" + this.Lang + "']", nsmgr);
                    }
                }
                catch // 防止字段名中不合法字符用于xpath抛出异常
                {
                    nodeLabel = null;
                }

                string strLabel = "";
                if (nodeLabel != null)
                {
                    strLabel = DomUtil.GetNodeText(nodeLabel);
                }
#endif

                ListViewItem item = new ListViewItem(strName);
                item.SubItems.Add(strLabel);

                this.listView_fieldNameList.Items.Add(item);
            }

            return(0);
        }
Ejemplo n.º 26
0
        // 从marceditor_macrotable.xml文件中解析宏
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        public static int GetFromLocalMacroTable(string strFilename,
                                                 string strName,
                                                 bool bSimulate,
                                                 out string strValue,
                                                 out string strError)
        {
            strError = "";
            strValue = "";
            int nRet = 0;

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(strFilename);
            }
            catch (FileNotFoundException)
            {
                return(0);
            }
            catch (Exception ex)
            {
                strError = "文件 '" + strFilename + "' 装载到XMLDOM时发生错误: " + ex.Message;
                return(-1);
            }

            // 全名找一次
            XmlNode node = dom.DocumentElement.SelectSingleNode("item[@name='" + strName + "']");

            if (node == null)
            {
                // (不干净名字)再按照去掉了+-符号的名字来找一次
                if (strName.IndexOf("+") != -1 ||
                    strName.IndexOf("-") != -1)
                {
                    string strPureName = strName.Replace("+", "").Replace("-", "");
                    node = dom.DocumentElement.SelectSingleNode("item[@name='" + strPureName + "']");
                }
                else
                {
                    // 干净的名字再找一次dom中的不干净名字
                    if (node == null)
                    {
                        node = FindMacroItem(dom.DocumentElement,
                                             strName);
                    }
                }

                if (node == null)
                {
                    return(0);
                }
            }
            string strOldValue = node.InnerText;
            string strNodeName = DomUtil.GetAttr(node, "name");

            // 是否先操作、然后返回值。否则就是先返回值,后操作
            // 如果有增/减量要求
            if (HasIncDecChar(strName, out int nDelta, out bool bOperFirst) == true ||
                HasIncDecChar(strNodeName, out nDelta, out bOperFirst) == true)
            {
                if (string.IsNullOrEmpty(strOldValue) == true)
                {
                    strOldValue = "0";
                }

                if (bOperFirst == false)
                {
                    strValue = strOldValue;
                }

                // 给一个被字符引导的数字增加一个数量。
                // 例如 B019X + 1 变成 B020X
                nRet = StringUtil.IncreaseNumber(strOldValue,
                                                 nDelta,
                                                 out string strNewValue,
                                                 out strError);
                if (nRet == -1)
                {
                    strError = "IncreaseNumber() error :" + strError;
                    return(-1);
                }

                if (bOperFirst == true)
                {
                    strValue = strNewValue;
                }

                if (bSimulate == false)
                {
                    node.InnerText = strNewValue;
                    dom.Save(strFilename);
                }
                return(1);
            }

            strValue = strOldValue;
            return(1);
        }
Ejemplo n.º 27
0
    public override string Convert(string strXml)
    {
        string strError = "";
        int    nRet     = 0;

        XmlDocument dom = new XmlDocument();

        try
        {
            dom.LoadXml(strXml);
        }
        catch (Exception ex)
        {
            return(ex.Message);
        }

        string        strStyle = ""; // 页面风格名称 例如"_dark"
        List <string> formats  = StringUtil.FindPrefixInList(StringUtil.SplitList(this.Formats, ','), "style_");

        if (formats.Count > 0)
        {
            strStyle = formats[0].Substring("style".Length);
        }

        string strLink = "<link href='%mappeddir%\\styles\\readerhtml" + strStyle + ".css' type='text/css' rel='stylesheet' />"
                         + "<link href=\"%mappeddir%/jquery-ui-1.8.7/css/jquery-ui-1.8.7.css\" rel=\"stylesheet\" type=\"text/css\" />"
                         + "<script type=\"text/javascript\" src=\"%mappeddir%/jquery-ui-1.8.7/js/jquery-1.4.4.min.js\"></script>"
                         + "<script type=\"text/javascript\" src=\"%mappeddir%/jquery-ui-1.8.7/js/jquery-ui-1.8.7.min.js\"></script>"
                         + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\"></meta>"
                         + "<meta http-equiv='Content-type' content='text/html; charset=utf-8' ></meta>"
                         + "<script type='text/javascript' charset='UTF-8' src='%mappeddir%\\scripts\\readerxml2html.js" + "'></script>"
                         + "<script type='text/javascript' charset='UTF-8' src='%mappeddir%\\scripts\\getsummary.js" + "'></script>";

        // 证状态
        string strReaderState = DomUtil.GetElementText(dom.DocumentElement, "state");
        string strExpireDate  = DomUtil.GetElementText(dom.DocumentElement, "expireDate");

        string strBodyClass = "";

        // return:
        //      -1  检测过程发生了错误。应当作不能借阅来处理
        //      0   可以借阅
        //      1   证已经过了失效期,不能借阅
        //      2   证有不让借阅的状态
        nRet = this.App.CheckReaderExpireAndState(dom, out strError);
        if (nRet != 0)
        {
            strBodyClass = "warning";
        }

        bool bExpired = false;

        if (nRet == 1)
        {
            bExpired = true;
        }

        StringBuilder strResult = new StringBuilder(4096);

        strResult.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");

        strResult.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n\t<head>" + strLink + "</head>\r\n\t<body"
                         + (string.IsNullOrEmpty(strBodyClass) == false ? " class='" + strBodyClass + "'" : "")
                         + ">");

        // 左右分布的大表格
        strResult.Append("\r\n\t\t<table class='layout'>");
        strResult.Append("\r\n\t\t\t<tr class='content'>");

        string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode");
        string strPersonName    = DomUtil.GetElementText(dom.DocumentElement, "name");

        string strFingerprint = DomUtil.GetElementText(dom.DocumentElement, "fingerprint");

        string strWeixinBinding = StringUtil.GetParameterByPrefix(DomUtil.GetElementText(dom.DocumentElement, "email"),
                                                                  "weixinid",
                                                                  ":");

        string strPhotoPath = "";

        if (this.RecPath != "?")
        {
            strPhotoPath = GetPhotoPath(dom, this.RecPath);
        }

        strResult.Append("<td class='photo'>");
        strResult.Append("<img id='cardphoto' class='pending' name='"
                         + (this.RecPath == "?" ? "?" : "object-path:" + strPhotoPath) // 这里直接用读者证条码号也可以,只不过前端处理速度稍慢
                         + "' src='%mappeddir%\\images\\ajax-loader.gif' alt='" + HttpUtility.HtmlEncode(strPersonName) + " 的照片'></img>");

        string strIcons = "";

        if (string.IsNullOrEmpty(strFingerprint) == false)
        {
            strIcons += "<img src='%mappeddir%\\images\\fingerprint.png' style='background-color:#ffffff;' alt='有指纹信息'>";
        }
        if (string.IsNullOrEmpty(strWeixinBinding) == false)
        {
            strIcons += "<img src='%mappeddir%\\images\\wechat_16.png' alt='有微信绑定信息'>";
        }

        if (string.IsNullOrEmpty(strIcons) == false)
        {
            strResult.Append("<br/>" + strIcons);
        }

        strResult.Append("</td>");
        strResult.Append("<td class='warning' id='insertpoint'></td>");

        // 识别信息表格
        strResult.Append("\r\n\t\t\t\t<td class='left'><table class='readerinfo'>");


        // 证条码号
        string strReaderBarcodeLink = "<a href='javascript:void(0);' onclick=\"window.external.OpenForm('ReaderInfoForm', this.innerText, true);\">" + strReaderBarcode + "</a>";

        strResult.Append("<tr class='content barcode'><td class='name'>读者证条码号</td><td class='value'>" + strReaderBarcodeLink + "</td></tr>");

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

        strResult.Append("<tr class='content readertype'><td class='name'>读者类别</td><td class='value'>" + strReaderType + "</td></tr>");


        // 姓名
        strResult.Append("<tr class='content name'><td class='name'>姓名</td><td class='value' >" + strPersonName
                         + "</td></tr>");

        // 补齐高度
        strResult.Append("<tr class='content blank'><td class='name'></td><td class='value' ></td></tr>");

        strResult.Append("</table></td>");

        strResult.Append("<td class='middle'>&nbsp;</td>");

        strResult.Append("<td class='right'>");

        strResult.Append("<table class='readerinfo'>");

        // 证状态
        strResult.Append("<tr class='content state'><td class='name'>证状态</td><td class='value'>"
                         + strReaderState + "</td></tr>");

        /*
         *      // 发证日期
         *      strResult.Append( "<tr class='content createdate'><td class='name'>发证日期</td><td class='value'>" + LocalDate(DomUtil.GetElementText(dom.DocumentElement, "createDate")) + "</td></tr>");
         */


        // 失效日期
        string strExpireDateValueClass = "expiredate";

        if (bExpired == true)
        {
            strExpireDateValueClass = "expireddate";
        }

        strResult.Append("<tr class='content " + strExpireDateValueClass + "'><td class='name'>失效日期</td><td class='value'>" + LocalDate(strExpireDate) + "</td></tr>");

        strResult.Append("<tr class='content department'><td class='name'>单位</td><td class='value'>"
                         + DomUtil.GetElementText(dom.DocumentElement, "department") + "</td></tr>");

        strResult.Append("<tr class='content comment'><td class='name'>注释</td><td class='value'><div class='wide'><div>"
                         + DomUtil.GetElementText(dom.DocumentElement, "comment") + "</td></tr>");

        // 补齐高度
        strResult.Append("<tr class='content blank'><td class='name'></td><td class='value' ></td></tr>");

        strResult.Append("</table>");

        strResult.Append("</td></tr>");

        // 大表格收尾
        strResult.Append("</table>");

        // 获得日历
        Calendar calendar = null;

        // return:
        //      -1  出错
        //      0   没有找到日历
        //      1   找到日历
        nRet = this.App.GetReaderCalendar(strReaderType,
                                          this.LibraryCode,
                                          out calendar,
                                          out strError);
        if (nRet == -1 || nRet == 0)
        {
            strResult.Append(strError);
            calendar = null;
        }

        string strWarningText = "";

        // ***
        // 违约/交费信息
        XmlNodeList nodes = dom.DocumentElement.SelectNodes("overdues/overdue");

        if (nodes.Count > 0)
        {
            strResult.Append("<div class='tabletitle'>违约/交费信息</div>");
            strResult.Append("<table class='overdue'>");
            strResult.Append("<tr class='columntitle'><td>册条码号</td><td>说明</td><td>金额</td><td nowrap>以停代金情况</td><td>起点日期</td><td>期限</td><td>终点日期</td><td>ID</td><td>注释</td></tr>");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node       = nodes[i];
                string  strBarcode = DomUtil.GetAttr(node, "barcode");
                string  strOver    = DomUtil.GetAttr(node, "reason");

                string strBorrowPeriod = DomUtil.GetAttr(node, "borrowPeriod");

                string strBorrowDate = LocalDateOrTime(DomUtil.GetAttr(node, "borrowDate"), strBorrowPeriod);

                string strReturnDate    = LocalDateOrTime(DomUtil.GetAttr(node, "returnDate"), strBorrowPeriod);
                string strID            = DomUtil.GetAttr(node, "id");
                string strPrice         = DomUtil.GetAttr(node, "price");
                string strOverduePeriod = DomUtil.GetAttr(node, "overduePeriod");

                // 把一行文字变为两行显示
                strBorrowDate = strBorrowDate.Replace(" ", "<br/>");
                strReturnDate = strReturnDate.Replace(" ", "<br/>");

                strID = SplitTwoLine(strID);

                string strComment = DomUtil.GetAttr(node, "comment");
                if (String.IsNullOrEmpty(strComment) == true)
                {
                    strComment = "&nbsp;";
                }

                // string strBarcodeLink = "<a href='" + App.OpacServerUrl + "/book.aspx?barcode=" + strBarcode + "&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";
                string strBarcodeLink = "<a href='javascript:void(0);' onclick=\"window.external.OpenForm('ItemInfoForm', this.innerText, true);\"  onmouseover=\"window.external.HoverItemProperty(this.innerText);\">" + strBarcode + "</a>";

                string strPauseInfo = "";

                if (StringUtil.IsInList("pauseBorrowing", this.App.OverdueStyle) == true &&
                    String.IsNullOrEmpty(strOverduePeriod) == false)
                {
                    string strPauseStart = DomUtil.GetAttr(node, "pauseStart");

                    if (String.IsNullOrEmpty(strPauseStart) == false)
                    {
                        strPauseInfo = "从 " + DateTimeUtil.LocalDate(strPauseStart) + " 开始,";
                    }

                    string strUnit        = "";
                    long   lOverduePeriod = 0;

                    // 分析期限参数
                    nRet = LibraryApplication.ParsePeriodUnit(strOverduePeriod,
                                                              out lOverduePeriod,
                                                              out strUnit,
                                                              out strError);
                    if (nRet == -1)
                    {
                        strError = "在分析期限参数的过程中发生错误: " + strError;
                        strResult.Append(strError);
                    }

                    long   lResultValue      = 0;
                    string strPauseCfgString = "";
                    nRet = this.App.ComputePausePeriodValue(strReaderType,
                                                            this.LibraryCode,
                                                            lOverduePeriod,
                                                            out lResultValue,
                                                            out strPauseCfgString,
                                                            out strError);
                    if (nRet == -1)
                    {
                        strError = "在计算以停代金周期的过程中发生错误: " + strError;
                        strResult.Append(strError);
                    }

                    strPauseInfo += "停借期 " + lResultValue.ToString() + LibraryApplication.GetDisplayTimeUnit(strUnit) + " (计算过程如下: 超期 " + lOverduePeriod.ToString() + LibraryApplication.GetDisplayTimeUnit(strUnit) + ",读者类型 " + strReaderType + " 的 以停代金因子 为 " + strPauseCfgString + ")";
                }

                strResult.Append("<tr class='content'>");
                strResult.Append("<td class='barcode' >" + strBarcodeLink + "</td>");
                strResult.Append("<td class='reason'><div class='wide'></div>" + strOver + "</td>");
                strResult.Append("<td class='price' >" + strPrice + "</td>");
                strResult.Append("<td class='pauseinfo'>" + strPauseInfo + "</td>");
                strResult.Append("<td class='borrowdate' >" + strBorrowDate + "</td>");
                strResult.Append("<td class='borrowperiod' >" + LibraryApplication.GetDisplayTimePeriodString(strBorrowPeriod) + "</td>");
                strResult.Append("<td class='returndate' >" + strReturnDate + "</td>");
                strResult.Append("<td class='id' >" + strID + "</td>");
                strResult.Append("<td class='comment' width='30%'>" + strComment + "</td>");
                strResult.Append("</tr>");
            }

            if (StringUtil.IsInList("pauseBorrowing", this.App.OverdueStyle) == true)
            {
                // 汇报以停代金情况
                string strPauseMessage = "";
                nRet = App.HasPauseBorrowing(
                    calendar,
                    this.LibraryCode,
                    dom,
                    out strPauseMessage,
                    out strError);
                if (nRet == -1)
                {
                    strError = "在计算以停代金的过程中发生错误: " + strError;
                    strResult.Append(strError);
                }
                if (nRet == 1)
                {
                    strResult.Append("<td colspan='8'>" + strPauseMessage + "</td>");   // ???
                }
            }

            strResult.Append("</table>");


            strWarningText += "<div class='warning amerce'><div class='number'>" + nodes.Count.ToString() + "</div><div class='text'>待交费</div></div>";
        }

        // ***
        // 借阅的册
        strResult.Append("<div class='tabletitle'>借阅信息</div>");

        nodes = dom.DocumentElement.SelectNodes("borrows/borrow");
        int nBorrowCount = nodes.Count;

        strResult.Append("<table class='borrowinfo'>");

        strResult.Append("<tr class='borrow_count'><td colspan='9' class='borrow_count'>");

        string strMaxItemCount = GetParam(strReaderType, "", "可借总册数");

        strResult.Append("最多可借:" + strMaxItemCount + " ");

        int nMax = 0;

        try
        {
            nMax = System.Convert.ToInt32(strMaxItemCount);
        }
        catch
        {
            strResult.Append("当前读者 可借总册数 参数 '" + strMaxItemCount + "' 格式错误");
            goto CONTINUE1;
        }

        strResult.Append("当前可借:" + System.Convert.ToString(Math.Max(0, nMax - nodes.Count)) + "");

CONTINUE1:

        int nOverdueCount = 0;

        strResult.Append("</td></tr>");

        if (nodes.Count > 0)
        {
            strResult.Append("<tr class='columntitle'><td>册条码号</td><td>摘要</td><td>卷册</td><td>价格</td><td>续借次</td><td>借阅日期</td><td>期限</td><td>操作者</td><td>应还日期</td><td>续借注</td></tr>");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node            = nodes[i];
                string  strBarcode      = DomUtil.GetAttr(node, "barcode");
                string  strNo           = DomUtil.GetAttr(node, "no");
                string  strBorrowDate   = DomUtil.GetAttr(node, "borrowDate");
                string  strPeriod       = DomUtil.GetAttr(node, "borrowPeriod");
                string  strOperator     = DomUtil.GetAttr(node, "operator");
                string  strRenewComment = DomUtil.GetAttr(node, "renewComment");

                string strConfirmItemRecPath = DomUtil.GetAttr(node, "recPath");
                string strBiblioRecPath      = DomUtil.GetAttr(node, "biblioRecPath");
                string strPrice         = DomUtil.GetAttr(node, "price");
                string strTimeReturning = DomUtil.GetAttr(node, "timeReturning");

                string strVolume = DomUtil.GetAttr(node, "volume");

#if NO
                string strOverDue = "";
                bool   bOverdue   = false;
                // 检查超期情况。
                // return:
                //      -1  数据格式错误
                //      0   没有发现超期
                //      1   发现超期   strError中有提示信息
                nRet = App.CheckPeriod(
                    calendar,
                    strBorrowDate,
                    strPeriod,
                    out strError);
                if (nRet == -1)
                {
                    strOverDue = strError;
                }
                else if (nRet == 1)
                {
                    strOverDue = strError;      // "已超期";
                    bOverdue   = true;
                }
                else
                {
                    strOverDue = "<a title='" + strError + "'>" + LocalDate(strTimeReturning) + "</a>";
                    // strOverDue = strError;	// 可能也有一些必要的信息,例如非工作日
                }
#endif
                string strOverDue = "";
                bool   bOverdue   = false;  // 是否超期
                {
                    DateTime timeReturning = DateTime.MinValue;
                    string   strTips       = "";

                    DateTime timeNextWorkingDay;
                    long     lOver         = 0;
                    string   strPeriodUnit = "";

                    // 获得还书日期
                    // return:
                    //      -1  数据格式错误
                    //      0   没有发现超期
                    //      1   发现超期   strError中有提示信息
                    //      2   已经在宽限期内,很容易超期
                    nRet = this.App.GetReturningTime(
                        calendar,
                        strBorrowDate,
                        strPeriod,
                        out timeReturning,
                        out timeNextWorkingDay,
                        out lOver,
                        out strPeriodUnit,
                        out strError);
                    if (nRet == -1)
                    {
                        strOverDue = strError;
                    }
                    else
                    {
                        strTips    = strError;
                        strOverDue = timeReturning.ToString("d");
                        if (nRet == 1)
                        {
                            nOverdueCount++;
                            bOverdue    = true;
                            strOverDue += " ("
                                          + string.Format(this.App.GetString("已超期s"), // 已超期 {0}
                                                          this.App.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit))
                                          + ")";
                        }

                        strOverDue = "<a title='" + strError.Replace("'", "\"") + "'>" + strOverDue + "</a>";
                    }
                }


                // string strBarcodeLink = "<a href='" + App.OpacServerUrl + "/book.aspx?barcode=" + strBarcode + "&borrower=" + strReaderBarcode + "&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";
                string strBarcodeLink = "<a href='javascript:void(0);' onclick=\"window.external.OpenForm('ItemInfoForm', this.innerText, true);\"  onmouseover=\"window.external.HoverItemProperty(this.innerText);\">" + strBarcode + "</a>";

                /* strResult.Append( "<tr class='content' "+strColor+" nowrap>"); */
                if (bOverdue == true)
                {
                    strResult.Append("<tr class='content overdue'>");
                }
                else
                {
                    strResult.Append("<tr class='content'>");
                }
                strResult.Append("<td class='barcode' nowrap>" + strBarcodeLink + "</td>");
                strResult.Append("<td class='summary pending'><br/>BC:" + strBarcode + "|" + strConfirmItemRecPath
                                 + (string.IsNullOrEmpty(strBiblioRecPath) == true ? "" : "|" + strBiblioRecPath) + "</td>");


                strResult.Append("<td class='volume' nowrap>" + HttpUtility.HtmlEncode(strVolume) + "</td>");
                strResult.Append("<td class='price' nowrap align='right'>" + strPrice + "</td>");
                strResult.Append("<td class='no' nowrap align='right'>" + strNo + "</td>");
                strResult.Append("<td class='borrowdate' >" + LocalDateOrTime(strBorrowDate, strPeriod) + "</td>");
                strResult.Append("<td class='period' nowrap>" + LibraryApplication.GetDisplayTimePeriodString(strPeriod) + "</td>");
                strResult.Append("<td class='operator' nowrap>" + strOperator + "</td>");
                strResult.Append("<td class='returndate' width='30%'>" + strOverDue + "</td>");
                strResult.Append("<td class='renewcomment' width='30%'>" + strRenewComment.Replace(";", "<br/>") + "</td>");
                strResult.Append("</tr>");
            }
        }

        strResult.Append("</table>");

        if (nOverdueCount > 0)
        {
            strWarningText += "<div class='warning overdue'><div class='number'>" + nOverdueCount.ToString() + "</div><div class='text'>已超期</div></div>";
        }

        // ***
        // 预约请求
        strResult.Append("<div class='tabletitle'>预约请求</div>");
        nodes = dom.DocumentElement.SelectNodes("reservations/request");

        if (nodes.Count > 0)
        {
            int nArriveCount = 0;

            strResult.Append("<table class='reservation'>");
            strResult.Append("<tr class='columntitle'><td nowrap>册条码号</td><td nowrap>到达情况</td><td nowrap>摘要</td><td nowrap>请求日期</td><td nowrap>操作者</td><td nowrap>配书情况</td></tr>");

            foreach (XmlElement node in nodes)
            {
                string strBarcodes    = DomUtil.GetAttr(node, "items");
                string strRequestDate = LocalTime(DomUtil.GetAttr(node, "requestDate"));

                string strOperator           = DomUtil.GetAttr(node, "operator");
                string strArrivedItemBarcode = DomUtil.GetAttr(node, "arrivedItemBarcode");

                string strSummary = this.App.GetBarcodesSummary(
                    this.SessionInfo,
                    strBarcodes,
                    strArrivedItemBarcode,
                    "html", // "html,forcelogin",
                    "" /*"target='_blank'"*/);

                string strClass = "content";

                int nBarcodesCount = GetBarcodesCount(strBarcodes);
                // 状态
                string strArrivedDate = DomUtil.GetAttr(node, "arrivedDate");
                string strState       = DomUtil.GetAttr(node, "state");
                if (strState == "arrived")
                {
                    strArrivedDate = ItemConverter.LocalTime(strArrivedDate);
                    strState       = "册 " + strArrivedItemBarcode + " 已于 " + strArrivedDate + " 到书";

                    if (nBarcodesCount > 1)
                    {
                        strState += string.Format("; 同一预约请求中的其余 {0} 册旋即失效",  // ";同一预约请求中的其余 {0} 册旋即失效"
                                                  (nBarcodesCount - 1).ToString());
                    }
                    strClass = "content active";

                    nArriveCount++;
                }

                string strBox = node.GetAttribute("box");
                if (string.IsNullOrEmpty(strBox) == false)
                {
                    strClass += " boxing";
                }

                strResult.Append("<tr class='" + strClass + "'>");
                strResult.Append("<td class='barcode'>"
                                 + MakeBarcodeListHyperLink(strBarcodes, strArrivedItemBarcode, ", ")
                                 + (nBarcodesCount > 1 ? " 之一" : "")
                                 + "</td>");
                strResult.Append("<td class='state'>" + strState + "</td>");
                strResult.Append("<td class='summary'>" + strSummary + "</td>");
                strResult.Append("<td class='requestdate'>" + strRequestDate + "</td>");
                strResult.Append("<td class='operator'>" + strOperator + "</td>");
                strResult.Append("<td class='boxing'>" + strBox + "</td>");
                strResult.Append("</tr>");
            }
            strResult.Append("</table>");

            if (nArriveCount > 0)
            {
                strWarningText += "<div class='warning arrive'><div class='number'>" + nArriveCount.ToString() + "</div><div class='text'>预约到书</div></div>";
            }
        }

        if (string.IsNullOrEmpty(strWarningText) == false)
        {
            strResult.Append("<div id='warningframe'>" + strWarningText + "</div>");
        }

        // ***
        // 借阅历史

        if (StringUtil.IsInList("noborrowhistory", this.Formats) == false)
        {
            strResult.Append("<div class='tabletitle'>借阅历史</div>");

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

            if (nodes.Count > 0)
            {
                strResult.Append("<table class='borrowhistory'>");

                strResult.Append("<tr class='borrow_count'><td colspan='10' class='borrow_count'>");

                XmlNode nodeHistory     = dom.DocumentElement.SelectSingleNode("borrowHistory");
                string  strHistoryCount = "";
                if (nodeHistory != null)
                {
                    strHistoryCount = DomUtil.GetAttr(nodeHistory, "count");
                }
                strResult.Append("共借阅: " + strHistoryCount + " 册 (下面表格中仅显示了最近借阅过的最多 " + this.App.MaxPatronHistoryItems.ToString() + " 册)");

                strResult.Append("</td></tr>");

                strResult.Append("<tr class='columntitle'><td nowrap>序</td><td nowrap>册条码号</td><td nowrap>摘要</td><td nowrap>卷册</td><td nowrap>续借次</td><td nowrap>借阅日期</td><td nowrap>期限</td><td nowrap>借阅操作者</td><td nowrap>续借注</td><td nowrap>还书日期</td><td nowrap>还书操作者</td></tr>");

                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node              = nodes[i];
                    string  strBarcode        = DomUtil.GetAttr(node, "barcode");
                    string  strNo             = DomUtil.GetAttr(node, "no");
                    string  strBorrowDate     = DomUtil.GetAttr(node, "borrowDate");
                    string  strPeriod         = DomUtil.GetAttr(node, "borrowPeriod");
                    string  strBorrowOperator = DomUtil.GetAttr(node, "borrowOperator"); // 借书操作者
                    string  strOperator       = DomUtil.GetAttr(node, "operator");       // 还书操作者
                    string  strRenewComment   = DomUtil.GetAttr(node, "renewComment");
                    // string strSummary = "";
                    string strConfirmItemRecPath = DomUtil.GetAttr(node, "recPath");
                    string strBiblioRecPath      = DomUtil.GetAttr(node, "biblioRecPath");
                    string strReturnDate         = DomUtil.GetAttr(node, "returnDate");
                    string strVolume             = DomUtil.GetAttr(node, "volume");

                    // string strBarcodeLink = "<a href='" + App.OpacServerUrl + "/book.aspx?barcode=" + strBarcode + "&borrower=" + strReaderBarcode + "&forcelogin=userid' target='_blank'>" + strBarcode + "</a>";
                    string strBarcodeLink = "<a href='javascript:void(0);'  onclick=\"window.external.OpenForm('ItemInfoForm', this.innerText, true);\" onmouseover=\"OnHover(this.innerText);\">" + strBarcode + "</a>";

                    strResult.Append("<tr class='content'>");
                    strResult.Append("<td class='index' nowrap>" + (i + 1).ToString() + "</td>");
                    strResult.Append("<td class='barcode' nowrap>" + strBarcodeLink + "</td>");
                    strResult.Append("<td class='summary pending'>BC:" + strBarcode + "|" + strConfirmItemRecPath
                                     + (string.IsNullOrEmpty(strBiblioRecPath) == true ? "" : "|" + strBiblioRecPath) + "</td>");

                    strResult.Append("<td class='volume' nowrap>" + HttpUtility.HtmlEncode(strVolume) + "</td>");
                    strResult.Append("<td class='no' nowrap align='right'>" + strNo + "</td>");
                    strResult.Append("<td class='borrowdate' >" + LocalDateOrTime(strBorrowDate, strPeriod) + "</td>");
                    strResult.Append("<td class='period' nowrap>" + LibraryApplication.GetDisplayTimePeriodString(strPeriod) + "</td>");
                    strResult.Append("<td class='borrowoperator' nowrap>" + strBorrowOperator + "</td>");
                    strResult.Append("<td class='renewcomment' width='30%'>" + strRenewComment.Replace(";", "<br/>") + "</td>");
                    strResult.Append("<td class='returndate' nowrap>" + LocalDateOrTime(strReturnDate, strPeriod) + "</td>");
                    strResult.Append("<td class='operator' nowrap>" + strOperator + "</td>");
                    strResult.Append("</tr>");
                }

                strResult.Append("</table>");
            }
        }

        strResult.Append("</body></html>");

        return(strResult.ToString());
    }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        int FillList(out string strError)
        {
            strError = "";

            this.listView1.Items.Clear();

            if (string.IsNullOrEmpty(this.XmlFilename) == true)
            {
                return(0);
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(this.XmlFilename);
            }
            catch (Exception ex)
            {
                strError = "装入文件 " + this.XmlFilename + " 到XMLDOM过程中出错: " + ex.Message;
                return(-1);
            }

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

            foreach (XmlNode node in nodes)
            {
                string strName      = DomUtil.GetAttr(node, "name");
                string strHost      = DomUtil.GetAttr(node, "host");
                string strUrl       = DomUtil.GetAttr(node, "url");
                string strLocalFile = DomUtil.GetAttr(node, "localFile");   // 2013/5/11
                string strCategory  = DomUtil.GetAttr(node, "category");

                // 用宿主名字过滤
                if (this.FilterHosts.Count > 0)
                {
                    if (this.FilterHosts.IndexOf(strHost) == -1)
                    {
                        continue;
                    }
                }

                int nImageIndex = 0;

                // 用目录过滤
                if (string.IsNullOrEmpty(strCategory) == false)
                {
                    if (MatchCategory(strCategory, this.Category) == false)
                    {
                        continue;
                    }
                    // 特殊颜色
                    nImageIndex = 1;
                }

                ListViewItem item = new ListViewItem();
                item.ImageIndex = nImageIndex;
                ListViewUtil.ChangeItemText(item, 0, strName);

                if (this.InstalledUrls.IndexOf(strUrl) != -1)
                {
                    ListViewUtil.ChangeItemText(item, 1, "已安装");
                }

                ListViewUtil.ChangeItemText(item, 2, GetHanziHostName(strHost));
                ListViewUtil.ChangeItemText(item, 3, strUrl);

                this.listView1.Items.Add(item);

                ProjectItem project = new ProjectItem();
                project.Name     = strName;
                project.Host     = strHost;
                project.Url      = strUrl;
                project.FilePath = strLocalFile;
                item.Tag         = project;
            }

            SetItemColor();

            return(0);
        }
Ejemplo n.º 30
0
        // 获得一个普通数据库的定义(包括数据库名captions,froms name captions)
        // 格式为

        /*
         * <database>
         *  <caption lang="zh-cn">中文图书</caption>
         *  <caption lang="en">Chinese book</caption>
         *  <from style="title">
         *      <caption lang="zh-cn">题名</caption>
         *      <caption lang="en">Title</caption>
         *  </from>
         *  ...
         *  <from name="__id" />
         * </database>         * */
        // return:
        //      -1  error
        //      0   not found such database
        //      1   found and succeed
        public int GetDatabaseDef(
            string strDbName,
            out string strDef,
            out string strError)
        {
            strError = "";
            strDef   = "";

            int nRet = 0;

            XmlDocument dom = new XmlDocument();

            dom.LoadXml("<database />");


            {
                ResInfoItem dbitem = KernelDbInfo.GetDbItem(
                    this.root_dir_results,
                    strDbName);
                if (dbitem == null)
                {
                    strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项";
                    return(0);
                }

                // 在根下加入<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 = dom.CreateElement("caption");
                    dom.DocumentElement.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

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

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

                // 插入<from>元素
                XmlNode fromnode = dom.CreateElement("from");
                dom.DocumentElement.AppendChild(fromnode);
                DomUtil.SetAttr(fromnode, "style", item.TypeString);    // style

                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 = dom.CreateElement("caption");
                    fromnode.AppendChild(newnode);
                    DomUtil.SetAttr(newnode, "lang", strLang);
                    DomUtil.SetNodeText(newnode, strName);
                }
            }

            strDef = dom.OuterXml;

            return(1);
        }