예제 #1
0
 public EspackPageCounter(EspackFont pFont, bool pActive = true, string pFormat = "Page {0} of {1}", HorizontalAlignment pAlignment = HorizontalAlignment.Right)
 {
     Font      = pFont;
     Active    = pActive;
     Format    = pFormat;
     Alignment = pAlignment;
 }
예제 #2
0
 // Constructor.
 public EspackPrintingText(string pText, EspackFont pFont = null, float pX = -1, float pY = -1, bool pEOL = false, bool pTitle = false)
 {
     Text       = pText;
     Font       = pFont != null ? pFont.Font : null;
     Brush      = pFont != null ? pFont.Brush : null;
     X          = pX;
     Y          = pY;
     EOL        = pEOL;
     Title      = pTitle;
     Persistent = pTitle;
 }
예제 #3
0
 public void AddText(bool pTitle, string pText, EspackFont pFont = null, float pX = -1, float pY = -1, bool pEOL = false)
 {
     if (CurrentArea != null)
     {
         CurrentArea.AddText(pText, pFont, pX, pY, pEOL, pTitle);
     }
     else
     {
         MessageBox.Show("There is not current Area defined.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #4
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);
        }
예제 #5
0
        // Constructor
        public EspackPrintingArea(EnumDocumentZones pZone, RectangleF pArea, float pMaxHeight, EspackFont pFont = null, EnumZoneDocking pDocking = EnumZoneDocking.ALLOWED)
        {
            Zone    = pZone;
            Docking = pDocking;

            // Set dimensions
            X          = pArea.X;
            Y          = pArea.Y;
            Width      = pArea.Width;
            Height     = pArea.Height;
            RectangleF = pArea;
            MaxHeight  = pMaxHeight;

            // Set the font/brush.
            Font = pFont;
        }
예제 #6
0
 // Add a text object to the list
 public void AddText(string pText, EspackFont pFont = null, float pX = -1, float pY = -1, bool pEOL = false, bool pTitle = false)
 {
     // Create and add the object to the list
     Items.Add(new EspackPrintingText(pText, pFont, pX, pY, pEOL, pTitle));
 }
예제 #7
0
 public EspackPrintingArea(EnumDocumentZones pZone, EspackFont pFont = null, EnumZoneDocking pDocking = EnumZoneDocking.ALLOWED)
     : this(pZone, new RectangleF(-1, -1, -1, -1), -1, pFont, pDocking)
 {
 }
예제 #8
0
 public EspackPrintingArea(EnumDocumentZones pZone, float pX, float pY, float pWidth, float pHeight, float pMaxHeight = -1, EspackFont pFont = null, EnumZoneDocking pDocking = EnumZoneDocking.ALLOWED)
     : this(pZone, new RectangleF(pX, pY, pWidth, pHeight), pMaxHeight, pFont, pDocking)
 {
 }
예제 #9
0
 public void AddText(string pText, EspackFont pFont = null, float pX = -1, float pY = -1, bool pEOL = false)
 {
     AddText(false, pText, pFont, pX, pY, pEOL);
 }
예제 #10
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);
 }
예제 #11
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;
            }
        }