ホテル管理システム
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
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using HotelPms.Share.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
 
namespace HotelPms.Share.Windows.Report
{
    public class GridCsv : ReportBase, IDisposable, IReport
    {
        #region  ★★★★★ Declartions ★★★★★
 
        private bool m_Disposed = false;
 
        #endregion
 
        #region  ★★★★★ Property ★★★★★
 
        #endregion
 
        #region  ★★★★★ Class Event ★★★★★
 
        public GridCsv(DataTable data, GridStyle style)
        {
            m_Data = data;
            m_Style = style;
        }
 
        ~GridCsv()
        {
            Dispose(false);
        }
 
        protected virtual void Dispose(bool disposing)
        {
            if (!m_Disposed)   //一回だけ
            {
                if (disposing)
                {
                    //Managed Resources
                }
 
                //Unmanaged resources
                m_Disposed = true;
            }
        }
 
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
 
        #endregion
 
        #region  ★★★★★ Control Event ★★★★★
        #endregion
 
        #region  ★★★★★ Private Function ★★★★★
        #endregion
 
        #region  ★★★★★ Public  Function ★★★★★
 
        public void Output()
        {
            string path = System.IO.Path.GetTempFileName().Replace(".tmp", ".csv");
            Output(path);
            Process.Start(path);
        }
 
        public void Output(string file)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(file, false, Encoding.UTF8))
                {
                    StringBuilder colNames = new StringBuilder();
                    int col = 0;
                    foreach (ColumnStyle cs in m_Style.ColumnStyle)
                    {
                        if (col > 0) { colNames.Append(","); }
                        colNames.Append("\"");
                        colNames.Append(cs.Text);
                        colNames.Append("\"");
                        col++;
                    }
                    sw.WriteLine(colNames.ToString());
 
                    //データ
                    for (int i = 0; i < m_Data.Rows.Count; i++)
                    {
                        StringBuilder row = new StringBuilder();
                        col = 0;
                        foreach (ColumnStyle cs in m_Style.ColumnStyle)
                        {
                            string text = m_Data.Rows[i][cs.DataField].ToString();
                            if (col > 0) { row.Append(","); }
                            row.Append("\"");
                            row.Append(text);
                            row.Append("\"");
                            col++;
                        }
                        sw.WriteLine(row.ToString());
                    }
 
                    sw.Close();
                }
            }
            catch
            {
            }
        }
 
 
        #endregion
 
    }
}