示例#1
0
        // 后插字段
        /// <summary>
        /// 插入一个新的字段对象,在参考位置的后面
        /// </summary>
        /// <param name="nIndex">插入位置。字段对象将插入到这个位置的后面</param>
        /// <param name="field">字段对象</param>
        public void InsertAfter(int nIndex,
                                Field field)
        {
            Debug.Assert(nIndex < this.Count, "InsertAfterField(),nIndex参数不合法");

            // 内存对象加一个
            this.InsertInternal(nIndex + 1,
                                field);

            // 根据字段类型,设焦点位置
            if (field.m_strName == this.MarcEditor.DefaultFieldName)
            {
                this.MarcEditor.SetActiveField(field, 1);
            }
            else if (Record.IsControlFieldName(field.m_strName) == true)
            {
                this.MarcEditor.SetActiveField(field, 3);
            }
            else
            {
                this.MarcEditor.SetActiveField(field, 2);
            }

            // 失效从当前新增字段到末尾的区域
            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = false;
            iRect.rect = this.MarcEditor.GetItemBounds(nIndex + 1,
                                                       -1,
                                                       BoundsPortion.FieldAndBottom);
            this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Horz,
                                                 iRect);
        }
示例#2
0
        // 对内
        // 追加一个新字段,供外部使用
        // 该函数不仅处理内存对象,还处理界面的事情
        // parameters:
        //		strName	新字段名称
        //		strIndicator	新字段指示符
        //		strValue	新字段值(里面可能包含正规的字段指示符ASCII31)
        /// <summary>
        /// 新增一个字段对象
        /// </summary>
        /// <param name="strName">字段名</param>
        /// <param name="strIndicator">字段指示符</param>
        /// <param name="strValue">字段内容</param>
        /// <param name="bInOrder">是否要按照字段名顺序插入到适当位置</param>
        /// <returns>新增的字段对象</returns>
        public Field Add(string strName,
                         string strIndicator,
                         string strValue,
                         bool bInOrder)
        {
            strValue = strValue.Replace(Record.SUBFLD, Record.KERNEL_SUBFLD);

            int   nOutputPosition = -1;
            Field field           = this.AddInternal(strName,
                                                     strIndicator,
                                                     strValue,
                                                     true,
                                                     bInOrder,
                                                     out nOutputPosition);


            // 界面失效区域

            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = false;
            if (nOutputPosition == -1)
            {
                iRect.rect = this.MarcEditor.GetItemBounds(this.Count - 1,
                                                           1,
                                                           BoundsPortion.FieldAndBottom);
            }
            else
            {
                if (this.MarcEditor.FocusedFieldIndex > nOutputPosition)
                {
                    this.MarcEditor.SelectedFieldIndices[0] = (int)this.MarcEditor.SelectedFieldIndices[0] + 1;
                }
                iRect.rect = this.MarcEditor.GetItemBounds(nOutputPosition,
                                                           -1,
                                                           BoundsPortion.FieldAndBottom);
            }

            // 根据字段类型,设焦点位置
            if (field.m_strName == this.MarcEditor.DefaultFieldName)
            {
                this.MarcEditor.SetActiveField(field, 1);
            }
            else if (Record.IsControlFieldName(field.m_strName) == true)
            {
                this.MarcEditor.SetActiveField(field, 3);
            }
            else
            {
                this.MarcEditor.SetActiveField(field, 2);
            }

            //this.marcEditor.ActiveField(field,3);

            this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Both,
                                                 iRect);

            return(field);
        }
示例#3
0
        // 前插一个字段
        /// <summary>
        /// 插入一个字段对象
        /// </summary>
        /// <param name="nIndex">位置</param>
        /// <param name="field">字段对象</param>
        public /*override*/ new void Insert(int nIndex,
                                            Field field)
        {
            Debug.Assert(nIndex <= this.Count, "nIndex参数不合法");
            // Debug.Assert(oValue is Field, "必须为Field类型");
            // Field field = (Field)oValue;

            // 把内容还原,把当前焦点设为空,省得Active时把下标搞错
            this.MarcEditor.ClearSelectFieldIndices();

            this.InsertInternal(nIndex,
                                field);

            // 根据字段类型,设焦点位置
            if (field.m_strName == this.MarcEditor.DefaultFieldName)
            {
                this.MarcEditor.SetActiveField(field, 1);
            }
            else if (Record.IsControlFieldName(field.m_strName) == true)
            {
                this.MarcEditor.SetActiveField(field, 3);
            }
            else
            {
                this.MarcEditor.SetActiveField(field, 2);
            }

            // 失效范围
            int nStartIndex = 0;

            if (nIndex > 0)
            {
                nStartIndex = nIndex - 1;
            }
            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = false;
            iRect.rect = this.MarcEditor.GetItemBounds(nStartIndex,
                                                       -1,
                                                       BoundsPortion.FieldAndBottom);
            this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Both,
                                                 iRect);
        }
示例#4
0
        // 删除一个字段,可供内部或外部使用,
        // 该函数不仅处理内存对象,还处理界面的事情
        // parameters:
        //		nFieldIndex	字段索引号
        /// <summary>
        /// 在指定位置删除一个字段对象
        /// </summary>
        /// <param name="nFieldIndex">位置</param>
        public /*override*/ new void RemoveAt(int nFieldIndex)
        {
            this.MarcEditor.Flush();
            this.RemoveAtInternal(nFieldIndex);

            // 把小edit控件隐藏
            this.MarcEditor.SelectedFieldIndices.Remove(nFieldIndex);
            this.MarcEditor.HideTextBox();

            if (nFieldIndex < this.Count)
            {
                this.MarcEditor.SetActiveField(nFieldIndex, this.MarcEditor.m_nFocusCol);
            }

            // 应把失效区域计算出来,进行优化
            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = false;
            //iRect.rect =
            this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Vert,
                                                 iRect);
        }
示例#5
0
        /// <summary>
        /// 删除若干字段对象
        /// </summary>
        /// <param name="fieldIndices">位置下标数组</param>
        public void RemoveAt(int[] fieldIndices)
        {
            // 清除选中对象
            this.MarcEditor.ClearSelectFieldIndices();

            int nMixIndex = 1000;

            for (int i = 0; i < fieldIndices.Length; i++)
            {
                int nIndex = fieldIndices[i];
                if (nIndex < nMixIndex)
                {
                    nMixIndex = nIndex;
                }
                this[nIndex] = null;
            }

            for (int i = 0; i < this.Count; i++)
            {
                if (this[i] == null)
                {
                    this.RemoveAtInternal(i);
                    i--;
                }
            }

            if (nMixIndex < this.Count)
            {
                this.MarcEditor.SetActiveField(nMixIndex, this.MarcEditor.m_nFocusCol);
            }

            // 应把失效区域计算出来,进行优化
            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = true;
            this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Vert,
                                                 iRect);
        }
示例#6
0
        // 设Marc数据设到内存对象中
        // parameters:
        //		strMarc	Marc记录 机内格式
        internal int SetMarc(string strMarc,
                             bool bCheckMarcDef,
                             out string strError)
        {
            strError = "";

            bool bHasFocus = this.marcEditor.Focused;

            if (strMarc == null)
            {
                strMarc = "";
            }

            if (strMarc.Length < 24)
            {
                strMarc = strMarc + new string('?', 24 - strMarc.Length);
            }

            // 清空原来的内存对象
            this.marcEditor.ClearSelectFieldIndices();
            this.Fields.Clear();



            /*
             *
             * if (bCheckMarcDef == true && this.marcEditor.MarcDefDom == null)
             *      {
             *              GetConfigFileEventArgs ar = new GetConfigFileEventArgs();
             *              ar.Path = "marcdef";
             *              ar.Stream = null;
             *
             *              this.marcEditor.OnGetConfigFile(ar);
             *              if (ar.ErrorInfo != "")
             *              {
             *                      strError = "获取marcdef出错,原因:" + ar.ErrorInfo;
             *                      return -1;
             *              }
             *              if (ar.Stream != null)
             *              {
             *                      ar.Stream.Seek(0, SeekOrigin.Begin);
             *                      this.marcEditor.MarcDefDom = new XmlDocument();
             *                      try
             *                      {
             *                              this.marcEditor.MarcDefDom.Load(ar.Stream);
             *                      }
             *                      catch(Exception ex )
             *                      {
             *                              this.marcEditor.MarcDefDom = null;
             *                              strError = "加载marcdef配置文件到dom时出错:" + ex.Message;
             *                              return -1;
             *                      }
             *                      ar.Stream.Close();
             *              }
             *      }
             *
             * */


            List <string> fields = null;

            strMarc = strMarc.Replace(Record.SUBFLD, Record.KERNEL_SUBFLD);
            Record.GetMarcFields(strMarc,
                                 out fields);
            if (fields == null)
            {
                return(0);
            }

            // TODO: 在每个子字段符号前插入\x200e符号
            for (int i = 0; i < fields.Count; i++)
            {
                string strText = fields[i];

                int nOutputPosition;

                string strName      = "";
                string strIndicator = "";
                string strValue     = "";
                if (i == 0)                 // 取头标区
                {
                    strValue = strText;
                    if (strValue.Length != 24)
                    {
                        if (strValue.Length > 24)
                        {
                            strValue = strText.Substring(0, 24);
                        }
                        else
                        {
                            strValue = strText + new string(' ', 24 - strText.Length);
                        }
                    }
                    this.Fields.AddInternal("###",
                                            "",
                                            strValue,
                                            false,     //bFireTextChanged
                                            false,     //bInOrder
                                            out nOutputPosition);
                    continue;
                }

                if (strText.Length < 3)
                {
                    strText = strText + new string(' ', 3 - strText.Length);
                }

                strName = strText.Substring(0, 3);
                if (IsControlFieldName(strName) == true)
                {
                    strIndicator = "";
                    strValue     = strText.Substring(3);
                }
                else
                {
                    if (strText.Length < 5)
                    {
                        strText = strText + new string(' ', 5 - strText.Length);
                    }

                    strIndicator = strText.Substring(3, 2);
                    strValue     = strText.Substring(5);
                }
                // 可以考虑把字段加好了再统计计算显示页面
                this.Fields.AddInternal(strName,
                                        strIndicator,
                                        strValue,
                                        false,  //bFireTextChanged
                                        false,  //bInOrder
                                        out nOutputPosition);
            }

            // 总体触发一次TextChnaged事件
            this.marcEditor.FireTextChanged();

            this.marcEditor.InitialFonts();

            // 设第一个节点为当前活动焦点
            if (bHasFocus == true)
            {
                if (this.Fields.Count > 0)
                {
                    this.marcEditor.SetActiveField(0, 3, true);
                }
            }
            else
            {
                /*
                 * if (this.Fields.Count > 0)
                 *  this.marcEditor.SetActiveField(0, 3, false);
                 * */
            }

            InvalidateRect iRect = new InvalidateRect();

            iRect.bAll = true;
            this.marcEditor.AfterDocumentChanged(ScrollBarMember.Both,
                                                 iRect);

            return(0);
        }