ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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<List<Cell>> m_ObjList = null;
        private List<Cell> m_CurrentPageData = null;
        private Rectangle m_OwnerArea;
        private string m_Title = string.Empty;
 
        #endregion
 
        #region  ★★★★★ Property ★★★★★
 
 
 
 
        #endregion
 
        #region  ★★★★★ Class Event ★★★★★
 
        public FormReport(List<List<Cell>> 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
    }
}