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