コード例 #1
0
ファイル: EasyMarcControl.cs プロジェクト: renyh1013/dp2
        internal void ToggleHide(FieldLine field)
        {
            this.DisableUpdate();
            try
            {
                bool bNewValue = !field.Visible;

                field.Visible = bNewValue;

                int nStart = this.Items.IndexOf(field);
                if (nStart == -1)
                    return;

                if (field.ExpandState != ExpandState.Collapsed)
                {
                    // 将下属子字段显示或者隐藏
                    for (int i = nStart + 1; i < this.Items.Count; i++)
                    {
                        EasyLine current = this.Items[i];
                        if (current is FieldLine)
                            break;
                        if (current.Visible != bNewValue)
                            current.Visible = bNewValue;
                    }
                }
            }
            finally
            {
                this.EnableUpdate();
            }
        }
コード例 #2
0
ファイル: EasyMarcControl.cs プロジェクト: renyh1013/dp2
        // 插入一个新的字段
        public FieldLine NewField(int index)
        {
            EasyLine ref_line = null;

            if (index < this.Items.Count)
                ref_line = this.Items[index];

            if (ref_line is SubfieldLine)
            {
                ref_line = GetFieldLine(ref_line as SubfieldLine);
                if (ref_line == null)
                {
                    throw new Exception("index 为 " + index.ToString() + " 的子字段行没有找到字段行");
                }
                index = this.Items.IndexOf(ref_line);
                Debug.Assert(index != -1, "");
            }

            // 询问字段名
            NewSubfieldDialog dlg = new NewSubfieldDialog();
            GuiUtil.SetControlFont(dlg, this.Font);
            // dlg.Font = this.Font;

            dlg.Text = "新字段";
            dlg.AutoComplete = true;

            if (ref_line != null)
                dlg.NameString = ref_line.Name;
            else
                dlg.NameString = this.DefaultFieldName;
            dlg.MarcDefDom = this.MarcDefDom;
            dlg.Lang = this.Lang;

            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return null;

            bool bControlField = Record.IsControlFieldName(dlg.NameString);
            string strDefaultValue = "";
            string strIndicator = "  ";
            if (bControlField == false)
                strDefaultValue = new string((char)31, 1) + "a";

            List<string> results = null;
            string strError = "";
            // 获得宏值
            // parameters:
            //      strSubFieldName 子字段名。特殊地,如果为"#indicator",表示想获取该字段的指示符缺省值
            // return:
            //      -1  error
            //      0   not found 
            //      1   found
            int nRet = GetDefaultValue(
                0,  // index,
                dlg.NameString,
                "",
                out results,
                out strError);
            if (nRet == -1)
                MessageBox.Show(this, strError);

            if (results != null
                && results.Count > 0)
            {
                strDefaultValue = results[0];
                if (bControlField == false)
                    SplitDefaultValue(strDefaultValue,
                        out strIndicator,
                        out strDefaultValue);
            }

            bool bChanged = false;

            // 辅助剖析子字段的对象
            MarcField field_node = new MarcField(dlg.NameString, strIndicator, strDefaultValue);

            FieldLine field_line = new FieldLine(this);
            field_line.IsControlField = bControlField;
            field_line.Name = dlg.NameString;
            field_line.Caption = GetCaption(dlg.NameString, "", this._includeNumber);
            if (bControlField == false)
            {
                field_line.Indicator = strIndicator;  // 从 marcdef 中获得缺省的指示符值
                field_line.ExpandState = ExpandState.Expanded;
            }

            EasyLine after_line = null;
#if FIX
            bool bExpanded = false;
            bool bHideChanged = false;
#endif
            if (dlg.InsertBefore == true)
            {
                after_line = ref_line;
            }
            else
            {
                // 如果插入点是字段行,需要跳过下属的子字段行
                // EasyLine ref_line = this.Items[index];
                if (ref_line is FieldLine)
                {
                    List<EasyLine> lines = GetSubfieldLines(ref_line as FieldLine);
                    index += lines.Count + 1;
                }
                else
                    index++;

                if (index < this.Items.Count)
                    after_line = this.Items[index];
            }

#if FIX
            if (after_line != null)
            {
                // 如果插入位置后面一个字段是隐藏状态,则会出现故障,需要先修改为显示状态,插入后再隐藏
                if (after_line is FieldLine && after_line.Visible == false)
                {
                    this.ToggleHide(after_line as FieldLine);
                    bHideChanged = true;
                }
                // 如果本字段是收缩状态,则会出现故障,需要先修改为展开状态,插入后再收缩
                if (after_line.ExpandState == ExpandState.Collapsed)
                {
                    this.ToggleExpand(after_line);
                    Debug.Assert(after_line.ExpandState == ExpandState.Expanded, "");
                    bExpanded = true;
                }
            }
#endif

            InsertNewLine(index++,
    field_line,
    false);
            bChanged = true;

            // 如果必要,创建子字段对象
            foreach (MarcSubfield subfield_node in field_node.ChildNodes)
            {
                SubfieldLine subfield_line = new SubfieldLine(this);
                subfield_line.Name = subfield_node.Name;
                subfield_line.Caption = GetCaption(field_node.Name, subfield_node.Name, this._includeNumber);
                subfield_line.Content = subfield_node.Content;
                InsertNewLine(index++,
                    subfield_line,
                    false);
                bChanged = true;
            }

#if FIX
            // 把参考行恢复到以前的状态
            if (after_line != null && bExpanded == true)
            {
                this.ToggleExpand(after_line);
                Debug.Assert(after_line.ExpandState == ExpandState.Collapsed, "");
            }
            if (after_line != null && bHideChanged == true)
            {
                this.ToggleHide(after_line as FieldLine);
            }
#endif
            if (bChanged == true)
                this.FireTextChanged();

            return field_line;
        }
コード例 #3
0
ファイル: EasyMarcControl.cs プロジェクト: renyh1013/dp2
        // 获得一个字段行下属的全部子字段行
        List<EasyLine> GetSubfieldLines(FieldLine field)
        {
            List<EasyLine> results = new List<EasyLine>();
            int nStart = this.Items.IndexOf(field);
            if (nStart == -1)
                return results;
            for (int i = nStart + 1; i < this.Items.Count; i++)
            {
                EasyLine line = this.Items[i];
                if (line is FieldLine)
                    break;
                results.Add(line);
            }

            return results;
        }
コード例 #4
0
ファイル: EasyMarcControl.cs プロジェクト: renyh1013/dp2
        // 设置 MARC 记录内容
        public void SetMarc(string strMarc)
        {
            this.Clear();
            this.MarcDefDom = null;  // 迫使重新获得字段名提示信息

            this.DisableUpdate();
            try
            {
                int nLineIndex = 0;
                MarcRecord record = new MarcRecord(strMarc);
                this._header = record.Header.ToString();    // 头标区
                foreach (MarcField field in record.ChildNodes)
                {
                    FieldLine field_line = new FieldLine(this);
                    field_line.Name = field.Name;
                    field_line.Caption = GetCaption(field.Name, "", this._includeNumber);
                    // field_line.Indicator = field.Indicator;
                    InsertNewLine(nLineIndex++,
                        field_line,
                        false);
                    field_line.IsControlField = field.IsControlField;
                    if (field.IsControlField == true)
                    {
                        field_line.Content = field.Content;
                        field_line.ExpandState = ExpandState.None;
                    }
                    else
                    {
#if NO
                        // 指示符行
                        IndicatorLine indicator_line = new IndicatorLine(this);
                        indicator_line.Name = "";
                        indicator_line.Caption = "指示符";
                        indicator_line.Content = field.Indicator;
                        InsertNewLine(nLineIndex++,
                            indicator_line);
#endif
                        field_line.Indicator = field.Indicator;

                        foreach (MarcSubfield subfield in field.ChildNodes)
                        {
                            SubfieldLine subfield_line = new SubfieldLine(this);
                            subfield_line.Name = subfield.Name;
                            subfield_line.Caption = GetCaption(field.Name, subfield.Name, this._includeNumber);
                            subfield_line.Content = subfield.Content;
                            InsertNewLine(nLineIndex++,
                                subfield_line,
                                false);
                        }

                        field_line.ExpandState = ExpandState.Expanded;
                    }
                }

                this.Changed = false;
                ResetLineState();
            }
            finally
            {
                this.EnableUpdate();
            }
        }