Ejemplo n.º 1
0
        private void MarcEditor_ParseMacro(object sender, ParseMacroEventArgs e)
        {
            string strResult = "";
            string strError = "";

            // 借助于MacroUtil进行处理
            int nRet = m_macroutil.Parse(
                e.Simulate,
                e.Macro,
                out strResult,
                out strError);
            if (nRet == -1)
            {
                e.ErrorInfo = strError;
                return;
            }

            e.Value = strResult;
        }
Ejemplo n.º 2
0
        // 获得缺省值
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        public int GetDefaultValue(int index,
            out string strValue,
            out string strError)
        {
            strValue = "";
            strError = "";

            TemplateLine line = (TemplateLine)this.templateRoot.Lines[index];
			if (line == null)
			{
                strError = "未找到序号为'" + Convert.ToString(index) + "'行";
                return -1;
			}

            if (line.DefaultValue == null)
            {
                strError = "缺省值未定义";
                return 0;
            }

            if (this.ParseMacro == null)
            {
                strError = "没有挂接事件";
                return 0;    // 没有挂接事件
            }

            ParseMacroEventArgs e = new ParseMacroEventArgs();
            e.Macro = line.DefaultValue;
            this.ParseMacro(this, e);
            if (String.IsNullOrEmpty(e.ErrorInfo) == false)
            {
                strError = e.ErrorInfo;
                return -1;
            }

            strValue = e.Value;
            return 1;
        }
Ejemplo n.º 3
0
        // 获得宏值
        // parameters:
        //      nPushIndex  需要实做的字符串事项的下标。如果为-1,表示没有要实做的事项(即全部都是模拟)
        //      strSubFieldName 子字段名。特殊地,如果为"#indicator",表示想获取该字段的指示符缺省值
        // return:
        //      -1  error
        //      0   not found 
        //      >0  found 结果的个数
        private int GetDefaultValue(
            // bool bSimulate,
            int nPushIndex,
            string strFieldName,
            string strSubFieldName,
            out List<string> results,
            out string strError)
        {
            Debug.Assert(strFieldName != null, "strFieldName参数不能为null");
            Debug.Assert(strSubFieldName != null, "strSubFieldName参数不能为null");
            // Debug.Assert(strValue != null, "strValue参数不能为null");

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

            // 检查MarcDefDom是否存在
            if (this.MarcDefDom == null)
            {
                strError = m_strMarcDomError;
                return -1;
            }

            // 根据字段名找到配置文件中的该字段的定义
            XmlNode node = null;

            if (strSubFieldName == "" || strSubFieldName == "#indicator")
            {
                // 只找到字段
                node = this.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + strFieldName + "']");
            }
            else
            {
                // 找到子字段
                node = this.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + strFieldName + "']/Subfield[@name='" + strSubFieldName + "']");
            }

            if (node == null)
            {
                return 0;   // not found def
            }

            XmlNodeList value_nodes = null;

            if (strSubFieldName == "#indicator")
            {

                value_nodes = node.SelectNodes("Property/Indicator/Property/DefaultValue");
            }
            else
            {
                value_nodes = node.SelectNodes("Property/DefaultValue");
            }

            if (value_nodes.Count == 0)
                return 0;

            for (int i = 0; i < value_nodes.Count; i++)
            {
                string strOutputValue = value_nodes[i].InnerText;

                // 去掉定义值中的\r\n或者单独的\r和\n。这种具有\r\n的效果可能由notepad中折行状态时paste到编辑配置文件对话框并保存来造成.
                strOutputValue = strOutputValue.Replace("\r", "");
                strOutputValue = strOutputValue.Replace("\n", "");

                // 子字段符号
                strOutputValue = strOutputValue.Replace("\\", new string((char)31, 1));

                ParseMacroEventArgs e = new ParseMacroEventArgs();
                e.Macro = strOutputValue;
                // e.Simulate = bSimulate;
                if (i == nPushIndex)
                    e.Simulate = false; // 实做
                else
                    e.Simulate = true;  // 模拟

                TemplateControl_ParseMacro((object)this, e);
                if (String.IsNullOrEmpty(e.ErrorInfo) == false)
                {
                    strError = e.ErrorInfo;
                    return -1;
                }

                strOutputValue = e.Value;

                /*
                strOutputValue = MacroTimeValue(strOutputValue);

                // 替换下划线
                strOutputValue = strOutputValue.Replace("_", " ");


                if (strSubFieldName == "")
                {
                    // 替换子字段符号
                    strOutputValue = strOutputValue.Replace('$', Record.SUBFLD);
                }
                 * */

                results.Add(strOutputValue);
            }

            return results.Count;
        }
Ejemplo n.º 4
0
        // 兑现宏
        void TemplateControl_ParseMacro(object sender, ParseMacroEventArgs e)
        {
            // 将一些基本的宏兑现
            // %year%%m2%%d2%%h2%%min2%%sec2%.%hsec%

            string strOutputValue = MacroTimeValue(e.Macro);

            // 替换下划线
            // 只替换前面连续的'_'
            // strOutputValue = strOutputValue.Replace("_", " ");

            // 替换字符串最前面一段连续的字符
            strOutputValue = StringUtil.ReplaceContinue(strOutputValue, '_', ' ');

            // 替换子字段符号
            strOutputValue = strOutputValue.Replace(Record.KERNEL_SUBFLD, Record.SUBFLD);   // $?

            e.Value = strOutputValue;
            e.ErrorInfo = "";

            // 如果是一般的宏, MARC编辑器控件就可以解决
            // 如果控件外围没有支持事件, 也只能这里解决部分
            if (e.Macro.IndexOf("%") == -1 || this.ParseMacro == null)
            {
                return;
            }
            else
            {
                // 否则还需要求助于宿主
                ParseMacroEventArgs e1 = new ParseMacroEventArgs();
                e1.Macro = e.Value; // 第一次处理过的, 再级联处理
                e1.Simulate = e.Simulate;
                this.ParseMacro(this, e1);

                e.Value = e1.Value;
                e.ErrorInfo = e1.ErrorInfo;
                return;
            }
        }
Ejemplo n.º 5
0
        // 获得宏值
        // parameters:
        //      strSubFieldName 子字段名。特殊地,如果为"#indicator",表示想获取该字段的指示符缺省值
        // return:
        //      -1  error
        //      0   not found 
        //      1   found
        private int GetDefaultValue(
            bool bSimulate,
            string strFieldName,
            string strSubFieldName,
            out string strOutputValue,
            out string strError)
        {
            Debug.Assert(strFieldName != null, "strFieldName参数不能为null");
            Debug.Assert(strSubFieldName != null, "strSubFieldName参数不能为null");
            // Debug.Assert(strValue != null, "strValue参数不能为null");

            strError = "";
            strOutputValue = "";

            // 检查MarcDefDom是否存在
            if (this.MarcDefDom == null)
            {
                strError = m_strMarcDomError;
                return -1;
            }

            // 根据字段名找到配置文件中的该字段的定义
            XmlNode node = null;

            if (strSubFieldName == "" || strSubFieldName == "#indicator")
            {
                // 只找到字段
                node = this.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + strFieldName + "']");
            }
            else
            {
                // 找到子字段
                node = this.MarcDefDom.DocumentElement.SelectSingleNode("Field[@name='" + strFieldName + "']/Subfield[@name='" + strSubFieldName + "']");
            }

            if (node == null)
            {
                return 0;   // not found def
            }

            XmlNode nodeValue = null;

            if (strSubFieldName == "#indicator")
            {
                nodeValue = node.SelectSingleNode("Property/Indicator");
            }
            else
            {
                nodeValue = node.SelectSingleNode("Property/DefaultValue");
            }
            if (nodeValue == null)
                return 0;

            if (strSubFieldName == "#indicator")
            {
                strOutputValue = DomUtil.GetAttr(nodeValue, "DefaultValue");
            }
            else
            {
                strOutputValue = nodeValue.InnerText;
            }

            // 去掉定义值中的\r\n或者单独的\r和\n。这种具有\r\n的效果可能由notepad中折行状态时paste到编辑配置文件对话框并保存来造成.
            strOutputValue = strOutputValue.Replace("\r", "");
            strOutputValue = strOutputValue.Replace("\n", "");


            ParseMacroEventArgs e = new ParseMacroEventArgs();
            e.Macro = strOutputValue;
            e.Simulate = bSimulate;

            TemplateControl_ParseMacro((object)this, e);
            if (String.IsNullOrEmpty(e.ErrorInfo) == false)
            {
                strError = e.ErrorInfo;
                return -1;
            }

            strOutputValue = e.Value;

            /*
            strOutputValue = MacroTimeValue(strOutputValue);

            // 替换下划线
            strOutputValue = strOutputValue.Replace("_", " ");


            if (strSubFieldName == "")
            {
                // 替换子字段符号
                strOutputValue = strOutputValue.Replace('$', Record.SUBFLD);
            }
             */
            return 1;
        }