예제 #1
0
        // Add the results of a query to the current area
        public bool AddQuery(string pSQL, cAccesoDatosNet pConn, EspackFont pFont = null, bool pHideTitles = false)
        {
            using (var _rs = new DynamicRS(pSQL, pConn))
            {
                _rs.Open();
                if (_rs.RecordCount == 0)
                {
                    MessageBox.Show("The query returned no data.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                else
                {
                    Dictionary <string, List <string> > _matrix = new Dictionary <string, List <string> >();

                    foreach (var _item in _rs.Fields)
                    {
                        _matrix[_item.ToString()] = new List <string>();
                    }

                    int _col;

                    _rs.ToList().ForEach(_row =>
                    {
                        _col = 0;
                        _row.ItemArray.ToList().ForEach(_column =>
                        {
                            _matrix[_matrix.Keys.ToList()[_col]].Add(_column.ToString());
                            _col++;
                        });
                    });

                    foreach (var _key in _matrix.Keys)
                    {
                        Areas.Add(CurrentArea = new EspackPrintingArea(EnumDocumentZones.BODY, pFont, pDocking: EnumZoneDocking.RIGHTWARDS));

                        // Add current column title
                        if (!pHideTitles)
                        {
                            AddText(true, _key.ToString(), true);
                            CurrentArea.PermanentRows++;
                        }
                        // Add data for current column
                        foreach (var _item in _matrix[_key])
                        {
                            AddText(_item.ToString(), true);
                            CurrentArea.DataRows++;
                        }
                    }
                }
            }
            return(true);
        }
예제 #2
0
        // OnPrintPage event, triggered on each new page
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            EspackPrintingArea _previousArea = null;

            var _g = e.Graphics;

            _g.PageUnit = GraphicsUnit.Millimeter;


            if (Pager.Counter == 0)
            {
                float _minBodyY = 0;
                float _maxBodyY = 0;

                //VisibleArea=new RectangleF(HardMargins.X,HardMargins.Y,_g.VisibleClipBounds.)
                VisibleArea = new RectangleF(_g.VisibleClipBounds.X, _g.VisibleClipBounds.Y, _g.VisibleClipBounds.Width, _g.VisibleClipBounds.Height);

                PointF _pagerSize;

                // Header areas
                Areas.Where(_item => (_item.Zone == EnumDocumentZones.HEADER)).ToList().ForEach(_item =>
                {
                    _item.ArrangeItems(_g, HardMargins, _previousArea);
                    _minBodyY     = (_minBodyY < _item.Y + _item.Height) ? _item.Y + _item.Height : _minBodyY;
                    _previousArea = _item;
                });

                // Footer areas
                _previousArea = null;
                Areas.Where(_item => (_item.Zone == EnumDocumentZones.FOOTER)).ToList().ForEach(_item =>
                {
                    _item.ArrangeItems(_g, HardMargins, _previousArea);
                    _maxBodyY     = (_maxBodyY < _item.Y + _item.Height) ? _item.Y + _item.Height : _maxBodyY;
                    _previousArea = _item;
                });

                _maxBodyY = _g.VisibleClipBounds.Bottom - HardMargins.Y - _maxBodyY;

                // If pager is active, we must take it into account
                if (Pager.Active)
                {
                    _pagerSize = Pager.Size(_g);
                    _maxBodyY -= _pagerSize.Y;
                    Pager.Y    = _g.VisibleClipBounds.Bottom - HardMargins.Y - _pagerSize.Y;
                    Pager.X    = _g.VisibleClipBounds.Right - HardMargins.X - _pagerSize.X;
                }

                // Move the footer relative positions to its absolute place
                Areas.Where(_item => (_item.Zone == EnumDocumentZones.FOOTER)).ToList().ForEach(_item =>
                {
                    _item.Move(0, _maxBodyY);
                });

                // Set the Y limits for body areas
                Areas.Where(_item => (_item.Zone == EnumDocumentZones.BODY)).ToList().ForEach(_item =>
                {
                    _item.Y         = _minBodyY;
                    _item.MaxHeight = _maxBodyY;
                    Pager.Rows      = Pager.Rows < _item.Items.Count ? _item.Items.Count : Pager.Rows;
                });
                Pager.Counter = 1;
                Pager.Total   = 1;
            }

            _previousArea = null;

            // body areas stuff
            Areas.Where(_item => (_item.Zone == EnumDocumentZones.BODY)).ToList().ForEach(_item =>
            {
                _item.ArrangeItems(_g, HardMargins, _previousArea);
                _previousArea = _item;
            });


            // printing
            Areas.ForEach(_item =>
            {
                _item.Draw(_g);
                if (_item.Zone == EnumDocumentZones.BODY && Pager.Counter == 1 && Pager.Total == 1)
                {
                    Pager.Total = (int)Math.Ceiling((_item.DataRows + 0.0) / (_item.DataRows - (_item.Items.Count - _item.PermanentRows)));
                }
            });

            // paging
            if (Pager.Active)
            {
                _g.DrawString(Pager.Text, Pager.Font.Font, Pager.Font.Brush, Pager.X, Pager.Y);
            }
            e.HasMorePages = Pager.Counter < Pager.Total;
            Pager.Counter++;

            base.OnPrintPage(e);
        }
예제 #3
0
 // Add a new area and set it as current
 public void AddArea(EnumDocumentZones pZone, EspackFont pFont = null, EnumZoneDocking pDocking = EnumZoneDocking.NONE)
 {
     CurrentArea = new EspackPrintingArea(pZone, pFont, pDocking);
     Areas.Add(CurrentArea);
 }
예제 #4
0
        // Convert all relative positions to absolute
        public void ArrangeItems(Graphics pGraphics, PointF HardMargins, EspackPrintingArea pPreviousArea)
        {
            if (pPreviousArea != null)
            {
                bool _setCoords = true;

                if (Docking != EnumZoneDocking.NONE)
                {
                    switch (pPreviousArea.Docking)
                    {
                    case EnumZoneDocking.RIGHTWARDS:
                        if (X == -1)
                        {
                            X = pPreviousArea.X + pPreviousArea.Width + 2;
                        }
                        if (Y == -1)
                        {
                            Y = pPreviousArea.Y;
                        }
                        _setCoords = false;
                        break;

                    case EnumZoneDocking.DOWNWARDS:
                        if (X == -1)
                        {
                            X = pPreviousArea.X;
                        }
                        if (Y == -1)
                        {
                            Y = pPreviousArea.Y + pPreviousArea.Height;
                        }
                        _setCoords = false;
                        break;
                    }
                }

                if (_setCoords)
                {
                    if (X == -1)
                    {
                        X = HardMargins.X;
                    }
                    if (Y == -1)
                    {
                        Y = pPreviousArea.Y + pPreviousArea.Height;
                    }
                }

                if (Font == null)
                {
                    Font = pPreviousArea.Font;
                }
            }
            else
            {
                // Set the min visible coordinates as default
                if (X == -1)
                {
                    X = HardMargins.X;
                }
                if (Y == -1)
                {
                    Y = HardMargins.Y;
                }
                Font = Font ?? new EspackFont();
            }

            // Calculate the X and Y for each item when they are not defined
            IEspackPrintingItem _previousItem = null;
            EspackPrintingText  _previousText = null;
            Brush _previousBrush = null;
            Pen   _previousPen   = null;

            foreach (var _item in Items)
            {
                // Cast _item as IEspackPrintingItem
                var _currentItem = (IEspackPrintingItem)_item;
                _currentItem.Graphics = pGraphics;

                // If not ready to be printed, it needs to be arranged
                if (!_currentItem.PrintMe)
                {
                    if (_currentItem.GetType().Name != "EspackPrintingDrawing")
                    {
                        if (_previousItem != null)
                        {
                            // Previous item exists
                            if (_currentItem.X == -1 && _currentItem.Y == -1)
                            {
                                // X and Y not set. Set them depending of EOL value
                                if (!_previousItem.EOL)
                                {
                                    _currentItem.X = _previousItem.X + _previousItem.Width;
                                    _currentItem.Y = _previousItem.Y;
                                }
                                else
                                {
                                    if (Zone == EnumDocumentZones.BODY && _previousItem.Y + _previousItem.Height > MaxHeight)
                                    {
                                        break;
                                    }
                                    _currentItem.X = X; // LEFT MARGIN
                                    _currentItem.Y = _previousItem.Y + _previousItem.Height;
                                }
                            }
                        }
                        else
                        {
                            // First element: set defaults if not passed
                            _currentItem.X = _currentItem.X == -1 ? X : X + _currentItem.X; // LEFT MARGIN
                            _currentItem.Y = _currentItem.Y == -1 ? Y : Y + _currentItem.Y; // TOP MARGIN
                        }
                        // Only for text objects

                        if (_currentItem.GetType().Name == "EspackPrintingText")
                        {
                            // Cast it to EspackPrintingText
                            using (var _currentText = (EspackPrintingText)_currentItem)
                            {
                                if (_previousText != null)
                                {
                                    // Not the first text object
                                    if (_currentText.Font == null)
                                    {
                                        // Get the font from the previous object if set
                                        Font _f = _previousText.Font ?? (Font)Font.Font.Clone();

                                        // Disable the auto bold when the previous text was bold-forced and current is not a title
                                        if ((_previousText.ForcedBold || _previousText.ForcedUnderline) && !_currentText.Title)
                                        {
                                            _f = new Font(_f.Name, _f.Size, _f.Style & (_previousText.ForcedBold?~FontStyle.Bold: _f.Style) & (_previousText.ForcedUnderline && Zone == EnumDocumentZones.BODY ? ~FontStyle.Underline : _f.Style));
                                        }

                                        // Set current font
                                        _currentText.Font = _f;
                                    }

                                    // Set current brush
                                    if (_currentText.Brush == null)
                                    {
                                        _currentText.Brush = _previousBrush ?? (Brush)Font.Brush.Clone();
                                    }
                                }
                                else
                                {
                                    // First text object: set font / brush
                                    _currentText.Font  = _currentText.Font ?? (Font)Font.Font.Clone();
                                    _currentText.Brush = _currentText.Brush ?? (Brush)Font.Brush.Clone();
                                }

                                // Force bold if current text is a title (and font was not bold)
                                if (_currentText.Title && !(_currentText.Font.Bold && _currentText.Font.Underline))
                                {
                                    _currentText.ForcedBold = !_currentText.Font.Bold;
                                    if (Zone == EnumDocumentZones.BODY)
                                    {
                                        _currentText.ForcedUnderline = !_currentText.Font.Underline;
                                    }
                                    _currentText.Font = new Font(_currentText.Font.Name, _currentText.Font.SizeInPoints, _currentText.Font.Style | FontStyle.Bold | (Zone == EnumDocumentZones.BODY?FontStyle.Underline:0));
                                }
                                _previousText  = _currentText;
                                _previousBrush = _currentText.Brush;
                            }
                        }

                        // Calculate the Height / Width of current area
                        if (_currentItem.X - X + _currentItem.Width > Width)
                        {
                            Width = _currentItem.X - X + _currentItem.Width;
                        }
                        if (_currentItem.Y - Y + _currentItem.Height > Height)
                        {
                            Height = _currentItem.Y - Y + _currentItem.Height;
                        }
                    }
                    // Only for drawing objects (totally independent to the area)
                    else if (_currentItem.GetType().Name == "EspackPrintingDrawing")
                    {
                        if (((EspackPrintingDrawing)_currentItem).Pen == null)
                        {
                            ((EspackPrintingDrawing)_currentItem).Pen       = _previousPen ?? (Pen)Pen.Clone();
                            ((EspackPrintingDrawing)_currentItem).Pen.Brush = _previousBrush ?? (Brush)Font.Brush.Clone();
                        }
                        _previousBrush = ((EspackPrintingDrawing)_currentItem).Pen.Brush;
                        _previousPen   = ((EspackPrintingDrawing)_currentItem).Pen;
                    }

                    // Set current item as ready to be printed
                    _currentItem.PrintMe = true;
                }
                _previousItem = _currentItem;
            }
        }