Mercurial > mercurial > hgweb_searcher03.cgi
view src/bprint.cpp @ 8:4967d1e2b30c
Alert when not mask in batch print mode.
author | pyon@macmini |
---|---|
date | Fri, 01 Nov 2013 18:44:37 +0900 |
parents | 76db82822e73 |
children | 52958cd4a073 |
line wrap: on
line source
// Filename : bprint.cpp // Last Change: 01-Nov-2013. // #include "bprint.h" #include "marksheet.h" #include "dndfile.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, 90 ); m_grid->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_ALWAYS ); // 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 ); this->SetDropTarget( new DnDFile( m_grid ) ); 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 ); wxArrayString log; 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 ); bool notyet_mask = true; 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 ( notyet_mask && IsMarksheet( file, m_zmin, m_zmax, m_lmin, m_lmax ) ) { // マークシート表面をマスクする 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 ); notyet_mask = false; } 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 ); wxString pst = wxT("処理済"); wxString logmsg = path; if ( notyet_mask ) { pst.Append( wxT(" 非マスク") ); logmsg.Append( wxT(" not mask") ); } m_grid->SetCellValue( r, 3, pst ); log.Add( logmsg ); } WriteLog( log ); } /* 入力禁止 */ 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 ); } /* 印刷ログ */ void FrameBatchPrint::WriteLog( wxArrayString logline ) { wxDateTime now = wxDateTime::Now(); wxString log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("bp_") + now.Format( wxT("%Y%m%d%H%M%S.log") ); wxTextFile file( log_file ); file.Create(); wxTextFile logfile; logfile.Open( log_file ); for ( int n = 0; n < logline.GetCount(); n++ ) { logfile.AddLine( logline[n] ); } logfile.Write(); logfile.Close(); }