Mercurial > mercurial > hgweb_searcher03.cgi
diff src/bprint.cpp @ 2:c066fde99517
Added Batch Print Mode.
author | pyon@macmini |
---|---|
date | Fri, 23 Aug 2013 18:32:09 +0900 |
parents | |
children | 1a64119ab257 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bprint.cpp Fri Aug 23 18:32:09 2013 +0900 @@ -0,0 +1,185 @@ +// Filename : bprint.cpp +// Last Change: 23-Aug-2013. +// + +#include "bprint.h" +#include "marksheet.h" +#include "db.h" + +FrameBatchPrint::FrameBatchPrint( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) + : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + this->SetBackgroundColour( wxColour( wxT("WHEAT") ) ); + + wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); + + m_grid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_grid->CreateGrid( 25, 4 ); + m_grid->EnableEditing( true ); + m_grid->EnableGridLines( true ); + m_grid->EnableDragGridSize( false ); + m_grid->SetMargins( 0, 0 ); + + // Columns + m_grid->EnableDragColMove( false ); + m_grid->EnableDragColSize( true ); + m_grid->SetColLabelSize( 30 ); + m_grid->SetColLabelValue( 0, wxT("被保険者番号") ); + m_grid->SetColLabelValue( 1, wxT("氏名") ); + m_grid->SetColLabelValue( 2, wxT("最新フォルダ") ); + m_grid->SetColLabelValue( 3, wxT("ステータス") ); + m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + m_grid->SetColSize( 0, 100 ); + m_grid->SetColSize( 1, 100 ); + m_grid->SetColSize( 2, 220 ); + m_grid->SetColSize( 3, 70 ); + + // Rows + m_grid->EnableDragRowSize( true ); + m_grid->SetRowLabelSize( 30 ); + m_grid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Cell Defaults + m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTRE ); + bSizerTop->Add( m_grid, 1, wxALL|wxEXPAND, 5 ); + + wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL ); + + bSizerButton->Add( 0, 20, 0, 0, 5 ); + + m_buttonClear = new wxButton( this, ID_BPCLEAR, wxT("クリア"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonClear, 0, wxALL, 5 ); + + m_buttonPrint = new wxButton( this, ID_BPPRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerButton->Add( m_buttonPrint, 0, wxALL, 5 ); + + bSizerButton->Add( 0, 20, 0, 0, 5 ); + + m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonClose->SetDefault(); + bSizerButton->Add( m_buttonClose, 0, wxALL, 5 ); + + bSizerTop->Add( bSizerButton, 0, wxEXPAND, 5 ); + + this->SetSizer( bSizerTop ); + this->Layout(); + + this->Centre( wxBOTH ); + + SetGridReadOnly(); +} + +FrameBatchPrint::~FrameBatchPrint() +{ +} + +// Event Table +BEGIN_EVENT_TABLE( FrameBatchPrint, wxDialog ) + EVT_GRID_CELL_CHANGING( FrameBatchPrint::OnInput ) + EVT_BUTTON( ID_BPCLEAR, FrameBatchPrint::OnClear ) + EVT_BUTTON( ID_BPPRINT, FrameBatchPrint::OnPrint ) +END_EVENT_TABLE() + +// Event Handlers & Functions +/* 氏名などを表示 */ +void FrameBatchPrint::OnInput( wxGridEvent& event ) +{ + wxString hhsno = event.GetString(); + int r = event.GetRow(); + for ( int c = 1; c < m_grid->GetNumberCols(); c++ ) + m_grid->SetCellValue( r, c, wxEmptyString ); + + wxArrayString info = wxSplit( GetHhsInfoByHhsNo( hhsno ), '_', '\\' ); + wxArrayString path = GetPathByHhsNo( hhsno ); + + if ( info.IsEmpty() ) info.Add( wxEmptyString ); + if ( path.IsEmpty() ) { + wxMessageBox( wxT("ファイルがありません.") ); + path.Add( wxEmptyString ); + } + + m_grid->SetCellValue( r, 1, info[0] ); + m_grid->SetCellValue( r, 2, path[0] ); +} + +/* グリッドをクリア */ +void FrameBatchPrint::OnClear( wxCommandEvent& WXUNUSED(event) ) +{ + m_grid->ClearGrid(); +} + +/* 一括印刷処理 */ +void FrameBatchPrint::OnPrint( wxCommandEvent& WXUNUSED(event) ) +{ + wxPrintDialogData pd; + wxPrinter p( &pd ); + p.PrintDialog( NULL ); + + for ( int r = 0; r < m_grid->GetNumberRows(); r++ ) { + wxString path = m_grid->GetCellValue( r, 2 ); + + // 印刷用の html を作成 + if ( path.IsEmpty() ) continue; + + wxDir dir( path ); + if ( !dir.IsOpened() ) return; + + wxString html; + html = html + wxT("<html><body>\n"); + + wxString file; + bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); + int n = 0; + wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH; + while ( cout ) { + file = path + wxFILE_SEP_PATH + file; + file.Replace( wxFILE_SEP_PATH, wxT("/") ); + wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n ); + + if ( n == 0 ) { // 1枚目はマスクする + wxImage img_org( file, wxBITMAP_TYPE_JPEG ); + int ver = GetMarksheetVersion( file ); + if ( ver == 2 ) { + img_org.SetRGB( m_mask1, 255, 255, 255 ); // cm name + img_org.SetRGB( m_mask2, 255, 255, 255 ); // cm no. + img_org.SetRGB( m_mask3, 255, 255, 255 ); // barcode + } + else { // 古いマークシート ver == 1 + img_org.SetRGB( m_mask1old, 255, 255, 255 ); // cm name + img_org.SetRGB( m_mask2old, 255, 255, 255 ); // cm no. + img_org.SetRGB( m_mask3old, 255, 255, 255 ); // barcode + } + img_org.SaveFile( tmpjpg ); + } + else { + wxCopyFile( file, tmpjpg, true ); + } + html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); + cout = dir.GetNext( &file ); + n++; + } + html = html + wxT("</body></html>"); + + // start printing + wxHtmlPrintout hpout( wxT("Searcher03") ); + hpout.SetMargins( 0, 0, 0, 0, 0 ); + + hpout.SetHtmlText( html, wxEmptyString, false ); + p.Print( NULL, &hpout, false ); + + m_grid->SetCellValue( r, 3, wxT("処理済") ); + } +} + +/* 入力禁止 */ +void FrameBatchPrint::SetGridReadOnly( void ) +{ + for ( int r = 0; r < m_grid->GetNumberRows(); r++ ) + for ( int c = 1; c < m_grid->GetNumberCols(); c++ ) + m_grid->SetReadOnly( r, c, true ); +} + +