Example #1
0
        // 将机内格式的字符串设置到字段
        // 最后一个字符可以是 30 (表示字段结束),也可以没有这个字符
        void setFieldText(string strText)
        {
            // 去掉末尾的 30 字符
            if (strText != null && strText.Length >= 1)
            {
                if (strText[strText.Length - 1] == (char)30)
                {
                    strText = strText.Substring(0, strText.Length - 1);
                }
            }

            if (string.IsNullOrEmpty(strText) == true)
            {
                throw new Exception("字段 Text 不能设置为空");
            }

            if (strText.Length < 3)
            {
                throw new Exception("字段 Text 不能设置为小于 3 字符");
            }

            string strFieldName = strText.Substring(0, 3);

            strText = strText.Substring(3); // 剩余部分

            this.m_strName = strFieldName;
            if (MarcNode.isControlFieldName(strFieldName) == true)
            {
                throw new Exception("MARC 外围字段的字段名不能使用控制字段名 '" + strFieldName + "'");
            }
            else
            {
                // 普通字段

                // 剩下的内容为空
                if (string.IsNullOrEmpty(strText) == true)
                {
                    this.Indicator = DefaultIndicator;
                    return;
                }

                // 还剩下一个字符
                if (strText.Length < 2)
                {
                    Debug.Assert(strText.Length == 1, "");
                    this.Indicator = strText + new string(MarcQuery.DefaultChar, 1);
                    return;
                }

                // 剩下两个字符以上
                this.m_strIndicator = strText.Substring(0, 2);
                this.Content        = strText.Substring(2);
            }
        }
Example #2
0
        // 将机内格式的字符串设置到字段
        // $1200  $axxx$bxxx
        void setFieldText(string strText)
        {
            if (string.IsNullOrEmpty(strText) == true)
            {
                throw new Exception("内嵌字段 Text 不能设置为空");
            }
            if (strText[0] == MarcQuery.SUBFLD[0])
            {
                if (strText.Length < 5)
                {
                    throw new Exception("内嵌字段 Text 不能设置为小于 5 字符");
                }
                if (strText[0] != MarcQuery.SUBFLD[0])
                {
                    throw new Exception("内嵌字段 Text 第一字符必须是子字段符号");
                }
                if (strText[1] != '1')
                {
                    throw new Exception("内嵌字段 Text 第二字符必须为 '1'");
                }

                // 去掉头部的 $1  字符
                strText = strText.Substring(2);
                if (strText.Length < 3)
                {
                    throw new Exception("字段 Text 剥离前二字符后,不能设置为小于 3 字符");
                }
            }
            else
            {
                if (strText.Length < 3)
                {
                    throw new Exception("内嵌字段 Text 不能设置为小于 3 字符");
                }
            }

            string strFieldName = strText.Substring(0, 3);

            strText = strText.Substring(3); // 剩余部分

            this.m_strName = strFieldName;
            if (MarcNode.isControlFieldName(strFieldName) == true)
            {
                // 控制字段
                this.m_strIndicator = "";

                // 剩下的内容为空
                if (string.IsNullOrEmpty(strText) == true)
                {
                    this.Content = "";
                    return;
                }

                this.m_strContent = strText;    // 不要用this.Content,因为会惊扰到重新创建下级的机制
            }
            else
            {
                // 普通字段

                // 剩下的内容为空
                if (string.IsNullOrEmpty(strText) == true)
                {
                    this.Indicator = DefaultIndicator;
                    return;
                }

                // 还剩下一个字符
                if (strText.Length < 2)
                {
                    Debug.Assert(strText.Length == 1, "");
                    this.Indicator = strText + new string(MarcQuery.DefaultChar, 1);
                    return;
                }

                // 剩下两个字符以上
                this.m_strIndicator = strText.Substring(0, 2);
                this.Content        = strText.Substring(2);
            }
        }