/// <summary>
        /// build a byte stream containing the WTD workstation command orders from all
        /// of the visual items on the canvas. The visual item list is the equivalent of
        /// the 5250 format table.
        /// </summary>
        /// <param name="VisualItems"></param>
        /// <returns></returns>
        public byte[] BuildOrderStream(CanvasPositionCursor Caret)
        {
            ByteArrayBuilder ba = new ByteArrayBuilder();

            // start header order.
            {
                byte[] cmdKeySwitches = new byte[] { 0x00, 0x00, 0x00 };
                var    buf            = StartHeaderOrder.Build(0x00, 0x00, 24, cmdKeySwitches);
                ba.Append(buf);
            }

            // insert cursor order.
            {
                var zeroRowCol = Caret.RowCol as ZeroRowCol;
                var rowCol     = zeroRowCol.ToOneRowCol() as OneRowCol;
                var buf        = InsertCursorOrder.Build(rowCol);
                ba.Append(buf);
            }

            // build sets of SBA, StartField and TextData orders for each visual item. The
            // visual item represents something on the screen. Whether output literal or
            // and input field.
            // VisualItem visualItem = null;
            IVisualItem iVisual = null;
            var         cursor  = this.FirstVisualItem();

            while (cursor != null)
            {
                var pvVisualItem = iVisual;
                iVisual = cursor.GetVisualItem();

                if (iVisual is VisualSpanner)
                {
                }
                else
                {
                    {
                        var buf = SetBufferAddressOrder.Build(
                            iVisual.ItemRowCol.ToOneRowCol() as OneRowCol);
                        ba.Append(buf);
                    }

                    var visualItem = iVisual as VisualItem;
                    if (iVisual.IsField == true)
                    {
                        var vtb = iVisual as VisualTextBlock;
                        var ffw = vtb.FFW_Bytes;

                        byte attrByte = iVisual.AttrByte.Value;
                        int  lgth     = iVisual.ShowText.Length;
                        var  buf      = StartFieldOrder.Build(ffw[0], ffw[1], attrByte, lgth);
                        ba.Append(buf);
                    }

                    // create a text data order from either the text of the literal item. Or the
                    // text value of the entry field.
                    {
                        byte[] buf = null;
                        var    s1  = iVisual.ShowText;
                        if (iVisual.IsField == true)
                        {
                            buf = TextDataOrder.Build(s1, null, iVisual.TailAttrByte);
                        }
                        else if (visualItem.CreateFromItem != null)
                        {
                            var litItem = visualItem.CreateFromItem as ShowLiteralItem;

                            if (litItem.rao_RepeatTextByte != null)
                            {
                                var toRowCol = (iVisual.ItemEndRowCol() as ZeroRowCol).ToOneRowCol();
                                buf = RepeatToAddressOrder.Build(
                                    litItem.rao_RepeatTextByte.Value, toRowCol as OneRowCol);
                            }

                            else
                            {
                                var attrByte = litItem.AttrByte;
                                if (s1.Length < litItem.tdo_Length)
                                {
                                    s1 = s1.PadRight(litItem.tdo_Length);
                                }
                                buf = TextDataOrder.Build(s1, attrByte, iVisual.TailAttrByte);
                            }
                        }
                        else
                        {
                            buf = TextDataOrder.Build(s1, iVisual.AttrByte, iVisual.TailAttrByte);
                        }
                        ba.Append(buf);
                    }
                }
                cursor = cursor.NextItem(true);
            }

            return(ba.ToByteArray());;
        }
Exemplo n.º 2
0
        /// <summary>
        /// build a byte stream containing the WTD workstation command orders from all
        /// of the visual items on the canvas. The visual item list is the equivalent of
        /// the 5250 format table.
        /// </summary>
        /// <returns></returns>
        public byte[] BuildOrderStream()
        {
            var ba = new ByteArrayBuilder();

            // start header order.
            {
                byte[] cmdKeySwitches = new byte[] { 0x00, 0x00, 0x00 };
                var    buf            = StartHeaderOrder.Build(0x00, 0x00, 24, cmdKeySwitches);
                ba.Append(buf);
            }

            // insert cursor order.
            {
                var rowCol = this.CaretRowCol;
                if (rowCol == null)
                {
                    rowCol = new OneRowCol(1, 1, this);
                }
                var buf = InsertCursorOrder.Build(rowCol);
                ba.Append(buf);
            }

            // build sets of SBA, StartField and TextData orders for each visual item. The
            // visual item represents something on the screen. Whether output literal or
            // and input field.
            // VisualItem visualItem = null;
            foreach (var dictItem in this.FieldDict)
            {
                var contentItem = dictItem.Value;
                {
                    var buf = SetBufferAddressOrder.Build(
                        contentItem.RowCol.ToOneRowCol() as OneRowCol);
                    ba.Append(buf);
                }

                if (contentItem is ContentField)
                {
                    var contentField = contentItem as ContentField;
                    var ffw          = contentField.FFW_Bytes;

                    byte attrByte = contentField.GetAttrByte(this).Value;
                    int  lgth     = contentField.LL_Length;
                    var  buf      = StartFieldOrder.Build(ffw[0], ffw[1], attrByte, lgth);
                    ba.Append(buf);
                }

                // create a text data order from either the text of the literal item. Or the
                // text value of the entry field.
                {
                    byte[] buf = null;
                    var    s1  = contentItem.GetShowText(this);
                    if (contentItem is ContentField)
                    {
                        buf = TextDataOrder.Build(s1, null, null);
                    }
                    else
                    {
                        buf = TextDataOrder.Build(s1, contentItem.GetAttrByte(this), null);
                    }
                    ba.Append(buf);
                }
            }

            return(ba.ToByteArray());;
        }