2
|
1 // Filename : bprint.cpp
|
4
|
2 // Last Change: 11-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 );
|
|
123
|
|
124 for ( int r = 0; r < m_grid->GetNumberRows(); r++ ) {
|
|
125 wxString path = m_grid->GetCellValue( r, 2 );
|
|
126
|
|
127 // 印刷用の html を作成
|
|
128 if ( path.IsEmpty() ) continue;
|
|
129
|
|
130 wxDir dir( path );
|
|
131 if ( !dir.IsOpened() ) return;
|
|
132
|
|
133 wxString html;
|
|
134 html = html + wxT("<html><body>\n");
|
|
135
|
|
136 wxString file;
|
|
137 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
|
4
|
138 bool notyet_mask = true;
|
2
|
139 int n = 0;
|
|
140 wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH;
|
|
141 while ( cout ) {
|
|
142 file = path + wxFILE_SEP_PATH + file;
|
|
143 file.Replace( wxFILE_SEP_PATH, wxT("/") );
|
|
144 wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n );
|
|
145
|
4
|
146 double zmin = 0.095713;
|
|
147 double zmax = 0.147142;
|
|
148 long lmin = 2072393;
|
|
149 long lmax = 2472318;
|
|
150
|
|
151 if ( notyet_mask && IsMarksheet( file, zmin, zmax, lmin, lmax ) ) { // マークシート表面をマスクする
|
2
|
152 wxImage img_org( file, wxBITMAP_TYPE_JPEG );
|
|
153 int ver = GetMarksheetVersion( file );
|
|
154 if ( ver == 2 ) {
|
|
155 img_org.SetRGB( m_mask1, 255, 255, 255 ); // cm name
|
|
156 img_org.SetRGB( m_mask2, 255, 255, 255 ); // cm no.
|
|
157 img_org.SetRGB( m_mask3, 255, 255, 255 ); // barcode
|
|
158 }
|
|
159 else { // 古いマークシート ver == 1
|
|
160 img_org.SetRGB( m_mask1old, 255, 255, 255 ); // cm name
|
|
161 img_org.SetRGB( m_mask2old, 255, 255, 255 ); // cm no.
|
|
162 img_org.SetRGB( m_mask3old, 255, 255, 255 ); // barcode
|
|
163 }
|
|
164 img_org.SaveFile( tmpjpg );
|
|
165 }
|
|
166 else {
|
|
167 wxCopyFile( file, tmpjpg, true );
|
|
168 }
|
|
169 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
|
|
170 cout = dir.GetNext( &file );
|
|
171 n++;
|
|
172 }
|
|
173 html = html + wxT("</body></html>");
|
|
174
|
|
175 // start printing
|
|
176 wxHtmlPrintout hpout( wxT("Searcher03") );
|
|
177 hpout.SetMargins( 0, 0, 0, 0, 0 );
|
|
178
|
|
179 hpout.SetHtmlText( html, wxEmptyString, false );
|
|
180 p.Print( NULL, &hpout, false );
|
|
181
|
|
182 m_grid->SetCellValue( r, 3, wxT("処理済") );
|
|
183 }
|
|
184 }
|
|
185
|
|
186 /* 入力禁止 */
|
|
187 void FrameBatchPrint::SetGridReadOnly( void )
|
|
188 {
|
|
189 for ( int r = 0; r < m_grid->GetNumberRows(); r++ )
|
|
190 for ( int c = 1; c < m_grid->GetNumberCols(); c++ )
|
|
191 m_grid->SetReadOnly( r, c, true );
|
|
192 }
|
|
193
|
|
194
|