Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        // 获得字段的MARC格式
        // parameters:
        //      bAddFLDEND  是否加字段结束符
        // return:
        //      字段的MARC字符串
        /// <summary>
        /// 获取本字段的 MARC 字符串 (机内格式)
        /// </summary>
        /// <param name="bAddFLDEND">是否包含字段结束符</param>
        /// <returns>MARC 字符串</returns>
        public string GetFieldMarc(bool bAddFLDEND)
        {
            if (this.Name == "###") // 头标区
            {
                this.m_strValue = this.m_strValue.PadRight(24, '?');
                return(this.m_strValue);
            }


            if (Record.IsControlFieldName(this.m_strName) == true) // 控制字段
            {
                if (this.Indicator != "")
                {
                    //Debug.Assert(false,"不可能的情况,控制字段无字段指示符");
                    this.m_strIndicator = "";
                }
            }
            else
            {
                if (this.Indicator.Length != 2)
                {
                    //Debug.Assert(false,"不可能的情况,字段指示符1必须是两位");

                    if (this.m_strIndicator.Length > 2)
                    {
                        this.m_strIndicator = this.m_strIndicator.Substring(0, 2);
                    }
                    else
                    {
                        this.m_strIndicator = this.m_strIndicator.PadLeft(2, ' ');
                    }
                }
            }
            string strFieldMarc = this.m_strName + this.m_strIndicator + this.m_strValue;

            if (bAddFLDEND == true)
            {
                strFieldMarc += Record.FLDEND;
            }


            strFieldMarc = strFieldMarc.Replace(Record.KERNEL_SUBFLD, Record.SUBFLD);
#if BIDI_SUPPORT
            strFieldMarc = strFieldMarc.Replace("\x200e", "");
#endif
            return(strFieldMarc);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        // 画单元格,包括背景,文字 和 左上线条
        // parameter:
        //		g	Graphics对象
        //		nCol	列号
        //				0 字段说明;
        //				1 字段名;
        //				2 字段指示符
        //				3 字段内容
        //		rect	区域 如果为null,则自动根据列号计算 但目前不支持
        // return:
        //		void
        internal void DrawCell(Graphics g,
                               int nCol,
                               Rectangle rect)
        {
            Debug.Assert(g != null, "g参数不能为null");

            string strText = "";
            int    nWidth  = 0;

            bool bEnabled  = this.container.MarcEditor.Enabled;
            bool bReadOnly = this.container.MarcEditor.ReadOnly;

            Brush brush = null;

            try
            {
                if (nCol == 0)
                {
                    // NameCaption

                    Color backColor;

                    if (bEnabled == false || bReadOnly == true)
                    {
                        backColor = SystemColors.Control;
                    }
                    else
                    {
                        backColor = this.container.MarcEditor.defaultNameCaptionBackColor;
                    }


                    // 如果本行为当前活动行,则名称部分高亮显示
                    if (this.Selected == true)//this.container.marcEditor.CurField == this)
                    {
                        if (backColor.GetBrightness() < 0.5f)
                        {
                            backColor = ControlPaint.Light(backColor);
                        }
                        else
                        {
                            backColor = ControlPaint.Dark(backColor);
                        }
                    }

                    strText = this.m_strNameCaption;
                    nWidth  = this.container.record.NameCaptionPureWidth;
                    brush   = new SolidBrush(backColor);
                }
                else if (nCol == 1)
                {
                    // Name
                    Color backColor;

                    if (bEnabled == false || bReadOnly == true)
                    {
                        backColor = SystemColors.Control;
                    }
                    else
                    {
                        backColor = this.container.MarcEditor.defaultNameBackColor;
                    }

                    if (this.Name == "###")
                    {
                        backColor = this.container.record.marcEditor.defaultNameCaptionBackColor;
                    }

                    // 如果本行为当前活动行,则名称部分高亮显示
                    if (this.Selected == true)//this.container.marcEditor.FocusedField == this)
                    {
                        backColor = ControlPaint.Light(backColor);
                    }

                    strText = this.m_strName;
                    nWidth  = this.container.record.NamePureWidth;
                    brush   = new SolidBrush(backColor);
                }
                else if (nCol == 2)
                {
                    // Indicator
                    Color backColor;

                    if (bEnabled == false || bReadOnly == true)
                    {
                        backColor = SystemColors.Control;
                    }
                    else
                    {
                        backColor = this.container.MarcEditor.defaultIndicatorBackColor;
                    }

                    if (Record.IsControlFieldName(this.Name) == true)
                    {
                        backColor = this.container.MarcEditor.defaultIndicatorBackColorDisabled;
                    }

                    // 如果本行为当前活动行,则名称部分高亮显示
                    if (this.Selected == true)//this.container.marcEditor.FocusedField == this)
                    {
                        backColor = ControlPaint.Light(backColor);
                    }

                    strText = this.m_strIndicator;
                    nWidth  = this.container.record.IndicatorPureWidth;
                    brush   = new SolidBrush(backColor);
                }
                else if (nCol == 3)
                {
                    // m_strValue
                    strText = this.m_strValue;
                    nWidth  = this.container.record.ValuePureWidth + 0; // 1为微调,正好!
                    if (bEnabled == false || bReadOnly == true)
                    {
                        brush = new SolidBrush(SystemColors.Control);
                    }
                    else
                    {
                        brush = new SolidBrush(this.container.MarcEditor.defaultContentBackColor);
                    }
                }
                else
                {
                    Debug.Assert(false, "nCol的值'" + Convert.ToString(nCol) + "'不合法");
                }

                //               new Point(-this.container.MarcEditor.DocumentOrgX + 0, -this.container.MarcEditor.DocumentOrgY + this.container.MarcEditor.DocumentHeight),
                //new Point(-this.container.MarcEditor.DocumentOrgX + this.container.MarcEditor.DocumentWidth, - this.container.MarcEditor.DocumentOrgY + 0),

                using (LinearGradientBrush linGrBrush = new LinearGradientBrush(
                           new Point(0, 0),
                           new Point(this.container.MarcEditor.DocumentWidth, 0),
                           Color.FromArgb(255, 240, 240, 240), // 240, 240, 240
                           Color.FromArgb(255, 255, 255, 255)  // Opaque red
                           ))                                  // Opaque blue
                {
                    linGrBrush.GammaCorrection = true;

                    // --------画背景----------------------------

                    if ((nCol == 1 || nCol == 2 || nCol == 3) &&
                        (bEnabled == true && bReadOnly == false))
                    {
                        g.FillRectangle(linGrBrush, rect);
                    }
                    else
                    {
                        g.FillRectangle(brush, rect);
                    }
                }

                // --------画线条----------------------------

                // 只画上,左

                // 画上方的线条
                Field.DrawLines(g,
                                rect,
                                this.container.record.GridHorzLineHeight,
                                0,
                                0,
                                0,
                                this.container.record.marcEditor.defaultHorzGridColor);

                // 画左方的线条
                int nGridWidth = 0;
                if (nCol == 1)
                {
                    nGridWidth = this.container.record.GridVertLineWidthForSplit;
                }
                else
                {
                    nGridWidth = this.container.record.GridVertLineWidth;
                }

                // indicator左边的竖线短一点
                if (nCol == 2)
                {
                    rect.Y     += 2;
                    rect.Height = this.container.record.NamePureHeight;
                }

                Field.DrawLines(g,
                                rect,
                                0,
                                0,
                                nGridWidth,//this.container.GridVertLineWidth,
                                0,
                                this.container.MarcEditor.defaultVertGridColor);

                if (nCol == 2)  // 还原
                {
                    rect.Y -= 2;
                }

                // --------画文字----------------------------
                if (nWidth > 0)
                {
                    Rectangle textRect = new Rectangle(
                        rect.X + nGridWidth /*this.container.GridVertLineWidth*/ + this.container.record.CellLeftBlank,
                        rect.Y + this.container.record.GridHorzLineHeight + this.container.record.CellTopBlank,
                        nWidth,
                        this.PureHeight);

                    // 这里的 font 是引用,因此不需要释放
                    Font font = null;
                    if (nCol == 0)
                    {
                        font = this.container.MarcEditor.CaptionFont;
                        //Debug.Assert(font != null, "");
                    }
                    else if (nCol == 1 || nCol == 2)
                    {
                        font = this.container.MarcEditor.FixedSizeFont;
                        //Debug.Assert(font != null, "");
                    }
                    else
                    {
                        font = this.container.MarcEditor.Font;
                        // Debug.Assert(font != null, "");
                    }

                    if (font == null)
                    {
                        font = this.container.MarcEditor.Font;
                    }

                    Debug.Assert(font != null, "");


                    // System.Drawing.Text.TextRenderingHint oldrenderhint = g.TextRenderingHint;
                    // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                    if (nCol == 0)  // 字段名提示
                    {
                        /*
                         * StringFormat format = StringFormat.GenericDefault; //new StringFormat();
                         * g.DrawString(strText,
                         *  font,
                         *  brush,	// System.Drawing.Brushes.Blue,
                         *  textRect,
                         *  format);
                         */

                        Color textcolor = this.container.MarcEditor.defaultNameCaptionTextColor;

                        if (this.Selected == true)
                        {
                            textcolor = ReverseColor(textcolor);
                        }

                        TextRenderer.DrawText(
                            g,
                            strText,
                            font,
                            textRect,
                            textcolor,
                            TextFormatFlags.EndEllipsis);
                    }
                    else if (nCol == 1)    // 字段名
                    {
                        TextRenderer.DrawText(
                            g,
                            strText,
                            font,
                            textRect,
                            this.container.MarcEditor.defaultNameTextColor,
                            MarcEditor.editflags); // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
                    }
                    else if (nCol == 2)            // 指示符
                    {
                        TextRenderer.DrawText(
                            g,
                            strText,
                            font,
                            textRect,
                            this.container.MarcEditor.defaultIndicatorTextColor,
                            MarcEditor.editflags);  // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
                    }
                    else
                    {   // 内容
#if BIDI_SUPPORT
                        strText = strText.Replace(new string(Record.KERNEL_SUBFLD, 1), "\x200e" + new string(Record.KERNEL_SUBFLD, 1));
#endif
                        TextRenderer.DrawText(
                            g,
                            strText,
                            font,
                            textRect,
                            this.container.MarcEditor.m_contentTextColor,
                            MarcEditor.editflags);  // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding);
                    }
                }
            }
            finally
            {
                if (brush != null)
                {
                    brush.Dispose();
                }
            }

#if NO
            // 2015/10/19
            if (linGrBrush != null)
            {
                linGrBrush.Dispose();
            }
#endif
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 设置本字段的 MARC 字符串 (机内格式)
        /// </summary>
        /// <param name="strFieldMarc">本字段的 MARC 字符串</param>
        /// <param name="bFlushEdit">是否自动刷新小 Edit</param>
        internal void SetFieldMarc(string strFieldMarc, bool bFlushEdit)
        {
            if (this.container == null)
            {
                return;
            }

            int index = this.container.IndexOf(this);

            if (index == 0)
            {
                this.m_strValue = strFieldMarc;
                // 2011/4/21
                this.CalculateHeight(null,
                                     true);
                return;
            }

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

            string strName      = "";
            string strIndicator = "";
            string strValue     = "";

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

                strIndicator = strFieldMarc.Substring(3, 2);

                strValue = strFieldMarc.Substring(5);
            }

            string strCaption = this.container.MarcEditor.GetLabel(strName);

            strValue = strValue.Replace(Record.SUBFLD, Record.KERNEL_SUBFLD);
            this.m_strNameCaption = strCaption;
            this.m_strName        = strName;
            this.m_strIndicator   = strIndicator;
            this.m_strValue       = strValue;
            if (this.container.MarcEditor.FocusedField == this)
            {
                /*
                 * if (this.container.MarcEditor.m_nFocusCol == 2)
                 *              this.container.MarcEditor.curEdit.Text = this.m_strValue;
                 * */
                if (bFlushEdit == true)                                // 2014/7/10
                {
                    this.container.MarcEditor.ItemTextToEditControl(); // 2009/3/6 changed
                }
            }
            this.CalculateHeight(null,
                                 true);

            this.container.MarcEditor.FireTextChanged();
        }