ホテル管理システム
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
using HotelPms.Share.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace HotelPms.Share.Windows.Report
{
    public class ReportFactory
    {        
        public static void OutputGrid(DataTable data, GridStyle style)
        {
            ReportType type = ReportType.Print;
            using(FormTypeSelect form = new FormTypeSelect())
            {
                if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; }
                type = form.ReportType;
            }
            OutputGrid(data, style, type);
        }
 
        public static string GetTempFileName()
        {
            string root = Application.StartupPath.TrimEnd(Path.DirectorySeparatorChar) + @"\Output\";
            if(!Directory.Exists(root)) { Directory.CreateDirectory(root);  }
 
            return $"{root}{DateTime.Now.ToString("yyyyMMddHHmmssfff")}";
        }
 
        public static void OutputGrid(DataTable data, GridStyle style, ReportType type)
        {
            string path = string.Empty;
           IReport report = null;
            if (type == ReportType.Print) { report = new GridReport(data, style, string.Empty); }
            else if (type == ReportType.Pdf) 
            {
                path = GetTempFileName() + ".pdf";
                report = new GridReport(data, style, path); 
            }
            else if (type == ReportType.Xlsx) { report = new GridExcel(data, style, true, GetTempFileName()); }
            else if (type == ReportType.Xls) { report = new GridExcel(data, style, false, GetTempFileName()); }
            else if (type == ReportType.Csv) { report = new GridCsv(data, style); }
            else if (type == ReportType.Xml) { report = new GridXml(data, style); }
                       
            if (report == null) { return; }
            report.Output();
            report.Dispose();
 
            if (type == ReportType.Pdf) { CConvert.StartFile(path); }
        }
 
        public static void OutputForm(List<List<Cell>> rptList, Rectangle ownerArea, PaperKind paper, string titlem)
        {
            OutputForm(rptList, ownerArea, paper, titlem, -1);
        }
 
        public static void OutputForm(List<List<Cell>> rptList, Rectangle ownerArea, PaperKind paper, string title, int rptType)
        {
            ReportType type = ReportType.Print;
            if (rptType == -1)
            {
                using (FormTypeSelect form = new FormTypeSelect())
                {
                    form.btnItem2.Enabled = false;
                    form.btnItem3.Enabled = false;
                    form.btnItem6.Enabled = false;
                    form.btnItem7.Enabled = false;
                    if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; }
                    type = form.ReportType;
                }
            }
            else
            {
                type = (ReportType)rptType;
            }
 
            IReport report = null;
            if (type == ReportType.Print) { report = new FormReport(rptList, ownerArea, paper, title); }
 
            if (report == null) { return; }
            report.Output();
            report.Dispose();
        }
 
        public static int SelectType()
        {
            ReportType type = ReportType.Print;
            using (FormTypeSelect form = new FormTypeSelect())
            {
                form.btnItem2.Enabled = false;
                form.btnItem3.Enabled = false;
                form.btnItem6.Enabled = false;
                form.btnItem7.Enabled = false;
                if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return -1; }
                type = form.ReportType;
            }
            return (int)type;
        }
 
    }
}