Exemplo n.º 1
0
        void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            // Zuerst die Gesamtbreite aller Spalten ermitteln
            int totalWidth = 0;

            foreach (XPTable.Models.Column column in personGroupTable.ColumnModel.Columns)
            {
                if (column.Visible)
                {
                    totalWidth += column.Width;
                }
            }

            // Jetzt den Prozentanteil jeder einzelnen Spalte errechnen und auf die Seite hochrechnen
            int[] columnWidth = new int[personGroupTable.ColumnModel.Columns.Count];
            int   nr          = 0;

            foreach (XPTable.Models.Column column in personGroupTable.ColumnModel.Columns)
            {
                if (column.Visible)
                {
                    columnWidth[nr] = (int)((double)e.MarginBounds.Width / (double)totalWidth * (double)column.Width);
                    nr++;
                }
            }

            bool printThisPage = (e.PageSettings.PrinterSettings.PrintRange == PrintRange.AllPages ||
                                  currentPage >= e.PageSettings.PrinterSettings.FromPage &&
                                  currentPage <= e.PageSettings.PrinterSettings.ToPage);

            int yPosition = e.MarginBounds.Top;

            // Spaltenüberschrift drucken
            if (printThisPage)
            {
                PrintHeader(e.Graphics, e.MarginBounds, columnWidth, personGroupTable, ref yPosition);
            }

            int startYPosition = yPosition;

            if (personGroupTable.Visible)
            {
                for (int i = currentPrintRecord; i < personGroupTable.TableModel.Rows.Count; i++)
                {
                    if (yPosition + printFont.Height > e.MarginBounds.Bottom)
                    {
                        currentPrintRecord = i;
                        yPosition          = e.MarginBounds.Top;

                        if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages &&
                            currentPage >= e.PageSettings.PrinterSettings.ToPage)
                        {
                            e.HasMorePages = false;
                            break;
                        }

                        if (printThisPage)
                        {
                            currentPage++;
                            e.HasMorePages = true;
                            break;
                        }

                        currentPage++;

                        printThisPage = (e.PageSettings.PrinterSettings.PrintRange == PrintRange.AllPages ||
                                         currentPage >= e.PageSettings.PrinterSettings.FromPage &&
                                         currentPage <= e.PageSettings.PrinterSettings.ToPage);

                        if (printThisPage)
                        {
                            PrintHeader(e.Graphics, e.MarginBounds, columnWidth, personGroupTable, ref yPosition);
                        }
                    }

                    if (printThisPage)
                    {
                        int colNr     = 0;
                        int xPosition = e.MarginBounds.Left;
                        foreach (XPTable.Models.Cell cell in personGroupTable.TableModel.Rows[i].Cells)
                        {
                            if (personGroupTable.ColumnModel.Columns[cell.Index].Visible)
                            {
                                //e.Graphics.DrawString(cell.Text, printFont, Brushes.Black, new PointF(xPosition, yPosition));
                                StringFormat sf = new StringFormat();
                                sf.Trimming = StringTrimming.EllipsisCharacter;

                                e.Graphics.DrawString(cell.Text, printFont, Brushes.Black, new RectangleF(xPosition, yPosition, columnWidth[colNr], printFont.Height), sf);
                                xPosition += columnWidth[colNr];
                                colNr++;
                            }
                        }
                    }

                    yPosition += printFont.Height;
                }
            }
            else
            {
                int column = 0;

                for (int i = currentPrintRecord; i < personGroup.PersonGroup.Count; i++)
                {
                    int xPosition;

                    PersonGroupDataSet.PersonGroupRow personGroupRow = personGroup.PersonGroup[i];

                    if (yPosition + printFont.Height * 7 > e.MarginBounds.Bottom)
                    {
                        if (column < 1)
                        {
                            column++;
                            yPosition = startYPosition;
                        }
                        else
                        {
                            currentPrintRecord = i;
                            yPosition          = e.MarginBounds.Top;

                            if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages &&
                                currentPage >= e.PageSettings.PrinterSettings.ToPage)
                            {
                                e.HasMorePages = false;
                                break;
                            }

                            if (printThisPage)
                            {
                                currentPage++;
                                e.HasMorePages = true;
                                break;
                            }

                            currentPage++;

                            printThisPage = (e.PageSettings.PrinterSettings.PrintRange == PrintRange.AllPages ||
                                             currentPage >= e.PageSettings.PrinterSettings.FromPage &&
                                             currentPage <= e.PageSettings.PrinterSettings.ToPage);

                            if (printThisPage)
                            {
                                PrintHeader(e.Graphics, e.MarginBounds, columnWidth, personGroupTable, ref yPosition);
                            }
                            column = 0;
                        }
                    }

                    if (column == 0)
                    {
                        xPosition = e.MarginBounds.Left;
                    }
                    else
                    {
                        xPosition = e.MarginBounds.Left + e.MarginBounds.Width / 2;
                    }

                    int imageWidth = printFont.Height * 7;

                    if (printThisPage)
                    {
                        if (!personGroupRow.IsImageFilenameNull() && personGroupRow.ImageFilename.Length > 0)
                        {
                            try
                            {
                                Image img = Image.FromFile(Misc.FindCover(personGroupRow.ImageFilename));

                                SizeF      imageBoundingBox = new SizeF(imageWidth, imageWidth);
                                SizeF      bestSize         = GetBestFitSize(img, imageBoundingBox);
                                RectangleF imageRect        = new RectangleF(
                                    new PointF(
                                        xPosition + (imageBoundingBox.Width - bestSize.Width) / 2,
                                        yPosition + (imageBoundingBox.Height - bestSize.Height) / 2),
                                    bestSize);
                                e.Graphics.DrawImage(img, imageRect);
                            }
                            catch       // Fehler ignorieren
                            {
                            }
                        }
                    }

                    xPosition += imageWidth + 20;

                    StringFormat sf = new StringFormat();
                    sf.Trimming = StringTrimming.EllipsisCharacter;
                    int       artistWidth = e.MarginBounds.Width / 2 - imageWidth - 30;
                    Rectangle artistRect  = new Rectangle(xPosition, yPosition, artistWidth, printFont.Height);
                    if (printThisPage)
                    {
                        e.Graphics.DrawString(personGroupRow.Name, printFontBold, Brushes.Black, artistRect, sf);
                    }

                    string artistType = DataBase.GetNameOfPersonGroupType((PersonGroupType)(personGroupRow.IsTypeNull() ? 0 : personGroupRow.Type));
                    string artistSex  = DataBase.GetNameOfPersonGroupSex((SexType)(personGroupRow.IsSexNull() ? 0 : personGroupRow.Sex));

                    int yOffset = (int)((double)printFontBold.Height * 1.5);

                    if (printThisPage)
                    {
                        e.Graphics.DrawString(artistType + ", " + artistSex, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                    }

                    yOffset += printFont.Height;

                    if (!personGroupRow.IsCountryNull() && personGroupRow.Country.Length > 0)
                    {
                        if (printThisPage)
                        {
                            e.Graphics.DrawString(StringTable.Country + ": " + personGroupRow.Country, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                        }
                        yOffset += printFont.Height;
                    }

                    if (!personGroupRow.IsBirthDayNull())
                    {
                        if (printThisPage)
                        {
                            if ((PersonGroupType)personGroupRow.Type == PersonGroupType.Single)
                            {
                                e.Graphics.DrawString(StringTable.Born + ": " + personGroupRow.BirthDay, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                            }
                            else
                            {
                                e.Graphics.DrawString(StringTable.Founded + ": " + personGroupRow.BirthDay, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                            }
                        }
                        yOffset += printFont.Height;
                    }

                    if (!personGroupRow.IsDayOfDeathNull())
                    {
                        if (printThisPage)
                        {
                            if ((PersonGroupType)personGroupRow.Type == PersonGroupType.Single)
                            {
                                e.Graphics.DrawString(StringTable.Died + ": " + personGroupRow.DayOfDeath, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                            }
                            else
                            {
                                e.Graphics.DrawString(StringTable.BreakAway + ": " + personGroupRow.DayOfDeath, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                            }
                        }
                        yOffset += printFont.Height;
                    }

                    if (!personGroupRow.IsURLNull())
                    {
                        if (printThisPage)
                        {
                            e.Graphics.DrawString(personGroupRow.URL, printFont, Brushes.Black, new PointF(xPosition, yPosition + yOffset));
                        }
                        yOffset += printFont.Height;
                    }

                    yPosition += printFont.Height * 8;
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            //base.OnDrawItem(e);
            if (e.Index >= Items.Count || e.Index < 0)
            {
                return;
            }

            Graphics g = e.Graphics;

            if ((e.State & DrawItemState.Selected) != 0)
            {
                g.FillRectangle(new SolidBrush(ColorTable.MenuItemSelected), e.Bounds);
                Rectangle rect = Rectangle.FromLTRB(e.Bounds.Left, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom - 1);
                g.DrawRectangle(new Pen(ColorTable.MenuItemBorder), rect);
            }
            else
            {
                LinearGradientBrush b = new LinearGradientBrush(e.Bounds, ProfessionalColors.ToolStripGradientBegin, ProfessionalColors.ToolStripGradientEnd, LinearGradientMode.Vertical);
                g.FillRectangle(b, e.Bounds);
            }

            int xpos = e.Bounds.Left + ItemHeight + Border * 2;

            PersonGroupDataSet.PersonGroupRow item = (PersonGroupDataSet.PersonGroupRow)Items[e.Index];

            g.DrawString(item.Name, fontBold, Brushes.Black, new PointF(xpos, e.Bounds.Top + Border));

            string artistType = DataBase.GetNameOfPersonGroupType((PersonGroupType)(item.IsTypeNull() ? 0 : item.Type));
            string artistSex  = DataBase.GetNameOfPersonGroupSex((SexType)(item.IsSexNull() ? 0 : item.Sex));

            g.DrawString(artistType + ", " + artistSex, fontNormal, Brushes.Black, new PointF(xpos, e.Bounds.Top + 18));

            int yOffset = 36;

            if (!item.IsCountryNull() && item.Country.Length > 0)
            {
                g.DrawString(StringTable.Country + ": " + item.Country, fontNormal, Brushes.Black, new PointF(xpos, e.Bounds.Top + yOffset));
                yOffset = 54;
            }

            if (!item.IsBirthDayNull())
            {
                if ((PersonGroupType)item.Type == PersonGroupType.Single)
                {
                    g.DrawString(StringTable.Born + ": " + Misc.FormatDate(item.BirthDay), fontNormal, Brushes.Black, new PointF(xpos, e.Bounds.Top + yOffset));
                }
                else
                {
                    g.DrawString(StringTable.Founded + ": " + Misc.FormatDate(item.BirthDay), fontNormal, Brushes.Black, new PointF(xpos, e.Bounds.Top + yOffset));
                }
                //                yOffset += 16;
            }

            if (!item.IsDayOfDeathNull())
            {
                if ((PersonGroupType)item.Type == PersonGroupType.Single)
                {
                    g.DrawString(StringTable.Died + ": " + Misc.FormatDate(item.DayOfDeath), fontNormal, Brushes.Black, new PointF(xpos + (Width - xpos) / 2, e.Bounds.Top + yOffset));
                }
                else
                {
                    g.DrawString(StringTable.BreakAway + ": " + Misc.FormatDate(item.DayOfDeath), fontNormal, Brushes.Black, new PointF(xpos + (Width - xpos) / 2, e.Bounds.Top + yOffset));
                }
                yOffset += 16;
            }

            if (!item.IsImageFilenameNull() && item.ImageFilename.Length > 0)
            {
                if (!imageCache.ContainsKey(item.ImageFilename))
                {
                    try
                    {
                        byte[] imageBytes = File.ReadAllBytes(Misc.FindCover(item.ImageFilename));

                        MemoryStream m = new MemoryStream(imageBytes);

                        Image img = Image.FromStream(m);
                        m.Close();

                        imageCache.Add(item.ImageFilename, img);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (imageCache.ContainsKey(item.ImageFilename))
                {
                    Size origSize         = new Size(ItemHeight - Border * 2, ItemHeight - Border * 2);
                    Size imageBestFitSize = GetBestFitSize(imageCache[item.ImageFilename], origSize);

                    Rectangle imageRect = new Rectangle(
                        new Point(e.Bounds.Left + Border + (origSize.Width - imageBestFitSize.Width) / 2,
                                  e.Bounds.Top + Border + (origSize.Height - imageBestFitSize.Height) / 2),
                        imageBestFitSize);

                    g.DrawImage(imageCache[item.ImageFilename], imageRect);
                }
            }
            else
            {
                Size origSize         = new Size(ItemHeight - Border * 2, ItemHeight - Border * 2);
                Size imageBestFitSize = GetBestFitSize(Images.MissingPersonImage, origSize);

                Rectangle imageRect = new Rectangle(
                    new Point(e.Bounds.Left + Border + (origSize.Width - imageBestFitSize.Width) / 2,
                              e.Bounds.Top + Border + (origSize.Height - imageBestFitSize.Height) / 2),
                    imageBestFitSize);

                g.DrawImage(Images.MissingPersonImage, imageRect);
            }

            if (!item.IsURLNull())
            {
                g.DrawString(item.URL, fontSmall, Brushes.Blue, new PointF(xpos + (Width - xpos) / 2, e.Bounds.Top + 10));
            }
        }