2
|
1 // Filename : bprint.cpp
|
6
|
2 // Last Change: 18-Sep-2013.
|
2
|
3 //
|
|
4
|
|
5 #include "bprint.h"
|
|
6 #include "marksheet.h"
|
3
|
7 #include "dndfile.h"
|
2
|
8 #include "db.h"
|
|
9
|
|
10 FrameBatchPrint::FrameBatchPrint( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
11 : wxDialog( parent, id, title, pos, size, style )
|
|
12 {
|
|
13 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
14 this->SetBackgroundColour( wxColour( wxT("WHEAT") ) );
|
|
15
|
|
16 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
|
|
17
|
|
18 m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
|
|
19
|
|
20 // Grid
|
|
21 m_grid->CreateGrid( 25, 4 );
|
|
22 m_grid->EnableEditing( true );
|
|
23 m_grid->EnableGridLines( true );
|
|
24 m_grid->EnableDragGridSize( false );
|
|
25 m_grid->SetMargins( 0, 0 );
|
|
26
|
|
27 // Columns
|
|
28 m_grid->EnableDragColMove( false );
|
|
29 m_grid->EnableDragColSize( true );
|
|
30 m_grid->SetColLabelSize( 30 );
|
|
31 m_grid->SetColLabelValue( 0, wxT("被保険者番号") );
|
|
32 m_grid->SetColLabelValue( 1, wxT("氏名") );
|
|
33 m_grid->SetColLabelValue( 2, wxT("最新フォルダ") );
|
|
34 m_grid->SetColLabelValue( 3, wxT("ステータス") );
|
|
35 m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
|
|
36 m_grid->SetColSize( 0, 100 );
|
|
37 m_grid->SetColSize( 1, 100 );
|
|
38 m_grid->SetColSize( 2, 220 );
|
|
39 m_grid->SetColSize( 3, 70 );
|
3
|
40 m_grid->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS );
|
2
|
41
|
|
42 // Rows
|
|
43 m_grid->EnableDragRowSize( true );
|
|
44 m_grid->SetRowLabelSize( 30 );
|
|
45 m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
|
|
46
|
|
47 // Cell Defaults
|
|
48 m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
|
|
49 bSizerTop->Add( m_grid, 1, wxALL|wxEXPAND, 5 );
|
|
50
|
|
51 wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL );
|
|
52
|
|
53 bSizerButton->Add( 0, 20, 0, 0, 5 );
|
|
54
|
|
55 m_buttonClear = new wxButton( this, ID_BPCLEAR, wxT("クリア"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
56 bSizerButton->Add( m_buttonClear, 0, wxALL, 5 );
|
|
57
|
|
58 m_buttonPrint = new wxButton( this, ID_BPPRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
59 bSizerButton->Add( m_buttonPrint, 0, wxALL, 5 );
|
|
60
|
|
61 bSizerButton->Add( 0, 20, 0, 0, 5 );
|
|
62
|
|
63 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
64 m_buttonClose->SetDefault();
|
|
65 bSizerButton->Add( m_buttonClose, 0, wxALL, 5 );
|
|
66
|
|
67 bSizerTop->Add( bSizerButton, 0, wxEXPAND, 5 );
|
|
68
|
|
69 this->SetSizer( bSizerTop );
|
|
70 this->Layout();
|
|
71
|
|
72 this->Centre( wxBOTH );
|
|
73
|
3
|
74 this->SetDropTarget( new DnDFile( m_grid ) );
|
2
|
75 SetGridReadOnly();
|
|
76 }
|
|
77
|
|
78 FrameBatchPrint::~FrameBatchPrint()
|
|
79 {
|
|
80 }
|
|
81
|
|
82 // Event Table
|
|
83 BEGIN_EVENT_TABLE( FrameBatchPrint, wxDialog )
|
|
84 EVT_GRID_CELL_CHANGING( FrameBatchPrint::OnInput )
|
|
85 EVT_BUTTON( ID_BPCLEAR, FrameBatchPrint::OnClear )
|
|
86 EVT_BUTTON( ID_BPPRINT, FrameBatchPrint::OnPrint )
|
|
87 END_EVENT_TABLE()
|
|
88
|
|
89 // Event Handlers & Functions
|
|
90 /* 氏名などを表示 */
|
|
91 void FrameBatchPrint::OnInput( wxGridEvent& event )
|
|
92 {
|
|
93 wxString hhsno = event.GetString();
|
|
94 int r = event.GetRow();
|
|
95 for ( int c = 1; c < m_grid->GetNumberCols(); c++ )
|
|
96 m_grid->SetCellValue( r, c, wxEmptyString );
|
|
97
|
|
98 wxArrayString info = wxSplit( GetHhsInfoByHhsNo( hhsno ), '_', '\\' );
|
|
99 wxArrayString path = GetPathByHhsNo( hhsno );
|
|
100
|
|
101 if ( info.IsEmpty() ) info.Add( wxEmptyString );
|
|
102 if ( path.IsEmpty() ) {
|
|
103 wxMessageBox( wxT("ファイルがありません.") );
|
|
104 path.Add( wxEmptyString );
|
|
105 }
|
|
106
|
|
107 m_grid->SetCellValue( r, 1, info[0] );
|
|
108 m_grid->SetCellValue( r, 2, path[0] );
|
|
109 }
|
|
110
|
|
111 /* グリッドをクリア */
|
|
112 void FrameBatchPrint::OnClear( wxCommandEvent& WXUNUSED(event) )
|
|
113 {
|
|
114 m_grid->ClearGrid();
|
|
115 }
|
|
116
|
|
117 /* 一括印刷処理 */
|
|
118 void FrameBatchPrint::OnPrint( wxCommandEvent& WXUNUSED(event) )
|
|
119 {
|
|
120 wxPrintDialogData pd;
|
|
121 wxPrinter p( &pd );
|
|
122 p.PrintDialog( NULL );
|
6
|
123 wxArrayString log;
|
2
|
124
|
|
125 for ( int r = 0; r < m_grid->GetNumberRows(); r++ ) {
|
|
126 wxString path = m_grid->GetCellValue( r, 2 );
|
|
127
|
|
128 // 印刷用の html を作成
|
|
129 if ( path.IsEmpty() ) continue;
|
|
130
|
|
131 wxDir dir( path );
|
|
132 if ( !dir.IsOpened() ) return;
|
|
133
|
|
134 wxString html;
|
|
135 html = html + wxT("<html><body>\n");
|
|
136
|
|
137 wxString file;
|
|
138 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
|
4
|
139 bool notyet_mask = true;
|
2
|
140 int n = 0;
|
|
141 wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH;
|
|
142 while ( cout ) {
|
|
143 file = path + wxFILE_SEP_PATH + file;
|
|
144 file.Replace( wxFILE_SEP_PATH, wxT("/") );
|
|
145 wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n );
|
|
146
|
5
|
147 if ( notyet_mask && IsMarksheet( file, m_zmin, m_zmax, m_lmin, m_lmax ) ) { // マークシート表面をマスクする
|
2
|
148 wxImage img_org( file, wxBITMAP_TYPE_JPEG );
|
|
149 int ver = GetMarksheetVersion( file );
|
|
150 if ( ver == 2 ) {
|
|
151 img_org.SetRGB( m_mask1, 255, 255, 255 ); // cm name
|
|
152 img_org.SetRGB( m_mask2, 255, 255, 255 ); // cm no.
|
|
153 img_org.SetRGB( m_mask3, 255, 255, 255 ); // barcode
|
|
154 }
|
|
155 else { // 古いマークシート ver == 1
|
|
156 img_org.SetRGB( m_mask1old, 255, 255, 255 ); // cm name
|
|
157 img_org.SetRGB( m_mask2old, 255, 255, 255 ); // cm no.
|
|
158 img_org.SetRGB( m_mask3old, 255, 255, 255 ); // barcode
|
|
159 }
|
|
160 img_org.SaveFile( tmpjpg );
|
|
161 }
|
|
162 else {
|
|
163 wxCopyFile( file, tmpjpg, true );
|
|
164 }
|
|
165 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
|
|
166 cout = dir.GetNext( &file );
|
|
167 n++;
|
|
168 }
|
|
169 html = html + wxT("</body></html>");
|
|
170
|
|
171 // start printing
|
|
172 wxHtmlPrintout hpout( wxT("Searcher03") );
|
|
173 hpout.SetMargins( 0, 0, 0, 0, 0 );
|
|
174
|
|
175 hpout.SetHtmlText( html, wxEmptyString, false );
|
|
176 p.Print( NULL, &hpout, false );
|
|
177
|
|
178 m_grid->SetCellValue( r, 3, wxT("処理済") );
|
6
|
179 log.Add( path );
|
2
|
180 }
|
6
|
181 WriteLog( log );
|
2
|
182 }
|
|
183
|
|
184 /* 入力禁止 */
|
|
185 void FrameBatchPrint::SetGridReadOnly( void )
|
|
186 {
|
|
187 for ( int r = 0; r < m_grid->GetNumberRows(); r++ )
|
|
188 for ( int c = 1; c < m_grid->GetNumberCols(); c++ )
|
|
189 m_grid->SetReadOnly( r, c, true );
|
|
190 }
|
|
191
|
6
|
192 /* 印刷ログ */
|
|
193 void FrameBatchPrint::WriteLog( wxArrayString logline )
|
|
194 {
|
|
195 wxDateTime now = wxDateTime::Now();
|
|
196 wxString log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("bp_") + now.Format( wxT("%Y%m%d%H%M%S.log") );
|
|
197 wxTextFile file( log_file );
|
|
198 file.Create();
|
|
199 wxTextFile logfile;
|
|
200 logfile.Open( log_file );
|
2
|
201
|
6
|
202 for ( int n = 0; n < logline.GetCount(); n++ ) {
|
|
203 logfile.AddLine( logline[n] );
|
|
204 }
|
|
205 logfile.Write();
|
|
206 logfile.Close();
|
|
207 }
|
|
208
|