ホテル管理システム
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
using Microsoft.Win32;
using HotelPms.Share.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelPms.Share.Windows.Util;
 
namespace HotelPms.Share.Windows.Report
{
    public enum ReportType : int
    {
        Print = 0,
        Pdf,
        Xlsx,
        Csv,
        Html,
        Json,
        Xml,
        Xls,
        Preveiw,
    }
 
#pragma warning disable CA1416
    public abstract class ReportBase
    {
        protected float m_PrintWidth = 700F;   // 印字使用幅(A4)
        protected float m_PrintHeight = 1032F;   // 印字使用高(A4)
 
        protected float m_LeftMargins = 50F;  //左余白
        protected float m_TopMargins = 60F;  //上余白
 
        protected int m_PageCount = 0;
        protected int m_PageIndex = 1;
        protected int m_DataRowIndex = 0;
        protected float m_DetailRowHeight = 0F;
        protected float m_TitleHeight = 0F;
        protected int m_DetailRowCount = 0;
        protected float m_HeaderHeight = 0F;
        protected float m_CaptionHeight = 0F;  //項目名の固定行
        protected float m_FooterHeight = 0F;
 
 
        protected DataTable m_Data = null;
 
        public DataTable Data
        {
            get { return m_Data; }
            set { m_Data = value; }
        }
 
        protected GridStyle m_Style = null;
 
        public GridStyle Style
        {
            get { return m_Style; }
            set { m_Style = value; }
        }
    
        /// <summary>
        /// 1/100 インチ ⇒ Point
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public float GetPointWithDisplay(float value)
        {
            return value * 0.72F;
        }
 
        public float GetTextHeight(Graphics g, Font font)
        {
            return g.MeasureString("A", font).Height;
        }
 
        public float GetTextWidth(Graphics g, Font font, string text)
        {
            return g.MeasureString(text, font).Width;
        }
 
        public static void CreateColumnStyle(DataGridView grid, GridStyle style)
        {
            style.ColumnStyle.Clear();
            int total = 0;
            int lastIdx = 0;
            foreach (DataGridViewColumn col in grid.Columns)
            {
                if (!col.Visible || (col.CellType.Name != "DataGridViewTextBoxCell")) { continue; }
                total += col.Width;
                lastIdx = col.Index;
            }
 
            float rate = 0F;
            foreach (DataGridViewColumn col in grid.Columns)
            {
                if (!col.Visible || (col.CellType.Name != "DataGridViewTextBoxCell")) { continue; }
 
                ColumnStyle colStyle = new ColumnStyle();
                colStyle.DefaultCellStyle = new CellStyle();
                colStyle.WidthRate = lastIdx == col.Index ? (1.0F - rate) : (float)CConvert.Divide(col.Width * 1.0F, total, 2);
                colStyle.Width = col.Width * 1.0F;
                rate += colStyle.WidthRate;
                colStyle.DataField = col.DataPropertyName.Length > 0 ? col.DataPropertyName : col.Name;
                colStyle.Text = col.HeaderText;
                colStyle.Alignment = GeneralSub.ToStringAlignment(grid.ColumnHeadersDefaultCellStyle.Alignment);
                colStyle.LineAlignment = GeneralSub.ToLineStringAlignment(grid.ColumnHeadersDefaultCellStyle.Alignment);
                colStyle.DefaultCellStyle.Alignment = GeneralSub.ToStringAlignment(col.DefaultCellStyle.Alignment);
                colStyle.DefaultCellStyle.LineAlignment = GeneralSub.ToLineStringAlignment(col.DefaultCellStyle.Alignment);
                colStyle.DefaultCellStyle.Font = col.DefaultCellStyle.Font; 
                colStyle.Font = grid.ColumnHeadersDefaultCellStyle.Font;    
                style.ColumnStyle.Add(colStyle);
            }
        }
        
        public static SortedDictionary<string, string> ReadFontInformation()
        {
            var dictionary = new SortedDictionary<string, string>();
 
            RegistryKey mykey = Registry.LocalMachine;
 
            string key = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts";
            using (RegistryKey regkey = mykey.OpenSubKey(key, false))
            {
                if (regkey != null)
                {
                    //获取字体名  
                    string[] mynames = regkey.GetValueNames();
 
                    foreach (string name in mynames)
                    {
                        //获取字体的文件名  
                        string myvalue = regkey.GetValue(name).ToString();
 
                        if (myvalue.Substring(myvalue.Length - 4).ToUpper() == ".TTF" && myvalue.Substring(1, 2).ToUpper() != @":\")
                        {
                            string val = name.Substring(0, name.Length - 11);
                            dictionary[val] = myvalue;
                        }
                    }
                    regkey.Close();
                }
            }
            return dictionary;
        }
    }
}