using HotelPms.Share.Util; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Windows.Forms; namespace HotelPms.Share.Windows.Report { public class FormReport : PrintGdiPlus, IDisposable, IReport { #region ★★★★★ Declartions ★★★★★ private bool m_Disposed = false; private float m_CurrentY = 0F; private List> m_ObjList = null; private List m_CurrentPageData = null; private Rectangle m_OwnerArea; private string m_Title = string.Empty; #endregion #region ★★★★★ Property ★★★★★ #endregion #region ★★★★★ Class Event ★★★★★ public FormReport(List> objList, Rectangle ownerArea, PaperKind paper, string title) { m_ObjList = objList; m_OwnerArea = ownerArea; m_Title = title; foreach (PaperSize ps in m_PrintDoc.PrinterSettings.PaperSizes) { if (ps.Kind == paper) { m_PrintDoc.DefaultPageSettings.PaperSize = ps; break; } } if (m_OwnerArea.Width > m_OwnerArea.Height) { m_PrintDoc.DefaultPageSettings.Landscape = true; } this.PrintDoc.PrintPage += PrintDoc_PrintPage; m_PageIndex = 0; } ~FormReport() { Dispose(false); } protected override void Dispose(bool disposing) { if (!m_Disposed) //一回だけ { if (disposing) { //Managed Resources } //Unmanaged resources m_Disposed = true; } base.Dispose(disposing); } public override void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion #region ★★★★★ Control Event ★★★★★ private void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { m_CurrentPageData = m_ObjList[m_PageIndex]; e.Graphics.PageUnit = GraphicsUnit.Pixel; //画面と同じ単位 //e.Graphics.PageUnit = GraphicsUnit.Display; //印字範囲 98% float width = (e.PageBounds.Width - (int)e.PageSettings.HardMarginX * 2) * e.Graphics.DpiX / 100; float height = (e.PageBounds.Height - (int)e.PageSettings.HardMarginY * 2) * e.Graphics.DpiY / 100; m_PrintWidth = width * 0.98F; m_PrintHeight = height * 0.98F; m_LeftMargins = (width * 1.0F - m_PrintWidth) / 2; m_TopMargins = (height * 1.0F - m_PrintHeight) / 2; Font titleFont = new Font("MS UI Gothic", 18F); Font detailFont = new Font("MS UI Gothic", 9F); m_TitleHeight = GetTextHeight(e.Graphics, titleFont) + 6F; //ヘッダーの高さ m_DetailRowHeight = GetTextHeight(e.Graphics, detailFont) + 6F; //ヘッダーの高さ float detailHeight = m_PrintHeight - m_TitleHeight; //タイトルの印刷 Cell title = new Cell(); title.Text = m_Title; title.Style.RectangleF = new RectangleF(new PointF(m_LeftMargins, m_TopMargins), new SizeF(m_PrintWidth, m_TitleHeight)); title.Style.Font = titleFont; DrawCell(e.Graphics, title); //印字時間+ページ m_CurrentY = m_TopMargins + m_TitleHeight - m_DetailRowHeight; Cell page_printDate = new Cell(); page_printDate.Text = string.Format("{0} 頁:{1}/{2}", DateTime.Now.ToString("yyyy年MM月dd日(ddd) HH:mm:ss"), m_PageIndex + 1, m_ObjList.Count); page_printDate.Style.RectangleF = new RectangleF(new PointF(m_LeftMargins, m_CurrentY), new SizeF(m_PrintWidth, m_DetailRowHeight)); page_printDate.Style.Alignment = StringAlignment.Far; DrawCell(e.Graphics, page_printDate); //画面の描く float rateX = (e.Graphics.DpiX / 96.0F); float rateY = (e.Graphics.DpiY / 96.0F); float zoomRate = (m_PrintWidth / (m_OwnerArea.Width * rateX)) < (detailHeight / (m_OwnerArea.Height * rateY)) ? (m_PrintWidth / (m_OwnerArea.Width * rateX)) : (detailHeight / (m_OwnerArea.Height * rateY)); foreach (Cell item in m_CurrentPageData) { item.Style.RectangleF = new RectangleF(m_LeftMargins + item.Style.RectangleF.Left * rateX * zoomRate, m_TopMargins + item.Style.RectangleF.Top * rateX * zoomRate + m_TitleHeight, item.Style.RectangleF.Width * rateX * zoomRate, item.Style.RectangleF.Height * rateX * zoomRate); DrawCell(e.Graphics, item); } //e.Graphics.DrawRectangle(Pens.Blue, m_LeftMargins, m_TopMargins + m_TitleHeight, (m_OwnerArea.Width * rateX * zoomRate), (m_OwnerArea.Height * rateY * zoomRate)); //次のページ if (m_PageIndex == m_ObjList.Count - 1) { e.HasMorePages = false; } else { m_PageIndex++; e.HasMorePages = true; } } #endregion #region ★★★★★ Private Function ★★★★★ #endregion #region ★★★★★ Public Function ★★★★★ #endregion } }