ホテル管理システム
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
using HotelPms.Share.Windows.Component;
using HotelPms.Share.Windows.Report;
using HotelPms.Share.Windows.Report.Member;
using HotelPms.Share.Windows.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace HotelPms.SourceFactory
{
    public partial class FormReport : Form
    {
        private DataTable listData;
 
        private DataTable data;
 
        public FormReport()
        {
            InitializeComponent();
        }
 
        private void FormReport_Load(object sender, EventArgs e)
        {
            GeneralSub.SetDoubleBuffered(dataGridView1);
            GeneralSub.InitDataGridView(dataGridView1, true);
            InitData();
            InitReport();
 
            CreateTestData();
            dataGridView1.DataSource = listData;
            SetGridStyle();
        }
 
        private void InitData()
        {
            data = new DataTable();
            data.Columns.Add("Field0", typeof(DateTime));
            data.Columns.Add("Field1", typeof(DateTime));
            data.Columns.Add("Field2", typeof(int));
            data.Columns.Add("Field3", typeof(int));
            data.Columns.Add("Field4", typeof(int));
            data.Columns.Add("Field5", typeof(int));
            data.Columns.Add("Field6", typeof(int));
            data.Columns.Add("Field7", typeof(int));
            data.Columns.Add("Field8", typeof(int));
            data.Columns.Add("Field9", typeof(string));
 
            for (int i = 0; i < 100; i++)
            {
                DataRow row = data.NewRow();
                row["Field0"] = DateTime.Now.AddDays((double)i);
                row["Field1"] = DateTime.Now.AddMinutes(i);
                row["Field2"] = i + 10000;
                row["Field3"] = i + 5000;
                row["Field4"] = i + 6000;
                row["Field5"] = i + 7000;
                row["Field6"] = i + 8000;
                row["Field7"] = i + 9000;
                row["Field8"] = i + 4000;
                row["Field9"] = $"備考ですよ:{i}";
            }
        }
 
        private void InitReport()
        {
            pnlPageHeader.SetPropertyEx("ReportTag", new ReportControl() { ItemType = ReportControl.EItemType.PageHeader });
            pnlGroupHeader.SetPropertyEx("ReportTag", new ReportControl() { ItemType = ReportControl.EItemType.GroupHeader });
            pnlDetail.SetPropertyEx("ReportTag", new ReportControl() { ItemType = ReportControl.EItemType.Detail });
        }
 
        private void SetGridStyle()
        {
            dataGridView1.ColumnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Control;
 
            dataGridView1.Columns[0].Width = 250;
            dataGridView1.Columns[1].Width = 100;
            dataGridView1.Columns[2].Width = 80;
            dataGridView1.Columns[2].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[3].Width = 200;
            dataGridView1.Columns[4].Width = 150;
            dataGridView1.Columns[5].Width = 100;
            dataGridView1.Columns[6].Width = 60;
            dataGridView1.Columns[6].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns[7].Width = 100;
            dataGridView1.Columns[8].Width = 100;
            dataGridView1.Columns[9].Width = 150;
            dataGridView1.Columns[10].Width = 150;
            dataGridView1.Columns[10].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            dataGridView1.Columns[11].Width = 100;
            dataGridView1.Columns[11].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            dataGridView1.Columns[12].Width = 100;
            dataGridView1.Columns[12].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            dataGridView1.Columns[13].Width = 100;
            dataGridView1.Columns[13].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            dataGridView1.Columns[14].Width = 100;
            dataGridView1.Columns[14].DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
        }
 
 
        private void CreateTestData()
        {
            listData = new DataTable();
            listData.Columns.Add("予約No", typeof(string));
            listData.Columns.Add("部屋タイプ", typeof(string));
            listData.Columns.Add("部屋No", typeof(int));
            listData.Columns.Add("氏名", typeof(string));
            listData.Columns.Add("カナ", typeof(string));
            listData.Columns.Add("到着日", typeof(DateTime));
            listData.Columns.Add("泊数", typeof(int));
            listData.Columns.Add("出発日", typeof(DateTime));
            listData.Columns.Add("部屋人数", typeof(int));
            listData.Columns.Add("利用合計", typeof(int));
            listData.Columns.Add("入金合計", typeof(int));
            listData.Columns.Add("現金", typeof(int));
            listData.Columns.Add("クレジット", typeof(int));
            listData.Columns.Add("クーポン", typeof(int));
            listData.Columns.Add("その他", typeof(int));
 
            for (int i = 0; i < 100; i++)
            {
                Random rd = new Random(Guid.NewGuid().GetHashCode());
 
                DataRow row = listData.NewRow();
                listData.Rows.Add(row);
 
                row["予約No"] = Guid.NewGuid().ToString();
                row["部屋タイプ"] = GetType(rd.Next(1, 4));
                row["部屋No"] = rd.Next(101, 3000);
                int nameId = rd.Next(1, 11);
                row["氏名"] = GetName(nameId) + " " + GetKanjiNumber(rd.Next(1, 11)) + "郎";
                row["カナ"] = GetNameKana(nameId);
 
                DateTime cinDate = DateTime.Now.Date.AddDays((double)rd.Next(1, 10));
                int stay = rd.Next(1, 99);
                DateTime coutDate = cinDate.AddDays((double)stay);
                row["到着日"] = cinDate;
                row["泊数"] = stay;
                row["出発日"] = coutDate;
                row["部屋人数"] = rd.Next(1, 11);
 
                int cash = rd.Next(0, 100000);
                int credit = rd.Next(0, 100000);
                int coupon = rd.Next(0, 100000);
                int other = rd.Next(0, 100000);
 
                row["利用合計"] = cash + credit + coupon + other;
                row["入金合計"] = cash + credit + coupon + other;
                row["現金"] = cash;
                row["クレジット"] = credit;
                row["クーポン"] = coupon;
                row["その他"] = other;
            }
        }
 
        private string GetKanjiNumber(int type)
        {
            switch (type)
            {
                case 1:
                    return "一";
                case 2:
                    return "二";
                case 3:
                    return "三";
                case 4:
                    return "四";
                case 5:
                    return "五";
                case 6:
                    return "六";
                case 7:
                    return "七";
                case 8:
                    return "八";
                case 9:
                    return "九";
                case 10:
                    return "十";
                default:
                    return "太";
            }
        }
 
        private string GetNameKana(int type)
        {
            switch (type)
            {
                case 1:
                    return "クマモト";
                case 2:
                    return "フクオカ";
                case 3:
                    return "サトウ";
                case 4:
                    return "ナカタ";
                case 5:
                    return "ナカノ";
                case 6:
                    return "タムラ";
                case 7:
                    return "キムラ";
                case 8:
                    return "ヨシカワ";
                case 9:
                    return "キチセ";
                case 10:
                    return "ヨシカワ";
                default:
                    return "タナカ";
            }
        }
 
        private string GetName(int type)
        {
            switch (type)
            {
                case 1:
                    return "熊本";
                case 2:
                    return "福岡";
                case 3:
                    return "佐藤";
                case 4:
                    return "中田";
                case 5:
                    return "中野";
                case 6:
                    return "田村";
                case 7:
                    return "木村";
                case 8:
                    return "吉川";
                case 9:
                    return "吉瀬";
                case 10:
                    return "吉岡";
                default:
                    return "田中";
            }
        }
 
        private string GetType(int type)
        {
            switch(type)
            {
                case 1:
                    return "シングル";
                case 2:
                    return "ダブル";
                default:
                    return "ツイン";
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("印刷対象を選択してください。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //using (Graphics g = this.CreateGraphics())
            //{
            //    g.PageUnit = GraphicsUnit.Pixel;
            //    using (Font font = new Font("MS UI Gothic", 9F))
            //    {
            //        float w = g.MeasureString("濃", font).Width;
            //    }
            //}
 
            // Truncate([numChars*7+5]/7*256)/256
            using (DataTable data = (dataGridView1.DataSource as DataTable).Copy())
            {
                GridStyle style = new GridStyle();
                style.DefaultRowStyle.Padding = new Padding(10);
                style.DefaultCellStyle.Font = dataGridView1.DefaultCellStyle.Font;
 
                //ヘッダー情報設定
                style.Header.DefaultRowStyle.Font = new Font("MS UI Gothic", 12F);
                style.Header.DefaultRowStyle.Padding = new Padding(5);
                style.Header.DefaultCellStyle.Font = new Font("MS UI Gothic", 12F);
 
                #region 一行目
                PrintRow printRow = new PrintRow();
                style.Header.Rows.Add(printRow);
 
                //右下⇒印刷日時+頁:
                CellStyle cellTyle = new CellStyle
                {
                    Dock = DockStyle.Right,
                    WidthMode = CellStyle.EWidthMode.TextWidth,
                    Padding = new Padding(0, 3, 3, 0),
                    Font = new Font("メイリオ", 10F),
                    Alignment = StringAlignment.Far,
                    LineAlignment = StringAlignment.Far,
                    Template = "印刷日時:{0}\r\n頁:{1} / {2}"
                };
                //cellTyle.TopBorder.Visible = cellTyle.LeftBorder.Visible = cellTyle.RightBorder.Visible = cellTyle.BottomBorder.Visible = true;
                Cell cell = new Cell { CellType = Cell.CellKind.TimeAndPage, Style = cellTyle };
                printRow.Cells.Add(cell);
 
                //タイトル
                cellTyle = new CellStyle
                {
                    Dock = DockStyle.Fill,
                    WidthMode = CellStyle.EWidthMode.AutoFill,
                    Padding = new Padding(0, 3, 3, 0),
                    Font = new Font("メイリオ", 18F),
                    Alignment = StringAlignment.Near,
                    LineAlignment = StringAlignment.Center,
                };
                //cellTyle.TopBorder.Visible = cellTyle.LeftBorder.Visible = cellTyle.RightBorder.Visible = cellTyle.BottomBorder.Visible = true;
                cell = new Cell { CellType = Cell.CellKind.Text, Style = cellTyle, Text = "部屋別売上一覧" };
                printRow.Cells.Add(cell);
                #endregion
 
                #region 二行目
 
                printRow = new PrintRow();
                style.Header.Rows.Add(printRow);
 
                cellTyle = new CellStyle
                {
                    LocalXMode = CellStyle.ELocalXMode.BeginOfCol,
                    WidthMode = CellStyle.EWidthMode.EndOfCol,
                    BeginCol = 0,
                    EndCol = 3,
                    Padding = new Padding(0, 3, 3, 0),
                    Font = new Font("メイリオ", 10F),
                    Alignment = StringAlignment.Near,
                    LineAlignment = StringAlignment.Center,
                    Template = "利用期間:{0}"
                };
                //cellTyle.TopBorder.Visible = cellTyle.LeftBorder.Visible = cellTyle.RightBorder.Visible = cellTyle.BottomBorder.Visible = true;
                cell = new Cell { CellType = Cell.CellKind.Text, Style = cellTyle, Text = "2021/09/01~2021/09/30" };
                printRow.Cells.Add(cell);
 
                cellTyle = new CellStyle
                {
                    LocalXMode = CellStyle.ELocalXMode.BeginOfCol,
                    WidthMode = CellStyle.EWidthMode.TextWidth,
                    BeginCol = 4,
                    Padding = new Padding(0, 3, 3, 0),
                    Font = new Font("メイリオ", 10F),
                    Alignment = StringAlignment.Near,
                    LineAlignment = StringAlignment.Center,
                };
                //cellTyle.TopBorder.Visible = cellTyle.LeftBorder.Visible = cellTyle.RightBorder.Visible = cellTyle.BottomBorder.Visible = true;
                cell = new Cell { CellType = Cell.CellKind.Text, Style = cellTyle, Text = "利用状態:在室、アウト" };
                printRow.Cells.Add(cell);
 
                #endregion 
 
                ReportBase.CreateColumnStyle(dataGridView1, style);
                ReportFactory.OutputGrid(data, style);
            }
 
            MessageBox.Show("OK");
        }
    }
}